8000 KEYCLOAK-18051 Add regex redirect-uri client policy by patrick-primesign · Pull Request #8236 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
8000

KEYCLOAK-18051 Add regex redirect-uri client policy - #8236

Closed
patrick-primesign wants to merge 1 commit into
keycloak:mainfrom
primesign:KEYCLOAK-18051-regex-client-policy
Closed

patrick-primesign wants to merge 1 commit into
keycloak:mainfrom
primesign:KEYCLOAK-18051-regex-client-policy

Conversation

@patrick-primesign
Copy link
Copy Markdown
Contributor

@abstractj abstractj added kind/enhancement Categorizes a PR related to an enhancement impact/high status/needs-discussion PR needs discussion on developer mailing list labels Jul 6, 2021
@stianst
stianst commented Sep 9, 2022
Copy link
Copy Markdown
Contributor

Sorry for the late reply to this one. Wondering if there's still interest in this PR if so perhaps we can discuss how to proceed.

If so could you provide a bit more context behind the approach here? It seems like the idea is that clients can register '*' as redirect-uris, then the client-policy is used to configure a regex-pattern that can check the redirect-uri used by the authorization request. That seems a bit the wrong way around to me.

I would have rather expected to have a client-policy that is used to decide what redirect-uris a client can register, so would check on client create/update rather than on authz requests.

Wondering if it also might be nice to convert this into a redirect-uri policy and have some more options than just regex to incorporate some of the stuff we've discussed in #9278.

@stianst
stianst commented Sep 9, 2022
Copy link
Copy Markdown
Contributor

One more thing is that it would be good to separate the client-ids condition into a separate PR.

@stianst
stianst commented Sep 9, 2022
Copy link
Copy Markdown
Contributor

Added some more thoughts to #9278 (comment)

@CorneliaLahnsteiner
CorneliaLahnsteiner commented Sep 12, 2022 •
Copy link
Copy Markdown
Contributor

Hi @stianst. There is still interest in bringing this pull request upstream. We are already using this change in production (since a year) and it works pretty well.

The idea behind this PR is to allow (next to wildcards) RegEx for the allowed redirect-uris. However, the specs very clearly state that redirect-uris should be a strict string comparison. Therefore, we decided that an realm admin has to explicitly configure the RegEx by a client policy.

Configuration steps:

  1. Register 'https://*' as valid redirect-uris at client level
  2. Register in realm settings under client policies a new profile and add the executor "regex-redirect-uri" where you configure the valid redirect-uris in RegEx pattern
  3. Register a new client policy and add the condition "client-ids" where you configure the clients who should be affected by the RegEx validation
  4. Finally add the client profile to the client policy to enable the RegEx validation for the specific clients

The RegEx pattern is used by the authorization request to validate the redirect-uri.

To understand your suggestion: Your approach would be to register a client policy that decides what kind of valid-redirect uris (wildcard, RegEx) a client may have. Furthermore, adapt the client settings to also allow RegEx (if a client-policy is set for the specific client). And change this method to also support RegEx validation:

private static boolean matchesRedirects(Set<String> validRedirects, String redirect) {

Your approach also seems justified to me, but it is a deeper change in Keycloak than the current change. A question to your approach: At the client settings, can we query if this client has set the regex client policy? What should happen, if we remove this client at the client-policies?

Thanks,
Cornelia

@CorneliaLahnsteiner
Copy link
Copy Markdown
Contributor

One more thing is that it would be good to separate the client-ids condition into a separate PR.

It is no proplem to seperate the condition into a sperate PR.

@stianst
stianst commented Jul 26, 2023
Copy link
Copy Markdown
Contributor

There's a more extensive executor in #14659. Perhaps we would want to keep that one, and in this one only keep the client-id condition?

8000
@mposolda
Copy link
Copy Markdown
Contributor

Few points to this:

  • There was executor added in the PR for Client policies: executor for validate and match a redirect URI #25637 and should be available in Keycloak 24. Hence the "executor" part of this PR is out-of-date now and can be likely removed

  • So effectively the only "new" part to this PR might be condition for client-ids. But I am wondering if this condition is really needed? As for instance you can use existing condition ClientRolesCondition, which applies when client has client role with the particular name. This allows that you can add client role to all requested clients (this role can be used purely as "marker role" to specify that particular client policy should be applied. No users need to be added to this role at all). It seems the approach based on "client role" has more flexibility and it can scale much better as in case when realm has thousands of clients and you want policy to be executed for half of them for instance, it won't scale well to have client-ids condition with thousand of client-ids explicitly named. It would be bad for both performance (iterating over 1000 client-ids in every request) as well as manageability.

@CorneliaLahnsteiner
Copy link
Copy Markdown
Contributor

Few points to this:

  • There was executor added in the PR for Client policies: executor for validate and match a redirect URI #25637 and should be available in Keycloak 24. Hence the "executor" part of this PR is out-of-date now and can be likely removed
  • So effectively the only "new" part to this PR might be co 8000 ndition for client-ids. But I am wondering if this condition is really needed? As for instance you can use existing condition ClientRolesCondition, which applies when client has client role with the particular name. This allows that you can add client role to all requested clients (this role can be used purely as "marker role" to specify that particular client policy should be applied. No users need to be added to this role at all). It seems the approach based on "client role" has more flexibility and it can scale much better as in case when realm has thousands of clients and you want policy to be executed for half of them for instance, it won't scale well to have client-ids condition with thousand of client-ids explicitly named. It would be bad for both performance (iterating over 1000 client-ids in every request) as well as manageability.

@mposolda great, thanks for the information! I will have a look at the already merged solution (#25637) in the next few days. If our solution is outdated by the solution already merged, then this pull request offers no added value and can be closed.
And I agree with your second comment. It is more performant to use the already existing client roles instead of our client-ids.

@mposolda
Copy link
Copy Markdown
Contributor

@CorneliaLahnsteiner Cool, Thanks! Please comment here or close the PR if you are already comfortable with existing approach. Thanks for your contribution regardless!

@mposolda
Copy link
Copy Markdown
Contributor

@CorneliaLahnsteiner @patrick-primesign No further feedback, so I am closing this for now. Just to summary:

  • Regex redirect-uri enforcer executor is already available in Keycloak 24
  • Condition for client-ids might not be needed as condition for client-roles can be used

But feel free to re-open if you think that some parts of this PR still should be added (or maybe rather create new GH issue and/or PR if something doesn't work as expected in Keycloak 24, which is going to be released soon).

@mposolda mposolda closed this Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement Categorizes a PR related to an enhancement status/needs-discussion PR needs discussion on developer mailing list team/core-shared

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0