Skip to content

fix(chart): the controller's webhook RBAC follows the condition that renders the webhook (#1411) - #1426

Merged
bpalermo merged 2 commits into
mainfrom
fix/controller-mutating-webhook-rbac
Oct 8, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/controller-mutating-webhook-rbac

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Closes #1411

This pull request was written by an agent (Claude Code). It fixes #1411. It does not change anything for #1412 and does not close it: see "About #1412" below for why, and for what the owner needs to decide.

The bug (#1411)

Three things depend on "the pod-mutating webhook exists":

Template What it does Condition before
controller-webhook.yaml renders the MutatingWebhookConfiguration namespaceInjection OR injectPodNdots
controller-deployment.yaml passes --mutating-webhook-config-name (SPIRE-served webhook only) namespaceInjection OR injectPodNdots
controller-rbac.yaml grants mutatingwebhookconfigurations (SPIRE-served webhook only) injectPodNdots alone

With controller.webhook.spire=true, namespaceInjection=true, injectPodNdots=false the controller was told to fill in the caBundle of an object it had no permission to read.

The fix

One helper, aether.controller.mutatingWebhook (_helpers.tpl), read by all three templates. A second helper, aether.controller.mutatingWebhookName, gives the object and the flag the same name from one place (the rendered name is unchanged).

I looked for anything else gated on the same fact. There is nothing else in the chart. The identity-gate flags (--identity-gate=…) are gated on spire.enabled and controller.webhook.identityGate.enabled, not on the webhook existing; with both switches off they are passed and are inert, because nothing routes a pod to /mutate. I left that as it is on purpose: making them follow the helper would change the controller's pod template (and roll it) for a release with both switches off, with no change in behaviour.

Truth table, rendered (helm template, helm v3.18.4)

config = the MutatingWebhookConfiguration renders; flag = --mutating-webhook-config-name is passed; rbac = the ClusterRole grants mutatingwebhookconfigurations. The flag and the grant are expected exactly when the webhook is SPIRE-served and the configuration renders.

Before (chart 2.4.17):

spire  nsInj  ndots  | config   flag   rbac   | agree
true   true   true   | yes      yes    yes    | AGREE
true   true   false  | yes      yes    no     | DISAGREE
true   false  true   | yes      yes    yes    | AGREE
true   false  false  | no       no     no     | AGREE
false  true   true   | yes      no     no     | AGREE
false  true   false  | yes      no     no     | AGREE
false  false  true   | yes      no     no     | AGREE
false  false  false  | no       no     no     | AGREE

After (this branch):

spire  nsInj  ndots  | config   flag   rbac   | agree
true   true   true   | yes      yes    yes    | AGREE
true   true   false  | yes      yes    yes    | AGREE
true   false  true   | yes      yes    yes    | AGREE
true   false  false  | no       no     no     | AGREE
false  true   true   | yes      no     no     | AGREE
false  true   false  | yes      no     no     | AGREE
false  false  true   | yes      no     no     | AGREE
false  false  false  | no       no     no     | AGREE

Render diff, before and after

All eight cells plus the default render, certificate lines masked as docs/runbook.md ("Rendering the chart reproducibly") describes. Every differing line, counted over the nine renders:

    273 <     helm.sh/chart: aether-2.4.17
    273 >     helm.sh/chart: aether-2.4.18
      1 >   - apiGroups: ["admissionregistration.k8s.io"]
      1 >     resources: ["mutatingwebhookconfigurations"]
      1 >     verbs: ["get", "list", "watch", "update", "patch"]

Before the version bump the nine renders were byte-identical to main except the affected cell, whose only difference was those three rule lines in ClusterRole/<release>-aether-controller-<namespace>.

What an upgrade does

  • Default values, and any release with controller.injectPodNdots=true, or with the self-signed webhook: nothing but the helm.sh/chart label on each object, as with any chart release. That label is on object metadata, not in any pod template.
  • controller.webhook.spire=true + namespaceInjection=true + injectPodNdots=false: the controller's ClusterRole gains one rule. Nothing else.
  • No pod template changes in any cell, so no pod rolls. Measured by the diff above; //charts/aether:aether_pod_template_version_test and its siblings also pass.
  • Nothing for an operator to do. talos-main runs with both switches on and is not affected (checked by the task's author, not by me).

What happens at runtime without the rule (read from the code, not reproduced)

I read controller/internal/meshconfig/cabundle.go, controller/internal/cmd/root.go, common/manager, and controller-runtime v0.25.2's cache. No Go is changed here.

  • The injector runs on the leader only. It patches the validating configuration first, then calls Get on the mutating one through the manager's client, which reads from the informer cache.
  • That first Get starts an informer for MutatingWebhookConfiguration. Without list/watch the informer never syncs, and a cached Get waits for the sync with no timeout. So the call does not fail: it never returns. The injector's own error line (webhook caBundle injection failed) is never logged. The only log signal is client-go's reflector reporting the forbidden list, repeatedly.
  • Because the injector is stuck inside that call, it never returns to its loop, so the validating webhook's caBundle is written once and not refreshed when the SPIRE trust bundle rotates, for as long as that leader lives.
  • The manager's cache-sync readiness check waits on every informer, including this one, so the leader replica should go NotReady and leave the webhook Service's endpoints. The second replica (default replicaCount: 2) keeps serving.
  • The mutating configuration's caBundle stays empty; the apiserver cannot verify the controller, and with failurePolicy: Ignore namespace injection and the identity gate are skipped silently, as the issue says.

I could not verify this on a cluster: it needs SPIRE issuing the controller an SVID, and the task was to read. Treat the four runtime points as inferred.

Tests, red first

Eight new targets in charts/aether/BUILD.bazel, one per cell (helm_template_match_test with document_patterns for the cells where the configuration renders with the SPIRE-served webhook; helm_template_absent_test for the others). Against the unchanged chart:

//charts/aether:aether_mutating_webhook_self_signed_both_test            PASSED
//charts/aether:aether_mutating_webhook_self_signed_namespace_injection_only_test PASSED
//charts/aether:aether_mutating_webhook_self_signed_ndots_only_test      PASSED
//charts/aether:aether_mutating_webhook_self_signed_off_test             PASSED
//charts/aether:aether_mutating_webhook_spire_both_test                  PASSED
//charts/aether:aether_mutating_webhook_spire_ndots_only_test            PASSED
//charts/aether:aether_mutating_webhook_spire_off_test                   PASSED
//charts/aether:aether_mutating_webhook_spire_namespace_injection_only_test FAILED
FAIL: ClusterRole/release-name-aether-controller-default (aether/templates/controller-rbac.yaml, document 1) does not match the pattern:
  ... the first 7 of the pattern's 14 lines match (lines 46-49 ...); the rest does not match what follows

One is red (the affected cell); the other seven are guards for behaviour that must not change. After the fix: bazel test //charts/... //bazel/helm/..., 186 of 186 pass.

Also run: bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... and make format-check, both clean. The remote cache was unreachable for part of the session ("Failed to query remote execution capabilities: UNAVAILABLE"), so the final test and lint runs were local, with the remote cache flags emptied on the command line.

Docs

About #1412 (controller.webhook.spire=true with spire.enabled=false)

The issue asks to fail the render for this pair. I did not, because what I read says the pair is a working configuration rather than a contradiction, and failing it would break it:

  • values.yaml, the header of controller-webhook.yaml and docs/configuration.md all describe the webhook certificate source as decoupled from mesh SPIRE. values.yaml describes spire.enabled as "the mesh-wide mTLS switch", not as "SPIRE is installed".
  • Everything the SPIRE-served webhook needs is gated on controller.webhook.spire alone: the flag, the socket path, the csi.spiffe.io volume, the ClusterSPIFFEID, the RBAC, and no Secret. With spire.enabled=false the render is coherent: only the controller uses SPIRE, and it is passed --identity-gate=false.
  • The controller's --spire-enabled means only "serve the webhook with an SVID and inject the bundle". It has no mesh meaning.
  • The runbook tells an operator whose GitOps tool renders with helm template (Argo CD) to serve the webhook with SPIRE, because the self-signed path generates a new CA on every sync. With a render failure, such an operator running the mesh without mTLS would have no stable webhook certificate at all. The runbook's "render both sides with --set controller.webhook.spire=true" way of diffing would also stop working for any values file with spire.enabled=false.
  • What a failure would protect against is webhook.spire=true on a cluster with no SPIRE. spire.enabled does not tell the chart that, and the same mistake is possible with spire.enabled=true.

Against that: #231, which introduced the value, was about the other direction (mesh SPIRE on, self-signed webhook); one template comment (agent-proxy-daemonset.yaml) treats spire.enabled=false as "SPIRE is not deployed"; and nothing in the repository uses the pair. So this is the owner's call. If spire.enabled=false is meant to say "there is no SPIRE in this cluster", the failure is a small follow-up; if not, the issue is better closed with a sentence in values.yaml saying the pair is supported and a test that pins it.

On the test guard from #1410: no helm_template_test in charts/aether/BUILD.bazel sets spire.enabled=false. The only test that does is aether_identity_gate_no_spire_test, on the masked rule. Its comment says the pair "cannot be rendered"; today it can.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…renders the webhook (#1411)

controller-webhook.yaml rendered the MutatingWebhookConfiguration, and
controller-deployment.yaml passed --mutating-webhook-config-name, when either
controller.namespaceInjection or controller.injectPodNdots was on.
controller-rbac.yaml granted mutatingwebhookconfigurations under
injectPodNdots alone. With controller.webhook.spire=true,
namespaceInjection=true and injectPodNdots=false the controller was told to
fill in the caBundle of an object it had no permission to read.

The condition is now one helper, aether.controller.mutatingWebhook, read by
all three templates; the object's name is one helper too. Eight template
tests render {SPIRE-served webhook} x {namespaceInjection} x {injectPodNdots}
and check that the object, the flag and the grant agree in every cell. One of
them failed against the unchanged chart (the affected cell); the other seven
are guards.

The render is byte-identical to 2.4.17 in every cell except that one, which
gains the ClusterRole rule. No pod template changes.

Chart 2.4.18.

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 13:39

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 shared condition resolves the RBAC mismatch and comprehensive render tests cover every configuration combination.

0 open findings

What changed in this PR

Centralizes the pod-mutating webhook condition so rendering, controller arguments, and SPIRE RBAC remain consistent.

Changes:

  • Adds shared helpers for webhook existence and naming.
  • Fixes RBAC for namespace-injection-only deployments.
  • Adds an eight-cell render truth table and operational documentation.
File Description
charts/​aether/​templates/​_helpers.tpl Defines shared webhook helpers.
charts/​aether/​templates/​controller-webhook.yaml Uses shared rendering and naming logic.
charts/​aether/​templates/​controller-deployment.yaml Uses shared condition for the controller flag.
charts/​aether/​templates/​controller-rbac.yaml Grants RBAC whenever the webhook renders.
charts/​aether/​BUILD.bazel Tests all relevant configuration combinations.
charts/​aether/​Chart.yaml Bumps the chart to 2.4.18.
charts/​aether/​values.yaml Documents conditional SPIRE RBAC.
docs/​configuration.md Updates webhook configuration guidance.
docs/​runbook.md Adds diagnosis and recovery instructions.

🧠 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 13:47

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 shared condition resolves the RBAC mismatch and is comprehensively covered across all configuration combinations.

0 open findings

🧠 Review effort: Balanced


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

@bpalermo
bpalermo merged commit 07a9458 into main Oct 8, 2026
31 checks passed
@bpalermo
bpalermo deleted the fix/controller-mutating-webhook-rbac branch October 8, 2026 13:57
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: with the SPIRE-served webhook, namespaceInjection on and injectPodNdots off, the controller has no RBAC to patch the mutating webhook's caBundle

2 participants