Skip to content

[CIMD]: unauthenticated creation of service-account clients from the fetched metadata document - #55214

Open
tnorimat wants to merge 1 commit into
keycloak:mainfrom
Hitachi:ISSUE-55106
Open

tnorimat wants to merge 1 commit into
keycloak:mainfrom
Hitachi:ISSUE-55106

Conversation

@tnorimat

Copy link
Copy Markdown
Contributor

closes #55106

@tnorimat
tnorimat requested a review from a team as a code owner November 16, 2026 05:57
Copilot AI balanced review requested due to automatic review settings November 16, 2026 05:57
@tnorimat

Copy link
Copy Markdown
Contributor Author

Previously, the grant_types of a fetched Client ID Metadata Document were applied in full, so an unauthenticated request could register a client with client_credentials (service account), CIBA, device authorization, token exchange, JWT authorization grant or UMA enabled.

The client-id-metadata-document executor now has an Allowed grant types option (cimd-allowed-grant-types). Grant types not in the list are removed from the metadata on both registration and refresh. If the list is empty, only authorization_code and refresh_token are allowed, so these grants can no longer be enabled from the document unless an administrator explicitly allows them.

Grants that are not allowed are removed instead of rejected, consistent with the existing Accept Public Client with Confidential-only Grant Types option, so clients that declare extra grants (e.g. Claude Desktop) keep working.

New tests in ClientIdMetadataDocumentTest cover the reported scenario, including a re-fetch and a rejected client_credentials request, and an explicitly configured allow list. The MCP guide describes the new option.

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

Critical grant restrictions remain bypassable because refreshes can retain disallowed service accounts and response-type conversion can enable flows excluded by the allow list.

2 open issues
What changed in this PR

This PR addresses #55106 by adding a configurable grant-type allow list to CIMD client registration and refresh, limiting capabilities enabled by unauthenticated metadata documents.

Changes:

  • Default allowed grants to authorization_code and refresh_token, filtering other requested grants.
  • Add tests for default restrictions, metadata refresh, service-account denial, and explicit administrator overrides.
  • Document the configuration and risks of allowing additional grants.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​client/​policies/​ClientIdMetadataDocumentTest.java Tests default restrictions and configured grant allowances.
services/​src/​main/​java/​org/​keycloak/​protocol/​oauth2/​cimd/​clientpolicy/​executor/​AbstractClientIdMetadataDocumentExecutorFactory.java Exposes the allowed-grant-types configuration and help text.
services/​src/​main/​java/​org/​keycloak/​protocol/​oauth2/​cimd/​clientpolicy/​executor/​AbstractClientIdMetadataDocumentExecutor.java Adds allow-list configuration and metadata grant filtering.
docs/​guides/​securing-apps/​mcp-authz-server.adoc Documents defaults and cautions for additional grants.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 06:18

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

A 304 refresh can let existing clients retain disallowed grants indefinitely, and re-allowing UMA does not restore authorization services without re-registering the client.

2 open issues
2 resolved since last review

Review effort: Balanced

…fetched metadata document

closes keycloak#55106

Signed-off-by: Takashi Norimatsu <takashi.norimatsu.ws@hitachi.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 06:49

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

Existing CIMD service-account clients can still obtain tokens directly after client_credentials is disallowed because token requests do not enforce the current allow list, and rejected metadata refreshes can bypass cleanup.

1 open issue
2 resolved since last review

Review effort: Balanced

enforceResourceIndicator(preAuthorizationRequestContext, session.getContext().getRealm().getClientByClientId(clientId));
// no update, but the allowed grant types and the resource parameter still need to be enforced on every authorization request.
ClientModel clientModel = session.getContext().getRealm().getClientByClientId(clientId);
provider.restrictGrantTypes(clientModel, getAllowedGrantTypes());

@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.cluster.ClientInvalidationClusterTest#crudWithoutFailover

Keycloak CI - Clustering IT

org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
...

Report flaky test

org.keycloak.testsuite.cluster.ClientInvalidationClusterTest#crudWithFailover

Keycloak CI - Clustering IT

jakarta.ws.rs.WebApplicationException: Create method returned status Forbidden (Code: 403); expected status: Created (201). Response body: {"error":"HTTP 403 Forbidden"}
	at org.keycloak.testsuite.admin.ApiUtil.getCreatedId(ApiUtil.java:38)
	at org.keycloak.testsuite.cluster.ClientInvalidationClusterTest.createEntity(ClientInvalidationClusterTest.java:54)
	at org.keycloak.testsuite.cluster.ClientInvalidationClusterTest.createEntity(ClientInvalidationClusterTest.java:21)
	at org.keycloak.testsuite.cluster.AbstractInvalidationClusterTest.createEntityOnCurrentFailNode(AbstractInvalidationClusterTest.java:111)
...

Report flaky test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CIMD]: unauthenticated creation of service-account clients from the fetched metadata document

2 participants