Skip to content

fix(agent): pin a workload-shaped client SAN on the inbound socket (#843) - #850

Merged
bpalermo merged 3 commits into
mainfrom
fix/843-inbound-client-san-pin
Sep 20, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/843-inbound-client-san-pin

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #843.

The gap

proxy.DownstreamTransportSocket set RequireClientCertificate: true with a validation context carrying no SAN matchers at all. The handshake therefore proved one thing: the trust bundle signed something. Any certificate that bundle chains to satisfied it, workload SVID or not.

The inbound HCM then stamps that certificate's URI SAN into XFCC with SANITIZE_SET (ingress.go:231-235), and RBAC/ext_authz decisions key on the result. So the property every XFCC-derived rule assumes — "this value came off a verified workload identity" — was never actually established.

The fix

The destination cannot pin a specific ServiceAccount; in a mesh any workload may legitimately call, and identity-level authorization belongs in RBAC/ext_authz. It can require the certificate to be structurally a workload SVID. Every mTLS inbound chain now carries a combined validation context with one match_typed_subject_alt_names entry:

san_type: URI
matcher: { prefix: "spiffe://<trust-domain>/ns/" }

layered over the same SDS-rotated trust bundle as before.

Prefix matchers are supported for URI SANs on the pinned build. createStringSanMatcher builds a generic StringSanMatcher(GEN_URI, matcher, context) for san_type: URI (source/common/tls/cert_validator/san_matcher.cc), so the full StringMatcher surface applies. Only DNS has a special case (an exact matcher becomes RFC 6125 wildcard matching via DnsExactStringSanMatcher). Verified at the pinned commit 13144fb itself, not just at the checkout's HEAD.

The TCP floor gets the same pin, and needs it most. It is the listener's DEFAULT chain, so anything matching nothing more specific lands there, and tcp_proxy forwards raw bytes to the application — no XFCC, no HTTP-level authorization behind it at all. An unpinned floor would be a hole underneath every pinned HTTP chain.

The empty-trust-domain trap

WorkloadSANPrefix("") returns "", and the socket then emits no matcher — byte-identical to the pre-#843 shape — rather than spiffe:///ns/. That prefix matches no certificate any CA in this mesh has ever issued, so it would fail every inbound handshake on the affected pod, permanently, because the malformed config is already published. That is rev222 (#815/#819) with a whole node's blast radius.

That branch is defence in depth, not a live path: NewInboundListener already returns ErrNoTrustDomain before reaching the transport socket on the mTLS path, so the reachable "no trust domain" outcome is a skipped pod with a WARN naming it, never a silently downgraded listener. TestNewInboundListener_NoTrustDomainRefuses pins that guard, and TestDownstreamTransportSocket_NoTrustDomainEmitsNoMatcher pins the fallback shape.

Why no inbound_unpinned counter (the #840 question, argued)

#840's aether.agent.identity.cluster_unpinned is right for clusters and wrong here, because the two paths make opposite choices about what to ship.

The cluster path deliberately ships the unpinned form when the pin cannot be rendered — an unpinned cluster still works, so the degradation was invisible, and a counter is the only way to tell a window that outlived its bound from one that never happened. Worse, one of its two causes (endpoints with no namespace metadata) is not a window at all: it persists for as long as the registry serves those endpoints.

The inbound path ships nothing: the only reachable no-trust-domain outcome is a refusal that the caller already logs by pod name. There is no silent window for a counter to make loud.

What could go wrong is a future caller that bypasses NewInboundListener's guard — and a runtime counter would only report that after it shipped. So the gate here is a build-time config-shape assertion (UnpinnedInboundChains) over the generated bootstrap bytes, which fails the build instead. That is strictly stronger for this failure mode. If an unpinned inbound ever becomes a deliberate runtime state the way an unpinned cluster is, it should get a counter then; today it would be a metric seeded at zero that can never move.

Non-vacuity of the //test/envoy_validate gate

envoy --mode validate accepts an unpinned downstream context — the same fail-open direction #832 found on the upstream side — so a passing validate says nothing about the pin. Forcing WorkloadSANPrefix to return "" and re-running:

=== RUN   TestEnvoyValidate
    validate_test.go:180: node_bootstrap.json: mTLS-terminating filter chains with no client match_typed_subject_alt_names: [inbound_test-pod/in_tcp_test-pod inbound_test-pod/in_test-pod inbound_test-pod/in_test-pod_8080]
    validate_test.go:180: node_uds_bootstrap.json: mTLS-terminating filter chains with no client match_typed_subject_alt_names: [inbound_test-pod/in_tcp_test-pod inbound_test-pod/in_test-pod inbound_test-pod/in_test-pod_8080 inbound_test-pod/in_test-pod_9090]
=== RUN   TestEnvoyValidate/node_bootstrap.json
        configuration '/tmp/TestEnvoyValidate3436248065/001/node_bootstrap.json' OK
...
--- FAIL: TestEnvoyValidate (0.54s)
    --- PASS: TestEnvoyValidate/node_bootstrap.json (0.07s)
    --- PASS: TestEnvoyValidate/node_cleartext_bootstrap.json (0.07s)
    --- PASS: TestEnvoyValidate/node_uds_bootstrap.json (0.07s)
    --- PASS: TestEnvoyValidate/capture_bootstrap.json (0.08s)
    --- PASS: TestEnvoyValidate/capture_route_target_bootstrap.json (0.09s)
    --- PASS: TestEnvoyValidate/outbound_zero_vhost_route_bootstrap.json (0.06s)
    --- PASS: TestEnvoyValidate/edge_bootstrap.json (0.07s)

The assertion names every affected chain while all seven bootstraps still report OK. Break reverted; with the pin in place every bootstrap validates OK again, which is also the positive proof that the pinned Envoy accepts a prefix matcher on a DownstreamTlsContext.

Scope is structural, never an allow-list: a chain is checked precisely when it sets require_client_certificate. The edge's downstream contexts do not (external callers have no mesh identity), so they fall out automatically.

Who must still be accepted — checked, not assumed

Caller Identity Passes
Mesh workload (any namespace) spiffe://<td>/ns/<ns>/sa/<sa> yes
inboundready_<pod> probe the node agent's own SVID yes
Edge gateway spiffe://<td>/ns/aether-ingress/sa/<sa> yes
SPIRE node/agent identities spiffe://<td>/spire/agent/… rejected — the point
Other trust domain spiffe://other/ns/… rejected

The probe row is the dangerous one and it is where a rev222 repeat would have come from: the probe dials every local pod's inbound every 5s presenting the node identity, so a rejection there demotes endpoints across the node. On this mesh the agent is an ordinary pod, so SPIRE's fallback ClusterSPIFFEID issues it spiffe://<td>/ns/aether-system/sa/aether-agent — not spiffe://<td>/node/<node> (#825, stated in networkfilter.go). TestInboundReadyProbeIsAcceptedByInboundValidation now asserts the certificate the probe presents satisfies the prefix the listener ships, so a change to either half is loud.

Fixture trap found and fixed while checking that. //test/envoy_validate's builders still spelled the node identity as spiffe://<td>/node/test-node — an identity the new pin would reject. The validate harness cannot see client identities, so the fixture was inert, but it modelled the exact certificate shape whose rejection would take a node's endpoints down. Replaced with the production shape behind a named constant and a comment. (//test/mtlspool's spiffeNode is the same spelling but builds its own certs against its own Go TLS server, never the inbound builder — left alone, flagged here.)

Related, deliberately not bundled

The issue notes that keeping the agent's own identity out of app inbound would be a different and stricter rule. It would be: it needs an exclusion, not a prefix, and it would break the readiness probe unless the probe is exempted first. Not done here.

Deploy note

This changes the inbound filter chains' bytes, so Envoy replaces and drains every mesh pod's inbound chains once on rollout (--drain-time-s, 10s here). Budget a deploy; nothing in this PR has been applied to a cluster.

Verification

bazel test //...                                              107 tests pass
bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...   clean
make gazelle && make format                                   clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 3 commits September 20, 2026 08:53
)

proxy.DownstreamTransportSocket set RequireClientCertificate: true with a
validation context carrying no SAN matchers at all, so the inbound handshake
proved only trust-bundle membership — any certificate that bundle signs,
including identities that are not workload SVIDs. The inbound HCM then stamps
that certificate's URI SAN into XFCC with SANITIZE_SET (ingress.go), and
RBAC/ext_authz decisions key on that value, so the property every XFCC-derived
rule assumes was never actually established.

The destination cannot pin a specific ServiceAccount — in a mesh any workload
may legitimately call — but it can require the certificate to be STRUCTURALLY a
workload SVID. Each mTLS inbound chain now carries a combined validation
context with one match_typed_subject_alt_names entry: san_type URI, prefix
"spiffe://<trust-domain>/ns/". Envoy builds StringSanMatcher(GEN_URI, matcher)
for URI SANs (source/common/tls/cert_validator/san_matcher.cc), so the full
StringMatcher surface applies; only DNS gets the RFC 6125 special case.

The TCP floor gets the same pin and needs it most: it is the listener's DEFAULT
chain and tcp_proxy forwards raw bytes to the application, so there is no XFCC
and no HTTP-level authorization behind it at all.

Empty trust domain emits NO matcher, never "spiffe:///ns/". A prefix built from
an empty trust domain matches no certificate any CA in this mesh has issued, so
it would fail every inbound handshake on that pod — #815/#819 with a node's
blast radius. That branch is defence in depth rather than a live path:
NewInboundListener already returns ErrNoTrustDomain first, so the reachable
outcome is a skipped pod with a WARN naming it.

No new counter for an unpinned inbound, deliberately, unlike #840's
cluster_unpinned: that counter exists because the cluster path deliberately
SHIPS the unpinned form as the lesser evil and did so silently. Here the lesser
evil is refusing to build the listener, which is already loud. The gate is a
build-time config-shape assertion instead — UnpinnedInboundChains over the
generated bootstrap bytes — which also covers a future caller that bypasses the
ErrNoTrustDomain guard, something a runtime counter could not.

envoy --mode validate ACCEPTS an unpinned downstream context, the same
fail-open direction #832 found upstream. Proved non-vacuous by forcing
WorkloadSANPrefix to "": the assertion named every affected chain
(inbound_test-pod/in_tcp_test-pod, /in_test-pod, /in_test-pod_8080) while all
seven bootstraps still reported "configuration ... OK".

The node identity satisfies the pin: the agent is an ordinary pod, so SPIRE's
fallback ClusterSPIFFEID issues it spiffe://<td>/ns/aether-system/sa/aether-agent
(#825). That matters because the inboundready_<pod> probe dials every local pod
presenting it — a rejection there would demote endpoints, the rev222 failure
mode. //test/envoy_validate's fixtures still spelled the node identity as
spiffe://<td>/node/test-node, which the new pin would REJECT; they now use the
production shape, and a proxy-package test asserts the probe's certificate
satisfies the pin directly.

Scope note: the prefix names the LOCAL trust domain, which makes it exactly as
restrictive as the upstream pin already shipped (cache/mtls.go renders exact
spiffe://<local-td>/ns/<ns>/sa/<svc> matchers). Cross-trust-domain traffic is
therefore already impossible in the client direction, and proposal 019 states a
shared trust domain as a precondition with SPIRE federation deferred. If
federation is ever enabled both pins must widen together.

This changes the inbound filter chains' bytes, so Envoy replaces and drains
every mesh pod's inbound chains once on rollout (--drain-time-s, 10s here).

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 1adf2a0 into main Sep 20, 2026
21 checks passed
@bpalermo
bpalermo deleted the fix/843-inbound-client-san-pin branch September 20, 2026 12:34
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.

Inbound validation context accepts any trust-domain member: pin a spiffe://<td>/ns/*/sa/* URI SAN prefix

1 participant