Skip to content

feat: generic OIDC identity provider (w3id) behind the login seam - #701

Merged
pdettori merged 19 commits into
mainfrom
feat/oidc-identity-provider
Nov 11, 2026
Merged

pdettori merged 19 commits into
mainfrom
feat/oidc-identity-provider

Conversation

@galmasi

@galmasi galmasi commented Nov 9, 2026 •

Copy link
Copy Markdown

What

Adds a generic OIDC identity provider alongside GitHub's OAuth device flow, so deployments inside IBM (w3id) or in front of any enterprise OIDC provider (Keycloak, Dex, Entra) can log in. Verified end to end on a live cluster: a real w3id login (authorize → browser SSO → callback → code exchange → JWKS verification → API token + refresh family), then a reset back to GitHub logins on the same image to confirm no regression.

Approach

The browser authorization-code flow with the control plane itself as the redirect target (its GET /v1/auth/oidc/callback, typically behind an OpenShift Route). The state token plays the device code and the authorize URL plays the verification URI, so mocactl's polling login needed zero logic changes — and the code exchange plus client secret stay entirely server-side; mocactl never sees either.

Review status (thanks @ingpaolodettori-dev)

  • ✅ Rebase done. The branch is rebased onto current main (was 174 behind, 10 conflicting files). The subject grammar is reconciled three ways: SUBJECT_RE admits github:<id>, test:<index> (ADR-0045) and oidc:<sub>, and the sandbox-profile boot guard's message now says github:/oidc: instead of only github:.
  • ✅ Client secret is a file, not an env var. It rides the projected credentials volume as /run/credentials/SH_OIDC_CLIENT_SECRET (the moca-test-users pattern, MI1 §6.7), so no kubectl child inherits it; no code change was needed — it was already in CONTROL_PLANE_SECRETS.
  • ✅ Browser↔terminal binding (ed1db012). The authorize URL was itself a capability: an attacker who starts a login and walks a victim with a live SSO session into opening the URL got a fully verified login as the victim. The fix is the device flow's binding, re-expressed: the login start mints a short user code (XXXX-XXXX, no confusables) shown only in the terminal and never in the URL; the callback runs in two rounds — the provider's redirect exchanges and verifies the id_token but parks the principal unconfirmed and renders an HTML form, and the typed code (constant-time compare, ≤5 tries) settles the login. The poll keeps answering authorization_pending until then, which is the walk-in attack failing exactly there. mocactl needs no change; there is a dedicated test asserting the attack fails.

Commits

  1. c272e0a5 — the provider. OidcProvider behind the existing IdentityProvider seam: discovery (issuer cross-checked per OIDC §4.3), server-side code exchange, RS256 id_token verification against a cached JWKS (refetched once on unknown kid), iss/aud/exp/sub checks. The callback route is browser-facing plain text; an unverified id_token settles a denial so the poll reports it instead of hanging in authorization_pending. SH_IDENTITY_PROVIDER selects github (default, unchanged) or oidc. mocactl: userCode optional, provider-neutral prompt/TUI/expiry messages. 16 offline tests with real per-run RSA keypairs. Docs: openapi.yaml, env-var rows, docs/guides/oidc-login-w3id.md.
  2. a6857eb7 — deploy plumbing. Five sticky keys in moca-settings, Deployment env from ConfigMap + the client secret as a projected credential file; a GitHub stack renders exactly as before. Replica decision counts either provider. Validated against the mock-kubectl setup harness and the supervisor manifest-render tests.
  3. cedcf18f — boot fix (found deploying live): configFromEnv required SH_GITHUB_CLIENT_ID unconditionally, CrashLooping an oidc deployment before provider selection ever ran.
  4. 19de8dee — email sub fix (found logging in live): w3id's sub is the intranet email address; the subject charset now allows @/+ (still no whitespace or :, the provider/subject separator).
  5. 5dc5cdee — rebase reconciliation. The three-way subject grammar and boot-guard message; the client secret moved into the projected credentials volume.

Testing

  • control-plane: 1145 passing (with a live Redis); mocactl: 1704 passing; supervisor manifest renders and the deploy/k8s setup harness green; tsc --noEmit and prettier clean in every touched package.
  • Live: full w3id login on OpenShift (epoc001), including two real misconfigurations the offline tests had masked (commits 3 and 4), then reset to GitHub device-flow login on the same image.

Known limitations (documented in the guide)

  • Pending login states live in the control plane pod's memory — run one replica (the default) until a Redis-backed PendingAuthStore lands.
  • RS256 only; id_token sub must match the documented charset.
  • Ship the mocactl update with or before the server change for OIDC deployments (an older mocactl renders undefined where the user code goes — polling still works).

Assisted-By: Claude Code

@galmasi
galmasi requested a review from mrsabath November 9, 2026 19:23
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 9, 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.

Thanks: the provider is careful work (issuer cross-check, kid-refetch, a denial that settles the poll, real-key tests). Three things block merge.

must-fix

  1. Rebase. The branch conflicts with main and CI never ran. mergeable_state is dirty. The branch is 174 commits behind, and 10 files conflict (control-plane.yaml, setup.sh, openapi.yaml, configuration.md, handlers.ts, identity.ts, index.ts, main.ts, routes.ts, routes.test.ts). Because of the conflict, only DCO has run on this head: no ci, lint, k8s-kind-e2e, or codeql. Main has since landed #616 (test-user logins, ADR-0045), which touches the same seams: TEST_SUBJECT_RE / test:N subjects, a testUsers provider path in main.ts, a sandbox-profile boot guard whose message says only github: subjects can be enrolled, and the projected credentials volume. The rebase has to reconcile SUBJECT_RE and that guard with test:N and oidc:.
  2. The OIDC client secret is delivered as an env var. See the inline comment on control-plane.yaml. That contradicts MI1 §6.7 and this manifest's own header ("Its secrets are FILES under CREDENTIALS_DIRECTORY"). The control plane spawns kubectl without an env option, so every child inherits it.
  3. Nothing binds the browser that finishes the login to the terminal that started it (inline on oidc.ts). The authorize URL is the capability. Anyone who gets a victim to open it while the victim has a live w3id SSO session logs in as the victim, with one click and no code or consent screen. GitHub's device flow, which this borrows its trust model from, has the user code and the "authorize this device" page as that binding.

Suggestions and nits are inline.


Author: galmasi (MEMBER, maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), K8s manifests, Shell (setup.sh), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits, all signed off: yes
CI status: not run (merge conflict); DCO only

Comment thread deploy/k8s/base/control-plane.yaml Outdated
# Absent when no moca-oidc Secret exists; the control plane refuses to boot with
# SH_IDENTITY_PROVIDER=oidc and no secret, naming it -- a misconfiguration the
# readiness probe surfaces as a CrashLoop with that message in the pod log.
- name: SH_OIDC_CLIENT_SECRET

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: SH_OIDC_CLIENT_SECRET arrives here as an env var through secretKeyRef. MI1 §6.7 (systemd-credentials.ts) says secrets are files, never env vars, because env is inherited by children and visible in /proc/<pid>/environ. withCredentials returns a copy, but process.env still holds the value, and kubectl.ts spawn('kubectl', args, …) passes no env, so every kubectl child gets the client secret. The guide (oidc-login-w3id.md) also says "mounted or resolved like the other CONTROL_PLANE_SECRETS", but the other secrets are mounted, not resolved from env. After the rebase, follow main's ADR-0045 pattern: add - secret: { name: moca-oidc, optional: true, items: [{ key: SH_OIDC_CLIENT_SECRET, path: SH_OIDC_CLIENT_SECRET }] } as another source of the projected credentials volume, and drop this env entry. credentialValue already maps ENOENT to unset, and required() then names the missing secret for an oidc deployment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 5dc5cdee: the secret now rides the projected credentials volume as /run/credentials/SH_OIDC_CLIENT_SECRET (the moca-test-users pattern), so no kubectl child inherits it — verified on a live deployment (ENV_VAR_PRESENT=[]). It was already in CONTROL_PLANE_SECRETS, so withCredentials reads the file with no code change.

* the id_token against the provider's JWKS, and parks the principal against the state.
* 4. mocactl's poll (POST /v1/auth/device/token) picks it up, exactly as with GitHub.
*
* The STATE is the capability, on the device-code trust model: single-use, TTL-bound, and worth

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (security): "The STATE is the capability, on the device-code trust model". The device-code model has a second factor that this flow drops. The user sees a code on their terminal and confirms the same code on a provider consent page. Here, the authorize URL alone carries the state. An attacker can run POST /v1/auth/device, send the verificationUri to a colleague ("please open this moca link"), and poll. If the victim has a live w3id SSO session, the provider redirects straight to the callback, and the attacker's poll receives a refresh family for oidc:<victim>, admin role included if the victim is in SH_ADMIN_SUBJECTS. This is one click, with no prompt to the victim. Options: (a) have the callback render a confirmation page showing a short code that mocactl also prints, settling only on a POST after the user confirms it matches (CSRF-protected); (b) use an RFC 8252 loopback redirect, so the code returns to the mocactl process that started the login (it needs PKCE then, and a public client or a server-side exchange keyed by verifier); (c) at minimum, bind the state to a secret held only by mocactl, e.g. mocactl sends a code_challenge on /v1/auth/device and must present the verifier on poll. Note that (c) alone does not stop phishing, because the attacker's own mocactl holds the verifier. (a) or (b) is the real fix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in ed1db012 and completed in ca44063c: the login start now mints a terminal-displayed user code, and the callback runs a confirmation round. See also the round-2 threads — the code alone was not sufficient, and the final binding adds a browser-bound token.

const e = await this.get(state);
if (!e) return false;
// A settled entry keeps its TTL: the polling client has the rest of the window to collect it.
Object.assign(e, patch);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: settle patches an entry that is already settled. A second callback overwrites the outcome, for example GET /v1/auth/oidc/callback?state=<s>&error=x turns a successful login into a denial (or, for a token-exchange path, replaces the principal). The state ends up in browser history and provider logs. Refuse to settle an entry that already has a principal or denial. That also makes the state single-use at the callback, not only at the poll. A Redis-backed store will need this to be atomic (SET NX or a Lua CAS) anyway.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 7383fb4c: settle is write-once per outcome — a principal is never replaced, a denial is terminal, and provider-side refusals (a replayed ?error=, a failed exchange) never flip a login that already succeeded past the provider. Only the confirm path's too-many-wrong-codes transition may deny a parked entry. Tests cover the replay and the double-exchange.

Comment thread packages/control-plane/src/oidc.ts Outdated
// 32 random bytes, base64url: the state is the capability the client polls with, so it is
// unguessable for the same reason a device code or refresh token is.
const state = randomBytes(32).toString('base64url');
await this.store.put({ state, expiresAtMs: this.now() + this.stateTtlS * 1000 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: POST /v1/auth/device is unauthenticated, and each call now parks an entry in pod memory for 15 minutes with no cap. Under the GitHub provider, GitHub absorbed this and rate-limited it. Here the control plane holds every entry itself, so a loop of anonymous POSTs grows the Map until the 512Mi limit OOMs the pod. A full sweep also runs on every touch, so each call costs O(n). Cap the pending entries (refuse with 503 + Retry-After past N), or rate-limit the route.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 7383fb4c: put() caps live entries (10k default) and login starts past the cap answer quota_exceeded (429); the expiry sweep runs only when a put would be refused, so the common path is O(1). Test fills a capped store, asserts the 429, and asserts recovery after expiry.

Comment thread packages/control-plane/src/identity.ts Outdated
* `oidc:<provider sub>` (oidc.ts). One RE so enrollment (SH_ALLOWED_SUBJECTS) can validate entries
* without knowing which provider the deployment runs.
*/
export const SUBJECT_RE = /^(?:github:[0-9]+|oidc:[A-Za-z0-9][A-Za-z0-9._@+-]{0,127})$/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: SUBJECT_RE restates SUB_RE from oidc.ts by hand. If one changes without the other (as commit 14b3cd9 had to change both), enrollment and login will disagree. Build it from one exported source, e.g. new RegExp(^(?:github:[0-9]+|oidc:${SUB_PATTERN})$). When rebasing, decide whether test:N belongs here. Main's sandbox-profile guard (main.ts sandboxProfileConfig) refuses SH_TEST_USERS because only github: subjects can be enrolled, and its message needs updating for oidc:.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in c97f5c94: both SUBJECT_RE and SUB_RE now build from one exported OIDC_SUB_PATTERN in identity.ts, so enrollment and token verification cannot drift. The rebase reconciliation (test:N in the grammar, the boot-guard message) landed in 5dc5cdee.

</Box>
) : null}
<Spinner
label={`waiting for approval · code expires in ${formatDuration(secondsLeft * 1000)}`}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: this still says "code expires in", and the hints at L90 still offer "c copy code" when there is no user code (the c key is now a no-op). Make both conditional on start.userCode, like the prompt text.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in f04c71f2: the c copy code hint is conditional on start.userCode existing, and the spinner says 'sign-in window closes in' rather than 'code expires in'.

if (!aud.includes(this.clientId)) {
throw new CpError('unauthorized', 'the id_token audience is not this client');
}
if (typeof claims.exp !== 'number' || claims.exp + this.clockSkewS <= nowS) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: iat/nbf are not checked. They're not strictly required with a server-side code exchange, but an nbf in the future (beyond skew) is cheap to refuse and matches OIDC Core §3.1.3.7.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in b8297857: nbf beyond the clock-skew allowance is refused, per OIDC Core §3.1.3.7. Tested alongside the exp case.

@clawgenti clawgenti 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 adds a generic OIDC provider (authorization-code flow, with the control plane as the redirect target) behind the existing identity seam. The provider code is careful: it cross-checks the discovery issuer, refetches the JWKS on an unknown kid, and tests against real per-run RSA keys. I agree with the three must-fix items in the existing CHANGES_REQUESTED review on this head and don't repeat them here. Above all, the branch conflicts with main (mergeable_state: dirty), so only DCO has run on 14b3cd9: no CI, lint, e2e or CodeQL. This review adds two suggestions and one nit not covered there.

Must-fix (restated, not new): rebase onto main so CI runs on this head.

