Skip to content

[feat][authentication] Add JWKS support for AuthenticationProviderToken - #18336

Closed
nodece wants to merge 1 commit into
apache:masterfrom
nodece:authentication-provider-jwks
Closed

[feat][authentication] Add JWKS support for AuthenticationProviderToken#18336
nodece wants to merge 1 commit into
apache:masterfrom
nodece:authentication-provider-jwks

Conversation

@nodece

@nodece nodece commented Nov 4, 2022

Copy link
Copy Markdown
Member

Motivation

Add JWKS support for AuthenticationProviderToken.

Modifications

  • Add tokenKeySet config to provide the JWKS support

Verifying this change

  • Added RSA test
  • Added EC test

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: nodece#11

@nodece nodece added this to the 2.12.0 milestone Nov 4, 2022
@github-actions github-actions Bot added the doc-required Your PR changes impact docs and you will update later. label Nov 4, 2022
@nodece

nodece commented Nov 4, 2022

Copy link
Copy Markdown
Member Author

/pulsarbot rerun-failure-checks

@codecov-commenter

codecov-commenter commented Nov 22, 2022

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.48%. Comparing base (68ca60c) to head (7ed2770).
⚠️ Report is 3187 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18336      +/-   ##
============================================
- Coverage     50.05%   46.48%   -3.58%     
+ Complexity    11024    10441     -583     
============================================
  Files           703      703              
  Lines         68814    68816       +2     
  Branches       7378     7377       -1     
============================================
- Hits          34446    31986    -2460     
- Misses        30621    33219    +2598     
+ Partials       3747     3611     -136     
Flag Coverage Δ
unittests 46.48% <ø> (-3.58%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 117 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rdhabalia rdhabalia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this PR is adding new feature and it should go through PIP.

@codelipenghui

Copy link
Copy Markdown
Contributor

this PR is adding new feature and it should go through PIP.

+1

@nodece Could you please start a proposal for this change?

@nodece

nodece commented Dec 7, 2022

Copy link
Copy Markdown
Member Author

this PR is adding new feature and it should go through PIP.

Thanks.

Let me make a PIP.

if (bytes == null || bytes.length == 0) {
throw new IOException("invalid JWKs data");
}
json = new String(AuthTokenUtils.readKeyFromUrl(data), StandardCharsets.UTF_8);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why call this function AuthTokenUtils.readKeyFromUrl(data) again?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. Here should be bytes.

return AuthTokenUtils.decodePublicKey(validationKey, publicKeyAlg);
} else {
throw new IOException("No secret key was provided for token authentication");
return null;

@tuteng tuteng Dec 7, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's the third case, it seems like it should be considered adding it to the if branch of the readKeyFromUrl, which is essentially where the public key is read (file, string or an http host)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See lines 158-162.

This method just gets the public or secret key. When returns null, we read the JWKS data.

}
}

private static final class TokenSigningKeyResolver implements SigningKeyResolver {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the TokenSigningKeyResolver should be called in the readKeyFromUrl function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See line 491.

data is a file path or data-url.

@nodece
nodece force-pushed the authentication-provider-jwks branch from 9dfe47c to 7ed2770 Compare December 8, 2022 03:06
@github-actions

Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions Bot added the Stale label Jan 23, 2023
@nodece

nodece commented Feb 14, 2023

Copy link
Copy Markdown
Member Author

Ping @michaeljmarshall, could you track this PR?

@github-actions github-actions Bot removed the Stale label Feb 15, 2023
String kid = node.get("kid").textValue();
KeyFactory kf;
// Reference from:
// https://github.com/auth0/jwks-rsa-java/blob/0.21.2/src/main/java/com/auth0/jwk/Jwk.java#L176

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason we cannot use this library directly instead of copying the code here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We just use the Jwk class, and don't want to introduce the other dependency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The license might require that we change this PR: https://github.com/auth0/jwks-rsa-java/blob/0.21.2/LICENSE.

@dave2wave - are you able to provide any guidance on the licensing aspect here? Thanks!

@michaeljmarshall michaeljmarshall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#8152 asks for support to rotate public keys and to load new public keys "on the fly". This PR appears to add support for loading multiple public keys on start up, but it does not provide support for rotation or dynamic loading. Is that correct? If so, I don't think we should say this PR fixes #8152.

@nodece

nodece commented Feb 15, 2023

Copy link
Copy Markdown
Member Author

#8152 asks for support to rotate public keys and to load new public keys "on the fly". This PR appears to add support for loading multiple public keys on start up, but it does not provide support for rotation or dynamic loading. Is that correct? If so, I don't think we should say this PR fixes #8152.

You are right, I think we can listener to the file changes.

@michaeljmarshall michaeljmarshall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes while we determine the licensing portion of this PR.

String kid = node.get("kid").textValue();
KeyFactory kf;
// Reference from:
// https://github.com/auth0/jwks-rsa-java/blob/0.21.2/src/main/java/com/auth0/jwk/Jwk.java#L176

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The license might require that we change this PR: https://github.com/auth0/jwks-rsa-java/blob/0.21.2/LICENSE.

@dave2wave - are you able to provide any guidance on the licensing aspect here? Thanks!

@github-actions

Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions Bot added the Stale label Mar 18, 2023
@poorbarcode poorbarcode modified the milestones: 3.0.0, 3.1.0 Apr 10, 2023
@nodece

nodece commented Jul 7, 2023

Copy link
Copy Markdown
Member Author

Closing this PR with #19849.

@nodece

nodece commented Mar 7, 2024

Copy link
Copy Markdown
Member Author

Use #22215 instead of this PR.

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

Labels

area/authn doc-required Your PR changes impact docs and you will update later. ready-to-test Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants