Commit Graph

250 Commits

Author SHA1 Message Date
Quentin Gliech d3d6c3dcd9 Split the cleanup jobs into multiple files 2026-02-04 12:12:28 +01:00
Quentin Gliech 378f24b118 Clear out last active IP on each sessions after 30 days (#5448) 2026-01-26 13:57:01 +01:00
Quentin Gliech dbdb2970ed Refactor inactive IP cleanup to use pagination
This should avoid dead many dead tuples when processing batches of
sessions to cleanup
2026-01-23 18:52:33 +01:00
Quentin Gliech b0e836eb44 Cleanup finished user/browser sessions (#5444) 2026-01-23 18:27:45 +01:00
Quentin Gliech 40cb5b0094 Cleanup finished OAuth 2.0 sessions (#5443) 2026-01-23 18:23:55 +01:00
Quentin Gliech 26caee7c99 Add cleanup jobs for inactive session IP addresses
This adds three new scheduled cleanup jobs that clear the last_active_ip
field from sessions that have been inactive for more than 30 days:

- CleanupInactiveOAuth2SessionIpsJob
- CleanupInactiveCompatSessionIpsJob
- CleanupInactiveUserSessionIpsJob

This helps with data minimization by not retaining IP addresses longer
2026-01-23 16:29:29 +01:00
Quentin Gliech 5bca9726b6 Add cleanup job for finished user sessions
Implements hard deletion of user/browser sessions that have been finished for more than 30 days, but only after all child sessions are cleaned up.

User sessions can only be deleted when no child sessions exist, ensuring backchannel logout propagation continues to work correctly.
2026-01-22 15:44:57 +01:00
Quentin Gliech a66d652a70 Add cleanup job for finished OAuth2 sessions
Implements hard deletion of OAuth2 sessions that have been finished for more than 30 days, including their associated access and refresh tokens.
2026-01-22 15:44:56 +01:00
Quentin Gliech c29c4c3a5e Re-enable upstream OAuth session cleanup job
It should be safe to run now
2026-01-21 14:50:03 +01:00
Quentin Gliech 1bd11e7656 Disable cleanup of upstream OAuth sessions
This job is temporarily disabled due to pending database backfill work.
It will be re-enabled in a future release.
2026-01-21 12:28:19 +01:00
Quentin Gliech e095938da5 Only cleanup orphan upstream authorization sessions
This includes sessions that were never completed, and sessions where
user_session was cleaned up. This is to avoid breaking features like
OIDC Backchannel Logout after 30 days.
2026-01-21 12:25:42 +01:00
Quentin Gliech 7272813925 Implement cleanup job for queue jobs
Add scheduled cleanup job that removes old completed and failed queue
jobs after 30 days. Jobs are kept for debugging purposes.

Includes migration to change the next_attempt_id FK constraint from NO
ACTION to SET NULL, allowing cleanup of retry chains without breaking
foreign key constraints.

One caveat is that cleanup is based on their creation time, *not* when
they got completed/failed. This means that if the job takes a long time
(as in, several days) to get scheduled, it might get cleared as soon as
it runs. This is fine for now, we may want to revisit this if we start
scheduling jobs far in the future
2026-01-19 12:25:04 +01:00
Quentin Gliech a721302201 Implement cleanup jobs for upstream OAuth sessions and links
Add two cleanup jobs scheduled hourly:

1. Upstream OAuth authorization sessions - removes sessions after 30 days
2. Orphaned upstream OAuth links - removes links after 7 days where user_id IS NULL. These are links created during upstream OAuth 2.0 login but never associated with a user
2026-01-19 12:24:13 +01:00
Quentin Gliech 766ff6c8f3 Implement cleanup job for email authentications
Add scheduled cleanup job that removes old user email authentications
after 7 days. Runs every hour.
2026-01-16 17:56:16 +01:00
Quentin Gliech 2ae95e30ec Implement cleanup job for user recovery sessions
Add scheduled cleanup job that removes old user recovery sessions after
7 days. Runs hourly.

Implementation uses ULID cursor-based pagination with no additional
indexes needed. Child tickets cascade-delete automatically.
2026-01-16 17:46:01 +01:00
Quentin Gliech 0aaa9f79b4 Implement cleanup job for OAuth2 device code grants
Add cleanup job that removes device code grants older than 7 days.
Uses ULID cursor-based pagination for efficiency.

- Add cleanup method to OAuth2DeviceCodeGrantRepository
- Add CleanupOAuthDeviceCodeGrantsJob task
- Register handler and schedule to run hourly
2026-01-16 17:40:11 +01:00
Quentin Gliech 53010538bc Implement cleanup job for OAuth2 authorization grants
Add cleanup job that removes authorization grants older than 7 days.
Uses ULID cursor-based pagination for efficiency.

- Add cleanup method to OAuth2AuthorizationGrantRepository trait
- Add CleanupOAuthAuthorizationGrantsJob task
- Register handler and schedule to run hourly
2026-01-16 17:39:38 +01:00
Quentin Gliech d71d59dba2 Allow hourly cleanup jobs to run for longer 2026-01-16 11:25:28 +01:00
Quentin Gliech edb6ba9606 Cleanup finished compat sessions after 30 days 2026-01-15 12:29:43 +01:00
Quentin Gliech 4c93d6dedf Adjust the retention period for user registrations to 30 days 2026-01-14 17:51:55 +01:00
Quentin Gliech e33f3f1e25 Cleanup old user registrations from the database 2026-01-14 14:01:10 +01:00
Quentin Gliech b693d789ae Remove imported unsupported threepids when deactivating a user (#5406) 2026-01-13 17:30:20 +01:00
Quentin Gliech 8c50547aea Cleanup consumed refresh tokens 2026-01-12 11:18:18 +01:00
Quentin Gliech 7349da0889 Cleanup revoked refresh tokens 2026-01-09 18:37:09 +01:00
Quentin Gliech 8ae879a7df Handle garbage-collected access tokens in the refresh token logic
We check if the access token was used when a double-refresh happened,
but can't do that reliably as we started garbage-collecting expired
access tokens
2026-01-09 18:09:05 +01:00
Quentin Gliech 6f0d642618 Setup recurring jobs schedules when running in tests 2026-01-09 18:07:44 +01:00
Quentin Gliech fba290e706 Cleanup expired OAuth 2.0 access tokens 2026-01-09 13:38:50 +01:00
Quentin Gliech 9216902ed4 Rename the cleanup revoked access tokens job
"cleanup-expired-tokens" was not accurate, and since the plan is to have
different jobs for the different kind of tokens, we renamed this job to
use a more accurate description
2026-01-09 13:36:46 +01:00
Quentin Gliech 61d1c7383e Introduce a way to clear jobs from a deprecated queue 2026-01-09 12:08:20 +01:00
Quentin Gliech 3e7cb60f63 Clean up revoked access tokens in batches 2026-01-08 19:03:09 +01:00
Quentin Gliech 8390560a1c Allow jobs to declare a timeout and cancel them 2026-01-08 19:03:09 +01:00
Quentin Gliech 48a826fe4c Remove imported unsupported threepids when deactivating a user 2026-01-08 15:33:50 +01:00
Olivier 'reivilibre 7d5e9b863d Revoke personal sessions on user deactivation 2025-10-22 11:27:10 +01:00
Olivier 'reivilibre 98c765cf6b storage: include PATs alongside personal sessions 2025-10-20 14:33:30 +01:00
Olivier 'reivilibre 6aa483a1f8 Sync devices from personal sessions 2025-10-07 19:54:59 +01:00
Quentin Gliech ad7fedf6ff Adapt most code to use the new edges and cursors 2025-09-29 15:08:46 +02:00
Quentin Gliech 6a1d67f452 Merge remote-tracking branch 'origin/main' into feat/login_hint_with_email 2025-08-18 16:43:00 +02:00
Quentin Gliech 6a2492e70b Fix a few clippy lints, mostly in doc comments 2025-08-18 10:34:28 +02:00
mcalinghee c314802fcd move Clock/MockClock/SystemClock/BoxClock/BoxRng to mas-data-model 2025-07-31 11:17:33 +02:00
Quentin Gliech ea873577aa Fix many clippy warnings
This is because the tracing-attributes update made clippy look at those
again. I've removed the `too_many_lines` lint, as it's not really useful
and we ignore it most of the time anyway.
2025-07-30 14:49:38 +02:00
Quentin Gliech d06f7c27d2 Handle device syncs for many devices more quickly (#4815) 2025-07-23 17:40:28 +02:00
Quentin Gliech 44c24e362c Handle device syncs for many devices more quickly 2025-07-23 17:37:25 +02:00
Quentin Gliech 70aba2a086 Fix the user deactivation/reactivation jobs
Those got broken when we switched to using localparts in the
HomeserverConnection in #4801
2025-07-23 10:38:27 +02:00
Quentin Gliech 8af1b7a3fa Take the localpart instead of the MXID in HomeserverConnection methods 2025-07-18 16:39:24 +02:00
Andrew Ferrazzutti d807975137 Decouple (un)locking from (re/de)activation
Unify the admin API, CLI, and GraphQL API in not having the unlock
command also reactivate, or the deactivate command also lock.

Still let the unlock command of the CLI and GraphQL API to also
reactivate the target user, albeit as a non-default option.
2025-07-16 14:17:01 -04:00
Andrew Ferrazzutti eca22d335b Format 2025-07-16 14:17:01 -04:00
Andrew Ferrazzutti 6c1afee13d Separate active state from lock state in admin API
- Allow the admin API to deactivate a user without locking it, and to
  unlock a user without reactivating it.
- Make unlock-and-reactivate flows unset the "deactivated_at" timestamp.
- Revert adding an "unlock" parameter on `ReactivateUserJob`, as the
  option is used only by the admin API which doesn't use a job.
2025-07-16 14:17:01 -04:00
Andrew Ferrazzutti a8b8c8e31c Add admin API endpoint to reactivate user 2025-07-16 14:17:01 -04:00
Quentin Gliech e66782207b Ignore clippy lint 2025-07-09 18:04:45 +02:00
Quentin Gliech 388bfc25c2 Test helper to run all tests in the job queue 2025-07-09 17:26:09 +02:00