Repository navigation
Conversation
Add the token validation of the access control redesign (D-388) as its own package, behind one interface (TokenValidator), with the implementation selected by tesk.api.auth.token-validator (only jwt for now; introspection can be added later, D-408). JwtAccessTokenValidator accepts single signed JWT access tokens (typ at+jwt) of the configured issuers (exact iss), checked against the issuer's keys from its discovery or a JWKS URI, with asymmetric algorithms only, exp, iat and sub required, nbf, max age and clock skew. User tokens need one of the issuer's audiences (front-end client IDs); listed service clients (client claim and sub both the client ID) need their own ID in aud (D-392). Users with a listed client's ID and delegated tokens (act) are refused. The caller is identified by <iss>|<sub>. Not wired into the request authentication yet. The key handling of ServiceClientTokenServices is reused in IssuerVerifier (a copy until the switch removes that class). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Explain the rules in the Javadoc instead of citing decision records, log refusals at INFO (callers without a valid token control their rate) and accepted service clients at DEBUG, use switch expressions, and note in ServiceClientTokenServices that its key handling has a copy in IssuerVerifier until it is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Requests that arrive while the keys of an issuer are fetched now wait for that fetch (bounded by the timeouts) instead of being refused, and unavailable keys raise IssuerUnavailableException (for 503) instead of InvalidTokenException (401), so that clients retry. Also: the clock skew is the whole leeway for iat in the future (jose4j adds it to the configured allowance), timeout-seconds is at most 300 (no int overflow of the milliseconds), TokenPrincipal.toString leaves out the claims (personal data), and a token of one issuer signed with another issuer's key is tested to be refused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Only the first attempt to fetch an issuer's keys makes other requests wait (at most 15 s); later attempts refuse at once, so that forged tokens of a dead issuer can't hold request threads. Keys that can't be fetched again after the cache expired are reported as unavailable (IssuerUnavailableException) instead of an invalid token. A failed fetch is logged once at WARN, refused requests at INFO. timeout-seconds is at most 60. Docs say that callers map the exceptions to 401/503. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Reviewer's GuideData structuresDefine the caller identity and validation settings that the validator depends on, including issuer, audience, client, algorithm, and token-lifetime data.
APIExpose the token-validation contract, its refusal and issuer-unavailable outcomes, and the factory that selects a validator.
ImplementationImplement JWT access-token parsing, issuer-specific signature and claim checks, caller classification, and unavailable-key handling through the issuer verifier.
Record that the existing service-client introspector has copied key-handling logic that must stay synchronized until replacement.
DocumentationDocument the token-validation design, issuer and token rules, configuration properties, and the fact that authentication does not yet use the validator.
TestsTest issuer URL security, key fetching and refresh throttling, concurrent first-use behavior, and unavailable-key signaling.
Exercise JWT acceptance and refusal rules, issuer-key isolation and outages, caller classification, and startup configuration validation.
Verify property binding and defaults, validator selection, principal identity and safe string representation, and generic error reasons.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #221 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 56 63 +7
Lines 2612 2929 +317
Branches 313 361 +48
==========================================
+ Hits 2612 2929 +317 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Adds the token validation of the access control redesign as its own package,
uk.ac.ebi.tsc.tesk.config.security.token. It is not wired into the request authentication yet: behaviour is unchanged. A later slice switches authentication to it and removesUserInfoTokenIntrospector(as authentication) andServiceClientTokenServices.TokenValidator: the only interface for token validation. It takes a bearer token and returns aTokenPrincipal, or throws anInvalidTokenExceptionwhose message gives the reason and never the token.TokenValidators.createpicks the implementation fromtesk.api.auth.token-validator. Onlyjwtexists for now. RFC 7662 introspection could be added later as a new implementation and a new value, with no changes for callers.JwtAccessTokenValidatoraccepts JWT access tokens only:issmust match a configured issuer exactly, and the token is checked only against that issuer's keys;jwks-uri(https only, http only for localhost);RS256,ES256);noneand HMAC are refused at startup;typmust beat+jwt;exp,iatandsubare required;nbf, the maximum age and the clock skew are checked.audmust contain one of the issuer'saudiences, which are the front ends' client IDs;subare both the listed ID):audmust contain the client's own ID;subequals a listed client's ID is refused;act(delegation) are refused until delegated actors are decided; that slice replaces this check.TokenPrincipal.owner()is<iss>|<sub>. There is no group model.IssuerUnavailableExceptionrather thanInvalidTokenException. Its caller is to answer 503 instead of 401, so that clients retry. Requests that arrive during the first fetch wait for it, at most 15 s. Later failed attempts refuse at once. Each failed fetch is logged once at WARN.IssuerVerifierreuses the key handling ofServiceClientTokenServices: the JWKS cache, the throttled refetch for unknown key IDs, the discovery backoff andisSecure. It is a copy until that class is removed, and both copies note that they must be kept in sync.docs/development.mdwith the settings. The settings will go intoconfiguration.mdandaccess-control.mdwhen the validator is wired in, because they have no effect before that.The audience defaults are provisional. No real LS Login user token has been checked yet for
typ,audand where the entitlements live. uniqueg will check one before this slice is final. Ifaudturns out unusable, the audience rule changes before the wiring slice.Closes #222
Verification
./mvnw clean verify(JDK 21, Dockereclipse-temurin:21-jdk): all unit and integration tests pass, and the 100% line and branch coverage check passes../mvnw spotless:check checkstyle:check: clean.mkdocs build --strict: clean.JwtAccessTokenValidatorTest(75 cases, against WireMock-served discovery and JWKS),IssuerVerifierTestandTokenValidatorsTest(binding from properties, defaults, selection).Declined review findings
Move the structural checks of the settings to Bean Validation (quality, medium). Declined: the security checks (https, asymmetric algorithms, duplicate issuers and clients, an issuer that accepts nothing) are cross-field checks and have to stay in code. Splitting the checks between annotations and code would put them in two places. All the checks are in one place now, with the property paths in their messages.
Refuse unlisted clients own tokens (
sub== client claim, client not listed), or require the client claim to be one of the audiences (adversarial, low). Declined for now: the design matrix treats an unlisted client with a valid token as an authenticated caller without the create right (row 9, 403 on create), and whetherazpcan be bound to the front ends depends on the pending LS Login user-token check.Make
IssuerVerifiershared withServiceClientTokenServicesnow instead of copying (quality, medium). Declined for this slice: it would touch the class that a parallel slice (removal of the group model) changes, and the wiring slice deletes it anyway. I added keep-in-sync notes to both copies instead.Make the thread-based
IssuerVerifiertests drive two real requests instead of setting the field by reflection (quality round 2, medium). Declined: the test exercises exactly the re-check branch, and its waits are condition-based (no timing assertions).Track the duplicate key handling and the registration of the settings in an issue (quality round 2, low). Covered by the wiring issue (see the design slice plan), which deletes
ServiceClientTokenServicesand registers and documents the settings.Open questions
allowAnyAudienceopt-in of the current service-client settings carry over into the new pipeline, or does "aud= the client's own ID" replace it? The config format (a list of objects per client) allows either without rework. This needs a decision before the wiring slice.🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5