You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(chart): the OPA authz sidecar reloads its policy on change; a policy update no longer rolls the proxy (#1383) - #1436
The OPA preset's sidecar now runs opa run --server --watch … /policy/policy.rego, always (no value, no switch), and the checksum/opa-policy annotation from #1367 is gone from the proxy pod template. Changing proxy.authzSidecar.opa.policy changes the ConfigMap only: the running sidecars reload it and no proxy pod is replaced, so there is no Envoy hot restart for a policy change.
No validation is added, by the owner's decision: checking a policy before it is applied is the job of whoever updates it. The docs say so and give the commands.
What an operator sees on upgrade: with the OPA preset on, the upgrade to chart 2.4.19 rolls the proxy DaemonSet once (the annotation leaves the pod template and the sidecar gains --watch). With the preset off, or with a bring-your-own sidecar, the render is byte-identical to main. After that, a policy change is fleet-wide within about a minute and is not staged: there is no node-by-node roll to stop at a bad policy any more.
Chart 2.4.19 (main took 2.4.18 with #1426 while this was in progress).
Render, before and after
Default values and the bring-your-own sidecar: byte-identical (cmp). With the OPA preset on (comments omitted):
The cluster was brought up by e2e/authz.sh up with this branch's chart; policies were changed by helm upgrade with the values read back (helm get values, never --reuse-values).
Result
Policy changed (allow header letmein → second)
letmein went 200 → 403 and second 403 → 200, 55 s after helm upgrade returned. Same pod UID, authz and proxy restart counts 0, DaemonSet generation 1, Envoy restart_epoch 0, before and after
Kubelet delivery of the ConfigMap, eight changes
27, 44, 44, 46, 53, 55, 63, 64 s after helm returned; the decision followed within 0.5 s each time
8,607 requests sent through a reload (allowed by both policies)
8,607 × 200, ext_authz.error +0
Policy that does not parse (rego_parse_error), sidecar running
not loaded. The last good policy kept deciding, no exit, no restart, /health 200, /v1/policies still the old text
Policy that parses but does not compile (rego_type_error: undefined function)
the same
Valid policy again
loaded 46 s after helm returned, same pod, no restart
Bad policy on the node, then the authz container stopped
the restarted OPA exits 1 (error: load error: … rego_parse_error), Init:CrashLoopBackOff, pod 1/2; proxy keeps running; every check is an ext_authz error, 403 under DENY (18 of 18). A valid policy recovered it 8 s after the upgrade began, same pod
Bad policy on the node, then the proxy pod deleted
the new pod stays Init:CrashLoopBackOff and proxy never starts. The old pod's Envoy served on (with its own sidecar's last good policy) for its 155 s successor wait, then exited: the node had no proxy and requests failed to connect. A valid policy recovered it in 125 s (53 s delivery, then the kubelet's restart back-off)
How a failed reload shows. Only in the sidecar's log, and at level info: "msg":"Processed file watch event." with a non-null "err" (five lines per ConfigMap update). OPA's /metrics on the diagnostic socket holds Go runtime and http_request_duration_seconds series only; there is no reload metric, and /v1/status answers status plugin not enabled. /v1/policies returns the policy actually loaded, which can be compared with the ConfigMap. The runbook has both commands.
Which invocation works.--watch with the file, /policy/policy.rego, as the chart already named it. OPA follows the kubelet's ..data symlink swap because it watches the file's directory. Given the directory /policy instead, OPA 1.21.1 loads the volume's three copies (policy.rego, ..data/policy.rego, the timestamped directory) and refuses to start with rego_type_error: multiple default rules data.envoy.authz.allow found at …. That comparison was run with docker run on a directory laid out and swapped the way the kubelet's atomic writer does it, not on kind. The mount has no subPath.
Tests
Written first and seen failing against the unchanged chart:
//charts/aether:aether_opa_watch_test FAILED (the args hold no "--watch")
//charts/aether:aether_opa_policy_no_checksum_test FAILED the render contains 'checksum/' / 'annotations:', which must be absent
//charts/aether:aether_opa_policy_change_keeps_proxy_pod_test FAILED templates/agent-proxy-daemonset.yaml changes with the changed values, and must not:
… at 49c49: the value of checksum/opa-policy:
That second one needed a rule the repository did not have, helm_template_value_ignored_test in //bazel/helm:defs.bzl (the mirror of helm_template_value_changes_test). Its control is that the whole render must differ, so values that change nothing cannot pass. //bazel/helm:template_rules_test covers both of its failure modes and that it prints no rendered text.
aether_opa_watch_test also pins the file argument and the mount without subPath.
The default-values guard (no annotation on the proxy pod template) stays, renamed, and also requires no --watch.
e2e/authz.sh gains step d (nightly job authz, no new job): a policy change by helm upgrade, a policy that does not parse, and the first policy again, with the pod UID, restart counts, DaemonSet generation and Envoy epoch required to stay the same and ext_authz.error to stay flat. Run on kind against this branch: passed (new policy deciding after 66 s). Run against main's chart: fails at "the policy change replaced or restarted the proxy pod" (a second pod surged in, generation 4 → 5, epoch 3 → 4).
Locally: bazel test //charts/... //bazel/helm/... //e2e/... //agent/internal/supervisorcmd/..., the lint build, make format-check, make actionlint, scripts/check-shell-lint.sh.
Not verified
More than one node. Each kubelet syncs on its own timer; "every node within about a minute" is the kubelet's documented behaviour plus the single-node timings above.
failureMode: ALLOW with a crash-looping sidecar (the docs state the fail-open consequence from the filter's semantics; only DENY was run).
The sidecar-restart and new-pod cases with a bad policy were measured by hand and are not in CI. Step d covers the running-sidecar path only.
talos-main: nothing was deployed. After the upgrade there, the check is the runbook's loop over kubectl logs … -c authz | grep 'Processed file watch event' following a policy change.
…licy update no longer rolls the proxy (#1383)
The OPA preset runs `opa run --watch`, unconditionally, and the
`checksum/opa-policy` annotation (#1367) leaves the proxy pod template. A
changed policy is delivered by the kubelet's ConfigMap sync and loaded by
the running sidecar; no pod is replaced and Envoy is not hot-restarted.
No validation is added: checking a policy before applying it is the
responsibility of whoever changes it, and the docs give the commands.
Measured on kind (Kubernetes 1.35.8, OPA 1.21.1):
- a policy changed by `helm upgrade` decides 46-64 s after helm returns,
with the same pod UID, restart counts, DaemonSet generation and Envoy
epoch; 8,607 of 8,607 requests through a reload answered, 0 ext_authz
errors;
- a policy that does not parse or compile is not loaded: the running
sidecar keeps the last good one, logs the error at level info and
exports no metric; a sidecar that STARTS with it exits 1;
- `/policy/policy.rego` is the invocation that works; given the `/policy`
directory OPA loads the ConfigMap volume's three copies and refuses to
start.
Tests: the #1367 checksum tests are turned around (no annotation with the
preset on; two policies render one byte-identical DaemonSet, through the
new helm_template_value_ignored_test rule), and e2e/authz.sh gains step d.
Chart 2.4.19. The first upgrade with the OPA preset on rolls the proxy
DaemonSet once.
Closes#1383
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Avoid misclassifying delayed ConfigMap delivery as OPA reload rejection
docs/runbook.md:3337
The one-minute test can falsely report a rejected reload: this section records successful ConfigMap deliveries taking 63–64 seconds. First verify that the pod’s mounted policy.rego matches the ConfigMap, then compare OPA’s loaded policy; only that distinguishes kubelet delivery delay from OPA rejection.
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
…e against a request; read watch events unfiltered (#1383)
- `opa eval --fail` is given a representative ext_authz request with
`--input`, and the claim is narrowed to what it proves: the decision is
defined for that one request. Without an input it rejected a correct
policy that has no default. Checked with OPA 1.21.1 against the e2e
policy, a policy without a default, and one that does not define the
decision.
- 27-64 s is an observation on one node, not a bound: each kubelet
delivers a ConfigMap update on its own schedule. The docs and the chart
comments describe the rollout as unstaged and asynchronous, and say how
to confirm convergence per proxy pod.
- The runbook's reload check shows the latest watch events, successes
included, and says what a null err, a non-null err and no event mean.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1383
An agent wrote this pull request.
What changes
The OPA preset's sidecar now runs
opa run --server --watch … /policy/policy.rego, always (no value, no switch), and thechecksum/opa-policyannotation from #1367 is gone from the proxy pod template. Changingproxy.authzSidecar.opa.policychanges the ConfigMap only: the running sidecars reload it and no proxy pod is replaced, so there is no Envoy hot restart for a policy change.No validation is added, by the owner's decision: checking a policy before it is applied is the job of whoever updates it. The docs say so and give the commands.
What an operator sees on upgrade: with the OPA preset on, the upgrade to chart 2.4.19 rolls the proxy DaemonSet once (the annotation leaves the pod template and the sidecar gains
--watch). With the preset off, or with a bring-your-own sidecar, the render is byte-identical tomain. After that, a policy change is fleet-wide within about a minute and is not staged: there is no node-by-node roll to stop at a bad policy any more.Chart
2.4.19(maintook 2.4.18 with #1426 while this was in progress).Render, before and after
Default values and the bring-your-own sidecar: byte-identical (
cmp). With the OPA preset on (comments omitted):template: metadata: - annotations: - checksum/opa-policy: 4d2b53476811ded7f3e9f37b684721007ab75e14aa97bbd0b02cdbdd4f3d8080 labels: … args: - "run" - "--server" + - "--watch" - "--skip-version-check" - "--addr=unix:///run/aether/authz/opa-api.sock" - "--set=plugins.envoy_ext_authz_grpc.addr=unix:///run/aether/authz/authz.sock" - "--set=decision_logs.console=true" - "/policy/policy.rego"Measured (kind v0.33.0, Kubernetes 1.35.8, OPA 1.21.1, one node,
failureMode: DENY)The cluster was brought up by
e2e/authz.sh upwith this branch's chart; policies were changed byhelm upgradewith the values read back (helm get values, never--reuse-values).letmein→second)letmeinwent 200 → 403 andsecond403 → 200, 55 s afterhelm upgradereturned. Same pod UID,authzandproxyrestart counts 0, DaemonSet generation 1, Envoyrestart_epoch0, before and afterext_authz.error+0rego_parse_error), sidecar running/health200,/v1/policiesstill the old textrego_type_error: undefined function)authzcontainer stoppederror: load error: … rego_parse_error),Init:CrashLoopBackOff, pod 1/2;proxykeeps running; every check is anext_authzerror, 403 under DENY (18 of 18). A valid policy recovered it 8 s after the upgrade began, same podInit:CrashLoopBackOffandproxynever starts. The old pod's Envoy served on (with its own sidecar's last good policy) for its 155 s successor wait, then exited: the node had no proxy and requests failed to connect. A valid policy recovered it in 125 s (53 s delivery, then the kubelet's restart back-off)How a failed reload shows. Only in the sidecar's log, and at level
info:"msg":"Processed file watch event."with a non-null"err"(five lines per ConfigMap update). OPA's/metricson the diagnostic socket holds Go runtime andhttp_request_duration_secondsseries only; there is no reload metric, and/v1/statusanswersstatus plugin not enabled./v1/policiesreturns the policy actually loaded, which can be compared with the ConfigMap. The runbook has both commands.Which invocation works.
--watchwith the file,/policy/policy.rego, as the chart already named it. OPA follows the kubelet's..datasymlink swap because it watches the file's directory. Given the directory/policyinstead, OPA 1.21.1 loads the volume's three copies (policy.rego,..data/policy.rego, the timestamped directory) and refuses to start withrego_type_error: multiple default rules data.envoy.authz.allow found at …. That comparison was run withdocker runon a directory laid out and swapped the way the kubelet's atomic writer does it, not on kind. The mount has nosubPath.Tests
Written first and seen failing against the unchanged chart:
aether_opa_policy_checksum_testand…_changes_test(fix(chart): a chart release rolls only the pods whose spec changed (#1363) #1367, the annotation is present and follows the policy) are replaced by their opposites: no annotation with the preset on, and two policies rendering one byte-identical DaemonSet.helm_template_value_ignored_testin//bazel/helm:defs.bzl(the mirror ofhelm_template_value_changes_test). Its control is that the whole render must differ, so values that change nothing cannot pass.//bazel/helm:template_rules_testcovers both of its failure modes and that it prints no rendered text.aether_opa_watch_testalso pins the file argument and the mount withoutsubPath.--watch.e2e/authz.shgains step d (nightly jobauthz, no new job): a policy change byhelm upgrade, a policy that does not parse, and the first policy again, with the pod UID, restart counts, DaemonSet generation and Envoy epoch required to stay the same andext_authz.errorto stay flat. Run on kind against this branch: passed (new policy deciding after 66 s). Run againstmain's chart: fails at "the policy change replaced or restarted the proxy pod" (a second pod surged in, generation 4 → 5, epoch 3 → 4).Locally:
bazel test //charts/... //bazel/helm/... //e2e/... //agent/internal/supervisorcmd/..., the lint build,make format-check,make actionlint,scripts/check-shell-lint.sh.Not verified
failureMode: ALLOWwith a crash-looping sidecar (the docs state the fail-open consequence from the filter's semantics; only DENY was run).kubectl logs … -c authz | grep 'Processed file watch event'following a policy change.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr