Skip to content

Source SPIFFE ID is not in the upstream pool key: pooled connections carry a foreign client identity into XFCC #831

Closed as not planned

Description

@bpalermo

The source workload's SPIFFE ID is stamped into filter state but does not contribute to Envoy's upstream connection-pool hash key. Two pods on the same node with different ServiceAccounts talking to the same upstream share one connection pool, so whichever source happened to create the connection supplies the client certificate that every later request rides — including requests from the other workload.

The destination does not catch it, stamps the wrong identity into XFCC, and any RBAC or ext_authz decision keyed on source identity then authorizes the wrong workload.

This predates today's changes. It is not a regression from #815 (the previous netns-path key was also envoy.string); release two made it neither better nor worse. Found while investigating #829, which it is not the cause of.

The chain

  1. agent/internal/xds/proxy/networkfilter.go:175 stamps the source identity with FactoryKey: "envoy.string" → Envoy constructs a Router::StringAccessorImpl.
  2. source/common/router/string_accessor_impl.h:8 — StringAccessorImpl : public StringAccessor only. It does not implement Hashable.
  3. source/common/network/transport_socket_options_impl.cc:47-53 — CommonUpstreamTransportSocketFactory::hashKey folds a downstream-shared filter-state object into the hash only if dynamic_cast<const Hashable*> succeeds.

So aether.source.spiffe_id contributes zero bytes to the pool hash. Pools are keyed by cluster + host and are shared across source identities on the node proxy.

Why the destination cannot catch it

agent/internal/xds/proxy/transportsocket.go:35-49 (DownstreamTransportSocket) sets RequireClientCertificate: true with a validation context carrying no SAN matchers — trust-domain membership only. Any workload in aether.internal satisfies it. XFCC is then stamped SANITIZE_SET from that peer certificate (agent/internal/xds/proxy/ingress.go:231-235), so the wrong source identity is propagated as though verified.

Impact

On a node hosting multiple ServiceAccounts — which is the normal case — XFCC-based authorization is not sound. Concretely, common/extensionfilter/ RBAC rules and the OPA preset behind the authz canary (which has a source-identity rule) can admit or deny based on an identity that is not the caller's.

Severity is bounded by requiring co-location on one node and a shared upstream, and by the fact that both identities are legitimate mesh workloads — this is not an escalation from outside the mesh. It is a workload-to-workload authorization boundary failure inside it.

Fix

Preferred: make the source-identity filter-state object Hashable so it lands in CommonUpstreamTransportSocketFactory::hashKey. Either upstream a Hashable string filter-state factory, or a hashable: true knob on set_filter_state. aether already carries Envoy patches, so this is tractable.

Interim, not recommended: fold the source identity into something already hashed. serverNameOverride is hashed (transport_socket_options_impl.cc:28-30) and aether's upstream SNI is currently only a port number — but that changes what the destination demuxes on, so it trades one correctness problem for another.

Independently worth doing (transportsocket.go:35-49): the destination cannot pin a specific ServiceAccount, since any mesh peer may legitimately call. It can require a well-formed spiffe://<td>/ns/*/sa/* URI SAN via a prefix matcher, which rejects a non-workload certificate and makes the XFCC value structurally trustworthy.

Until fixed: document that upstream connection reuse can carry a foreign source identity, and that XFCC-based RBAC/ext_authz decisions are not sound on a node hosting multiple ServiceAccounts.

Test that would have caught it

Two pods with different ServiceAccounts on one node, both calling the same upstream; assert the destination's XFCC URI SAN matches the actual caller on every request, not just the first. Nothing in the tree does this today — existing coverage exercises one identity per node path, which is exactly the shape that hides a pool-key omission.

test/envoy_validate cannot cover this: it is a runtime pooling property with no configuration expression at all.

Status of the evidence

Derived from reading the aether and Envoy sources at the pinned Envoy revision (1.40.0-dev.20260904.13144fb), with the three links above verified individually. It has not yet been demonstrated live. The integration test described above is the cheapest demonstration and should be written before the fix, so the fix has a failing test to turn green.

