Skip to content

fix: 🥅 Audit leaf_unavailable as 503 - #991

Merged
evaline-ju merged 2 commits into
rossoctl:mainfrom
evaline-ju:leaf-unavailable
Nov 23, 2026
Merged

evaline-ju merged 2 commits into
rossoctl:mainfrom
evaline-ju:leaf-unavailable

Conversation

@evaline-ju

Copy link
Copy Markdown
Contributor

Summary

Audit leaf_unavailable as 503 rather than 502: the upstream has already been dialed and verified and the guest's CONNECT answered 200, so the failed certificate mint is the proxy's own refusal, not an upstream fault.

Justification

By the time leaf_unavailable fires, serve has dialed the upstream, verified its certificate, and answered the guest's CONNECT with 200 (intercept.go:82-111). The failure is the proxy's: it can't mint a leaf, for example because its interception CA has expired. 502 means the upstream gave a bad response. The proxy keeps 502 for real upstream faults (upstream_unreachable, upstream_unverified) and uses 503 when it can't do its own part (credential_unavailable), which also clears once the CA is renewed.

The conformance contract said this event's status was recorded "although no HTTP response is sent". That was wrong, since the guest had already received the 200. It now says that a refusal during the TLS handshake is audited with the refusal's own status, as misdirected_request (421) already is. This changes a value the contract documented, but no other implementation exists yet and no conformance case checked it.

No test covered this audit event before. The new one fails on main (502) and passes here. A one-off run of the real binary with an expiring CA showed the same.

Addresses deferred item in #653.

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass.
  • Docs: changed behavior, flags or environment variables are reflected in the relevant README or
    docs/ page, with the right maturity label (see docs/CONTRIBUTING-DOCS.md).
  • Docs: make check-links passes if any Markdown changed.
  • A new spec or ADR is registered in docs/specs/README.md or docs/adrs/README.md. - N/A

@evaline-ju
evaline-ju requested a review from pdettori as a code owner November 23, 2026 16:31
@evaline-ju evaline-ju added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 23, 2026

@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

The change is correct and its justification holds against the code. In serve, the upstream is dialled and its certificate verified, and the CONNECT 200 is written (intercept.go:82-111), before GetCertificate calls ic.ca.Leaf; so a mint failure at that point is the proxy's own refusal, not an upstream fault — 503 rather than 502 is the right classification, and it matches credential_unavailable's semantics. The contract and the design doc are updated consistently: the status field now documents handshake-time refusals alongside misdirected_request 421, and the design-doc failure table gains a matching row. leaf_unavailable appears in only three files (internal/egress/audit.go, egress/conformance/doc.go, the MI1 spec), and no conformance case, dashboard or config pinned the old 502, so the blast radius of the value change is nil. One nit inline; nothing blocking.

Author: evaline-ju (CONTRIBUTOR — returning external)
Areas reviewed: Go (egress interceptor, tests), conformance contract doc, MI1 design spec
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (19/19)

Verified on head 2e04b2f in a worktree: go build ./..., go vet ./internal/egress/... ./egress/... and gofmt -l clean; go test ./internal/egress/ ok (48.7s); the new test also passes 5x under -race. Positive control: the test hunk applied alone to origin/main (de6c9b5) fails exactly as the PR body says, emitting Status:502 ... Decision:leaf_unavailable.

Signed-off-by: Evaline Ju <[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.

Review at 3ca903825b9e5a3f1edc8e2d5c74684c14cff478.

The reclassification is right, and the reasoning in the description checks out against the head source. By the time GetCertificate calls ic.ca.Leaf, serve has dialled the upstream, completed the upstream TLS handshake, and written the CONNECT 200, so a failed mint is the proxy's own refusal — the same class as credential_unavailable, which is already 503. Real upstream faults stay 502 (upstream_unreachable, upstream_unverified).

The conformance doc fix closes a real contradiction: status was "the HTTP status the guest was answered with", which cannot be true for an event that also said "no HTTP response is sent". The new wording aligns leaf_unavailable with misdirected_request (421), the existing precedent for auditing a status after the CONNECT 200. I checked conformance/cases.go — no case pinned the old 502 — so nothing else needed updating.

The new test is the first coverage for this event and fails on main (502) while passing here. It is not vacuous: newTestCA gives the interception CA a 48 h window and the injected clock is set past that CA's own NotAfter, so Leaf really errors; open() has already read the CONNECT 200 before the handshake; and e.up.count() counts recorded requests, so == 0 genuinely means no request reached the upstream even though the proxy dialled and handshook it first.

3ca90382 ("Expire CA in test") closes the nit from the 2e04b2f review. The coupling to newTestCA's window is gone: the clock is now set from e.guestCA.cert.NotAfter instead of a hard-coded 49 * time.Hour, so a change to that helper's window can no longer invalidate the test. I checked that pinning to exactly NotAfter still exercises expiry — Leaf rejects with !now.Before(ca.cert.NotAfter) (leafca.go:105), so the boundary instant counts as expired. That is a different route from the newTestCAWindow suggestion earlier in the thread, and it works without adding a CA-window field to icOpts.

No inline comments.

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: Go (remote-worker/internal/egress/intercept.go, intercept_test.go), conformance package docs, spec docs
Agent/IDE config (.claude/.vscode): none
Commits: 2, both signed off (DCO green)
CI status: all checks green at 2e04b2f; at 3ca90382 they were still queued when this review was posted.

Not run here: the Go test suite (modules not built in this checkout).

@evaline-ju
evaline-ju merged commit cbccf32 into rossoctl:main Nov 23, 2026
18 checks passed
@evaline-ju
evaline-ju deleted the leaf-unavailable branch November 23, 2026 17:33
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.

3 participants