Skip to content

Let delegate clients change policy on restart - #6918

Merged
jhrozek merged 1 commit into
mainfrom
configured-client-reconcile
Oct 22, 2026
Merged

jhrozek merged 1 commit into
mainfrom
configured-client-reconcile

Conversation

@jhrozek

@jhrozek jhrozek commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Since #6473 (v0.47.0), changing a delegate client's scopes or audiences on Redis storage fails startup with client "<id>" is already registered as a different configured client. In Kubernetes the new pod never becomes Ready and the rollout stays stuck until someone deletes the Redis row by hand. Before #6473, delegates were written with an unconditional SET, so this is a regression. The strict check came from the #6473 review for SPIFFE placeholders. Delegate clients were never discussed there and picked it up as a side effect. The configured broker clients in #6893 need this fixed first, because their grants change routinely.

  • ReconcileConfiguredClient now decides by client kind, through one shared function, configuredClientConflict in pkg/authserver/storage/types.go, used by both the memory and Redis backends:
    • A DCR-issued row is still never overwritten.
    • A SPIFFE placeholder and a non-placeholder client never replace each other, in either direction.
    • Two SPIFFE placeholders must still match in full, unchanged from Normalize canonical inbound grants #6473.
    • Two non-placeholder (delegate) clients replace each other. The one refusal is a flip between public and confidential.
  • A replace that changes scopes or audiences logs a WARN, configured client replaced with a different policy, with client_id and the old and new values. Secrets are never logged.
  • fingerprintOfClient now reads resources and SPIFFE identity only for reserved placeholders, matching what the Redis backend stores, so both backends compare the same inputs.
  • Docs: docs/arch/11-auth-server-storage.md gets a new "Configured clients across restarts" section. 17-token-exchange-delegation.md, 18-spiffe-association-declarations.md and docs/redis-storage.md are updated to match.

Fixes #6906

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)

  • E2E tests (task test-e2e)

  • Linting (task lint)

  • Manual testing (describe below)

  • Unit tests: a shared table runs the conflict rules against both backends (memory and miniredis). There are also Redis-only cases:

    • a replace clears the TTL and removes the ID from the DCR cap index;
    • legacy rows;
    • an empty-identity placeholder;
    • a WATCH abort that is retried;
    • the WARN fires once across a retry.
  • In-process integration test: TestConfiguredDelegateClientPolicyChangeAcrossRestarts restarts a real embedded auth server against one shared miniredis. It checks that:

    • a scope change takes effect and is enforced on token exchange;
    • an unchanged restart logs no policy WARN;
    • a changed SPIFFE association still fails startup.
  • Kind e2e: virtualmcp_delegate_clients_redis_test.go edits a delegate's scopes on a Redis-backed VirtualMCPServer. It waits for the rollout and checks that the new scopes are enforced. It runs in CI's operator e2e job. It was not run locally; it compiles (task lint runs go vet over it).

Changes

