Skip to content

SBX0.2b egress credentials: deferred follow-ups #653

Open

Description

@pdettori

Follow-ups deferred during the SBX0.2b user-scoped egress credentials work (#624 spec, #627, #630, #641, #646). The full ledger is in the rulings comment on #646: #646 (comment)

Test gaps that hide real checks (do first)

  • deploy/sbx/tests/smoke.test.sh: LOGS_KEPT is undefined, so the "PAT never in logs" assertion never runs. Also has a no-op || true assertion. (Test: revive two step-7 assertions in the sbx smoke that could not fail #655)
  • smoke step 7: drop_branch reports success on a 404; a failed add triggers a spurious delete; the fixed credential name smoke-gh can collide between concurrent runs.

Spec / audit

  • Spec §8/§11: say that an upstream Set-Cookie minted from the injected token reaches the guest (a derived credential). This is inherent to any endpoint that derives a credential from the token.
  • Control plane: no audit line for the 500 outcomes (credential_unsafe, destination_ambiguous) or a mid-flight delete. Only issued and none are logged today.
  • moca-egress: leaf_unavailable is audited with status 502 although no HTTP response is sent. This is documented in doc.go; decide whether to keep it.

Deploy

  • setup.sh: stale host tokens for hosts dropped while the feature is off persist until the next on-run.
  • install-host.sh: CA manifest lines persist after --uninstall-egress (re-logged "kept"); wait_egress_ready checks only that the socket exists; credential paths are removed without a directory check; no re-run test with a new token.
  • install-host.sh: a mktemp leak on install failure; remove_egress drops unknown egress <kind> manifest lines.
  • build-snapshot.sh: the openssl-missing message is misleading.

Proxy

  • CPCredentials: cache expiry is measured from fetch end, not request start, so an entry can live up to ~timeout longer than the server TTL. MOCA_EGRESS_CREDENTIALS_URL accepts userinfo, query and path. Eviction does a full scan under the mutex.
  • Interceptor: refuse()'s drain write deadline is overridden by the idle touch.
  • Conformance: redactEvent is shallow; no assertion that sub is absent on non-injection events.

Coverage

  • control-plane: egress-config cases (non-numeric TTL, uppercase-hex token, multi-entry KEK ring); a test that the consumer-refusal message text matches; the vault-store array-binding round trip.
  • mocactl: add --json shape, --host a,b splitting, non-preset basic field=value stdin.

Open (not deferred minors)

  • Live acceptance item 3: a second user's sandbox gets a 401 on the first user's private repo and a public clone works. Not run yet; needs a second enrolled user.
  • Vault-backed credential store (phase-1 follow-up to the file store).

Assisted-By: Claude Code

Activity

  1. added this to the v0.11.0 milestone on Nov 17, 2026
  2. evaline-ju commented on Nov 18, 2026

    @evaline-ju
    Contributor

    Status after #655, #669 and #870 (checked on main):

    Done: smoke step 7 (#669); the Set-Cookie note (spec, and accepted risk in security-review.md); audit of the 500s (#870) and mid-flight delete; the install-host.sh mktemp leak and unknown manifest lines; the build-snapshot.sh openssl message; the interceptor drain deadline; redactEvent and the sub check; control-plane and mocactl coverage.

    Partly done: CPCredentials (expiry and URL rules done; the full scan on eviction remains, a design change); install-host.sh (directory check and re-run test done).

    Need a decision: leaf_unavailable audited as 502; setup.sh stale tokens while off (kept by design); the CA's manifest lines after uninstall (kept on purpose); wait_egress_ready only checking the socket; and, new from #870, sub on an upstream_unreachable refusal that carried a token.

    Open: live acceptance item 3 (needs a second user). The Vault-backed store is on main (vault-store.ts); standing Vault up is #823.

    Proposing to tick the done boxes.

  3. evaline-ju commented on Nov 19, 2026

    @evaline-ju
    Contributor

    CPCredentials eviction scan: proposing to keep it. It runs only when the cache is full and a
    new key comes in, so at most once per control-plane call. Full means maxCacheEntries = 4096,
    the cache's size limit; the scan's worst case grows with it.

    Measured with a Go benchmark of insertLocked alone, from a test file in
    remote-worker/internal/egress (cpcreds.go as of 94e6df5, unchanged on main), on an
    Apple M1 Max with go1.26.0 (go test ./internal/egress -run '^$' -bench BenchmarkTmp -benchtime 2s). One goroutine, no lock contention:

    Case Setup ns/op
    Full, all live (worst case) 4096 unexpired entries with distinct expiries; each op inserts a new key, so it scans all 4096 and evicts one 92,798 (~93 µs)
    Not full (normal case) each op inserts a new key; the map is reset before it fills 325 (~0.3 µs)

    The worst case needs 4096 distinct (sandbox, host) lookups within their TTL (60 s for "no
    credential"). One way a guest gets there is a wildcard allowlist and a stream of new
    subdomains. In that case each miss is also a control-plane call, which costs more than the
    scan and which a heap would not change.

    Benchmark
    package egress
    
    import (
    	"strconv"
    	"testing"
    	"time"
    )
    
    func BenchmarkTmpInsertFullLive(b *testing.B) {
    	now := time.Unix(0, 0)
    	c := &CPCredentials{now: func() time.Time { return now }, cache: map[cpKey]cpEntry{}}
    	for i := 0; i < maxCacheEntries; i++ {
    		c.insertLocked(cpKey{"s", strconv.Itoa(i)}, cpEntry{expires: now.Add(time.Duration(i+1) * time.Second)})
    	}
    	b.ResetTimer()
    	for i := 0; i < b.N; i++ {
    		c.insertLocked(cpKey{"n", strconv.Itoa(i)}, cpEntry{expires: now.Add(time.Hour)})
    	}
    }
    
    func BenchmarkTmpInsertNotFull(b *testing.B) {
    	now := time.Unix(0, 0)
    	c := &CPCredentials{now: func() time.Time { return now }, cache: map[cpKey]cpEntry{}}
    	b.ResetTimer()
    	for i := 0; i < b.N; i++ {
    		if len(c.cache) >= maxCacheEntries-1 {
    			c.cache = map[cpKey]cpEntry{}
    		}
    		c.insertLocked(cpKey{"n", strconv.Itoa(i)}, cpEntry{expires: now.Add(time.Hour)})
    	}
    }
  4. modified the milestones: v0.11.0, v0.12.0 on Nov 20, 2026
  5. evaline-ju commented on Nov 23, 2026

    @evaline-ju
    Contributor

    @pdettori here's the state of #653 and what needs your sign-off:

    Decided and merged: leaf_unavailable is now audited as 503, not 502 (#991). The upstream is already verified and the CONNECT answered 200 when the mint fails, so the refusal is the proxy's own. The contract text was corrected and a test added.

    Please confirm:

    1. Keep the CPCredentials eviction scan. It runs at most once per control-plane call, costs about 93 µs in the worst case (benchmark above), and is cheaper than the control-plane call that triggers it.
    2. Move live acceptance item 3 to its own issue. It needs a second enrolled user on a live SBX0.
    3. Point the Vault box at Stand up Vault for secret management #823. The code is on main (vault-store.ts), and standing Vault up is tracked there.

    If you agree, I'll tick the boxes and close this issue.

    Assisted-By: Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions