Skip to content

[ELY-2903] skip nonce check on oidc client refresh. Check nonce on oi…#2277

Closed
rsearls wants to merge 1 commit intowildfly-security:2.xfrom
rsearls:ELY-2903-refresh-tokens-skip-nonce
Closed

[ELY-2903] skip nonce check on oidc client refresh. Check nonce on oi…#2277
rsearls wants to merge 1 commit intowildfly-security:2.xfrom
rsearls:ELY-2903-refresh-tokens-skip-nonce

Conversation

@rsearls
Copy link
Copy Markdown
Contributor

@rsearls rsearls commented Apr 22, 2025

…dc request authentication

https://issues.redhat.com/browse/ELY-2903

@rsearls rsearls requested review from fjuma and skyllarr as code owners April 22, 2025 19:47
try {
TokenValidator tokenValidator = TokenValidator.builder(clientConfiguration).build();
TokenValidator.VerifiedTokens verifiedTokens = tokenValidator.parseAndVerifyToken(idTokenString, accessTokenString, cookie);
TokenValidator.VerifiedTokens verifiedTokens = tokenValidator.parseAndVerifyToken(idTokenString, accessTokenString, cookie, false);
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.

With the approach I mentioned below, we could leave this unchanged (and the nonce won't get validated).

Copy link
Copy Markdown
Contributor

@fjuma fjuma left a comment

Choose a reason for hiding this comment

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

We should add a test case for the refresh token case to validate this fix.

@fjuma
Copy link
Copy Markdown
Contributor

fjuma commented Apr 22, 2025

@rsearls Just to check, were you able to reproduce the issue with Keycloak?

@rsearls rsearls force-pushed the ELY-2903-refresh-tokens-skip-nonce branch from 504e217 to ddcdf0e Compare April 22, 2025 20:06
}

public VerifiedTokens parseAndVerifyToken(final String idToken, final String accessToken,
OidcHttpFacade.Cookie cookie) throws OidcException {
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.

Just realized, I guess the cookie is something that is specifically used for the nonce validation case, right? So perhaps there's some more cleanup that would be good to do so this method would just need to take the idToken and accessToken.

Looking back at the original PR, RefreshableOidcSecurityContext was updated so that it was possible to pass it the session random value cookie but that's no longer needed now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@rsearls rsearls force-pushed the ELY-2903-refresh-tokens-skip-nonce branch from ddcdf0e to f1167c9 Compare April 22, 2025 21:26
Copy link
Copy Markdown
Contributor Author

@rsearls rsearls left a comment

Choose a reason for hiding this comment

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

requested changes pushed

}

public VerifiedTokens parseAndVerifyToken(final String idToken, final String accessToken,
OidcHttpFacade.Cookie cookie) throws OidcException {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@rsearls rsearls force-pushed the ELY-2903-refresh-tokens-skip-nonce branch from f1167c9 to 0157e01 Compare April 25, 2025 20:29
@rsearls
Copy link
Copy Markdown
Contributor Author

rsearls commented Apr 25, 2025

test case pushded

@rsearls rsearls force-pushed the ELY-2903-refresh-tokens-skip-nonce branch from 0157e01 to 71fa1b4 Compare April 28, 2025 20:50
private static final int ACCESS_TOKEN_LIFESPAN = 120;
private static final int SESSION_MAX_LIFESPAN = 120;
private static final int REFRESH_ACCESS_TOKEN_LIFESPAN = 10;
private static final int REFRESH_SESSION_MAX_LIFESPAN = 10;
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.

Just curious, is there a reason these low numbers are needed here if we are forcing the refresh to happen regardless?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Git CI was failing on every test platform due to time over run for this test.
With a lifespan of 120. testRefreshToken was taking 35sec to run and all the
tests in the file 2+mins. Reducing the lifespan for this test enabled the test file
to run in about 1.5 min.

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.

Do we know what was causing the test to take longer to run in that case? Because we're calling refreshToken with checkActive set to false, I'm just wondering why changing the access token lifespan would impact the test duration.

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.

I tried using a lifespan of 120 locally but I don't seem to see a significant difference in the overall time the test takes to run compared to when the lifespan is set to 10.

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.

I think we could try setting the lifespan back to 120 and see if the CI issue occurs. If it does, we can then take a closer look to see what's happening. I can't think of why the token lifespan would be affecting the test duration here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

another job has failed.
https://github.com/wildfly-security/wildfly-elytron/actions/runs/14781730898
This job just failed with 1 Bind Address already in use: NET_Bind (window-11)
All other jogs canceled (I'm assuming because none responsive)
I have restarted the job.

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.

Thanks, Rebecca. Yes, I see the bind address in use message in the tests. Thanks for re-triggering. We should create an ELY issue for this intermittent bind address problem on Windows. Looks like the tests that I've seen fail with this intermitent issue are ElytronAuthenticatorTest, MaskedPasswordSaslAuthenticationTest, JwtSecurityRealmTest, OAuth2SaslClientV10Test, and OAuth2SaslClientV11Test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't see this as an elytron issue. It's an issue with the github CI env. We see this type of failure in the middle of the (U.S.) day not in the morning or evening. Most likely the system is under heavy load at that time which causes communication delays. Perhaps we should discuss this with the github CI maintenance team first.

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.

I'm wondering if it could be related to something happening in a previous test where something doesn't get stopped/cleaned up in time before these tests start or something like that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is always a possibility. Most likely it would be very hard to find as the failures are random and not reproducable locally. Perhaps asking the performance team to evaluate elytron.

" \"" + REALM + "\" : \"" + TEST_REFRESH_REALM + "\",\n" +
" \"" + RESOURCE + "\" : \"" + CLIENT_ID + "\",\n" +
" \"" + PUBLIC_CLIENT + "\" : \"false\",\n" +
" \"" + AUTH_SERVER_URL + "\" : \"" + authServerUrl + "\",\n" +
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.

It would be good to use the client-id, provider-url configuration instead in this config.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}

public RefreshableOidcSecurityContext(OidcClientConfiguration clientConfiguration, OidcHttpFacade.Cookie cookie, OidcTokenStore tokenStore, String tokenString,
public RefreshableOidcSecurityContext(OidcClientConfiguration clientConfiguration, OidcTokenStore tokenStore, String tokenString,
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.

Just an FYI for other reviewers, this isn't public API.

@rsearls
Copy link
Copy Markdown
Contributor Author

rsearls commented May 1, 2025

Requested changes complete

OidcAccount account = (OidcAccount) session.getAttachment(OidcAccount.class.getName());
assertNotNull("No OidcAccount for token refresh", account);
RefreshableOidcSecurityContext refreshableContext = account.getOidcSecurityContext();
assertNotNull("No RefreshableOidcSecurityContext for token refresh", account);
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.

s/account/refreshableContext

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed

}
private InputStream getOidcRefreshConfigurationInputStream(String clientSecret, String authServerUrl) {
String oidcConfig = "{\n" +
" \"" + REALM + "\" : \"" + TEST_REALM + "\",\n" +
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.

The realm isn't needed here (since the provider-url is being specified and that contains the realm)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

@fjuma
Copy link
Copy Markdown
Contributor

fjuma commented May 1, 2025

Thanks @rsearls! This is looking good. You can go ahead and squash the commits. Thanks.

@rsearls rsearls force-pushed the ELY-2903-refresh-tokens-skip-nonce branch from 8890357 to 681cfcc Compare May 1, 2025 18:33
public static final String CLIENT_SECRET = "longerclientsecretthatisstleast256bitslong";
public static KeycloakContainer KEYCLOAK_CONTAINER;
public static final String TEST_REALM = "WildFly";
public static final String TEST_REFRESH_REALM = "WildFlyRefresh";
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.

Just one last small comment - if this is unused, it can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

@rsearls rsearls force-pushed the ELY-2903-refresh-tokens-skip-nonce branch from 681cfcc to dab06c1 Compare May 1, 2025 19:11
Copy link
Copy Markdown
Contributor

@fjuma fjuma left a comment

Choose a reason for hiding this comment

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

Thanks very much @rsearls!

@fjuma fjuma added the +1 FJ label May 1, 2025
@fjuma fjuma requested a review from darranl May 1, 2025 19:20
Copy link
Copy Markdown
Contributor

@darranl darranl left a comment

Choose a reason for hiding this comment

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

Hi @rsearls thank you for getting to the end of this one, as we need to include the fix in a couple of streams can you please send a PR to the 2.2.x branch and I will take it from there.

@rsearls
Copy link
Copy Markdown
Contributor Author

rsearls commented May 5, 2025

branch 2.2.x pr #2282

@skyllarr
Copy link
Copy Markdown
Contributor

skyllarr commented Jul 8, 2025

Hi @rsearls , just checking if this PR can be closed? Since it is resolved in 2.6.4.Final

@rsearls
Copy link
Copy Markdown
Contributor Author

rsearls commented Jul 8, 2025

closing as this was resolved in 2.6.4.Final

@rsearls rsearls closed this Jul 8, 2025
@rsearls
Copy link
Copy Markdown
Contributor Author

rsearls commented Jul 8, 2025 via email

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants