KNOX-3353: Eliminate K8sPreAuthFederationFilter and consolidate logic in ServiceAccountValidator#1269
Merged
Merged
Conversation
… in ServiceAccountValidator
Contributor
Author
Test Results22 tests 22 ✅ 2s ⏱️ Results for commit 1aaea85. ♻️ This comment has been updated with latest results. |
…tor discovery This change replaces the static initializer in PreAuthService with lazy, instance-based loading to ensure ServiceLoader respects the Thread Context ClassLoader of the specific filter instance. This resolves discovery issues where providers in separate JARs (like the K8s validator) were missed due to premature static initialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KNOX-3353 - Eliminate K8sPreAuthFederationFilter and consolidate logic in ServiceAccountValidator
What changes were proposed in this pull request?
Consolidated the Kubernetes pre-authentication logic by eliminating the redundant
K8sPreAuthFederationFilterand moving its resolver management and initialization directly intoServiceAccountValidator.Key changes include:
PreAuthServiceto use lazy, instance-based validator discovery: removed the static initializer and static map in favor of a per-filter instance discovery. This ensures thatServiceLoaderuses the correctClassLoadercontext for each topology, resolving issues where providers in separate JARs (like the K8s validator) were missed.PreAuthValidatorinterface to includeinit(FilterConfig)anddestroy()methods for better lifecycle management.AbstractPreAuthFederationFilterto properly initialize and destroy all configured validators.ServiceAccountValidatorto manage theK8sServiceAccountResolverand its cache internally.preauth.k8s.sa.prefix.K8sPreAuthFederationFilter,K8sPreAuthContributor, and related service registrations.How was this patch tested?
The changes were verified by running existing and updated unit tests:
mvn test -pl gateway-provider-security-k8s: VerifiedServiceAccountValidator,K8sServiceAccountResolver, andSpiffeIdlogic.mvn test -pl gateway-provider-security-preauth: VerifiedAbstractPreAuthFederationFilter,IPValidator, andDefaultValidatorwith the new lifecycle methods.ServiceAccountValidatorTestcorrectly mocks the resolver and validates parameter handling.Manual tested on a kind cluster using the same SA and RBAC CR's from #1268. My
health.xmllooks like this:Happy path:
Negative case:
Log:
Integration Tests
N/A
UI changes
N/A