[
https://issues.apache.org/jira/browse/KNOX-2149?focusedWorklogId=360623&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-360623
]
ASF GitHub Bot logged work on KNOX-2149:
----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Dec/19 00:45
Start Date: 17/Dec/19 00:45
Worklog Time Spent: 10m
Work Description: risdenk commented on pull request #216: KNOX-2149 -
JWTTokenProvider - JWT verification with OIDC provider by invoking JWKS
verification url
URL: https://github.com/apache/knox/pull/216#discussion_r358540112
##########
File path:
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AbstractJWTFilter.java
##########
@@ -223,38 +239,60 @@ else if (t instanceof ServletException) {
}
}
}
-
protected Subject createSubjectFromToken(JWT token) {
- final String principal = token.getSubject();
+ String principal = token.getSubject();
+ String claimvalue = null;
+ if (expectedPrincipalClaim != null) {
+ claimvalue = token.getClaim(expectedPrincipalClaim);
+ }
+ if (claimvalue != null) {
+ principal = claimvalue.toLowerCase(Locale.ROOT);
+ }
@SuppressWarnings("rawtypes")
HashSet emptySet = new HashSet();
Set<Principal> principals = new HashSet<>();
Principal p = new PrimaryPrincipal(principal);
principals.add(p);
// The newly constructed Sets check whether this Subject has been set
read-only
- // before permitting subsequent modifications. The newly created Sets also
prevent
+ // before permitting subsequent modifications. The newly created Sets also
+ // prevent
// illegal modifications by ensuring that callers have sufficient
permissions.
//
- // To modify the Principals Set, the caller must have
AuthPermission("modifyPrincipals").
- // To modify the public credential Set, the caller must have
AuthPermission("modifyPublicCredentials").
- // To modify the private credential Set, the caller must have
AuthPermission("modifyPrivateCredentials").
+ // To modify the Principals Set, the caller must have
+ // AuthPermission("modifyPrincipals").
+ // To modify the public credential Set, the caller must have
+ // AuthPermission("modifyPublicCredentials").
+ // To modify the private credential Set, the caller must have
+ // AuthPermission("modifyPrivateCredentials").
return new Subject(true, principals, emptySet, emptySet);
}
- protected boolean validateToken(HttpServletRequest request,
HttpServletResponse response,
- FilterChain chain, JWT token)
- throws IOException, ServletException {
+ protected boolean validateToken(HttpServletRequest request,
HttpServletResponse response, FilterChain chain,
+ JWT token) throws IOException, ServletException {
boolean verified = false;
+
try {
- if (publicKey == null) {
- verified = authority.verifyToken(token);
- }
- else {
+ if (publicKey != null) {
verified = authority.verifyToken(token, publicKey);
+ } else if (expectedJWKSUrl != null) {
+ JWSAlgorithm expectedJWSAlg = JWSAlgorithm.parse(expectedSigAlg);
+ JWKSource<SecurityContext> keySource = new RemoteJWKSet<>(new
URL(expectedJWKSUrl));
+ JWSKeySelector<SecurityContext> keySelector = new
JWSVerificationKeySelector<>(expectedJWSAlg, keySource);
+ // Create a JWT processor for the access tokens
+ ConfigurableJWTProcessor<SecurityContext> jwtProcessor = new
DefaultJWTProcessor<>();
+ jwtProcessor.setJWSKeySelector(keySelector);
+ JWTClaimsSetVerifier<SecurityContext> claimsVerifier = new
DefaultJWTClaimsVerifier<>();
+ jwtProcessor.setJWTClaimsSetVerifier(claimsVerifier);
+ // Process the token
+ SecurityContext ctx = null; // optional context parameter, not
required here
+ jwtProcessor.process(token.toString(), ctx);
+ verified = true;
Review comment:
So I think there is a misunderstanding here between my last comment and
current set of code.
I would have expected something like the following:
`verified = authority.verifyToken(token, url);`
Where the specifics are delegated down to the `JWTokenAuthority` instead of
trying to have the `AbstractJWTFilter` handle all of this. I would expect very
little to be verified directly here.
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 360623)
Time Spent: 5h 40m (was: 5.5h)
> Knox JWTTokenProvider - JWT verification with OIDC provider by invoking JWKS
> verification url
> ---------------------------------------------------------------------------------------------
>
> Key: KNOX-2149
> URL: https://issues.apache.org/jira/browse/KNOX-2149
> Project: Apache Knox
> Issue Type: New Feature
> Components: KnoxSSO
> Reporter: Saravanan Sathyamoorthy
> Assignee: Neeraj Verma
> Priority: Major
> Time Spent: 5h 40m
> Remaining Estimate: 0h
>
> Current capability in Apache Knox -
> Knox has pac4j provider
> ([https://knox.apache.org/books/knox-0-12-0/user-guide.html#Pac4j+Provider+-+CAS+/+OAuth+/+SAML+/+OpenID+Connect])
> that provides OIDC support (
> [https://knox.apache.org/books/knox-0-12-0/user-guide.html#For+OpenID+Connect+support:])
> However this only works for UI applications.
> For REST API -> we need to use JWT token provider (
> [https://knox.apache.org/books/knox-0-12-0/user-guide.html#JWT+Provider])
> that takes .pem file ( certificate with public key to decrypt the token) as
> argument.
> Implementation class ->
> [https://github.com/apache/knox/blob/master/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java]
> - takes (public static final String SSO_VERIFICATION_PEM =
> "sso.token.verification.pem" ) as argument.
> This .pem file is parsed to get the public key to validate the token.
> // token verification pem
> String verificationPEM =
> filterConfig.getInitParameter(SSO_VERIFICATION_PEM);
> // setup the public key of the token issuer for verification
> if (verificationPEM != null) {
> publicKey = CertificateUtils.parseRSAPublicKey(verificationPEM);
> }
>
> .Resolution:
> Option 1 - We can change the code to pass the public key and use it for
> token validation. Down side is every time we change the key there should be a
> Knox config change.
> Option 2 - We can change the code to pass the JWKS verification url and if a
> key is changed - no knox config change is required. Change done to support
> using JWKS verification url to validate the token :
> We selected Option 2 to make things more robust.
> Class JWTFederationFilter was changed to get an additional parameter (JWKS
> verification url) and code to use this url to get the public key and then use
> this to validate the token. This approach will make it easy to maange for key
> rotation.
> Library used is - [https://github.com/okta/okta-jwt-verifier-java]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)