Activity

  1. added
    bug
    on Sep 19, 2026
  2. bpalermo commented on Sep 19, 2026

    @bpalermo
    OwnerAuthor

    Severity raised: under HTTP/2 this is the steady state, not a race

    The original report framed this as connection reuse carrying a foreign identity — a race whose window is one pooled connection's lifetime. That understated it.

    aether's upstream is HTTP/2 (agent/internal/xds/proxy/transportsocket.go:103, AlpnProtocols: []string{"h2"}). So many streams from many source pods multiplex onto one upstream connection, whose client certificate was fixed by whichever source happened to create it. The destination then stamps XFCC SANITIZE_SET from that single certificate (ingress.go:231-235), and its DownstreamTransportSocket pins no client SANs (transportsocket.go:35-49) so it cannot object.

    Under h2 this is not a race with a window. It is the steady state on any node hosting more than one ServiceAccount — which is the normal case. Every RBAC and ext_authz decision keyed on source SPIFFE ID is unsound there, continuously.

    Not the same defect as #829

    Worth recording, since the two were investigated together and the link looked plausible. The hash-key omission cannot produce #829's symptom: connection pools are per host (ThreadLocalClusterManagerImpl keys its pool containers by HostConstSharedPtr), so a pool cannot hand back a connection to a different destination; and every transport socket within one cluster carries identical sanURIs and sni (egress.go:466 is a single call; transportsocketmatch.go:120-127 varies only the client-cert SDS name), so even a maximally wrong socket selection cannot change what is expected of the peer.

    So: this omission mis-attributes identity on success; it cannot mis-report it on failure. #829 has a separate and now-identified cause (upstream TLS session resumption). This issue stands entirely on its own, and at higher severity than #829 — #829 fails closed and is visible as errors, this one fails open and is invisible by construction.

    Additional evidence for the fix

    A cheap discriminator that would prove the leak end to end, one line in agent/internal/xds/proxy/accesslog.go:

    kv("source_spiffe_id", "%FILTER_STATE(aether.source.spiffe_id:PLAIN)%")

    If a stream from one workload logs its own source_spiffe_id while the destination's XFCC reports a different identity for the same request, the leak is demonstrated rather than derived. :PLAIN is mandatory — the formatter defaults to TYPED and renders -, the same trap already documented at networkfilter.go:106-108. The filter-state key already exists and currently has exactly one reader; this is its identity twin.

    Until the Hashable fix lands, the runbook should state that XFCC-derived authorization is not sound on a node hosting multiple ServiceAccounts.

  3. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    Demonstrated: the mechanism is real, aether is not exposed. Refuted at step 4.

    Run against the pinned proxy (aether-proxy:cff8beb8…, 1.40.0-dev) in a new
    runtime harness, //test/mtlspool — PR #841. Both directions were measured, so
    this is no longer derived.

    The link that fails

    Steps 1-3 of the chain are all confirmed. envoy.string →
    Router::StringAccessorImpl, not Hashable;
    CommonUpstreamTransportSocketFactory::hashKey folds a downstream shared
    filter-state object into the pool hash only behind a successful
    dynamic_cast<const Hashable*>; the source SPIFFE ID contributes zero bytes
    to the pool key. That part of the report is exactly right, and I reproduced its
    consequence.

    The step that fails is the one immediately after:

    Pools are keyed by cluster + host and are shared across source identities on the node proxy.

    They are not shared. Every mesh cluster the node proxy builds sets
    connection_pool_per_downstream_connection: true —
    proxy.NewServiceCluster / proxy.NewTCPServiceCluster, fed by
    SnapshotCache.perDownstreamConnectionPool() (= !c.edge), covering the HTTP
    service clusters (cache/cluster.go:338,356,423) and the TCP floor
    (cache/capture.go:322). Envoy mixes the downstream connection id into the pool
    hash in both pool paths — cluster_manager_impl.cc:2189 (HTTP) and :2317
    (TCP), via ConnectionImplBase::hashKey → addIdToHashKey(hash, id()). One pool
    per downstream connection, and on the capture/outbound path a downstream
    connection is one pod, so there is nothing for a second source to inherit.

    The edge passes false, correctly — it has one identity, which cannot leak into
    itself.

    The measurement

    Two source workloads, different ServiceAccounts, one node, same upstream.
    The destination reports the URI SAN it actually verified — the same value the
    inbound listener stamps into XFCC (SANITIZE_SET +
    set_current_client_cert_details.uri). --concurrency 1, because pools are per
    worker thread.

    Negative control — the flag removed, i.e. the configuration this issue assumed:

      B req[0]:  destination verified spiffe://aether.internal/ns/demo/sa/source-a on upstream connection 1
      B req[1]:  destination verified spiffe://aether.internal/ns/demo/sa/source-a on upstream connection 1
      ...
      B req[10]: destination verified spiffe://aether.internal/ns/demo/sa/source-a on upstream connection 1
    source-b requests verified as something other than source-b: 11/11
    

    11/11, all on one upstream HTTP/2 connection. The escalation in the follow-up
    comment was right: under h2 this is steady state, not a race. The Envoy defect
    this issue describes is completely real — it simply requires a configuration
    aether does not have.

    Production configuration:

      A req[0..10]: destination verified .../sa/source-a on upstream connection 1
      B req[0..10]: destination verified .../sa/source-b on upstream connection 2
    

    Every request, own identity, own connection. The node identity has its own
    certificate in the harness so an on_no_match (#686/#825) cannot be mistaken for
    a pooling leak.

    So XFCC-derived RBAC/ext_authz is sound here — conditionally

    Not because the identity is in the pool key (it is not), but because the pool is
    never shared. That makes connection_pool_per_downstream_connection security
    configuration on the node proxy, not a throughput knob
    — and nothing said so
    where someone tuning connection pooling would look. That was the real gap this
    issue exposed, and it is now closed three ways in #841:

    • TestNodeProxyPerSourceClustersPoolPerDownstreamConnection fails the build if
      any cluster with a per-source transport_socket_matcher loses the flag
      (verified red by flipping perDownstreamConnectionPool());
    • //test/mtlspool keeps the runtime property under test, with the negative
      control as its own proof that the green result can fail;
    • the runbook's "Why a wrong cert cannot leak across sources through pooling"
      note is upgraded from derived to demonstrated and says plainly not to turn the
      flag off.

    The observability suggested here shipped

    source_spiffe_id is now an access-log attribute (:PLAIN, as flagged — TYPED
    renders - for a StringAccessorImpl), and the pinned Envoy parses it in
    //test/envoy_validate. Joined to the destination line's
    downstream_peer_uri_san (#824) on x_request_id, the claimed and the verified
    identity must agree. A disagreement is a matcher miss or a pooling leak — the
    discriminator this issue asked for, in place regardless of the verdict.

    Not established

    • Not measured on talos-main (out of scope). The harness is single-worker on
      loopback; the production proxy's many workers only make sharing less likely.
    • UDP (NewUDPServiceCluster) carries no flag and no client certificate — mesh
      UDP is plaintext by design, so there is no identity to leak, but nothing here
      examined it.

    Carried forward as separate issues

    • The Hashable fix is still the right end state: it would let the mesh drop
      connection_pool_per_downstream_connection and recover cross-source upstream
      multiplexing, which is real throughput currently being paid for correctness.
      The flag is a mitigation, not a design.
    • The independent hardening this issue proposed is untouched and still worth
      doing: DownstreamTransportSocket (transportsocket.go:35-49) pins no client
      SANs, so a spiffe://<td>/ns/*/sa/* prefix matcher would make the XFCC value
      structurally trustworthy.

    Closing as refuted-as-reported. The analysis was correct about Envoy and found a
    genuine documentation and regression-guard gap; it was wrong about aether's
    exposure.

  4. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    Refuted as reported — see the demonstration above. Follow-ups split out per finding: #842 (make the filter state Hashable so the mitigation flag can come off) and #843 (pin a workload-SVID URI SAN prefix on the inbound validation context). PR #841 carries the harness, the access-log discriminator, the regression guard and the runbook update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions