A release job gets a ten-minute SSH certificate for one command (AHT-231) #208

Merged
merge-queue merged 1 commit from forgejo-release-cert into main 2026-11-29 08:54:23 -08:00
Owner

Step 1 of the certificate delivery plan on AHT-231: a release's delivery job holds no stored key. It exchanges its own Forgejo Actions job token for a ten-minute SSH certificate that can run one command.

What it does

  • New endpoint POST /api/auth/exchange/ssh-cert/forgejo (src/forgejo-actions-auth.ts). Bearer is the job's OIDC token; body is {public_key, purpose}. The token is verified the way the k8s exchanges verify theirs (RS256, the issuer's published keys through discovery, issuer https://forgejo.romaine.life/api/actions, audience https://auth.romaine.life/ssh-cert, unexpired), then a claim rule must accept it.
  • The server fixes everything else. at-update-release gives principal forgejo-release:at-update with force-command "C:\Program Files\at-home\at-update\current\at-update.exe" --task-run; treadmill-wake gives forgejo-release:nas-wake with sudo /usr/syno/sbin/synonet --wake E8:FF:1E:D8:9B:FB eth0. 600 seconds, key id forgejo:<repository>:<run_id>, no extensions. public_key must be ssh-ed25519 and not a certificate.
  • Claim rules are a table, forgejoActions.sshCertRules in k8s/values.yaml, passed to the pod as FORGEJO_SSH_CERT_RULES. As shipped: release/ci.yml in any nelsong6/* or romaine-life/* repository on refs/heads/main or refs/heads/master, started by push or workflow_dispatch; and pipeline-templates' deliver.yml dispatched on its main. No matching row refuses; an empty or unreadable table refuses every job; a pull request event is refused even if a row lists it.
  • src/ssh-cert.ts: signUserCert takes an optional forceCommand, written as the force-command critical option. Without it the certificate is byte-for-byte what it was (the existing tests still assert empty critical options).
  • Client (client/ssh-host.go): romaine-auth ssh-host accepts the forgejo-release:at-update principals line only as command="<that command>",restrict forgejo-release:at-update (client.ReleasePrincipalLine), in either option order, at most once, and refuses it bare, with another command, with an option added back, or for any other forgejo-release: principal. The CLI now reads the principals file by line so that line stays whole. device: lines are read and checked exactly as before, and --user-scope still refuses the release line.
  • Metric auth_ssh_cert_forgejo_exchange_total{result}; log lines forgejo ssh certificate issued and forgejo ssh certificate refused. README section "A release job's certificate".

What it doesn't do

  • Nothing calls the endpoint yet, and no host lists either principal: the PCs' principals line (at-home-tools), the NAS line and the delivery workflow (pipeline-templates) are the plan's later steps.
  • It does not touch the existing POST /api/auth/exchange/ssh-cert (glimmung's), its allowlist, or the machine certificates.
  • No key or secret is added. The certificates are signed with the SSH CA key auth already holds.

Not yet confirmed, and how the logs settle it

Which workflow a called workflow's token names in workflow and workflow_ref has not been read from a real token. The release suite reaches the PCs through pipeline-templates' deliver.yml as a called workflow; the shipped rule assumes that job's token names the caller's release/ci.yml (existing OpenBao roles bind workflow to values of that form, such as tofu/ci.yml). If the token names deliver.yml instead, the request is refused with 403 denied_claims and nothing is issued. Every refusal of a verified token writes one forgejo ssh certificate refused line carrying repository, ref, workflow, workflow_ref, event_name and run_id as the token had them, and never the token, so the first real delivery either gets its certificate or shows the exact values to put in the table. workflow_ref is not bound by the shipped rows for the same reason; a row can bind it with workflowRefs once its form is known.

Also not confirmed: that auth's pod reaches forgejo.romaine.life (a failure is 503 error_issuer_unreachable, logged, and retried on the next request rather than kept until a restart), and the job token's lifetime.

Tests

  • src/forgejo-actions-auth.test.ts: tokens signed with a locally generated RS256 key behind a local JWKS, against the rules read from k8s/values.yaml. Accepted: release on main/master by push/dispatch, pipeline-templates' dispatch. Refused: wrong repository, ref, workflow, event, pull request events, missing or non-text claims, bad run id; wrong audience, issuer, signing key, expired, HS256; unknown purpose; a non-ed25519 key or a certificate as the key. Each purpose's certificate decodes to its one principal, the force-command critical option alone, no extensions, 600 seconds, and verifies under the CA; ssh-keygen -L reads the same.
  • client/ssh-host_test.go: the release line accepted only with its command and restrict; refused bare and in eleven other forms; device: lines unchanged.

🤖 Generated with Claude Code

Step 1 of the certificate delivery plan on [AHT-231](https://openproject.home.romaine.life/wp/AHT-231): a release's delivery job holds no stored key. It exchanges its own Forgejo Actions job token for a ten-minute SSH certificate that can run one command. ## What it does - **New endpoint** `POST /api/auth/exchange/ssh-cert/forgejo` (`src/forgejo-actions-auth.ts`). Bearer is the job's OIDC token; body is `{public_key, purpose}`. The token is verified the way the k8s exchanges verify theirs (RS256, the issuer's published keys through discovery, issuer `https://forgejo.romaine.life/api/actions`, audience `https://auth.romaine.life/ssh-cert`, unexpired), then a claim rule must accept it. - **The server fixes everything else.** `at-update-release` gives principal `forgejo-release:at-update` with force-command `"C:\Program Files\at-home\at-update\current\at-update.exe" --task-run`; `treadmill-wake` gives `forgejo-release:nas-wake` with `sudo /usr/syno/sbin/synonet --wake E8:FF:1E:D8:9B:FB eth0`. 600 seconds, key id `forgejo:<repository>:<run_id>`, no extensions. `public_key` must be `ssh-ed25519` and not a certificate. - **Claim rules are a table**, `forgejoActions.sshCertRules` in `k8s/values.yaml`, passed to the pod as `FORGEJO_SSH_CERT_RULES`. As shipped: `release/ci.yml` in any `nelsong6/*` or `romaine-life/*` repository on `refs/heads/main` or `refs/heads/master`, started by `push` or `workflow_dispatch`; and pipeline-templates' `deliver.yml` dispatched on its `main`. No matching row refuses; an empty or unreadable table refuses every job; a pull request event is refused even if a row lists it. - **`src/ssh-cert.ts`**: `signUserCert` takes an optional `forceCommand`, written as the `force-command` critical option. Without it the certificate is byte-for-byte what it was (the existing tests still assert empty critical options). - **Client** (`client/ssh-host.go`): `romaine-auth ssh-host` accepts the `forgejo-release:at-update` principals line only as `command="<that command>",restrict forgejo-release:at-update` (`client.ReleasePrincipalLine`), in either option order, at most once, and refuses it bare, with another command, with an option added back, or for any other `forgejo-release:` principal. The CLI now reads the principals file by line so that line stays whole. `device:` lines are read and checked exactly as before, and `--user-scope` still refuses the release line. - **Metric** `auth_ssh_cert_forgejo_exchange_total{result}`; log lines `forgejo ssh certificate issued` and `forgejo ssh certificate refused`. README section "A release job's certificate". ## What it doesn't do - Nothing calls the endpoint yet, and no host lists either principal: the PCs' principals line (at-home-tools), the NAS line and the delivery workflow (pipeline-templates) are the plan's later steps. - It does not touch the existing `POST /api/auth/exchange/ssh-cert` (glimmung's), its allowlist, or the machine certificates. - No key or secret is added. The certificates are signed with the SSH CA key auth already holds. ## Not yet confirmed, and how the logs settle it Which workflow a **called** workflow's token names in `workflow` and `workflow_ref` has not been read from a real token. The release suite reaches the PCs through pipeline-templates' `deliver.yml` as a called workflow; the shipped rule assumes that job's token names the caller's `release/ci.yml` (existing OpenBao roles bind `workflow` to values of that form, such as `tofu/ci.yml`). If the token names `deliver.yml` instead, the request is refused with 403 `denied_claims` and nothing is issued. Every refusal of a verified token writes one `forgejo ssh certificate refused` line carrying `repository`, `ref`, `workflow`, `workflow_ref`, `event_name` and `run_id` as the token had them, and never the token, so the first real delivery either gets its certificate or shows the exact values to put in the table. `workflow_ref` is not bound by the shipped rows for the same reason; a row can bind it with `workflowRefs` once its form is known. Also not confirmed: that auth's pod reaches `forgejo.romaine.life` (a failure is 503 `error_issuer_unreachable`, logged, and retried on the next request rather than kept until a restart), and the job token's lifetime. ## Tests - `src/forgejo-actions-auth.test.ts`: tokens signed with a locally generated RS256 key behind a local JWKS, against the rules read from `k8s/values.yaml`. Accepted: release on main/master by push/dispatch, pipeline-templates' dispatch. Refused: wrong repository, ref, workflow, event, pull request events, missing or non-text claims, bad run id; wrong audience, issuer, signing key, expired, HS256; unknown purpose; a non-ed25519 key or a certificate as the key. Each purpose's certificate decodes to its one principal, the `force-command` critical option alone, no extensions, 600 seconds, and verifies under the CA; `ssh-keygen -L` reads the same. - `client/ssh-host_test.go`: the release line accepted only with its command and `restrict`; refused bare and in eleven other forms; `device:` lines unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A release job gets a ten-minute SSH certificate for one command (AHT-231)
All checks were successful
Suite default / check-rules (pull_request) Successful in 7s
Suite default / reused-checks (pull_request) Successful in 5s
Suite default / check-logs (pull_request) Successful in 7s
Suite go / check-format (pull_request) Successful in 8s
Suite go / check-test-linux (pull_request) Successful in 10s
Suite release / check-build (go, ubuntu-latest) (, go, false, ubuntu-latest, , go) (pull_request) Successful in 20s
Suite release / module (pull_request) Has been skipped
Suite release / reserve (pull_request) Has been skipped
Suite release / finalize (pull_request) Has been skipped
Suite release / deploy-image (pull_request) Has been skipped
Suite go / check-test-windows (pull_request) Successful in 47s
Suite web-app / check-test (.) (pull_request) Successful in 57s
Suite release / check-package (pull_request) Successful in 36s
Suite tofu / reused-checks (pull_request) Successful in 6s
Suite release / home-sync (pull_request) Has been skipped
Suite default / scope (pull_request) Successful in 6s
Suite tofu / check-plan (pull_request) Has been skipped
Suite tofu / apply (pull_request) Has been skipped
Suite web-app / check-image (pull_request) Has been skipped
Suite web-app / publish (pull_request) Has been skipped
Suite web-app / publish-static (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite default / check-fetches (pull_request) Has been skipped
Suite release / scope (pull_request) Successful in 7s
Suite release / build (go, ubuntu-latest) (, go, false, ubuntu-latest, , go) (pull_request) Has been skipped
Suite release / publish (pull_request) Has been skipped
Suite go / reused-checks (pull_request) Successful in 4s
Suite web-app / reused-checks (pull_request) Successful in 4s
Suite release / reused-checks (pull_request) Successful in 4s
merge-queue landed on main
838cd58830
POST /api/auth/exchange/ssh-cert/forgejo takes a Forgejo Actions job token and an
ed25519 public key and signs a certificate whose principal and force-command auth
fixes per purpose (at-update-release, treadmill-wake): 600 seconds, no extensions,
key id forgejo:<repository>:<run_id>. A table of claim rules in k8s/values.yaml
decides which jobs are let in; no matching rule refuses, a pull request event is
always refused, and a refusal logs the token's claims, never the token.

romaine-auth ssh-host installs the forgejo-release:at-update principal only as the
line with its forced command and restrict, and refuses it bare.
merge-queue deleted branch forgejo-release-cert 2026-11-29 08:54:23 -08:00
Sign in to join this conversation.
No description provided.