-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce OIDC code flow access token verification only if JWT is in the application code #39718
Merged
sberyozkin
merged 1 commit into
quarkusio:main
from
sberyozkin:oidc_code_flow_access_token_for_custom_packages
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...oidc/deployment/src/test/java/io/quarkus/oidc/test/CodeFlowVerifyAccessTokenDisabled.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.oidc.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.gargoylesoftware.htmlunit.SilentCssErrorHandler; | ||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.gargoylesoftware.htmlunit.html.HtmlForm; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.keycloak.server.KeycloakTestResourceLifecycleManager; | ||
|
||
@QuarkusTestResource(KeycloakTestResourceLifecycleManager.class) | ||
public class CodeFlowVerifyAccessTokenDisabled { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the "Test" in the class name? |
||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(ProtectedResourceWithoutJwtAccessToken.class) | ||
.addAsResource("application-verify-access-token-disabled.properties", "application.properties")); | ||
|
||
@Test | ||
public void testVerifyAccessTokenDisabled() throws IOException, InterruptedException { | ||
try (final WebClient webClient = createWebClient()) { | ||
|
||
HtmlPage page = webClient.getPage("http://localhost:8081/protected"); | ||
|
||
assertEquals("Sign in to quarkus", page.getTitleText()); | ||
|
||
HtmlForm loginForm = page.getForms().get(0); | ||
|
||
loginForm.getInputByName("username").setValueAttribute("alice"); | ||
loginForm.getInputByName("password").setValueAttribute("alice"); | ||
|
||
page = loginForm.getInputByName("login").click(); | ||
|
||
assertEquals("alice:false", page.getBody().asNormalizedText()); | ||
|
||
webClient.getCookieManager().clearCookies(); | ||
} | ||
} | ||
|
||
private WebClient createWebClient() { | ||
WebClient webClient = new WebClient(); | ||
webClient.setCssErrorHandler(new SilentCssErrorHandler()); | ||
return webClient; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...deployment/src/test/java/io/quarkus/oidc/test/ProtectedResourceWithoutJwtAccessToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.oidc.test; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.jwt.JsonWebToken; | ||
|
||
import io.quarkus.oidc.IdToken; | ||
import io.quarkus.oidc.runtime.OidcConfig; | ||
import io.quarkus.security.Authenticated; | ||
|
||
@Path("/protected") | ||
@Authenticated | ||
public class ProtectedResourceWithoutJwtAccessToken { | ||
|
||
@Inject | ||
@IdToken | ||
JsonWebToken idToken; | ||
|
||
@Inject | ||
OidcConfig config; | ||
|
||
@GET | ||
public String getName() { | ||
return idToken.getName() + ":" + config.defaultTenant.authentication.verifyAccessToken; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ns/oidc/deployment/src/test/resources/application-verify-access-token-disabled.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus | ||
quarkus.oidc.client-id=quarkus-web-app | ||
quarkus.oidc.credentials.secret=secret | ||
quarkus.oidc.application-type=web-app |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OIDC Token propagation line basically says that we register filters that are not actually used while we have all build time information:
JsonWebToken
is actually injected inside bean used by the application (by actively used JAX-RS filter), then it should use verified JWT?As for SmallRye JWT package unfortunately I don't know it well enough, but to have unused beans registered by default surprises me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik
This is only available in the Resteasy Classic based optional filter which as far as I know noone has used, this is why I did not make the same feature available in the reactive propagation filter. That feature is about using a JWT build API to construct a new JWT token from the coming JWT token and then resigning it with the new key, setting a new audience. But users never used it because the token propagation supports the token exchange grants.
So this check is just to avoid that unused feature interfering, IMHO it is not worth the effort and start checking at the quarkus-oidc level if that filter is used given that filter is also expected to work with smallrye-jwt.
If it is meant to be propagated then not really, we won't use for any security decisions locally and users won't access it directly.
We are talking about this feature: https://quarkus.io/guides/security-openid-connect-client-reference#restclient-jsonwebtokenrequestfilter
As I said I haven' seen any evidence it being used, instead the exchange token grants are used to set a new audience, resign etc. And like I said, in cases where it is not enforced users can just enable with the property. But if resteasy easy client users will use that extension to propagate Google binary access token, it will cause a failure
because we will detect
JsonWebToken
- so if someone, theoretically at least, uses that feature, and wants to have it verified they can enable the verification, I suppose I can update the migration guide.That producer is probably 7 years old, it may have been myself or Scott who coded it, fair to say it is not the best CDI code written but we just should not let in interfere in this feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy that. Thanks for in detail explanation.