Skip to content
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

Password policy change not forcing users to update password #14150

Open
wbauern opened this issue Sep 1, 2022 · 6 comments · May be fixed by giz-berlin/keycloak#1
Open

Password policy change not forcing users to update password #14150

wbauern opened this issue Sep 1, 2022 · 6 comments · May be fixed by giz-berlin/keycloak#1
Labels
area/authentication Indicates an issue on Authentication area kind/feature Categorizes a PR related to a new feature team/core-clients

Comments

@wbauern
Copy link

wbauern commented Sep 1, 2022

Describe the bug

The Keycloak 18/19 documentation states the following in the section on password policies:

After saving the policy, Keycloak enforces the policy for new users and sets an Update Password action for existing users to ensure they change their password the next time they log in.

This does not appear to work as stated. I tried it with both version 18 and 19 Keycloak servers freshly downloaded and running locally. I can create a new user with a password then add a new more restrictive password policy to the realm. The user can still log in with the original password and it does not present me with the update password form. If I create a new user the new password policy does apply correctly.

Am I missing some other configuration step for this feature or is this a defect?

Version

18.0.2 and 19.0.1

Expected behavior

After making the password policy more restrictive a user logging in with a noncompliant password would be forced to change their password after next login.

Actual behavior

The user logs in successfully but no change password form is presented.

How to Reproduce?

  1. Start with a new Keycloak 18 or 19 download.
  2. Create a new realm with no password policy.
  3. Add a user with a password of "password".
  4. Verify that the login works.
  5. Add a Requires 1 digit policy to the realm's password policy.
  6. Verify that the login still works and that no change password form is presented.
  7. Verify that the new password policy is in place when adding a new user.

Anything else?

No response

@wbauern wbauern added kind/bug Categorizes a PR related to a bug status/triage labels Sep 1, 2022
@stianst stianst added the area/authentication Indicates an issue on Authentication area label Sep 16, 2022
@mposolda mposolda added this to the 22.0.0 milestone Nov 24, 2022
@mposolda
Copy link
Contributor

Preliminary adding this to Keycloak 22 to doublecheck. On the other hand, it is possible that it would be postponed further.

If anyone from the community is able to fix this before, it will be welcome! Please comment here that you want to work on this issue. See "Contributors" section under https://www.keycloak.org/community for more details.

@thomas-riccardi
Copy link
Contributor

remark: implementing what the doc says is a end-user visible change, touching all users; it may useful to add a warning in the UI when saving the password policy change?

@pedro-hos
Copy link
Contributor

Hello, @mposolda I would like to try to work on this issue. I am thinking that the best approach is to check the password policies during the login time and if doesn't match, redirect to update the password. OR just letting the user know that the password isn't ok.

@mposolda mposolda modified the milestones: 22.0.0, Backlog Mar 27, 2023
@mposolda mposolda added kind/feature Categorizes a PR related to a new feature and removed kind/bug Categorizes a PR related to a bug labels Mar 27, 2023
@mposolda
Copy link
Contributor

I am sorry for the confusion around this. Keycloak never worked in a way that when password policy is added/updated, existing users are enforced to update their password during login. So the docs is incorrect about this. I've created separate issue to clearify the docs #19363 .

Also changed this to "Feature" as we can potentially improve this and make something to enforce behaviour for existing users. IMO it should be configurable somehow (not yet sure if at the authenticator configuration level or at the realm level - new option at password policies).

@sirkrypt0
Copy link
Contributor

Hi @pedro-hos did you already start working on this issue? Otherwise, I'd like to contribute this feature @mposolda . I agree that this should be made configurable at the realm level. Then, the PasswordCredentialProvider can validate the policies on each login similar to what it already does on credential creation:

PolicyError error = session.getProvider(PasswordPolicyManagerProvider.class).validate(realm, user, password);
if (error != null) throw new ModelException(error.getMessage(), error.getParameters());

@pedro-hos
Copy link
Contributor

Hi @sirkrypt0 No, you can go ahead and work on this. No problem, just confirm with @mposolda if it's ok also.

