Hi everybody,
as Stian suggested, I would like to kick off a discussion on the topic of dynamic/custom scopes.
Background:
Before KC10, Keycloak accepted any scope parameter coming from the client. With Keycloak 10, it started to validate the scopes sent from the client and rejected unknown scopes (https://github.com/keycloak/keycloak/pull/6943) because the spec says the authorization server should respond with “invalid_scope” if “The requested scope is invalid, unknown, or malformed.”
This change caused some problem for people relying on the old behaviour. In https://issues.redhat.com/browse/KEYCLOAK-14143, there was a discussion to solve this problem by
For the approach of turning scope validation into an SPI, a PR was already submitted:
https://github.com/keycloak/keycloak/pull/7721
In our case, we do have quite a lot of scopes that are essentially validated elsewhere. So all three of the above-mentioned approaches would work for us.
I assume there are definitely use-cases for more dynamic scopes than the built-in Keycloak scopes, because they could be short-lived / bound to specific transactions / time-limited resources etc.
The SPI approach allows to capture these scenarios so I do like it.
If I get Stians concerns correctly, he is a little worried that people will just implement an SPI accepting all scopes making Keycloak break the spec and potentially creating an environment with security issues.
It would be really great to get other peoples’ opinions on this topic.
Thanks and best regards,
Sebastian
Mit freundlichen Grüßen / Best regards
Dr.-Ing.
Sebastian Schuster
Project Delivery Berlin 22 (IOC/PDL22)
Bosch.IO GmbH | Ullsteinstr. 128 | 12109 Berlin | GERMANY |
www.bosch.io
Tel. +49 30 726112-485 | Mobil +49 152 02177668 | Telefax +49 30 726112-100 |
Threema /
Threema Work: MF9VMEAE |
Sebastian...@bosch.io
Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr. Stefan Ferber, Dr. Aleksandar Mitrovic, Yvonne Reckling
Reading that part of the spec, I think it leaves a little room for interpretation (surprise, surprise):
The authorization server MAY fully or partially ignore the scope
requested by the client, based on the authorization server policy or
the resource owner's instructions. If the issued access token scope
is different from the one requested by the client, the authorization
server MUST include the "scope" response parameter to inform the
client of the actual scope granted.
The way I would understand this section is that it would actually be fine to ignore unknown scopes
as long as the authorization server responds with the set of known/granted scopes specifically.
In that light the section https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
invalid_scope The requested scope is invalid, unknown, or malformed.
just states what error is returned when the authorization server choses to not ignore a scope.
I would say the above argumentation would at least allow to override the now-standard behaviour
of Keycloak to always return invalid_scope on unknown scopes using an SPI as implemented in
https://github.com/keycloak/keycloak/pull/7721
@stian WDYT?
Best regards,
Sebastian
Mit freundlichen Grüßen / Best regards
Dr.-Ing.
Sebastian Schuster
Project Delivery Berlin 22 (IOC/PDL22)
Bosch.IO GmbH | Ullsteinstr. 128 | 12109 Berlin | GERMANY |
www.bosch.io
Tel. +49 30 726112-485 | Mobil +49 152 02177668 | Telefax +49 30 726112-100 |
Threema / Threema Work: MF9VMEAE |
Sebastian...@bosch.io
Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr. Stefan Ferber, Dr. Aleksandar Mitrovic, Yvonne Reckling
--
You received this message because you are subscribed to the Google Groups "Keycloak Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
keycloak-dev...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/keycloak-dev/faf36e2f-96c7-4f78-82ad-4d7709be446bn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/141601B1-547F-46FD-A93B-2857F9EFF9F6%40bosch.com.
In regards of the following section from RFC 6749:"The authorization server MAY fully or partially ignore the scope requested by the client, based on the authorization server policy or the resource owner's instructions. If the issued access token scope is different from the one requested by the client, the authorization server MUST include the "scope" response parameter to inform the client of the actual scope granted."My interpretation is in line of yours, Sebastian. Therefore, invalid_scopes should be processed according to a custom validation configuration specifically to Authorization server in question. In addition, in the light of this RFC, my vision is that the more appropriate manner is to provide a SPI, Pigor. In this way, the implementation of the FAPI Lodging Intent would be possible, as suggested by you, Leandro.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/8d631977-214b-48c4-b8fa-0f2c9d133becn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/fddbcaaf-d075-4ded-bd45-7c07e7c21633n%40googlegroups.com.
Few points to this:
- As pointed, the specification allows various interpretations around scope validations. IMO it will be good to stick to current behaviour and reject unknown scopes by default, but at the same time, have an easy way to allow "dynamic" scopes. I think it is needed that people can relax on scopes validations without need to implement their own provider of any SPI.
- Regarding scope validation, I am thinking that instead of introducing separate SPI, we can possibly re-use the existing client policies SPI, which was recently added, and possibly have the executor dedicated to validate scopes? This would mean that we may need to add the default validation to the separate executor, which will be added to some default policy. This will first require to have auto-created default client policy added to each realm. Auto-created client policy is not yet available, but I think that from the long term perspective, it may be way to go https://issues.redhat.com/browse/KEYCLOAK-18463. Administrators might be able to remove auto-created policy or link to the client profile, which won't have the default executor. This will allow effectively disable scope validations without any changes. And I hope it will work fine with the use-cases like lodging intent (See below).
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/ffb23cfa-d3e7-81e3-4b15-ba49f7fa0f71%40redhat.com.
Hi everybody,
thanks for the hint with the getDynamicClientScopes() @Pedro. I took a look at it and although I think it could do the job, I don’t think it would be a great solution since
a) ClientStorageProviderSPI is pretty heavyweight and
b) from the name it should be more concerned with how clients are stored technically and not about the business logic of how scopes are validated for an individual client – this sounds like a different concern to me.
I also like Marek’s idea make it easy to turn off scope validation, maybe as a simple switch in the default implementation of scope validation.
I also agree with Pedro that for proper dynamic scopes, especially when it comes to examples like lodging intent, this should be visible on the consent screen.
I would also prefer to have a separate SPI for this. But then
https://github.com/keycloak/keycloak/pull/7721 would probably not be sufficient as things like the calculation of scopes to show on the consent screen
(https://github.com/keycloak/keycloak/blob/458c841c390589ec95e173e2d0955be54cdce887/services/src/main/java/org/keycloak/services/managers/AuthenticationManager.java#L1143)
and more would have to be adapted.
Tbh. I find it hard to judge whether having a separate SPI for this is the best way to go or whether this should be part of client policies… It touches client, client scope and user (consent), so its somewhere in the middle…
Best regards,
Sebastian
Mit freundlichen Grüßen / Best regards
Dr.-Ing.
Sebastian Schuster
Project Delivery Berlin 22 (IOC/PDL22)
Bosch.IO GmbH | Ullsteinstr. 128 | 12109 Berlin | GERMANY |
www.bosch.io
Tel. +49 30 726112-485 | Mobil +49 152 02177668 | Telefax +49 30 726112-100 |
Threema / Threema Work: MF9VMEAE |
Sebastian...@bosch.io
Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr. Stefan Ferber, Dr. Aleksandar Mitrovic, Yvonne Reckling
To view this discussion on the web visit
https://groups.google.com/d/msgid/keycloak-dev/CA%2B3s2iR5KVE2AyMJOr89Xys75-%3Dsu550%3DpHT%3D%2BN0ZiD1rSK51A%40mail.gmail.com.
Hi everybody,
thanks for the hint with the getDynamicClientScopes() @Pedro. I took a look at it and although I think it could do the job, I don’t think it would be a great solution since
a) ClientStorageProviderSPI is pretty heavyweight and
b) from the name it should be more concerned with how clients are stored technically and not about the business logic of how scopes are validated for an individual client – this sounds like a different concern to me.
I also like Marek’s idea make it easy to turn off scope validation, maybe as a simple switch in the default implementation of scope validation.
I also agree with Pedro that for proper dynamic scopes, especially when it comes to examples like lodging intent, this should be visible on the consent screen.
I would also prefer to have a separate SPI for this. But then https://github.com/keycloak/keycloak/pull/7721 would probably not be sufficient as things like the calculation of scopes to show on the consent screen
(https://github.com/keycloak/keycloak/blob/458c841c390589ec95e173e2d0955be54cdce887/services/src/main/java/org/keycloak/services/managers/AuthenticationManager.java#L1143) and more would have to be adapted.
Tbh. I find it hard to judge whether having a separate SPI for this is the best way to go or whether this should be part of client policies… It touches client, client scope and user (consent), so its somewhere in the middle…
+1 for Pedro and your point here. I proposed client policies just for the use-case of disabling strict validation of scope parameterc. But regarding full support of dynamic client scopes including consent screen etc, it seems that separate SPI would have more sense.
Maybe the support for lodging intent can be added as prototype to see what would be all the capabilities required for the SPI? Maybe some design/prototype of it can help. Hopefully it will help us to see what would be best approach to easily disable scope validations for those users, who are interested just in that use-case of disable strict scopes validation.
Marek
Reading that part of the spec, I think it leaves a little room for interpretation (surprise, surprise):
The authorization server MAY fully or partially ignore the scope
requested by the client, based on the authorization server policy or
the resource owner's instructions. If the issued access token scope
is different from the one requested by the client, the authorization
server MUST include the "scope" response parameter to inform the
client of the actual scope granted.
The way I would understand this section is that it would actually be fine to ignore unknown scopes
as long as the authorization server responds with the set of known/granted scopes specifically.
In that light the section https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
invalid_scopeThe requested scope is invalid, unknown, or malformed.just states what error is returned when the authorization server choses to not ignore a scope.
I would say the above argumentation would at least allow to override the now-standard behaviour
of Keycloak to always return invalid_scope on unknown scopes using an SPI as implemented in https://github.com/keycloak/keycloak/pull/7721@stian WDYT?
But if you want to support things like lodging intent, Keycloak would have to return a dynamically requested scope for a specific transaction if it was granted by the user (or no scope at all if all requested scopes were granted).
Mit freundlichen Grüßen / Best regards
Dr.-Ing.
Sebastian Schuster
Project Delivery Berlin 22 (IOC/PDL22)
Bosch.IO GmbH | Ullsteinstr. 128 | 12109 Berlin | GERMANY |
www.bosch.io
Tel. +49 30 726112-485 | Mobil +49 152 02177668 | Telefax +49 30 726112-100 |
Threema / Threema Work: MF9VMEAE |
Sebastian...@bosch.io
Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr. Stefan Ferber, Dr. Aleksandar Mitrovic, Yvonne Reckling
From: Stian Thorgersen <stho...@redhat.com>
Reply to: "st...@redhat.com" <st...@redhat.com>
Date: Wednesday, 23. June 2021 at 12:30
To: "Schuster Sebastian (IOC/PAU1)" <Sebastian...@bosch.io>
Cc: Leandro de Bortoli <leandrob...@gmail.com>, Keycloak Dev <keyclo...@googlegroups.com>
So how do we proceed here? I think https://github.com/keycloak/keycloak/pull/7721 would be the KISS solution of the problem.
Maybe it could be beneficial if the SPI instead of only returning true/false on the whole list returns a (sub-)-list of valid scopes, empty
list if invalid_scpope should be returned. Then you could also tell the client he got less scopes from the SPI for other reasons than
the user not granting a certain scope (future Keycloak feature, hopefully). But not sure if that’s super useful…
Best regards,
Sebastian
Mit freundlichen Grüßen / Best regards
Dr.-Ing.
Sebastian Schuster
Project Delivery Berlin 22 (IOC/PDL22)
Bosch.IO GmbH | Ullsteinstr. 128 | 12109 Berlin | GERMANY |
www.bosch.io
Tel. +49 30 726112-485 | Mobil +49 152 02177668 | Telefax +49 30 726112-100 |
Threema / Threema Work: MF9VMEAE |
Sebastian...@bosch.io
Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr. Stefan Ferber, Dr. Aleksandar Mitrovic, Yvonne Reckling
To view this discussion on the web visit
https://groups.google.com/d/msgid/keycloak-dev/DCC56653-45A8-4C14-9DCA-0D2D7DD0CD5D%40bosch.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/36fd78f2-2291-4c5a-a082-3da355cbe06dn%40googlegroups.com.