8000 Increase internal algorithm security using HS512 and 128 byte hmac keys by rmartinc · Pull Request #26957 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Increase internal algorithm security using HS512 and 128 byte hmac keys #26957

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

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

rmartinc
Copy link
Contributor

Closes #13080

PR that increase security in default internal algorithm (used by actions, refresh tokens,...). As discussed in the issue the default hmac size has been updated from 64 to 128 bytes and the internal algorithm has changed from HS256 to HS512. Things to consider:

  1. We can maintain default hmac size (64) and just increase the size for the initial provider. If you prefer this solution just let me know.
  2. The new HS512 internal key is called hmac-generated-hs512 instead of previous hmac-generated. I decided to do that to differentiate the provider names in migrations. But maybe we prefer to maintain the same name or rename old HS256 for compatibility.

It's just a draft for now. We also need to decide if we want this in keycloak 24 or we wait for 25. For the moment the upgrade task is for 24 but it can be moved to 25. An upgrading note commenting the final changes is also needed before moving out from draft.

Copy link
Contributor
@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

  • Added one nitpick comment.

  • Besides that, it seems that there are some conflicts in the meantime.

  • Did some search for the Algorithm.HS256 and found few more places using that as a default. Wonder if we should try to update those as well when we are at this? Some of the places I found (might missed some):

    • Attributes.HS_ALGORITHM_PROPERTY (This probably causes that HS256 is still pre-selected as the default algorithm in the UI for the configuration properties of some providers)
    • AbstractOAuth2IdentityProvider.getSignatureContext() - looks this one is also documented here https://www.keycloak.org/docs/latest/server_admin/index.html#_identity_broker_oidc (see "client assertion signature algorithm" section), so might change the docs too
    • CIBAAuthenticationRequest - but here I am not 100% sure if CIBA specification explicitly mentions HS256 should be the default, so might be good to doublecheck...
  • Do we also want to mention this a bit in changes-24_0_0.adoc ? It is internal in theory, but still can be nice to mention this, so people are aware

Finally, it may be probably good to add some minor update to

@rmartinc
Copy link
Contributor Author
  * `Attributes.HS_ALGORITHM_PROPERTY` (This probably causes that HS256 is still pre-selected as the default algorithm in the UI for the configuration properties of some providers)

I have changed to set HS512 as the default one now.

  * `AbstractOAuth2IdentityProvider.getSignatureContext()` - looks this one is also documented here https://www.keycloak.org/docs/latest/server_admin/index.html#_identity_broker_oidc (see "client assertion signature algorithm" section), so might change the docs too

I have not done this point. Changing this can break current configurations and this is really not related to internal keycloak signature. This is just using the client secret to create a JWT for the broker authentication, any other HS algorithm can be configured and it's an admin decision. If you think it's important I will do it but take in mind that configurations with no alg specified are changing from HS256 to HS512 and can break.

  * `CIBAAuthenticationRequest` - but here I am not 100% sure if CIBA specification explicitly mentions HS256 should be the default, so might be good to doublecheck...

Done! I have checked that this direct signature is used to create the auth_req_id which, in the spec, is just an ID. The problem with this change is that previous IDs will be invalid after migration (as the token is using direct JWE enc/sig) and a new authentication is needed. But this was thought with no idea of rating keys, so I just changed it anyway.

* Do we also want to mention this a bit in `changes-24_0_0.adoc` ? It is internal in theory, but still can be nice to mention this, so people are aware

Yep, for sure. I'll do when the other comments are OK.

Copy link
@keycloak-github-bot keycloak-github-bot bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.model.session.OfflineSessionPersistenceTest#testPersistenceMultipleNodesClientSessionsAtRandomNode

Keycloak CI - Store Model Tests

java.lang.AssertionError: Execution didn't complete: java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "org.keycloak.models.UserSessionModel.getStarted()" because "userSession" is null
	at org.junit.Assert.fail(Assert.java:89)
	at org.keycloak.testsuite.model.KeycloakModelTest.inIndependentFactories(KeycloakModelTest.java:428)
	at org.keycloak.testsuite.model.session.OfflineSessionPersistenceTest.testPersistenceMultipleNodesClientSessionsAtRandomNode(OfflineSessionPersistenceTest.java:208)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...

Report flaky test

@mposolda
Copy link
Contributor

@rmartinc Thanks for the updates! So perhaps only migration docs and then we're good to go?

@rmartinc
Copy link
Contributor Author

Done! I added a little upgrading section explaining we have changed from HS256 to HS512 for internal tokens. If tests are OK tomorrow will move it out of draft.

@mposolda mposolda requested a review from andymunro February 13, 2024 17:55
@mposolda
Copy link
Contributor

@andymunro Do you please have a chance to review the documentation part of this PR?

@mposolda mposolda self-assigned this Feb 13, 2024
@ahus1
Copy link
Contributor
ahus1 commented Feb 14, 2024

@kami619 - this change might (will?) affect Keycloak's performance.

Once this is merged and available in a nightly release, please keep an eye on the nightly KCB runs if we need to update our sizing guide. Please add a new issue to the Keycloak project so we can track this, and update that issues's milestone for KC24 or KC25 depending on when this is being merged. Thanks!

@kami619
Copy link
Contributor
kami619 commented Feb 14, 2024

@ahus1 thanks, I will track this.

@mposolda
Copy link
Contributor

@ahus1 @kami619 This is good point. Sorry we did not explicitly pinged you about this.

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

Successfully merging this pull request may close these issues.

Encoded token stored as KC_RESTART cookie uses weak algorithm- HS256
5 participants
0