Skip to content

egress: carry non-HTTP and streaming traffic through the sdsmint MITM leg - #1086

Merged
Bowei Du (bowei) merged 1 commit into
agent-substrate:mainfrom
haiyanmeng:non-http-egress
Aug 20, 2026
Merged

Bowei Du (bowei) merged 1 commit into
agent-substrate:mainfrom
haiyanmeng:non-http-egress

Conversation

@haiyanmeng

@haiyanmeng haiyanmeng commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator
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.

Addresses #823

Manual Verification:

It's a good idea to open an issue first for discussion.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

@haiyanmeng

haiyanmeng commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Manual test: SSH egress

Confirms that SSH — traffic that is neither HTTP nor TLS — reaches the internet
through the MITM egress gateway and lands on the passthrough filter chain.

Uses the sandbox demo, whose /process endpoint runs arbitrary argv inside the
actor, so no purpose-built fixture is needed.

1. Install

hack/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

--experimental-use-sdsmint selects manifests/ate-install/atenet-egress-with-sdsmint.yaml
instead of the shipped gateway. Without it there is no MITM listener and nothing
to test.

2. Create an actor

kubectl 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 demos/sandbox/client. It dials ateapi with no credentials and fails
with Unauthenticated: missing bearer token.

3. Helper

/process takes JSON and returns {"stdout","stderr","exitCode"} with the
output escaped. Build the request with jq so commands need no quoting:

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 exitCode. A slow command
can outlast the router timeout and return 504 while still running in the actor.

4. Install ssh in the actor

The image is plain Alpine: no ssh, no git, no curl. Installing them needs
egress, and HTTPS egress does not work yet — the gateway mints a leaf off a CA
the actor does not trust, so apk fails with TLS: server certificate not trusted. Alpine signs packages independently of the transport, so switch the
repos to HTTP:

ate_run my-sandbox-1.demo "sed -i 's|https|http|g' /etc/apk/repositories && apk add --no-cache openssh-client"

5. Run SSH

Copy in the key you already use for GitHub. Check first that it works and has no
passphrase — the actor has no agent and nothing to prompt at:

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-key

Pass it in envvars, not interpolated into the command string, so it stays out
of shell history and process lists:

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.json

The fingerprint it prints must match ssh-keygen -lf ~/.ssh/id_ed25519.pub.
Then connect:

ate_run my-sandbox-1.demo 'ssh -T -o StrictHostKeyChecking=no [email protected] 2>&1'
Hi haiyanmeng! You've successfully authenticated, but GitHub does not provide shell access.

Exit 1 is the success case — GitHub is refusing a shell, not refusing you.

For the transport detail, add -v:

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
SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU, which confirms the session
was not intercepted — the passthrough chain is meant to be blind.

Without a key you get Permission denied (publickey) and exit 255 instead. That
also proves the transport works, since it comes after a completed key exchange.

Your personal key leaves the machine. sandbox-template defaults to
Full snapshot scope, so the key is copied into the GCS snapshot bucket on
every pause and outlives the actor. Either delete the actor without pausing
it, or use a template with onPause: Data / onCommit: Data and no DurableDir
volumes — demos/sandbox/ssh-egress-test.yaml.tmpl is exactly that, and writes
no filesystem content at all. For anything longer-lived, register a throwaway
deploy key instead (gh repo deploy-key add) so it can be revoked on its own.

6. Check the gateway

The gateway logs two formats on one stream: the CONNECT leg as text, the three
MITM legs as JSON. Filter before parsing.

kubectl logs -n ate-system deploy/atenet-egress -c envoy --tail=400 \
  | jq -Rc 'fromjson? // empty | select(.leg)' | tail

SSH must appear as passthrough:

{"leg":"passthrough","sni":null,"upstream":"140.82.113.3:22",
 "bytes_rcvd":3022,"bytes_sent":2749,"flags":"-"}
  • leg is passthrough, not mitm or cleartext. Before the fix, non-HTTP
    traffic was parsed as HTTP, dropped, and logged nowhere at all.
  • upstream is the IP:port from the CONNECT, so original_dst_address survived
    the internal hop. This chain has no Host or SNI to fall back on.
  • Both byte counts are non-zero, so a real session crossed it.

