Skip to content

Make the source-identity filter state Hashable so the mesh can drop connection_pool_per_downstream_connection #842

Closed

Description

@bpalermo

Split out of #831, which established (PR #841) that aether is not exposed to the
cross-source certificate leak because every node-proxy mesh cluster sets
connection_pool_per_downstream_connection: true.

That flag is a mitigation, not a design. It buys correctness by giving every
downstream connection its own upstream pool, which means the node proxy cannot
multiplex
streams from different source pods onto a shared upstream HTTP/2
connection. On a node with many pods talking to the same service that is a real
and permanent cost: one upstream connection per downstream connection, one
handshake each, and no h2 stream concurrency benefit across sources.

The root cause is narrow and fixable upstream. set_filter_state's default
FactoryKey: "envoy.string" builds a Router::StringAccessorImpl
(source/common/router/string_accessor_impl.h), which implements StringAccessor
only. CommonUpstreamTransportSocketFactory::hashKey
(source/common/network/transport_socket_options_impl.cc:47-53) folds a
downstream shared filter-state object into the upstream pool hash only if
dynamic_cast<const Hashable*> succeeds. Envoy already ships a hashable variant
(envoy.hashable_string → HashableString); the set_filter_state config has no
way to ask for it for an inline literal.

Two shapes, either of which is enough:

  1. a hashable: true knob on FilterStateValue that selects the hashable string
    factory, or
  2. upstream a Hashable string filter-state factory registered under a name the
    control plane can put in factory_key.

With that, aether.source.spiffe_id lands in the pool key and pools separate by
identity rather than by connection — which is the correct granularity: pods
sharing a ServiceAccount could then share upstream connections, and pods that do
not, could not. connection_pool_per_downstream_connection could come off every
mesh cluster.

aether already carries Envoy patches (proxy/), so this is tractable here before
it lands upstream.

Do not start this without re-reading #841's runbook note. The flag and the
matcher key are a pair: removing the flag before the filter state is hashable
re-opens the leak that //test/mtlspool's negative control reproduces (11/11
requests from the second ServiceAccount verified as the first). Sequence it as
hashable-first, flag-off-second, with //test/mtlspool green at every step.