sirkrypt0 added a commit to giz-berlin/keycloak that referenced this issue May 14, 2024
Previously, Keycloak would only validate the password policy for new users and password
changes. However, it may be desired to force all existing users to update their passwords
when the password policy has changed.

To accomplish this, this adds a new ValidateOnLogin password policy that can be configured
per realm much like the existing password policies.
When this policy is present, the password of the user will be validated against the
current password policy on each login. This can be done for both, local users and users
in the LDAP.

Closes keycloak#14150

Signed-off-by: Tobias Kantusch <[email protected]>
@stianst stianst removed this from the Backlog milestone Jul 9, 2024
sirkrypt0 added a commit to giz-berlin/keycloak that referenced this issue Jul 30, 2024
Previously, Keycloak would only validate the password policy for new users and password
changes. However, it may be desired to force all existing users to update their passwords
when the password policy has changed.

To accomplish this, this adds a new ValidateOnLogin password policy that can be configured
per realm much like the existing password policies.
When this policy is present, the password of the user will be validated against the
current password policy on each login. This can be done for both, local users and users
in the LDAP.

When the LDAP is in read-only mode and the password no longer matches
the policy, an error is shown, but the user is not given the option to
update their password, as that doesn't work with read-only LDAP.
Administrators with a read-only LDAP are free to disable the policy on
login to avoid this.

Currently, users are only shown a generic error message that their
password no longer matches the policy, but not the exact error.
This is because I didn't find a way to properly pass the PolicyError up
to the authenticator which handles the password validation, as the
policy errors contain parameters (like minimum lower case chars) and
their error messages are localized based on the users locale.

Closes keycloak#14150

Signed-off-by: Tobias Kantusch <[email protected]>
sirkrypt0 added a commit to giz-berlin/keycloak that referenced this issue Jul 30, 2024
Previously, Keycloak would only validate the password policy for new users and password
changes. However, it may be desired to force all existing users to update their passwords
when the password policy has changed.

To accomplish this, this adds a new ValidateOnLogin password policy that can be configured
per realm much like the existing password policies.
When this policy is present, the password of the user will be validated against the
current password policy on each login. This can be done for both, local users and users
in the LDAP.

When the LDAP is in read-only mode and the password no longer matches
the policy, an error is shown, but the user is not given the option to
update their password, as that doesn't work with read-only LDAP.
Administrators with a read-only LDAP are free to disable the policy on
login to avoid this.

Currently, users are only shown a generic error message that their
password no longer matches the policy, but not the exact error.
This is because I didn't find a way to properly pass the PolicyError up
to the authenticator which handles the password validation, as the
policy errors contain parameters (like minimum lower case chars) and
their error messages are localized based on the users locale.

Closes keycloak#14150

Signed-off-by: Tobias Kantusch <[email protected]>
sirkrypt0 added a commit to giz-berlin/keycloak that referenced this issue Jul 30, 2024
Previously, Keycloak would only validate the password policy for new
users and password changes. However, it may be desired to force all
existing users to update their passwords when the password policy has
changed.

To accomplish this, this adds a new ValidateOnLogin password policy
that can be configured per realm much like the existing password
policies. When this policy is present, the password of the user will
be validated against the current password policy on each login. This
can be done for both, local users and users in the LDAP.

When the LDAP is in read-only mode and the password no longer matches
the policy, an error is shown, but the user is not given the option to
update their password, as that doesn't work with read-only LDAP.
Administrators with a read-only LDAP are free to disable the policy on
login to avoid this.

Currently, users are only shown a generic error message that their
password no longer matches the policy, but not the exact error.
This is because I didn't find a way to properly pass the PolicyError up
to the authenticator which handles the password validation, as the
policy errors contain parameters (like minimum lower case chars) and
their error messages are localized based on the users locale.

Closes keycloak#14150

Signed-off-by: Tobias Kantusch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/authentication Indicates an issue on Authentication area kind/feature Categorizes a PR related to a new feature team/core-clients
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants