Repository navigation
feat(provider): accept a SpiffeIdVerifier in SslContextOptions - #521
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
SpiffeTrustManager can verify peer SPIFFE IDs with a SpiffeIdVerifier callback, which lets an application accept peers by rule (a trust domain, a path prefix, a lookup in another system) instead of from a fixed set of IDs. SpiffeSslContextFactory, the documented way to build an SSLContext backed by the Workload API, only accepted a Supplier of accepted SPIFFE IDs or acceptAnySpiffeId, so using a verifier meant creating the key and trust managers and initializing the SSLContext by hand. Add a spiffeIdVerifier option to SslContextOptions, with a builder method, a getter and a constructor that takes it. getSslContext creates the SpiffeTrustManager with the verifier when it is set. A verifier is a complete authorization decision on its own, so combining it with acceptedSpiffeIdsSupplier or acceptAnySpiffeId is rejected with an IllegalArgumentException instead of letting one silently override the other. The existing behavior of the supplier and acceptAnySpiffeId options is unchanged, and the error raised when no option is configured now also mentions the verifier. Document the option in the provider README with an example that accepts any workload in a trust domain, and add a changelog entry. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
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.
What
Adds a
spiffeIdVerifieroption toSpiffeSslContextFactory.SslContextOptions, so anSSLContextbuilt bySpiffeSslContextFactorycan check peer SPIFFE IDs with a customSpiffeIdVerifier:Details:
SslContextOptionsgets aspiffeIdVerifier(...)builder method, agetSpiffeIdVerifier()getter, and a constructor that takes the verifier. The existing 4-argument constructor delegates to it.getSslContextbuilds theSpiffeTrustManagerwith it. The trust manager verifies the chain against the bundles first, then calls the verifier with the peer's SPIFFE ID and chain, as it already does for verifiers passed to its constructor.acceptedSpiffeIdsSupplieroracceptAnySpiffeIdis also set,getSslContextthrowsIllegalArgumentExceptioninstead of letting one option silently override the other.acceptAnySpiffeIdoptions behave as before. The one visible change is the message of theIllegalArgumentExceptionthrown when no option is configured, which now mentions the verifier.SpiffeTrustManagerFactoryoverload is added.engineGetTrustManagers(BundleSource, SpiffeIdVerifier)would make existingengineGetTrustManagers(source, null)calls ambiguous at compile time.Why
#77 added
SpiffeIdVerifiertoSpiffeTrustManagerso applications can accept peers by rule instead of from a fixed set of IDs. Examples are any workload in a trust domain, a path prefix, or a lookup in another system. go-spiffe offers the same thing withtlsconfig.Authorizer.SpiffeSslContextFactoryis the documented way to get anSSLContextbacked by the Workload API, but it only took aSupplier<Set<SpiffeId>>oracceptAnySpiffeId. To use a verifier, callers had to create the key manager and trust manager and initialize theSSLContextthemselves.Compatibility: this only adds a constructor, a getter and a builder method.
:java-spiffe-provider:japicmppasses.How tested
SpiffeSslContextFactoryTest:SSLContextis created with only a verifier, and the options return itacceptedSpiffeIdsSupplier, or withacceptAnySpiffeId, throwsIllegalArgumentExceptionSSLEngines, with SVIDs and a bundle generated for the test: the verifier is called on both sides, with the peer's SPIFFE ID and certificate chainSpiffeVerificationExceptionfails the handshake with anSSLHandshakeExceptioncaused by that exceptiongetSslContextignores the verifier../gradlew :java-spiffe-provider:test :java-spiffe-provider:javadoc :java-spiffe-provider:japicmp(92 provider tests pass).