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

Impl: JWT claim authorization #4167

Merged
merged 32 commits into from
Sep 24, 2024

Conversation

zhaohuabing
Copy link
Member

@zhaohuabing zhaohuabing commented Sep 6, 2024

Implementation for: #4009
Related issue: #3367

This PR also changes the default value ofPayloadInMetada of the JWT filter from JwtProvider.Issuer to JwtProvider.Name as JwtProvider.Issuer is optional and we need the metadata in the authorization.

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing requested a review from a team as a code owner September 6, 2024 07:40
@zhaohuabing zhaohuabing marked this pull request as draft September 6, 2024 07:40
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 90.40000% with 24 lines in your changes missing coverage. Please review.

Project coverage is 65.90%. Comparing base (e5fe849) to head (ccba224).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
internal/xds/translator/authorization.go 90.20% 13 Missing and 11 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4167      +/-   ##
==========================================
+ Coverage   65.75%   65.90%   +0.15%     
==========================================
  Files         197      197              
  Lines       23565    23762     +197     
==========================================
+ Hits        15494    15661     +167     
- Misses       6967     6986      +19     
- Partials     1104     1115      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing marked this pull request as ready for review September 10, 2024 09:27
Copy link
Contributor

@zetaab zetaab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit, but I am also thinking that which JWT this is now going to use? There is use-case for both access_token and id_token. Is there way to specify which one it should use?

examples/kubernetes/http-routing.yaml Outdated Show resolved Hide resolved
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing
Copy link
Member Author

one nit, but I am also thinking that which JWT this is now going to use? There is use-case for both access_token and id_token. Is there way to specify which one it should use?

It's up to you. A JWT provider must be defined in the JWT configuration within the same SecurityPolicy.

If we want to use the ID Token retreived from the OIDC, we need to modify the OAuth2 filter to allow it to add the ID Token in the headers.

@zhaohuabing zhaohuabing requested a review from zetaab September 11, 2024 01:35
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zetaab
Copy link
Contributor

zetaab commented Sep 11, 2024

I can get this working with idtoken by following configuration (it verifies sub AND that I have some single group that is needed... just for testing)

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
  name: demo-api-jwt
  namespace: demo
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: demo-api
  jwt:
    providers:
    - name: cognito
      extractFrom:
        cookies:
        - IdToken
      claimToHeaders:
      - claim: sub
        header: x-sub
      - claim: custom:jobtitle
        header: x-jobtitle
      - claim: custom:department
        header: x-department
      - claim: email
        header: x-email
      - claim: cognito:groups
        header: x-groups
      - claim: name
        header: x-name
      remoteJWKS:
        uri: https://cognito-idp.eu-central-1.amazonaws.com/xxx/.well-known/jwks.json
  authorization:
    defaultAction: Deny
    rules:
    - action: Allow
      principal:
        jwt:
          provider: cognito
          claims:
          - name: sub
            values: [ca28333f-177f-4b7a-90c3-snip]
          - name: cognito:groups
            valueType: StringArray
            values: [AAD_FOOBAR]

great job @zhaohuabing

@zhaohuabing
Copy link
Member Author

I can get this working with idtoken by following configuration (it verifies sub AND that I have some single group that is needed... just for testing)
@zetaab Thanks for verifying it!

@zetaab
Copy link
Contributor

zetaab commented Sep 16, 2024

@arkodg do you have idea who could get progress in this PR? its waiting for review

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing requested a review from arkodg September 20, 2024 04:17
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg arkodg requested review from a team and removed request for zetaab September 23, 2024 23:07
@zhaohuabing zhaohuabing merged commit 8dfd151 into envoyproxy:main Sep 24, 2024
27 checks passed
@zhaohuabing zhaohuabing deleted the jwt-claim-auth-impl branch September 24, 2024 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants