Skip to content

Fixes 35799: Look key ids up in the key sets in configured order - #35929

Merged
karanh37 merged 2 commits into
mainfrom
feature/sso-key-set-lookup-order
Oct 23, 2026
Merged

karanh37 merged 2 commits into
mainfrom
feature/sso-key-set-lookup-order

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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)

  • The flaws: Fixes 35799: Integration tests that sign in through mock identity providers #35894's cache held keys by kid alone, which caused two problems:
    • When two key sets published the same kid with 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-up kid triggered. (Gitar; Greptile P1 "Unrelated lookups replace signing keys".)
    • A download read the requested key back from the 100-key cache, which a large set could already have evicted. (Greptile P1 "Published keys can get rejected".)
  • Now:
    • Each download of a set is cached whole under its URL and replaces the set's previous download. It lives as long as before: a day for 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.
    • Sets are asked in configured order, so the first set that publishes an id wins, as it did before Fixes 35799: Integration tests that sign in through mock identity providers #35894:
      • cached downloads answer only up to the first set with no cached download;
      • otherwise the sets are asked in order from the first: a set whose cached download holds the id answers, and every other set is downloaded, because the id may have just been rotated into it.
    • A set whose download fails (an error, a timeout, or an answer with no keys) keeps its cached copy. A set that fails with no cached copy is skipped by cached lookups until a lookup of an unknown kid downloads 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")

  • The state, nonce and issuer tests now also require the callback's own answer: a 500 whose body names the reason.
  • The replay test requires the redirect to /signin.
  • An unrelated server error now fails each of them.

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:

  • Bug fix

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:

  • Shared 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.
  • Cached copies: a later set's cached copy answers when the earlier set is downloaded again.
  • Dropped keys: a key stops verifying at its set's next download, and a set is downloaded again after its lifetime.
  • Large sets: a set larger than the cache still verifies, and a set of 300 keys stays cached whole.
  • Failing sets:
    • a failing set and a hanging set are not asked again by lookups the cache answers;
    • an answer with no keys keeps the cached keys;
    • a kid repeated in one set resolves to its first entry.

Unit tests

  • I added unit tests for the new/changed logic: IdentityProviderKeysTest, with the KeySetServer fixture.
  • Coverage of changed production lines by unit tests (jacoco 0.8.10, joined with git diff -U0 against main): 57/57 (100%).
  • Unit runs on the final code, in one run: the planner's 3 classes, MCP's IdTokenValidatorTest, and every test in the security and socket packages: 95 classes, 1,252 service tests and 11 MCP tests, all passing.
  • RED proof, each new test against the code before its fix:
    • Keys cached by kid alone: a kid two sets share resolved to the second set's key.
    • Keys cached per set and kid:
      • the shared kid still resolved to the second set once the first set's download had failed, or its copy had expired first;
      • a dropped key kept verifying after newer downloads no longer carried it;
      • the first key of a 1,001-key set was refused.
    • No failure mark: ten lookups a minute apart downloaded the provider's set ten times instead of once.
    • A five-minute mark: a hanging first set was asked again every five minutes, holding requests up for its timeouts.
    • Marking a set that still had a cached copy: after that copy expired, a shared kid resolved to the later set's key for up to a day (firstConfiguredSetWinsAfterADownloadFailedWhileItWasCached).

Backend integration tests

  • Changed ITs: SsoOidcCallbackHardeningIT, through SsoFlows.assertCallbackRefused.
  • Local run on the final commit, global-state lane, -Pmysql-elasticsearch: 5 Sso*IT classes, 62 tests, 0 failures.
  • The planner selects 74 ITs, everything that authenticates through JwtFilter. They run in CI on this branch and are recorded in the block below.

Local Java test run: PASSED

  • Commit: 11d9aef96342 (base origin/main)
  • Finished: 2026-10-22 16:35 UTC · 1.3 min
  • Details: the classes each step ran, why these tests, the commands
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (3 classes) 3 29 0 0 1.3 passed
integration mysql-elasticsearch · parallel passed in CI
integration mysql-elasticsearch · isolated passed in CI
integration mysql-elasticsearch · rdf passed in CI
integration cache-tests · isolated passed in CI
  • Impacted, not run locally: 2 classes (listed in the details)

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

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 (the pr-checklist skill 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:

    • the first set lost a shared kid after a failed or expired download;
    • a failing set listed first was downloaded again on every lookup;
    • a hanging set listed first held requests up every five minutes;
    • a failure recorded while a set was cached outlived that copy. The last pass proposed this fix and checked it against the new test.

    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.md gains a v2 amendment.

  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 3/5

Fix the oversized-set fallback and overlapping downloads before merging.

Findings

  1. P1 Published keys get refused ▶
  2. P1 Older downloads erase new keys ▶

Summary

The PR caches whole key sets by URL and looks up signing keys in configured order.

  • Token checks use the first matching key set in configured order.
  • OIDC callback tests check the reason for each refusal.

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]
Loading

Reviews (1) · Last reviewed commit: "test(sso): assert why the callback refus..." · Reviewed by Greptile

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.
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 22, 2026
@gitar-bot

gitar-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
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 kid wins. Failed or hanging sets keep their cached copy or are skipped until re-downloaded, and callback tests now assert the refusal reason. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@mohityadav766

Copy link
Copy Markdown
Member Author

Local Java test run: PASSED — details

  • Commit: 11d9aef96342 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (3 classes): IdentityProviderKeysTest (19 passed), KeySetSourceTest (1 passed), MultiUrlJwkProviderTest (9 passed)
  • integration · mysql-elasticsearch · parallel: every lane class, in this CI run
  • integration · mysql-elasticsearch · isolated: every lane class, in this CI run
  • integration · mysql-elasticsearch · rdf: every lane class, in this CI run
  • integration · cache-tests · isolated: every lane class, in this CI run
Why these tests
  • area it-harness ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/sso/SsoFlows.java
  • area security ← openmetadata-service/src/main/java/org/openmetadata/service/security/IdentityProviderKeys.java, openmetadata-service/src/main/java/org/openmetadata/service/security/KeySetSource.java
  • changed test ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/SsoOidcCallbackHardeningIT.java, openmetadata-service/src/test/java/org/openmetadata/service/security/IdentityProviderKeysTest.java
  • smoke ← code other than a test class changed
Impacted, not run locally (2)
  • GoogleSsoSignInUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
  • GoogleSsoBootstrapUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
Commands
mvn -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

@mohityadav766
mohityadav766 marked this pull request as ready for review October 22, 2026 16:35
@mohityadav766
mohityadav766 requested a review from a team as a code owner October 22, 2026 16:35
Comment on lines +144 to +145
.maximumWeight(MAX_CACHED_KEYS)
.weigher((String keySetUrl, Map<String, Jwk> keys) -> Math.max(1, keys.size()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Published keys get refused

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.

Comment on lines +201 to +202
keys = indexById(source.fetchAll());
downloadedSets.put(source.url(), keys);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

@mohityadav766 mohityadav766 self-assigned this Oct 22, 2026
@mohityadav766
mohityadav766 added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-23T09:02:28Z)

Blocked the queue: playwright-summary

Failed Playwright tests:

  • Features/Glossary/LargeGlossaryPerformance.spec.ts › should handle large number of glossary terms with pagination

@karanh37
karanh37 added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 916a04f Oct 23, 2026
186 of 189 checks passed
@karanh37
karanh37 deleted the feature/sso-key-set-lookup-order branch October 23, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration tests that sign in through mock identity providers

3 participants