Skip to content

fix(chart): the webhook certificate is reused, replaced only when incomplete or rotated; helm template's exception is documented (#1364) - #1368

Merged
bpalermo merged 1 commit into
upgrade/chart-pod-template-labelsfrom
upgrade/chart-webhook-cert-reuse
Oct 8, 2026
Merged

bpalermo merged 1 commit into
upgrade/chart-pod-template-labelsfrom
upgrade/chart-webhook-cert-reuse

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Closes #1364

Top of a stack of two; #1367 (for #1363) is the base.

What an upgrade does today (the issue's second half is not what happens)

The issue says an upgrade rewrites the webhook secret and CA bundle each time. It does not: controller-webhook.yaml already looks the Secret up and reuses it.

Question Answer How I know
Does the Secret's data change on helm upgrade? No Measured on kind with main's chart and Helm 3.18.4: the data hash is the same after an upgrade to another version, a downgrade and an upgrade at a changed version
Does the caBundle change with it? No Same runs: the three webhooks' caBundle hash is unchanged
Is the Secret object touched at all? Yes, its metadata: resourceVersion changes because the helm.sh/chart label changes Same runs
Does the controller restart or reload because of the certificate? No. Nothing ties the pod to the Secret. Without SPIRE the controller serves from controller-runtime's default cert directory, whose certwatcher (fsnotify plus a 10 s poll) reloads a changed file without a restart Read in controller/internal/cmd/root.go and controller-runtime v0.25.2 (pkg/webhook/server.go, pkg/certwatcher). Not exercised on a running controller
And helm template? A new CA and certificate on every render: six lines differ (the Secret's ca.crt, tls.crt, tls.key, and three caBundle) Measured; now pinned by a test

talos-main cannot show any of this: it runs controller.webhook.spire=true (read with helm get values), so there is no self-signed Secret there. The controller pods there are as old as the last deploy, which is the roll #1363 describes, not this.

Reuse is safe for the current names by construction: the certificate's two SANs are <service>.<namespace>.svc[.cluster.local] and the Secret is looked up as <service>-cert in <namespace>, so another service name or namespace is another Secret. On kind the serving certificate verified against the caBundle and carried both SANs after every step.

What changes

  1. A half-written Secret is replaced, not reused. main reused the Secret whenever ca.crt was present. Measured on kind: with tls.key emptied, every upgrade of main's chart fails with Secret "aether-controller-webhook-cert" is invalid: data[tls.key]: Required value until someone deletes the Secret. This chart generates a new pair instead.
  2. controller.webhook.certRotation (default "", never rotate). The pair is valid ten years and nothing renewed it; the only way to rotate was deleting the Secret by hand. A new value generates a new pair on the next upgrade and is stamped on the Secret (aether.io/webhook-cert-rotation); the same value, clearing it, or restoring it after clearing rotates nothing (the stamp stays on a reused Secret). A token rather than a boolean, so a value left in a GitOps repository does not rotate on every reconcile.
  3. During a regeneration over an existing Secret, caBundle carries the new CA and the one being replaced, so the certificate the controller is still serving keeps verifying until it reloads. The next upgrade renders the new CA alone. Without this, every rotation opens a window in which the webhooks fail open (failurePolicy: Ignore): pods admitted then are not mutated. This narrows the window; it does not close it (raised in review): Helm patches the Secret before the webhook configurations, so a controller pod that starts in between, or an upgrade that fails in between, serves the new certificate against the old caBundle until the upgrade completes. Closing it needs the new CA trusted one upgrade before the new certificate is served; not done here, and the docs say so.
  4. helm template is the documented exception, in the template header, values.yaml, docs/configuration.md and a new runbook section ("Rendering the chart reproducibly") with the masking recipe, the controller.webhook.spire=true alternative and its limits, how to hash the certificate before and after an upgrade without printing it, and the rotation procedure.

The lookup uses in controller-meshconfig.yaml and edge-meshconfig.yaml are deterministic (seed the MeshConfig once, resource-policy: keep); they render the same thing every time without a cluster and are left alone.

No pod template changes: nothing rolls because of this PR.

Measured on kind

Kind v0.33.0, the pinned node image, Helm 3.18.4, its own kubeconfig, deleted afterwards. Only hashes, counts and metadata were printed.

Step (this chart) Secret data caBundle Serving cert vs caBundle
upgrade, nothing set unchanged unchanged, 1 cert OK
certRotation=2026-10 new, annotation stamped new, 2 certs OK
same value again unchanged (resourceVersion too) new CA alone, 1 cert OK
value cleared unchanged, stamp kept unchanged OK
the same value restored unchanged (resourceVersion too) unchanged OK
a different value new, restamped 2 certs OK
tls.key emptied, then upgrade new, all three keys 2 certs OK
Secret deleted, then upgrade new 1 cert OK
chart with only version + appVersion changed unchanged unchanged OK

Tests

New rule helm_template_reproducible_test (bazel/helm/defs.bzl): renders twice and compares, with named keys masked, and fails if the mask hides a different number of lines than declared.

  • Red first against the unchanged template: aether_webhook_cert_rotation_stamp_test (the value is stamped on the Secret).
  • Guards, green before and after, because they pin the exception rather than a change: aether_reproducible_masked_test and ..._all_enabled_masked_test (identical with exactly six lines masked), aether_reproducible_webhook_spire_test (identical with no mask), aether_webhook_cert_rotation_off_test (no annotation by default), aether_webhook_cert_rotation_spire_test (no Secret with SPIRE). Mutation check: dropping caBundle from the mask fails the masked test (the mask hid 3 lines, want 6).

Not testable hermetically: everything behind lookup (reuse, the incomplete-Secret branch, rotation, the two-CA bundle). helm template has no cluster to look in. Those are covered by the kind run above, which is not in CI.

What an operator does on upgrade

Nothing. The existing Secret is reused and gains no annotation. To check, hash before and after:

kubectl -n aether-system get secret aether-controller-webhook-cert -o jsonpath='{.data}' | sha256sum

Verified

bazel test //charts/... //bazel/helm/..., bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //..., make format-check.

Not verified

  • A running controller picking up a rotated certificate without a restart: read in controller-runtime's code, never run (the controller image did not start on kind).
  • Helm 4 against a cluster, and Flux's helm-controller: the kind upgrades used Helm 3.18.4.
  • What helm diff shows by default: the runbook says it needs --dry-run=server to look the Secret up; I did not run the plugin.

Noticed, not changed

  • The self-signed pair expires after ten years with nothing warning about it; the webhooks would then fail open silently.
  • helm upgrade with no value flags reuses the previous release's values (Helm 3 default), which is how a certRotation "removed" from the command line stays set.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

@bpalermo
bpalermo added this pull request to stack #1369 October 7, 2026 22:40
@bpalermo bpalermo changed the title fix(chart): the webhook certificate is reused, replaced only when incomplete or rotated; helm template's exception is documented and pinned (#1364) fix(chart): the webhook certificate is reused, replaced only when incomplete or rotated; helm template's exception is documented (#1364) Oct 7, 2026
@bpalermo
bpalermo force-pushed the upgrade/chart-webhook-cert-reuse branch from 04e38be to 0323b77 Compare October 7, 2026 22:53
Copilot AI balanced review requested due to automatic review settings October 7, 2026 22:53

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

Certificate rotation has a trust-ordering race, and test diagnostics can expose generated secrets.

2 open findings
What changed in this PR

Adds reusable webhook certificates, explicit rotation, and documentation for nondeterministic offline Helm renders.

Changes:

  • Regenerates incomplete certificates and supports token-based rotation.
  • Adds reproducibility tests with certificate masking.
  • Documents rendering, verification, and rotation procedures.
File Description
docs/​runbook.md Documents reproducible rendering and rotation.
docs/​configuration.md Documents webhook settings.
charts/​aether/​values.yaml Adds certRotation.
charts/​aether/​templates/​controller-webhook.yaml Implements reuse and rotation.
charts/​aether/​Chart.yaml Bumps chart version.
charts/​aether/​BUILD.bazel Adds chart tests.
bazel/​helm/​defs.bzl Adds reproducibility test rule.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bazel/helm/defs.bzl Resolved
Copilot AI balanced review requested due to automatic review settings October 7, 2026 22:59
@bpalermo
bpalermo force-pushed the upgrade/chart-webhook-cert-reuse branch from 0323b77 to ca5cdaf Compare October 7, 2026 22:59

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 SPIRE workaround documentation omits required identity configuration and could leave admission webhooks failing open.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

Comment thread docs/runbook.md Resolved
Copilot AI balanced review requested due to automatic review settings October 7, 2026 23:15
@bpalermo
bpalermo force-pushed the upgrade/chart-webhook-cert-reuse branch from ca5cdaf to 74ac71f Compare October 7, 2026 23:15

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

A new test can expose generated private-key material and uses a nonportable regex.

2 open findings
1 resolved since last review

🧠 Review effort: Balanced

Comment thread charts/aether/BUILD.bazel Resolved
Comment thread charts/aether/BUILD.bazel Resolved
Copilot AI balanced review requested due to automatic review settings October 7, 2026 23:31
@bpalermo
bpalermo force-pushed the upgrade/chart-webhook-cert-reuse branch from 74ac71f to b756355 Compare October 7, 2026 23:31

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

Clearing the rotation token loses its idempotency stamp, allowing the same token to rotate certificates again.

1 open finding
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.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 23:48
@bpalermo
bpalermo force-pushed the upgrade/chart-webhook-cert-reuse branch from b756355 to a66635b Compare October 7, 2026 23:48

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 cluster-dependent certificate reuse and rotation branches lack automated coverage.

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.

…omplete or rotated; helm template's exception is documented and pinned (#1364)

With controller.webhook.spire=false the chart generates a self-signed
webhook CA and serving certificate. An upgrade already reused the Secret
it found (lookup), so a real upgrade changed neither the Secret's data
nor a caBundle. A render without a cluster cannot look anything up and
generates a new pair every time: six lines of `helm template` differ
between two renders.

- The reuse is stated and hardened: a Secret with an empty or missing
  ca.crt, tls.crt or tls.key is replaced. Before, an empty tls.key made
  every upgrade fail ("data[tls.key]: Required value").
- controller.webhook.certRotation rotates on demand: a new value
  generates a new pair once and is stamped on the Secret. During that
  upgrade caBundle carries the new CA and the one being replaced.
- helm_template_reproducible_test renders twice and compares: identical
  with the six certificate lines masked, and with no mask at all when
  controller.webhook.spire=true. A new render-time value fails it.
- The runbook has the recipe for a stable diff and for rotation.

Chart aether 2.4.16. No pod template changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

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

Certificate rotation is cluster-state-dependent, lacks automated coverage for lookup branches, and retains a documented fail-open transition window.

0 open findings

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.

@bpalermo
bpalermo merged commit 695675e into main Oct 8, 2026
50 of 60 checks passed
@bpalermo
bpalermo deleted the upgrade/chart-webhook-cert-reuse branch October 8, 2026 00: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: helm template is not reproducible by default (the webhook CA and certificate are regenerated on every render)

2 participants