Skip to content

feat(chart): the OPA authz sidecar reloads its policy on change; a policy update no longer rolls the proxy (#1383) - #1436

Merged
bpalermo merged 7 commits into
mainfrom
feat/opa-policy-watch-1383
Oct 8, 2026
Merged

bpalermo merged 7 commits into
mainfrom
feat/opa-policy-watch-1383

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 8, 2026

Copy link
Copy Markdown
Owner

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 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):

   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 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:
  • aether_opa_policy_checksum_test and …_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.
  • 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.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new Helm test rule’s nondeterministic whole-render control can pass even when changed values have no effect.

1 open finding
What changed in this PR

Updates the OPA authorization sidecar to reload policy changes in place, avoiding proxy pod rolls and Envoy hot restarts.

Changes:

  • Enables OPA’s --watch mode and removes the policy checksum annotation.
  • Adds chart and end-to-end reload coverage.
  • Documents validation, failure, and recovery behavior.
File Description
.github/​workflows/​e2e.yaml Documents expanded authz verification.
bazel/​helm/​BUILD.bazel Registers new Helm-rule test fixtures.
bazel/​helm/​defs.bzl Adds the value-ignored Helm test rule.
bazel/​helm/​template_rules_test.sh Tests new rule failure modes.
bazel/​helm/​testdata/​secretchart/​BUILD.bazel Adds rule test cases.
charts/​README.md Documents Helm test selection.
charts/​aether/​BUILD.bazel Replaces checksum tests with watch/no-roll tests.
charts/​aether/​Chart.yaml Bumps chart to 2.4.19.
charts/​aether/​templates/​agent-proxy-daemonset.yaml Enables OPA watching and removes checksum rolling.
charts/​aether/​templates/​agent-proxy-opa-policy.yaml Documents watched policy behavior.
charts/​aether/​values.yaml Adds policy operational guidance.
docs/​configuration.md Documents configuration and validation workflow.
docs/​runbook.md Adds failure detection and recovery procedures.
e2e/​authz.sh Verifies live reloads and invalid-policy handling.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread bazel/helm/defs.bzl Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:08
@bpalermo
bpalermo force-pushed the feat/opa-policy-watch-1383 branch from ec48db3 to 81cd30d Compare October 8, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new ignored-value Helm rule can falsely pass when changed options introduce nondeterministic rendering.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread bazel/helm/defs.bzl Resolved
…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
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:12
@bpalermo
bpalermo force-pushed the feat/opa-policy-watch-1383 branch from 81cd30d to 8829674 Compare October 8, 2026 14:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The configuration guide can validate policies against the wrong OPA version when the image value is overridden.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread docs/configuration.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The runbook’s one-minute rejection test can misdiagnose normal ConfigMap delivery delays already observed at 63–64 seconds.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity 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.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The validation guidance contains two misleading statements that could cause operators to validate policies incorrectly.

2 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread charts/aether/values.yaml Resolved
Comment thread docs/configuration.md Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The documented validation command evaluates without request input and can incorrectly reject valid input-dependent policies.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread docs/configuration.md Resolved
Comment thread docs/runbook.md Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Operator guidance contains an ambiguous reload diagnostic and overstates ConfigMap propagation guarantees.

4 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread docs/configuration.md Resolved
Comment thread docs/runbook.md Resolved
…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
Copilot AI balanced review requested due to automatic review settings October 8, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The runtime change is focused and backed by chart, rule, E2E, and operational documentation coverage.

0 open findings

4 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

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.

chart: the OPA authz sidecar does not watch its policy, so a policy change needs a proxy roll

2 participants