--
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/4f97a561-937d-48c6-844f-4fc9772a3657%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/CAJgngAdLJY2ihUu0ZcvYzHSu-E95QbHULLYpCfjX4MXQ%2BGKM4w%40mail.gmail.com.
Hi,
One opinion from my side: I had the same issue and tried my best to apply the authorization policy idea of https://stackoverflow.com/questions/54305880/how-can-i-restrict-client-access-to-only-one-group-of-users-in-keycloak.
This didn’t work at all. But it sounds quite natural to model it that way.
So I would like to “vote” for Stians proposal to apply Authorization Service handling to login flow, too.
Only in case of performance degradations by this change, the authentication flow solution (which sounds like a great workaround, but unfortunately has no applicable license for us, e.g. Apache 2) would be better for us, as this can be activated for each applicable client.
Mit freundlichen Grüßen / Best regards
Frank Thiele
Open Source Services 2 - Product Group Customer Success Services (INST-CSS/BSV-OS2)
Bosch.IO GmbH | Ziegelei 7 | 88090 Immenstaad |
GERMANY | www.bosch.io
Tel. +49 30 726112-0 | Telefax +49 30 726112-100 |
external.F...@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/d039fed4-27f4-31b8-d4c6-c62b1d4e35c7%40redhat.com.
One of my customers had a similar, but much simpler use case. They wanted authentication being rejected if the user does not have at least one role of the requested client.I solved this with a RequiredAction plugin that's doing this check at the end of the authentication flow.
On the other hand I don't like it very much to mingle authorization into authentication flow and rejecting an already successful authentication due to authorization restrictions.
--
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/bfea521b-c9ed-4e24-8a67-3c25e2ea867f%40googlegroups.com.
Hi,
One opinion from my side: I had the same issue and tried my best to apply the authorization policy idea of https://stackoverflow.com/questions/54305880/how-can-i-restrict-client-access-to-only-one-group-of-users-in-keycloak.
I thought about using the authz services as well, but gave up on that idea, since they are IMHO pretty hard to configure at the moment.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/CAK-7U1gp_T9a7qTMP%2BsnE3qWeT6F%2B%2BxDPBG4%3DsO0Ope6NQYA%2BA%40mail.gmail.com.
Hello at all,Thanks for the interesting discussion so far!@StianI hear you... and I'd love to improve Keycloak in this regard, but I often need to come up with a solution that works now with what is already there.As I said, I try the same approach with an authenticator, which just uses the internal authorization services with something like a client access policy.Furthermore I still think that the Authorization Services are quite complicated and the (REST) API for programmatic policy definitions is quite cumbersome.A textual approach would IMHO be much easier to work with IMHO.
Regarding authorization decisions, I think that they should be decided at the earliest possible moment, in order to avoid unnecessary round-trips.So, if Keycloak could already decide whether a user can access a particular application during login or token request for a particular client, then this would be a great wayto avoid unnecessary session creation, reduce round-trips and request latency.@MarekDo you have an idea how I could express the following with authorization service policies?- only users with the role1 or role2 can access a list of clients- users with role3 should not be able to access a list of clientsWith that one could write an authenticator, which evaluates the appropriate policies for a given client. The relevant policies could then be matched by following a naming conventionfor client-ids like common prefixes etc. Depending on the outcome of the policy decision one could either allow or deny the authentication.@FrankI just added an Apache 2 License to the extension playground examples.@AllBtw. it would be really handy, if Keycloak would support a label mechanism which would allow to assign labels to clients. This could serve as a logical grouping mechanism, which could then be usedto bind all kinds of logic (authentication flows, policies, mappers, etc.) to set of labels without being hard-wired to a particular client / scope. Another option would be to allow Client-Groups, but I think having a label mechanism would be more powerful.
Hello,
I gave the Authz based Authenticator idea another spin and I just finished a working prototype: https://github.com/thomasdarimont/keycloak-extension-playground/tree/master/auth-check-authz-policy-extensionThe policy evaluation is currently hand-rolled since I couldn't find a better way to evaluate the policies in the current context.
@Marek Do you have any suggestions how I could use the standard AuthorizationProvider#getPolicyEvaluator() in this context?
I am not sure. TBH I am not that familiar with the details of
authorization services at the implementation level. So my best
advice would be to look at the javadoc, existing codebase which
using that and existing tests. CCing Pedro, who is best expert
regarding authorization services.
More below
@Stian would something along this lines suite you better?
Cheers,Thomas
On Fri, 17 Apr 2020 at 22:11, Thomas Darimont <thomas....@googlemail.com> wrote:
Hello at all,
Thanks for the interesting discussion so far!
@StianI hear you... and I'd love to improve Keycloak in this regard, but I often need to come up with a solution that works now with what is already there.As I said, I try the same approach with an authenticator, which just uses the internal authorization services with something like a client access policy.Furthermore I still think that the Authorization Services are quite complicated and the (REST) API for programmatic policy definitions is quite cumbersome.A textual approach would IMHO be much easier to work with IMHO.
Regarding authorization decisions, I think that they should be decided at the earliest possible moment, in order to avoid unnecessary round-trips.So, if Keycloak could already decide whether a user can access a particular application during login or token request for a particular client, then this would be a great wayto avoid unnecessary session creation, reduce round-trips and request latency.
@Marek
Do you have an idea how I could express the following with authorization service policies?- only users with the role1 or role2 can access a list of clients- users with role3 should not be able to access a list of clients
I think both the use-cases can be modelled with the policies.
AFAIK Role-Policy can have both "positive" and "negative" logic,
so the logic like "user with role3 should not be able to access a
list of clients" should be doable with the negative logic. Also
you can add more roles into the single role-policy.
Also I guess that every client, which is subject to
authorization, can have it's own "Resource" or eventually also
"Authorization Scope", but maybe authorization scope is not
needed. Then you may need to create "Permission" as a binding
between resources (clients) and policies. Maybe there is better
way, but I would probably start with a model like this and then
see if it's fine or not...
Marek
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/CAJgngAfmQSD9jixmpo6iaJLyhrZXH5%3DNi6bR1eDnO_w7LVSNtw%40mail.gmail.com.
Hello,
I gave the Authz based Authenticator idea another spin and I just finished a working prototype: https://github.com/thomasdarimont/keycloak-extension-playground/tree/master/auth-check-authz-policy-extensionThe policy evaluation is currently hand-rolled since I couldn't find a better way to evaluate the policies in the current context.@Marek Do you have any suggestions how I could use the standard AuthorizationProvider#getPolicyEvaluator() in this context?
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/CAK-7U1j6b1gHdLMENHVA90jgcXTDHho1M4XA%3DbwsFCusKtyh%3Dg%40mail.gmail.com.
Hello at all,Thanks for the interesting discussion so far!@StianI hear you... and I'd love to improve Keycloak in this regard, but I often need to come up with a solution that works now with what is already there.As I said, I try the same approach with an authenticator, which just uses the internal authorization services with something like a client access policy.Furthermore I still think that the Authorization Services are quite complicated and the (REST) API for programmatic policy definitions is quite cumbersome.A textual approach would IMHO be much easier to work with IMHO.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/CAK-7U1h8XEVH08YKXYdnpPL_XDFX61xwGHV2cCEnaMukW0sObw%40mail.gmail.com.
I thought about using the authz services as well, but gave up on that idea, since they are IMHO pretty hard to configure at the moment.I think a textual declarative configuration would be much easier to work with.Especially when thinking about configuration as code.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-dev/CAK-7U1gp_T9a7qTMP%2BsnE3qWeT6F%2B%2BxDPBG4%3DsO0Ope6NQYA%2BA%40mail.gmail.com.
Hello Pedro et al.,
wow - thank you all for the great discussion so far!
@Stian
> One low-hanging fruit way would also be to have some required role option on a client.
This idea sounds promising and would solve my example use-case, but my gut feeling tells me, that this might be too short-sighted in the long run.
I think a grouping mechanism for clients, where you could then add this required role option would be better than configuring this on individual clients.
I like the access-option idea. However one should make sure that this also works with more complex access-polices.
@Pedro
The "LocalAuthorizationService" in the featured "Client Authorization" extension https://www.keycloak.org/extensions.html looks interesting
https://github.com/cloudtrust/keycloak-authorization/blob/master/src/main/java/io/cloudtrust/keycloak/protocol/LocalAuthorizationService.java#L75
However, it also patches a few Keycloak classes like OIDCLoginProtocol, which makes it difficult to be used in newer Keycloak versions.
https://github.com/cloudtrust/keycloak-authorization/blob/91ecebe876a4ace82a2078c6471ab65d588e3bbe/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java#L238
I try to incorporate your suggestions with the PolicyProvider#evaluate API another spin here:
https://github.com/thomasdarimont/keycloak-extension-playground/blob/master/auth-check-authz-policy-extension/src/main/java/com/github/thomasdarimont/keycloak/auth/authzpolicy/AuthzPolicyAuthenticator.java#L64
, although I didn't have much success last time.
Regarding the code:
```
PolicyProvider policyProvider = authorizationProvider.getProvider(parentPolicy.getType());
if (policyProvider == null) {
throw new RuntimeException("Unknown parentPolicy provider for type [" + parentPolicy.getType() + "].");
}
policyProvider.evaluate(new DefaultEvaluation(permission, executionContext, parentPolicy, decision, authorizationProvider, decisionCache));
```
If I have a policy "special-client-access" that should limit access to a group of clients (expressed as a nested "client policy") to users that have certain roles (expressed as a "role policy").
The "client policy" just contains client1,client2 and client3.
The "role policy" just contains role1
If all policies of the "special-client-access" apply in the given context, I want to allow access to the client.
How could I express that with the above API?
The executionContext probably needs the current user and the current target client, but what is a decision, what is my "parentPolicy" ("special-client-access"?), and why do I need need a decisionCache here?
when I wrote the example, I played a while with the API but eventually gave up, but as said I give it another try :)
@all
I didn't want to invent a new mechanism just for the fun of it :) I just wanted to find a way that works now which allows me to implement the use-case mentioned above.
The current authorization services framework is quite powerful and a very flexible authorization toolkit, which I'd love to use it but, when I try I fail most of the time.
Many things are either not documented, are lacking examples, or are intended to be used outside of Keycloak via the Authorization Service REST API.
When I give the above authenticator another spin, I try to jot down some more concrete things that I'm currently missing or that are difficult to use.
> Sorry, but I don't agree. Is that complicated?
I have the impression that I stepped on your toe, if this is the case then I apologize... sorry, that was not my intention! :)
```
ClientResource client = getClient();
AuthorizationResource authorization = client.authorization();
RolePolicyRepresentation representation = new RolePolicyRepresentation();
representation.setName("Realm Client Role Policy");
representation.addRole("Client Role A");
authorization.policies().role().create(representation);
```
No this particular example is not difficult per se, but requires applications to replicate a part of their domain model as resources to Keycloak,
but for this I need to start another discussion on another day :)
Back to the discussion about a DSL:
I choose to use a textual representation for access-policies because I wanted a single and easily diffable format that I put into source control, that can easily be transferred between environments.
The complex object model is currently quite difficult to port between environments if possible at all?!
With a textual DSL which is just interpreted I don't need to create, update, sync object models, which makes it easy to transfer them across different environments.
Other authorization frameworks like casbin https://github.com/casbin/casbin#policy-persistence (Java Library: https://github.com/casbin/jcasbin) follow a similar approach.
Perhaps we could think of a textual representation of an authorization policy set that can be imported into Keycloak.
> Declarative policies are good but not a silver bullet. There are some other options out there that have their language for expressing policies.
I agree with you here. As always it's a trade-off, a powerful DSL can be quite complex and hard to understand, on the other hand, an easy DSL can is probably quite inflexible, but easy to understand and does the job.
> First of all, it is one more thing you need to learn. And a good DSL goes beyond what you are proposing here.
My intent was not to invent a new general DSL :) I wanted to build something small and deliberately inflexible which solves a very specific problem.
Wrt. to the performance part, yes that's something where authorization services need some improvements, but this is also material for another discussion.
Hello Pedro et al.,
wow - thank you all for the great discussion so far!
@Stian
> One low-hanging fruit way would also be to have some required role option on a client.
This idea sounds promising and would solve my example use-case, but my gut feeling tells me, that this might be too short-sighted in the long run.
I think a grouping mechanism for clients, where you could then add this required role option would be better than configuring this on individual clients.
I like the access-option idea. However one should make sure that this also works with more complex access-polices.