ClientUpdaterSourceGroupsCondition and ClientUpdaterSourceRolesCondition prevent usage of CIMD - #52601
Open
reda-alaoui wants to merge 1 commit into
Open
ClientUpdaterSourceGroupsCondition and ClientUpdaterSourceRolesCondition prevent usage of CIMD#52601reda-alaoui wants to merge 1 commit into
reda-alaoui wants to merge 1 commit into
Conversation
…ion prevent usage of CIMD Closes keycloak#52152 Signed-off-by: Réda Housni Alaoui <reda-alaoui@hey.com>
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Fixes Keycloak issue #52152 where configuring ClientUpdaterSourceGroupsCondition / ClientUpdaterSourceRolesCondition could break Client ID Metadata Document (CIMD) create/update flows by throwing on non-CRUD contexts.
Changes:
- Update source-groups/roles client policy conditions to avoid throwing on unexpected context types.
- Add CIMD create/update regression tests covering both groups and roles conditions.
- Generalize the redirect-uris policy helper to support a configurable condition provider/config.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/base/src/test/java/org/keycloak/tests/client/policies/ClientIdMetadataDocumentTest.java | Adds regression tests for CIMD with updater-source conditions and extends a policy helper to accept a pluggable condition. |
| services/src/main/java/org/keycloak/services/clientpolicy/condition/ClientUpdaterSourceRolesCondition.java | Avoids throwing ClientPolicyException on unsupported context types by returning a vote instead. |
| services/src/main/java/org/keycloak/services/clientpolicy/condition/ClientUpdaterSourceGroupsCondition.java | Avoids throwing ClientPolicyException on unsupported context types by returning a vote instead. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return getVoteForGroupsMatched(((ClientCRUDContext)context).getToken()); | ||
| } else { | ||
| throw new ClientPolicyException(OAuthErrorException.SERVER_ERROR, "unexpected context type."); | ||
| return ClientPolicyVote.NO; |
| return getVoteForRolesMatched(((ClientCRUDContext)context).getToken()); | ||
| } else { | ||
| throw new ClientPolicyException(OAuthErrorException.SERVER_ERROR, "unexpected context type."); | ||
| return ClientPolicyVote.NO; |
Comment on lines
+463
to
+539
| @Test | ||
| public void testClientUpdaterSourceGroupsConditionOnCimdCreateAndUpdate() throws Exception { | ||
| // https://github.com/keycloak/keycloak/issues/52152 | ||
| ClientIdUriSchemeCondition.Configuration conditionConfig = createDefaultConditionConfig(); | ||
| ClientIdMetadataDocumentExecutor.Configuration executorConfig = createDefaultExecutorConfig(); | ||
|
|
||
| SecureRedirectUrisEnforcerExecutor.Configuration redirectUrisConfig = new SecureRedirectUrisEnforcerExecutor.Configuration(); | ||
| redirectUrisConfig.setAllowHttpScheme(false); | ||
| redirectUrisConfig.setAllowIPv4LoopbackAddress(true); | ||
|
|
||
| ClientUpdaterSourceGroupsCondition.Configuration updaterSourceConditionConfig = new ClientUpdaterSourceGroupsCondition.Configuration(); | ||
| updaterSourceConditionConfig.setGroups(List.of("topGroup")); | ||
|
|
||
| updateCimdAndSecureRedirectUrisPolicy(conditionConfig, executorConfig, redirectUrisConfig, | ||
| ClientUpdaterSourceGroupsConditionFactory.PROVIDER_ID, updaterSourceConditionConfig); | ||
|
|
||
| setCimdPublicClient(); | ||
| String code = loginUserAndGetCode(true); | ||
| AccessTokenResponse tokenResponse = oauth.client(CLIENT_ID).accessTokenRequest(code).send(); | ||
| Assertions.assertEquals(200, tokenResponse.getStatusCode()); | ||
|
|
||
| ClientRepresentation clientRepresentation = findByClientIdByAdmin(); | ||
| Assertions.assertTrue(clientRepresentation.isPublicClient()); | ||
|
|
||
| logout(tokenResponse.getIdToken()); | ||
|
|
||
| timeOffSet.set(CIMD_EXECUTOR_MIN_CACHE_TIME_SEC + 3); | ||
|
|
||
| cimd.getRepresentation().setLogoUri("http://localhost:8500/logo2.png"); | ||
| code = loginUserAndGetCode(false); | ||
| tokenResponse = oauth.client(CLIENT_ID).accessTokenRequest(code).send(); | ||
| Assertions.assertEquals(200, tokenResponse.getStatusCode()); | ||
|
|
||
| clientRepresentation = findByClientIdByAdmin(); | ||
| Assertions.assertEquals("http://localhost:8500/logo2.png", clientRepresentation.getAttributes().get("logoUri")); | ||
|
|
||
| logoutAndDelete(clientRepresentation.getId(), tokenResponse.getIdToken()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testClientUpdaterSourceRolesConditionOnCimdCreateAndUpdate() throws Exception { | ||
| // https://github.com/keycloak/keycloak/issues/52152 | ||
| ClientIdUriSchemeCondition.Configuration conditionConfig = createDefaultConditionConfig(); | ||
| ClientIdMetadataDocumentExecutor.Configuration executorConfig = createDefaultExecutorConfig(); | ||
|
|
||
| SecureRedirectUrisEnforcerExecutor.Configuration redirectUrisConfig = new SecureRedirectUrisEnforcerExecutor.Configuration(); | ||
| redirectUrisConfig.setAllowHttpScheme(false); | ||
| redirectUrisConfig.setAllowIPv4LoopbackAddress(true); | ||
|
|
||
| ClientUpdaterSourceRolesCondition.Configuration updaterSourceConditionConfig = new ClientUpdaterSourceRolesCondition.Configuration(); | ||
| updaterSourceConditionConfig.setRoles(List.of("admin")); | ||
|
|
||
| updateCimdAndSecureRedirectUrisPolicy(conditionConfig, executorConfig, redirectUrisConfig, | ||
| ClientUpdaterSourceRolesConditionFactory.PROVIDER_ID, updaterSourceConditionConfig); | ||
|
|
||
| setCimdPublicClient(); | ||
| String code = loginUserAndGetCode(true); | ||
| AccessTokenResponse tokenResponse = oauth.client(CLIENT_ID).accessTokenRequest(code).send(); | ||
| Assertions.assertEquals(200, tokenResponse.getStatusCode()); | ||
|
|
||
| ClientRepresentation clientRepresentation = findByClientIdByAdmin(); | ||
| Assertions.assertTrue(clientRepresentation.isPublicClient()); | ||
|
|
||
| logout(tokenResponse.getIdToken()); | ||
|
|
||
| timeOffSet.set(CIMD_EXECUTOR_MIN_CACHE_TIME_SEC + 3); | ||
|
|
||
| cimd.getRepresentation().setLogoUri("http://localhost:8500/logo2.png"); | ||
| code = loginUserAndGetCode(false); | ||
| tokenResponse = oauth.client(CLIENT_ID).accessTokenRequest(code).send(); | ||
| Assertions.assertEquals(200, tokenResponse.getStatusCode()); | ||
|
|
||
| clientRepresentation = findByClientIdByAdmin(); | ||
| Assertions.assertEquals("http://localhost:8500/logo2.png", clientRepresentation.getAttributes().get("logoUri")); | ||
|
|
||
| logoutAndDelete(clientRepresentation.getId(), tokenResponse.getIdToken()); | ||
| } |
|
|
||
| logout(tokenResponse.getIdToken()); | ||
|
|
||
| timeOffSet.set(CIMD_EXECUTOR_MIN_CACHE_TIME_SEC + 3); |
|
|
||
| logout(tokenResponse.getIdToken()); | ||
|
|
||
| timeOffSet.set(CIMD_EXECUTOR_MIN_CACHE_TIME_SEC + 3); |
Comment on lines
+1145
to
+1146
| String redirectUrisConditionProvider, | ||
| ClientPolicyConditionConfigurationRepresentation redirectUrisConditionConfig) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52152