Repository navigation
Return invalid_client for failed client assertions - #7036
Conversation
…wt assertion An expired, not-yet-valid or future-issued client assertion surfaced as a plain error (500), an assertion whose exp exceeds MaxAssertionLifespan as a plain error from SetClientAssertionJWT (500), and an unknown signing key or a reused jti as invalid_request / jti_known (400). RFC 6749 section 5.2 assigns invalid_client to every failed client authentication. Map those outcomes to invalid_client in a strategy wrapped around fosite's default one, and have both storage backends return invalid_client for an over-long lifetime. Storage failures keep surfacing as server errors. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Alex Castillo <[email protected]>
jhrozek
left a comment
There was a problem hiding this comment.
Thanks for picking this up. The remap fixes the cases from #7028 and #6995 (I checked it against fosite v0.49.0). There are a few changes needed before merge, listed below in order of importance. Each inline comment says what to change and which test should prove it.
- A Redis failure during the jti check must stay a 500 (inline on
client_assertion_errors.go:40). This is the only change that needs some design. I've sketched it there. - The integration test for the expired case must assert the status code (inline on
integration_test.go, about line 6810). - Keep a missing
client_assertionas 400 invalid_request (inline onclient_assertion_errors.go:41). - Fix the doc comment and add the two comments explaining the matching (inline).
- Docs: add this paragraph to
docs/arch/17-token-exchange-delegation.md, after "rejects replay while the assertion is valid. Noclient_secret…" (around line 344):Also add a before/after line under "Does this introduce a user-facing change?" for the storage-failure and missing-assertion cases.Every failed assertion check (unknown `kid`, bad signature, wrong `iss`, `sub` or `aud`, expired or not yet valid, `exp` more than 5 minutes ahead, reused `jti`) is refused with HTTP 401 `invalid_client`. The `error_description` names the check that failed. A storage failure while checking or recording the `jti` is HTTP 500 `server_error`, so clients can retry it. A request that sets `client_assertion_type` but omits `client_assertion` is HTTP 400 `invalid_request`.
- PR housekeeping:
- Change
Fixes #7028toPart of #7028. The issue's acceptance also includes the strict issuer-onlyaudcheck, which this PR doesn't do. - Drop the
fix(authserver):prefix from the title and the commit subject. This repo doesn't use conventional commits (CONTRIBUTING.md). Something like "Return invalid_client for failed client assertions" works. - Add one line under special notes: "Without a clock-skew margin (#6954), a client whose clock runs slightly fast now gets 401 invalid_client for a future
iatinstead of a 500."
- Change
You don't need to do #6954 (clock skew) or the strict audience check here.
…n errors Address review: a Redis failure while reserving the jti stays HTTP 500 server_error (recorded through RecordClientAssertionStoreFailure, since fosite discards the storage error), a missing client_assertion stays 400 invalid_request, the expired integration case asserts 401 invalid_client, and the matching rules and docs are explained. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Alex Castillo <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Alex Castillo <[email protected]>
|
Thanks, all points addressed in the new commit:
This comment was drafted with Claude Code. |
|
Thanks, all six review threads are addressed, I resolved them. On the strict audience question: let's leave it out of this PR. It changes which assertions are accepted, not what we return on failure, and it needs a migration option, so I'll split it out of #7028 into its own issue. That way this PR covers everything left in #7028, so please change "Part of #7028" to "Closes #7028" in the description. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7036 +/- ##
==========================================
+ Coverage 80.46% 80.50% +0.04%
==========================================
Files 852 853 +1
Lines 87035 87063 +28
==========================================
+ Hits 70030 70094 +64
+ Misses 17000 16964 -36
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The private_key_jwt invalid_client remap (#7036) merged before its lint and e2e jobs finished, and both fail on main. The virtualmcp e2e spec still expected a replayed assertion to get 400 jti_known; it now gets 401 invalid_client, as intended. gosec G101 flagged the assertion type constant because its name contained "Bearer", so it is renamed, and an unused test parameter is blanked for revive. Co-authored-by: Mecatl <[email protected]>
Failed client assertions now return 401 invalid_client (#7036), including when the kid is no longer registered. The JWKS rollout e2e spec still expected 400 invalid_request for the retired key, so it failed on every Kubernetes version. Co-authored-by: Mecatl <[email protected]>
Closes #7028
Summary
A failed
private_key_jwtclient assertion got a different answer depending on which check failed:nbfin the future, oriatin the future: 500server_error(fosite returns the claim validation error unwrapped);expbeyondMaxAssertionLifespan: 500server_error(SetClientAssertionJWTreturned a plain error, in both the memory and Redis stores);kidnot in the client's key set: 400invalid_request;jti: 400jti_known.RFC 6749 §5.2 assigns
invalid_client(401) to every failed client authentication, and clients treatserver_erroras a retryable outage. This covers the cases in #7028 and the two folded in from #6995.newClientAssertionErrorStrategy(pkg/authserver/server/client_assertion_errors.go) wraps fosite's default client authentication strategy, inside the SPIFFE dispatcher. Forjwt-bearerassertions it turns the claim validation errors,invalid_request(unknown key) andjti_knownintoinvalid_client. Other errors, such as a storage outage or a server misconfiguration, pass through unchanged and stay 500s.SetClientAssertionJWTinMemoryStorageandRedisStoragereturnsinvalid_clientwhen the lifetime exceeds the maximum.jti_knownon replay, 400 for a rotated-outkid) now expect 401invalid_client.Type of change
Test plan
task test)task test-e2e)task lint-fix)TestClientAssertionErrorStrategyruns real fosite client authentication with an ES256 client: a valid assertion still authenticates; expired, futureiat, futurenbf, reusedjti, unknownkid, wrong signing key and wrongaudall give 401invalid_client; a storage failure is returned untouched. Lifetime-limit tests were added for both storage backends.go test ./pkg/authserver/...passes; without the change the updated integration and storage tests fail.Does this introduce a user-facing change?
Yes. Every rejected
private_key_jwtclient assertion now gets 401invalid_clientfrom the token endpoint instead of 500server_error, 400invalid_requestor 400jti_known. A storage failure while checking the jti is still 500server_error; a missingclient_assertionis 400invalid_request.Special notes for reviewers
The optional strict-audience setting (issuer as the only
audvalue) from #7028 is not included here, and clock skew stays with #6954. Happy to add the strict audience in this PR or a follow-up, whichever you prefer.Without a clock-skew margin (#6954), a client whose clock runs slightly fast now gets 401
invalid_clientfor a futureiatinstead of a 500.This pull request was prepared with the assistance of an AI coding agent (Claude Code) and submitted by Alex Castillo, who is responsible for its content.