auth: housekeeping job — nothing removes stale sessions, login sessions or device codes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- mongodb, postgresql, python
- Domain
- authentication, backend, database
Research direction
Start with the existing sweep functions at campus/auth/resources/session.py:84 and campus/auth/resources/device_code.py:286, then docs/auth-login-flow.md and docs/auth-token-invariants.md for the delete and keep rules. The open decisions (session grace period, login_sessions retention) need a maintainer answer before code. Done means a cron-invoked, idempotent, chunked job that deletes only the listed expired records, never credentials or their tokens, and treats an empty match as success.
Written by the indexing model from the issue text.
Description
Part of #1243 (cron jobs under Railway serverless). campus.audit gets a job for rollups and retention (#1249); campus.auth needs one too.
What is true today
campus.auth has two sweep functions and nothing calls either. No timer, startup hook, script or caller exists in campus, campus-core, campus-common or campus-model. There are no TTL indexes: both Mongo initialisation hooks are pass.
| Store | Backend | Expires | Removed when | Grows by |
|---|---|---|---|---|
auth_sessions |
Mongo | expires_at, 10 min |
finalize; sweep() exists (campus/auth/resources/session.py:84) and is reachable only through POST /auth/v1/sessions/sweep, whose only callers are tests |
One per abandoned login flow |
login_sessions |
Mongo | expires_at, 30 days |
Logout; replaced by the next login from the same browser cookie. No sweep | One per login that never logs out, and per CLI login, which has no cookie to replace |
device_codes |
Mongo | expires_at, 600 s |
Claim at token issue. sweep() exists (campus/auth/resources/device_code.py:286) with no caller |
One per abandoned device flow |
tokens |
Mongo | expires_at, 7 days |
Revoke, supersede, disconnect | Only through two operator-only paths that orphan a document |
yapper events |
Postgres | none | Nothing in the suite | One per emitted event |
The Postgres tables (credentials, app_credentials, users, vault_clients, access_grants, vault) are bounded by users, clients and admin actions and carry no expiry.
Expired records are ignored at read time, or marked (device_codes get state="expired"), never removed. Expired-but-unswept sessions appear in the admin session list, which loads the whole collection and paginates in Python.
The docs say otherwise: docs/auth-login-flow.md states that the 10-minute session TTL "is enforced by the sweep job (POST /auth/v1/sessions/sweep), not on every read". No such job exists, so a stale campus session can still complete a login.
What a job must and must not delete
Delete:
auth_sessionspastexpires_at, with a grace period of a day or more. A login that pauses for more than 10 minutes is otherwise cut off.login_sessionspastexpires_at.device_codespastexpires_at.tokensdocuments that nocredentials.token_idorapp_credentials.token_idreferences.
Leave alone:
credentialsrows, and thetokensdocument a row points to, even whenexpires_athas passed. The row is the long-lived grant (docs/auth-token-invariants.mdA4), the refresh grant resolves through that document, and the code exchange unions scopes from it. Deleting either forces a re-login or silently drops accumulated scopes.users,vault_clients,access_grants,vaultandapp_credentials.
Shape
A Railway cron job, per #1249: catch-up work, chunked, idempotent, with each run recorded in a ledger. The job needs a credential, which raises the question of how the sweep is invoked:
- Calling
POST /auth/v1/sessions/sweepover HTTP needs a credential for campus.auth and wakes the service. The route now validatesat_time(see the fix PR), but it has no operator gate: any authenticated client may call it, and it loads every session and deletes one at a time. - Running the sweep in-process against storage, as the
campus-migratejob does for migrations, avoids both. It needs no API surface and no credential.
The second looks right. It also gives login_sessions and device_codes their missing callers.
Sharp edges for whoever writes it
delete_matching({})deletes everything in both backends. Never call it with an empty query.delete_matchingraisesNoChangesAppliedErrorwhen nothing matched, in both the Postgres and Mongo backends. A run with nothing to do is a success.betweenis not translated for Mongo. Useltorlte.- A retention figure for
login_sessionsis a decision:docs/auth-login-flow.mdcalls them "login audit records", and they carrydevice_idanduser_agent. Logout already deletes them, so the code does not treat them as durable, but deleting them after 30 days ends any "who logged in from where" look-back.
To decide
- Grace period for
auth_sessions. - Whether
login_sessionsare audit records (keep for N months after expiry) or working state (delete at expiry). - Whether yapper
eventsget a retention too.
- Dominant language
- Python
- Stars
- 0
- Forks
- 2
- Avg merge
- 39m
- Merged PRs (30d)
- 235
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nyjc-computing/campus
-
enhancement for-collaborators for-contributors
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nyjc-computing/campus#451 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
nyjc-computing/campus#1320 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 25/100
nyjc-computing/campus#1309 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 18/100
nyjc-computing/campus#1300 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 5/100
nyjc-computing/campus#1295 · 4 comments ·
Maintainers usually reply within 1 day
All issues in nyjc-computing/campus
Similar issues
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
kornia/kornia-rs#1416 · 1 comment ·
Maintainers usually reply within 2 days
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PolicyEngine/ai-inequality#64 ·
Maintainers usually reply within 1 day
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePossibly taken @PabloRoque claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pymc-devs/pymc-extras#839 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day