Repository navigation
Description
Description:
isHTTPRouteFilterReferencingSecret in internal/provider/kubernetes/predicates.go
(function starts at line 309 on current main; the buggy fall-through is its
final statement) returns true on both branches:
func (r *gatewayAPIReconciler) isHTTPRouteFilterReferencingSecret(nsName *types.NamespacedName) bool {
routeFilterList := &egv1a1.HTTPRouteFilterList{}
if err := r.client.List(context.Background(), routeFilterList, &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(secretHTTPRouteFilterIndex, nsName.String()),
}); err != nil {
r.log.Error(err, "unable to find associated HTTPRouteFilter")
return false
}
if len(routeFilterList.Items) > 0 {
return true
}
return true // BUG: should be `return false`
}The final return true should be return false (compare the sibling helpers,
e.g. isBackendTLSPolicyReferencingSecret / isCtpReferencingSecret, which
return len(list.Items) > 0).
Because this helper is part of the validateSecretForReconcile predicate chain
on the cluster-wide Secret watch, and because it is gated only on the
HTTPRouteFilter CRD existing (r.hrfCRDExists) — not on any HTTPRouteFilter
instances or secret references existing — the effective behavior is:
On any cluster where the HTTPRouteFilter CRD is installed (the default EG
install), every Secret create/update/delete event in the entire cluster passes
the predicate and enqueues a full reconcile: complete resource-snapshot
rebuild, full gateway-api translation of all routes/policies, and a full xDS
regeneration.
Expected behavior: a Secret event should only trigger reconciliation when the
Secret is actually referenced by a Gateway, SecurityPolicy, ClientTrafficPolicy,
EnvoyProxy, BackendTLSPolicy, EnvoyExtensionPolicy, HTTPRouteFilter
(credential injection), or Backend — which is exactly what the surrounding
predicate chain is built to do.
Impact observed in production: a secret-sync controller in our cluster rewrote
a CA-cert Secret in ~90 namespaces every ~30s (identical data, metadata-only
churn). This drove the Envoy Gateway controller to a sustained ~2–3 full
reconciles per second, indefinitely (verified 1:1: 94 Secret watch events and
94 reconciles counted in the same 30-second window). Any common noisy Secret
writer (external-secrets-operator refresh loops, cert-manager renewal waves,
Vault sidecar lease rotation, etc.) reproduces this on any EG install.
Secondary impact: the sustained reconcile rate produces continuous back-to-back
XdsIR updates, which greatly widens the window for the watchable
DeepEqual-vs-mutation data race tracked in #9445 — in our environment this
escalated the predicate bug into a control-plane crash loop
(panic: reflect: slice index out of range in the coalesce goroutine, 20+
container restarts per pod over 3 days). Fixing this predicate removed the
sustained-reconcile regime and stopped the panics; the race itself remains and
is tracked separately in #9445.
The bug was introduced with the direct response feature (#4508, Oct 2024) and
is present in every release since (verified on v1.8.1, v1.8.2, and current
main).
Repro steps:
-
Install Envoy Gateway (default install; the HTTPRouteFilter CRD is included)
with any GatewayClass/Gateway. No HTTPRouteFilter instances are required —
only the CRD needs to exist. -
Port-forward the EG metrics endpoint and note the reconcile counter:
kubectl port-forward -n envoy-gateway-system deploy/envoy-gateway 19001:19001 & curl -s localhost:19001/metrics | grep 'controller_runtime_reconcile_total.*success'
-
Write an unreferenced Secret in a loop (any namespace, never referenced
by any Gateway API or EG resource):kubectl create ns predicate-test for i in $(seq 1 60); do kubectl create secret generic noisy -n predicate-test \ --from-literal=tick="$i" --dry-run=client -o yaml | kubectl apply -f - sleep 1 done
-
Re-check the reconcile counter: it increments 1:1 with the Secret writes
(~60 additional reconciles). Expected: 0 additional reconciles, since the
Secret is not referenced by anything. -
(Control) Apply the one-line fix (
return false) and repeat: the counter no
longer moves.
Environment:
- Envoy Gateway: v1.8.1 (docker.io/envoyproxy/gateway:v1.8.1); bug verified
present in v1.8.2 and currentmainas well; introduced in feat: direct response #4508 - Kubernetes: EKS v1.3x
- HTTPRouteFilter CRD installed (default EG CRD set); 10 HTTPRouteFilter
instances in-cluster (none referencing Secrets — the credential-injection
index lookup correctly returns an empty list, which is exactly the branch
that falls through toreturn true) - Cluster scale where measured: 2 Gateways / 2 GatewayClasses, ~57 HTTPRoutes,
13 GRPCRoutes, ~58 BackendTrafficPolicies, 7 EnvoyPatchPolicies
Logs:
Sustained reconcile storm on an otherwise change-free cluster (leader pod,
uptime ~30 min):
controller_runtime_reconcile_total{controller="gatewayapi-...",result="success"} 2749
workqueue_adds_total{controller="gatewayapi-...",name="gatewayapi-..."} 2749
watchable_publish_total{message="provider-resources",runner="provider",status="success"} 2749
watchable_event_total{event_type="update",runner="gateway-api"} 2531
watchable_event_total{event_type="update",runner="xds"} 4489
watchable_publish_total{message="httproute-status",runner="gateway-api",status="success"} 144267
watchable_publish_total{message="backendtrafficpolicy-status",runner="gateway-api",status="success"} 146798
1:1 correlation measured in the same 30-second window: 94 Secret MODIFIED
watch events (an external controller re-writing an unreferenced CA Secret
across namespaces) and reconcile counter delta of exactly 94
(8566 → 8660). After stopping the external Secret writer, the reconcile
counter froze completely (0 reconciles in 90s), with no other change to the
cluster or to EG.
Leader pod log volume during the storm (2-minute sample): ~7,500
"processing ..." provider log lines and ~6,800 "added ... to resource tree" lines, i.e. a full resource-tree rebuild roughly every 2 seconds with
no Gateway API resource changing.
Suggested fix (one line + regression test)
if len(routeFilterList.Items) > 0 {
return true
}
- return true
+ return false
}Regression test suggestion: with the HTTPRouteFilter CRD present and no
HTTPRouteFilter referencing the Secret, validateSecretForReconcile must
return false for an unreferenced Secret (this is the case that would have
caught the bug; the sibling is*ReferencingSecret helpers already have the
correct shape).
Activity
docs: add release note for envoyproxy#9486