8000 Cache federated-identity/service-account queries for already-managed users by sguilhen · Pull Request #55240 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Cache federated-identity/service-account queries for already-managed users - #55240

Merged
pedroigor merged 2 commits into
keycloak:mainfrom
sguilhen:55237-usercache-federated-serviceaccount
Nov 27, 2026
Merged

pedroigor merged 2 commits into
keycloak:mainfrom
sguilhen:55237-usercache-federated-serviceaccount

Conversation

@sguilhen
@sguilhen sguilhen commented Nov 16, 2026 •
Copy link
Copy Markdown
Contributor

Closes #55237

@sguilhen
sguilhen requested review from a team as code owners 8000 November 16, 2026 17:35
Copilot AI balanced review requested due to automatic review settings November 16, 2026 17:35
@sguilhen
sguilhen force-pushed the 55237-usercache-federated-serviceaccount branch from 16c387a to 21d8613 Compare November 16, 2026 17:38
Copilot AI left a comment
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.

🟡 Changes recommended

The test can pass with the old early return because the client representation request prepopulates the username query, preventing it from exercising the intended managed-user cache-miss path.

1 open issue
What changed in this PR

Extends the username/email caching fix from #54646 to federated-identity and service-account lookups, addressing #55237 when users are already managed in the session.

Changes:

  • Caches both lookup queries on eligible managed-user paths, preserving revision and lifespan handling.
  • Adds realm checks and a service-account client-link check.
  • Adds integration tests that inspect cache entries after sequential user lookups.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​model/​UserCacheManagedUserQueryTest.java Adds managed-user query-caching tests for both lookup types.
model/​infinispan/​src/​main/​java/​org/​keycloak/​models/​cache/​infinispan/​UserCacheSession.java Stores eligible lookup queries before returning already-managed users.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 17:38
Copilot AI left a comment
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.

🔵 Needs a closer look

The regression test setup prepopulates the username query cache, so the lookup takes the cache-hit path and passes without the production fix rather than exercising the intended managed-user cache-miss branch.

1 open issue

Review effort: Balanced

@sguilhen
sguilhen force-pushed the 55237-usercache-federated-serviceaccount branch from 21d8613 to d1973ad Compare November 16, 2026 17:45
Copilot AI balanced review requested due to automatic review settings November 16, 2026 17:45
Copilot AI left a comment
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.

🟢 Approval recommended

No active review issues remain for the federated-identity and service-account query-caching changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.broker.KcSamlBrokerTest#loginClientWithDotsInName

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

@sguilhen
sguilhen force-pushed the 55237-usercache-federated-serviceaccount branch from d1973ad to 689954d Compare November 25, 2026 19:19
Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:19
Copilot AI left a comment
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.

🟡 Changes recommended

Token-only federated identity updates unnecessarily evict the reverse-lookup cache, forcing subsequent broker logins to query the delegate even though the provider/user-ID mapping is unchanged.

1 open issue

Review effort: Balanced

…users

Closes keycloak#55237

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
@sguilhen
sguilhen force-pushed the 55237-usercache-federated-serviceaccount branch from 689954d to 58bf5e1 Compare November 26, 2026 11:45
Copilot AI balanced review requested due to automatic review settings November 26, 2026 11:45
Copilot AI left a comment
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.

🟢 Approval recommended

No active review issues were identified for the managed-user lookup caching changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@stianst stianst added the kind/bug Categorizes a PR related to a bug label Nov 27, 2026
…s broker user id changes

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 16:07
Copilot AI left a comment
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.

🟢 Approval recommended

No active review issues block the managed-user lookup caching and federated-identity invalidation changes.

No open issues 🎉

Review effort: Balanced

@pedroigor
pedroigor merged commit b3ffffb into keycloak:main Nov 27, 2026
97 checks passed
ahus1 pushed a commit to ahus1/keycloak that referenced this pull request Dec 2, 2026
…users (keycloak#55240)

* Cache federated-identity/service-account queries for already-managed users

Closes keycloak#55237

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>

* Invalidate old and new reverse lookup keys when a federated identity's broker user id changes

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>

---------

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky-test kind/bug Categorizes a PR related to a bug team/core-iam

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UserCacheSession.getUserByFederatedIdentity() and getServiceAccount() have the same managed-user early return as #54645

4 participants

0