Microservice to Microservice calls, authorization from a queue message

后端 未结 3 558
终归单人心
终归单人心 2021-02-08 05:48

Context: I\'m creating a cloud platform to support multiple applications with SSO. I\'m using Keycloak for authentication and Netflix Z

相关标签:
3条回答
  • 2021-02-08 05:55

    One common setup is to have an API gateway that verify all incoming requests by their JWT. The API Gateway validates the signature of the JWT (or decrypt it for encrypted JWT's), checks the the expiry time etc, and extract the scopes and the User ID (sub) from it.

    It then compare the scopes with a set of defined scopes for each micrto service, and if the scope provides the user (subject) access, the request is forwarded to the micro service. The User ID (sub in the JWT), along with other needed information stored in the JWT is placed in custom requests headers like X-IGNACIO-SUBJECT

    0 讨论(0)
  • 2021-02-08 06:04

    Disclaimer: I never used Keycloak, but the tag wiki says it's compliant with OAuth2 so I'll trust that information.


    At a really high-level view, you seem to have two requirements:

    1. authenticate actions triggered by an end user while he's using your system.
    2. authenticate actions triggered by your system at an unknown time and where there is no requirement for a end-user to be online.

    You already met the first one, by relying on a token-based authentication system and I would do exactly the same for the second point, the only difference would be that the tokens would be issued to your system using the OAuth2 client credentials grant instead of the other grants that are targeted at scenarios where there is an end-user.

    (source: Client Credentials Grant)

    In your case, Keycloak would play the role of Auth0 and your client applications are microservices which can maintain client secrets used to authenticate themselves in the authorization server and obtain access tokens.

    One thing to have in mind is that if your system relies on the sub claim for much more than authentication and authorization then you may need to make some adjustments. For example, I've seen systems where performing action A required to know that it was targeted at user X and Y, but the payload for the action only received user Y and assumed user X was the current authenticated principal. This works fine when everything is synchronous, but by merely switching the payload to specify both users would mean that the action could be done asynchronously by a system authenticated principal.

    0 讨论(0)
  • 2021-02-08 06:08

    As you said your microservices use JWT for authentication which always passes through a gateway, in this way you can actually use the concept of FEIGN CLIENT. Feign as rest client example.

    0 讨论(0)
提交回复
热议问题