Repository navigation
Fixes 35799: Look key ids up in the key sets in configured order - #35929
Conversation
IdentityProviderKeys cached downloaded keys by key id, so when two key sets published the same id, a download of the second set replaced the first set's key, and tokens signed with it were refused. The download also read the requested key back from the bounded cache, which a set larger than the cache could already have evicted. Each download of a set is now cached whole under the set's URL, replacing its previous download. A lookup answers from cached sets only up to the first set with no cached download. Otherwise it asks the sets in configured order from the first, downloading each one whose cached download lacks the id, so the first set that publishes the id wins, as when the sets were asked in turn. The key is read from the download itself, and a key the provider dropped stops verifying at its set's next download. A set whose download fails keeps its cached copy. One that fails with no cached copy is skipped by cached lookups until a lookup of an unknown id downloads it again, or a key lifetime passes. Otherwise an unreachable set listed first would hold requests up for its timeouts each time a resolved key expires.
The state, nonce and issuer tests passed whenever the login ended without a token and a live session, so an unrelated server error at the callback passed as a refusal. They now also require the callback's own answer: a 500 whose body names the reason. The replay test also requires the redirect to the sign-in page.
Code Review ✅ Approved🔴 High risk · Changing identity-provider key lookup and cache expiry affects JWT authentication; tokens signed with dropped keys could be rejected after the next download. Reworks the SSO identity provider key lookup so each key set's download is cached whole under its URL and sets are queried in configured order, so the first set publishing a VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
Local Java test run: PASSED — details
Tests run locally
Why these tests
Impacted, not run locally (2)
Commandsmvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=IdentityProviderKeysTest,KeySetSourceTest,MultiUrlJwkProviderTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<63 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=SessionMultiNodeIT,SsoOidcCallbackHardeningIT,SsoOidcConfidentialLoginIT,SsoOidcProviderProfilesIT,SsoOidcPublicBearerIT,SsoTokenRenewalIT,UserMetricsResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=rdf -Dit.test=RdfFusekiAuthorizationIT,RdfPolicyRevocationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=global-state -Dit.test=SessionRedisMultiNodeIT,TokenRevocationRedisMultiNodeIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false |
| .maximumWeight(MAX_CACHED_KEYS) | ||
| .weigher((String keySetUrl, Map<String, Jwk> keys) -> Math.max(1, keys.size())) |
There was a problem hiding this comment.
downloadCache cannot retain a set with more than 1,000 keys. Each uncached kid from that set needs another download. With the default budget, 11 distinct valid key lookups before a refill exhaust the budget, so the last lookup fails even though its key is published. Reading directly from the download fixes only the first lookup.
Add a bounded fallback for oversized sets and test several distinct keys after the download budget is spent.
| keys = indexById(source.fetchAll()); | ||
| downloadedSets.put(source.url(), keys); |
There was a problem hiding this comment.
Older downloads erase new keys
downloadedSets.put lets a slow, older response replace a newer key set. Different kid lookups can download the same URL together because only the budget check is synchronized. If the provider adds a key between those downloads, the older response can erase that newly cached key. A later lookup then needs another download and fails if the overlapping requests spent the budget.
Serialize downloads per URL, or prevent older downloads from replacing newer ones, and cover this order with a test.
🚦 Removed from the merge queue —
|
Describe your changes:
Fixes #35799
Follow-up to #35894. Its review threads were answered while it sat in the merge queue, which takes no new commits, so the fixes land here. Two commits:
fix(auth): look a key id up in the key sets in configured order (IdentityProviderKeys, ADR:2026-10-20-identity-provider-key-sets-are-fetched-with-timeouts-and-a-rate-limit, amended as v2)kidalone, which caused two problems:kidwith different keys, a download of the later set replaced the earlier set's key, and tokens signed with it were refused. This held even for a download a made-upkidtriggered. (Gitar; Greptile P1 "Unrelated lookups replace signing keys".)JwtFilter, six hours for MCP. The cache holds at most 1,000 keys across sets, and a key is read from the download that found it.kiddownloads it again, or a key lifetime passes. So an unreachable or hanging set listed first does not hold up the requests the cache can answer. A set that fails while it has a cached copy is not marked, because the mark would outlive the copy.test(sso): assert why the callback refused a login (Greptile P2 "Callback crashes pass refusal tests")/signin.Behaviour change to note: a key the provider drops now stops verifying at its set's next download. In #35894 it lasted a day after the last download that carried it.
Type of change:
High-level design:
Described above. The rules are recorded in the v2 amendment of the key-set ADR.
Tests:
Use cases covered
IdentityProviderKeysTest, 19 cases. The new or rewritten ones:kid: the first configured set wins after a failed download of it, after a failed download while it was cached, and after its cached copy expired before the later set's.kidrepeated in one set resolves to its first entry.Unit tests
IdentityProviderKeysTest, with theKeySetServerfixture.git diff -U0against main): 57/57 (100%).IdTokenValidatorTest, and every test in thesecurityandsocketpackages: 95 classes, 1,252 service tests and 11 MCP tests, all passing.kidalone: akidtwo sets share resolved to the second set's key.kid:kidstill resolved to the second set once the first set's download had failed, or its copy had expired first;kidresolved to the later set's key for up to a day (firstConfiguredSetWinsAfterADownloadFailedWhileItWasCached).Backend integration tests
SsoOidcCallbackHardeningIT, throughSsoFlows.assertCallbackRefused.-Pmysql-elasticsearch: 5Sso*ITclasses, 62 tests, 0 failures.JwtFilter. They run in CI on this branch and are recorded in the block below.Local Java test run: PASSED
11d9aef96342(baseorigin/main)Ingestion integration tests
Playwright (UI) tests
Manual testing performed
Not applicable: a server-side lookup change and test code, each behaviour proven by a test that fails without it.
UI screen recording:
Not applicable — no UI change.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: not applicable, no schema changes.
For a UI feature or feature task: not applicable, no UI change.
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.The review-thread fixes had five focused fresh-eyes passes. Each 🔴 they found is fixed, with a test that fails without the fix:
kidafter a failed or expired download;No 🔴 is answered instead of fixed.
Decision check:
docs/decisions/2026-10-20-identity-provider-key-sets-are-fetched-with-timeouts-and-a-rate-limit.mdgains a v2 amendment.I have added a test that covers the exact scenario we are fixing.
🤖 Generated with Claude Code
Fix the oversized-set fallback and overlapping downloads before merging.
Findings
Summary
The PR caches whole key sets by URL and looks up signing keys in configured order.
Intentional behavior recorded from
mohityadav766: dropped keys stop resolving after their set is refreshed; failed sets without cached copies may temporarily yield to later sets to avoid repeated timeout delays.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Look up key ID] --> B{Brief resolved-key cache hit?} B -->|Yes| C[Return key] B -->|No| D[Check known sets in configured order] D --> E{Cached lookup finds key?} E -->|Yes| C E -->|No| F[Ask sets in configured order] F --> G{Download allowed and successful?} G -->|Yes| H[Replace whole cached set] G -->|No| I[Use cached copy if available] H --> J{Key found?} I --> J J -->|Yes| C J -->|No| K[Try next set or refuse]Reviews (1) · Last reviewed commit: "test(sso): assert why the callback refus..." · Reviewed by Greptile