Skip to content

Remove user sessions when resetting password#33347

Merged
potiuk merged 2 commits into
apache:mainfrom
potiuk:add-session-deleting-on-password-reset
Aug 13, 2023
Merged

Remove user sessions when resetting password#33347
potiuk merged 2 commits into
apache:mainfrom
potiuk:add-session-deleting-on-password-reset

Conversation

@potiuk

@potiuk potiuk commented Aug 12, 2023

Copy link
Copy Markdown
Member

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

potiuk commented Aug 13, 2023

Copy link
Copy Markdown
Member Author

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

@potiuk
potiuk requested a review from pierrejeambrun August 13, 2023 15:32

@hussein-awala hussein-awala 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.

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

Comment thread airflow/utils/db_cleanup.py Outdated
Comment thread airflow/auth/managers/fab/security_manager/override.py Outdated
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".
@potiuk
potiuk force-pushed the add-session-deleting-on-password-reset branch from 0e2ca67 to 10c5e4e Compare August 13, 2023 18:14
Comment thread airflow/auth/managers/fab/security_manager/override.py Outdated

@hussein-awala hussein-awala 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.

LGTM

@pierrejeambrun pierrejeambrun 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.

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
@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 <[email protected]>

---------

Co-authored-by: Hussein Awala <[email protected]>
(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 <[email protected]>

---------

Co-authored-by: Hussein Awala <[email protected]>
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.

5 participants