Repository navigation
feat(provider): add SpiffeIdVerifier factory methods - #524
Merged
maxlambrecht merged 1 commit intoNov 20, 2026
Merged
Conversation
maxlambrecht
approved these changes
Nov 20, 2026
maxlambrecht
left a comment
Member
There was a problem hiding this comment.
LGTM! These factories are great additions!
SslContextOptions and SpiffeTrustManager accept a SpiffeIdVerifier, but every caller has to write the verifier by hand, even for the common authorization rules. go-spiffe ships these rules as tlsconfig.AuthorizeAny, AuthorizeID, AuthorizeOneOf and AuthorizeMemberOf. Add static factory methods to the SpiffeIdVerifier interface: - acceptAny() accepts any SPIFFE ID - acceptId(SpiffeId) accepts only the given SPIFFE ID - acceptOneOf(SpiffeId...) and acceptOneOf(Collection<SpiffeId>) accept any of the given SPIFFE IDs, copied when the verifier is created - acceptMemberOf(TrustDomain) accepts any SPIFFE ID in the trust domain Null arguments and null elements are rejected with a NullPointerException when the verifier is created. A verifier created with no SPIFFE IDs rejects every peer. Rejections throw SpiffeVerificationException with the same message format as the existing Supplier-based verifier. SpiffeTrustManager now uses acceptAny() instead of its private accept-any constant. Adding static methods to an interface is binary compatible, and japicmp passes. Document the factory methods in the provider README, keep an example of a custom verifier for other rules, and add a changelog entry. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
maxlambrecht
force-pushed
the
feat/spiffe-id-verifier-factories
branch
from
November 20, 2026 02:42
709e3b4 to
c659925
Compare
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 static factory methods to
SpiffeIdVerifierfor the common peer authorization rules:SpiffeIdVerifier.acceptAny()accepts any SPIFFE ID.SpiffeIdVerifier.acceptId(SpiffeId)accepts only the given SPIFFE ID.SpiffeIdVerifier.acceptOneOf(SpiffeId...)andacceptOneOf(Collection<SpiffeId>)accept any of the given SPIFFE IDs.SpiffeIdVerifier.acceptMemberOf(TrustDomain)accepts any SPIFFE ID in the trust domain.Details:
acceptOneOf, throwsNullPointerExceptionwhen the verifier is created, not during a handshake.acceptOneOfcopies the SPIFFE IDs, so later changes to the array or collection don't affect the verifier. The Javadoc and README point toacceptedSpiffeIdsSupplierfor a set that changes over time. With no SPIFFE IDs, the verifier rejects every peer.SpiffeVerificationException.acceptIdandacceptOneOfuse the message of the existing Supplier-based verifier (SPIFFE ID ... in X.509 certificate is not accepted), andacceptMemberOfsays which trust domain was expected.SpiffeTrustManager(BundleSource)now usesacceptAny()instead of its private accept-any constant. Behavior is unchanged.SpiffeIdVerifiergets a class-level Javadoc.acceptMemberOfin the example, and keeps an example of a hand-written verifier for other rules (a path prefix). The changelog lists the methods under Unreleased.Why
#521 made
SpiffeIdVerifierusable fromSslContextOptions, but callers still had to write the verifier themselves even for the usual rules, such as "any workload in my trust domain" (the README example was exactly that lambda). go-spiffe provides these rules astlsconfig.AuthorizeAny,AuthorizeID,AuthorizeOneOfandAuthorizeMemberOf. Ready-made verifiers also avoid small mistakes in hand-written ones, such as comparing SPIFFE ID strings or trust domain names instead of usingSpiffeId.equalsandmemberOf.Compatibility: this only adds static methods to the
SpiffeIdVerifierinterface, which is binary and source compatible for existing implementations and lambdas.:java-spiffe-provider:japicmppasses.How tested
SpiffeIdVerifierTest:acceptAnyaccepts IDs from any trust domain, including a root IDacceptIdaccepts an equal SPIFFE ID and rejects other paths, a child path and another trust domain, with the expected messageacceptOneOf(array and collection) accepts the given IDs and rejects others; changes to the array or collection after creation don't affect the verifier; an empty set rejects everythingacceptMemberOfaccepts IDs in the trust domain (including one parsed from an upper-case trust domain) and rejects other trust domains, includingexample.org.other, with the expected messageNullPointerExceptionwith the expected messages; a null SPIFFE ID is rejected by every verifierSpiffeSslContextFactoryTest: mutual TLS handshake between two in-memorySSLEngines, with the client usingacceptId(server)and the server usingacceptMemberOf(example.org). The handshake succeeds, and withacceptOneOfof a different ID it fails with anSSLHandshakeExceptioncaused by the verifier'sSpiffeVerificationException../gradlew :java-spiffe-provider:test :java-spiffe-provider:javadoc :java-spiffe-provider:japicmp(108 provider tests pass).