Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Claims to JWT tokens. #111

Open
taaraora opened this issue Jun 27, 2019 · 6 comments
Open

Add Custom Claims to JWT tokens. #111

taaraora opened this issue Jun 27, 2019 · 6 comments

Comments

@taaraora
Copy link

Hi, I wonder is it possible to add custom claims to JWT tokens. I want to attach user roles list to JWT token when user is authenticated.

@cainlevy
Copy link
Member

cainlevy commented Jul 1, 2019

There's currently no way for the app to inject data into AuthN's authentication process.

Can you say more about your use case? I prefer to check permissions on each request, so I don't personally have established patterns to recommend.

@taaraora
Copy link
Author

taaraora commented Jul 3, 2019

Hi, I'm considering using Open Policy Agent as an authorization agent for microservices. When microservice receives API request I can just forward that request to OPA and it makes the authorization decision. Such an approach requires to distribute Roles information to each OPA agent also attach User roles list to each request. JWT work nicely in such case because I can just attach a list of roles to JWT token as custom claims.

@cainlevy
Copy link
Member

cainlevy commented Jul 3, 2019

related: #114

@cainlevy
Copy link
Member

Apologies for not following up sooner. I'm not sure where to go with this yet.

My understanding of this proposal is that AuthN could save your Open Policy Agent a network request by including static roles in the identity token. Is that accurate?

When I try to generalize this solution to a broad number of use cases, I wonder:

  • Will OPA sometimes need to load the user anyway for other information?
  • Would the potentially saved network request be meaningful? My experience with authorization is that a decision can require bits of context about the user, the target resource, and even related resources. Pushing the decision into an external service could require loading a lot of context into that service.
  • What if roles change? Effective user moderation sometimes involves revoking or suspending key privileges, and enforcement should not wait for the user's session to expire or reauthenticate.

@cainlevy
Copy link
Member

cainlevy commented Jul 24, 2019

⚠️ If anyone follows the OPA documentation and attempts to integrate a JWT as described then please don't rely on this process to establish trust. ⚠️

This is an incomplete list of flaws in the currently documented approach. Each could compromise your system:

  • does not verify signature
  • does not verify issuer
  • does not verify intended audience
  • does not check token expiration

@taaraora
Copy link
Author

Apologies for not following up sooner. I'm not sure where to go with this yet.

My understanding of this proposal is that AuthN could save your Open Policy Agent a network request by including static roles in the identity token. Is that accurate?

When I try to generalize this solution to a broad number of use cases, I wonder:

  • Will OPA sometimes need to load the user anyway for other information?
  • Would the potentially saved network request be meaningful? My experience with authorization is that a decision can require bits of context about the user, the target resource, and even related resources. Pushing the decision into an external service could require loading a lot of context into that service.
  • What if roles change? Effective user moderation sometimes involves revoking or suspending key privileges, and enforcement should not wait for the user's session to expire or reauthenticate.
  • OPA needs to have enough data to make a decision, that is it. Of course, that requires extra logic which keeps OPA "cache" updated when a role or other decision critical data is changed.
  • In my case, all token details verifications are done on API gateway, that means when token passes API Gateway it can be treated as trusted. I agree that such an approach exposes some potential internal attack surfaces.
  • If decision-making data has been changed we just update OPA "cache", if token itself was revoked we should not pass such requests (in my case API gateway does it, but we can make service mesh verify that or use any other means).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants