Repository navigation
feat(provider): add SpiffeIdVerifier.acceptIdPrefix - #528
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
Accepting every workload under a path is a common authorization rule (the workloads of a Kubernetes namespace, the agents under /spire/agent), but none of the SpiffeIdVerifier factory methods covers it, so callers have to write it by hand. The obvious hand-written check, spiffeId.getPath().startsWith(prefix), also accepts paths that only share a string prefix: /backend accepts /backend-admin. go-spiffe 2.9.0 added this rule as spiffeid.MatchIDPrefix and tlsconfig.AuthorizeIDPrefix. Add SpiffeIdVerifier.acceptIdPrefix(SpiffeId prefix). It accepts a SPIFFE ID that is in the trust domain of the prefix and whose path is the path of the prefix or extends it with more segments, so the prefix is matched on segment boundaries. Paths are compared case-sensitively, as the SPIFFE ID spec requires. Rejections throw SpiffeVerificationException naming the peer SPIFFE ID and the prefix. A prefix without a path is rejected with an IllegalArgumentException when the verifier is created, pointing to acceptMemberOf. go-spiffe returns a matcher that rejects every ID in that case because its constructors cannot fail; failing at creation surfaces the mistake when the SSLContext is built instead of on every handshake. A null prefix throws NullPointerException, like the other factory methods. Document the method in the provider README. The README's example of a custom verifier was the hand-written path prefix check, so replace it with a rule the factory methods don't cover. Add a changelog entry. Adding a static method to an interface is binary compatible, and japicmp passes. 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
SpiffeIdVerifier.acceptIdPrefix(SpiffeId prefix), a factory method for a verifier that accepts a SPIFFE ID and any SPIFFE ID under its path:Details:
spiffe://example.org/backendacceptsspiffe://example.org/backendandspiffe://example.org/backend/api. It rejectsspiffe://example.org/backend-admin,spiffe://example.org/Backend/apiandspiffe://other.org/backend/api.SpiffeId.SpiffeVerificationException:SPIFFE ID <id> in X.509 certificate does not match the prefix <prefix>.spiffe://example.org) throwsIllegalArgumentExceptionwhen the verifier is created, and the message points toacceptMemberOf. go-spiffe'sMatchIDPrefixreturns a matcher that rejects every ID in this case, because its constructors can't fail. Failing at creation reports the mistake when theSSLContextis built instead of on every handshake. A null prefix throwsNullPointerException, like the other factory methods.getPath().startsWith("/backend/")), so it now shows a rule the factories don't cover: a Kubernetes service account name in any namespace. The changelog lists the method under Unreleased.Why
Accepting every workload under a path is a common authorization rule, for example the workloads of a Kubernetes namespace (
/ns/prod) or the SPIRE agents under/spire/agent. None of the factories added in #524 covers it, so callers had to write the check themselves. The obvious check,spiffeId.getPath().startsWith(prefix), also accepts paths that only share a string prefix:/backendwould accept/backend-admin. go-spiffe 2.9.0 added this rule asspiffeid.MatchIDPrefixandtlsconfig.AuthorizeIDPrefix, and this follows its semantics.Compatibility: this only adds a static method to the
SpiffeIdVerifierinterface, which is binary and source compatible for existing implementations and lambdas.:java-spiffe-provider:japicmppasses.How tested
SpiffeIdVerifierTest:/ns/prod), accepts/ns/prod/sa/weband rejects/ns/production/sa/web,/nsand/prod/backend-admin,/backendapi,/Backend/api,/frontend/backend, the trust domain's root ID and IDs in other trust domains (other.org,example.org.other), checking the messageSpiffeSslContextFactoryTest: mutual TLS handshake between two in-memorySSLEngines where each side accepts the other withacceptIdPrefix. With the prefixspiffe://example.org/serv, which shares a string prefix with the server's/serverpath but not a segment boundary, the handshake fails with anSSLHandshakeExceptioncaused by the verifier'sSpiffeVerificationException../gradlew :java-spiffe-provider:test :java-spiffe-provider:javadoc :java-spiffe-provider:japicmp(115 provider tests pass).