Skip to content

RC1-2: per-sandbox AuthBridge egress forward-proxy (Hop 2) - #97

Merged
pdettori merged 12 commits into
rossoctl:mainfrom
pdettori:feat/rc1-2-hop2-sandbox-egress
Jul 13, 2026
Merged

pdettori merged 12 commits into
rossoctl:mainfrom
pdettori:feat/rc1-2-hop2-sandbox-egress

Conversation

@pdettori

Copy link
Copy Markdown
Member

RC1-2 — Hop 2: per-sandbox AuthBridge egress forward-proxy

Second hop of the RC1 AuthBridge egress control-plane PoC. Adds AB2, a per-sandbox forward-proxy sidecar on the harness's sandbox→external HTTP egress hop:

  • the sandbox holds only a placeholder credential;
  • AB2 injects the real egress credential (from a mounted secret) on an allowed request;
  • AB2 denies a disallowed MCP tools/call before egress (control before injection);

so a model-influenced workload never holds the real credential and a denied action never reaches injection. Everything is gated behind SH_AUTHBRIDGE (off by default); the flag-off path is byte-for-byte unchanged.

Stacked on #96 (RC1-1). This branch is based on feat/rc1-1-hop1-llm-gateway — it needs RC1-1's SH_AUTHBRIDGE setup wiring and the AuthBridge image fixes. Review/merge after #96; rebase onto main once #96 lands (one trivial expected conflict on the H1-deny probe line in leaf-smoke.sh, touched here to bypass the sandbox proxy).

What's in it

  • deploy/knative/echo-target.yaml + echo-target/ — plain-HTTP echo target reflecting the Authorization header (dev.local/echo-target:rc1).
  • deploy/knative/authbridge/ab2-config.yaml — AB2 forward-proxy ConfigMap; outbound chain mcp-parser → ibac → static-inject; ibac no_intent_policy: deny + unclassified_policy: passthrough; static-inject key_by: host, default Authorization/Bearer inject header; proxy-sidecar mode binds a loopback reverse listener as the config requires.
  • deploy/knative/sandbox-pool-ab2.yaml — SH_AUTHBRIDGE pool variant with the authbridge-ab2 sidecar, HTTP(S)_PROXY (upper- and lower-case) + placeholder egress-cred env, using a baked-tools image (dev.local/sandbox-rc1:rc1).
  • deploy/knative/sandbox.Dockerfile — add curl to the baked sandbox tools.
  • deploy/knative/setup-kind.sh — SH_AUTHBRIDGE wiring: build/load the echo + sandbox images, create ab2-egress-cred, apply echo/ab2-config/pool variant, force pod recreation (the Sandbox controller does not roll pods on CR spec change) and wait for the old pods to be deleted.
  • deploy/knative/leaf-smoke.sh — Hop-2 claims (H2-secret-free / H2-inject / H2-deny) with GET-based readiness + pod spec-env inspection + retry curls (resilient to flaky kubectl exec on single-node kind); the H1-deny probe now bypasses the sandbox proxy so it reaches AB1 directly.
  • packages/knative-server/test/authbridge-manifests.test.ts — AB2 sidecar / echo / chain-order + boot-critical config shape assertions.

Verification

  • Live Kind gate: 16/16 leaf-smoke claims pass with SH_AUTHBRIDGE=1 — H2-secret-free, H2-inject (real cred injected at AB2, reflected by echo, sandbox never held it), H2-deny (ibac deny pre-egress), plus all Hop-1 and standard leaf-session claims.
  • pnpm --filter @sh/knative-server test → green (manifest-shape tests).
  • Flag-off (SH_AUTHBRIDGE unset): all new behavior is gated; the base sandbox-pool.yaml and default paths are unchanged.

Assisted-By: Claude Code

pdettori added 10 commits July 10, 2026 23:05
Add deploy/knative/authbridge/ab1-deployment.yaml — the shared
harness->LLM reverse-proxy gateway for RC1-1 Hop 1. Runs the AuthBridge
authlib INBOUND pipeline (inference-parser -> ibac -> static-inject) in
front of https://api.anthropic.com, using the static-policy ibac gate
(no_intent_policy: allow, judge_inference: true) and static-inject keyed
by key_by: static / key: api.anthropic.com (not the inbound Host).
Inert by default: applied only when SH_AUTHBRIDGE=1, not wired into any
kustomization base.

Add an 'AB1 manifest' describe block to authbridge-manifests.test.ts
asserting the Deployment/Service/ConfigMap shape, the container image,
and the embedded config's inbound plugin chain order and static-inject
key config.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Adds deploy/knative/authbridge/harness-egress-ab1.yaml, a SH_AUTHBRIDGE=1-only
tightened egress NetworkPolicy (same name serverless-harness-egress, applied
by task 1g on the RC1 path to overwrite the base policy at apply time). It
replaces the base's external 0.0.0.0/0:443 rule with an AB1-scoped rule
(podSelector app=authbridge-ab1, TCP 8080) and keeps only the 6443 apiserver
port (drops 443), realizing Z2's 'harness reaches only AB1'.

The base deploy/knative/harness-egress-policy.yaml is left byte-for-byte
unchanged so the flag-off default keeps its existing external-LLM egress on
an enforcing CNI (OCP).

Adds a manifest-shape test describe block asserting: single NetworkPolicy
named serverless-harness-egress, same podSelector/policyTypes as the base,
an AB1 egress rule on TCP 8080, DNS (53) and apiserver (6443) rules present,
and explicitly no rule combining ipBlock 0.0.0.0/0 with port 443.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…-1 claims

- setup-kind.sh (1g): under SH_AUTHBRIDGE=1, require a real ANTHROPIC_API_KEY, create
  ab1-llm-cred (real key, keyed api.anthropic.com) and llm-credentials (AB1-PLACEHOLDER,
  base-url=http://authbridge-ab1:8080) so the harness pod is secret-free, then apply
  ibac-stub.yaml + authbridge/ab1-deployment.yaml + the tightened
  authbridge/harness-egress-ab1.yaml (overwrites the base NetworkPolicy by name) and wait
  for both Deployments to roll out. Flag-off path runs the original step-8 logic unchanged
  inside an else branch.
- leaf-smoke.sh (1f): under SH_AUTHBRIDGE=1, add three gated claims after Setup and before
  Claim 2 — H1-secret-free (harness env holds only the AB1 placeholder + base URL, no
  sk-ant-/sk-* leak), H1-allow (a leaf only completes if AB1 injected the real key), and
  H1-deny (flip AB1's no_intent_policy to deny, prove the leaf fails and AB1 rejects before
  injecting via its logs, then unconditionally revert to allow so Claims 2-8 run in allow
  mode). Entirely new block; no existing lines touched.

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]>
Add || true to the H1-deny probe dispatch so a curl timeout / connection
drop under set -euo pipefail cannot abort the script before the
unconditional ab1_set_policy allow revert, which would otherwise strand
AB1 in no_intent_policy:deny for the rest of this and future runs.

Also bail out of ab1_set_policy with return 1 (logging a warning) when the
ConfigMap read comes back empty, so a transient empty $cur can no longer
overwrite config.yaml with empty content and break AB1 after restart. Both
ab1_set_policy call sites gain || true so the new return-1 path cannot
itself abort the script under set -e.

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]>
…pefail)

The H1-deny claim never actually flipped AB1 to no_intent_policy: deny:
its ConfigMap read used an invalid jsonpath ({.data["config.yaml"]}),
returning empty so ab1_set_policy bailed. Also make the deny check robust:
prove deny-before-inject via a direct 403 probe (a leaf dispatch raced the
AB1 restart via harness connection pooling), poll with a longer wget timeout,
and neutralize wget's non-zero exit so pipefail doesn't drop a matched 403.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ne 403 match)

Whole-branch review nits: the H1-deny comment said 'outbound chain' (the
chain is under pipeline.inbound); and the deny probe matched the bare
substring '403' — tighten to the SSE status line 'HTTP/x 403' to avoid a
false positive from e.g. a Content-Length containing 403.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…d SH_AUTHBRIDGE

Add AB2, a per-sandbox forward-proxy sidecar that injects the real egress
credential (the sandbox holds only a placeholder) and denies disallowed
actions before egress, on the harness's sandbox to external HTTP hop. Gated
behind SH_AUTHBRIDGE (off by default; the flag-off path is unchanged).

- echo-target.yaml + echo-target/ (Dockerfile, echo.js): plain-HTTP echo
  target that reflects the Authorization header (dev.local/echo-target:rc1).
- authbridge/ab2-config.yaml: AB2 forward-proxy ConfigMap; outbound chain
  mcp-parser then ibac then static-inject; ibac no_intent_policy: deny +
  unclassified_policy: passthrough (deny-before-inject); static-inject
  key_by: host, default Authorization/Bearer inject_header; proxy-sidecar
  mode also binds a loopback reverse listener as the config requires.
- sandbox-pool-ab2.yaml: SH_AUTHBRIDGE variant of the pool with the
  authbridge-ab2 sidecar, HTTP(S)_PROXY (upper- and lower-case) + placeholder
  egress-cred env, using a baked tools image (dev.local/sandbox-rc1:rc1) so
  tools are present at start (no apk-at-startup race, no apk-through-proxy).
- sandbox.Dockerfile: add curl to the baked sandbox tools.
- setup-kind.sh: SH_AUTHBRIDGE wiring - build/load the echo and sandbox
  images, create the ab2-egress-cred secret, apply echo/ab2-config/pool
  variant, then force pod recreation and wait for the old pods to be deleted
  (the Sandbox controller does not roll pods on CR spec change).
- leaf-smoke.sh: Hop-2 claims (H2-secret-free/inject/deny), run before the
  Hop-1 block, using GET-based readiness + pod spec-env inspection + retry
  curls to be resilient to flaky kubectl exec; the H1-deny probe now bypasses
  the sandbox proxy so it reaches AB1 directly.
- authbridge-manifests.test.ts: AB2 sidecar, echo, and outbound chain-order
  shape assertions.

Live Kind gate: 16/16 leaf-smoke claims pass with SH_AUTHBRIDGE=1 (H2
secret-free + real-cred injection at AB2 + deny-before-egress, plus Hop-1 and
the standard leaf-session claims).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…roxy addrs)

The RC1-2 AB2 forward-proxy live gate is not in CI, so authbridge-manifests.test.ts
is the only automated guard on the AB2 config. Assert the top-level fields whose
absence would prevent proxy-sidecar boot (mode, listener.forward_proxy_addr,
reverse_proxy_addr, reverse_proxy_backend), addressing the final-review I1 finding.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Comment thread deploy/knative/echo-target/echo.js Fixed
Comment thread deploy/knative/echo-target/echo.js Fixed
…-injection)

Strip CR/LF from req.method/req.url/Authorization before logging in the RC1-2
echo target so a crafted request cannot forge or split log lines. Addresses the
CodeQL js/log-injection alerts (rossoctl#32/rossoctl#33) on PR rossoctl#97. The reflected JSON response
is unchanged (already safe via JSON.stringify), so the Hop-2 smoke assertions
(which read the response body, not the log) are unaffected.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori

Copy link
Copy Markdown
Member Author

Addressed the CodeQL log-injection alerts (#32/#33) on deploy/knative/echo-target/echo.js in commit 2b076b7: client-controlled values (req.method/req.url/Authorization) are now stripped of CR/LF via a logSafe() helper before being logged, so a crafted request can't forge or split log lines. The reflected JSON response is unchanged (already safe via JSON.stringify), so the Hop-2 smoke assertions — which read the response body, not the log — are unaffected. CodeQL will re-scan on this push.

Assisted-By: Claude Code

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Author's own PR — GitHub won't allow a formal APPROVE; posting as a comment review. Assessment: would-approve.)

Clean, well-documented Hop-2 addition to the RC1 AuthBridge egress PoC. The security-critical invariant holds in the manifests: the real egress credential lives only in ab2-egress-cred, mounted read-only into the authbridge-ab2 sidecar; the sandbox container mounts only workspace and carries ECHO_CRED=PLACEHOLDER-TOKEN, so it never holds the real cred. Everything is gated behind SH_AUTHBRIDGE (off by default), the flag-off path is untouched, and the CodeQL log-injection fix in echo.js is correct. Live gate reports 16/16 and all CI is green.

Two non-blocking notes inline (1 nit, 1 suggestion). Note this PR is stacked on #96 (diff vs main includes RC1-1 files) — review/merge after #96 and rebase.

Assisted-By: Claude Code

Comment thread deploy/knative/echo-target/Dockerfile Resolved
Comment thread deploy/knative/sandbox-pool-ab2.yaml Resolved
…RC1-2 review nits)

Addresses two review nits on rossoctl#97:
- echo-target/Dockerfile: add USER node so the echo target actually runs as the
  non-root uid-1000 user (matches echo.js's note; it binds :8080, no root needed).
- sandbox-pool-ab2.yaml: document that NO_PROXY="" routes ALL sandbox egress
  through AB2, so any future direct in-cluster egress (redis, apiserver) would be
  hijacked by the host-keyed static-inject and fail-closed unless added to NO_PROXY
  (the reason the H1-deny probe clears the proxy vars).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit 8f85a8b into rossoctl:main Jul 13, 2026
10 checks passed
@pdettori
pdettori deleted the feat/rc1-2-hop2-sandbox-egress branch July 13, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants