Skip to content

fix(registry): kubernetes backend must not serve managed pods as TCP endpoints - #430

Merged
bpalermo merged 1 commit into
mainfrom
fix/mesh-http-k8s-registry-protocol
Jun 29, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/mesh-http-k8s-registry-protocol

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Problem

The MESH-HTTP conformance score was stuck at 5 PASS / 3 FAIL (MeshHTTPRouteRedirectHostAndStatus, MeshHTTPRouteRequestHeaderModifier, MeshFrontend). Prior investigation attributed the fails to registrar-replica churn; live config_dump on a kind mesh proxy disproves that and pins the real cause.

Root cause (config_dump evidence)

On a local kind mesh (aether + SPIRE off + redirect-all + the conformance echo shapes), curl from a meshed pod gave deterministic, non-churn results:

shape before
echo/set (RequestHeaderModifier, backendRef echo-v1:8080) 503 5/5
echo-v2/ (MeshFrontend, backendRef echo-v2:80) 503 5/5
echo/host-and-status (Redirect, no backend) 301 5/5

The cap_http RouteConfiguration was correct — the /set route carried request_headers_to_add: X-Header-Set, the redirect routes emitted Route_Redirect, the catch-all forwarded to the backend cluster. But the referenced outbound clusters (echo-v1.<ns>.aether.internal, echo-v2.<ns>.aether.internal) were absent from CDS — only the inbound app_*/health_* static clusters + passthrough_original_dst were present. Agent snapshot logs showed clusters:7, vhosts:0, tcpCount:3 in steady state. Redirect "worked" because it needs no backend cluster; every backendRef-forwarding route 503'd with no_healthy_upstream.

The Kubernetes registry backend (the conformance/CI registry) derives every endpoint from a managed pod's mesh-inbound (HTTP/h2) listener and ignored the protocol argument, returning the same pod set for a PROTOCOL_TCP query as for HTTP. The agent's LoadClustersFromRegistry builds each service's HTTP cluster + GAMMA cap_http vhost from the HTTP listing, then in a second pass overwrites the same map key with a vhost-less tcp:true entry from the TCP listing — relying on the invariant "a service is HTTP or TCP, never both" (true for etcd/ddb, which key endpoints by protocol). The kubernetes backend violated it: every mesh service collapsed to a TCP-only entry, dropping its CDS cluster and GAMMA vhost.

Fix

The kubernetes backend treats HTTP/UNSPECIFIED as the served protocol and returns no endpoints for PROTOCOL_TCP (ListAllEndpoints → empty map, ListEndpoints → nil). HTTP/UNSPECIFIED behaviour is unchanged; etcd/ddb backends are unaffected. Production posture (SPIRE on, real TCP services via etcd/ddb) is untouched.

Validation (live kind, SPIRE off, redirect-all)

After the fix the agent snapshot goes clusters 7→10 / vhosts 0→3 / tcpCount 3→0, the three outbound service clusters appear in CDS, and curl from a meshed pod:

shape after
echo/set → backend sees RequestHeader=X-Header-Set:set-overwrites-values 200 ✓
echo-v2/ response header x-header-set: set 200 ✓
echo/hostname-redirect → 302 Found + location: http://example.org/hostname-redirect ✓
echo/host-and-status → 301 Moved Permanently + location: http://example.org/host-and-status ✓

Added TestKubernetesRegistry_TCPProtocolReturnsEmpty as a regression guard. All registry/cache/registrar tests pass.

🤖 Generated with Claude Code

…endpoints

The Kubernetes registry derives every endpoint from a managed pod's
mesh-inbound (HTTP/h2 over :15008) listener; it has no per-pod TCP service.
But ListEndpoints/ListAllEndpoints ignored the protocol argument and returned
the same pod set for a PROTOCOL_TCP query as for HTTP.

The agent's LoadClustersFromRegistry builds each service's HTTP cluster (and
its outbound/cap_http GAMMA vhost) from the HTTP listing, then in a second
pass OVERWRITES the same map key with a vhost-less tcp:true entry from the TCP
listing — relying on the invariant "a service is HTTP or TCP, never both"
(true for etcd/ddb, which key endpoints by protocol). The kubernetes backend
violated that invariant: every mesh service collapsed to a TCP-only entry, so
its CDS cluster and GAMMA cap_http vhost disappeared from the proxy snapshot
and captured requests routing to it 503'd (no_healthy_upstream).

This is the root cause of the MESH-HTTP conformance MeshHTTPRouteRequestHeaderModifier
and MeshFrontend fails (and intermittently RedirectHostAndStatus's forwarding
paths): live config_dump on a kind mesh proxy showed cap_http routes correctly
carrying the header mutation / redirect / weighted backends, but referencing
`<svc>.<ns>.aether.internal` clusters that were absent from CDS (only inbound
app_*/health_* + passthrough present), snapshot vhosts:0, tcpCount:3.

Fix: the kubernetes backend treats HTTP/UNSPECIFIED as the served protocol and
returns no endpoints for PROTOCOL_TCP (ListAllEndpoints returns an empty map,
ListEndpoints nil). HTTP/UNSPECIFIED behaviour is unchanged; etcd/ddb backends
are unaffected. Validated live on kind (SPIRE off, redirect-all): after the
fix the agent snapshot goes clusters 7→10 / vhosts 0→3, the three outbound
service clusters appear in CDS, and curl from a meshed pod returns
X-Header-Set:set-overwrites-values to the backend, 301/302 + Location
example.org for redirects, and the echo-v2 response X-Header-Set:set for the
MeshFrontend shape.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S
@bpalermo

Copy link
Copy Markdown
Owner Author

Conformance run results + honest residual

Two clean kind MESH-HTTP runs post-fix (no manual interference). The fix is data-plane-complete but the upstream suite still times out on a separate convergence artifact.

Every failing shape now returns the exact expected conformance response, stably, via the suite's exact request:

shape exact suite request result
RequestHeaderModifier client http://echo/set --method=GET -H Some-Other-Header:val -H X-Header-Set:some-other-value backend sees X-Header-Set:set-overwrites-values — 10/10, and 50/50 clean, 40/40 clean even under active route churn (0 passthrough leaks)
Weight client http://echo/ 30/10 of 40 (≈75/25, matches 70/30)
MeshFrontend client http://echo-v2/ 200 + resp x-header-set: set 8/8
RedirectHostAndStatus client http://echo/host-and-status / /hostname-redirect 301 / 302 + location: http://example.org/... 8/8

Live config_dump after the fix: agent snapshot clusters 7→10, vhosts 0→3, tcpCount 3→0; the three outbound <svc>.<ns>.aether.internal clusters appear in CDS. Steady-state churn = 0 snapshots/60s.

Residual (orthogonal to this PR, pre-existing)

The suite stayed 4 PASS / 4 FAIL because RequiredConsecutiveSuccesses=3 is never met: the run log shows the modifier applied 271× (set-overwrites-values present) but requests intermittently leak to the redirect-all ORIGINAL_DST passthrough (kube-proxy, no GAMMA → got some-other-value) during the suite's own cross-test apply/delete churn — a harness/RDS-reload convergence race I cannot reproduce manually even under deliberate churn. Same 300s-timeout signature existed in the pre-#430 baselines. This PR removes the deterministic 503 config root cause (the load-bearing fix); the consecutive-success convergence artifact is a separate next hop (candidates: atomic cap_http RDS reload, or scope redirect-all passthrough to never shadow a known route target).

mesh-http CI job stays SOFT; GATEWAY-HTTP hard gate untouched.

@bpalermo
bpalermo merged commit 1360290 into main Jun 29, 2026
14 checks passed
@bpalermo
bpalermo deleted the fix/mesh-http-k8s-registry-protocol branch June 29, 2026 01:25
bpalermo added a commit that referenced this pull request Jun 29, 2026
#431)

