You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/06/09 16:11:09 UTC

[GitHub] [incubator-apisix] sshniro opened a new issue #1679: feature : OAuth Authorization plugin for Keycloak

sshniro opened a new issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679


   ### Issue description
   [Keycloak](https://www.keycloak.org/) is an Identity Server from RedHad based on OAuth/OIDC. Keycloak provides a very powerful [policy engine](https://www.keycloak.org/docs/latest/authorization_services/index.html#_policy_overview) for Authorization. It can support Roles base, Attribute-based, and Dynamic authorization strategies. 
   
   The following image shows how APISIX can be integrated with Keycloak Server.
   
   ![image](https://user-images.githubusercontent.com/13045528/84159205-180ec600-aa6d-11ea-941e-76a66ae35d0e.png)
   
   The following is a proposed schema for the authz-keycloak plugin:
   ```bash
   curl http://127.0.0.1:9080/apisix/admin/routes/5  -X PUT -d '
   {
       "uri": "/get",
       "host": "httpbin.org",
       "plugins": {
           "authz-keycloak": {
             "token_endpoint": "token_endpoint_url",
             "grant_type": "token_endpoint_url",
             "enforcement_policy": "Permissive OR Enforcing",
             "permissions": [{"resourse_name#scope_1_name"}, {{"resourse_name#scope_2_name"}}]
           }
       },
       "upstream_id": 50
   }'
   ```
   Enforcing mode will reject calls that do not have a associated permission and Permissive enforcement policy will allow the API call if no permission is tied with the resource/path.
   
   I would like to contribute to this plugin and would like to hear the thoughts of the community.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its the implementation of PEP to enforce policies for API calls. Keycloak only provides adapters for Java and JS.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   Keycloak provides the above API to check if you have permission to access a resource or not.
   By, passing in the `response_mode` as `decision` will result in a `200` or `403` response based on the permission assigned to that operation.
   
   In the official authorization adapter, you can define the scopes and paths for your resources and Keycloak internally makes these API calls to check if you have the permission to the required scope and resource. Also, in the Keycloak policy enforcer file, you can opt-out to not to define the paths. Then the adapters do a lazy loading to fetch the matching paths and resources dynamically.
   
   The following image shows a sample configuration of Keycloak JSON with matching paths, methods, and scopes:
   ![image](https://user-images.githubusercontent.com/13045528/84576135-bb841180-adb2-11ea-8fd2-08bcf34a541c.png)
   
   Therefore, as the first implementation, I propose to implement the authorization flow by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support the lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.
   
   The following is a [reference from the Keycloak adapter](https://github.com/keycloak/keycloak/blob/f70af83fb628da80dc54968248af85b9ac25a45f/authz/client/src/main/java/org/keycloak/authorization/client/resource/ProtectedResource.java#L220) on how it tries to find the relevant resources by trying to match the URI.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] chnliyong commented on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
chnliyong commented on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643651653


   This looks like a subset of [PEP](https://www.keycloak.org/docs/latest/authorization_services/index.html#_enforcer_overview).
   
   I fell little confused, what's the relationship of the `permissions` array  and the requested method+uri.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] moonming commented on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
moonming commented on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-642415312


   LGTM
   @chnliyong please take a look, thx


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its a subset of PEP.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   In the official authorization adapter, you can define the scopes and paths for your endpoints and Keycloak internally makes these API calls to check if you have the permission to the required scope. Also, in the keycloak policy enforcer file you can opt-out to not to define the paths and the adapters does a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore as the first implementation I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its the implementation of PEP to enforce policies for API calls. Keycloak only provides an adapter for Java and JS.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   Keycloak provides the above API to check if you have permission to access a resource or not.
   By, passing in the `response_mode` as `decision` will result in a 200 or 403 response based on the permission assigned to that operation.
   
   In the official authorization adapter, you can define the scopes and paths for your endpoints and Keycloak internally makes these API calls to check if you have the permission to the required scope and resource. Also, in the Keycloak policy enforcer file, you can opt-out to not to define the paths and the adapters do a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore, as the first implementation, I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support the lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.
   
   The following is a [reference from the Keycloak adapter](https://github.com/keycloak/keycloak/blob/f70af83fb628da80dc54968248af85b9ac25a45f/authz/client/src/main/java/org/keycloak/authorization/client/resource/ProtectedResource.java#L220) on how it tries to find the relevant resources by trying to match the URI.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro commented on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro commented on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its a subset of PEP.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   In the official authorization adapter, you can define the scopes and paths for your endpoints and Keycloak internally makes these API calls to check if you have the permission to the required scope. Also, in the keycloak policy enforcer file you can opt-out to not to define the paths and the adapters does a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore as the first implementation I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support lazy loading of paths and permissions.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] chnliyong commented on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
chnliyong commented on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643650950


   This looks like a subset of [PEP](https://www.keycloak.org/docs/latest/authorization_services/index.html#_enforcer_overview).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its the implementation of PEP to enforce policies for API calls. Keycloak only provides adapters for Java and JS.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   Keycloak provides the above API to check if you have permission to access a resource or not.
   By, passing in the `response_mode` as `decision` will result in a 200 or 403 response based on the permission assigned to that operation.
   
   In the official authorization adapter, you can define the scopes and paths for your resources and Keycloak internally makes these API calls to check if you have the permission to the required scope and resource. Also, in the Keycloak policy enforcer file, you can opt-out to not to define the paths and the adapters do a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore, as the first implementation, I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support the lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.
   
   The following is a [reference from the Keycloak adapter](https://github.com/keycloak/keycloak/blob/f70af83fb628da80dc54968248af85b9ac25a45f/authz/client/src/main/java/org/keycloak/authorization/client/resource/ProtectedResource.java#L220) on how it tries to find the relevant resources by trying to match the URI.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis closed issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
membphis closed issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its the implementation of PEP to enforce policies for API calls. Keycloak only provides an adapter for Java JS.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   Keycloak provides the above API to check if you have permission to access a resource or not.
   By, passing in the `response_mode` as `decision` will result in a 200 or 403 response based on the permission assigned to that operation.
   
   In the official authorization adapter, you can define the scopes and paths for your endpoints and Keycloak internally makes these API calls to check if you have the permission to the required scope and resource. Also, in the Keycloak policy enforcer file, you can opt-out to not to define the paths and the adapters do a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore, as the first implementation, I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support the lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.
   
   The following is a [reference from the Keycloak adapter](https://github.com/keycloak/keycloak/blob/f70af83fb628da80dc54968248af85b9ac25a45f/authz/client/src/main/java/org/keycloak/authorization/client/resource/ProtectedResource.java#L220) on how it tries to find the relevant resources by trying to match the URI.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its a subset of PEP.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   Keycloak provides the above API to check if you have permission to access a resource or not.
   By, passing in the `response_mode` as `decision` will result in a 200 or 403 response based on the permission assigned to that operation.
   
   In the official authorization adapter, you can define the scopes and paths for your endpoints and Keycloak internally makes these API calls to check if you have the permission to the required scope. Also, in the Keycloak policy enforcer file, you can opt-out to not to define the paths and the adapters do a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore as the first implementation, I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.
   
   The following is a reference from the Keycloak adapter on how it tries to find the relevant resource by trying to match the URI.
   https://github.com/keycloak/keycloak/blob/f70af83fb628da80dc54968248af85b9ac25a45f/authz/client/src/main/java/org/keycloak/authorization/client/resource/ProtectedResource.java#L220


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] chnliyong removed a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
chnliyong removed a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643650950


   This looks like a subset of [PEP](https://www.keycloak.org/docs/latest/authorization_services/index.html#_enforcer_overview).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] sshniro edited a comment on issue #1679: feature : OAuth Authorization plugin for Keycloak

Posted by GitBox <gi...@apache.org>.
sshniro edited a comment on issue #1679:
URL: https://github.com/apache/incubator-apisix/issues/1679#issuecomment-643652813


   Yes @chnliyong its a subset of PEP.
   
   ![image](https://user-images.githubusercontent.com/13045528/84575018-91c6ec80-adaa-11ea-94f6-662896c1aa1d.png)
   
   Keycloak provides the above API to check if you have permission to access a resource or not.
   By, passing in the `response_mode` as `decision` will result in a 200 or 403 response based on the permission assigned to that operation.
   
   In the official authorization adapter, you can define the scopes and paths for your endpoints and Keycloak internally makes these API calls to check if you have the permission to the required scope. Also, in the Keycloak policy enforcer file, you can opt-out to not to define the paths and the adapters do a lazy loading to fetch the matching paths and resources dynamically.
   
   Therefore as the first implementation, I propose to implement this by having the definitions of what is the resource and scope needed to access a route, and future enhancements would support lazy loading of paths and permissions.
   
   Please do have a look at the unit tests of the PR on how the authorization is enforced.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org