Skip to content

fix(xds): pin the ConfigSource determinism contract Envoy's provider reuse depends on (#852) - #857

Merged
bpalermo merged 1 commit into
mainfrom
fix/852-config-source-hash-determinism
Sep 20, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/852-config-source-hash-determinism

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #852. Documentation and tests only — no production behaviour changes. agent/internal/xds/config/common.go is comment-only.

Headline: aether is safe, but both of #852's premises are wrong at the pin

Re-verified at 1.40.0-dev.20260904.13144fb (read via git show 13144fb:<path>, since #844's trace came from a checkout 211 commits ahead).

1. initial_fetch_timeout is EXEMPT from the RDS reuse key — not "the first field released into it".

RouteConfigProviderManager::addDynamicProvider (source/common/rds/route_config_provider_manager.h:47-54) releases it before hashing and puts it back after:

auto* orig_initial_timeout =
    const_cast<RdsConfig&>(rds).mutable_config_source()->release_initial_fetch_timeout();
const uint64_t manager_identifier = MessageUtil::hash(rds);
const_cast<RdsConfig&>(rds).mutable_config_source()->set_allocated_initial_fetch_timeout(
    orig_initial_timeout);

So two listeners differing only in initial_fetch_timeout do share a provider. #839's field is the one addition that could never have split anything. The normalisation is unconditional as of d9bda64c84 (envoy#40660, which retired the normalize_rds_provider_config runtime guard), and it is RDS-only — scoped RDS, ECDS and ODCDS hash it in.

Also worth recording: reuse matches on the hash alone. reuseDynamicProvider does a bare find(manager_identifier); route_config_name appears only inside a RELEASE_ASSERT message.

2. A map-typed field cannot split a provider.

MessageUtil::hash is DeterministicProtoHash::hash on any normal build (source/common/protobuf/utility.cc:166-172) — a reflection walk, not a serialisation — and it folds map entries with addition, with a comment saying that is exactly the point (source/common/protobuf/deterministic_hash.cc:78-100). Repeated non-map fields are walked in order and are hash-significant.

The hazard therefore redraws:

Envoy (provider reuse) go-control-plane (snapshot version)
map field safe (addition-folded) hazard — #135's mechanism, currently closed by the Deterministic marshals in TypedConfig and MarshalResource
repeated field from a map range hazard — splits the provider hazard
semantic divergence hazard n/a

Live Envoy-side risks are ConfigSource.authorities and, if api_config_source is ever used, grpc_services / initial_metadata / config_validators, plus a genuine semantic difference between call sites (resource_api_version set on one and not the other, ads vs an equivalent api_config_source).

Corrected blast radius

#852 claim Verdict What actually happens
Two subscriptions on the wire, doubled RDS traffic Wrong — and on aether, zero cost ads:{} resolves to the single process-wide ADS mux, and the chart's ads_config is api_type: DELTA_GRPC, so that mux is the delta one. Its WatchMap refcounts per resource name: findAdditions reports a name only when watch_interest_ had no entry (source/extensions/config_subscription/grpc/watch_map.cc:314-328), and only those names reach updateSubscriptionInterest (new_grpc_mux_impl.cc:323-335). A second watch on an already-watched name costs zero wire bytes. On the SotW mux it would instead be one redundant DiscoveryRequest at addWatch (grpc_mux_impl.cc:178-190, :298).
http.<prefix>.rds.out_http.* appears twice under different scopes Wrong as stated Scope is http.<hcm stat_prefix>.rds.<route_config_name>., and the process-wide allocator dedupes by stat name (source/common/stats/allocator.cc:299-316). Where the prefixes match, one series reads double — config_reload, update_success, update_attempt all +2 per push; version/update_time are set() and stay honest. That is aether's case for out_http and cap_http, whose HCM stat_prefixes are the constants outbound_http/capture_http. The per-Gateway edge listeners take their stat_prefix from the listener name, so a split there would give two separate trees.
No NACK, no warning, valid config, healthy proxy Right Nothing fires anywhere; there is no duplicate-name check in the manager and no log on the multi-watch path.

Costs #852 did not mention, all real: /config_dump lists the route config twice (dumpRouteConfigs emits one dynamic_route_configs entry per provider) — the unambiguous detection signal, independent of stat_prefix collision; two fully parsed route tables per worker thread; a second parse/build on every push; independent warming, each provider burning its own initial_fetch_timeout.

Hash-keyed sites aether actually reaches

  • RDS — hash(Rds) minus config_source.initial_fetch_timeout (route_config_provider_manager.h:47-54). Consumers: every pod's out_http, every pod's cap_http, and the per-Gateway edge HTTP + HTTPS + QUIC listeners, which all three name EdgeGatewayRouteName.
  • SDS — StrCat(hash(sds_config_source), ".", config_name, warm) (source/common/secret/secret_manager_impl.h:90-91). Every transport socket.
  • ECDS — StrCat(hash(config_source), ".", name) — subset.go's config_discovery.
  • ODCDS — hash(odcds_config), timeout included — httpfilter.go.
  • EDS is not hash-keyed (one subscription per cluster), but eds_config sits inside the Cluster proto that CDS hashes wholesale for its no-op guard.

Tests

agent/internal/xds/config/determinism_test.go (new) and one addition to filterchain_test.go, modelled on cache/determinism_test.go:

  • TestConfigSourceBytesIdenticalAcrossConstructions — 12 independent constructions of each ConfigSource must serialise identically. Uses a plain proto.Marshal: Deterministic:true canonicalises maps and would go quiet on half of what this is for.
  • TestConfigSourceCarriesNoMapField — walks the populated message tree and fails on any set map field. Catches the one-entry map the byte comparison misses.
  • TestOutboundChainRDSIdenticalAcrossPods — two pods differing in every field the chain builder reads must produce a byte-identical out_http Rds. Deliberately stricter than Envoy's own key.

Confirmed red first

Three temporary production edits, reverted before commit.

Jittered initial_fetch_timeout:

--- FAIL: TestConfigSourceBytesIdenticalAcrossConstructions/XDSConfigSourceADSWithInitialFetch
    expected: []byte{0x22, 0x8, 0x8, 0xf, 0x10, 0x80, 0xbc, 0xe7, 0xd1, 0x1, 0x1a, 0x0}
    actual  : []byte{0x22, 0x7, 0x8, 0xf, 0x10, 0xc0, 0x88, 0xec, 0x5f, 0x1a, 0x0}
    Messages: XDSConfigSourceADSWithInitialFetch produced different bytes on construction 1: ...

A 6-entry google_grpc.channel_args map in SDSConfigSourceFromCluster — both tests fire, the map test naming the exact path:

--- FAIL: TestConfigSourceCarriesNoMapField/SDSConfigSourceFromCluster
    SDSConfigSourceFromCluster.api_config_source.grpc_services[0].google_grpc.channel_args.args
    is a populated map field: ...
--- FAIL: TestConfigSourceBytesIdenticalAcrossConstructions/SDSConfigSourceFromCluster
    - 00000020  65 5f 61 67 65 6e 74 42  c0 01 0a 1e 0a 16 67 72  |e_agentB......gr|
    - 00000030  70 63 2e 6b 65 65 70 61  6c 69 76 65 5f 74 69 6d  |pc.keepalive_tim|
    + 00000020  65 5f 61 67 65 6e 74 42  c0 01 0a 21 0a 16 67 72  |e_agentB...!..gr|

A pod-derived timeout in the egress Rds:

--- FAIL: TestOutboundChainRDSIdenticalAcrossPods
    - 00000000  0a 0c 22 08 08 1b 10 80  f2 cc d1 02 1a 00 12 08  |..".............|
    + 00000000  0a 0c 22 08 08 1b 10 c0  b0 83 c3 01 1a 00 12 08  |..".............|
      00000010  6f 75 74 5f 68 74 74 70                           |out_http|
    Messages: the out_http Rds differs between pods: ...

Validation

bazel test //agent/internal/xds/... green (7/7). bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/internal/xds/... clean. make gazelle / make format run. Full //... is green except //agent/internal/proxy/hotrestart:hotrestart_test, which is a pre-existing 2s-tolerance timing assertion in coordination_test.go:150 that trips under parallel-build load — unrelated to this change, which touches no non-xds package. No charts/ change. Not deployed; talos-main untouched.

Could not establish

  • Nothing material. The two questions the source review left open were both closed afterwards:
    • Runtime-layer flags — resolved. aether ships no layered_runtime and no reloadable_features override anywhere in the chart or bootstrap (the only mention is a comment about hot_restart_propagate_stat_tags), so Envoy's compiled-in defaults stand: unified_mux and xdstp_based_config_singleton_subscriptions are both false.
    • The redundant DiscoveryRequest — moot. That cost belongs to the SotW mux; aether's ads_config is DELTA_GRPC, so the delta mux's WatchMap refcounting applies and the duplicate watch never reaches the wire at all.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

@bpalermo
bpalermo force-pushed the fix/852-config-source-hash-determinism branch from fd1533f to 142a59f Compare September 20, 2026 14:02
…reuse depends on (#852)

aether is safe today, and documentation-only — no behaviour changes. But #852's
two premises are both wrong at the pinned Envoy
(1.40.0-dev.20260904.13144fb), so the comment records what the source actually
says rather than what the issue assumed.

Correction 1: initial_fetch_timeout is EXEMPT from the RDS reuse key, not "the
first field released into it". addDynamicProvider releases
config_source.initial_fetch_timeout before MessageUtil::hash and restores it
after (source/common/rds/route_config_provider_manager.h:47-54), so two listeners
differing only there still share one provider. #839's field is the one addition
that could never have split anything. The exemption is RDS-only: scoped RDS, ECDS
and ODCDS hash it in.

Correction 2: a map-typed field cannot split a provider. MessageUtil::hash is
DeterministicProtoHash::hash on any normal build (utility.cc:166-172) — a
reflection walk, not a serialisation — and it folds map entries with ADDITION
precisely so order cannot matter (deterministic_hash.cc:78-100). Repeated
NON-map fields ARE walked in order and are hash-significant. So the live
Envoy-side hazard is a repeated field built by ranging a Go map
(ConfigSource.authorities, api_config_source's grpc_services / initial_metadata /
config_validators) or a genuine semantic divergence between call sites — not
serialisation skew. Maps stay a go-control-plane-side snapshot-version hazard,
which is #135's mechanism, currently closed by the Deterministic marshals in
TypedConfig and cache MarshalResource.

Blast radius, likewise corrected. It is NOT doubled RDS traffic: ads:{} resolves
to the one process-wide ADS mux, which rebuilds resource_names through a dedup
set on every request (grpc_mux_impl.cc:178-190), so the cost is a single
redundant DiscoveryRequest at addWatch and zero steady-state bytes. It is NOT a
new stat series where the HCM stat_prefixes match: the allocator dedupes by stat
name (allocator.cc:299-316), so one series reads DOUBLE — which is aether's case
for out_http and cap_http, whose stat_prefixes are the constants "outbound_http"
and "capture_http", while the per-Gateway edge listeners take theirs from the
listener name and would split into two trees. The unambiguous signal is
/config_dump, where dumpRouteConfigs emits one dynamic_route_configs entry per
provider. The real costs are two parsed route tables per worker, a second
parse/build per push, and independent warming. No NACK and no warning is right.

Adds three guards, all confirmed red before landing:

- TestConfigSourceBytesIdenticalAcrossConstructions: twelve independent
  constructions of every ConfigSource this package hands out must serialise
  identically. Uses a PLAIN proto.Marshal deliberately — Deterministic:true
  canonicalises map fields and would go quiet on half of what this is for.
- TestConfigSourceCarriesNoMapField: walks the populated message tree and fails
  on any set map-typed field, which the byte comparison misses for a one-entry
  map.
- TestOutboundChainRDSIdenticalAcrossPods: two pods differing in every field the
  chain builder reads must produce a byte-identical out_http Rds. Deliberately
  stricter than Envoy's own key.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo force-pushed the fix/852-config-source-hash-determinism branch from 142a59f to 79f84ce Compare September 20, 2026 14:04
@bpalermo
bpalermo merged commit 2b6acc4 into main Sep 20, 2026
21 checks passed
@bpalermo
bpalermo deleted the fix/852-config-source-hash-determinism branch September 20, 2026 14:15
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.

RDS provider reuse keys on a hash of the whole Rds message: any config_source byte change silently doubles subscriptions

1 participant