Mirrors the keying contract (#428) for the second cross-backend invariant the
agent's LoadClustersFromRegistry relies on: a service serves HTTP xor TCP, never
both (cluster.go: the TCP cluster pass overwrites the HTTP map key, so a service
under both protocols loses its cluster + GAMMA vhost — the #430 kubernetes-backend
bug). registrytest.RequireProtocolDisjoint(httpServices, tcpServices) fails if any
service key appears under both. Wired into the kubernetes backend's protocol test.

Same consistency model as the keying work: one invariant, one shared contract that
every backend test can run, so a backend ignoring the protocol arg fails CI rather
than silently collapsing services to TCP-only.


Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S

Co-authored-by: Claude Opus 4.8 <[email protected]>
bpalermo added a commit that referenced this pull request Jun 29, 2026
…arget (#432)

The MESH-HTTP feature tests (RequestHeaderModifier / MeshFrontend / Redirect /
Weight) flaked: the modifier applied 271x in-suite but never hit
RequiredConsecutiveSuccesses=3 in a row. Root cause is an RDS-reload convergence
race under the conformance suite's own cross-test apply/delete churn — NOT config
generation (proven correct by #423/#424/#430 + stable-config curl).

Mechanism: a GAMMA HTTPRoute add/delete makes the gamma reconciler re-list and
re-`SetServiceRoutes` between two reconciles. In the delete→create gap the route
target's `serviceRoutes` entry is momentarily empty, so its dedicated cap_http
vhost is absent. Envoy's per-RouteConfiguration RDS apply is atomic, so the leak
implies the PUSHED table was itself missing the vhost: an in-flight captured
request to that KNOWN target then lands on the redirect-all catch-all (domain "*")
and falls to `passthrough_original_dst` → kube-proxy → the GAMMA filters are
silently skipped ("got some-other-value"), resetting the consecutive-success
counter. Not reproducible manually (the stable-config curl always runs between
rebuilds); only under the suite's rapid churn.

Fix (direction 2, the robust invariant): the passthrough must never shadow a
service the mesh knows about. The redirect-all catch-all now carries a
known-target safety net — one `:authority` safe_regex route per in-scope mesh
authority (all non-mesh cluster.local spellings, any port), pinning it to its mesh
cluster BEFORE the passthrough fallthrough. The set is derived from the STABLE
signals (captureAuthorities, fed by the generated mesh Services and untouched by
HTTPRoute churn, plus current route targets) — deliberately NOT the demand-scoped
dependency set, whose route-target membership churns with the rule and would
re-introduce the race. A known service's captured traffic therefore fails CLOSED
into the mesh (a brief 503 if the demand-scoped cluster is momentarily absent,
which the harness cleanly retries) instead of OPEN to kube-proxy. The dedicated
vhost still wins on host-match precedence when present and carries the GAMMA
filters; this is the floor.

Scope: redirect-all capture only (no passthrough ⇒ nothing to shadow ⇒ catch-all
keeps its hard 404). GATEWAY-HTTP (edge) and production mTLS paths untouched.

Tests: proxy-level (a known target resolves to its cluster under every spelling +
port, never the passthrough; foreign/mesh-shaped authorities unaffected; gated on
redirect-all), cache-level (the safety net survives a simulated GAMMA-rule-clear
churn even as the dedicated vhost vanishes), and `envoy --mode validate` accepts
the new route shape.


Claude-Session: https://claude.ai/code/session_01N7oY7W8oDXrqDzFgoZh25S

Co-authored-by: Claude Opus 4.8 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 21, 2026
…ackend (#888)

The kubernetes backend returned nil for every PROTOCOL_TCP query, so a pod
annotated `endpoint.aether.io/protocol: tcp` was accepted at registration and
silently dropped on read. On the chart-default backend the operator saw
Accepted=True on their TCPRoute and no endpoints, with no diagnostic (#878).

The blanket return was a workaround, not a property of Kubernetes, and its own
comment said so. The real cause was one layer down: podToEndpoint never read
the protocol annotation, so every managed pod looked like an HTTP endpoint and
answering a TCP query with that same set made every mesh service collapse to a
TCP-only entry -- LoadClustersFromRegistry overwrites the HTTP cluster + GAMMA
cap_http vhost with a vhost-less tcp:true entry, and captured requests 503'd
(#430). Reading the annotation removes the need for the workaround.

Both listings now filter on the pod's declared protocol, in BOTH directions:
returning HTTP pods under TCP is #430, and returning TCP pods under HTTP is the
same bug mirrored. "A service is HTTP or TCP, never both" still holds, because
every pod behind one ServiceAccount carries the same annotation, so
RequireProtocolDisjoint keeps passing -- and now has a call site where both
maps are non-empty and it can actually fail.

Also fixes a second missing parser found alongside it: podToEndpoint never read
endpoint.aether.io/ports either, so Ports was nil on every endpoint this
backend returned and proposal 005's per-port EDS membership silently did
nothing here while working on the write-based backends.

Both omissions had one cause -- two copies of the annotation parsers that
drifted by OMISSION rather than disagreement -- so the parsers move to a shared
leaf package, //registry/endpointmeta, alongside //registry/export.

The health-check mode deliberately does NOT move. The two readings differ on
the UNSET case and the difference is load-bearing: the CNI path defaults to EDS
(delegated liveness is its default) while this backend must default to
UNSPECIFIED, because it derives endpoints from the API server and the delegated
active-HC path applies only to the write-based backends. Unifying them would
have silently flipped the CNI registration path in production. Both sides now
say so.

No behaviour change for the existing fleet: with no protocol annotation a pod
is HTTP, which is what every managed pod is today, so the TCP listing stays
empty exactly as before.

Negative controls, both seen red before landing:
  - restoring the blanket TCP short-circuit fails 2 subtests of
    TestListEndpointsFiltersByPodProtocol (and only those -- the
    mirror-direction cases pass either way, as they should);
  - setting Ports back to nil fails 11 subtests.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 21, 2026
…889)

Both cluster passes wrote c.clusters[serviceName]. The HTTP pass built a
service's h2 cluster, outbound vhost and GAMMA cap_http vhost; the TCP pass ran
second and OVERWROTE the same key with a vhost-less tcp:true entry. A service
present in both listings therefore lost its cluster and both vhosts, and
captured requests to it 503'd with no_healthy_upstream -- the #430 failure
mode.

That was unreachable while a service could only be one protocol. It is not any
more. The registry key is <ns>/<serviceAccount> and the protocol is a PER-POD
annotation, so a ServiceAccount whose pods disagree -- `protocol: tcp` on half
a Deployment -- puts one service in both listings. True on etcd all along (the
CNI registers each pod under its own protocol key), and on the kubernetes
backend since #878.

TCP entries are now keyed by their own Envoy cluster name, "tcp:<fqdn>", as
per-port and alias entries already were. The four readers that looked a TCP
service up by bare key follow: captureTCPClusters and edgeTCPClusters take the
TCP entry (which also pins the right SANs -- for a split service the two
entries have DIFFERENT endpoints), captureUDPClusters takes whichever entry
carries the service-level facts it needs, and edgeMeshClusterNameLocked now
correctly reports "not found" for a TCP-only service instead of returning an h2
cluster name that clustersEndpointsAndVhosts never emits.

Bare-name CLA ownership: both entries reference an EDS resource named for the
service, so exactly one may publish it. The HTTP entry owns it when the service
has one; otherwise the TCP entry does. Two EDS resources under one name is a
snapshot-consistency error in go-control-plane, or a silent last-writer-wins.

retainAbsentClustersLocked now names a rebuilt load assignment after the one it
replaces rather than after the map key. Those coincide for HTTP and per-port
entries, but a TCP entry is keyed "tcp:<fqdn>" while publishing the BARE-name
resource its floor cluster resolves through -- keying off the map key there
would have retained an empty CLA under a name nothing references and left the
real one unpublished.

Two deviations from the accepted proposal, both recorded in it:

  - RequireProtocolDisjoint is NOT retired here. Its specified replacement
    asserts the two listings' port_protocols agree, and that field arrives in
    Phase 2; retiring now drops a working guard for nothing. Annotated in place
    as a convention rather than an invariant.
  - envoy_validate gains no case. Phase 1 changes no Envoy resource SHAPE, and
    the risk it introduces (duplicate EDS name) is invisible to
    `envoy --mode validate`, which does not resolve dynamic cluster refs. A
    gate that cannot fail is not a gate (#853).

Negative control: with both production files restored to main and the new test
file unchanged, exactly the two new tests fail and no existing test does --
Phase 1 is additive at the xDS contract.

Not yet a usable mixed service: the capture chain is still the portless /32 for
TCP-classified services, so a split service's HTTP side is still shadowed by
it. That is Phase 2, which adds the TCP mesh port.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant