Skip to content

Conversation

@cwperks
Copy link
Member

@cwperks cwperks commented May 30, 2023

Re-creating #2708 with the jar hell fix merged into main and addressing 2 minor comments from the PR.

Description

Extending auth with jwks_uri parameter to omit passing openid_connect_url with openid-configuration

  • Category: feature
  • Why these changes are required? To add possibility to define a JWKS endpoint for JWT-based authentication
  • What is the old behavior before changes and new behavior after changes? Old behavior remains the same, new one omits the part with calling openid-configuration endpoint of IdP

Issues Resolved

#1858

Check List

  • New functionality includes testing
  • Commits are signed per the DCO using --signoff

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.

sebastianmichalski and others added 3 commits May 29, 2023 09:46
Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>

KeySetRetriever keySetRetriever = new KeySetRetriever(settings.get("openid_connect_url"),
getSSLConfig(settings, configPath), settings.getAsBoolean("cache_jwks_endpoint", false));
var jwksUri = settings.get("jwks_uri");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want strongly typed where possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched this to String

static final JwtToken MC_COY_EXPIRED = create(MCCOY_SUBJECT, TEST_AUDIENCE, ROLES_CLAIM, TEST_ROLES_STRING, JwtConstants.CLAIM_EXPIRY, 10);
static final JwtToken MC_COY = create(MCCOY_SUBJECT, TEST_AUDIENCE, TEST_ISSUER, ROLES_CLAIM, TEST_ROLES_STRING);

static final JwtToken MC_COY_2 = create(MCCOY_SUBJECT, TEST_AUDIENCE, TEST_ISSUER, ROLES_CLAIM, TEST_ROLES_STRING);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you make a second identical token? It does not look it is every compared to MC_COY so it seems like any tests using MC_COY_SIGNED_OCT_2 could just use MC_COY_SIGNED_OCT_1? Perhaps I am misreading things?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like the intention was that it was signed with a larger octet key, but it was not being configured correctly down below. I updated it now to ensure its using TestJwk.OCT_2 as expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

These Jwks are originally used for SelfRefreshingKeySetTest and are being re-purposed for these tests.

Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

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

Should we close the other PR then?

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Member Author

cwperks commented May 30, 2023

@DarshitChanpura Yes, the other PR should be closed unless there are any substantial changes requested in the review.

@cwperks
Copy link
Member Author

cwperks commented May 30, 2023

Looking at the test failures

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Member Author

cwperks commented May 30, 2023

I just pushed a fix for the tests. There were 2 issues:

  1. JWTVerifier was not doing a null/empty check before checking if required issuer or required audience settings matches. It would always try to compare against an unset value instead of checking if the setting was set before performing the validation.
  2. A new claim was added to MCCOY_SUBJECT so the count of attributes needed to be incremented in most tests of SingleKeyHTTPJwtKeyByOpenIdConnectAuthenticatorTest.

@DarshitChanpura
Copy link
Member

DarshitChanpura commented May 30, 2023

Looks like the tests are still failing😥.

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Member Author

cwperks commented May 30, 2023

@DarshitChanpura I pushed another commit to fix tests. I created more TestJwts to make it more obvious what the usage of each TestJwt was by giving them a clearer name which resembles the test case they are used for.

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Merging #2808 (8ca5c52) into main (9be79bd) will increase coverage by 0.12%.
The diff coverage is 91.42%.

@@             Coverage Diff              @@
##               main    #2808      +/-   ##
============================================
+ Coverage     61.48%   61.61%   +0.12%     
- Complexity     3401     3413      +12     
============================================
  Files           266      266              
  Lines         18865    18893      +28     
  Branches       3302     3305       +3     
============================================
+ Hits          11599    11640      +41     
+ Misses         5669     5656      -13     
  Partials       1597     1597              
Impacted Files Coverage Δ
...ic/auth/http/jwt/AbstractHTTPJwtAuthenticator.java 58.42% <60.00%> (+3.13%) ⬆️
...byoidc/HTTPJwtKeyByOpenIdConnectAuthenticator.java 90.00% <80.00%> (-4.12%) ⬇️
...azon/dlic/auth/http/jwt/keybyoidc/JwtVerifier.java 88.67% <100.00%> (+2.63%) ⬆️
.../dlic/auth/http/jwt/keybyoidc/KeySetRetriever.java 78.94% <100.00%> (+2.75%) ⬆️

... and 2 files with indirect coverage changes

@DarshitChanpura DarshitChanpura merged commit 4b38671 into opensearch-project:main May 30, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 30, 2023
* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
(cherry picked from commit 4b38671)
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 30, 2023
* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
(cherry picked from commit 4b38671)
RyanL1997 pushed a commit that referenced this pull request May 30, 2023
* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)
---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
(cherry picked from commit 4b38671)

Co-authored-by: Craig Perkins <cwperx@amazon.com>
cwperks added a commit that referenced this pull request May 31, 2023
* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
(cherry picked from commit 4b38671)

Co-authored-by: Craig Perkins <cwperx@amazon.com>
RyanL1997 pushed a commit to RyanL1997/security that referenced this pull request Jun 9, 2023
…ject#2808)

* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
MaciejMierzwa pushed a commit to MaciejMierzwa/security that referenced this pull request Jun 13, 2023
…ject#2808)

* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
MaciejMierzwa pushed a commit to MaciejMierzwa/security that referenced this pull request Jun 13, 2023
…ject#2808)

* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
RyanL1997 pushed a commit to RyanL1997/security that referenced this pull request Jun 13, 2023
…ject#2808)

* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
samuelcostae pushed a commit to samuelcostae/security that referenced this pull request Jun 19, 2023
…ject#2808)

* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
samuelcostae pushed a commit to samuelcostae/security that referenced this pull request Jun 19, 2023
…ject#2808)

* [FEATURE] usage of JWKS with JWT (w/o OpenID connect)

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>

* Change issuer to audience

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Switch to OCT_2 and use String instead of var

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Only check required issuer and required audience if set

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Fix test cases

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused import

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Sebastian Michalski <shekerama@gmail.com>
Signed-off-by: Sam <samuel.costa@eliatra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.8 Backport to 2.8 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants