caelum0x 6801c08af9
Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / node suites (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
feat(RIT-OPS,RIT-BRD): rename gitea -> rit everywhere we control, deployed + live-verified
apps/gitea -> apps/rithub-server; compose services/containers renamed
(rithub-server-app/postgres/act-runner) with explicit project name and
volume names pinned to the exact existing Docker volumes (no data loss);
our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper
on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs ->
ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter
+ giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram
(tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go
internal/giteaclient -> internal/ritclient in rithub-async-import (go
build/test clean); new /auth/rit + /forges/rit/connect routes with
/gitea back-compat aliases; locale/swagger/footer/captcha template text
scrubbed of remaining "Gitea" strings.

Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea
renamed to /srv/rithub-server with a symlink kept, docker compose up -d from
the new path, act_runner network-alias fix for its persisted instance URL.
Live-verified: docker compose config diff showed zero unintended value
changes, DB row counts unchanged (19 users, 635 repos), full route
regression 200/expected, 0 "gitea" in headers/bodies on every checked page,
real git clone+push over HTTPS and SSH with a disposable account (deleted
after). Deferred on purpose (documented in plans/railyard.md): the forge
discriminator / DB column names / Postgres role+volume names (data
migrations, not a naming change) and the upstream GITEA__ env-to-ini keys
and X-Gitea-* wire headers (hardcoded in the vendored engine binary).

See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and
live evidence.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-12-01 16:34:39 +03:00

4.1 KiB

rithub-device-auth

Real browser sign-in for rit login (RIT-ACT, 2026-12-01). Rithub previously had no OAuth2 device-code flow (/login/oauth/device is a plain 404 on the engine) -- rit login could only open the token-settings page and have a human paste a personal access token. This service adds the real thing: an RFC-8628-shaped device-authorization flow, wrapping the engine's own real OAuth2 "Rit CLI" application (confirmed registered 2026-11-18, extended this pass with a second redirect_uri) rather than inventing a second, parallel identity system.

Routes (proxied by Caddy on rithub.dev)

  • POST /api/rit/device/code -- rit login calls this first. Returns {device_code, user_code, verification_uri, verification_uri_complete, expires_in, interval}.
  • GET /device[?code=XXXX-XXXX] -- the human-facing confirmation page, in Rithub's own chrome (reuses the engine's real nav/footer markup and stylesheets, same technique as rithub-outage-protect). Requires an existing rithub.dev session cookie; redirects to /user/login otherwise. Lists the exact scopes being granted.
  • GET /device/authorize?user_code=... -- generates a PKCE pair, stores the verifier server-side, 302s into the engine's own real /login/oauth/authorize (native consent screen, session-cookie authenticated by the engine itself).
  • GET /api/rit/device/callback -- the engine's OAuth2 redirect target. Exchanges the authorization code for a real access token via /login/oauth/access_token, authenticated with the PKCE verifier (no client secret -- the "Rit CLI" app is a public/non-confidential client).
  • POST /api/rit/device/token -- polled by rit login: authorization_pending / slow_down / expired_token / access_denied / {access_token, token_type, scope} (single-use: a device_code can only ever be exchanged for its token once).

Security notes

  • Only a SHA-256 hash of each device_code is ever stored (src/store.mjs) -- the raw value is handed to the CLI once and never written anywhere else. The 8-char user_code excludes visually ambiguous characters (0/O, 1/I/L).
  • Every record expires after 10 minutes and is in-memory only (a restart simply fails in-flight sign-ins the same way an expiry would).
  • The OAuth state parameter reused as the correlator is the device_code's hash, not the raw code -- the browser never sees the value the CLI is polling with.
  • Polling is rate-limited to roughly one request every 4 seconds per device_code (slow_down).
  • The resulting token is a real engine OAuth2 access token scoped to exactly read:repository write:repository read:issue write:issue read:organization write:organization read:user write:user read:package write:package (src/ritOAuth.mjs) -- never broader than what rit actually uses.
  • This service never has the user's password and never impersonates a user server-side (sudo/admin-token tricks) -- it only accepts a token the engine itself minted after that exact human approved that exact scope list in their own browser session.

Engine-side change made alongside this service (2026-12-01)

  • [oauth2] ACCESS_TOKEN_EXPIRATION_TIME = 2592000 added to the engine's app.ini (was unset, default 3600s/1h) -- shared by every OAuth2 app on this instance including Ritgram's "Sign in with Rithub", but harmless there since Ritgram re-authenticates on every sign-in anyway. Without this, a rit login session would silently die after an hour with no refresh-token plumbing in the CLI yet.
  • The pre-existing "Rit CLI" OAuth2 application (id 5, registered 2026-11-18 for a loopback-redirect flow that was apparently never finished) was extended via PATCH /api/v1/user/applications/oauth2/5 to add https://rithub.dev/api/rit/device/callback as a second redirect_uri, alongside its existing http://127.0.0.1:42813/callback (kept, not removed).

Deploy

Same convention as rithub-outage-protect/rithub-billing: rsync/scp this directory to the box, pm2 start ecosystem.config.cjs (or pm2 reload rithub-device-auth), add Caddy handle /device* and handle /api/rit/device* blocks proxying to 127.0.0.1:3357, reload Caddy.