Repository navigation
fix(egress): SBX0.2b egress-credential follow-ups - #870
Merged
Merged
Conversation
CPCredentials stamped a cache entry's expiry with the time the control plane's answer arrived. The server's ttlSeconds starts when it answered, which is after the request left, so a slow lookup let the entry outlive the server's TTL by the call's duration, up to the client timeout. fly now reads the clock before the call and counts the TTL from there, which can only end an entry early. TestTTLMeasuredFromRequestStart advances the fake clock inside the fake control plane to stand in for a slow call and fails without the fix. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…le clock icConn.refuse set a drainTimeout write deadline on the guest TLS and then wrote the refusal through it. The guest TLS runs over an idleConn, whose every Write refreshes the idle clock, so the write's own refresh replaced the one-second drain deadline with the idle one: a guest that stopped reading held the conn, and its per-VM slot, for the whole idle bound. The idle clock gains stop(), which makes later touches no-ops, and refuse stops it before setting its deadlines; nothing on a conn being refused is live any more. Two tls.Conn close_notify writes would still each take up to the standard library's own five seconds against such a guest, so a refusal the guest did not take closes the socket at once, and the drain timer is armed before CloseWrite so the close_notify falls inside the drain bound. TestInterceptRefuseWriteBoundedByDrainTimeout runs a refusal over a net.Pipe whose guest never reads; without the fix refuse is still blocked after five seconds, with it it returns after one. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…event Two gaps in the public conformance suite's audit handling. redactEvent, which keeps credentials out of the suite's failure messages, looked at top-level keys and strings only. An implementation may emit nested objects or arrays (a header map, a list of attempts), and an authorization key or a Bearer string inside one printed as is. It now walks objects and arrays; TestRedactEventIsDeep fails without that. The audit contract says sub is present on credential_injected events and absent or "" on every other, but only one case (the forged-headers one) checked the second half. harness.next now checks it on every event a case reads, the way wait already checks via. Mutation-checked: making the proxy stamp a subject on every event fails 42 subtests with "a tunnel event carries sub ...". Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…egress-ca file validate_egress_ca parses the certificate with openssl and discards its stderr, so on a build host without openssl a good certificate was refused as "not a parseable X.509 certificate", pointing the operator at the wrong problem. The tool is now checked first, with its own message. The new build-snapshot.test.sh case runs validate_egress_ca with a PATH that has grep but no openssl; on main it reports the certificate unparseable. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
POST /v1/egress/credential audited the two answers it gives most often, egress_credential_issued and egress_credential_none, but not its two 500s: credential_unsafe (a stored value that cannot render) and destination_ambiguous (two credentials on one port and prefix, reachable only by a write race). Both mean a sandbox's request went out without the credential its owner stored, and the audit could not say why. Both are now audited as egress_credential_refused, with the error code as reason and the credential names involved (never a value), then thrown unchanged. Other resolver failures, such as the store being down, are not a credential's doing and still pass through unaudited. The spec's §4.2 audit item says so. Two new egress-handlers tests fail without the change; the unsafe one also checks that the stored value is not in any log line. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
install_egress renders the moca-egress unit into a mktemp file, compares it with the installed unit and installs it. Under `set -e` a failing render or install ended the script between the mktemp and the rm, leaving the temp file behind on every failed run. Both steps now remove it before dying, and the render failure says which file is missing. ca_fingerprint's hash step gets the same treatment. The new install-host.test.sh case runs a script copy whose unit source is missing, with mktemp shimmed into one directory (macOS's ignores TMPDIR without a template). On main it fails with "a failed egress install left its temp file". Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
uninstall_egress_credentials and remove_egress delete, as root, every path
an `egress credential` manifest line names. The manifest is a file under
SBX_ENV_DIR, not proof that a path is this script's, so an edited or
corrupted line could delete any file on the host. remove_credential_file
now removes only the drop-in and files directly in the credential
directory; anything else is kept and named ("kept PATH (not a credential
file of this script)"), and its line stays.
The new install-host.test.sh case plants three such lines (a path outside
the directory, one below it, one through `..`); on main --uninstall-egress
deletes all three.
Part of rossoctl#653
Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
…old one The --egress tests re-ran with the same token only. A rotated token (or a host re-listed by setup.sh) is the re-run that matters: the token file must hold the new token alone, stay 0600 and be recorded once, moca-egress must be restarted to read it, the new token must not reach a unit file, the output or a command line, and the CA must survive. Test-only; it passes on main. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…nsumer refusal's text egressConfigFromEnv: a TTL that Number() alone would take (a unit suffix, a fraction, an exponent, hex, a sign) and an uppercase-hex host token are refused; a multi-entry KEK ring (what a rotation leaves) is accepted, and a ring with one bad entry is refused naming that entry. Mutation-checked: parsing the TTL with Number() and matching tokens case-insensitively fail five of the new cases. resolveInferenceName's refusal of a named non-inference credential was checked by code only; its text, which the user sees, is now pinned too. Test-only. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…ield=value stdin Three paths of `mocactl sbx credentials add` had no test: a comma-separated --host (split and trimmed, across repeated flags), a non-preset multi-field kind read as field=value lines from stdin (a value may itself hold "=", and a missing field is a usage error before any request), and the --json output (one object on stdout, never the secret). Mutation-checked: dropping the comma split fails the first. Test-only. Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
…gged as removed An `egress credential <dir>/` manifest line (the directory itself) passed the path check: nothing was deleted, but the log said removed and the line was forgotten (review nit). Part of rossoctl#653 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
approved these changes
Nov 17, 2026
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review at e6d34b1
This PR takes 11 small follow-ups from #653. Checked statically:
refusealways ends the conn, so stopping the shared idle clock can't stall live traffic, and the earlypc.c.Close()is safe next to the idempotent releases.- Counting the TTL from
startonly shortens a cache entry. reasonalready exists on the audit entry, andrefusedrethrows the original error unchanged.- Every version of
install-host.shon main records only the drop-in and files directly in the credential directory, so the tighterremove_credential_filekeeps nothing an older install wrote. - The strict
subcheck matches the reference proxy on every path conformance reaches today. The intercepted upstream-failure case is still open in #653, as the PR body says. - The spec §4.2 text matches the code.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (egress, conformance), TypeScript (control-plane, mocactl tests), Shell (install-host.sh, build-snapshot.sh, tests), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 11 commits, all signed-off: yes
CI status: all checks passing at submit time except deploy-scripts-bash32 (macOS), still pending
nit: 7 of 11 commit subjects are over 72 characters (e.g. test(control-plane): cover the egress settings' edge cases and the consumer refusal's text, 90). Advisory only.
Drafted by an AI reviewer and approved by a human before posting.
12 of 16 tasks
2 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #653
The issue's small, self-contained follow-ups, one commit each. The first section ("test gaps that hide real checks") was done by #655 and #669. What is left after this PR needs a decision or is a larger piece of work; it is listed under "Out of scope" with the reason.
What changed and why
Proxy (
remote-worker/internal/egress)cpcreds.go,fly). The expiry used to be stamped when the control plane's answer arrived. The server'sttlSecondsstarts when it answered, which is after the request left, so a slow lookup let an entry outlive the server's TTL by the length of the call, up to the client timeout. Counting from the start can only end an entry early.drainTimeout, not the idle clock (intercept.go,icConn.refuse;deadline.go). The guest TLS runs over anidleConn, whose everyWriterefreshes the idle clock. So the refusal write's own refresh replaced the one-second drain deadline with the idle one, and a guest that stopped reading held the conn, and its per-VM slot, for the whole idle bound.idleClockgainsstop(), which turns later refreshes into no-ops, andrefusestops it first.tls.Conn's close_notify writes set their own five-second deadline, so two more changes keep that out too: a refusal the guest did not take closes the socket at once, and the drain timer is armed beforeCloseWrite.Conformance suite (
remote-worker/egress/conformance)redactEventis deep. It used to look only at top-level keys and strings, so anauthorizationkey or aBearerstring inside a nested object or array was printed in a failure message.subrule is checked on every event a case reads. The contract is thatsubis present oncredential_injectedevents and absent or""on every other. Only one case checked the second half;harness.nextnow checks it, the waywaitalready checksvia.doc.gosays so.Control plane
egress-handlers.ts).credential_unsafeanddestination_ambiguousare now written asegress_credential_refused, with the error code asreasonand the credential names involved (never a value). Before, onlyissuedandnonewere audited. Other resolver failures (the store being down, for example) still pass through unaudited. The spec's §4.2 audit item is updated.Deploy
build-snapshot.sh --egress-casays when openssl is missing. Without openssl, a good certificate was refused as "not a parseable X.509 certificate".install-host.sh:install_egressremoves its temp file on every failure. Underset -e, a failing render or install of the unit exited between themktempand therm. The render failure now also names the missing unit source.install-host.shremoves only its own credential files.--uninstall-egressand the last worker's uninstall deleted, as root, every path that anegress credentialmanifest line named. Now only the drop-in and the files directly in the credential directory are removed; any other path is kept, and the log names it.Coverage (test-only)
install-host.test.sh: an--egressre-run with a new token (replaced, 0600, recorded once, moca-egress restarted, no leak, CA kept).egress-config.test.ts: TTLs thatNumber()alone would accept (60s,60.5,6e1,0x3c,+60), an uppercase-hex token, and a multi-entry KEK ring (accepted, and refused when one entry is bad).credential-store.test.ts: the text of the consumer refusal (credential 'gh' has consumer 'sandbox-egress', not 'inference').sbx-credentials.test.ts(mocactl):add --jsonshape,--host a,bsplitting and trimming, and a non-presetbasicread asfield=valuelines from stdin.An empty credential name (
egress credential <dir>/, the directory itself) is now kept and named, not logged as removed with its line forgotten; a test pins it and fails without the fix.Validation
Each fix has a test that fails without it (the fix reverted, the test kept) and passes with it:
TestTTLMeasuredFromRequestStart(cpcreds_test.go)calls = 1, want 2: the entry outlived the server's TTL by the call's durationTestInterceptRefuseWriteBoundedByDrainTimeout(abort_test.go), a refusal over anet.Pipewhose guest never readsrefuse still blocked after 5.001s: the idle refresh overrode the drain deadline(with only thestop()call removed, it also fails: the close_notify writes alone hold it about 7 s)-count=3TestRedactEventIsDeep(redact_test.go)subcheck inharness.next, mutation: the proxy stamps a subject on every eventa tunnel event carries sub ...egress-handlers.test.ts: twoaudits a ... refusalcasesexpected [] to deep equally contain ObjectContaining{…}(both)build-snapshot.test.sh:no openssl: ...the refusal names the missing tool (want '1', got '0'),the good certificate is not called unparseable (want '0', got '1')PASSinstall-host.test.sh: failed egress installFAIL: a failed egress install left its temp file: tmp.…install-host.test.sh: foreign credential linesFAIL: --uninstall-egress deleted …/cred-outside/precious, which is not a file of …/etc/egressThe coverage tests pass on main, which is expected. Where it applies, they were mutation-checked: parsing the TTL with
Number()and matching tokens case-insensitively fail five of the newegress-configcases, and dropping the--hostcomma split fails the splitting case.Suites run:
remote-worker:go vet ./...clean;go test -race ./internal/egress/... ./egress/...ok (the conformance suite runs in-process and against the built binary).packages/control-plane:tsc --noEmitclean;vitest run80 files, 1947 passed, 3 skipped.packages/mocactl:sbx-credentials.test.ts23/23. The full suite had timing failures (Test timed out in 5000ms, inapp.test.tsx,sbx-push.test.ts,sbx-doctor.test.tsand others) on a heavily loaded machine. This PR changes no mocactl source, only that one test file.packages/server: not affected (no server or harness file, and no environment variable name, changes here).deploy/sbx/tests/install-host.test.shanddeploy/microvm/tests/build-snapshot.test.shexit 0;shellcheck -x -S warningis clean on every changed script.python3 scripts/check-doc-links.py: 0 broken links.Out of scope
Each remaining point of #653, with its state on main:
NewCPCredentialsrefuses userinfo, a query, a fragment and a path, pinned byTestNewCPCredentialsURLRefusals). Spec §8 already says that aSet-Cookieminted from the injected token reaches the guest, anddocs/sbx/security-review.mdlists it as an accepted risk. A credential deleted mid-flight is audited (egress_credential_nonewhen none is left, pinned byanswers no_credential, audited, when the only credential vanishes mid-flight; a partial delete issues the survivors under their own names). The vault store's array-binding round trip is covered (vault-store.test.ts,round-trips a multi-binding ... descriptor unchanged).remove_egressalready leaves an unknownegress <kind>line and its file alone (*) continue).leaf_unavailableaudited with status 502 although no HTTP response is sent. The issue asks whether to keep it. It is documented inconformance/doc.go.setup.sh). By design, an off run leavessbx-egressalone so the KEK survives. Revoking the tokens on an off run would mean every host's bundle must be copied again when the feature is turned back on. While the feature is off, the control plane does not read the tokens.--uninstall-egress(and log "kept" again). The CA is kept on purpose, because snapshots carry it, and its line is the record that this script owns it. Dropping the line would orphan the file.subcheck: when an injected request's upstream fails,icConn.exchangerefuses with the injection's event, so theupstream_unreachableevent keepssub(and, on purpose,credential). The contract sayssubappears only oncredential_injected. No conformance case reaches this path today. Either the contract should allowsubon a refusal that carried a token, or the refusal should clear it. This PR changes neither.wait_egress_readychecks only that the socket exists. The unit isType=notify, so a successful start already means the socket is bound. A connect probe would need a tool (socat, python) the host may not have.Every commit is signed off (DCO).
Assisted-By: Claude Code