Repository navigation
fix(agent): pin a workload-shaped client SAN on the inbound socket (#843) - #850
Merged
Merged
Conversation
) 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #843.
The gap
proxy.DownstreamTransportSocketsetRequireClientCertificate: truewith 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_namesentry:layered over the same SDS-rotated trust bundle as before.
Prefix matchers are supported for URI SANs on the pinned build.
createStringSanMatcherbuilds a genericStringSanMatcher(GEN_URI, matcher, context)forsan_type: URI(source/common/tls/cert_validator/san_matcher.cc), so the fullStringMatchersurface applies. OnlyDNShas a special case (anexactmatcher becomes RFC 6125 wildcard matching viaDnsExactStringSanMatcher). Verified at the pinned commit13144fbitself, 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_proxyforwards 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 thanspiffe:///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:
NewInboundListeneralready returnsErrNoTrustDomainbefore 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_NoTrustDomainRefusespins that guard, andTestDownstreamTransportSocket_NoTrustDomainEmitsNoMatcherpins the fallback shape.Why no
inbound_unpinnedcounter (the #840 question, argued)#840's
aether.agent.identity.cluster_unpinnedis 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_validategateenvoy --mode validateaccepts an unpinned downstream context — the same fail-open direction #832 found on the upstream side — so a passing validate says nothing about the pin. ForcingWorkloadSANPrefixto return""and re-running:The assertion names every affected chain while all seven bootstraps still report
OK. Break reverted; with the pin in place every bootstrap validatesOKagain, which is also the positive proof that the pinned Envoy accepts a prefix matcher on aDownstreamTlsContext.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
spiffe://<td>/ns/<ns>/sa/<sa>inboundready_<pod>probespiffe://<td>/ns/aether-ingress/sa/<sa>spiffe://<td>/spire/agent/…spiffe://other/ns/…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
ClusterSPIFFEIDissues itspiffe://<td>/ns/aether-system/sa/aether-agent— notspiffe://<td>/node/<node>(#825, stated innetworkfilter.go).TestInboundReadyProbeIsAcceptedByInboundValidationnow 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 asspiffe://<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'sspiffeNodeis 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
🤖 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