Author: galmasi (NONE — first-time tier per the REST author_association. This may only mean private org membership; another reviewer lists the author as a maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), K8s manifests, Shell (setup.sh), Docs, Tests
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits, all signed-off: yes
CI status: DCO only (merge conflict blocks the rest)

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread packages/control-plane/src/oidc.ts Outdated
for (const k of ['issuer', 'clientId', 'clientSecret', 'redirectUri'] as const) {
if (!opts[k]) throw new Error(`the oidc identity provider requires ${k}`);
}
this.issuer = opts.issuer.replace(/\/+$/, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: stripping trailing slashes from the configured issuer breaks providers whose issuer legitimately ends in /. Auth0 is one (https://<tenant>.auth0.com/). OIDC Discovery §4.3 and Core §3.1.3.7 require an exact match, and both checks (L182 against discovery issuer, and claims.iss in verifyIdToken) compare against the stripped value. So such a provider fails with identity_provider_misconfigured even when the operator configured the issuer exactly. Keep the configured issuer verbatim for the comparisons, and strip the slash only where you build ${issuer}/.well-known/openid-configuration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in b8297857: the configured issuer is kept verbatim — no slash-trimming — so exact-match providers with trailing-slash issuers (Auth0 tenants) work. A test configures such an issuer and passes discovery and authorize-URL construction.

Comment thread packages/control-plane/src/oidc.ts Outdated
}
const idToken = body.id_token;
if (typeof idToken !== 'string' || idToken.length === 0) {
throw this.misconfigured('the token endpoint replied with no id_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.

suggestion: after the state is confirmed live, these paths throw without settling it: no id_token here, a non-JSON or non-2xx token reply via parseJson at L254, a rejected fetch (network error), and a discovery failure. The browser gets an error, but mocactl keeps polling authorization_pending for the rest of the 15-minute window. The comment at L268-270 says the design avoids exactly that. Wrap the post-validation part of handleCallback so any failure also settles a denial (generic text for the poll, details in the log), then rethrow for the browser response. A test with the token endpoint returning a non-JSON 502 would pin this down.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 7383fb4c: discovery, exchange and parse failures now settle a denial ("the sign-in could not complete: ") instead of leaving the poll hanging; the reason carries URLs and provider codes, never the client secret. A test scripts a rejecting token endpoint and asserts the poll hears unauthorized immediately.

Comment thread docs/reference/configuration.md Outdated
| `SH_CREDENTIAL_DIR` | none | Required for `file` | File store path |
| `SH_CREDENTIAL_NAMESPACE` | `sh-credentials` | Kubernetes store; the K8s manifests use `moca-credentials` | Secret namespace |
| `VAULT_ADDR`, `VAULT_TOKEN` or `VAULT_TOKEN_FILE` (exactly one), `VAULT_NAMESPACE`, `SH_VAULT_KV_MOUNT` (`secret`), `SH_VAULT_PATH` (`moca/credentials`) | none | Vault store only; no template wires it. Token is a **secret** | Vault credential store |
| `SH_ADMIN_SUBJECTS` | none | Comma-separated `github:<id>` | Admin role |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: SH_ADMIN_SUBJECTS still documents only github:<id>. With this PR it also takes oidc:<sub> entries, as the new guide says.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d9eac98e: the row now says comma-separated github:<id> or oidc:<sub>.

George Almasi added 5 commits November 10, 2026 10:59
… login seam

Add an oidc IdentityProvider (discovery + JWKS, RS256 id_token verification)
that runs the browser authorization-code flow with the control plane itself
as the redirect target, so mocactl's polling login is unchanged: the state
token it polls with plays the device code, and the authorize URL plays the
verification URI. The code exchange and the client secret stay server-side.

- new GET /v1/auth/oidc/callback (auth: none, plain text, browser-facing);
  an unverified id_token settles a denial so the poll hears it instead of
  hanging in authorization_pending for the rest of the window
- SH_IDENTITY_PROVIDER selects github (default, unchanged) or oidc;
  SH_OIDC_{ISSUER,CLIENT_ID,REDIRECT_URI} configure it and the client
  secret arrives as a runtime credential (CONTROL_PLANE_SECRETS), never
  committed
- subjects mint as oidc:<sub>; SH_ALLOWED_SUBJECTS validates both forms
  via one SUBJECT_RE
- mocactl: userCode is optional (no typed code in the oidc flow); the
  prompt, TUI overlay, and expiry messages are provider-neutral
- docs: env-var rows, openapi.yaml callback path, and a w3id deployment
  guide (registration, Route, single-replica caveat)

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
moca-settings gains five sticky keys (SH_IDENTITY_PROVIDER, SH_OIDC_ISSUER,
SH_OIDC_CLIENT_ID, SH_OIDC_REDIRECT_URI, SH_OIDC_SCOPE); the control plane
Deployment reads them plus SH_OIDC_CLIENT_SECRET from a moca-oidc Secret the
operator creates (optional secretKeyRef, so a GitHub stack renders exactly
as before). The replica decision counts either provider: a stack switched
from github to oidc keeps its control plane as SH_GITHUB_CLIENT_ID empties.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…loyment

configFromEnv validated the github client id unconditionally, before
identityProviderFromEnv ever ran, so an oidc control plane CrashLooped at
boot with 'SH_GITHUB_CLIENT_ID is required' -- found deploying to epoc001,
where the MU1 secrets let the boot reach that line (the offline repro had
stopped one check earlier, at the private key). Required only when the
provider is github; the oidc provider enforces its own SH_OIDC_* inputs.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
w3id's sub claim is the user's intranet email address, which the sub
charset (written for UUID-style subs) refused at login with 'the id_token
has no usable sub claim' -- found logging in against the epoc001
deployment. Allow @ and + alongside the alphanumerics; still no whitespace,
control characters, or colon (the provider/subject separator). SUBJECT_RE
(enrollment validation) follows, so oidc:<email> subjects enroll.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…t guard

The rebase onto main (which landed test-user logins, ADR-0045) merged three
subject forms into one grammar: SUBJECT_RE now admits github:<id>,
test:<index> and oidc:<sub> (email charset), and the sandbox-profile boot
guard's message says github:/oidc: subjects rather than only github: ones.
Also folds the oidc client secret into the projected credentials volume as
a FILE under CREDENTIALS_DIRECTORY (MI1 §6.7), the moca-test-users pattern,
instead of the env var the first cut used -- it is already in
CONTROL_PLANE_SECRETS, so withCredentials reads it with no code change.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
@galmasi
galmasi force-pushed the feat/oidc-identity-provider branch from 115bc04 to 5dc5cde Compare November 10, 2026 16:14

@clawgenti clawgenti 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.

Clawgenti Code Review

Summary

A well-structured OIDC provider behind the existing IdentityProvider seam. The discovery issuer cross-check, server-side code exchange, RS256/JWKS verification with real per-run keys in tests, and the file-not-env client secret all look solid. One must-fix stands: the browser↔terminal binding the PR body already lists as pending. Without it, an unauthenticated caller can mint an authorize URL, get a victim with a live SSO session to open it, and collect the victim's API token from the poll. I also flag two suggestions (an unbounded pending-login store behind an unauthenticated route, and issuer normalisation that breaks providers whose issuer ends in /) and one nit.

Author: galmasi (NONE — first-time)
Areas reviewed: TypeScript (control-plane, mocactl), K8s manifests, Shell (deploy/k8s/setup.sh), YAML/OpenAPI, Docs, Tests, Security
Agent/IDE config (.claude/.vscode): none
Commits: 5 commits, all signed-off: yes
CI status: passing (DCO is the only check reported)

Verdict: COMMENT. One must-fix (see inline). Every file was read in full, as the first-time-contributor tier requires.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

deviceCode: state,
// No user code: the browser session at the provider IS the thing the person completes, and
// the state rides in the URL rather than being read and typed.
verificationUri: authorize.toString(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (security): the authorize URL is a bearer capability, and the person who started the login doesn't have to be the person who finishes it. POST /v1/auth/device is unauthenticated, so an attacker can mint a state, send the verificationUri to a victim, and poll deviceCode themselves. With w3id, a live SSO session often means no consent screen, so one click by the victim settles the attacker's state with the victim's principal. The attacker then receives an API token plus refresh family as oidc:<victim>. The PR body lists this as a planned follow-up; it should land before OIDC is enabled anywhere. Two options: a short confirmation code that only the originating terminal shows, typed or compared on the callback page; or binding the state to a secret the polling client holds (e.g. return a separate poll secret from /v1/auth/device and keep it out of the URL).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in ed1db012 and completed in ca44063c: the confirmation round mints a terminal user code AND a browser-bound token in the round-1 response; round 2 requires both. The round-2 thread correctly caught that the code alone was bypassable — the token is the fix.

Comment thread packages/control-plane/src/oidc.ts Outdated
// 32 random bytes, base64url: the state is the capability the client polls with, so it is
// unguessable for the same reason a device code or refresh token is.
const state = randomBytes(32).toString('base64url');
await this.store.put({ state, expiresAtMs: this.now() + this.stateTtlS * 1000 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: every unauthenticated POST /v1/auth/device adds a 15-minute entry to MemoryPendingAuthStore, and nothing caps the count. A loop against the public route can grow the control plane's heap without limit, and sweep() walks the whole map on every put/get, so each request costs O(n). Consider a hard cap on pending entries (refuse with 429/503 once it's reached) and/or rate-limiting this route on the oidc provider.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 7383fb4c — same as the duplicate thread: 10k entry cap with quota_exceeded (429) on login starts, and the sweep only runs when a put would be refused.

Comment thread packages/control-plane/src/oidc.ts Outdated
for (const k of ['issuer', 'clientId', 'clientSecret', 'redirectUri'] as const) {
if (!opts[k]) throw new Error(`the oidc identity provider requires ${k}`);
}
this.issuer = opts.issuer.replace(/\/+$/, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: trailing slashes are stripped from the configured issuer, but discover() (body.issuer !== this.issuer) and verifyIdToken (claims.iss !== this.issuer) then compare exactly. Some providers' issuers legitimately end in / (Auth0, for example, uses https://<tenant>.auth0.com/), and OIDC requires an exact match. For those providers every discovery fails as misconfigured. Keep the configured value verbatim for the comparisons, and trim only when building the /.well-known/openid-configuration URL.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in b8297857 — the issuer is kept verbatim, no trimming; see the duplicate thread for the test.

</Box>
) : null}
<Spinner
label={`waiting for approval · code expires in ${formatDuration(secondsLeft * 1000)}`}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: with no user code (oidc), the spinner still reads waiting for approval · code expires in …. The rest of this PR moved to provider-neutral wording ("sign-in window"), so this label could follow.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in f04c71f2 — spinner and hints are provider-neutral and conditional on a user code.

Comment thread packages/control-plane/src/oidc.ts Fixed
jimcadden pushed a commit to rossoctl/automation that referenced this pull request Nov 10, 2026
begin --live handed the parsed diff_map to jq as --argjson diff_map, then
handed the whole enriched entry (which still contains the map) to jq again
as --argjson entry. Linux caps a single argv string at MAX_ARG_STRLEN
(128 KiB) independently of ARG_MAX, so any PR whose parsed diff_map crossed
that died with E2BIG: jq: Argument list too long. The crash landed after the
PR was marked in_progress in temp state but before pr_review_state_write, so
nothing persisted and the scanner re-queued the PR on every run.

Seen on rossoctl/repoman#12 (2026-10-29, diff_map 2659 lines) and
rossoctl/moca#701 (2026-11-10, diff_map 178 KB).

Write the parser output and the enriched entry to files and read them with
--slurpfile, so no PR-controlled data touches the command line.

Adds tests/test-pr-review-fixer-begin-large-diff.sh: a fixture diff whose
diff_map is ~570 KB, gh stubbed, asserting begin --live exits 0, the queued
diff_map matches the parser byte for byte, state.json persists the
in_progress entry, and no --argjson handoff of diff_map/entry returns. It
fails with the production E2BIG on the previous script and passes here.
Wired into both explicit lists in .github/workflows/tests.yml.

Fixes #138.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Clawgenti <[email protected]>
…d the login

Review item 3 (PR #701): the authorize URL was itself a capability. An
attacker who starts a login and gets a victim with a live SSO session to
open the authorize URL handed the attacker a fully verified login AS the
victim -- one click, no code to type, every signature genuine.

The fix is the device flow's binding, re-expressed: startDeviceAuth mints
a short user code (XXXX-XXXX, no confusables) shown only in the terminal
and never placed in the URL; the callback now runs in two rounds -- the
provider's redirect (?code=) exchanges and verifies the id_token but parks
the principal UNCONFIRMED and renders an HTML form, and the form's
submission (?confirm=) settles the login only on a constant-time match,
at most five tries before the login is refused outright. The poll keeps
answering authorization_pending until the confirmation lands, which is
the walk-in attack failing exactly there.

mocactl needs no change: it already prints and copies a user code when
one is present. The handler result grows an optional contentType so the
one browser-facing route can answer text/html; everything a query string
can carry is HTML-escaped, and no external resources or scripts ride the
page.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
Comment thread packages/control-plane/src/oidc.ts Fixed

@clawgenti clawgenti 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 adds a generic OIDC (w3id) identity provider behind the login seam. The provider is well built: discovery checks the issuer, the code exchange happens on the server, and the RS256/JWKS checks, deploy plumbing and docs are all solid. One must-fix: the new browser-to-terminal binding (ed1db012) can still be bypassed. The ?confirm= round needs only state + the user code, and the attacker who started the login holds both. CI also has two failures to resolve (below).

Author: galmasi (NONE — first-time)
Areas reviewed: TypeScript (control-plane, mocactl), Shell (deploy/k8s/setup.sh), K8s YAML, OpenAPI, Docs, Security
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: failing. deploy-scripts fails in "Run deploy shell tests" (exit 2). The same job passes on recent main runs, so this PR likely broke it; the setup.sh / moca-settings changes are the likely cause. CodeQL reports 2 new high alerts in oidc.ts (see the inline notes: one is a false positive, one is low risk). deploy-scripts-bash32 is still pending.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread packages/control-plane/src/oidc.ts Outdated
if (entry.confirmed) return 'confirmed';
// Constant time (secretMatches hashes both sides to a fixed width first): the reply's latency
// must not become a per-character oracle on the code.
if (!secretMatches(code.trim().toUpperCase(), entry.confirmCode)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (security): the browser-to-terminal binding can be bypassed. confirmSignIn checks only state + confirm, and the attacker holds both. The state is the deviceCode in their terminal, and the user code is shown in that same terminal. The walk-in attack still works:

  1. The attacker runs mocactl login and gets the authorize URL (with state) and XXXX-XXXX.
  2. The victim, who has a live SSO session, opens the URL. The callback verifies the victim's id_token and parks it as awaiting_confirmation.
  3. The attacker GETs /v1/auth/oidc/callback?state=<state>&confirm=<code> from their own machine, gets confirmed, and their poll then receives the victim's login.

Nothing ties round 2 to the browser that completed round 1. The defeats the walk-in attack test stops at step 2, so it does not cover this. Suggested fix: in round 1, mint a fresh random value that is never derivable from state and store it on the entry. Deliver it only in the round-1 response (an HttpOnly; Secure; SameSite=Strict cookie scoped to the callback path, and/or a hidden form field). Require it in round 2. Add a test where round 2 arrives with the right state + code but without that value, and assert it is refused.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in ca44063c: round 1 mints confirmToken = randomBytes(32), stores it on the entry, and returns it only in that response; the form carries it as a hidden field and round 2 requires it (constant-time), with a missing or wrong token burning a try. The hidden field is sufficient against this attacker precisely as you note — they never see the victim's response.

Comment thread packages/control-plane/src/oidc.ts Outdated
let code = '';
for (let i = 0; i < 8; i++) {
if (i === 4) code += '-';
code += CONFIRM_ALPHABET[bytes[i]! % CONFIRM_ALPHABET.length];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: CodeQL flags this as a biased modulo (high). Here 256 % 32 === 0, so the result is unbiased and the alert is a false positive. Still, add a comment or a // codeql[js/biased-cryptographic-random] justification so the check goes green and nobody later changes the alphabet length without noticing (31 or 33 chars would be biased).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Answered in b8297857: comment added documenting 256 % 32 === 0 and the change-guard.

Comment thread packages/control-plane/src/oidc.ts Outdated
for (const k of ['issuer', 'clientId', 'clientSecret', 'redirectUri'] as const) {
if (!opts[k]) throw new Error(`the oidc identity provider requires ${k}`);
}
this.issuer = opts.issuer.replace(/\/+$/, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: CodeQL flags /\/+$/ as a polynomial ReDoS (high). The issuer comes from operator env, so the real risk is low. A non-regex trim (while (s.endsWith('/')) s = s.slice(0, -1)) clears the alert at no cost.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Cleared in b8297857: the regex is gone — the issuer is no longer trimmed at all.

* brute force against MAX_WRONG_CODES tries inside one state's TTL.
*/
const CONFIRM_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
const CONFIRM_CODE_RE = /^[A-Z0-9]{4}-[A-Z0-9]{4}$/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: CONFIRM_CODE_RE is declared but never used. Either use it to reject malformed confirm input before calling secretMatches (cheap, and it gives a clearer error), or delete it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 7383fb4c: CONFIRM_CODE_RE now rejects malformed confirms before secretMatches, without burning one of the five tries (the shape is public; only guesses at the secret are scarce).

Comment thread docs/guides/oidc-login-w3id.md Outdated

## Logging in

`mocactl login` is the same command. With the oidc provider there is no code to type — the

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: This contradicts the flow described above and the example below. Since ed1db012 there is a code to type, and startDeviceAuth always returns userCode. Please update this sentence. The same staleness appears in openapi.yaml ("with NO userCode" / "absent when … (oidc)"), in the DeviceStart.userCode doc comment in identity.ts, and in the PR body's note that an older mocactl renders undefined.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d9eac98e: the guide, the openapi startDeviceAuth/userCode descriptions and DeviceStart.userCode's comment all describe the confirmation-code flow; the personal name in the transcript was scrubbed too.

Comment thread docs/api/openapi.yaml Outdated
userCode:
{
type: string,
description: absent when the provider needs no typed code (oidc),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Stale after the binding commit: the oidc provider now always returns userCode, and the user must type it on the callback page. Update this description (and the startDeviceAuth description above it) so client authors don't treat the field as optional for oidc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d9eac98e — the openapi descriptions now say the code is confirmed on the callback page, for both the start route and the field.

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

Thanks for landing the binding in this PR, and for the lint fix (SUBJECT_RE is on one line now, and lint is green). The confirmation page is a good shape, but as wired it does not yet bind the browser to the terminal.

must-fix

  1. The walk-in attack still works: the confirmation round is not bound to the browser that landed the redirect (oidc.ts:352, see inline). ?confirm= takes only state and the user code, and the attacker who started the login holds both: deviceCode is the state, and userCode is printed in their terminal. Flow: the attacker calls POST /v1/auth/device and sends the victim the authorize URL. The victim's live SSO session redirects to the callback, which parks the victim's principal (confirmed: false). The attacker then sends GET /v1/auth/oidc/callback?state=<deviceCode>&confirm=<userCode> from their own machine, gets confirmed, and the next poll returns a login as the victim. That is still one click from the victim and no code typed by them. The new test defeats the walk-in attack stops right before this step. The confirmation has to require something only the redirected browser holds. For example, have the ?code= round mint a random per-redirect token, keep it on the entry, and send it only in that HTML response (a hidden field, or an HttpOnly; Secure; SameSite=Lax cookie scoped to the callback path). Then ?confirm= succeeds only with token + user code. Please add a test where the attacker confirms with just state + userCode after a victim redirect and gets refused.
  2. CI from 5dc5cde, still open in code (the checks are pending on this head, but neither file changed): deploy-scripts: setup.sh still writes the five SH_IDENTITY_PROVIDER/SH_OIDC_* keys on every stack, while deploy/k8s/tests/setup.test.sh:446 (exact ten-key list) and :1301 (length == 10) still assert ten, and the "same ten keys" comments at setup.sh:1078 / setup.test.sh:443-445 are stale. CodeQL (high, polynomial regex): opts.issuer.replace(/\/+$/, '') at oidc.ts:192 is unchanged. Keep the issuer verbatim for the exact iss comparisons and build the discovery URL without a regex (the other review's trailing-slash point covers the same line).

Still open from 14b3cd9 / 5dc5cde (not reposted inline): settle-once (a later ?error= callback can still overwrite a parked or confirmed entry through Object.assign, oidc.ts:104); the pending-entry cap on unauthenticated POST /v1/auth/device; Login.tsx wording when there's no code (this is now moot for oidc, since a userCode is always present, but it is still true for any future code-less provider); and nbf.


Author: galmasi (MEMBER, maintainer)
Areas reviewed: TypeScript (control-plane oidc/handlers/server/identity, tests), Docs (openapi, w3id guide). Incremental from 5dc5cde (one new commit, ed1db01, fast-forward).
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed off: yes
CI status: pending (check, k8s-kind-e2e, codeql, deploy-scripts, deploy-scripts-bash32, proto); lint, DCO, docs, shellcheck, trivy, and dependency-review pass. On 5dc5cde, lint, deploy-scripts, and CodeQL were red.

Comment thread packages/control-plane/src/oidc.ts Outdated
* burns one of MAX_WRONG_CODES tries; exhausting them settles a denial, so the polling client
* hears the refusal instead of waiting out the window.
*/
private async confirmSignIn(state: string, code: string): Promise<OidcCallbackOutcome> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (security): nothing here proves the confirmation comes from the browser that completed the provider redirect. The inputs are state (= the attacker's deviceCode) and code (= the attacker's userCode), so the login's initiator can confirm a victim's parked principal directly: GET /v1/auth/oidc/callback?state=<deviceCode>&confirm=<userCode>. In the device flow, the code goes terminal → the human at the provider, and the provider binds it to that browser's session. Here the code check runs on our side with no browser credential, so it binds nothing. Suggested fix: in the ?code= round, mint confirmToken = randomBytes(32), store it on the entry, and emit it only in that response (a hidden form field, or an HttpOnly; Secure; SameSite=Lax cookie on /v1/auth/oidc/callback). Require it (constant-time) alongside the user code here, and count a missing or wrong token as a wrong try. Note that a hidden field alone is enough against this attacker, because they never see the victim's response.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in ca44063c, exactly along your lines: the ?code= round mints confirmToken = randomBytes(32), stores it on the entry, emits it only in that response (hidden form field), and confirmSignIn requires it constant-time alongside the user code, with a missing or wrong token counted as a wrong try.

});

describe('the browser-to-terminal binding (review item 3)', () => {
it('defeats the walk-in attack: a victim-completed callback mints no login without the code', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (test): this stops one step short of the attack. The attacker owns start.userCode too. Add await r.provider.handleCallback({ state: start.deviceCode, confirm: start.userCode }) without the browser-bound token, and assert it does not return confirmed and that completeDeviceAuth stays authorization_pending. That assertion fails today.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in ca44063c: the walk-in test now runs the attack to the end — the attacker confirms with state + user code (no token) and gets wrong_code with the poll still authorization_pending; the victim's browser, carrying its token, completes the login. That assertion fails on the pre-fix code, as predicted.

Comment thread packages/control-plane/src/handlers.ts Outdated
`${wrong ? '<p style="color:#b00">That code is not right — try again.</p>' : ''}` +
'<p>Enter the code shown in your terminal to finish signing in.</p>' +
`<form method="GET" action="/v1/auth/oidc/callback">` +
`<input type="hidden" name="state" value="${escapeHtml(state ?? '')}">` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: (1) The page is served with no Cache-Control: no-store, X-Frame-Options: DENY / Content-Security-Policy: frame-ancestors 'none'; default-src 'none'; style-src 'unsafe-inline', or Referrer-Policy: no-referrer. A framed confirmation form is a clickjacking surface, and once a browser token lives in this page it should not be cached. A headers field on the handler result (next to contentType) would carry these. (2) method="GET" puts the confirm code (and the future token) in the access logs and browser history. POST is cleaner, though the route then needs a form-body parse.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 6bdb13a0: every page the callback serves carries Cache-Control: no-store, X-Frame-Options: DENY, Content-Security-Policy: frame-ancestors 'none'; default-src 'none'; style-src 'unsafe-inline' and Referrer-Policy: no-referrer (via a headers field on handler results, next to contentType), and the form now POSTs urlencoded — the router parses the one form body a browser submits — so the code and token stay out of URLs, logs and history.

Comment thread packages/control-plane/src/oidc.ts Outdated
let code = '';
for (let i = 0; i < 8; i++) {
if (i === 4) code += '-';
code += CONFIRM_ALPHABET[bytes[i]! % CONFIRM_ALPHABET.length];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: the CodeQL "biased random" alert is a false positive: 256 % 32 == 0, so byte % 32 is uniform. Dismiss it with that reason, or add a one-line comment here so the next reader doesn't re-raise it. Separately, CONFIRM_CODE_RE (L145) is declared but never used. Either use it to reject malformed confirm values before they cost a try, or drop it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Both answered: the modulo justification comment landed in b8297857 (256 % 32 === 0, with the change-guard), and CONFIRM_CODE_RE is used in 7383fb4c to reject malformed confirms without burning a try.

Comment thread packages/control-plane/src/handlers.ts Outdated
},

// The OIDC callback is the one route answered by a BROWSER, not by mocactl, so it answers HTML
// (sanitizeCallbackText escapes everything a provider or a forger can put in a query). Two

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: sanitizeCallbackText doesn't exist. The helper is escapeHtml.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 6bdb13a0: the comment was rewritten around the handler refactor and now names escapeHtml.

@mrsabath

Copy link
Copy Markdown
Member

Tested the w3id login end to end against the epoc001 stack (thanks for the server, @galmasi) — the flow works: authorize → w3id SSO → callback → code confirmation → API token. Two doc nits in docs/guides/oidc-login-w3id.md, no code changes.

1. Line 84 contradicts the binding it documents

With the oidc provider there is no code to type — the prompt shows only the URL

This reads as pre-ed1db012. It contradicts its own example six lines down (line 90 does show and enter the code XY7C-K2M9) and the "browser-to-terminal binding" paragraph above it (line 40). Since the typed code is the walk-in-attack mitigation, a reader who trusts line 84 will file the code prompt as a bug.

Suggested: "With the oidc provider the prompt shows the URL and a short code; sign in at the provider, then type the code on the confirmation page."

2. The example authorize URL uses the issuer's path

Line 90 shows:

Open https://preprod.login.w3.ibm.com/oidc/endpoint/default/authorize?...

The real URL is under /v1.0/. w3id serves authorization_endpoint from a different path than its issuer — from both discovery documents:

issuer:                 https://preprod.login.w3.ibm.com/oidc/endpoint/default
authorization_endpoint: https://preprod.login.w3.ibm.com/v1.0/endpoint/default/authorize

and the live start confirms it:

"verificationUri": "https://preprod.login.w3.ibm.com/v1.0/endpoint/default/authorize?client_id=...&state=..."

SH_OIDC_ISSUER at line 65 is correct and shouldn't change — only the sample output, so nobody reads the mismatch as a misconfigured deployment.

One question, not a blocker

w3id's discovery advertises "none" in id_token_signing_alg_values_supported (alongside RS*, PS*, ES*, HS*). The PR says RS256 only and there are 16 offline id_token tests, so this is probably already covered — but is there an explicit test asserting an alg: none (or HS256-signed) id_token is rejected? Given the provider openly offers none, that feels like a cheap test to pin the classic bypass.

Not an issue — noting it so it doesn't get re-reported

I hit github.com/login/device instead of w3id on my first attempts. That was pnpm start -- login --control-plane-url ...: the -- makes node:util parseArgs (allowPositionals: true) push the flags into positionals, so --control-plane-url is never parsed and buildRuntime falls through to a stale SH_CONTROL_PLANE_URL pointing at a GitHub-mode stack. Reproduced in isolation; standard parseArgs behavior, nothing to do with this PR.

Assisted-By: Claude Code

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mocactl sbx login on an OIDC deployment

The code already covers both logins:

  • The sandbox profile picks the provider in the same place as the harness profile (main.ts, identityProviderFromEnv).
  • GET /v1/auth/oidc/callback is mounted on BOTH profiles.
  • SH_ALLOWED_SUBJECTS accepts oidc:<sub>.
  • mocactl sbx login goes through the same deviceLogin / devicePrompt as mocactl login.

The deployment side only covers deploy/k8s, though. As it stands, an SBX0 deployment can't be switched to OIDC. Recommended changes so mocactl sbx login works too:

  1. deploy/sbx/setup.sh: accept the OIDC settings.

    • SBX_GITHUB_CLIENT_ID is still unconditionally required (around line 110).
    • ensure_settings writes moca-settings with only SH_GITHUB_CLIENT_ID, SH_ADMIN_SUBJECTS and the two TTLs. So SH_IDENTITY_PROVIDER / SH_OIDC_ISSUER / SH_OIDC_CLIENT_ID / SH_OIDC_REDIRECT_URI / SH_OIDC_SCOPE are never set, and a re-run would overwrite any added by hand.
    • Suggest SBX_IDENTITY_PROVIDER (default github) plus SBX_OIDC_* inputs that are validated the same way the deploy/k8s/setup.sh changes do it. SBX_GITHUB_CLIENT_ID would then be required only when the provider is github (the cedcf18f fix, mirrored in the script).
  2. deploy/k8s/overlays/ocp-sbx/patch-control-plane.yaml: mount the client secret.

    • The overlay sets projected: null and replaces the credentials volume with a plain secret: moca-mu1 holding only SH_SESSION_TOKEN_PRIVATE_KEY and SH_JANITOR_TOKEN. That drops the optional moca-oidc source the base now adds, so an OIDC sandbox control plane would crash-loop at boot asking for SH_OIDC_CLIENT_SECRET.
    • Suggest keeping the volume projected, with moca-mu1 (those two items) plus an optional: true moca-oidc source (SH_OIDC_CLIENT_SECRET). That still leaves out the KEK and exchange token that SBX0 §4.1 removes on purpose.
    • deploy/sbx/tests/overlay.test.sh would need a case for it.
  3. Enrollment of oidc: subjects. /sbx:enroll and the SBX_ALLOWED_SUBJECTS / SBX_ADMIN_SUBJECTS handling assume GitHub accounts resolved to github:<id>. Taking oidc:<sub> entries as they are (validated against SUBJECT_RE, e.g. oidc:[email protected]) would let a w3id cohort be enrolled without editing by hand.

  4. Docs. docs/guides/oidc-login-w3id.md covers only the deploy/k8s path. A short SBX0 section in the guide (or in deploy/sbx/README.md / RUNBOOK.md) would help: the env inputs, the moca-oidc secret, the redirect URI on the sandbox control plane's own Route, and the single-replica caveat for pending logins.

  5. Tests / live check. No test runs the sandbox profile with SH_IDENTITY_PROVIDER=oidc from start to finish. Only route-profile.test.ts lists the new route. A main.test.ts case that boots the sandbox profile with OIDC and an oidc: allowlist, plus an sbx login against a sandbox-profile OIDC deployment, would cover what the epoc001 w3id run covered for the harness profile.

All of this could also be a follow-up PR if you'd rather keep #701 scoped to mocactl login. If so, it would be worth saying in the PR body / guide that SBX0 stays GitHub-only for now.

Nit: the comment on the now-optional userCode in packages/mocactl/src/api/types.ts ("the oidc flow: the browser is the approval") is out of date since ed1db012, which mints a typed code for the OIDC login too.

Assisted-By: Claude Code

…ed the redirect

Review round 2 (PR #701): the user code alone binds nothing against a
malicious initiator, because the initiator's terminal is where the code is
shown. An attacker who starts a login and walks a victim's live SSO session
through the provider redirect could confirm the victim's parked principal
with a bare GET ?state=<deviceCode>&confirm=<userCode> -- both inputs were
in the attacker's terminal all along.

Round 1 (the provider redirect) now mints a fresh 32-byte token, stores it
on the entry, and returns it ONLY in that response; the callback form
carries it as a hidden field, and round 2 requires it alongside the user
code, constant-time, with a missing or wrong token burning a try exactly
like a wrong code. The attacker never sees the victim's round-1 response,
so state + user code + this token together prove the confirmation came
from the browser that completed the redirect.

The walk-in test now runs the attack to the end: the attacker confirms
with everything their terminal showed and gets wrong_code; the victim's
browser, carrying its token, completes the login.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>

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

Thanks: ca44063 closes the walk-in attack the way we asked. Round 1 mints a 32-byte token, delivers it only in the response the browser receives, and round 2 compares token and code in constant time, with a missing token costing a try. The walk-in test now runs the attack to the end (attacker gets wrong_code, then the victim confirms), and I couldn't find another way around the binding. Must-fixes 1 and 2 from ed1db01 are closed.

must-fix

  1. A single typo now breaks the login (handlers.ts:664, see inline). The wrong_code branch re-renders the form with ct = confirmToken ?? ''. Only round 1 returns confirmToken, so after one mistyped code the hidden field is empty. Every resubmit from that page then fails tokenOk and costs a try. Four more submits get the login refused, even when the user types the right code. The unit tests pass token: landed.confirmToken by hand on every try, so they never see what the re-rendered page carries. Suggested fix: on wrong_code, re-render with the token this request carried (ctx.query.get('ct')). Echoing it back exposes nothing new, because the sender already had it. Alternatively, have confirmSignIn return confirmToken when the token matched but the code didn't. Please add a route-level test: land, submit a wrong code, take ct from the re-rendered body, submit the right code, and expect confirmed.
  2. deploy-scripts / deploy-scripts-bash32 are still red (carried from 5dc5cde; this commit doesn't touch either file). setup.sh writes the five SH_IDENTITY_PROVIDER/SH_OIDC_* keys, but deploy/k8s/tests/setup.test.sh:447 and :1302 still assert exactly ten keys. The "ten keys" comments are stale too.

suggestion

  • CodeQL is still red with 2 high alerts. opts.issuer.replace(/\/+$/, '') at oidc.ts:202 is still there. Keep the issuer verbatim for the iss checks and trim slashes without a regex. The modulo alert at :164 is a false positive (256 % 32 == 0). Dismiss it with that reason.
  • check failed at its "Install ripgrep" step (apt exit 100) before any code ran. That looks like a runner problem, so please re-run it. It passed on ed1db01.

Still open from earlier rounds (not reposted inline): settle-once (a later ?error= can still Object.assign over a parked or confirmed entry, oidc.ts:114), the pending-entry cap on unauthenticated POST /v1/auth/device, nbf, the callback page's security headers (no-store, frame-ancestors 'none', no-referrer) and GET→POST (the page now carries a token, so both matter more), the unused CONFIRM_CODE_RE (oidc.ts:155), and the sanitizeCallbackText → escapeHtml comment (handlers.ts:625). Also worth picking up: mrsabath's two doc nits in docs/guides/oidc-login-w3id.md (line 84 says there's no code to type; the example authorize URL uses the wrong path) and pdettori's SBX0 deploy gaps (deploy/sbx/setup.sh, the ocp-sbx credentials patch), or track them in a follow-up.

Comment thread packages/control-plane/src/handlers.ts Outdated
`<input type="hidden" name="state" value="${escapeHtml(state ?? '')}">` +
// The browser-bound half of the binding (oidc.ts): minted in the round-1 response this
// browser received, invisible to whoever started the login, required in round 2.
`<input type="hidden" name="ct" value="${escapeHtml(confirmToken ?? '')}">` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (functional): on wrong_code this field is empty, because confirmToken is only returned by round 1 (confirmSignIn returns { outcome: 'wrong_code' } with no token, oidc.ts:399). After one typo, every submit from the re-rendered page fails tokenOk and costs a try, and the fifth refuses the login even when the code is right. Suggested: value="${escapeHtml(confirmToken ?? ctx.query.get('ct') ?? '')}". Echoing the request's own token gives its sender nothing new. Add a route-level test that lands, submits a wrong code, pulls ct out of the re-rendered body, then submits the right code and expects confirmed. The current wrong-code test passes landed.confirmToken directly, so it misses this.

@clawgenti clawgenti 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.

Clawgenti Code Review

Summary

A carefully built OIDC provider behind the existing identity seam. The id_token checks (iss/aud/exp/sub, RS256 against the JWKS, kid refetch) and the two-round browser↔terminal binding look sound, and the walk-in attack has a dedicated test. Two things block merge: CI is red, and CodeQL reports 2 new high alerts. Separately, several docs and comments still describe the earlier flow with no user code.

Author: galmasi (NONE — first-time)
Areas reviewed: TypeScript (control-plane, mocactl), K8s manifests, Shell (deploy/k8s/setup.sh), OpenAPI/docs, tests
Agent/IDE config (.claude/.vscode): none
Commits: 7 commits, all signed-off: yes
CI status: failing — deploy-scripts and deploy-scripts-bash32 (make test-deploy), check (fails at "Install ripgrep", apt exit 100, which looks like a runner flake), and CodeQL (2 high). All of these pass on main at c241116.

Findings

# Severity Where Finding
1 must-fix deploy/k8s/setup.sh make test-deploy fails on both bash jobs, but is green on main
2 must-fix oidc.ts:164, oidc.ts:202 CodeQL gate: 2 new high alerts (one is a false positive, one is trivial to fix)
3 suggestion handlers.ts:660 The confirmation form uses GET, so ct/state/confirm land in URLs, history and access logs
4 suggestion oidc.ts:307 A second ?code= round on a state that already holds a principal overwrites it
5 suggestion openapi.yaml, identity.ts, headless.ts Docs and comments say oidc returns no userCode, but the final flow returns one
6 nit sandbox-config.ts:129 SUBJECT_RE now also admits test:N in SH_ALLOWED_SUBJECTS
7 nit handlers.ts:625 The comment references a sanitizeCallbackText that does not exist

I could not download the failing job logs (log storage timed out from the reviewer's sandbox), so finding 1 is based on the failing step names and the main-vs-PR comparison only.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread deploy/k8s/setup.sh
SH_API_TOKEN_TTL_SECONDS: $api_ttl, SH_SESSION_TOKEN_TTL_SECONDS: $session_ttl,
SH_MODEL_CATALOG_HOSTS: $catalog_hosts, SH_TEST_USERS: $test_users}')"
SH_MODEL_CATALOG_HOSTS: $catalog_hosts, SH_TEST_USERS: $test_users,
SH_IDENTITY_PROVIDER: $idp, SH_OIDC_ISSUER: $oidc_issuer, SH_OIDC_CLIENT_ID: $oidc_client_id,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix — CI's deploy-scripts and deploy-scripts-bash32 jobs (make test-deploy, which runs deploy/k8s/tests/setup.test.sh among others) fail on this head and pass on main c241116. The only deploy script this PR touches is setup.sh, so the most likely cause is this change to the moca-settings payload: the five new keys are now always written, even empty on a GitHub stack. A test that pins the exact ConfigMap data, or the replica/rollout logs at write_overlay/wait_ready, would break. The PR body says the setup harness is green, so it may have been run against a pre-rebase base. Please re-run make test-deploy on the rebased branch.

Comment thread packages/control-plane/src/oidc.ts Outdated
let code = '';
for (let i = 0; i < 8; i++) {
if (i === 4) code += '-';
code += CONFIRM_ALPHABET[bytes[i]! % CONFIRM_ALPHABET.length];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (CodeQL gate) — CodeQL flags this as a biased modulo on a CSPRNG. It is a false positive here, since 256 % 32 == 0 and every symbol is equally likely. But the alert is high and fails the CodeQL check. Either dismiss it with that justification, or use bytes[i]! & 31 (or randomInt(32)) plus a one-line comment, so the next alphabet change cannot silently introduce bias.

Comment thread packages/control-plane/src/oidc.ts Outdated
for (const k of ['issuer', 'clientId', 'clientSecret', 'redirectUri'] as const) {
if (!opts[k]) throw new Error(`the oidc identity provider requires ${k}`);
}
this.issuer = opts.issuer.replace(/\/+$/, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (CodeQL gate) — CodeQL flags /\/+$/ as a polynomial regex on uncontrolled input. The issuer is operator config, so the real-world risk is low, but this is the second high alert failing the check. A loop that trims trailing slashes (while (s.endsWith('/')) s = s.slice(0, -1)) clears it at no cost.

Comment thread packages/control-plane/src/handlers.ts Outdated
'Confirm your sign-in',
`${wrong ? '<p style="color:#b00">That code is not right — try again.</p>' : ''}` +
'<p>Enter the code shown in your terminal to finish signing in.</p>' +
`<form method="GET" action="/v1/auth/oidc/callback">` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (security) — With method="GET", round 2 puts state, ct (the browser-bound token) and confirm (the user code) into the query string. They end up in browser history, in OpenShift Route/ingress access logs, and in any intermediate proxy log, and the confirmToken's guarantee that only the victim's browser ever sees it then rests on nobody reading those logs inside the 15-minute window. method="POST" with a form-encoded body (plus a POST route) keeps all three out of URLs. While you are on this page, also consider Cache-Control: no-store and Content-Security-Policy: frame-ancestors 'none' (or X-Frame-Options: DENY) on these HTML responses, and a line telling the user to enter a code only from a terminal they started themselves. That warning is the standard mitigation for the device-code phishing pattern that remains possible here.

}
// The state must be live BEFORE the exchange: an unknown state is not ours to redeem, and
// refusing it first keeps a stranger from making the control plane spend a code at all.
if (!(await this.store.get(q.state))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — This only checks that the state is live. A second ?code= round on a state that already holds a parked principal re-runs the exchange and overwrites principal and confirmToken. As far as I can see it does not enable a login as someone else, because the confirm round still needs the new token and the user code. It does let anyone who holds the state replace the parked identity or invalidate the first browser's token. Refusing round 1 when entry.principal is already set would make the state genuinely single-use for the redirect, as the class comment describes.

Comment thread docs/api/openapi.yaml Outdated
device flow ENABLED -- it is off by default (spec §5.1.1).

With the oidc identity provider (SH_IDENTITY_PROVIDER=oidc), the same reply carries the
provider's authorize URL in verificationUri and a state token in deviceCode, with NO

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — This describes the pre-ed1db01 flow: the oidc reply now does carry a userCode, the terminal confirmation code (oidc.ts startDeviceAuth). The same stale claim appears in identity.ts:26 (DeviceStart.userCode doc), packages/mocactl/src/api/types.ts and headless.ts:106. For API consumers, the spec should say that userCode is present for both providers today, and what it means under oidc.

Comment thread packages/control-plane/src/identity.ts Outdated
deviceCode: string;
userCode: string;
/**
* The code the user reads and types at the verification URI. Absent when the provider needs no

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — This comment is stale for the same reason: the oidc flow now returns a userCode (the confirmation code typed into the callback page). If no provider currently omits it, consider keeping userCode required in the server type and making it optional only on the mocactl side, for backward compatibility.

}
if (!allowedSubjects.every((s) => GITHUB_SUBJECT_RE.test(s))) {
throw new Error(`SH_ALLOWED_SUBJECTS: every entry must match ${GITHUB_SUBJECT_RE}`);
if (!allowedSubjects.every((s) => SUBJECT_RE.test(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.

nit — Switching from GITHUB_SUBJECT_RE to SUBJECT_RE also lets test:N entries into SH_ALLOWED_SUBJECTS. That is harmless today, because test users refuse to boot on the sandbox profile, but it contradicts the ADR-0045 comment in main.ts ("a synthetic test:N subject can never be enrolled there"). A sandbox-specific RE (github|oidc only) would keep the invariant explicit.

Comment thread packages/control-plane/src/handlers.ts Outdated
},

// The OIDC callback is the one route answered by a BROWSER, not by mocactl, so it answers HTML
// (sanitizeCallbackText escapes everything a provider or a forger can put in a query). Two

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — sanitizeCallbackText does not exist; the escaping helper is escapeHtml (above).

George Almasi added 4 commits November 11, 2026 11:08
…, flood, and hang

Four review items in the store's path (PR #701 round 2):

- settle is write-once per outcome: a principal is never replaced (a
  second code exchange cannot swap who a parked login belongs to), and a
  denial is terminal. Provider-side refusals (a replayed ?error=, a
  failed exchange) never flip a login that already succeeded past the
  provider -- only the confirm path's too-many-wrong-codes transition
  may deny a parked entry.
- the confirm token is re-issued by NOTHING: a second landing of the
  provider redirect returns awaiting_confirmation with no token, so a
  second completer cannot harvest one and confirm another's login.
- put() caps live entries (10k default) and login starts past the cap
  answer quota_exceeded (429): the route is unauthenticated, and the cap
  is the only bound on anonymous memory. The expiry sweep runs only
  when a put would be refused, so the common path stays O(1).
- discovery, exchange and parse failures (provider down, non-JSON reply,
  no id_token) settle a denial instead of leaving the poll in
  authorization_pending for the rest of the window; the reason carries
  URLs and provider codes, never the client secret.
- a shape-wrong confirmation no longer burns one of the five tries: the
  shape is public, so only guesses at the secret must be scarce.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…-yet-valid id_token

- the configured issuer is kept VERBATIM instead of slash-trimmed: OIDC
  Discovery §4.3 and Core §3.1.3.7 compare by exact match, and providers
  whose issuer legitimately ends in '/' (Auth0 tenants) failed discovery
  against the trimmed value. Removing the trim also clears CodeQL's
  polynomial-ReDoS alert on the /\\/+$/ pattern -- the pattern is gone.
- nbf is now checked (beyond the clock-skew allowance) per OIDC Core
  §3.1.3.7; not strictly required with a server-side exchange, but cheap.
- a comment on the confirm-code modulo documents why it is unbiased
  (256 % 32 === 0) and what to do if the alphabet length ever changes,
  answering CodeQL's biased-crypto-random alert.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
SUBJECT_RE (enrollment) restated SUB_RE (id_token verification) by hand,
so a charset change had to be made twice -- and commit 19de8de indeed
had to. Both now build from one exported OIDC_SUB_PATTERN in identity.ts,
and the two can no longer disagree about what an oidc subject is.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…o POST

- every page the callback serves now carries Cache-Control: no-store,
  X-Frame-Options: DENY, a frame-ancestors 'none' CSP and
  Referrer-Policy: no-referrer, via a headers field on handler results:
  a framed confirmation form is a clickjacking surface, and the page's
  tokens must not live in a cache or leak onward.
- the confirmation form submits by POST (urlencoded), not GET, so the
  user code and the browser-bound token stay out of URLs, access logs
  and browser history. The router parses an urlencoded body for the one
  HTML form a browser submits; everything else still speaks JSON.
- the GET and POST routes share one implementation, reading query or
  form fields; the enumeration and contract tests cover both.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>

@clawgenti clawgenti 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.

Clawgenti Code Review

Summary

Since ca44063, this head closes most of the open items: settle-once, the pending-entry cap (429), nbf, the verbatim issuer, security headers, a POST confirmation form, and the CONFIRM_CODE_RE shape check. The deploy-scripts tests are green again. One must-fix is still open: a single mistyped code still breaks the login, because the wrong_code re-render sends an empty ct (see inline). CodeQL is still red, now with 1 high alert (the modulo false positive), which a maintainer needs to dismiss.

Author: galmasi (NONE — first-time)
Areas reviewed: TypeScript (control-plane, mocactl), K8s/VM deploy, Shell tests, OpenAPI/docs, tests
Agent/IDE config (.claude/.vscode): none
Commits: 14 commits, all signed-off: yes
CI status: failing. CodeQL has 1 high alert (oidc.ts:190, modulo on crypto random). It is a false positive since 256 % 32 == 0, and it needs a dismissal in code scanning; the new comment does not clear it. check is pending. Everything else passes.

Findings

# Severity Where Finding
1 must-fix handlers.ts:574 After one wrong code, the re-rendered form sends ct="", so every later submit burns a try and the login is refused (carried from ca44063, not yet fixed)
2 suggestion server.ts (urlencoded parse) The urlencoded body parser now applies to every POST route, not only oidcCallbackSubmit
3 nit mocactl/src/api/types.ts:21 The userCode comment still says the oidc flow needs no typed code

Still open from earlier rounds, not reposted inline: pdettori's SBX0 deploy gaps (deploy/sbx/setup.sh, the ocp-sbx credentials patch). Either fix them here, or note in the PR body and guide that SBX0 stays GitHub-only for now.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread packages/control-plane/src/handlers.ts Outdated
`<input type="hidden" name="state" value="${escapeHtml(state ?? '')}">` +
// The browser-bound half of the binding (oidc.ts): minted in the round-1 response this
// browser received, invisible to whoever started the login, required in round 2.
`<input type="hidden" name="ct" value="${escapeHtml(confirmToken ?? '')}">` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: a single typo still breaks the login. confirmToken is returned only by round 1 (settle with the principal). In round 2, confirmSignIn returns { outcome: 'wrong_code' } with no token, so this re-rendered form carries ct="". Every resubmit from that page then fails tokenOk and costs a try, and after 4 more submits the login is refused, even with the right code.

The new tests (a malformed confirmation does not burn a try, the POST test) pass token: landed.confirmToken by hand, so they never see what the re-rendered page carries.

Suggested fix: on wrong_code, echo back the token this request carried (field('ct')). The sender already holds it, so echoing exposes nothing. Then add a route-level test: land, POST a wrong code, take ct from the re-rendered body, POST the right code, and expect confirmed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 34978d12: the wrong-code re-render echoes back the ct the request carried (the sender already holds it, so echoing exposes nothing; only round 1 introduces a new token), and the route-level test now runs exactly the shape you described — land, wrong code, scrape ct from the re-rendered page, right code, confirmed.

Comment thread packages/control-plane/src/server.ts Outdated
// Two body languages: JSON for every client, and urlencoded for the one HTML form a
// browser submits (the oidc confirmation). Anything else a browser's <form> can send is
// refused, rather than half-parsed.
if ((req.headers['content-type'] ?? '').includes('application/x-www-form-urlencoded')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: this branch parses an urlencoded body for any POST/PUT/PATCH route, not just the confirmation form. That makes every JSON route reachable by a plain cross-site <form> (a simple request, so no CORS preflight). Bearer-token auth makes this low-risk today, but it widens the surface for no gain. Consider gating it on the route, e.g. a formBody: true flag on the oidcCallbackSubmit RouteSpec, and keep the invalid_json refusal everywhere else.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a42c3ef4 — the same formBody route flag; the parse is per-route now.

Comment thread packages/mocactl/src/api/types.ts Outdated
export interface DeviceStart {
deviceCode: string;
userCode: string;
/** Absent when the provider needs no typed code (the oidc flow: the browser is the approval). */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: this comment is out of date since ed1db012. The oidc flow now mints a user code that is typed on the confirmation page (see DeviceStart.userCode in identity.ts, already updated).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a42c3ef4 — the comment now matches DeviceStart.userCode in the control plane.

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

Thanks. bd28670 updates setup.test.sh to fifteen keys, and deploy-scripts / deploy-scripts-bash32 are green again.

I've read clawgenti's bd28670 review and agree with all of it: the wrong_code empty-ct must-fix (handlers.ts:574), the urlencoded parsing in server.ts, the stale userCode comment in mocactl types.ts, the CodeQL modulo alert, and the SBX0 deploy gaps. I'm not reposting those. Below are only the points that review doesn't cover.

must-fix

  1. New in bd28670: LoadCredential=SH_OIDC_CLIENT_SECRET:-/etc/... doesn't work as an "optional" credential (sh-control-plane.service:25, see inline). systemd's LoadCredential= has no - prefix. -/etc/serverless-harness/credentials/oidc-client-secret parses as a relative source. It contains /, so it isn't a valid credential name, and systemd logs "Credential source ... not valid, ignoring" and drops the line (config_parse_load_credential). A GitHub VM boots, but only because the line is ignored. An OIDC VM never gets the secret, so required(env, 'SH_OIDC_CLIENT_SECRET') (main.ts:138) stops boot. The env example says the secret must never go on an env line, which leaves no supported way to run oidc on a VM. setup-vm.test.sh:370 pins the broken string, so the suite can't catch it.
  2. A second way into the same dead form as clawgenti's handlers.ts:574 finding: reload or Back on the round-1 page. The page is no-store, so the browser re-requests ?code=. The provider refuses the replayed code, settleProviderDenial returns awaiting_confirmation with no token, and the page renders a form with ct="" that can never succeed. Echoing field('ct') fixes the wrong_code path but not this one. When there's no token at all, show a "this page is no longer valid; use the tab that opened from the sign-in, or start again in your terminal" message instead of a form. Please cover the reload case in the route-level test too.

suggestion

  • The GET callback route still accepts ?confirm=/ct (see inline).
  • control-plane.env.example says "Set all four" over five keys (SH_OIDC_SCOPE is optional). Say which four, or "the first four".
  • check failed at "Install ripgrep" (apt exit 100) for the third head in a row while main is green. Please re-run it.

LoadCredential=SH_CREDENTIAL_KEK:/etc/serverless-harness/credentials/credential-kek
LoadCredential=SH_EXCHANGE_TOKEN:/etc/serverless-harness/credentials/exchange-token
# Optional: the oidc client secret. The '-' prefix keeps a github VM booting without it.
LoadCredential=SH_OIDC_CLIENT_SECRET:-/etc/serverless-harness/credentials/oidc-client-secret

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: LoadCredential= has no - "optional" prefix (that's an ExecStart=/EnvironmentFile= convention). systemd parses -/etc/serverless-harness/credentials/oidc-client-secret as a relative source. Because it contains /, it isn't a valid credential name, so systemd logs Credential source "..." not valid, ignoring. and drops the whole line (config_parse_load_credential in src/core/load-fragment.c). The result:

  • github VM: boots, but only because the line is ignored (with a warning on every daemon-reload).
  • oidc VM: the secret is never loaded, so identityProviderFromEnv → required(env, 'SH_OIDC_CLIENT_SECRET') refuses to boot. The env example forbids the env-line route, so oidc on a VM can't work at all.

setup-vm.sh already solves this for an optional credential: ensure_operator_fallback writes a sh-control-plane.service.d/50-operator-inference-token.conf drop-in with the LoadCredential= line only while the file exists, and removes it when the file goes. Do the same for oidc-client-secret, and refuse at setup time when SH_IDENTITY_PROVIDER=oidc and the file is missing. That also lets the main unit keep exactly the MU1 credential count. systemd-analyze verify on the unit would have flagged this line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 294054a6: the invalid :- line is gone (you were right — systemd drops it entirely), and the credential now follows the ensure_operator_fallback discipline: setup-vm.sh writes sh-control-plane.service.d/50-oidc-client-secret.conf exactly while the file exists, removes it when it goes, and refuses at setup time when SH_IDENTITY_PROVIDER=oidc and the file is missing. The main unit is back to the MU1 credential count.

Comment thread deploy/vm/tests/setup-vm.test.sh Outdated
[[ "$(grep -c '^LoadCredential=' "$UNIT_CP")" == $(( ${#MU1_CREDENTIALS[@]} + 1 )) ]] ||
fail "$UNIT_CP must load exactly the ${#MU1_CREDENTIALS[@]} credentials setup-vm.sh writes, found" \
"$(grep -c '^LoadCredential=' "$UNIT_CP")"
grep -qxF 'LoadCredential=SH_OIDC_CLIENT_SECRET:-/etc/serverless-harness/credentials/oidc-client-secret' "$UNIT_CP" ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (test): this pins the invalid :-/ form, so the suite passes while systemd ignores the line (see the comment on sh-control-plane.service:25). Once the credential moves to a drop-in, revert the count check to ${#MU1_CREDENTIALS[@]} and test the drop-in instead: written when oidc-client-secret exists, removed when it doesn't.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 294054a6: the count check is back to ${#MU1_CREDENTIALS[@]}, and five new tests cover the drop-in — default installs nothing, oidc-without-file refuses naming the file, a present file gets the drop-in with the value never leaving it, an env-line secret refuses, and the drop-in is removed when the file goes.

Comment thread packages/control-plane/src/handlers.ts Outdated
// -- and the form's submission (POST, urlencoded) completes the sign-in, keeping the code and
// the browser token out of URLs, access logs and browser history. The refusal for a provider
// that holds its own flow (GitHub) names the setting to change, as the device-flow refusals do.
oidcCallback: (ctx, deps) => oidcCallbackImpl(deps, (k) => ctx.query.get(k)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: the GET route still runs the confirm round when ?confirm=/ct are present, so the code and token can still end up in URLs, logs, and history if anything sends them that way (an old bookmarked form, a hand-built link). Now that the form POSTs, consider having the GET path refuse confirm (400 "submit the form"), so the POST is the only way to confirm.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a42c3ef4: the GET route refuses ?confirm/?ct outright with a 400 page ("use the form on the sign-in page"), so the POST is the only way to confirm and the code and token can never ride a URL. The forged-state test now asserts that refusal.

George Almasi added 4 commits November 11, 2026 13:18
Review round 3: the wrong-code page carried ct="" (confirmSignIn returns
no token), so every resubmission from it failed the token check and
burned a try -- four more and the login was refused even with the right
code. The re-render now echoes back the ct the request carried: the
sender already holds it, so echoing exposes nothing, and only round 1
ever introduces a NEW token. Route-level test added in the exact shape
the reviewer described: land, wrong code, scrape ct from the re-rendered
page, right code, confirmed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…tional credential

Review round 3 caught that LoadCredential= has no '-' optional prefix (I
had invented one): systemd parses '-/etc/...' as a relative source,
rejects it, and DROPS the line -- so an oidc VM could never boot (the
secret never loads), while my test pinned the invalid spelling.

The credential now follows the operator-token discipline (ensure_operator_fallback,
#368): setup-vm.sh writes sh-control-plane.service.d/50-oidc-client-secret.conf
exactly while /etc/serverless-harness/credentials/oidc-client-secret
exists, removes it when the file goes, and refuses at setup time when
SH_IDENTITY_PROVIDER=oidc and the file is missing. The main unit is back
to the MU1 credential count; the env-key cross-check accepts a drop-in
loader (checked-in or setup-vm.sh's writer); five new tests cover
default, missing-file refusal, present-file drop-in, env-line refusal,
and removal.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…mask, discovery slash

Review round 3, suggestions and nits:

- urlencoded parsing is gated on a formBody flag on the one route that
  needs it: JSON routes are no longer reachable by a plain cross-origin
  HTML form (a CORS simple request).
- the GET callback refuses ?confirm/?ct outright (400): the confirmation
  submits by POST, so the code and the browser token can never ride a
  URL, an access log, or browser history.
- azp must name this client when aud is multi-valued (OIDC Core
  §3.1.3.7); tested both ways.
- the confirm-code index is byte & 31 -- a mask, not a modulo, so it is
  uniform -- with the 32-entry alphabet length enforced at load. Clears
  CodeQL's biased-crypto-random alert by construction rather than by
  dismissal.
- the discovery URL strips exactly one trailing slash (Discovery §4): a
  verbatim slash issuer no longer builds a double slash before
  .well-known.
- mocactl's DeviceStart.userCode comment caught up with ed1db01.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
…tion

The round-3 review asked for the oidc cases the settings block lacked:
settings written with the default scope, sticky across a re-run that
gives none of them, set-but-empty clearing back to github with the oidc
values emptied, oidc without an issuer refusing at setup, and a
near-miss provider name refusing. Also documents the pending-store
cap's fairness limitation in the w3id guide.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>

@clawgenti clawgenti 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.

Clawgenti Code Review

Summary

The four commits since bd28670 close most of what was open. A wrong-code re-render now echoes the ct it received, and a route-level test scrapes the re-rendered page. GET refuses confirm/ct. Urlencoded parsing is opt-in per route (formBody). azp is checked for multi-value audiences. The confirm code uses a mask instead of a modulo, with a load-time guard on the alphabet length, which should clear the CodeQL alert. Discovery strips one trailing slash. On the VM, the client secret now loads through a setup-vm.sh drop-in instead of the invalid - LoadCredential. The mocactl userCode comment is corrected. One must-fix is still open, carried from the maintainer's bd28670 review: reloading the round-1 page, or going Back to it, still renders a form with ct="" that can never succeed (see inline).

Author: galmasi (NONE — first-time)
Areas reviewed: TypeScript (control-plane, mocactl), Shell (deploy/vm, deploy/k8s tests), systemd unit, env template, docs, tests, security
Agent/IDE config (.claude/.vscode): none
Commits: 18 commits, all signed-off: yes
CI status: pending. Only DCO has reported on this head so far.

Findings

# Severity Where Finding
1 must-fix handlers.ts:570 Reload/Back on the round-1 page still yields a dead ct="" form (carried from ingpaolodettori-dev, bd28670 #2)
2 nit control-plane.env.example:32 Stale pointer to sh-control-plane.service for the secret, and "Set all four" over five keys

Still open from earlier rounds, not reposted inline: the SBX0 deploy gaps (deploy/sbx/setup.sh, the ocp-sbx credentials patch) are untouched. Either fix them here, or note that SBX0 stays GitHub-only.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

// it, so echoing exposes nothing, while omitting it would ship ct="" and make every retry
// fail the token check -- four more submits and the login is refused even with the right
// code (review round 3). Only round 1 ever introduces a NEW token.
const ct = confirmToken ?? field('ct') ?? '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (carried from ingpaolodettori-dev's bd28670 review, #2): this fixes the wrong_code path, but not a reload of, or Back to, the round-1 page. That page is no-store, so the browser re-sends GET ?code=…&state=…. The provider refuses the replayed code, and settleProviderDenial (oidc.ts:422) returns awaiting_confirmation with no confirmToken. A GET carries no ct, so this line falls through to '' and the form ships ct="". Every submit from that page fails tokenOk and burns a try, so a user who reloads once and then types the right code five times gets refused. When ct resolves to empty, render a "this page is no longer valid — use the tab the sign-in opened, or start again in your terminal" message instead of a form. Add a route-level test: land, re-GET the same ?code=, and assert that no form with an empty ct comes back.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 519086dc, in the shape you suggested: when no ct resolves (round-1 reload or Back — the spent code is refused, the login stays parked, nothing to carry), the page renders 'this page is no longer valid — use the tab that opened from the sign-in, or start again in your terminal' and no form at all. Route test: land, re-GET the same code/state with the provider refusing the replay, assert no <form in the body and the login still parked.

Comment thread deploy/vm/env/control-plane.env.example Outdated
# OPTIONAL. Set all four to switch logins from GitHub's device flow to an OIDC provider (e.g.
# w3id; docs/guides/oidc-login-w3id.md). SH_IDENTITY_PROVIDER=oidc plus the issuer, the client id
# and the callback URL exactly as registered with the provider. The CLIENT SECRET is a systemd
# credential (see sh-control-plane.service), never an env line.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: after 294054a, sh-control-plane.service no longer mentions the oidc secret. It is loaded by the 50-oidc-client-secret.conf drop-in that setup-vm.sh writes when credentials/oidc-client-secret exists. Point readers at that file path instead. Line 29 also still says "Set all four" over five keys (SH_OIDC_SCOPE is optional). Say "the first four".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 519086dc: the note now points at the sh-control-plane.service.d/50-oidc-client-secret.conf drop-in setup-vm.sh writes (and the credentials path), and says 'the first four' over the five keys.

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

Thanks. The four new commits close nearly everything open from bd28670. I checked each against the code:

  • ct echo on a wrong_code re-render (34978d1, handlers.ts:570). The route test now takes ct from the re-rendered page, as asked.
  • The oidc client secret loads through a 50-oidc-client-secret.conf drop-in that exists exactly while the file does, matching ensure_operator_fallback. Setup refuses when SH_IDENTITY_PROVIDER=oidc and the file is missing, or when the secret is on an env line, empty, or not 0600/0400. The main unit is back to the MU1 count, and setup-vm.test.sh covers all five cases (294054a).
  • Per-route formBody urlencoded parsing, GET refusing confirm/ct, the & 31 mask with a load-time length check, azp on multi-value aud, and one trailing slash stripped for discovery only (a42c3ef).
  • k8s setup.test.sh stickiness, clearing and validation cases, plus the pending-store fairness caveat (#716) in the guide (84968f9).

must-fix

  1. Still open from bd28670 (must-fix 2): reload or Back on the round-1 page still renders a form that can't succeed (see inline on handlers.ts:570). A reload GETs ?code=&state= again. The provider refuses the replayed code, settleProviderDenial sees the parked principal and returns awaiting_confirmation with no token. On GET, field('ct') is null, so the new fallback still produces ct="". Each submit of that form, even with the right code, fails the token check and burns a try (confirmSignIn). After MAX_WRONG_CODES tries the login is denied in the terminal. When the outcome is awaiting_confirmation and there's no ct at all, render a "this page is no longer valid; use the tab that opened from the sign-in, or start again in your terminal" page instead of a form. Please add a route test: land, then re-GET the same code/state with the provider refusing the code, and assert no form is rendered.

CI was still pending on this head when I drafted this.

Assisted-By: Claude Code

// it, so echoing exposes nothing, while omitting it would ship ct="" and make every retry
// fail the token check -- four more submits and the login is refused even with the right
// code (review round 3). Only round 1 ever introduces a NEW token.
const ct = confirmToken ?? field('ct') ?? '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (carried from bd28670): this fixes the POST wrong_code path, but not a reload or Back on the round-1 page. That re-GETs ?code=…&state=…, so confirm/ct are absent and the new GET guard lets it through. The provider refuses the already-spent code, settleProviderDenial (oidc.ts:422) returns awaiting_confirmation with no confirmToken, and field('ct') is null on GET, so ct is '' here. The user gets a form that can never succeed, and each submit burns one of MAX_WRONG_CODES (the token check fails first in confirmSignIn) until the terminal login is denied.

Suggested shape:

const ct = confirmToken ?? field('ct') ?? '';
if (ct === '') {
  return htmlPage('Sign-in page expired',
    '<p>This page is no longer valid. Use the tab that opened from the sign-in, or start again in your terminal.</p>');
}

Please add a route test that re-GETs the same code/state (the provider refusing the replayed code) and asserts no <form is in the body.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 519086dc — same hole, same commit: the empty-ct case renders the explanation page, never a form; the test asserts no <form and that the original tab's login is untouched (still authorization_pending, not denied).

…f shipping a dead form

Review round 4: Back or reload on the round-1 page re-sends the
provider's redirect. The spent code is refused, the login stays parked,
and the re-render has no confirm token to carry -- so the form shipped
ct="" and every submit from it burned a try until the login was denied,
right code included. When no ct resolves, the page now says the sign-in
is no longer valid and to use the tab the sign-in opened (or start
again), and never renders a form. Route test: land, re-GET the same
code/state, assert no <form and that the login is still parked.

Also points the env example's secret note at the drop-in that actually
loads it (294054a) and fixes its 'all four' over five keys.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>

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

Thanks. 519086d closes the last must-fix. A reload or Back on the round-1 page now gets an "expired" page instead of a form that can never succeed, and the route test covers the replayed-code path through to "login still parked". All our items from earlier rounds are verified fixed.

Not blocking (follow-up is fine; please say so on the threads):

  • clawgenti's sandbox-config.ts:129 nit (SUBJECT_RE lets test:N into SH_ALLOWED_SUBJECTS, which contradicts the ADR-0045 comment in main.ts) has no reply yet.
  • The SBX0 deploy gaps (deploy/sbx/setup.sh, the ocp-sbx credentials patch) are still untouched. A follow-up, or a note that SBX0 stays GitHub-only, is fine.
  • docs/guides/oidc-login-w3id.md:95: the example authorize URL still uses the issuer path (/oidc/endpoint/default/authorize). As mrsabath noted, w3id serves authorization_endpoint under /v1.0/.

Author: galmasi (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane handler + route test), env template (incremental 84968f9→519086d)
Agent/IDE config (.claude/.vscode): none
Commits: all signed-off: yes

@pdettori
pdettori merged commit dd0ce71 into main Nov 11, 2026
17 checks passed
cwiklik added a commit to cwiklik/moca that referenced this pull request Nov 11, 2026
Upstream moved from c241116 to dd0ce71 (23 commits), mostly the OIDC
identity provider (rossoctl#701) and rossoctl#715's sandbox-tier fixes. Merged rather than
rebased: the branch has an open PR (rossoctl#717), and a rebase needs a force-push
that is not authorized.

Two files conflicted, both because upstream and this branch edited adjacent
lines:

- `packages/control-plane/src/handlers.ts`: this branch adds `getMetrics`
  between `healthz` and `getDiscovery`; upstream deleted the blank line
  there. Resolution keeps `getMetrics` and drops the blank line.
- `docs/reference/configuration.md`: upstream added the OIDC rows to the
  control-plane table, this branch rewrote the `LEAF_RESULT_TTL_SECONDS`
  cell, and prettier realigns every row of a table when one cell's width
  changes -- so the whole table conflicted over one real edit. Resolution
  keeps upstream's table with this branch's cell re-applied.

`deploy/vm/tests/setup-vm.test.sh` carries one unrelated fix, not a merge
artifact: upstream 294054a added two GNU-style `sed -i` calls with no
suffix, which abort the whole suite on BSD sed ("invalid command code f")
before it can validate anything. Both now use the `-i.bak` + `rm -f` idiom
the file's six other `sed -i` calls already use. Without it the VM deploy
suite -- one of the two this branch changed -- cannot run on macOS.

Verified on the merged tree: `make typecheck`, control-plane 1210,
knative-server 558, mocactl 1704, supervisor 239, work-queue 12, harness 784
(the one failure is the known pre-existing macOS `mv` issue in
`context-overlay.test.ts`), plus both deploy suites,
`setup-vm.test.sh` and `compose.test.sh`.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 12, 2026
…ases' sed -i lines (rossoctl#701, 294054a) take a backup suffix and remove it, as the file's other sed -i lines do (BSD sed reads the next word as the suffix). 106 ok on macOS.

Assisted-By: Claude (Anthropic AI) <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 12, 2026
…der (rossoctl#701) and 22 more

Over sbx-upstream-1111's merge of c241116. Four conflicts, each resolved by keeping both sides:
- control-plane server.ts / handlers.ts: upstream's handler `headers` (the oidc page) is a superset of
  our `contentType`; upstream's lines kept.
- control-plane main.ts: upstream's github-only SH_GITHUB_CLIENT_ID check, with our `profile` kept
  (the combined profile reads it); the deps keep our presence reader, template catalog and host
  registry, with upstream's identityProviderFromEnv(env) for identity (github stays the default; it
  carries SH_ADMIN_SUBJECTS as before).
- docs/reference/configuration.md: the control-plane table keeps our SH_SANDBOX_TEMPLATES,
  SH_PROVENANCE_DIR and SH_TEMPLATE_HOSTS rows, and takes upstream's SH_IDENTITY_PROVIDER and SH_OIDC_*
  rows and its SH_GITHUB_CLIENT_ID / SH_ADMIN_SUBJECTS wording.

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 12, 2026
…-i.bak, so it runs on macOS

Upstream rossoctl#701 added two `sed -i '/^…=/d' "$OD/control-plane.env"` lines (the SH_OIDC_CLIENT_SECRET and
SH_IDENTITY_PROVIDER cases), GNU-only: BSD sed reads the script as the -i suffix and stops the test on
macOS ("invalid command code f"). Both now use `sed -i.bak … && rm -f ….bak`, as the rest of the file
does. Test-only; setup-vm.sh is unchanged. Found by autobench-sandbox's host review of the sync.

Tests: setup-vm.test.sh on bash 5, 106 ok, 0 not ok (it stopped after 90 before).

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 12, 2026
rossoctl#720)

The SH_OIDC_CLIENT_SECRET and SH_IDENTITY_PROVIDER cases added in rossoctl#701 used `sed -i '…' FILE`. BSD sed (macOS) reads the next word after -i as the backup suffix, so the test stopped there with "invalid command code". Use the form the file's other sed -i lines already use: `sed -i.bak '…' FILE && rm -f FILE.bak`. Test-only; setup-vm.sh is unchanged. On macOS with bash 5: 104 ok, 0 not ok.

Refs rossoctl#720.

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 12, 2026
…jects too (rossoctl#701, joint list D2)

Upstream's OIDC identity provider (rossoctl#701) mints `oidc:<provider sub>` subjects, but our member, owner and
quota checks took only `github:<numeric id>`, so an OIDC deployment could not enroll, make admin, hand a
template to, or set a quota for its own users. One grammar now serves all four: identity.ts's
MEMBER_SUBJECT_RE (github or oidc, built from the same OIDC_SUB_PATTERN login verifies; never `test:<n>`,
which SH_TEST_USERS enrolls and the sandbox profile refuses), used by member-handlers' subjectParam,
transferTemplateOwner, putQuota and the policy's quotaBySubject check, with one refusal text. The openapi
patterns (the Subject schema, the owner body, the four subject path parameters) widen to match: API
1.13.0. mocactl's help names both forms. A GitHub deployment sees no change.

The user's D2 on the joint upstream list (2026-11-12): adapt once on our branch, before I16, I24 and I25.
Not verified on an OIDC deployment (none here); the tests use an oidc subject directly.

Tests: control plane 1475 passed (3 skipped, with Redis), including an oidc enrollment, an oidc quota
override, an oidc owner passing the grammar, and test:1 / gitlab:1 / malformed oidc subjects refused;
mocactl's contract, cli, admin and templates tests 177 passed; tsc clean in both packages.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit that referenced this pull request Nov 13, 2026
A route that names another subject (a template's new owner here; the
members and quota routes later) takes a person's login from either real
provider, `github:<numeric id>` or `oidc:<provider sub>` (#701), and
never a synthetic `test:<n>` user. MEMBER_SUBJECT_RE is built from the
same OIDC_SUB_PATTERN as SUBJECT_RE, so the two cannot drift, and
MEMBER_SUBJECT_FORMS is the grammar as a refusal states it.

The same hunk is carried by the enrollment and admin-quota changes:
whichever lands first brings it, and the others merge onto it as is.

Refs #747

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit that referenced this pull request Nov 14, 2026
… the API

Who may use the sandbox service (SH_ALLOWED_SUBJECTS) and who is an admin
(SH_ADMIN_SUBJECTS) were settings only: every change was a setup.sh run, effective at
the subject's next refresh, and left no record.

With SH_PROVENANCE_DIR set, a members store (members.json beside the template catalog)
adds to those lists; the settings stay the bootstrap and are never edited by the API.

- GET /v1/subjects (any admin), PUT/DELETE /v1/subjects/{subject} and
  PUT/DELETE /v1/subjects/{subject}/roles/admin (an admin named in SH_ADMIN_SUBJECTS
  only; an API-granted admin gets 403), on both route profiles. A grant may carry
  `until` (epoch seconds) and lapses by itself.
- A settings subject cannot be unenrolled or revoked through the API
  (409 bootstrap_subject), and no admin revokes itself (409 self_revoke).
- Roles and enrollment are evaluated per request: the router replaces a verified
  token's roles with the subject's roles now, and the logins, the refresh and the
  egress owner check use the same evaluation (membershipNow). Without a store the
  token's claims stand, as before.
- Each change is a record on a new `members` provenance stream, with the new kinds
  `member` and `role` (an `expired` written once, by the first request that sees the
  lapse). provenance.ts and verify-provenance.py accept those kinds on that stream
  only.
- MEMBER_SUBJECT_RE in identity.ts: github:<id> or oidc:<sub>, built from the pattern
  the OIDC login verifies (#701); never test:<n>.

API 1.5.0 (openapi, CHANGELOG), the design spec and the HTTP API reference.

Refs #739

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit that referenced this pull request Nov 15, 2026
The quota route names another subject: a person's login from either real
provider, `github:<numeric id>` or `oidc:<provider sub>` (#701), and never
a synthetic `test:<n>` user. MEMBER_SUBJECT_RE is built from the same
OIDC_SUB_PATTERN as SUBJECT_RE, so the two cannot drift, and
MEMBER_SUBJECT_FORMS is the grammar as a refusal states it.

This is the same hunk the template admin and enrollment changes carry,
byte for byte: whichever lands first brings it, and the others merge onto
it as is.

Refs #748

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 17, 2026
@pdettori
pdettori deleted the feat/oidc-identity-provider branch November 18, 2026 19:21
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.

6 participants