8000 Validate client scopes registration policy configuration by graziang · Pull Request #40254 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Validate client scopes registration policy configuration #40254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025

Conversation

graziang
Copy link
Contributor
@graziang graziang commented Jun 4, 2025

Closes #40187

This PR just implements ClientScopesClientRegistrationPolicyFactory.validateConfiguration() to enable configuration validation for client registration policies. For client policies, looking at the code, it seems we don’t have any kind of configuration validation, It might be worth defining something similar to what we have for client registration policies as a follow-up.

@mposolda
Copy link
Contributor
mposolda commented Jun 5, 2025

@graziang Thanks!

Question: Do we have something similar for "client policies" as well? When someone uploads JSON with the client-policy-executor referencing not existing client scope, do we also prevent this? Original bug report was for "client registration policies", but thinking it can be good to doublecheck "client policies" as well (unless we are oing already?)

@graziang
Copy link
Contributor Author
graziang commented Jun 5, 2025

@mposolda thanks! Added in a separate commit a validation system for the configuration of client policy conditions. So far, I’ve implemented validation only for the client-scopes condition. This might cause issues when updating existing client policies that are misconfigured with invalid scopes.

@mposolda mposolda self-assigned this Jun 9, 2025
Copy link
Contributor
@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

@graziang The idea looks good to me, Thanks! But there are test failures, which look as a regression of the change.

IMO when there is fake-scope configured in the list of client-scopes condition, the create/update should fail. But if the configured list is empty or null, it should probably work? Could it be the reason of the test failure or is it something different?

public void validateConfiguration(KeycloakSession session, RealmModel realm, ClientPolicyConditionRepresentation conditionRepresentation) throws ClientPolicyException {
ClientScopesCondition.Configuration configuration = JsonSerialization.mapper.convertValue(conditionRepresentation.getConfiguration(), ClientScopesCondition.Configuration.class);

if (!realm.getClientScopesStream().map(ClientScopeModel::getName).toList().containsAll(configuration.getScopes())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work if configuration.getScopes() is null or empty list? I guess it doesn't work for null. Not 100% sure if this could be a reason of the test failures in the current PR (but maybe it is some completely cause...)

@graziang
Copy link
Contributor Author
graziang commented Jun 9, 2025

@mposolda Thanks for the review. The tests were failing because a client role was being used as a client 8000 scope, so the new validation was actually doing the right thing. I created a sample client scope to fix it. I also added the null check and included a test. Everything is in a separate commit to simplify the review.

@mposolda mposolda added the status/ready Ready to be merged label Jun 9, 2025
Copy link
Contributor
@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

@graziang Thanks! Trying to re-run the remaining failing tests. It seems they are not regression of this PR.

graziang added 3 commits June 10, 2025 09:56
Closes keycloak#40187

Signed-off-by: Giuseppe Graziano <g.graziano94@gmail.com>
Closes keycloak#40187

Signed-off-by: Giuseppe Graziano <g.graziano94@gmail.com>
Closes keycloak#40187

Signed-off-by: Giuseppe Graziano <g.graziano94@gmail.com>
@abstractj abstractj merged commit ad511cb into keycloak:main Jun 11, 2025
76 checks passed
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.

Client Registration with fake scope
4 participants
0