8000 Use policy iterations in Argon2 policyCheck by ahus1 · Pull Request #55027 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Use policy iterations in Argon2 policyCheck - #55027

Merged
ahus1 merged 1 commit into
keycloak:mainfrom
ahus1:is-53633-argon2-policy-iterations
Nov 11, 2026
Merged

ahus1 merged 1 commit into
keycloak:mainfrom
ahus1:is-53633-argon2-policy-iterations

Conversation

@ahus1
@ahus1 ahus1 commented Nov 11, 2026 •
Copy link
Copy Markdown
Member

Closes #53633

First part of the split of #53742. The overwrite of a concurrently changed credential is tracked in #55028.

Decisions and assumptions

  • policyCheck follows encodedCredential, not the other way around, so the existing rule stays: policy iterations of 100 or less are used, anything above is assumed to be meant for PBKDF2 and ignored.
  • Hashes that were created with a non-default policy iteration count are no longer re-hashed on login. Hashes that don't match the current policy still are.
  • The tests are in the new test framework. testArgon2 moved from the Arquillian PasswordHashingTest into the same class, and validates the password through the credential manager instead of the login form, as the form is not specific to Argon2.
  • A re-hash is detected by changed secret data, as every hash uses a new random salt.
  • Only the test for matching policy iterations fails without the fix. The others guard the surrounding behavior.

Based on the work of @d53dave in #53742.

Closes keycloak#53633

Co-authored-by: David Sere <dse@tuta.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Copilot AI left a comment
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.

🟢 Approval recommended

No active review issues block the change aligning Argon2 policy checks with hash-creation iteration rules.

No open issues 🎉

What changed in this PR

This PR aligns Argon2 policy checks with the iteration rules used when creating password hashes, preventing unnecessary re-hashing when a hash already matches the realm policy. The concurrent credential-overwrite issue remains separately tracked in #55028.

Changes:

  • Share iteration selection between policyCheck and encodedCredential, preserving the provider fallback for unset values or values above 100.
  • Add regression coverage for matching and changed policies, default iterations, and migration from PBKDF2.
  • Move the existing Argon2 test into the new test framework, using credential-manager validation.
File Description
testsuite/​integration-arquillian/​tests/​base/​src/​test/​java/​org/​keycloak/​testsuite/​forms/​PasswordHashingTest.java Remove the migrated Argon2 test and unused imports.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​model/​Argon2PasswordHashTest.java Cover Argon2 defaults, password validation, and policy-driven re-hashing.
crypto/​default/​src/​main/​java/​org/​keycloak/​crypto/​hash/​Argon2PasswordHashProvider.java Unify iteration selection for hashing and policy checks; clarify documentation.

Review effort: Balanced

@mabartos mabartos left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ahus1 I haven't spotted any issue. LGTM, thanks!

@ahus1
ahus1 marked this pull request as ready for review November 11, 2026 12:57
@ahus1
ahus1 requested review from a team as code owners November 11, 2026 12:57
8000
@ahus1
ahus1 enabled auto-merge (squash) November 11, 2026 12:57
@mposolda mposolda left a comment
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.

Approving on behalf of @mabartos review

@ahus1
ahus1 merged commit 8cd27e8 into keycloak:main Nov 11, 2026
96 checks passed
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.

Argon2 policyCheck ignores realm hashIterations, so every login triggers a password re-hash

4 participants

0