Repository navigation
fix(oidc): bound outstanding login starts per client address, not just in total - #874
Conversation
The pending-auth store's 10,000-entry cap bounds memory, but the login start is unauthenticated: one client looping starts could fill it with live 15-minute states, and every real user then got 429 for the rest of the TTL. Bound the live states one client address may hold as well (SH_OIDC_MAX_PENDING_PER_SOURCE, default 20, 0 is off), refusing with the total cap's 429 quota_exceeded while other addresses still start. The address is plumbed through RequestCtx.source to IdentityProvider.startDeviceAuth(source). It is the socket peer, or, behind SH_TRUSTED_PROXY_HOPS reverse proxies that append to X-Forwarded-For, the entry that many from the right; deploy/k8s sets it to 1 for the OpenShift Route, whose router appends the client's address and is (with the supervisor) the only caller the NetworkPolicy admits. Closes rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…rs: append The per-source login bound trusts the LAST X-Forwarded-For entry (SH_TRUSTED_PROXY_HOPS=1), which is the client's address only while the router appends. An IngressController's forwardedHeaderPolicy of IfNone passes a client's own header through (any address, a victim's included), and Never or Replace change what the last entry means. Pin append on the four Routes that reach the control plane (ocp, ocp-single's routes component, ocp-sbx, ocp-combined), and a manifest test that keeps every such Route pinned. Closes rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…keys On the k8s path, the only one that runs oidc, an operator could change neither setting: SH_OIDC_MAX_PENDING_PER_SOURCE had no ConfigMap ref and SH_TRUSTED_PROXY_HOPS was a literal '1'. Both are now sticky moca-settings keys that setup.sh writes and validates (given or stored), read by optional configMapKeyRefs. The per-source bound travels with the oidc block (empty: the control plane's 20); the hop count defaults to 1, the Route's router. The base comment now says who reaches the pod: the supervisor (base NetworkPolicy, and trusted, since it can write any X-Forwarded-For) and, on OpenShift, the router (the overlays). docs/operations/upgrades.md gets the Upgrade notes entry change-policy rule 5 asks for: the new default of 20, and that the upgrade must be a setup.sh re-run so the hop count and the Route annotation land. deploy/sbx/setup.sh is unchanged: it writes no oidc settings (GitHub only), so neither key would take effect there. Closes rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
settle()'s patch type admitted `source`, which would leave the per-source index pointing at an entry that no longer carries that source. PendingOidcPatch omits it with the state and the TTL. Closes rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
The oidc provider has answered 429 quota_exceeded at its total cap since it shipped, undocumented, and rossoctl#716 gives it a second cause (one client address at SH_OIDC_MAX_PENDING_PER_SOURCE). Document both. Additive, so the minor moves; 1.28.0, as 1.27.0 is taken by another change in review. Closes rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
2001:DB8:0::1 and 2001:db8::1 are one client, so they must be one per-source bucket. clientSource now takes the canonical RFC 5952 text of an IPv6 address (the URL parser's), beside the IPv4-mapped unmapping it already did. Closes rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…urce Signed-off-by: Rong Chang <[email protected]> # Conflicts: # docs/api/CHANGELOG.md # docs/api/openapi.yaml # docs/reference/change-policy.md
Main took 1.27.0 (rossoctl#864, the base URL's page), so this PR's contract version is 1.28.0, the next free one (it was 1.29.0 while rossoctl#874 held 1.28.0; whichever merges second renumbers). Its section goes above 1.27.0, and the change-policy list keeps both entries. rossoctl#863 made /turn a documented alias of POST /v1/turn, response by response, so the alias gets the new 422 too (the alias contract test caught it). Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
rossoctl#868 took 1.28.0 (the config bundle's format version, harness 1.5.0), so this PR's per-source bound on login starts is 1.29.0: its CHANGELOG section goes above 1.28.0, openapi.yaml and change-policy say 1.29.0, and the change-policy list keeps both entries in order. Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Well-rounded fix for #716: the per-source bound, the bySource index with empty-set dropping, and the XFF trust plumbing (canonical addresses, pinned Route annotations, manifest test) all hold up, and test coverage of the new bound and header parsing is thorough. Two suggestions below — one back-compat hazard for out-of-tree stores, one on the fewer-entries-than-hops fallback. No agent/IDE config files touched, no secrets, all commits signed off, CI green.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control plane), security (rate limiting, XFF trust), Helm/K8s overlays, docs
Agent/IDE config (.claude/.vscode): none
Commits: 7 commits, all signed-off: yes
CI status: passing
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| /** False when the store is at its cap; the caller refuses the login start. */ | ||
| put(entry: PendingOidcAuth): Promise<boolean>; | ||
| /** Anything but `parked` means a bound was hit; the caller refuses the login start. */ | ||
| put(entry: PendingOidcAuth): Promise<PendingPutOutcome>; |
There was a problem hiding this comment.
suggestion — put's contract changed from Promise<boolean> to Promise<PendingPutOutcome>, and PendingAuthStore is an exported extension point that docs/guides/oidc-login-w3id.md explicitly invites people to implement ("a Redis-backed PendingAuthStore"). A pre-existing out-of-tree store whose put still returns true on success now fails the parked !== 'parked' check in startDeviceAuth, so every login start 429s after upgrading — a silent outage for exactly the multi-replica deployments the guide steers there.
Suggested fix: normalize a truthy non-string return to 'parked' at the call site (one line), or at minimum call the compatibility break out in the 1.28.0 changelog entry and the upgrade notes.
There was a problem hiding this comment.
Fixed in 2a257c7: startDeviceAuth now reads a legacy boolean from put (true as parked, false as the total cap's refusal), and the interface type accepts it, so an existing store keeps starting logins after an upgrade. A test covers both values, and the changelog entry (1.29.0, after the renumbering) and the upgrade notes describe it: a custom store enforces the per-source bound only once it answers source_full.
| const header = Array.isArray(raw) ? raw.join(',') : raw; | ||
| if (!header) return fallback; | ||
| const entries = header.split(',').map((e) => e.trim()); | ||
| const picked = entries[Math.max(0, entries.length - hops)]!; |
There was a problem hiding this comment.
suggestion — when the header holds fewer entries than hops, the leftmost — client-written — entry is picked (Math.max(0, ...)), rather than falling back to the socket peer. The doc comment says the leftmost "stands" for a request that skipped a proxy, but a skipped proxy means the header is untrusted, not that the leftmost entry is real. The NetworkPolicy threat model (only supervisor + router reach the pod) mitigates this today, but any path around the router with a 1-entry XFF lets a client fill a victim's 20-slot bucket. Falling back to the peer when entries.length < hops would match express's trust proxy = n semantics and be strictly safer.
There was a problem hiding this comment.
Fixed in d1dfa36: when X-Forwarded-For holds fewer entries than SH_TRUSTED_PROXY_HOPS, clientSource falls back to the socket peer, as express's trust proxy = n does. Tests cover a short header (socket peer) and exactly hops entries (the hops-th from the right), and the doc comment and configuration.md say so.
PendingAuthStore is an extension point the oidc guide invites a shared store for, and rossoctl#716 changed put from a boolean to the outcome. A store written against the boolean would have failed every login start with 429 after an upgrade. The provider now reads true as parked and false as the total cap's refusal; in-tree stores keep answering the outcome. The 1.29.0 changelog entry and the upgrade notes say so. Refs rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
With fewer X-Forwarded-For entries than SH_TRUSTED_PROXY_HOPS the request skipped a proxy, so no entry is known to be a trusted proxy's. clientSource took the leftmost, client-written entry; it now falls back to the socket peer, as express's trust proxy = <count> does. A header with exactly hops entries still yields the hops-th from the right. Refs rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
There was a problem hiding this comment.
Summary
Reviewed the per-client-address OIDC login bound end to end: the MemoryPendingAuthStore per-source index and its remove/settle/sweep paths (including the emptied-set race and empty-set cleanup), the clientSource() trusted-proxy XFF selection with its IPv4-mapped/IPv6 canonicalization and non-IP fallbacks, the OpenShift Route header pinning, the setup.sh settings plumbing, and the 1.29.0 contract bump with docs/tests. The bound and index logic is correct and well covered by the new tests; backward compatibility with the pre-#716 boolean put contract is handled. No findings.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript control-plane, K8s manifests, shell setup script, OpenAPI/docs
Agent/IDE config (.claude/.vscode): none
Commits: 10 commits, all signed-off: yes
CI status: passing
All checks pass. Ready for human review.
Generated by RepoMan github-pr-review@9672454 (https://github.com/rossoctl/agent-skills/blob/96724547c162978f58d845b9a8331a679bf39444/skills/github-pr-review/SKILL.md).
pdettori
left a comment
There was a problem hiding this comment.
Summary
The per-source bound, the bySource index and its cleanup on remove and sweep, and clientSource() (canonical spellings, the fallback to the socket peer) all hold up. I checked the trust model against upstream/main. All four control-plane Routes use edge TLS, so HAProxy can append to X-Forwarded-For. The supervisor proxies no client login traffic. The only ingress is the base NetworkPolicy plus the ocp-sbx router policy. Both earlier bot findings are fixed (2a257c7, d1dfa36). One suggestion inline, not blocking.
Author: webchang (MEMBER — maintainer)
Areas reviewed: control-plane TypeScript, K8s overlays and NetworkPolicies, deploy/k8s/setup.sh and its tests, OpenAPI/docs
Agent/IDE config (.claude/.vscode): none
Commits: 10 commits, all signed-off: yes
CI status: passing
Assisted-By: Claude Code
| | `SH_OIDC_REDIRECT_URI` | none | **Required** when `oidc`. The control plane's public `GET /v1/auth/oidc/callback` URL, exactly as registered with the provider (e.g. its OpenShift Route) | Login | | ||
| | `SH_OIDC_CLIENT_SECRET` | none | **Secret, required** when `oidc`. Resolved through `withCredentials` (systemd credential or K8s secret), never committed | Login | | ||
| | `SH_OIDC_SCOPE` | `openid email profile` | Only when `oidc` | Login | | ||
| | `SH_OIDC_MAX_PENDING_PER_SOURCE` | `20` | Only when `oidc`. Live login starts one client address may hold, beside the 10,000 the control plane holds in total; past it that address gets the total cap's `429 quota_exceeded`, while other addresses still start. An abandoned start holds its slot for the state TTL (15 minutes). `0` turns the bound off, for a deployment whose clients all arrive from one address (an SSH tunnel); a malformed value refuses to boot. Which address a request comes from follows `SH_TRUSTED_PROXY_HOPS` | Login | |
There was a problem hiding this comment.
suggestion: The VM path's documented access is an SSH tunnel (deploy/vm/env/control-plane.env.example describes SH_PUBLIC_HARNESS_URL "behind an SSH tunnel"). So every oidc client there arrives from 127.0.0.1, and the new default of 20 caps the whole VM. That is exactly the case this row names for 0. But the VM env example lists SH_OIDC_SCOPE with the other oidc keys and not this one. Consider adding a commented #SH_OIDC_MAX_PENDING_PER_SOURCE= line there (e.g. "0 behind an SSH tunnel, where every client is one address"), plus a line for VM operators in the upgrade notes.
There was a problem hiding this comment.
Done in 09c19b5: the VM env example now has a commented #SH_OIDC_MAX_PENDING_PER_SOURCE=0 beside the other oidc keys, saying that behind the SSH tunnel every client arrives from 127.0.0.1, so 20 would cap the whole VM; the upgrade notes tell VM operators to set it.
Review suggestion: deploy/vm's documented access is an SSH tunnel, so every oidc client arrives from 127.0.0.1 and the default of 20 would cap the whole VM. The VM env example now carries a commented SH_OIDC_MAX_PENDING_PER_SOURCE=0 line with that reason, and the upgrade notes tell VM operators to set it. Refs rossoctl#716 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Brings 25 upstream merges since 1aa8dd6, among them the sbx OIDC identity provider (rossoctl#851), the Redis schema-version key and config bundle format marker (rossoctl#868), the provisioner Redis ACL user (rossoctl#869), the relay keepalive env (rossoctl#866), the per-source OIDC pending bound with the forwarded-headers Route pin (rossoctl#874), the egress refusal hints and control-plane index (rossoctl#864), the empty-workspace sweep (rossoctl#872) and the orphan-sweep log split (rossoctl#849). No conflicts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The container worker reads SH_WORKSPACE_IDLE, but nothing in deploy/k8s set it, so its 30-minute default applied: a HITL session that waited longer for a person resumed in an empty workspace. deploy/microvm writes 8h. setup.sh takes it as a sticky input, like SH_TRUSTED_PROXY_HOPS (#874): validated in parse_args and in write_settings for a stored value, stored in moca-settings, empty meaning 8h. The check mirrors the worker's time.ParseDuration and > 0 rule, and is stricter (whole h/m/s in order), so `30`, `-1m` and `0h` are refused before any apply. The sandboxes run in moca-sandbox and a configMapKeyRef reads only its own namespace, so setup.sh mirrors the value to ConfigMap moca-sandbox-settings there. base/sandbox.yaml and the workload PodTemplate read it with an optional ref (no ConfigMap: the worker's 30m). write_overlay stamps the value on the sandbox pod template, and the key is left out of the settings hash, so a change rolls only the sandboxes. 8h, not less: /workspace is the pod's writable layer (an emptyDir with no sizeLimit on ocp-single), with no ephemeral-storage limit or quota, so the idle sweep is the only bound. The README, configuration reference and upgrade note say so; the reset is still silent and there is no release. Part of #338 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Closes #716
What changed and why
POST /v1/auth/deviceis unauthenticated, so one client looping starts can fill the cap with live 15-minute states. Every real user then gets429 quota_exceededuntil those states expire, and a sweep cannot help because none of them has expired yet.MemoryPendingAuthStorenow also bounds how many live states one client address may hold (SH_OIDC_MAX_PENDING_PER_SOURCE, default 20;0turns it off). Past that bound, that address gets the total cap's refusal (429 quota_exceeded, with the message "...waiting from this address...") while other addresses still start.putnow returns'parked' | 'full' | 'source_full'instead of a boolean, so the provider can say which bound was hit.settle's patch type (PendingOidcPatch) cannot change an entry'ssource, which would desync the index.RequestCtx.source→IdentityProvider.startDeviceAuth(source?). GitHub's device flow parks no state here, so it ignores the address.clientSource()inserver.ts.X-Forwarded-For,SH_TRUSTED_PROXY_HOPS=<n>takes the entrynfrom the right (the same rule as express'strust proxy = <count>).X-Forwarded-Forentry is the client's only while the router appends. An IngressController whoseforwardedHeaderPolicyisIfNonewould pass a client's own header through, letting it choose any address, a victim's included;NeverorReplacechange what the entry means. So every Route that reaches the control plane now carrieshaproxy.router.openshift.io/set-forwarded-headers: append:overlays/ocp/routes.yaml,overlays/ocp-single/routes/route.yaml,overlays/ocp-sbx/api-route.yamlandoverlays/ocp-combined/api-route.yaml. A manifest test keeps every such Route pinned.deploy/k8s. Both are stickymoca-settingskeys, written and validated bydeploy/k8s/setup.sh(given or stored) and read by optionalconfigMapKeyRefs in the base Deployment.SH_OIDC_MAX_PENDING_PER_SOURCEtravels with the oidc block; empty means the control plane's 20.SH_TRUSTED_PROXY_HOPSdefaults to1, for the Route's router. A request with no header (kind, a port-forward) keys by the socket peer.X-Forwarded-For.deploy/sbx/setup.shis unchanged: it writes no oidc settings, so neither key would take effect there.POST /v1/auth/devicenow documents its429 quota_exceededand both of its causes. The total-cap refusal existed before but was undocumented. This is additive, so the minor version moves; 1.29.0, after feat(egress,control-plane): an egress refusal says what it means, and the control plane's base URL says what it is #864's 1.27.0 and feat: a Redis schema-version key, and the config bundle's format version carried and checked #868's 1.28.0. Updated:docs/api/CHANGELOG.mdanddocs/reference/change-policy.md.docs/reference/configuration.md.docs/guides/oidc-login-w3id.mdreplaces the "capped, not fair" limitation with the two bounds and what the trust relies on.docs/operations/upgrades.mdgains an "Upgrade notes" section (below).Upgrade notes
SH_OIDC_MAX_PENDING_PER_SOURCE;0turns the bound off). Users behind one NAT address share one bucket; raise the bound if they need more. GitHub logins are unchanged.deploy/k8s, upgrade by re-runningsetup.shwith the new--image. That run writesSH_TRUSTED_PROXY_HOPS=1and applies theappendannotation on the Routes. An image changed any other way leaves the key unset (0), and every login then keys by the router's address, so the deployment as a whole gets 20.X-Forwarded-For, setSH_TRUSTED_PROXY_HOPSto the number of such proxies.Tests
New tests:
packages/control-plane/test/oidc.test.ts, "the per-source bound (oidc: bound outstanding login starts per source, not just in total #716)":quota_exceeded, "from this address") while another source still starts;0turns the bound off.packages/control-plane/test/server.test.ts, "the client source (oidc: bound outstanding login starts per source, not just in total #716)":startDeviceAuth.packages/control-plane/test/main.test.ts:SH_TRUSTED_PROXY_HOPSdefaults to 0, reads1, and refusesoneat boot.packages/supervisor/test/k8s/forwarded-headers.test.ts:ocp,ocp-singlewith its routes component,ocp-sbxandocp-combined, every Route to the control plane is listed and pinsappend;moca-settingsthrough optional refs.deploy/k8s/tests/setup.test.sh:moca-settingsnow holds exactly nineteen keys;1;one,-1) is refused.Before and after:
The control plane: with the
src/changes stashed (main's code), 8 of the new tests fail. For example:Error: expected a throw, because main parks the third start from the same address;expected undefined to be '198.51.100.1'.The total-cap test and the
0-is-off test pass on main, as expected. With the fix, all of them pass.IPv6 spelling: without the canonicalization,
expected '2001:DB8:0:0::1' to be '2001:db8::1'.The manifests: with the
deploy/k8sbase and overlay changes stashed, all 5forwarded-headers.test.tstests fail; with them, all pass.Suites:
packages/control-plane:vitest run1948 passed, 3 skipped (the live Vault suite), including the OpenAPI contract-version test;tsc --noEmitis clean.packages/server:vitest run585 passed.packages/supervisor:test/k8s(the manifest renders): 110 passed;tsc --noEmitis clean.deploy/k8s/tests/setup.test.sh: all passed (117 checks).-S warningis clean ondeploy/k8s/setup.shand its test;scripts/check-doc-links.pyreports 0 broken links;Out of scope
Every commit is signed off (DCO).
Assisted-By: Claude Code