Skip to content

feat(control-plane): an installer token for the members API (SH_INSTALLER_TOKEN) - #888

Merged
pdettori merged 1 commit into
mainfrom
feat/sbx-installer-token
Nov 18, 2026
Merged

pdettori merged 1 commit into
mainfrom
feat/sbx-installer-token

Conversation

@galmasi

@galmasi galmasi commented Nov 18, 2026

Copy link
Copy Markdown

What

A static operator bearer — SH_INSTALLER_TOKEN, generated by deploy/sbx/setup.sh into moca-mu1 — that admits the members routes only (GET/PUT/DELETE /v1/subjects and 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

  • The five members routes move to a new auth: 'admin' flavor: an admin's API token (exactly as before — mocactl sbx admin is unchanged) or the installer's bearer. Handlers still enforce the admin role on both paths
  • The bearer check is timing-safe over fixed-length SHA-256 digests, fail-closed (unset matches nothing); a non-matching bearer falls through to API-token verification and is refused as any non-token is
  • A match mints the synthetic installer principal with the admin role — a subject form SUBJECT_RE refuses, so no login can ever mint it; onAllowList admits the role, so the enrollment gate holds; every audit line names subject: installer
  • settingsAdmin (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 configured
  • 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
  • Rotation: delete the key from moca-mu1 and re-run setup.sh — every pod rolls; the old bearer stops working at once

Tests

New installer-auth.test.ts drives 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.yaml documents the scheme (OR-security on the five routes). Control-plane suite (1998 tests), make typecheck, and make test-deploy all 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

…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]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 18, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] : []),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/api/openapi.yaml
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/api/openapi.yaml
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: [] }]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deploy/sbx/setup.sh
# 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread deploy/sbx/setup.sh
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@pdettori
pdettori merged commit 4c7e4ce into main Nov 18, 2026
23 of 24 checks passed
@pdettori
pdettori deleted the feat/sbx-installer-token branch November 18, 2026 20:46
@evaline-ju evaline-ju mentioned this pull request Nov 18, 2026
1 of 5 tasks
webchang added a commit to webchang/moca that referenced this pull request Nov 19, 2026
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]>
webchang added a commit to webchang/moca that referenced this pull request Nov 19, 2026
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]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants