Repository navigation
egress: carry non-HTTP and streaming traffic through the sdsmint MITM leg - #1086
Conversation
b65b844 to
17719da
Compare
Manual test: SSH egressConfirms that SSH — traffic that is neither HTTP nor TLS — reaches the internet Uses the sandbox demo, whose 1. Installhack/install-ate.sh --deploy-ate-system --experimental-use-sdsmint
hack/install-ate.sh --deploy-demo-sandbox
kubectl wait --for=condition=Ready actortemplate/sandbox-template -n ate-demo-sandbox --timeout=5m
2. Create an actorkubectl ate create atespace demo
kubectl ate create actor my-sandbox-1 -a demo --template ate-demo-sandbox/sandbox-template
kubectl ate resume actor my-sandbox-1 -a demo
kubectl port-forward -n ate-system svc/atenet-router 8000:80 &Do not use 3. Helper
ate_run() { # ate_run <actor>.<atespace> <shell command...>
local host="$1"; shift
jq -n --arg cmd "$*" '{command:["sh","-c",$cmd]}' \
| curl -sS -X POST http://localhost:8000/process \
-H "Host: ${host}.actors.resources.substrate.ate.dev" \
-H "Content-Type: application/json" --data-binary @- \
| jq -r '.stdout, .stderr, (if .exitCode != 0 then "[exit \(.exitCode)]" else empty end) | select(. != "")' \
| tr -d '\r'
}A command that fails still returns HTTP 200, so check 4. Install ssh in the actorThe image is plain Alpine: no ate_run my-sandbox-1.demo "sed -i 's|https|http|g' /etc/apk/repositories && apk add --no-cache openssh-client"5. Run SSHCopy in the key you already use for GitHub. Check first that it works and has no ssh -T -o BatchMode=yes -i ~/.ssh/id_ed25519 [email protected] # -> Hi <user>!
ssh-keygen -y -P '' -f ~/.ssh/id_ed25519 >/dev/null && echo "no passphrase"If it is passphrase-protected, strip it from a copy, never the original: cp ~/.ssh/id_ed25519 /tmp/actor-key && ssh-keygen -p -N '' -f /tmp/actor-keyPass it in umask 077
jq -n --rawfile key ~/.ssh/id_ed25519 '{
command:["sh","-c","mkdir -p /root/.ssh && chmod 700 /root/.ssh && printf %s \"$ACTOR_SSH_KEY\" > /root/.ssh/id_ed25519 && chmod 600 /root/.ssh/id_ed25519 && ssh-keygen -lf /root/.ssh/id_ed25519"],
envvars:{ACTOR_SSH_KEY:$key}}' > /tmp/payload.json
curl -sS -X POST http://localhost:8000/process \
-H "Host: my-sandbox-1.demo.actors.resources.substrate.ate.dev" \
-H "Content-Type: application/json" \
--data-binary @/tmp/payload.json | jq -r '.stdout, .stderr'
shred -u /tmp/payload.jsonThe fingerprint it prints must match ate_run my-sandbox-1.demo 'ssh -T -o StrictHostKeyChecking=no [email protected] 2>&1'Exit 1 is the success case — GitHub is refusing a shell, not refusing you. For the transport detail, add ate_run my-sandbox-1.demo 'ssh -vT -o StrictHostKeyChecking=no [email protected] 2>&1' \
| grep -vE 'load_hostkeys|no pubkey|identity file|no identity'The host key must be GitHub's published fingerprint Without a key you get
6. Check the gatewayThe gateway logs two formats on one stream: the CONNECT leg as text, the three kubectl logs -n ate-system deploy/atenet-egress -c envoy --tail=400 \
| jq -Rc 'fromjson? // empty | select(.leg)' | tailSSH must appear as {"leg":"passthrough","sni":null,"upstream":"140.82.113.3:22",
"bytes_rcvd":3022,"bytes_sent":2749,"flags":"-"}
The apk traffic from step 4 should show up as kubectl logs -n ate-system deploy/atenet-egress -c envoy --tail=400 | grep '\[egress\]'7. Clone a repo over SSH
ate_run my-sandbox-1.demo 'apk add --no-cache git && git clone [email protected]:agent-substrate/substrate.git /tmp/sub1 && ls /tmp/sub1 | head'This command has an error You can verify that the clone is successfully: ate_run my-sandbox-1.demo 'ls -alh /tmp/sub1'The gateway shows the same {"leg":"passthrough","upstream":"140.82.114.3:22",
"bytes_rcvd":251238,"bytes_sent":84006017,"duration_ms":7783,"flags":"-"}This is the record that shows the chain carries sustained bulk transfer, not 8. Server-speaks-firstSSH sends its banner first, so it does not exercise the listener-filter timeout. ate_run my-sandbox-1.demo 'sleep 6 | nc -w 8 smtp.gmail.com 25'The The gateway record proves the timeout path was taken: {"leg":"passthrough","upstream":"173.194.206.108:25","bytes_rcvd":0,"bytes_sent":74}
Clean upkubectl ate pause actor my-sandbox-1 -a demo
kubectl ate delete actor my-sandbox-1 -a demo |
960f1e2 to
892ec8b
Compare
Bowei Du (bowei)
left a comment
There was a problem hiding this comment.
Does this change come with tests?
I think the config looks ok
The automatic test coverage is out of scope for this PR, will be a followup. |
Testing gRPC, WebSocket, and SSE egress from a sandbox actor1. SetupStep 0 — an actor called hack/install-ate.sh --deploy-ate-system --experimental-use-sdsmint
hack/install-ate.sh --deploy-demo-sandbox # or hack/install-ate-kind.sh on kind
kubectl wait --for=condition=Ready actortemplate/sandbox-template -n ate-demo-sandbox --timeout=6m
kubectl ate create atespace demo # skip if it already exists
kubectl ate create actor probe -a demo --template ate-demo-sandbox/sandbox-template
kubectl ate resume actor probe -a demo
kubectl port-forward -n ate-system svc/atenet-router 8000:80 &The actor reports curl -sS -X POST http://localhost:8000/process \
-H "Host: probe.demo.actors.resources.substrate.ate.dev" \
-H "Content-Type: application/json" \
-d '{"command":["sh","-c","echo hello"]}'For a longer-lived probe, prefer a template with Then the ate_run() { # ate_run <actor>.<atespace> <shell command...>
local host="$1"; shift
local resp
resp=$(jq -n --arg cmd "$*" '{command:["sh","-c",$cmd]}' \
| curl -sS -m 300 -X POST http://localhost:8000/process \
-H "Host: ${host}.actors.resources.substrate.ate.dev" \
-H "Content-Type: application/json" --data-binary @-)
if ! printf '%s' "$resp" | jq -e . >/dev/null 2>&1; then
printf 'not JSON, so this never reached the actor: %s\n' "$resp" >&2
return 1
fi
printf '%s' "$resp" \
| jq -r '.stdout, .stderr, (if .exitCode != 0 then "[exit \(.exitCode)]" else empty end) | select(. != "")' \
| tr -d '\r'
}Step 1 — extract the MITM root, on the host. kubectl get secret egress-mitm-ca-pool -n ate-system -o jsonpath='{.data.pool}' \
| base64 -d \
| jq -r '.CAs[] | select(.ID=="mitm") | .RootCertificateDER' \
| base64 -d \
| openssl x509 -inform DER -out /tmp/mitm-ca.pem
openssl x509 -in /tmp/mitm-ca.pem -noout -subject # CN=substrate egress MITM CAThe pool blob also contains the signing key. Do not pass the whole blob into the Step 2 — repos to HTTP. No TLS is available in the actor yet. Alpine signs ate_run probe.demo 'sed -i "s|https|http|g" /etc/apk/repositories'Step 3 — install what Alpine has. Cleartext, so it works before any trust is ate_run probe.demo 'apk add --no-cache curl ca-certificates websocat'
Step 4 — install the MITM root into the actor's trust store. No egress: the jq -n --rawfile ca /tmp/mitm-ca.pem '{
command:["sh","-c","printf %s \"$MITM_CA\" > /usr/local/share/ca-certificates/mitm-ca.crt && update-ca-certificates"],
envvars:{MITM_CA:$ca}}' \
| curl -sS -X POST http://localhost:8000/process \
-H "Host: probe.demo.actors.resources.substrate.ate.dev" \
-H "Content-Type: application/json" --data-binary @- \
| jq -r '.stdout, .stderr'The system trust store rather than a loose Step 5 — fetch grpcurl. Needs HTTPS, which is why it is last. It doubles as ate_run probe.demo 'ver=1.9.3; curl -fsSL -o /tmp/g.tgz \
"https://github.com/fullstorydev/grpcurl/releases/download/v${ver}/grpcurl_${ver}_linux_x86_64.tar.gz" \
&& tar -xzf /tmp/g.tgz -C /usr/local/bin grpcurl && grpcurl --version'Written to a file rather than piped: busybox 2. The testsTargets are public, which is fine for a manual procedure and not for a presubmit 2.0 Pre-flight: does the leg speak h2 at all?ate_run probe.demo 'curl -sS -m 20 -o /dev/null \
-w "http_version=%{http_version} code=%{http_code}\n" https://example.com'Expect 2.1 gRPC over TLSate_run probe.demo 'grpcurl -max-time 30 grpcb.in:9001 list'
ate_run probe.demo 'grpcurl -max-time 30 -d "{\"f_string\":\"hello-mitm\"}" grpcb.in:9001 grpcbin.GRPCBin/DummyUnary'Reflection is itself a bidirectional stream, so 2.2 gRPC over h2cate_run probe.demo 'grpcurl -max-time 30 -plaintext -d "{\"f_string\":\"h2c-hello\"}" grpcb.in:9000 grpcbin.GRPCBin/DummyUnary'Exercises 2.3 gRPC server-streaming — detached
ate_run probe.demo 'rm -f /tmp/g4.log; setsid sh -c "grpcurl -max-time 90 \
-d {\\\"f_string\\\":\\\"stream\\\"} grpcb.in:9001 grpcbin.GRPCBin/DummyServerStream \
> /tmp/g4.log 2>&1; echo EXIT=\$? >> /tmp/g4.log" < /dev/null > /dev/null 2>&1 & echo started'
sleep 45
ate_run probe.demo 'echo "messages: $(grep -c fString /tmp/g4.log)"; tail -1 /tmp/g4.log'Expect 2.4 WebSocket over TLSate_run probe.demo '{ printf "hello-echo-1\n"; sleep 3; printf "hello-echo-2\n"; sleep 3; } \
| timeout 20 websocat wss://echo.websocket.org'Both messages must come back. Do not use 2.5 SSE over TLSate_run probe.demo 'curl -sS -N -m 8 -H "Accept: text/event-stream" \
https://stream.wikimedia.org/v2/stream/recentchange | grep -c "^event:"'
ate_run probe.demo 'curl -sS -N -m 6 -o /dev/null -H "Accept: text/event-stream" \
-w "time_starttransfer=%{time_starttransfer}s time_total=%{time_total}s size=%{size_download}\n" \
https://stream.wikimedia.org/v2/stream/recentchange'The first counts events; the second is the one that proves the body is not 2.6 Idle stream survival — detachedMust outlast both the 10s route timeout and the 5-minute idle timeout under for ka in "-keepalive-time 30" ""; do
tag=$([ -n "$ka" ] && echo with || echo without)
ate_run probe.demo "rm -f /tmp/idle-$tag.log; setsid sh -c '
{ printf \"{\\\"f_string\\\":\\\"before-idle\\\"}\n\"; sleep 400;
printf \"{\\\"f_string\\\":\\\"after-idle\\\"}\n\"; sleep 5; } \
| grpcurl $ka -max-time 500 -d @ grpcb.in:9001 grpcbin.GRPCBin/DummyBidirectionalStreamStream \
> /tmp/idle-$tag.log 2>&1
echo EXIT=\$? >> /tmp/idle-$tag.log' </dev/null >/dev/null 2>&1 & echo started-$tag"
done
# ...wait > 7 minutes, then collect
ate_run probe.demo 'cat /tmp/idle-with.log /tmp/idle-without.log'
The expected result is asymmetric; see §4. 2.7
|
| Test | leg |
protocol |
other |
|---|---|---|---|
| 2.1 gRPC/TLS | mitm |
HTTP/2 |
status 200, grpc_status OK |
| 2.2 gRPC/h2c | cleartext |
HTTP/2 |
status 200, grpc_status OK |
| 2.3 streaming | mitm |
HTTP/2 |
duration_ms ≈ 10000 |
| 2.4 WebSocket | mitm |
HTTP/1.1 |
status 101 — HTTP/1.1, not HTTP/2 |
| 2.5 SSE | mitm |
HTTP/2 |
duration_ms ≈ probe duration, flags DR |
| 2.6 idle | mitm |
HTTP/2 |
duration_ms > 400000 with keepalive, exactly ≈300100 without |
| 2.7 failed RPC | mitm |
HTTP/2 |
status 200 and grpc_status NotFound |
status 200 with a non-OK grpc_status on the same line is the whole reason
that field exists: without it every failed RPC reads as a success.
The CONNECT leg authorizes all of them. Its absence means the traffic never
went through the gateway and the test measured nothing. It is also where an
idle-timeout kill shows up, as flags=SI:
kubectl logs -n ate-system deploy/atenet-egress -c envoy --since=15m | grep '\[egress\]'Upstream protocol, per cluster. This is what distinguishes "the request
worked" from "the request took the intended path", and it is the assertion for
the gRPC/WebSocket split specifically:
kubectl port-forward -n ate-system deploy/atenet-egress 15000:15000 &
curl -s localhost:15000/stats \
| grep -E 'cluster\.egress_forward_proxy(_grpc|_cleartext)?\.upstream_(cx_http[12]_total|rq_(5xx|completed))' \
| grep -v ': 0$'egress_forward_proxy must show only http1, egress_forward_proxy_grpc
only http2, and upstream_rq_5xx must be absent. An http2 count on the
default cluster means gRPC and WebSocket traffic are sharing an upstream
protocol, which is the failure described in §4.
4. Results (2026-08-20)
Run by hand against a GKE cluster (substrate-poc) with the sdsmint gateway and
the sandbox demo installed, from actor probe in atespace demo. Every row was
confirmed against a gateway access-log line, not just a client exit code.
| Test | Result | Gateway saw |
|---|---|---|
| 2.0 ALPN pre-flight | pass | http_version=2 code=200 |
| 2.1 gRPC over TLS | pass | HTTP/2, grpc_status: OK, reflection + unary |
| 2.2 gRPC over h2c | pass | leg: cleartext, HTTP/2, grpc_status: OK |
| 2.3 gRPC server-streaming | pass | 10 messages, EXIT=0, duration_ms: 10108 |
| 2.4 WebSocket over TLS | pass after a fix | HTTP/1.1, status: 101, bidirectional echo |
| 2.5 SSE over TLS | pass | HTTP/2, 306 KB in 6 s, first byte at 0.32 s |
| 2.6 Idle stream survival | pass, conditional | see below |
2.7 grpc_status on failure |
pass | status: 200, grpc_status: NotFound |
| WebSocket over cleartext | not covered | every public ws:// echo service now 301s to HTTPS |
0bfb64a to
ddca29f
Compare
ddca29f to
2b33493
Compare
Bowei Du (bowei)
left a comment
There was a problem hiding this comment.
There are some questions on why gRPC need to be handled separately.
The e2e tests should also be added to avoid manual testing.
#1017 tracks the e2e test coverage work. |
… leg mitm_listener classified everything that was not TLS as HTTP, so SSH and every other non-HTTP protocol reached a connection manager that parsed the first bytes as a request line, found none, and dropped the connection with nothing in the access log. http_inspector now splits raw_buffer again, and a third chain tcp_proxies what neither inspector could claim. That chain cannot police what it carries -- an opaque stream has no Host and no SNI -- so it dials the IP:port ext_proc already authorized on the CONNECT, relayed across the internal hop as original_dst_address filter state through an internal_upstream socket. Nothing is weakened: these connections were not blocked before, they were accepted and mangled. Server-speaks-first protocols would otherwise deadlock both inspectors, so listener_filters_timeout is 1s with continue_on_listener_filters_timeout, which lands a silent client on the passthrough chain where it belongs. A long-lived stream was capped twice on the MITM leg: a route timeout runs until the response is complete, which for SSE or a WebSocket is never, and stream_idle_timeout reaped a stream that was merely quiet. Both drop to 0s there, and the CONNECT route to 0s as well. The outer HCM's 5 minute stream_idle_timeout still bounds an idle tunnel, and any byte in either direction resets it. Both HTTP chains also gain a websocket upgrade_config, because a leg that parses HTTP has to be told to proxy an upgrade rather than answer it. The MITM leaf now offers h2 as well as http/1.1, which grpc-go requires. Upstream stays HTTP/1.1 by default, since only it can carry an Upgrade to an origin that has no RFC 8441 extended CONNECT; gRPC needs HTTP/2 trailers instead, so content-type routes it to a second forward proxy that takes its protocol from upstream ALPN. The cleartext leg mirrors whatever the actor spoke. Access logs carry grpc_status, since a failed RPC is still HTTP 200.
2b33493 to
013fb0a
Compare
Addresses #823
Manual Verification: