Fix EC JWKS authentication support#6106
Fix EC JWKS authentication support#6106wheresNasha wants to merge 1 commit intoopensearch-project:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6106 +/- ##
==========================================
+ Coverage 74.78% 74.81% +0.03%
==========================================
Files 447 447
Lines 28428 28478 +50
Branches 4318 4332 +14
==========================================
+ Hits 21260 21307 +47
- Misses 5172 5177 +5
+ Partials 1996 1994 -2
🚀 New features to boost your workflow:
|
|
@wheresNasha Can you please fix the Code Hygiene errors? Run |
| if (key.getClass() == OctetSequenceKey.class) { | ||
| if (key instanceof OctetSequenceKey) { | ||
| result = new DefaultJWSVerifierFactory().createJWSVerifier(jwt.getHeader(), key.toOctetSequenceKey().toSecretKey()); | ||
| } else if (key instanceof RSAKey) { |
There was a problem hiding this comment.
Can we write tests to hit all of these branches?
There was a problem hiding this comment.
I have already addded test coverage for the missing EC (ECKey) branch here.
I also looked into adding OCT (OctetSequenceKey) coverage, but the current JWKS authentication flow does not appear to successfully authenticate symmetric OCT keys in the existing test infrastructure (extractCredentials() returns null), so that test is currently failing.
RSA coverage is already present, so this PR focuses on covering the missing EC path.
| .createJWSVerifier(jwt.getHeader(), key.toECKey().toECPublicKey()); | ||
| } else { | ||
| result = new DefaultJWSVerifierFactory().createJWSVerifier(jwt.getHeader(), key.toRSAKey().toRSAPublicKey()); | ||
| throw new IllegalArgumentException("Unsupported JWK key type: " + key.getClass()); |
There was a problem hiding this comment.
Not sure if it makes sense but should we keep the fallback logic in place?
Any idea what the entire universe of key types can be?
There was a problem hiding this comment.
I leaned toward explicit key type handling here since failing closed felt safer than broadly falling back and potentially masking unsupported JWK types.
From what I understand, Nimbus JWK currently supports symmetric (oct), RSA, EC, and additional types like OKP.
If preserving backward compatibility with prior RSA fallback makes more sense here, I’m happy to adjust it.
Signed-off-by: Sakshi Nasha <sakshinasha11@gmail.com>
cbae25a to
4143730
Compare
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
@cwperks Thanks for the helpful guidance! Please let me know your thoughts, and if everything looks good from your side, I can rebase the branch. |
Description
This PR fixes EC-based JWKS authentication support as part of issue #6045.
EC-based JWT verification using JWKS was not handled correctly, leading to authentication failures for EC-signed tokens.
Old behavior:
EC-signed JWTs using JWKS could fail validation due to missing or incorrect key handling.
New behavior:
EC JWKS keys are now properly parsed and used for JWT verification, enabling successful authentication for EC-signed tokens.
Issues Resolved
Fixes #6045
Is this a backport? If so, please add backport PR # and/or commits #, and remove
backport-failedlabel from the original PR.Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end? If so, please open a draft PR in the security dashboards plugin and link the draft PR here
Testing
Validated locally using EC-signed JWTs with JWKS
Tested token verification flow end-to-end
Confirmed backward compatibility with existing RSA-based flows
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.