Repository navigation
feat(control-plane): an installer token for the members API (SH_INSTALLER_TOKEN) - #888
Conversation
…LLER_TOKEN) A static operator bearer for the members routes -- GET/PUT/DELETE /v1/subjects and its roles routes -- and nowhere else: automation that enrolls users (an enrollment sync reading a registration repo, say) needs no login, no refresh tokens and no admin's credential. It cannot create sessions, run sandboxes or touch credentials. - routes.ts: the five members routes move to a new auth flavor 'admin': an admin's API token (as before) or the installer's bearer. Handlers still enforce the admin role on both paths, and settingsAdmin still admits settings-named admins alone -- the installer subject joins the members store's bootstrap admins when the token is configured, so the API never widens access beyond what the settings' admins control. - server.ts: the bearer is checked first, timing-safe over fixed-length SHA-256 digests, fail-closed (an unset SH_INSTALLER_TOKEN matches nothing); a match mints the synthetic 'installer' principal with the admin role -- a subject form SUBJECT_RE refuses, so no login can ever mint it, and onAllowList admits the role, so the enrollment gate holds. A non-matching bearer falls through to API-token verification and is refused as any non-token is. - main.ts: SH_INSTALLER_TOKEN rides CONTROL_PLANE_SECRETS (a file under CREDENTIALS_DIRECTORY, never an env line), must be 32+ characters, and is pairwise-distinct from the janitor's and every egress host's bearer. - deploy/sbx: setup.sh generates it once into moca-mu1 (kept across re-runs; rotate by deleting the key), and the ocp-sbx overlay and its two components mount it beside the janitor's. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: George Almasi <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This PR moves the five members routes from auth: 'api' to a new auth: 'admin' flavor that accepts an admin's API token or the static SH_INSTALLER_TOKEN, which mints a synthetic installer principal with the admin role. The auth fall-through (a non-matching bearer still reaches verifyToken, so admin API tokens work unchanged), the timing-safe fixed-length comparison, fail-closed behavior, secret plumbing (moca-mu1 → CONTROL_PLANE_SECRETS → CREDENTIALS_DIRECTORY), overlay mounts and test updates all check out; ensure_signing_key runs before apply_stack, so there is no upgrade ordering problem.
The findings are non-blocking: the installer is wired as a settings admin and can mint admins (a token-holder can escalate to a full admin login); the new installer subject appears in GET /v1/subjects against a schema that forbids it; the API change is missing its version/changelog entry; the operator docs and security review do not mention the new credential; and the combined profile carries a dead token.
Author: galmasi (MEMBER — maintainer)
Areas reviewed: TypeScript (control plane), OpenAPI docs, K8s overlays, Shell (setup.sh + tests), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes (DCO pass)
CI status: all green except deploy-scripts-bash32, which was cancelled after 17 min with zero steps executed (macOS runner never picked it up — infrastructure, not this diff). deploy-scripts (the same suites on bash 5) passed. Recommend a re-run before merge; deploy/sbx/tests/setup.test.sh is not in the bash-3.2 suite anyway.
PR format: conventional feat(...) title, 80 chars (72 is the advisory limit) — nit only.
| // alone so the API never widens access beyond them. | ||
| admins: [ | ||
| ...adminSubjectsFromEnv(env.SH_ADMIN_SUBJECTS), | ||
| ...(config.installerToken ? [INSTALLER_SUBJECT] : []), |
There was a problem hiding this comment.
The installer joins bootstrap.admins, which makes it a settings admin for every members operation — including PUT/DELETE /v1/subjects/{subject}/roles/admin. A holder of SH_INSTALLER_TOKEN can therefore grant the admin role to a github:<id> it controls and then log in as that subject: the router re-reads roles per request (membershipNow), so that login holds admin on every admin-gated route on this profile (list/delete every sandbox with ?all=, set policy and quotas, transfer templates, /metrics). The static bearer is effectively a full sbx-admin credential, which is broader than the "enroll users" scope the description claims, and a leaked token is a persistent admin escalation until someone deletes the key. Consider refusing grantAdmin/revokeAdmin (and maybe the subject DELETE) when p.sub === INSTALLER_SUBJECT, keeping enroll/unenroll for the automation; at minimum, document the token as admin-equivalent rather than janitor-scoped.
| The sandbox host janitor's `SH_JANITOR_TOKEN` (SBX0 §8.3); admits GET /v1/janitor/sandboxes | ||
| only. No user or admin API token is accepted there, and with none configured every call is | ||
| refused. | ||
| installerToken: |
There was a problem hiding this comment.
Because the installer is added to the members store's bootstrap admins, GET /v1/subjects now returns an entry with subject: "installer", enrolled: true, source: "env". But components.schemas.Subject.subject (line 1012) is ^(?:github:[0-9]+|oidc:…)$, so the response violates the documented contract, and source: env is described as "the deployment's settings", which this is not. Either omit INSTALLER_SUBJECT from MembersStore.list() or extend the schema/description to cover the synthetic install subject. Clients built from this document will otherwise see a subject the schema says cannot exist.
| settings (`source: env`: SH_ALLOWED_SUBJECTS, SH_ADMIN_SUBJECTS) or through this API | ||
| (`source: api`). Roles are evaluated per request: an API grant past its `until` is not listed. | ||
| security: [{ sessionToken: [] }] | ||
| security: [{ sessionToken: [] }, { installerToken: [] }] |
There was a problem hiding this comment.
This is an additive contract change (a new security scheme and a new auth alternative on five routes), so docs/reference/change-policy.md decision 5 asks for a minor info.version bump and a CHANGELOG entry — neither is here. The PR's base predates main's current 1.30.0, so merge main first and take 1.31.0. The contract test only enforces that openapi and CHANGELOG agree, so it will not catch the omission.
| # SBX_API_CA_FILE optional; a PEM CA the janitor trusts for the API Route, when that Route's | ||
| # certificate (the router's default, say) is not publicly trusted | ||
| # | ||
| # The installer token (SH_INSTALLER_TOKEN, in moca-mu1): generated once and kept, like the janitor's. |
There was a problem hiding this comment.
The setup.sh header documents rotation, but the operator docs do not. deploy/sbx/RUNBOOK.md still says "Remove that one key only: moca-mu1 also holds the janitor's token (SH_JANITOR_TOKEN)" — it now holds SH_INSTALLER_TOKEN too, and the janitor-rotation section is the natural place to add "the installer token rotates the same way (delete the key, re-run, roll the pods)". docs/sbx/security-review.md enumerates the route bearers and should name this new static one as well.
| export S_0="$priv" S_1="$jtok" S_2="$kid:$spki" S_3="$kek" S_4="$xtok" S_5="$itok" | ||
| apply_secret moca-mu1 SH_SESSION_TOKEN_PRIVATE_KEY SH_JANITOR_TOKEN SH_SESSION_TOKEN_PUBLIC_KEYS \ | ||
| SH_CREDENTIAL_KEK SH_EXCHANGE_TOKEN | ||
| SH_CREDENTIAL_KEK SH_EXCHANGE_TOKEN SH_INSTALLER_TOKEN |
There was a problem hiding this comment.
In SBX_PROFILE=combined, setup.sh now generates, stores and preserves SH_INSTALLER_TOKEN, but nothing reads it there: combinedProfileConfig never sets config.installerToken, so templateCatalogFromEnv does not add the installer subject to the bootstrap admins, and ocp-combined does not mount the key. Either wire the combined profile (and its bootstrap admins) to it, or do not generate it in combined mode — otherwise operators rotate a credential that has no effect.
| d = makeDeps({ config: { installerToken: TOKEN, routeProfile: 'sandbox' } }); | ||
| // The sandbox profile needs a signing key on the deps the harness did not set: reuse the one | ||
| // makeDeps built (makeDeps' own signer), which startControlPlane verifies against. | ||
| void signer; |
There was a problem hiding this comment.
generateKeyPairSync/makeSigner/signer/void signer are dead here (makeDeps already installs a signer), and the comment above contradicts the code: it says to reuse the signer makeDeps built, but nothing is reused. Two coverage gaps worth closing while here: (a) nothing exercises the installer as a settings admin against a real members store — that it passes settingsAdmin, enrolls/grants, and that records name by: installer; (b) the new SH_INSTALLER_TOKEN under-32-characters boot refusal in sandboxProfileConfig is untested (the janitor's equivalent is covered in sandbox-config.test.ts).
Brings 15 upstream merges since 2eb0219, among them the R2 host sampler in its reviewed form (rossoctl#904), the workspace-reset marker (rossoctl#895), turn budgets and cancel (rossoctl#856), the egress allow-all option (rossoctl#886), the sbx installer token (rossoctl#888), and the docs site with the product-name prose (rossoctl#884, rossoctl#885, rossoctl#899). One conflict, deploy/sbx/template-onboarding/README.md: upstream's product-name wording for the deploy/sbx table, keeping the fork's mint-login.sh row. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
GUIDE.pdf regenerated from GUIDE.md, which upstream moved to the product-name prose and the docs/sandbox paths. docs/specs/README.md's fork paragraph links the templates how-to instead of the moved user guide. GAPS-AND-ASSUMPTIONS names API 1.31.0 (harness 1.7.0) and notes under G38 that the installer bearer (rossoctl#888) counts as a settings admin. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
What
A static operator bearer —
SH_INSTALLER_TOKEN, generated bydeploy/sbx/setup.shintomoca-mu1— that admits the members routes only (GET/PUT/DELETE /v1/subjectsand its roles routes). Automation that enrolls users (e.g. a sync job reading a registration repo) needs no login, no refresh tokens, and no admin's credential. It cannot create sessions, run sandboxes, or touch credentials — scoped like the janitor's bearer, not a Vault-style root.How
auth: 'admin'flavor: an admin's API token (exactly as before —mocactl sbx adminis unchanged) or the installer's bearer. Handlers still enforce the admin role on both pathsinstallerprincipal with the admin role — a subject formSUBJECT_RErefuses, so no login can ever mint it;onAllowListadmits the role, so the enrollment gate holds; every audit line namessubject: installersettingsAdmin(the invariant that the API never widens access beyond settings-named admins) is preserved: the installer subject joins the members store's bootstrap admins only when the token is configuredSH_INSTALLER_TOKENridesCONTROL_PLANE_SECRETS(a file underCREDENTIALS_DIRECTORY, never an env line), must be 32+ characters, and is pairwise-distinct from the janitor's and every egress host's bearermoca-mu1and re-run setup.sh — every pod rolls; the old bearer stops working at onceTests
New
installer-auth.test.tsdrives the real HTTP server: the bearer authorizes the members routes, wrong/missing bearers are refused, the bearer is refused on plain-api routes, and nothing matches when unconfigured. Route-table, contract, and secrets-list tests updated for the new flavor;openapi.yamldocuments the scheme (OR-security on the five routes). Control-plane suite (1998 tests),make typecheck, andmake test-deployall green.Motivated live: the enrollment-sync CronJob design needed a non-interactive admin credential, and minting one via w3id required a browser login plus a 90-day refresh-token re-mint cycle.
Assisted-By: Claude Code