Skip to content

fix(chart): run the ext_authz sidecar as a native sidecar (#1275) - #1285

Merged
bpalermo merged 1 commit into
mainfrom
upgrade/authz-native-sidecar
Oct 5, 2026
Merged

bpalermo merged 1 commit into
mainfrom
upgrade/authz-native-sidecar

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

What

The ext_authz sidecar (proposal 027) in the aether-proxy pod is now a Kubernetes native sidecar: an init container with restartPolicy: Always, after install-supervisor and before proxy, with a startupProbe on the authz socket. Chart 2.4.9.

Closes #1275

Why

authz was the second regular container. The kubelet starts regular containers in order and does not wait for one before starting the next, so authz started after proxy. When its image had to be pulled (7–13 s on talos-main, on the first roll onto OPA 1.21.1), the new Envoy took the node's listeners with nothing listening on the authz socket. Every check in that window was an ext_authz error, which is a 403 under failureMode: DENY. On deletion both containers got SIGTERM at once, so OPA closed its socket while the old Envoy was still serving (successor_wait after kubectl delete pod, and drain_fallback).

Rendered pod spec (OPA preset on)

before (2.4.8) after (2.4.9)
initContainers install-supervisor install-supervisor, authz (restartPolicy: Always, startupProbe)
containers proxy, authz proxy

With the sidecar disabled (the default), the full helm template output is byte-identical to main's, apart from the randomly generated webhook certificates.

The probe

exec of the stdlib-only proxy-ready binary, which install-supervisor already stages at /opt/aether/proxy-ready. The probe runs inside the sidecar's own container, which mounts the supervisor-bin volume read-only. proxy-ready gets a second mode, --unix-socket=PATH: it exits 0 only if a connect(2) to that AF_UNIX socket succeeds. It uses raw syscall, not net, so the binary stays small (#673). Why this option:

  • Port probes are out. The pod is hostNetwork, so httpGet, tcpSocket and grpc probes reach whichever pod on the node holds the port (the same reason as mesh-dns: replace exec-marker readiness probe with in-process /healthz (reclaim ~250m fleet CPU) #582). The proxy's own readiness probe already avoids them for this reason.
  • No client in the OPA image. opa:*-envoy-static is distroless with no shell, and OPA's diagnostic API is already on a per-pod UDS that no kubelet probe can reach.
  • It checks the right thing. A connect to the gRPC socket is exactly what Envoy needs. Every authz sidecar must serve on that socket (OPA preset or bring-your-own), so one default works for both. A stale socket file left by a crashed sidecar answers ECONNREFUSED, so it does not pass. For OPA, the gRPC listener opens only after /policy/policy.rego has loaded.

The probe is configurable: proxy.authzSidecar.startupProbe.{periodSeconds,timeoutSeconds,failureThreshold} (1 / 1 / 120), .override (a full probe used verbatim), .enabled: false, plus optional livenessProbe and readinessProbe (none by default). A liveness kill is itself an authz outage, and a crashed sidecar is restarted in place anyway.

What the ordering guarantees across a hot-restart handoff

  • New pod: proxy, and with it the supervisor, the successor Envoy's fork and its takeover of the listeners, starts only after the authz socket accepts. The image pull now delays the new pod instead of the authz path. With maxUnavailable: 0 the old pod keeps serving meanwhile. A sidecar that never starts leaves the new pod in Init and stops the roll.
  • Old pod: the kubelet stops native sidecars only after every regular container has exited. The old Envoy is a child of the supervisor in proxy, so it has its own pod's authz for as long as it runs: in successor_wait, in drain_fallback, and while it is the draining hot-restart parent. In a plain DaemonSet surge roll the successor turns Ready only after the parent Envoy has exited (supervisor: on rev242 the old proxy pod gets SIGTERM mid-handoff (6–11 s after the fork, before the successor's readiness gate) in 7 of 15 handoffs #991), so this mostly matters for delete, drain and eviction.
  • Each Envoy of a handoff reaches the socket in its own pod's emptyDir.

Not guaranteed:

  • A sidecar that crashes mid-life still fails checks per failureMode until the kubelet restarts it.
  • "Accepting" is not "has a bundle-loaded policy" for a bring-your-own sidecar that binds before it loads its policy. That case needs .override.
  • The shared terminationGracePeriodSeconds still caps everything.

Minimum Kubernetes version

Native sidecars are on by default from 1.29 and GA in 1.33. The chart declares no kubeVersion, and I did not add one: that would gate the whole chart, including users who never enable authz. Instead, with proxy.authzSidecar.enabled, the template fails below 1.29 with proxy.authzSidecar requires Kubernetes >= 1.29 (native sidecar containers) … pass --kube-version. The comparison is semverCompare "<1.29.0-0", so provider suffixes like -eks- pass.

I chose to fail rather than fall back. An older apiserver drops the field, which leaves an init container that never exits, so every proxy pod is stuck in Init. Falling back to the old layout would silently bring back the 403s. With the sidecar disabled, no minimum applies. CI's kind runs 1.35.8. Helm 4.2's built-in default version is ≥ 1.29, so plain helm template renders.

Tests

helm_template_test / helm_template_absent_test / helm_template_fail_test in charts/aether/BUILD.bazel:

  • native sidecar order with the probe, for both the OPA preset and bring-your-own
  • proxy is the only regular container
  • the probe binary is mounted in the sidecar
  • override and disabled probe
  • authz disabled: absent
  • below 1.29: refused; 1.29 pre-release: renders; old cluster without authz: renders

Seen red before the template change: 7 of the new targets failed (aether_authz_native_sidecar_test, _byo_test, _startup_probe_override_test, _override_no_default_test, _startup_probe_disabled_test, _kube_version_min_test, _kube_version_too_old_test: "expected 'helm template' to be rejected, but it rendered successfully"). The two disabled-path targets passed, as they should.

//agent/cmd/proxy-ready:proxy-ready_test (new TestUnixSocket): listening, stale socket file, missing, regular file, and marker-does-not-rescue cases. deps_test still passes, so the binary is still stdlib-only. //agent/internal/supervisorcmd's chart-flag scan now skips the sidecar, which sits between install-supervisor and proxy.

Proof

  • bazel test //charts/... //e2e/... //agent/cmd/proxy-ready/... //agent/internal/supervisorcmd/... //agent/cmd/proxy-supervisor/...: 87/87 pass
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: clean
  • make format-check: clean
  • kind e2e (stacked PR test(e2e): kind e2e for the ext_authz sidecar and its roll ordering (#1275) #1287, e2e/authz.sh; pinned kind v0.33.0 installed into a scratch dir, k8s 1.35.8). The OPA image is evicted from the node before each roll, so the new pod's sidecar must pull it:
main's chart (2.4.8), AUTHZ_EXPECT=red:
    aether-proxy-8v5kq
      ctr  authz started=true running=2026-10-05T19:59:43Z
      ctr  proxy started=true running=2026-10-05T19:59:40Z
  allowed requests: 17878, codes:   17383 200     495 403
    t=+2s code=403 x18
    t=+3s code=403 x171
    t=+4s code=403 x176
    t=+5s code=403 x130
AUTHZ_ROLL EXPECT=red REQUESTS=17878 F403=495 OTHER_NON200=0 EXT_AUTHZ_ERRORS=990 EPOCH=2->3

this chart (2.4.9), fresh cluster:
    aether-proxy-cg24q
      init authz started=true running=2026-10-05T19:56:29Z
      ctr  proxy started=true running=2026-10-05T19:56:30Z
AUTHZ_ROLL EXPECT=green REQUESTS=17423 F403=0 OTHER_NON200=0 EXT_AUTHZ_ERRORS=0 EPOCH=0->1

this chart, upgraded in place from the 2.4.8 layout:
AUTHZ_ROLL EXPECT=green REQUESTS=17406 F403=0 OTHER_NON200=0 EXT_AUTHZ_ERRORS=0 EPOCH=4->5

EXT_AUTHZ_ERRORS sums http.*.ext_authz.error over every HCM on the node, so a request can count under more than one stat prefix. That is why the red run shows 990 errors for 495 × 403.

Not verified: the shutdown-side guarantee (old pod's authz alive through successor_wait / drain_fallback) is from the kubelet's documented native-sidecar termination order. The e2e does not exercise it directly. Not deployed to talos-main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

The authz container was a second regular container in the aether-proxy
pod. The kubelet starts regular containers in order without waiting, so
it started after `proxy`: when its image had to be pulled (7-13 s on
talos-main, the first roll onto OPA 1.21.1) the new Envoy took the node's
listeners with nothing behind the authz socket, and every check was an
ext_authz error - a 403 under failureMode DENY. On deletion both got
SIGTERM at once, so OPA closed its socket while the old Envoy was still
serving (successor_wait, drain_fallback).

It is now an init container with `restartPolicy: Always`, after
install-supervisor and before the proxy container, with a startupProbe:
the kubelet starts `proxy` only once the authz socket accepts, and stops
the sidecar only after `proxy` has exited.

The probe execs the staged stdlib-only proxy-ready prober inside the
sidecar's container (the OPA image is distroless with no shell, and a
port probe cannot be pod-local on this hostNetwork DaemonSet). proxy-ready
gains --unix-socket: exit 0 iff a connect(2) to that AF_UNIX socket
succeeds - raw syscall, no net package, so it stays tiny. It is the
contract every authz sidecar here already meets, so the default works
for the OPA preset and for a bring-your-own image; it is tunable
(proxy.authzSidecar.startupProbe.*), replaceable (.override) or
disableable (.enabled=false), with optional liveness/readiness probes.

Native sidecars need Kubernetes >= 1.29: an older apiserver drops the
field and leaves an init container that never exits. With the sidecar
enabled the chart refuses to render below 1.29; disabled, nothing
changes (the default render is byte-identical apart from the generated
webhook certificates).

supervisorcmd's chart-flag scan now skips the sidecar, which sits
between install-supervisor and the proxy container.

Chart 2.4.9.

Closes #1275

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo added this pull request to stack #1288 October 5, 2026 20:05
@bpalermo bpalermo changed the title upgrade/authz native sidecar fix(chart): run the ext_authz sidecar as a native sidecar (#1275) Oct 5, 2026
@bpalermo
bpalermo merged commit e84dff7 into main Oct 5, 2026
34 of 42 checks passed
@bpalermo
bpalermo deleted the upgrade/authz-native-sidecar branch October 5, 2026 22:04
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.

proxy pod: the ext_authz sidecar can start after the proxy is serving — authz errors (403 under failureMode DENY) until it is up

1 participant