Repository navigation
feat(control-plane): user-scoped sandbox-egress credentials and the owner lookup (SBX0.2b phase 1) - #630
Conversation
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
The control-plane half of SBX0.2b phase 1 (config, sandbox-profile credential routes, host[:port][/prefix] destinations, multi-header bindings, and the POST /v1/egress/credential owner lookup) is carefully built. It matches spec v1.2 §4.1–4.3 and is well tested. There is one must-fix: the destination_ambiguous fail-closed check can miss a duplicate (port, pathPrefix) when another prefix of the same length sorts between the two copies. There is also one suggestion: when egress is enabled, refuse at boot if the store would fall back to kubernetes.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane src + tests), OpenAPI
Agent/IDE config (.claude/.vscode): none
Commits: 5 commits (702762a..1f89321, on top of #627 @ caf45b1), all signed-off: yes
CI status: only DCO (pass) and k8s-kind-e2e (pending) ran. ci.yml triggers only on PRs to main, so the unit/typecheck suite has not run on this stacked head. Please get it run once the base becomes main.
Checked and fine: constant-time bearer comparison across all hosts with no early return; 404 sandbox_not_found used for unknown, terminated and other-host sandboxes alike; owner re-enrollment checked on every lookup; header refusal list and CR/LF/NUL refusal; secret-free errors and audit (names only); boot-time refusals in egress-config.ts (duplicate worker/token, TTL range); the harness profile's route table unchanged.
| elements.sort( | ||
| (x, y) => | ||
| x.port - y.port || | ||
| y.pathPrefix.length - x.pathPrefix.length || |
There was a problem hiding this comment.
must-fix — the destination_ambiguous check only compares adjacent elements, but the sort only groups equal (port, pathPrefix) pairs together when no other prefix of the same length sorts between them. The name tiebreak can split them apart.
Repro with this exact comparator: elements a:/aa, b:/bb, c:/aa (all port 443) sort to a/aa, b/bb, c/aa. The adjacent-pair loop sees no duplicate, so both /aa credentials are returned and moca-egress resolves the tie by order. Spec §4.2 step 3 / MI1 §6.3 item 4 says this must never happen. The state can be reached through the PUT list→put race the spec calls out. The test at egress-handlers.test.ts:251 only covers the two-element case, so it passes.
Fix: tiebreak on the prefix string before the name, so equal pairs are always adjacent:
x.port - y.port ||
y.pathPrefix.length - x.pathPrefix.length ||
(x.pathPrefix < y.pathPrefix ? -1 : x.pathPrefix > y.pathPrefix ? 1 : 0) ||
(x.name < y.name ? -1 : x.name > y.name ? 1 : 0)You could also check with a Set of `${port} ${pathPrefix}` keys. Please add a three-element test with an interleaved same-length prefix.
There was a problem hiding this comment.
Fixed in dc18f98.
- Detection no longer depends on the sort order. It uses a
Setkeyed on`${port} ${pathPrefix}`. - The sort is now fully deterministic: port, then prefix length descending, then the prefix string, then the name.
- The new three-element test seeds
a:/aa,b:/bb,c:/aaand expectsdestination_ambiguous. It failed on the old code. The two-element test is kept.
| credentials: sandboxProfile ? new UnavailableCredentialStore() : credentialStoreFromEnv(env), | ||
| // The sandbox profile stores credentials only when egress is configured (SBX0.2b). | ||
| credentials: | ||
| sandboxProfile && !config.sandbox?.egress |
There was a problem hiding this comment.
suggestion — when egress is on, this calls credentialStoreFromEnv(env), which defaults to SH_CREDENTIAL_STORE=kubernetes. The ocp-sbx overlay deletes SH_CREDENTIAL_STORE, and the sandbox control plane has no Kubernetes API access (spec E5, automountServiceAccountToken: false). So a deployment that sets SH_EGRESS_HOSTS + KEK but forgets the store switch boots healthy, then fails every /v1/credentials call and every lookup at runtime. The rest of this feature refuses bad config at boot, so do the same here: on the sandbox profile, refuse kubernetes (or an unset store) when egress is configured, and name SH_CREDENTIAL_STORE=file|vault. Add a test next to sandbox-config.test.ts "wires the real credential store".
There was a problem hiding this comment.
Fixed in dc18f98. On the sandbox profile with egress configured, boot now fails when SH_CREDENTIAL_STORE is unset, empty or kubernetes, with the message SH_CREDENTIAL_STORE must be file or vault on the sandbox profile with egress credentials (it has no Kubernetes API access).
It cannot fire on the harness profile, or with egress off. Tests beside "wires the real credential store" cover:
- unset, empty and
kubernetesare refused; fileandvaultare accepted.
The vault case only asserts that the refusal doesn't fire. No Vault call is made.
| export const staticResolver: EgressResolver = async (owner, d, deps) => { | ||
| const stored = await deps.credentials.get(owner, d.name); | ||
| // Deleted between the list and this read: the owner has no such credential any more. | ||
| if (!stored) throw new CpError('no_credential', 'no credential for this destination'); |
There was a problem hiding this comment.
nit — if a credential is deleted between list and this get, the whole lookup throws no_credential, even when the owner has other matching elements for the host. It also skips the egress_credential_none audit that the handler's own none() path writes. Consider omitting the element (the CONTRACT comment above already allows "omit") and letting the handler's empty-set path decide. Related: a credential with two entries for one host is decrypted once per element, so you could memoize per name within one lookup.
There was a problem hiding this comment.
Both done in dc18f98.
- Omit instead of fail.
staticResolvernow returnsnull(omit) whengetfinds nothing, and the CONTRACT comment is updated. The handler skips omitted elements, so they never appear on the wire asnull. If nothing is left, the handler takes its own empty-set path, which writes theegress_credential_noneaudit. - Decrypt once. A per-lookup
Map, local to the handler with no module-level cache, decrypts each credential name once. - Tests:
- the survivor is returned when one credential is deleted mid-flight;
- all deleted gives
no_credentialplus the none audit; - a single
getis made for one credential with two entries for the host.
caf45b1 to
86d8691
Compare
1f89321 to
45bf12f
Compare
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Re-reviewed at 45bf12f. This is a pure rebase onto #627's new head 86d8691: git range-diff shows all 5 commits (c1a2153, 283d45e, 1d6fd67, fb4b203, 45bf12f) identical (=) to 702762a..1f89321. Nothing in the control-plane changed, and the three review threads have no replies yet. All items from the 1f89321 review are still open:
- must-fix
packages/control-plane/src/egress-handlers.ts:88. Thedestination_ambiguouscheck compares only adjacent elements after a port → prefix-length → name sort, soa:/aa, b:/bb, c:/aaslips past the check. Add a prefix-string tiebreak before the name (or check with a Set keyed onport pathPrefix), plus a three-element test. - suggestion
packages/control-plane/src/main.ts:388. With egress on, the store defaults tokubernetes, which is unreachable on the sandbox profile (E5). Refuse it at boot and nameSH_CREDENTIAL_STORE=file|vault. - nit
packages/control-plane/src/egress-resolver.ts:31. A credential deleted between list and get fails the whole lookup withno_credential. Omit the element instead.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), OpenAPI (incremental: none changed)
Agent/IDE config (.claude/.vscode): none
Commits: 5 commits, all signed-off: yes
CI status: DCO and k8s-kind-e2e pass. ci.yml (unit/typecheck/lint) has not run, because the base is still #627's branch, not main.
…re (SBX0.2b) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ress is enabled Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…nd multi-header bindings Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…8s store with egress; omit mid-flight deletes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
45bf12f to
dc18f98
Compare
|
All three points are addressed in dc18f98, with replies on each thread. A re-review checked each one and found no new breakage. Rebase and CI. This PR is rebased onto Tests. |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Re-reviewed at dc18f98. The PR is now rebased onto main b374519 (#627 merged). git range-diff shows the 5 earlier commits are identical (=). The new commit dc18f98 closes all three items from our 1f89321/45bf12f reviews, and I verified each against the code:
- must-fix (fixed),
egress-handlers.ts.destination_ambiguousdetection now uses aSetkeyed on${port} ${pathPrefix}, so it no longer depends on sort order. The sort is fully deterministic: port, then prefix length descending, then prefix string, then name. The new three-elementa:/aa, b:/bb, c:/aatest covers the interleaved case, and the spec §10 test list is updated to match. - suggestion (fixed),
main.ts. On the sandbox profile with egress configured,depsFromEnvrefuses an unset, empty orkubernetesSH_CREDENTIAL_STOREat boot. Tests cover the refused values andfile/vault. - nit (fixed),
egress-resolver.ts.staticResolverreturnsnullfor a credential deleted mid-flight, and the handler omits that element. If nothing is left, it falls through tonone(), which writes theegress_credential_noneaudit. The issued audit now names only the kept credentials. A per-lookupMapdecrypts each credential once. Tests cover the survivor, all-vanished and single-getcases.
No new issues found in the incremental diff.
CI: ci.yml (unit/typecheck/lint) has not run on this head. The push happened while the base was still feat/623-sbx-host-egress, and ci.yml triggers only on pull_request: branches: [main]. The base change afterwards does not re-trigger it. Please push again, or close/reopen, so the full CI runs before merging. DCO and k8s-kind-e2e pass.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), spec docs (incremental)
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: DCO + k8s-kind-e2e pass; ci.yml not run on this head
Sixteen ADRs still said Proposed although their decisions are in code on main. Each status line now names the merged PRs that implemented it and the date the core landed (format of ADR-0042), and notes what is still owed where only part is built: - 0028 (rossoctl#170, rossoctl#201, rossoctl#340; its KEDA transport removed by ADR-0041) - 0029 (rossoctl#171), 0030 (rossoctl#214), 0031 (rossoctl#214, rossoctl#225) - 0032 (rossoctl#249, rossoctl#350, as amended by MI1) - 0035 (rossoctl#251; ADR-0048 adds lease mode beside it) - 0036 (rossoctl#347), 0038 (rossoctl#458), 0039 (rossoctl#467), 0040 (rossoctl#481) - 0043 (rossoctl#560, rossoctl#588, rossoctl#600, rossoctl#615), 0044 (rossoctl#563), 0045 (rossoctl#620) - 0046 (phase 1: rossoctl#630, rossoctl#641, rossoctl#646; phase 2 owed) - 0047 (M1 and M3: rossoctl#704, rossoctl#713, rossoctl#717, rossoctl#765; M2 owed) - 0048 (rossoctl#706, rossoctl#763, rossoctl#802, rossoctl#808, rossoctl#814; off by default until the security review's lease sections are signed off) The README index follows, and its 0033 row, which still said Proposed after rossoctl#249 accepted the ADR, is corrected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Stacked on #627. Review only the commits after
caf45b17: 702762a, 86a258f, d0d0118, 4cf3a05 and 1f89321.What
This is chunk 2 of the SBX0.2b plan: the control plane for user-scoped egress credentials (spec
docs/specs/2026-10-26-sbx-egress-credentials-design.mdv1.2, ADR-0046, phase 1). No deployment change: all of it is inert untilSH_EGRESS_HOSTSandSH_CREDENTIAL_KEKare both set. Setting only one of them fails startup.Configuration (
src/egress-config.ts).SH_EGRESS_HOSTSis JSON[{id, workers}].SH_EGRESS_TOKEN_<ID>, read as a systemd/K8s credential file.SH_EGRESS_CREDENTIAL_TTL_SECONDStakes 5–300 and defaults to 60.CredentialStore(the file store on a PVC, with Vault later as configuration only).Routes (
src/routes.ts,server.ts).GET/PUT/DELETE /v1/credentials*are mounted on the sandbox profile only when the feature is on (RouteSpec.requiresEgress). With the feature off, they return the unknown-path 404. On the sandbox profile:sandbox-egressconsumer is accepted;The harness profile is unchanged.
Destinations and bindings (
src/egress-destination.ts,src/egress-binding.ts).host[:port][/prefix], normalized and stored in the existingdestination.hosts.bindingis one binding or a list of 1–4.{field}and{base64(a:b)}.Host,Cookie/Set-Cookie,Proxy-*andX-Moca-*.409 destination_conflict.The lookup (
POST /v1/egress/credential,src/egress-handlers.ts,src/egress-resolver.ts).egresskind: the bearer is compared in constant time against every host's token.404 sandbox_not_found.no_credential.{name, port, pathPrefix, headers[], expiresAt}, sorted by port, then by prefix length descending.staticResolver).ttlSecondsis capped byexpiresAt, with a 5 s floor.egress_credential_issuedandegress_credential_none, and carry names only, never values.New error codes:
no_credential404destination_ambiguous500 (stored state from a write race)destination_conflict409credential_unsafe500docs/api/openapi.yamlis updated (path, schemas, theegresssecurity scheme).Tests
The
@moca/control-planevitest suite has 920 passed. Two suites,refresh-redisandsandbox-redis, need a live Redis and fail the same way at baseline in the local sandbox. CI has Redis.tsc --noEmitis clean.The route-profile and authz enumeration tests cover the off and on route tables. The router tests use real
buildHandler:Other tests cover secret-free errors, audit and logs, the TTL seam, and Vault/file/K8s round-trips of multi-header,
host:8443/adescriptors.Each task had an independent review. The follow-up commit fixed two real defects the reviews surfaced:
Next is chunk 3:
moca-egress(lookup client, cache, interception, conformance cases).🤖 Generated with Claude Code