-
Notifications
You must be signed in to change notification settings - Fork 91
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
Api specific backend jwt generation #1153
Conversation
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #1153 +/- ##
==========================================
- Coverage 34.20% 32.64% -1.57%
==========================================
Files 350 183 -167
Lines 40398 20829 -19569
Branches 12754 6736 -6018
==========================================
- Hits 13818 6799 -7019
+ Misses 26336 13905 -12431
+ Partials 244 125 -119
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
fb280f6
to
4474ca9
Compare
@@ -0,0 +1,34 @@ | |||
// Copyright (c) 2021, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright (c) 2021, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | |
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. |
string private_key_path = 11; | ||
|
||
int32 token_ttl = 12; | ||
int32 token_ttl = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did we keep it in the config, can't we move it to CR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no such field for ttl
under the jwt generator config. https://apim.docs.wso2.com/en/latest/deploy-and-publish/deploy-on-gateway/choreo-connect/passing-enduser-attributes-to-the-backend-via-choreo-connect/#enabling-the-default-backend-jwt-generator This value is populated in the code from some other config and kept under this jwt generator config. If it's needed, we can and support for api level ttl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we add it to cr?
//useKid becomes always false | ||
return JWTUtil.generateHeader(publicCert, signatureAlgorithm, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep it as it is till we fix the usekid properly
//useKid becomes always false | |
return JWTUtil.generateHeader(publicCert, signatureAlgorithm, false); | |
// TODO(benura) populate useKid accordingly, currently it's always false | |
return JWTUtil.generateHeader(publicCert, signatureAlgorithm, jwtConfigurationDto.useKid()); |
enabled = false | ||
encoding = "base64" # base64,base64url | ||
claimDialect = "http://wso2.org/claims" | ||
header = "X-JWT-Assertion" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no usage of this right? shall we remove it then?
@@ -0,0 +1,145 @@ | |||
/* | |||
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | |
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. |
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// APIPolicySpec defines the desired state of APIPolicy | ||
type APIPolicySpec struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we require this file, apipolicy type in test package? can't we remove this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have used this to unmarshal the policy yaml file in the test case
@@ -247,6 +247,9 @@ func CompareRequest(req *roundtripper.Request, cReq *roundtripper.CapturedReques | |||
if !ok { | |||
return fmt.Errorf("expected %s header to be set by the enforcer", name) | |||
} | |||
if actualVal == nil && actualVal[0] == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it a or condition?
if actualVal == nil && actualVal[0] == "" { | |
if actualVal == nil || actualVal[0] == "" { |
bool enabled = 1; | ||
string encoding = 2; | ||
string header = 3; | ||
string signingAlgorithm = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't we added custom claims?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we going to add these in JWT issuer level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it should come here. We were talking about adding claim mappings at the issuer level, not custom claims. They are 2 different features.
b12ed8b
to
bd0ca7b
Compare
bd0ca7b
to
2397f2d
Compare
Purpose
Define API Specific Backend JWT Token generation configs.
Issue
Goals
This removes the usage of
enforcer.jwtGenerator
property defined in the main config file and allows users to provide configurations individually for APIs rather than as a shared one.Approach
Added a new property for the
APIPolicy
to define the configurations. A sample will be as follows.Automation tests
Added an integration test to check whether the backend request is holding the JWT header defined in the configuration if token generation is allowed. Otherwise, that header should not be in the request.