Skip to content

TIGER-378: TTL + expiry + rotation for personal access tokens - #361

Merged
WebTigers merged 1 commit into
mainfrom
feat/tiger-378-pat-ttl-rotation
Oct 24, 2026
Merged

WebTigers merged 1 commit into
mainfrom
feat/tiger-378-pat-ttl-rotation

Conversation

@WebTigers

Copy link
Copy Markdown
Owner

Closes the Zeabur-#1 echo for long-lived machine PATs: a PAT was mint-once and immortal (died only on explicit revoke).

Core substrate (safe — NULL expires_at = never expires, so every existing token and ordinary user PAT is unchanged until a caller opts into a TTL):

  • migration 0057: user_credential.expires_at DATETIME NULL (additive, instant, no backfill).
  • createToken($userId, ?int $ttlSeconds) writes expires_at when a TTL is given; rotateToken() mints a fresh token overlap-safe (caller revokes the old only after distributing the new).
  • verifyTokenCredential() refuses an expired token exactly like a revoked one.
  • tokensFor() surfaces expires_at; purgeExpiredTokens() + the core.auth.purge_expired_tokens daily job sweep them.

Tests: TTL expires + stops verifying; a default token never expires; zero/negative TTL = no expiry; purge sweeps only the expired; tokensFor carries expires_at; rotate mints a working token with overlap. 13/13 UserCredential + 16/16 schedule green (PHP 8.5, MariaDB).

Follow-on (not in this PR, dev-first): mint the fleet machine PATs (node↔CP host/billing/vps) WITH a TTL + a control-plane rotation job that re-mints and pushes to the node with an overlap window — proven on the dev CP/node with monitoring before prod, since a failed rotation would otherwise expire a healthy node's auth.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ASauLLscjqdsNqBNsx2Typ

The one real Zeabur-#1 echo: a PAT was mint-once and immortal (died only on an
explicit revoke), so a leaked long-lived MACHINE PAT (node<->control-plane
host/billing/vps token) stayed valid until a human noticed.

Core substrate (safe: NULL expires_at = never expires, so every existing token and
every ordinary user PAT is unchanged until a caller opts into a TTL):
- migration 0057: add user_credential.expires_at DATETIME NULL (additive, instant).
- createToken($userId, ?int $ttlSeconds): write expires_at when a TTL is given;
  return it. rotateToken() mints a fresh token for the same owner (overlap-safe —
  the caller revokes the old one only after distributing the new).
- verifyTokenCredential(): refuse a token past expires_at, exactly like a revoked one.
- tokensFor(): surface expires_at for a manage-tokens screen.
- purgeExpiredTokens() + the core.auth.purge_expired_tokens daily job (hygiene;
  verification already refuses an expired token).

Tests: TTL expires + stops verifying; a default token never expires; a zero/negative
TTL means no expiry; purge sweeps only the expired; tokensFor carries expires_at;
rotate mints a working token with overlap. 13/13 UserCredential + 16/16 schedule green.

Follow-on (dev-first, not in this change): mint the fleet machine PATs WITH a TTL +
a control-plane rotation job that re-mints and pushes to the node with an overlap
window — proven on the dev CP/node with monitoring before it reaches prod, since a
failed rotation would otherwise expire a healthy node's auth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ASauLLscjqdsNqBNsx2Typ
@WebTigers
WebTigers merged commit 0652316 into main Oct 24, 2026
14 checks passed
@WebTigers
WebTigers deleted the feat/tiger-378-pat-ttl-rotation branch October 24, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant