Skip to content

enterprise/policies: Add Password Uniqueness History Policy#13453

Merged
rissson merged 66 commits intomainfrom
feature/unique_passwords
Apr 22, 2025
Merged

enterprise/policies: Add Password Uniqueness History Policy#13453
rissson merged 66 commits intomainfrom
feature/unique_passwords

Conversation

@melizeche
Copy link
Member

@melizeche melizeche commented Mar 10, 2025

Details

Continue work done in #10631
Closes #8307
Documentation PR: #13686

Steps to test:

  1. Create and setup a new "Password Uniqueness Policy"
  2. Edit default-password-change flow->stage bindings-> edit stage -> default-password-change-prompt and add the policy
image

Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

verkaufer and others added 27 commits August 17, 2024 11:05
…ry table

If the UniquePasswordPolicy is enabled anywhere, we now record the user's hashed password.
The system should aim to keep the number of historical passwords to a minimum to avoid wasting storage space.

Admins can configure how many passwords they want to preserve. If multiple instances of the UniquePasswordPolicy exist, the system takes the max() value of all enabled policies to determine how many passwords should remain after trimming.
…ings

Querying within post_delete for other PolicyBindings will include the PolicyBinding we're deleting. We have to account for that by checking for bindings other than the one we're looking at.
@netlify
Copy link

netlify bot commented Mar 10, 2025

Deploy Preview for authentik-docs canceled.

Name Link
🔨 Latest commit 272b74a
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/680789024ae4d30008d8354d

@netlify
Copy link

netlify bot commented Mar 10, 2025

Deploy Preview for authentik-storybook canceled.

Name Link
🔨 Latest commit 272b74a
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/6807890202cc8c0008490d3d

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
@BeryJu BeryJu force-pushed the feature/unique_passwords branch from 9bdfe9f to 8f56e1c Compare March 27, 2025 15:45
@melizeche melizeche changed the title policies/password: password uniqueness history core/policies: Password Uniqueness History Policy Mar 27, 2025
@melizeche melizeche changed the title core/policies: Password Uniqueness History Policy enterprise/policies: Add Password Uniqueness History Policy Mar 27, 2025
@melizeche melizeche requested a review from BeryJu March 27, 2025 20:22
# Check if any UniquePasswordPolicy is in use
unique_pwd_policy_in_use = UniquePasswordPolicy.is_in_use()

if unique_pwd_policy_in_use:
Copy link
Member

Choose a reason for hiding this comment

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

Should we also save as long as the policy exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that we should only save when the user explicitly wants to do that



@CELERY_APP.task()
def trim_user_password_history(user_pk: int):
Copy link
Member

Choose a reason for hiding this comment

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

As this is only called from trim_all_password_histories, I think we can just have one task deleting for all users

Copy link
Member

Choose a reason for hiding this comment

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

And it can also call check_and_purge_password_history as well.

I fail to see the difference between purge_password_history_table and check_and_purge_password_history though

Copy link
Member Author

@melizeche melizeche Apr 22, 2025

Choose a reason for hiding this comment

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

You're right, I refactored check_and_purge_password_history and purge_password_history_table into one function 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

as for trim_all_password_histories this approach allows us to have better error isolation(like if there's a problem with a particular user) and would scale better in huge user base

Copy link
Member

Choose a reason for hiding this comment

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

In other tasks we don't separate like this. I still want both of those tasks to be merged. If there are several thousands of users with password histories, I don't want several thousands of tasks to be scheduled.



@CELERY_APP.task()
def trim_user_password_history(user_pk: int):
Copy link
Member

Choose a reason for hiding this comment

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

In other tasks we don't separate like this. I still want both of those tasks to be merged. If there are several thousands of users with password histories, I don't want several thousands of tasks to be scheduled.

@melizeche melizeche requested a review from rissson April 22, 2025 12:00
rissson added 2 commits April 22, 2025 14:17
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
@rissson rissson enabled auto-merge (squash) April 22, 2025 12:19
@rissson rissson merged commit 723dccd into main Apr 22, 2025
86 checks passed
@rissson rissson deleted the feature/unique_passwords branch April 22, 2025 12:39
kensternberg-authentik added a commit that referenced this pull request Apr 25, 2025
* main: (49 commits)
  core: bump uvicorn from 0.34.1 to v0.34.2 (#14175)
  website/integrations: add xcreds (#14163)
  core, web: update translations (#14179)
  web: update default flow background (#14115)
  web: bump API Client version (#14176)
  enterprise/policies: Add Password Uniqueness History Policy (#13453)
  web/xliff: fix duplicated translations (#14164)
  website/docs: fix postgres pool recommended settings (#14149)
  core: bump astral-sh/uv from 0.6.14 to 0.6.16 (#14161)
  web: fix scrollbar styling (#12600)
  website: integrations: gravity: fix issuer URL (#14155)
  web: Packagify live reload plugin. (#14134)
  web: bump API Client version (#14062)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh-Hans (#14146)
  translate: Updates for file web/xliff/en.xlf in zh_CN (#14145)
  core: bump goauthentik.io/api/v3 from 3.2025024.7 to 3.2025024.8 (#14143)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh_CN (#14144)
  translate: Updates for file web/xliff/en.xlf in zh-Hans (#14139)
  core, web: update translations (#14142)
  core: bump yarl from 1.19.0 to v1.20.0 (#14128)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checking the new user password to make sure it is different from the previous ones

5 participants