Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions docs/arch/17-token-exchange-delegation.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,28 @@ reuse IDs between the two mechanisms.

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

On Kubernetes, a delegate-client Secret is injected as a pod environment
Expand Down
2 changes: 1 addition & 1 deletion pkg/authserver/runner/embeddedauthserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,7 @@ func TestEmbeddedAuthServer_SPIFFESerializedRestartPolicy(t *testing.T) {
assert.Empty(t, trust.Associations())
registry, err := authserver.NewSPIFFEAssociationRegistry(trust)
require.NoError(t, err)
require.NotNil(t, registry)
assert.Nil(t, registry)
// Every restart uses fresh memory. The initial and changed shapes
// name listener certificate files that do not exist, so only the
// SPIFFE-removed configuration can build a full server here.
Expand Down
20 changes: 10 additions & 10 deletions pkg/authserver/server_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,10 @@ func warnBlanketSelfIssuedExchange(delegateClients []DelegateClient, jwtBearerEn

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

// newSPIFFEX509ClientMatcher returns the matcher the client-authentication
// strategy uses to select the X.509 arm, or nil when no SPIFFE trust is
// configured, like newSPIFFEClientResolver. A method value on a nil registry
// would be non-nil.
// strategy uses to select the X.509 arm, or nil when no SPIFFE trust or no
// SPIFFE association is configured, like newSPIFFEClientResolver. A method
// value on a nil registry would be non-nil.
func newSPIFFEX509ClientMatcher(registry *SPIFFEAssociationRegistry) oauthserver.SPIFFEX509ClientMatcher {
if registry == nil {
return nil
Expand Down
11 changes: 7 additions & 4 deletions pkg/authserver/spiffe_association_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ type SPIFFEAssociationRegistry struct {
}

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

associations := trust.Associations()
registry := &SPIFFEAssociationRegistry{
byPattern: make(map[string]SPIFFEClientAuthConfig, len(associations)),
byClientID: make(map[string]SPIFFEClientAuthConfig, len(associations)),
Expand Down
16 changes: 16 additions & 0 deletions pkg/authserver/spiffe_association_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,19 @@ func testSPIFFEAssociation(clientID, scope string) SPIFFEClientAuthRunConfig {
GrantTypes: []string{oauthproto.GrantTypeTokenExchange},
}
}

func TestNewSPIFFEAssociationRegistryReturnsNilWithoutAssociations(t *testing.T) {
t.Parallel()

empty, err := NewSPIFFETrustConfig(nil, nil, []string{"openid"}, nil)
require.NoError(t, err)
require.Empty(t, empty.Associations())

for _, trust := range []*SPIFFETrustConfig{nil, empty} {
registry, err := NewSPIFFEAssociationRegistry(trust)
require.NoError(t, err)
assert.Nil(t, registry)
assert.Nil(t, newSPIFFEClientResolver(registry))
assert.Nil(t, newSPIFFEX509ClientMatcher(registry))
}
}
Loading