Activity

  1. added
    enhancement
    on Sep 20, 2026
  2. self-assigned this
    on Sep 20, 2026
  3. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    Correction to the framing, before anyone picks this up: aether carries no Envoy patches, so a local patch is not a cheap fallback.

    I had described one as a fallback "since we already carry Envoy patches". We do not. Verified: no *.patch or *.diff anywhere, no patches/ directory, and proxy/MODULE.bazel has no single_version_override, archive_override, git_override or patch machinery. Envoy is consumed as a clean bzlmod dependency.

    What I confused it with is the proxy/ workspace, which does something different and better: it composes Envoy rather than modifying it. proxy/source/extensions/filters/http/aether_stats is our own extension, and //:envoy is an envoy_cc_binary built against @envoy as an ordinary dependency with that extension linked in. Upstream source is untouched.

    Two consequences:

    1. Taking a local patch would mean introducing patch machinery to this repo for the first time — a single_version_override, a patch file to rebase across every future snapshot, and the loss of the clean-composition property. That is a real and recurring cost, not a shortcut.
    2. The extension mechanism cannot solve this. Hashable is a property of the object set_filter_state produces, and the dynamic_cast happens inside Envoy's transport-socket machinery — not in any filter we can supply. There is no way to fix this from our own extension.

    So this is genuinely gated on upstream, with no local escape hatch cheaper than the problem. Which strengthens the case for leaving it parked: the mitigation (connection_pool_per_downstream_connection: true) is correct, now guarded by //test/mtlspool against silent removal, and the cost is latency we have measured and lived with (~25 ms of a 29 ms p50 hop is a fresh handshake, per #735's attribution).

    An upstream plan has been requested from someone with Envoy expertise, covering: which API shape upstream would accept (hashable: true on set_filter_state versus a Hashable string factory), prior art, whether a runtime guard is expected, the pool-cardinality objection reviewers will raise, the test surface, and realistic lead time to a published snapshot. If the answer is that upstream is unlikely to take it, that is equally useful — it means the mitigation is permanent rather than interim, and we should stop describing it as a workaround.

  4. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    No upstream change is needed — the factory already exists, and it is in the commit we pin

    envoyproxy/envoy#43208 ("filter state: add hashable string factory", merged 2026-02-02, commit 35749578db) added a second generic factory beside envoy.string. Verified present at our pin 13144fb, in source/extensions/filters/common/set_filter_state/filter_config.cc:

    class HashableString : public Router::StringAccessorImpl, public Hashable {
    public:
      HashableString(absl::string_view value) : StringAccessorImpl(value) {}
      std::optional<uint64_t> hash() const override { return HashUtil::xxHash64(asString()); }
    };
    
    class GenericHashableStringObjectFactory : public StreamInfo::FilterState::ObjectFactory {
      std::string name() const override { return "envoy.hashable_string"; }
      ...
    };
    REGISTER_FACTORY(GenericHashableStringObjectFactory, StreamInfo::FilterState::ObjectFactory);

    Present on main, release/v1.38 and v1.39; absent from v1.37. Documented in well_known_filter_state.rst ("Same as envoy.string but supports connection pool hashing when shared with the upstream ... use with care as it can lead to significant increase in the number of upstream connections"), and security/secret.rst uses it for exactly our shape — selecting an upstream client certificate per filter-state value.

    So this issue is not upstream-gated, is not large, and needs no patch. Everything in my previous two comments about lead time, patch machinery and API-shape negotiation is moot.

    What actually has to change

    One string. agent/internal/xds/proxy/networkfilter.go:180 — FactoryKey: "envoy.string" → "envoy.hashable_string".

    The sharing precondition is already satisfied. hashKey only iterates options->downstreamSharedFilterStateObjects(), so an unshared object would never reach the hash regardless of Hashable. We already set SharedWithUpstream: ONCE (networkfilter.go:201), and the existing comment explains why ONCE rather than TRANSITIVE. That reasoning is unaffected.

    Nothing else should need touching. HashableString still derives from StringAccessorImpl, so %FILTER_STATE(...)% formatters and the transport-socket matching input keep working — the matcher input reads via serializeAsString(), which it inherits.

    Then drop connection_pool_per_downstream_connection: true from the mesh clusters. Pools partition per (host, source identity) instead of per downstream connection, which is the most sharing that is correct here, since the client certificate is per identity.

    Sequencing — do not collapse these

    The safe order is: switch the factory → prove the identity actually reaches the pool hash → only then drop the flag. Dropping it before partitioning is confirmed re-opens the leak, and it fails open: XFCC reports the wrong caller and nothing errors.

    //test/mtlspool already has the harness and the negative control. The assertion to add: with envoy.hashable_string + ONCE and the flag off, the destination attributes 11/11 of source-B's requests to source-B, and there are two upstream connections — one per identity — rather than one or N. Keep the envoy.string case red so the test pins the reason and not just the outcome.

    Cardinality

    The upstream answer to the footgun concern was to make this an explicitly named factory with a docs warning rather than a boolean, so the value must stay bounded — the SPIFFE ID (bounded by workloads per node) is fine, anything per-request is not. Worth a comment at the call site saying so.

    Credit: identified by the envoy session; independently verified here against the pinned source and our own config.

  5. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    rev228 FAILED on talos-main — rolled back. #863 must not be redeployed as-is.

    Deployed 16:03:39→16:05:58Z as helm rev228 (chart 0.93.0-297db48). Rolled back to the rev227 chart at 16:13Z (helm rev229). Outage window 16:05:57Z → ~16:15Z, ~9 minutes, costing ~27,988 mesh_dns timeouts and 122 http_errors. Full record: project_deploy_20260920_rev228.md.

    The failure

    At the instant the new proxies took the config, every mesh upstream mTLS connection stopped completing. They pause, they do not fail — so essentially none of the evidence you would look for exists:

    • envoy_cluster_ssl_connection_error_total — no new series
    • envoy_cluster_ssl_fail_verify_san_total — 0 series
    • upstream_transport_failure_reason:!="-" — 0 access-log records

    The only signature is source-side access logs: upstream_host selected, upstream_peer_uri_san="-", duration_ms≈1980, response_flags=DC — the client gives up first.

    signal rev227 rev228
    liveness 25/s, 0 errors 25/s, 0 errors — never affected
    mesh_dns success ~50/s frozen from ~16:06:30Z
    mesh_dns timeout 368 28,356, climbing ~50/s, no recovery
    authz canary allow=200 deny=403 allow=000000, first FAIL 16:05:57Z

    The local data path was fine throughout — this is upstream-mTLS only. The authz deny leg still returned 403 because ext_authz decides locally; only the allow leg, which needs a real upstream, failed. Same-node upstreams failed too.

    What PASSED, and is worth preserving in any replacement

    A brand-new ServiceAccount pod ADD warmed ZERO clusters — 120/120 samples across all five nodes, where rev225–227 cost a full re-warm wave (every cluster, ~15 s) on the receiving node. The identity set genuinely is out of the cluster bytes. This property is independent of the bug and is the thing #815 could never achieve across three releases. Whatever replaces this PR should keep it.

    Corrections to the issue's own assumptions

    cert_updated does not exist. Exported names are envoy_cluster_on_demand_secret_cert_requested_total and envoy_cluster_on_demand_secret_cert_active — nothing else. The "requested climbing without updated" check specified in the deploy brief was not expressible. requested vs active is the substitute, and note it is not a health signal: requested==active on w01–w04 while the mesh was fully broken. Only w05 diverged (requested=55, active=28).

    cluster_name does not resolve to the mesh cluster. Measured on real traffic: it is always the literal aether-proxy; the mesh cluster is upstream_cluster (e.g. aether-test/echo). Attributes are flat log-record attributes under stream {service.name=""}, field log_name:"aether_access_logs"; reporter=source carries source_spiffe_id as a workload SPIFFE ID, reporter=destination carries downstream_peer_uri_san with source_spiffe_id="-". This matters for k8s-talos-main: a connector keyed on cluster_name collapses every mesh cluster into one series.

    Not established

    Checks for pool partitioning and for both filter-state keys being present on the listeners are not gradeable from this run — with handshakes never completing, connection counts and peer identities are meaningless. A deliberate proxy roll and agent roll were not performed; the STOP fired first.

    So the mechanism is unproven in both directions: we know it breaks, and we do not know whether the parts that were supposed to work do.

    The lesson for the next attempt

    This shipped on source reading plus an in-process harness. The harness proved pool partitioning against a real Envoy binary — it never exercised on-demand SDS against SPIRE, which is exactly where it failed. Any retry needs that path exercised before a cluster sees it, and the failure mode to design the test around is a pause, not an error: no stat moves, nothing logs a failure, and a naive "is the mesh up?" check reads healthy right up until requests time out.

  6. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    Correction: cert_updated does exist — and its absence was the proof, not a gap

    My earlier comment on this issue stated:

    cert_updated does not exist. Exported names are envoy_cluster_on_demand_secret_cert_requested_total and envoy_cluster_on_demand_secret_cert_active — nothing else. The "requested climbing without updated" check specified in the deploy brief was not expressible.

    That is wrong, and it is the sharpest possible way to be wrong here. Re-querying the same 16:00–16:20Z window:

    envoy_cluster_on_demand_secret_cert_requested_total
    envoy_cluster_on_demand_secret_cert_updated_total     <-- exists
    envoy_cluster_on_demand_secret_cert_active
    

    It was absent because it was zero. This pipeline does not export a counter that was never incremented, so an absent counter and a zero counter are the same observation — which is exactly the "absence is not a missing metric" trap, walked into while looking straight at it.

    And the absence was not a gap in the evidence. It was the evidence. cert_updated is incremented in exactly one place: the completion callback of the selector's setContext (cert_selectors/on_demand/config.cc:204-215), reachable only from a secret actually arriving (or being removed). Zero therefore proves no SDS payload ever reached the selector — which is the whole outage in one counter. The deploy brief's "requested climbing without updated" check was expressible, was the right check, and would have named the root cause on the day.

    Two further corrections that follow from it:

    requested vs active is not a substitute. cert_active counts live secret subscriptions and is incremented on the same line as cert_requested (config.cc:105-106). Equality means only "nothing has been removed" — it reads equal in a completely healthy run. It is not a health signal in either direction.

    w05 (requested=55, active=28) is resolved, and is not an independent finding. It is a hot-restart accounting artefact. Per-node series:

    16:05:30Z 16:06:00Z onward
    cert_active 55 28
    cert_requested 55 55

    with envoy_server_live = 2 and envoy_server_hot_restart_epoch 0 → 1 at 16:05:00Z. Two Envoy epochs were live and both exporting; when the parent's series went away the summed gauge fell to the child's alone while the counter kept the merged total (StatMerger transfers gauges absolute, counters as deltas). No doRemoveCertificateConfig ran — consistent with cert_updated == 0. Nothing to file.

    Corollary worth keeping: cert_requested and cert_active cannot be compared across a hot restart at all.

    The signal that actually localises the failure, and which nobody looked at on the day, is envoy_sds_spiffe_<mangled>_init_fetch_timeout_total — an SDS subscription that sent a request and got no answer within 15 s. During the outage it climbed for the node SVID (2 → 6), prober (1 → 6), authz_canary and uds_client (0 → 1): every one of them a name that is also statically referenced, which is the root cause in a metric.

    Root cause and fix: #865.

  7. bpalermo commented on Sep 20, 2026

    @bpalermo
    OwnerAuthor

    Fixed and validated on talos-main — helm revision 230, 0.93.1-8d0d5da

    Correction: an earlier version of this comment called this "rev229". Revision 229 was the
    rollback to 227 that undid the failed rev228; the #842 fix landed as revision 230.

    PR #865 merged as 8d0d5da and deployed 2026-09-20T17:38:44Z; roll complete 17:41:10Z (~2.5 min, agent/proxy/mesh-dns all 5/5). PASS on every gate.

    gate rev228 (the outage) rev229
    ..._on_demand_secret_cert_updated_total absent — i.e. zero, which was the proof 157 (62 → 124 → 157, then saturated)
    envoy_sds_spiffe_*_init_fetch_timeout_total moved fleet-wide absent
    prober, 12 min spanning the roll ~28k mesh_dns timeouts, ~9 min outage 0 timeout, 0 http_error — 35,999 mesh_dns + 17,999 liveness success
    warming_clusters — peak 29–30 at proxy start (expected), settled to 0
    ssl_fail_verify_san / ssl_connection_error / ssl_session_reused — all absent — #829's fix still holding
    upstream_cx_connect_fail — 0 on every mesh (data-path) cluster. See the correction below.

    cert_updated flattening at 157 is the correct steady state, not a stall — it increments on delivery to the selector, so once every originating identity on a node holds one there is nothing to fetch until a rotation.

    The zero-timeout claim has a control: cert_updated = 157 comes from those same proxies, so the scrape path is demonstrably live and the missing series is a true zero rather than a dead instrument.

    Stream cost — first measurement, and a correction to the brief

    This was the one thing left unmeasured. sum(envoy_cluster_upstream_rq_active{aether_cluster="agent_xds"}) went 5 → 17 across the deploy: per node w01=5, w02–w05=3, i.e. 1 ADS + 2–4 lazy SotW SDS streams each. Against the agent's grpc.MaxConcurrentStreams(1000) that is negligible, and it tracks identity density as predicted (w01 is the densest node).

    ⚠ The metric named in the deploy brief cannot see this. envoy_cluster_upstream_cx_active{aether_cluster="agent_xds"} stayed flat at 5 across the whole deploy, because gRPC streams multiplex over a single HTTP/2 connection — it would have reported "no change" no matter how many streams opened. The right metric is upstream_rq_active (one active request == one gRPC stream). Worth remembering for any future xDS stream-count question.

    Closing. The 8 h soak is now unblocked.


    Correction: the connect failures were control-plane, not data-plane

    I originally reported "29 upstream_cx_connect_fail, roll-confined, absorbed by retries", which implied a transient on the data path. That was wrong on attribution, and the real result is cleaner than what I wrote.

    Broken out by cluster, the failures are entirely on agent_xds — Envoy's ADS socket to the node agent:

    sum by (aether_cluster) (envoy_cluster_upstream_cx_connect_fail_total)
      agent_xds  24
      (edge)      5
    

    Zero on any mesh cluster. The cause is the agent DaemonSet rolling (rev230 rolled all three node DaemonSets), not the proxy handoff: upstream_rq_pending_failure_eject steps by the same magnitude on the same nodes at the same instants — those ejected pending requests are the ADS stream requests — and envoy_control_plane_connected_state dips to 0 on all five nodes. The edge proxies show the same agent_xds ejects, and the edge proxy is not part of the proxy DaemonSet, which rules the proxy roll out as the cause.

    Two further notes worth carrying:

    • The number itself was inflated by an unsafe query. Node-proxy envoy_* series carry only a node label and no pod label, so during the surge overlap sum(increase(...[2m])) alternates between the outgoing and incoming pod. On w01 the raw counter was flat at 5 while increase() reported ≈16. Read raw counters across a roll window, not increase().
    • Nothing here changes the Make the source-identity filter state Hashable so the mesh can drop connection_pool_per_downstream_connection #842 verdict — the gates it turns on (cert_updated non-zero, SDS init-fetch timeouts absent, prober zero) are unaffected, and the data-path connect-failure count is zero rather than merely small.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions