Skip to content

Commit 94de838

Browse files
committed
Skip SPIFFE wiring without associations
A deployment with no SPIFFE associations still received a non-nil association registry, because the trust config is always built. The registry then installed a client resolver and an X.509 matcher, so a request carrying the SPIFFE JWT assertion type on a plain server took the SPIFFE arm and failed there instead of reaching the default client authentication path. NewSPIFFEAssociationRegistry now returns nil when the trust config has no associations, which leaves the resolver and the matcher unset. Associations is safe on a nil trust config, so a nil config takes the same path. The server comments that said these are nil only without a trust config are updated. Doc 17 lists the SPIFFE discovery entries. It also no longer says that omitting token_exchange from inbound_grants disables RFC 8693 entirely: token exchange stays enabled and advertised when a legacy delegate client or trusted-issuer policy is present, or when any SPIFFE association lists the token-exchange grant. Breaking: on a server with no SPIFFE associations, a request with the SPIFFE JWT assertion type now gets the default strategy's rejection instead of a SPIFFE-specific one. Part of #6204. Co-authored-by: Mecatl <noreply@mecatl.dev>
1 parent f206c7f commit 94de838

5 files changed

Lines changed: 50 additions & 22 deletions

File tree

‎docs/arch/17-token-exchange-delegation.md‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,28 @@ reuse IDs between the two mechanisms.
281281

282282
Both `/.well-known/oauth-authorization-server` and
283283
`/.well-known/openid-configuration` advertise the token-exchange grant in
284-
`grant_types_supported` by default. Setting `inbound_grants` with
285-
`token_exchange` omitted disables and stops advertising RFC 8693 entirely
286-
(`Config.DisableTokenExchange`, `AuthorizationServerConfig.TokenExchangeEnabled`)
287-
— the same flag governs both registration with fosite and discovery
288-
advertisement, so they cannot drift out of sync. `token_endpoint_auth_methods_supported` always
284+
`grant_types_supported` when token exchange is enabled. With no `inbound_grants`
285+
block it is enabled by default. Once `inbound_grants` is set, omitting its
286+
`token_exchange` block does not by itself turn RFC 8693 off: it stays enabled,
287+
and advertised, when a legacy delegate client or legacy trusted-issuer RFC 8693
288+
policy is present, or when any SPIFFE association lists the token-exchange
289+
grant. It is disabled, and no longer advertised, only when none of these is
290+
present (see the enablement rules in the token-only section above).
291+
`Config.DisableTokenExchange` and `AuthorizationServerConfig.TokenExchangeEnabled`
292+
carry the result. The same flag governs both registration with fosite and
293+
discovery advertisement, so they cannot drift out of sync. `token_endpoint_auth_methods_supported` always
289294
includes `none`. It also includes `client_secret_basic` and
290295
`client_secret_post` when confidential DCR is enabled or a configured delegate
291296
client authenticates with a secret, so a deployment whose delegate clients all
292297
use `private_key_jwt` does not advertise them. It includes `private_key_jwt`, together with
293298
`token_endpoint_auth_signing_alg_values_supported` (the implemented algorithms),
294299
when `allowPrivateKeyJWTRegistration` is enabled or a configured delegate client
295-
uses `private_key_jwt`. The RFC 7523 §2.1 JWT-bearer grant is advertised only
296-
when a trusted issuer opts into it. A private-key JWT DCR client is limited to
300+
uses `private_key_jwt`. It lists `spiffe_x509` and `spiffe_jwt` when some SPIFFE
301+
association enables that method, and `grant_types_supported` lists
302+
`client_credentials` when some association grants it (see
303+
[SPIFFE association declarations](18-spiffe-association-declarations.md)). The
304+
RFC 7523 §2.1 JWT-bearer grant is advertised only when a trusted issuer opts
305+
into it. A private-key JWT DCR client is limited to
297306
token exchange; it is not an authorization-code client.
298307

299308
On Kubernetes, a delegate-client Secret is injected as a pod environment

‎pkg/authserver/runner/embeddedauthserver_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,7 @@ func TestEmbeddedAuthServer_SPIFFESerializedRestartPolicy(t *testing.T) {
28612861
assert.Empty(t, trust.Associations())
28622862
registry, err := authserver.NewSPIFFEAssociationRegistry(trust)
28632863
require.NoError(t, err)
2864-
require.NotNil(t, registry)
2864+
assert.Nil(t, registry)
28652865
// Every restart uses fresh memory. The initial and changed shapes
28662866
// name listener certificate files that do not exist, so only the
28672867
// SPIFFE-removed configuration can build a full server here.

‎pkg/authserver/server_impl.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,10 @@ func warnBlanketSelfIssuedExchange(delegateClients []DelegateClient, jwtBearerEn
571571

572572
// decorateStorageForSPIFFE resolves the immutable association registry from the
573573
// validated SPIFFE trust model and installs the static overlay outside CIMD.
574-
// A nil cfg.SPIFFETrust means no SPIFFE associations are configured, which
575-
// yields a nil registry and leaves the storage chain unchanged. The returned
574+
// The registry is nil when no SPIFFE trust is configured or the trust config has
575+
// no associations, and the storage chain is then left unchanged. The returned
576576
// registry is also wired onto the fosite client-authentication strategy by the
577-
// caller (see newSPIFFEClientResolver); it is nil when no SPIFFE trust is
578-
// configured.
577+
// caller (see newSPIFFEClientResolver).
579578
func decorateStorageForSPIFFE(
580579
ctx context.Context, cfg Config, stor storage.Storage,
581580
) (storage.Storage, *SPIFFEAssociationRegistry, error) {
@@ -603,9 +602,10 @@ func decorateStorageForSPIFFE(
603602
// X.509-SVID and a JWT-SVID for the same association cannot reach different
604603
// authorization outcomes.
605604
//
606-
// It returns a nil resolver when no SPIFFE trust is configured. Returning a
607-
// non-nil func closing over a nil registry would make the strategy's
608-
// resolver != nil check pass when nothing is actually configured.
605+
// It returns a nil resolver when no SPIFFE trust or no SPIFFE association is
606+
// configured. Returning a non-nil func closing over a nil registry would make
607+
// the strategy's resolver != nil check pass when nothing is actually
608+
// configured.
609609
//
610610
// Method uses the shared leaf-package type because package server cannot
611611
// import authserver (authserver imports server). Package authserver aliases
@@ -627,9 +627,9 @@ func newSPIFFEClientResolver(registry *SPIFFEAssociationRegistry) oauthserver.SP
627627
}
628628

629629
// newSPIFFEX509ClientMatcher returns the matcher the client-authentication
630-
// strategy uses to select the X.509 arm, or nil when no SPIFFE trust is
631-
// configured, like newSPIFFEClientResolver. A method value on a nil registry
632-
// would be non-nil.
630+
// strategy uses to select the X.509 arm, or nil when no SPIFFE trust or no
631+
// SPIFFE association is configured, like newSPIFFEClientResolver. A method
632+
// value on a nil registry would be non-nil.
633633
func newSPIFFEX509ClientMatcher(registry *SPIFFEAssociationRegistry) oauthserver.SPIFFEX509ClientMatcher {
634634
if registry == nil {
635635
return nil

‎pkg/authserver/spiffe_association_registry.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,23 @@ type SPIFFEAssociationRegistry struct {
2727
}
2828

2929
// NewSPIFFEAssociationRegistry creates an immutable lookup registry from a
30-
// trust configuration. A nil trust configuration represents an absent SPIFFE
31-
// configuration and returns nil without enabling SPIFFE clients.
30+
// trust configuration. A nil trust configuration, or one with no associations,
31+
// represents an absent SPIFFE configuration and returns nil without enabling
32+
// SPIFFE clients: callers rely on a nil registry to leave the resolver and the
33+
// X.509 matcher unset, so a server without associations keeps the default
34+
// client authentication path.
3235
//
3336
// It rejects any two associations whose patterns could both match the same
3437
// concrete SPIFFE ID (including an exact duplicate, which is the identical
3538
// pattern matching itself) — associationForSPIFFEID resolves wildcard
3639
// patterns by an unordered map scan, so an unrejected overlap would make
3740
// resolution depend on random iteration order.
3841
func NewSPIFFEAssociationRegistry(trust *SPIFFETrustConfig) (*SPIFFEAssociationRegistry, error) {
39-
if trust == nil {
42+
associations := trust.Associations()
43+
if len(associations) == 0 {
4044
return nil, nil
4145
}
4246

43-
associations := trust.Associations()
4447
registry := &SPIFFEAssociationRegistry{
4548
byPattern: make(map[string]SPIFFEClientAuthConfig, len(associations)),
4649
byClientID: make(map[string]SPIFFEClientAuthConfig, len(associations)),

‎pkg/authserver/spiffe_association_registry_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,19 @@ func testSPIFFEAssociation(clientID, scope string) SPIFFEClientAuthRunConfig {
500500
GrantTypes: []string{oauthproto.GrantTypeTokenExchange},
501501
}
502502
}
503+
504+
func TestNewSPIFFEAssociationRegistryReturnsNilWithoutAssociations(t *testing.T) {
505+
t.Parallel()
506+
507+
empty, err := NewSPIFFETrustConfig(nil, nil, []string{"openid"}, nil)
508+
require.NoError(t, err)
509+
require.Empty(t, empty.Associations())
510+
511+
for _, trust := range []*SPIFFETrustConfig{nil, empty} {
512+
registry, err := NewSPIFFEAssociationRegistry(trust)
513+
require.NoError(t, err)
514+
assert.Nil(t, registry)
515+
assert.Nil(t, newSPIFFEClientResolver(registry))
516+
assert.Nil(t, newSPIFFEX509ClientMatcher(registry))
517+
}
518+
}

0 commit comments

Comments
 (0)