File Change
pkg/authserver/storage/types.go configuredClientConflict, policyChanged, warnConfiguredClientReplaced; reserved field on clientFingerprint; fingerprintOfClient reads resources and identity only for placeholders; contract doc
pkg/authserver/storage/memory.go Uses the shared decision; logs the WARN after releasing the lock
pkg/authserver/storage/redis.go Uses the shared decision inside WATCH/MULTI; logs the WARN once, after a successful EXEC
pkg/authserver/storage/spiffe_decorator.go Comment only
pkg/authserver/storage/*_test.go Shared table for both backends, Redis-specific cases, decorator cases, fingerprint field cases
pkg/authserver/delegate_client_restart_integration_test.go New in-process restart test against a shared miniredis
test/e2e/thv-operator/virtualmcp/virtualmcp_delegate_clients_redis_test.go New kind e2e for the rollout
docs/arch/11-*.md, 17-*.md, 18-*.md, docs/redis-storage.md Behavior, rolling updates, rollback, removed delegates

Does this introduce a user-facing change?

Yes.

  • Before (v0.47.0 and later): changing a delegate client's scopes or audiences on Redis storage failed startup with "already registered as a different configured client". The new pod never became Ready.
  • After: the change takes effect on restart. The server logs a WARN with the client ID and the old and new scopes and audiences.

Unchanged:

The memory backend was never affected.

Special notes for reviewers

  • Deliberate deviation: SPIFFE placeholders keep the strict check. In the Normalize canonical inbound grants #6473 review (2026-09-04), @JAORMX asked for the policy to be part of the placeholder fingerprint, to block rolling policy changes:

    "Two replicas using the same SPIFFE client ID/scopes/audiences but different RFC 8707 resources therefore reconcile as identical during a rolling policy change, while their in-process clients authorize different resource sets."

    SPIFFE clients are served from each replica's own config, so the strict check still makes sense there. Delegate clients are served from the shared Redis row, so the same check only blocks the rollout. The SPIFFE edit problem is tracked separately in Editing a SPIFFE client association on Redis storage leaves the new pod never ready #6907.

  • Accepted trade-off: rolling updates on Redis. The delegate row is shared and read on every token request.

    • A replica that restarts with an older config writes its old policy back. That policy stays until any replica next restarts.
    • So narrowing a delegate is not a reliable revocation until every replica runs the new config and no old-config pod restarts.
    • Scopes, and audiences requested with the audience parameter, come from the shared row alone. A resource parameter and the default audience are still checked against each replica's own allowedAudiences.
    • Secret rotation already behaves this way.
    • The details are in the new "Configured clients across restarts" section of docs/arch/11-auth-server-storage.md.
  • Rollback. An older binary (v0.47.0 or later) fails startup against a row this change replaced with a different policy. To roll back across a delegate policy edit, do one of these:

    1. Roll out the old policy on the new binary first, then roll back the binary.
    2. Delete the row just before the rollback.

    No new stored field was added, so older binaries can still read the rows. This is documented in the same section.

  • Grant types are not compared for delegate clients, and a grant change doesn't trigger the WARN. Delegate grants are fixed in code today. If they become configurable (Stable pre-provisioned broker client for token exchange and ID-JAG redemption #6893), revisit policyChanged.

  • Known limits, not fixed here:

  • Existing tests whose expectations changed:

    • TestMemoryStorage_ReconcileConfiguredClient and TestRedisStorage_ReconcileConfiguredClient: the "refuses a different configured client at the same ID" subtests are removed. The shared table covers replacement now.
    • TestSPIFFEStorageDecoratorRejectsDifferentConfiguredClientCollision: the comment is corrected. It seeds a non-placeholder client and now fails on the kind check.
    • The five SPIFFE tests that assert the "different configured client" substring are unchanged.
Approved implementation plan (decided design)

In ReconcileConfiguredClient, on both backends, when an existing row is found:

  1. A DCR-issued row is refused, unchanged. This check stays in each backend, because Redis needs clientFromStored's legacy-row handling.
  2. A kind mismatch (reserved placeholder against a non-reserved configured client), in either direction, is refused.
  3. If both are reserved, they must match in full, unchanged. A mismatch is refused.
  4. If both are non-reserved, the row is refused when public differs. A confidential-to-public flip would let refresh tokens issued to a confidential client be used without a secret. Otherwise the row is replaced: TTL 0 and ZRem from the DCR cap index, as today.
  5. When rule 4 replaces a row whose policy differs, it logs slog.Warn with client_id and the old and new scopes and audiences. The secret is never logged.

Symmetry fix: fingerprintOfClient reads resources and identity only when isReservedPlaceholder(c), matching buildStoredClient. There is no new stored field and no migration.

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Oct 22, 2026
Since #6473 (v0.47.0), changing a delegate client's scopes or
audiences on Redis failed startup with "already registered as a
different configured client". In Kubernetes the new pod never became
ready and the rollout stuck until someone deleted the Redis row by
hand. Before #6473, delegates were registered with an unconditional
write, so this is a regression.

ReconcileConfiguredClient now decides by client kind. A delegate
client replaces its stored row, unless the public/confidential class
flips, and a scope or audience change logs a WARN with the old and
new values. SPIFFE placeholders keep the strict fingerprint check, as
the #6473 review required, and a placeholder and a non-placeholder
never replace each other. Both backends share one decision function.

fingerprintOfClient now reads resources and identity only for
reserved placeholders, matching what the Redis backend stores.

On Redis the row is shared, so the last replica to start wins. During
a rollout with two configs, replicas can serve either policy, and
narrowing a delegate is not a reliable revocation until no old-config
pod restarts. An older binary (v0.47.0 or later) fails to start
against a row this change replaced with a different policy, so a
rollback needs the old policy written back first, or the row deleted.

Adds unit tests for both backends, an in-process restart test against
a shared Redis, and a kind e2e for the rollout (not yet run). Updates
the auth server storage, SPIFFE and Redis storage docs.

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the configured-client-reconcile branch from 9e86bc1 to c3cd8ee Compare October 22, 2026 11:43
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Oct 22, 2026
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.86%. Comparing base (d90a504) to head (c3cd8ee).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6918      +/-   ##
==========================================
+ Coverage   79.79%   79.86%   +0.06%     
==========================================
  Files         828      828              
  Lines       84632    84668      +36     
==========================================
+ Hits        67534    67616      +82     
+ Misses      17093    17047      -46     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhrozek
jhrozek marked this pull request as ready for review October 22, 2026 12:51
@jhrozek
jhrozek merged commit 0ea83e0 into main Oct 22, 2026
47 of 48 checks passed
@jhrozek
jhrozek deleted the configured-client-reconcile branch October 22, 2026 16:00
@jhrozek jhrozek mentioned this pull request Oct 27, 2026
3 tasks done
jhrozek added a commit that referenced this pull request Oct 28, 2026
Delegate clients could only be secret-authenticated, token-exchange-only
clients. Issue #6893 needs a pre-provisioned broker that keeps its
client_id across key rotation, so the config now accepts an auth method,
a JWKS file, grant types and redirect URIs.

One validator in the registration package checks these fields and shares
the DCR private_key_jwt key check. It runs on RunConfig (keys not yet
loaded), on the resolved Config (keys loaded) before any client is
registered, and when the client is built. Redirect URIs follow the
confidential-client rule: https, not loopback. refresh_token requires
authorization_code, as in DCR. The constructor keeps today's bare client
for default inputs and never marks the result as DCR-issued.

Every delegate client still counts as confidential for the
cleartext-transport check, private_key_jwt ones included. They send no
reusable secret, but unlike token-exchange-only DCR private_key_jwt
clients they can hold authorization_code and refresh_token, so codes and
tokens would cross plain HTTP. This matches the CRD rules and can be
relaxed later if an in-cluster HTTP issuer is needed. The transport
errors now name both triggers instead of only confidential registration.

Replacing a configured client now also logs the WARN from #6918 when its
grant types, redirect URIs or auth method change. A JWKS change is key
rotation and stays silent.

The runner does not load the JWKS file or pass the new fields yet; the
next change in the stack wires them, and the two are meant to land
together.

Co-authored-by: Mecatl <[email protected]>
jhrozek added a commit that referenced this pull request Oct 28, 2026
Delegate clients could only be secret-authenticated, token-exchange-only
clients. Issue #6893 needs a pre-provisioned broker that keeps its
client_id across key rotation, so the config now accepts an auth method,
a JWKS file, grant types and redirect URIs.

One validator in the registration package checks these fields and shares
the DCR private_key_jwt key check. It runs on RunConfig (keys not yet
loaded), on the resolved Config (keys loaded) before any client is
registered, and when the client is built. Redirect URIs follow the
confidential-client rule: https, not loopback. refresh_token requires
authorization_code, as in DCR. The constructor keeps today's bare client
for default inputs and never marks the result as DCR-issued.

Every delegate client still counts as confidential for the
cleartext-transport check, private_key_jwt ones included. They send no
reusable secret, but unlike token-exchange-only DCR private_key_jwt
clients they can hold authorization_code and refresh_token, so codes and
tokens would cross plain HTTP. This matches the CRD rules and can be
relaxed later if an in-cluster HTTP issuer is needed. The transport
errors now name both triggers instead of only confidential registration.

Replacing a configured client now also logs the WARN from #6918 when its
grant types, redirect URIs or auth method change. A JWKS change is key
rotation and stays silent.

The runner does not load the JWKS file or pass the new fields yet; the
next change in the stack wires them, and the two are meant to land
together.

Co-authored-by: Mecatl <[email protected]>
jhrozek added a commit that referenced this pull request Oct 28, 2026
Delegate clients could only be secret-authenticated, token-exchange-only
clients. Issue #6893 needs a pre-provisioned broker that keeps its
client_id across key rotation, so the config now accepts an auth method,
a JWKS file, grant types and redirect URIs.

One validator in the registration package checks these fields and shares
the DCR private_key_jwt key check. It runs on RunConfig (keys not yet
loaded), on the resolved Config (keys loaded) before any client is
registered, and when the client is built. Redirect URIs follow the
confidential-client rule: https, not loopback. refresh_token requires
authorization_code, as in DCR. The constructor keeps today's bare client
for default inputs and never marks the result as DCR-issued.

Every delegate client still counts as confidential for the
cleartext-transport check, private_key_jwt ones included. They send no
reusable secret, but unlike token-exchange-only DCR private_key_jwt
clients they can hold authorization_code and refresh_token, so codes and
tokens would cross plain HTTP. This matches the CRD rules and can be
relaxed later if an in-cluster HTTP issuer is needed. The transport
errors now name both triggers instead of only confidential registration.

Replacing a configured client now also logs the WARN from #6918 when its
grant types, redirect URIs or auth method change. A JWKS change is key
rotation and stays silent.

The runner does not load the JWKS file or pass the new fields yet; the
next change in the stack wires them, and the two are meant to land
together.

Co-authored-by: Mecatl <[email protected]>
jhrozek added a commit that referenced this pull request Oct 28, 2026
Delegate clients could only be secret-authenticated, token-exchange-only
clients. Issue #6893 needs a pre-provisioned broker that keeps its
client_id across key rotation, so the config now accepts an auth method,
a JWKS file, grant types and redirect URIs.

One validator in the registration package checks these fields and shares
the DCR private_key_jwt key check. It runs on RunConfig (keys not yet
loaded), on the resolved Config (keys loaded) before any client is
registered, and when the client is built. Redirect URIs follow the
confidential-client rule: https, not loopback. refresh_token requires
authorization_code, as in DCR. The constructor keeps today's bare client
for default inputs and never marks the result as DCR-issued.

Every delegate client still counts as confidential for the
cleartext-transport check, private_key_jwt ones included. They send no
reusable secret, but unlike token-exchange-only DCR private_key_jwt
clients they can hold authorization_code and refresh_token, so codes and
tokens would cross plain HTTP. This matches the CRD rules and can be
relaxed later if an in-cluster HTTP issuer is needed. The transport
errors now name both triggers instead of only confidential registration.

Replacing a configured client now also logs the WARN from #6918 when its
grant types, redirect URIs or auth method change. A JWKS change is key
rotation and stays silent.

The runner does not load the JWKS file or pass the new fields yet; the
next change in the stack wires them, and the two are meant to land
together.

Co-authored-by: Mecatl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing a delegate client's scopes or audiences on Redis storage fails startup

2 participants