The apk traffic from step 4 should show up as leg: cleartext, confirming the
new fallback chain did not swallow HTTP. And the CONNECT leg authorizes both:

kubectl logs -n ate-system deploy/atenet-egress -c envoy --tail=400 | grep '\[egress\]'
[egress] authority=140.82.113.3:22 peer_san=spiffe://substrate-actor.local/atespace/demo/actor/my-sandbox-1 code=200 flags=DC up_bytes=3022 down_bytes=2749

7. Clone a repo over SSH

git is not in the image either, and GitHub requires a key on port 22 even for
a public repo, so this reuses the one from step 5:

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 jq: parse error: Invalid numeric literal at line 1, column 9, which can be ignored.

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 on :22, with byte counts the
size of the repo — a key changes authentication, not transport:

{"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
just enough bytes to reach an auth prompt. A full clone of this repo takes about
8s; on a slower link one can outlast the router timeout and return 504 while
still running, so poll with ls rather than retrying, or use --depth 1.

8. Server-speaks-first

SSH sends its banner first, so it does not exercise the listener-filter timeout.
For that, use a protocol where the server greets first:

ate_run my-sandbox-1.demo 'sleep 6 | nc -w 8 smtp.gmail.com 25'
220 smtp.gmail.com ESMTP 5614622812f47-4b2d68769e1sm1723520b6e.8 - gsmtp

The sleep is required. /process gives the command no stdin, and busybox nc
closes the socket as soon as stdin hits EOF — without it nc exits 0 having
printed nothing, before the greeting arrives.

The gateway record proves the timeout path was taken:

{"leg":"passthrough","upstream":"173.194.206.108:25","bytes_rcvd":0,"bytes_sent":74}

bytes_rcvd: 0 means the client sent nothing at all, so neither listener filter
had anything to inspect and only listener_filters_timeout +
continue_on_listener_filters_timeout could have moved the connection onto this
chain.

Clean up

kubectl ate pause actor my-sandbox-1 -a demo
kubectl ate delete actor my-sandbox-1 -a demo

@haiyanmeng
haiyanmeng force-pushed the non-http-egress branch 2 times, most recently from 960f1e2 to 892ec8b Compare August 20, 2026 16:50

@bowei Bowei Du (bowei) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this change come with tests?

I think the config looks ok

@haiyanmeng

Copy link
Copy Markdown
Collaborator Author

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.
I did post the manual verification steps in the PR.

@haiyanmeng

haiyanmeng commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Testing gRPC, WebSocket, and SSE egress from a sandbox actor

1. Setup

Step 0 — an actor called probe. Every command addresses probe.demo, so
it must exist under that name. Installing the demo is separate from installing
the system: a cluster built with --deploy-ate-system alone has no
sandbox-template, and the router answers actor demo/probe not found with a
404.

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 STATUS_UNSPECIFIED with no ateom pod even when it is
healthy; that field is not populated by this API version. Smoke-test instead:

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 onPause: Data and no
DurableDir volumes — demos/sandbox/ssh-egress-test.yaml.tmpl is one — so the
tools installed below are not copied into the snapshot bucket on every pause.

Then the ate_run helper. It checks the router's reply is JSON before parsing:
without that, a 404 or a 504 surfaces as jq: parse error: Invalid numeric literal, which points at jq rather than at the actor.

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. RootCertificatePEM is empty
in practice; RootCertificateDER is the populated field.

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 CA

The pool blob also contains the signing key. Do not pass the whole blob into the
actor — extract the certificate on the host, as above, and inject only that.

Step 2 — repos to HTTP. No TLS is available in the actor yet. Alpine signs
packages independently of the transport, so this weakens nothing that matters.

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
established. This is also the traffic that should appear as leg: cleartext in
the gateway log.

ate_run probe.demo 'apk add --no-cache curl ca-certificates websocat'

websocat is in the community repo (1.14.1). grpcurl is not packaged and has
to be fetched in step 5.

Step 4 — install the MITM root into the actor's trust store. No egress: the
certificate travels in the request body. ate_run only takes a command, so this
call goes to /process directly with an envvars map — the same pattern the SSH
document uses for a private key, keeping the material out of shell history and
out of the actor's process list.

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 --cacert file, because websocat
has no flag to point at one. With it installed, every client below works
unmodified and no test command needs a --cacert.

Step 5 — fetch grpcurl. Needs HTTPS, which is why it is last. It doubles as
a bootstrap assertion: a verified-chain HTTPS transfer through the MITM.

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 tar does not reliably extract a
named member from a non-seekable stream. /usr/local/bin is writable.

2. The tests

Targets are public, which is fine for a manual procedure and not for a presubmit
lane: grpcb.in:9001 (gRPC/TLS, with reflection so no .proto is needed),
grpcb.in:9000 (the same service over h2c), wss://echo.websocket.org, and
https://stream.wikimedia.org/v2/stream/recentchange.

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 http_version=2 code=200. That single line says the connection was
intercepted, the injected root verified the minted leaf, and ALPN negotiated
HTTP/2. If this fails, nothing below will pass.

2.1 gRPC over TLS

ate_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 list succeeding already proves
HTTP/2 and trailers survive the round trip. Expect the service list, then
{"fString": "hello-mitm"}.

2.2 gRPC over h2c

ate_run probe.demo 'grpcurl -max-time 30 -plaintext -d "{\"f_string\":\"h2c-hello\"}" grpcb.in:9000 grpcbin.GRPCBin/DummyUnary'

Exercises use_downstream_protocol_config on the cleartext cluster.

2.3 gRPC server-streaming — detached

DummyServerStream takes about 10s, which is on the wrong side of the route
timeout, so this one has to be detached even though it is not a long test.

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 messages: 10 and EXIT=0.

2.4 WebSocket over TLS

ate_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 websocat -n1 for this — it prints the
server's greeting and exits before the echo arrives, so a broken upgrade path
looks identical to a working one.

2.5 SSE over TLS

ate_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
buffered to completion. A time_starttransfer far below time_total, with a
large size_download, is incremental delivery.

2.6 Idle stream survival — detached

Must outlast both the 10s route timeout and the 5-minute idle timeout under
test. Run both variants together so they share one idle window and differ only
in the keepalive flag.

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'

-d @ reads request messages from stdin, so the stream stays open exactly as
long as the producing subshell does — that 400s sleep is the idle window, and
it has to exceed 300s to mean anything. With no producer on stdin, grpcurl
sees EOF immediately and the stream closes before it can be idle at all.

The expected result is asymmetric; see §4.

2.7 grpc_status on a failed RPC

ate_run probe.demo 'grpcurl -max-time 30 -d "{\"code\":5,\"reason\":\"deliberate\"}" \
  grpcb.in:9001 grpcbin.GRPCBin/SpecificError'

Expect Code: NotFound, Message: deliberate.

It has to be a server-side error. Calling a nonexistent method looks like the
obvious test and is not one: grpcurl resolves the method against reflection
first and refuses locally, so nothing is sent and the gateway logs nothing.

3. How to verify the results

A client exit code is not evidence — it cannot distinguish traffic that went
through the gateway from traffic that bypassed it. Every test above is confirmed
against the gateway's own records.

The MITM legs, as JSON. The gateway writes two formats to one stream, the
CONNECT leg as text and the three MITM legs as JSON, so filter before parsing:

kubectl logs -n ate-system deploy/atenet-egress -c envoy --since=15m \
  | grep '^{' \
  | jq -r '[.leg, .protocol, .authority, (.path|.[0:46]), .status, (.grpc_status//"-"), .flags, .duration_ms] | @tsv'
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

@haiyanmeng
haiyanmeng force-pushed the non-http-egress branch 3 times, most recently from 0bfb64a to ddca29f Compare August 20, 2026 17:38
@haiyanmeng haiyanmeng changed the title egress: carry non-HTTP traffic through the sdsmint MITM leg egress: carry non-HTTP and streaming traffic through the sdsmint MITM leg Aug 20, 2026

@bowei Bowei Du (bowei) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are some questions on why gRPC need to be handled separately.
The e2e tests should also be added to avoid manual testing.

@haiyanmeng

Copy link
Copy Markdown
Collaborator Author

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.
@bowei
Bowei Du (bowei) merged commit 6fd47c1 into agent-substrate:main Aug 20, 2026
9 checks passed
@haiyanmeng
haiyanmeng deleted the non-http-egress branch August 20, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants