8000 Do the re-hash of password in a spearate transaction to continue login in case of model exception by rmartinc · Pull Request #39140 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Do the re-hash of password in a spearate transaction to continue login in case of model exception #39140

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
Apr 25, 2025

Conversation

rmartinc
Copy link
Contributor
@rmartinc rmartinc commented Apr 23, 2025

Closes #38970

The previous change in #26106 does not allow concurrent changes for the credential. This is normally OK but it can happen that login perform a re-hash when the realm policy has changed (manually or via migration). This is not a common situation but doing parallel logins in that circumstance can lead to ModelException in the login. This PR performs the re-hash in a separate transaction.

@mposolda @ahus1 WDYT?

Copy link
Contributor
@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

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

Thank you for this PR, the approach looks valid to me as the re-hashing of passwords is always a best-effort task. The approach with another DB transaction might increase the overhead a little bit, but it shouldn't be significant as the rehashing of passwords is a rare occurrence.

To make those attempts a bit more visible, I would like to log them as "info", still that is just my opinion on this.

Comment on lines 290 to 291
} catch (ModelException e) {
logger.debug("Error re-hasing the password in a different transaction", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} catch (ModelException e) {
logger.debug("Error re-hasing the password in a different transaction", e);
} catch (ModelException e) {
logger.info("Error re-hashing the password in a different transaction", e);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! And I have rebased too to incorporate fips changes. If tests go OK I will move this out of draft.

…n in case of model exception

Closes keycloak#38970

Signed-off-by: rmartinc <rmartinc@redhat.com>
@mhajas
Copy link
Contributor
mhajas commented Apr 24, 2025

@ahus1
Copy link
Contributor
ahus1 commented Apr 24, 2025

Thank you for this PR, the approach looks valid to me as the re-hashing of passwords is always a best-effort task.

Since this is a best-effort task would it make sense to perform this in background and not block the request processing while rehashing happens?

Since this is a best-effort task would it make sense to perform this in background and not block the request processing while rehashing happens?

I'd say it would make things more difficult to test, and again it is a rare occasion. We don't have any queue functionality today, and then we might limit the queue to avoid it to take many resources, we need to figure out how many threads should work on it ... so I'd rather keep it as is.

@ahus1 ahus1 self-assigned this Apr 24, 2025
@rmartinc
Copy link
Contributor Author

I have added backport to 26.2 for the issue. So I will provide PR for that branch when merged.

Copy link
Contributor
@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

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

Thank you for the change. Given the "+1" to my latest comment from @mhajas I assume this is good enough for merging.

@ahus1 ahus1 merged commit 6e66a7e into keycloak:main Apr 25, 2025
77 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.

Authentication request can fail with unknown_error
3 participants
0