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

Remove user sessions when resetting password #33347

Merged
merged 2 commits into from
Aug 13, 2023

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Aug 12, 2023

When user's password is reset, we also remove all DB sessions for that user.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@potiuk potiuk force-pushed the add-session-deleting-on-password-reset branch from a089e98 to aaa8c26 Compare August 13, 2023 14:41
@potiuk potiuk marked this pull request as ready for review August 13, 2023 14:41
@potiuk potiuk added this to the Airflow 2.7.1 milestone Aug 13, 2023
@potiuk potiuk force-pushed the add-session-deleting-on-password-reset branch 3 times, most recently from 2708578 to 0e2ca67 Compare August 13, 2023 15:26
@potiuk
Copy link
Member Author

potiuk commented Aug 13, 2023

Few screenshots:

  • Case for securecookie:
Screenshot 2023-08-13 at 17 23 06
  • Huge number of rows (8!)
Screenshot 2023-08-13 at 17 25 40

I already added the missing space BTW.

  • The airflow db clean command
Screenshot 2023-08-13 at 17 28 24

Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

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

Nit, IMHO I think we should not cleanup the session table on each reset password, but if the others are ok with that, I would be ok too

airflow/utils/db_cleanup.py Show resolved Hide resolved
airflow/auth/managers/fab/security_manager/override.py Outdated Show resolved Hide resolved
When user's password is reset, we also remove all DB sessions
for that user - for database session backend.

In case we are using securecookie mechanism, resetting password does
not invalidate old sessions, so instead we are displaying warning to
the user performing the reset that in order to clear existing
sessions of the user, the secure_key needs to be changed and it
will invalidate all sessions for all users.

Protection has been added in case the number of sessions in the DB
is too big to effectively scan and remove sessions for the user. In
such case we print warning for the user that sessions have not
been reset, and we suggest to improve the way their deployment
mechanisms create too many sessions - by either changing the way
how automation of the API calls is done and/or by purging the
sessions regularly by "airflow db clean".
Co-authored-by: Hussein Awala <hussein@awala.fr>
Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

LGTM

@potiuk potiuk modified the milestones: Airflow 2.7.1, Airflow 2.7.0 Aug 13, 2023
@potiuk potiuk merged commit 2caa186 into apache:main Aug 13, 2023
42 checks passed
@potiuk potiuk deleted the add-session-deleting-on-password-reset branch August 13, 2023 19:21
ephraimbuddy pushed a commit that referenced this pull request Aug 14, 2023
* Remove user sessions when resetting password

When user's password is reset, we also remove all DB sessions
for that user - for database session backend.

In case we are using securecookie mechanism, resetting password does
not invalidate old sessions, so instead we are displaying warning to
the user performing the reset that in order to clear existing
sessions of the user, the secure_key needs to be changed and it
will invalidate all sessions for all users.

Protection has been added in case the number of sessions in the DB
is too big to effectively scan and remove sessions for the user. In
such case we print warning for the user that sessions have not
been reset, and we suggest to improve the way their deployment
mechanisms create too many sessions - by either changing the way
how automation of the API calls is done and/or by purging the
sessions regularly by "airflow db clean".

* Update airflow/auth/managers/fab/security_manager/override.py

Co-authored-by: Hussein Awala <hussein@awala.fr>

---------

Co-authored-by: Hussein Awala <hussein@awala.fr>
(cherry picked from commit 2caa186)
@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Aug 14, 2023
ferruzzi pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Aug 17, 2023
* Remove user sessions when resetting password

When user's password is reset, we also remove all DB sessions
for that user - for database session backend.

In case we are using securecookie mechanism, resetting password does
not invalidate old sessions, so instead we are displaying warning to
the user performing the reset that in order to clear existing
sessions of the user, the secure_key needs to be changed and it
will invalidate all sessions for all users.

Protection has been added in case the number of sessions in the DB
is too big to effectively scan and remove sessions for the user. In
such case we print warning for the user that sessions have not
been reset, and we suggest to improve the way their deployment
mechanisms create too many sessions - by either changing the way
how automation of the API calls is done and/or by purging the
sessions regularly by "airflow db clean".

* Update airflow/auth/managers/fab/security_manager/override.py

Co-authored-by: Hussein Awala <hussein@awala.fr>

---------

Co-authored-by: Hussein Awala <hussein@awala.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants