Commit Graph
363 Commits
Author SHA1 Message Date
Quentin Gliech 401b1e299b Persist the browser locale on the device code grant
Capture the preferred language from the browser view which accepts the
device code grant and store it on the grant, so it can later be used to
render a human-readable device name.
2026-06-23 10:26:07 +02:00
Quentin Gliech fe622331a8 Admin API: allow listing and viewing of OAuth 2.0 clients (#5710) 2026-06-17 17:44:34 +02:00
Quentin Gliech 256c5e3ff5 storage: use an enum for the OAuth2ClientFilter client kind 2026-06-17 17:33:03 +02:00
Quentin Gliech d33577cf4d Admin API: filter users based on client usage (#5707) 2026-06-17 17:12:56 +02:00
Quentin Gliech 9464ca8038 Merge branch 'main' into quenting/admin-api/session-time-filters 2026-06-17 17:01:02 +02:00
Quentin Gliech a8ffce8f13 Admin API: allow filtering OAuth 2.0 sessions by multiple clients (#5708) 2026-06-17 16:40:53 +02:00
Quentin Gliech eb0ef6380c Merge branch 'main' into quenting/upstream-pass-parameters 2026-06-17 14:54:37 +02:00
Quentin Gliech 632d64d199 Per-provider registration token requirement (#5605) 2026-06-10 10:05:46 +02:00
Quentin Gliech cfd37bfa49 storage: add active-sessions filter to OAuth2ClientFilter 2026-06-01 17:30:16 +02:00
Quentin Gliech 2aaff36c82 storage: add grant_type filter to OAuth2ClientFilter 2026-06-01 17:30:16 +02:00
Quentin Gliech 9c93a19076 storage: add client_uri filter to OAuth2ClientFilter 2026-06-01 17:30:15 +02:00
Quentin Gliech 9f73007674 storage: add client_name filter to OAuth2ClientFilter 2026-06-01 17:30:15 +02:00
Quentin Gliech f9363d230d storage: add static/dynamic filter to OAuth2ClientFilter 2026-06-01 17:30:15 +02:00
Quentin Gliech c522bd49d1 storage: add list/count to OAuth2ClientRepository 2026-06-01 17:30:14 +02:00
Quentin Gliech db8306ed4c storage: filter app sessions (compat+oauth2 union) by creation time 2026-06-01 17:30:14 +02:00
Quentin Gliech 5cb9ca1043 storage: add multi-client filter to OAuth2SessionFilter
Add a new `for_clients(&[&Client])` method (and matching `clients()`
getter) on `OAuth2SessionFilter`. The existing single-client
`for_client(&Client)` is kept intact as GraphQL still uses it; the two
fields are independent and ANDed together when both happen to be set.

In the Postgres implementation the predicate uses sea-query's `is_in`,
which translates to a plain `column IN (...)`. As a side effect, an
empty client list matches no rows (sea-query emits `WHERE 1 = 2`),
which is the desired behaviour for an explicit "filter on this empty
set of clients" request.
2026-06-01 17:30:14 +02:00
Quentin Gliech d61ddd832c storage: filter browser sessions by creation time 2026-06-01 17:30:14 +02:00
Quentin Gliech da8faafe3b storage: filter compat sessions by creation time 2026-06-01 17:30:14 +02:00
Quentin Gliech 798c0b9c48 storage: filter OAuth2 sessions by creation time 2026-06-01 17:30:14 +02:00
Quentin Gliech 8ef0793031 storage: filter users by presence of an active OAuth2 session 2026-06-01 17:30:13 +02:00
Quentin Gliech 58b3a2e9f0 storage: filter users by presence of an active compat session
Adds `UserFilter::with_active_compat_session(has: bool)` and its
PostgreSQL implementation (an `EXISTS` / `NOT EXISTS` subquery against
`compat_sessions` on `user_id` with `finished_at IS NULL`).

Also adds a partial index `compat_sessions (user_id) WHERE finished_at IS
NULL` so that on installations with many finished compat sessions the
existence/non-existence check stays cheap.
2026-06-01 17:30:13 +02:00
Quentin Gliech 9a89e52d00 storage: filter users by active OAuth2 session with given clients
Adds `UserFilter::with_active_oauth2_session_for_any_of_clients` and its
PostgreSQL implementation (an `EXISTS` sub-query joining `oauth2_sessions`
on `user_id`, restricting to `finished_at IS NULL` and
`oauth2_client_id = ANY(...)`). The semantics are OR across the supplied
clients.

Also adds a partial composite index `oauth2_sessions (user_id,
oauth2_client_id) WHERE finished_at IS NULL` so that on installations with a
lot of churn we don't need to walk through finished sessions when answering
"does this user have an active session for any of these clients?". The
existing FK indexes can answer the query, but visit finished rows too.
2026-06-01 17:30:13 +02:00
Eric Eastwood fa23689962 #[allow -> #[expect 2026-05-21 16:37:47 -05:00
Quentin Gliech 33624b63de Persist raw downstream query parameters on oauth2_authorization_grants
Captures the raw query parameters from the downstream OAuth2 authorization
request, so they can later be referenced from templated upstream
authorization parameters. Existing call sites pass an empty map; a
follow-up commit will wire the downstream authorization handler to
to capture the real query parameters.
2026-05-13 17:42:32 +02:00
defaultdino 7342218175 fix provider.rs, format, and run update.sh 2026-04-03 19:22:57 +02:00
defaultdino 407f3cb4fa distinguish password vs upstream oauth registration token requirements 2026-04-03 17:41:37 +02:00
Olivier 'reivilibre bac118ab12 Fix compat token refresh giving back a consumed token 2026-02-13 15:16:43 +00: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 0486c6e05d Use the user_session_id on upstream authorisations for filtering instead
of authentications

This makes it one less table to read
2026-01-21 14:49:07 +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 39adf61089 Track user session authenticated through upstream auth sessions
This will help us avoid clearing upstream authorization sessions that
might still be useful to keep around for OIDC Backchannel Logouts
2026-01-21 12:19:05 +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 edb6ba9606 Cleanup finished compat sessions after 30 days 2026-01-15 12:29:43 +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 GliechandOlivier 'reivilibre' 0ed79f7c6d Fix typo in comment
Co-authored-by: Olivier 'reivilibre' <oliverw@element.io>
2026-01-13 17:22:48 +01:00
Quentin Gliech 2d26ed40a9 Apply suggestions from code review 2026-01-12 11:58:19 +01:00
Quentin GliechandCopilot cdc501fe7a Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-12 11:57:42 +01:00
Quentin Gliech 8c50547aea Cleanup consumed refresh tokens 2026-01-12 11:18:18 +01:00