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

feat: add mfa cleanup #1105

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/models/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func init() {
tableSessions := Session{}.TableName()
tableRelayStates := SAMLRelayState{}.TableName()
tableFlowStates := FlowState{}.TableName()
tableMFAChallenges := Challenge{}.TableName()

// These statements intentionally use SELECT ... FOR UPDATE SKIP LOCKED
// as this makes sure that only rows that are not being used in another
Expand All @@ -45,6 +46,7 @@ func init() {
fmt.Sprintf("delete from %q where id in (select id from %q where not_after < now() - interval '72 hours' limit 10 for update skip locked);", tableSessions, tableSessions),
fmt.Sprintf("delete from %q where id in (select id from %q where created_at < now() - interval '24 hours' limit 100 for update skip locked);", tableRelayStates, tableRelayStates),
fmt.Sprintf("delete from %q where id in (select id from %q where created_at < now() - interval '24 hours' limit 100 for update skip locked);", tableFlowStates, tableFlowStates),
fmt.Sprintf("delete from %q where id in (select id from %q where created_at < now() - interval '12 hours' limit 100 for update skip locked);", tableMFAChallenges, tableMFAChallenges),
J0 marked this conversation as resolved.
Show resolved Hide resolved
)

var err error
Expand Down
4 changes: 4 additions & 0 deletions migrations/20230508135423_add_cleanup_indexes.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ create index if not exists
create index if not exists
sessions_not_after_idx
on {{ index .Options "Namespace" }}.sessions (not_after desc);

create index if not exists
J0 marked this conversation as resolved.
Show resolved Hide resolved
mfa_challenge_created_at_idx
on {{ index .Options "Namespace" }}.mfa_challenges (created_at desc);