-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat: clean up session on janitor run #2567
Conversation
Thank you for the PR! The checkbox @Benehiko can probably assist you to find the right place to add tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long review times, kinda hectic at the moment :/
(&ls).TableName(), | ||
(&lr).TableName(), | ||
(&cr).TableName()), | ||
notAfter).Exec() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is problematic because the notAfter
has had a different context before. Now, this could remove sessions where users are signed in and that are not expired. I think not having any references is already a good indicator if this should be removed or not but I think we probably need to move this into it's own function and then add here
hydra/cmd/cli/handler_janitor.go
Lines 131 to 136 in be8de37
case OnlyTokens: | |
routines = append(routines, cleanup(p.FlushInactiveAccessTokens, "access tokens")) | |
routines = append(routines, cleanup(p.FlushInactiveRefreshTokens, "refresh tokens")) | |
case OnlyRequests: | |
routines = append(routines, cleanup(p.FlushInactiveLoginConsentRequests, "login-consent requests")) | |
} |
as an additional case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aeneasr You are right! The NOT EXISTS
conditions should be sufficient. The notAfter
condition could be an extra peace of mind not to delete unintended records. It also could potentially help with the performance of the query since the engine may require to do fewer row scans this way (I didn't do any sort of benchmarking, I am just guessing).
I can remove it if you think that's misleading.
Hi @mohsen3 This looks great! I believe since you are deleting from a new table you would have to write some additional tests to verify if the rows are being deleted or kept in You can add your tests inside As well as the helper tests inside janitor_test_helper.go I believe it might be better to add a new flag to this routine since this is deleting a different aspect of the database which might not always need to be run with |
Hi @Benehiko, Please bear with me since this is my first contribution to this repo :)
Do you still think having a separate switch is helpful? We can start from a single switch and separate it later if we found a use for it? |
That's no problem just ping me if you need help :) I see, yes you are right! Let's keep it then under the same switch |
While the PR is being worked on I will mark it as a draft. That declutters our review backlog :) Once you're done with your changes and would like someone to review them, mark the PR as ready and request a review from one of the maintainers. Thank you! |
Related issue
Closes #2561
@aeneasr
Proposed changes
Clean up the
hydra_oauth2_authentication_session
table whenhydra janitor $DSN --requests
is run.Checklist
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
[email protected]) from the maintainers to push
the changes.
works.
Further comments
hydra_oauth2_authentication_session
is quite a large table and requires clean up. It is the second largest table in our database right now.