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

87 lines
4.7 KiB
Markdown

# rithub-approvals
Agent push approval (RIT-ACT, `plans/railyard.md` next-coding-queue item 3).
A push made with an agent-session token that is a **force-push**, a
**branch delete**, or a push to a **protected branch** is held here instead
of landing directly; a named human with push/admin on the repo approves it
(with their own token, `rit push approve <id>` or `https://rithub.dev/approvals`)
or denies it (`rit push deny <id>`). An approved push lands with exactly
the approving human's own permissions -- never a more-privileged stored
credential -- and a denied one never touches the target branch at all.
## Why no stored admin token
Every other small pm2 service on this box (`rithub-billing`,
`rithub-outage-protect`) holds `RITHUB_ADMIN_TOKEN` because it needs to act
on a user's behalf without that user handing over a credential per request.
This service is different on purpose: the whole safety property it exists
for ("an approval can never do more than the approving human could already
do by hand") only holds if the git push that actually lands a held change
is authenticated as that human, not as some more-privileged service
account. So every mutating route here takes the caller's own bearer token
and uses *that* for both the permission check and the real `git push`
(`src/gitOps.mjs`) -- nothing is stored at rest except the approval ledger
itself (`data/approvals.json`), which never contains a token.
## How a push gets held
1. `rit push` (agent session, `RITHUB_AGENT_SESSION_ID` set) detects the
push needs approval and instead pushes the local commits to an
unprotected staging ref, `refs/pending/<id>`, on the same repo -- a
normal, always-allowed git push, never a bespoke transport.
2. It registers the pending approval (`POST /approvals/api/create`, then
`POST /approvals/api/:id/confirm` once the staging push lands), which
the server independently re-checks against the real remote ref before
trusting it (`src/gitOps.mjs#remotePendingTip`).
3. A human runs `rit push approve <id>` (or denies it). Approve fetches the
staged objects and re-pushes them onto the real target ref, with the
approving human's own token; deny deletes the staging ref. Either way
the target branch was never written to until a human said so.
Branch-delete holds skip the staging-ref dance entirely (nothing to stage
-- the delete intent *is* the full held action) and land via a normal
`DELETE /api/v1/repos/{owner}/{repo}/branches/{branch}` call using the
approving human's token.
## Routes
- `GET /approvals` -- web page, cookie session only (RIT-ACT gap 2, "no
pasted tokens", 2026-12-01): shows a cross-repo "my pending approvals"
inbox with one-click Approve/Deny, or a one-time "Authorize" link if
this browser/account hasn't completed the real OAuth2 consent yet. No
owner/repo fields, no token field, anywhere on the page.
- `GET /approvals/oauth/start` / `GET /approvals/oauth/callback` -- the
one-time OAuth2 (PKCE, same real "Rit CLI" app `rit login` uses) round
trip behind the page above (`src/ritOAuth.mjs`, `src/pkce.mjs`). The
resulting token is stored encrypted at rest, keyed by login
(`src/oauthTokenStore.mjs`) -- never sent to or stored in the browser.
- `GET /approvals/api/mine` / `POST /approvals/api/mine/:id/approve|deny`
-- cookie-session-only equivalents of `list`/`approve`/`deny` below,
used by the page above; `mine` has no owner/repo filter (every repo the
signed-in human can push/admin, across the whole ledger).
- `POST /approvals/api/agent-session/mark` -- RIT-ACT gap 1 (server-side
enforcement): `{session_id}`, Bearer token required. Called by every
`rit` command when `RITHUB_AGENT_SESSION_ID` is set
(`packages/rithub-cli/src/cli.mjs`) -- records that this exact token
(hash only, `src/agentSessionTokens.mjs`) belongs to an agent session,
so `apps/rithub-agent-gateway` can hold a RAW `git push` made with the
same credential later, even one that never goes through `rit` at all.
- `GET /approvals/api/list?owner=&repo=&status=` -- Bearer token required
(unchanged, still what `rit push list` calls).
- `POST /approvals/api/create` -- `{owner, repo, action: "push"|"delete", branch, forced, reason, session_id, newrev}`.
- `POST /approvals/api/:id/confirm` -- `{newrev}` (action="push" only).
- `POST /approvals/api/:id/cancel` -- requester-only, `awaiting_push` only.
- `POST /approvals/api/:id/approve` / `.../deny` -- Bearer token, push/admin on the repo required (unchanged, still what `rit push approve|deny` calls).
- `GET /approvals/api/:id` -- detail.
- `GET /approvals/health`.
## Local dev
```
cd apps/rithub-approvals
RITHUB_BASE_URL=https://rithub.dev node bin/start.mjs
```
Needs a real `git` on PATH (used for every land/discard operation) and
network access to `RITHUB_BASE_URL`.