Skip to content

feat(agent): upstream cluster mTLS via transport-socket matcher - #80

Merged
bpalermo merged 1 commit into
mainfrom
feat/upstream-cluster-mtls
Jun 7, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/upstream-cluster-mtls

Conversation

@bpalermo

@bpalermo bpalermo commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Implements the upstream cluster mTLS proposal — the final piece of the workload-mTLS data path.

Problem

Outbound traffic to service clusters was plaintext, so it could not complete the mutual-TLS handshake that destination pods' inbound listeners require (RequireClientCertificate: true). Live symptom: tls_inspector.tls_not_found, ssl.connection_error, upstream 503 connection termination.

Each pod's outbound listener already publishes its netns into the aether.network.network_namespace filter state (set_filter_state, shared_with_upstream: ONCE), but no cluster read it.

Change

Attach to every regular (non-local_) service cluster:

  • a transport_socket_matcher keyed on the aether.network.network_namespace filter state, mapping each local pod's netns → a named transport socket;
  • one transport_socket_match per unique local-pod SPIFFE ID, each presenting that pod's client cert over SPIRE-served SDS.

The upstream connection thus presents the originating pod's identity, selected per connection by which pod's outbound listener received it (mirrors e2e/config/envoy-a.yaml).

Details

  • New proxy.UpstreamTransportSocketMatcher / UpstreamTransportSocketMatches (match name = SPIFFE ID, deduped across pods sharing a service account; matcher uses the existing networkNamespaceFilterStateKey so the set/read keys can't drift).
  • UpstreamTransportSocket now advertises ALPN h2 (clusters are HTTP/2).
  • The cache tracks local pods' netns → SPIFFE ID (maintained in AddPod/RemovePod/LoadListenersFromStorage, same lifecycle as the listeners that emit the filter state) and clones each regular cluster at snapshot assembly (clustersEndpointsAndVhosts) to inject the matcher — no extra rebuild on pod or registry changes.
  • local_ clusters excluded; with no local pods, clusters stay plaintext (safe no-op).
  • Promote github.com/cncf/xds/go to a direct dependency for the xds matcher types.

Tests

  • matcher/matches: dedup by SPIFFE ID, match name = SPIFFE ID, matcher input key = aether.network.network_namespace, netns→action name.
  • ALPN h2 on the upstream socket.
  • cache: regular cluster carries the matcher after a pod is added; local_ excluded; no matcher before any local pod.

Open questions (from the proposal)

on_no_match is currently unset (fail-closed-ish: no fallback cleartext socket). Local-cluster mTLS is deferred. Both noted for follow-up.

Outbound traffic to service clusters was plaintext, so it could not complete the
mutual-TLS handshake required by destination pods' inbound listeners. Each pod's
outbound listener already publishes its network namespace into the
aether.network.network_namespace filter state (shared with the upstream
connection), but no cluster acted on it.

Attach to every regular (non-local) service cluster:
- a transport_socket_matcher keyed on the aether.network.network_namespace
  filter state, mapping each local pod's netns to a named transport socket, and
- one transport_socket_match per unique local-pod SPIFFE ID, each presenting that
  pod's client certificate over SPIRE-served SDS.

So the upstream connection presents the originating pod's identity, selected per
connection by which pod's outbound listener received it.

- New proxy helpers UpstreamTransportSocketMatcher / UpstreamTransportSocketMatches
  (match name = SPIFFE ID, deduped across pods sharing a service account).
- UpstreamTransportSocket now advertises ALPN h2 (clusters are HTTP/2).
- The cache tracks local pods' netns -> SPIFFE ID (maintained alongside listeners
  in AddPod/RemovePod/LoadListenersFromStorage) and clones each regular cluster at
  snapshot assembly to inject the matcher — no extra rebuild on pod or registry
  changes. local_ clusters are excluded; with no local pods, clusters stay plaintext.
- Promote github.com/cncf/xds/go to a direct dependency (xds matcher types).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bpalermo
bpalermo merged commit 5681eba into main Jun 7, 2026
10 checks passed
@bpalermo
bpalermo deleted the feat/upstream-cluster-mtls branch June 7, 2026 22:11
bpalermo added a commit that referenced this pull request Jun 8, 2026
Round 2 (PR 4/6): add the proven HBONE-style tunnel-client generators as
reusable proxy functions, ahead of wiring them into the outbound <C> cluster:

- NewTunnelInternalListener: the internal listener whose tcp_proxy encapsulates
  a stream into a CONNECT tunnel, setting the CONNECT :authority from the
  destination pod address carried in the passed-through tunnel metadata
  (%DYNAMIC_METADATA(tunnel:authority)%).
- NewTunnelOriginateCluster: the ORIGINAL_DST cluster the tunnel dials, reading
  the destination node address per-endpoint from tunnel.node (metadata_key).
  connection_pool_per_downstream_connection guarantees a source pod's tunnel
  connection is never reused for another source, so the per-source client cert
  (selected by the #80 transport-socket matcher on the source netns filter
  state, on-no-match -> node identity) cannot leak across identities — the
  leak-free path validated in the identity spike.
- InternalUpstreamTransportSocket: passes the selected endpoint's tunnel
  metadata across the internal-listener boundary.
- TunnelEndpointMetadata: builds endpoint metadata (envoy.lb subset keys +
  tunnel.authority/node).

Pure generators with unit tests; not yet wired into cluster/EDS generation, so
no behavior change. The <C> rewire + node_ip plumbing follows in the next
stacked PR.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
bpalermo added a commit that referenced this pull request Jun 8, 2026
…#86)

Round 2 (PR 4/6): add the proven HBONE-style tunnel-client generators as
reusable proxy functions, ahead of wiring them into the outbound <C> cluster:

- NewTunnelInternalListener: the internal listener whose tcp_proxy encapsulates
  a stream into a CONNECT tunnel, setting the CONNECT :authority from the
  destination pod address carried in the passed-through tunnel metadata
  (%DYNAMIC_METADATA(tunnel:authority)%).
- NewTunnelOriginateCluster: the ORIGINAL_DST cluster the tunnel dials, reading
  the destination node address per-endpoint from tunnel.node (metadata_key).
  connection_pool_per_downstream_connection guarantees a source pod's tunnel
  connection is never reused for another source, so the per-source client cert
  (selected by the #80 transport-socket matcher on the source netns filter
  state, on-no-match -> node identity) cannot leak across identities — the
  leak-free path validated in the identity spike.
- InternalUpstreamTransportSocket: passes the selected endpoint's tunnel
  metadata across the internal-listener boundary.
- TunnelEndpointMetadata: builds endpoint metadata (envoy.lb subset keys +
  tunnel.authority/node).

Pure generators with unit tests; not yet wired into cluster/EDS generation, so
no behavior change. The <C> rewire + node_ip plumbing follows in the next
stacked PR.

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

1 participant