Skip to content

test(chart): template tests reach every document of a multi-document template, and a failing test never prints Secret data (#1371, #1382) - #1410

Merged
bpalermo merged 6 commits into
mainfrom
test/chart-multidoc-masked-1371-1382
Oct 8, 2026
Merged

bpalermo merged 6 commits into
mainfrom
test/chart-multidoc-masked-1371-1382

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #1371
Closes #1382

Tests and test rules only. No template and no values.yaml changes (git diff origin/main -- charts/*/templates charts/*/values.yaml is empty), so the charts render what they rendered, apart from the helm.sh/chart version label.

The two facts behind the issues

Read from rules_helm's runner (helm/private/runner/runner.go):

  1. parseHelmOutput keeps one document per # Source: path, so for a template with several documents only the one helm prints last is searched. Helm prints a release's objects sorted by kind, so that is not the last one in the file either: for controller-webhook.yaml it is the ValidatingWebhookConfiguration, for controller-rbac.yaml the RoleBinding.
  2. It prints the whole render (fmt.Print(test_stream.String())) before it checks any pattern, so the render is in the test log of a passing test too, not only on a mismatch as chart tests: a failing helm_template_test prints the whole render, including the generated webhook private key #1382 says. Measured on this branch: the test.log of a passing aether_agent_restart_fast_path_test is 2,348 lines (the render); with the option described below it holds no kind: Secret and no tls.key. aether_template_test, moved to the masked rule, logs 4 lines.

#1371: which documents no test could reach

Measured by rendering each chart with the toolchain's helm (4.2.0) with every relevant switch on. [last] is the document a template_patterns entry searches.

Template Documents (in the order helm prints them) Covered before Now
aether agent-rbac.yaml ClusterRole, [last] ClusterRoleBinding neither both
aether agent-serviceaccount.yaml ServiceAccount (agent), [last] ServiceAccount (proxy) neither both
aether controller-rbac.yaml 2 ClusterRoles, 2 ClusterRoleBindings, Role, [last] RoleBinding none all six
aether controller-webhook.yaml Secret, MutatingWebhookConfiguration, [last] ValidatingWebhookConfiguration the Secret's rotation annotation only (absence tests, #1368) and the six generated lines (reproducibility test) all three
aether registrar-rbac.yaml ClusterRole, ClusterRoleBinding, Role, [last] RoleBinding none all four
aether edge-rbac.yaml ClusterRole, [last] ClusterRoleBinding neither both
aether edge-httproute.yaml one HTTPRoute per edge.gateway.httpRoutes entry, [last] by name none two routes
udsecho uds-cr-echo.yaml ServiceAccount, Deployment, [last] EndpointPolicy none all three
udsecho uds-echo.yaml, client.yaml ServiceAccount, [last] Deployment none all four
crds every template renders one document n/a no change
prober authz-canary.yaml 2 ServiceAccounts, 2 Deployments, [last] HTTPFilter already on helm_template_match_test (#1365, #1397) not touched here

No existing test was silently testing the wrong document: none of the 81 upstream tests in charts/aether is keyed on a multi-document template (the ten template files they name each render one document).

The new tests (25)

charts/aether: aether_agent_rbac_test, _namespace_test, _gamma_and_uds_off_test; aether_agent_service_accounts_test, aether_proxy_service_account_off_test; aether_controller_rbac_test, _webhook_spire_test; aether_registrar_rbac_test, _mcs_test; aether_edge_rbac_test, _tls_test; aether_edge_httproutes_test, _default_test; aether_webhook_documents_test, aether_webhook_ndots_only_test, aether_webhook_namespace_injection_only_test, aether_webhook_mutating_off_test; aether_webhook_spire_no_secret_test, _all_enabled_test; and the two moved tests below.
charts/udsecho: udsecho_documents_test, udsecho_socket_override_test, udsecho_policy_path_off_test, udsecho_no_secret_test.

What they pin, in short: each RBAC rule as rendered (the agent's eviction grant in the core group, the node patch grants, what agent.gamma, udsCsi.enabled, registrar.enableMCS, edge.tls.enabled and controller.webhook.spire add or remove); every binding's role and its one subject in the right namespace; every webhook entry's failurePolicy: Ignore, selector, path and a non-empty caBundle, and that the mutating configuration holds exactly the entries its two switches ask for; the Secret's shape (never its content).

Left out on purpose: label blocks on RBAC and ServiceAccount objects (the #1363 tests already cover what matters about labels); the SPIRE-served webhook's positive shape (the existing aether_webhook_cert_rotation_spire_test already asserts no Secret and no caBundle); the controller's RBAC with webhook.spire=true and injectPodNdots=false, which looks wrong and is reported below rather than pinned.

#1382: what a failing test prints

helm_template_match_test now prints the pattern, the document it searched, and at most 16 lines from where the pattern stopped matching, taken from a masked copy of the render (the rule is below). It never prints the render. Example (a temporary failurePolicy: Fail):

FAIL: MutatingWebhookConfiguration/release-name-aether-controller-default-pod-ndots (aether/templates/controller-webhook.yaml, document 2) does not match the pattern:
  \nwebhooks:\n(\s+#[^\n]*\n)*  - name: ndots\.pods\.aether\.io\n ...
  the first 6 of the pattern's 29 lines match (lines 13-21 of ...); the rest does not match what follows:
       19    - name: ndots.pods.aether.io
       20      admissionReviewVersions: ["v1"]
       21      sideEffects: None
       22>     # Ignore: a down webhook must never block pod scheduling (a fail-closed pod
       23      # webhook is a cluster-wide outage). Missing ndots only degrades musl mesh-DNS.
       24      failurePolicy: Fail

The other five rules in defs.bzl printed helm's output when helm failed; with --debug that includes the render. Every runner now captures helm's stdout (the render) and stderr apart and shows only stderr, masked and cut to 30 lines; the rejection test no longer prints a render that should have been rejected. One consequence: helm_template_match_test and helm_template_absent_test now search helm's stdout only, not stdout and stderr together.

The mask fails closed. It does not try to recognise a Secret, which YAML can spell in more ways than a line pattern can follow. A document is printed as it is only when it is plainly something else: exactly one top-level kind: <Word> line (optionally quoted, optional trailing comment) whose word is not Secret or List, not flow style or JSON, no top-level explicit (?) or merge (<<) key, and no kind: Secret anywhere else in it. In a document that might be a Secret, only these lines are ever printed, and only as simple key: scalar lines: the # Source: comment, apiVersion:, kind:, type:, metadata: and the name: / namespace: directly under it. Everything else is <masked>. So a ConfigMap written the usual way stays readable in an excerpt, and a failure in a Secret shows which Secret and where, never what is in it.

The shell is in bazel/helm/render_lib.sh: bash [[ =~ ]] and POSIX awk, no grep -P, no \s in an ERE or an awk pattern. The rule also translates \S now ([^[:space:]]), next to \n and \s: the prober tests merged in #1397 use \S+, which glibc's regcomp takes as it is and BSD's does not.

The test of the rule itself

//bazel/helm:template_rules_test runs fifteen runners that fail by design over bazel/helm/testdata/secretchart, a chart of Secrets in every shape (plain keys, stringData, a block scalar, a flow mapping, a Secret inside a List, data before kind, a kind line with a comment, whole documents in flow style and in JSON, whitespace before a key's colon, a kind that is anchored, tagged, aliased or missing, explicit and block-scalar keys, values behind a merge key), in which every Secret value starts with FORBIDDEN. It requires each to fail, to say what a reader needs, to stay within a line bound, and to print no FORBIDDEN byte. The control is :documents_test, which matches those same values in the same render. It repeats with every awk the host has (here: gawk, mawk, busybox awk).

The failing runners are not tests: scripts/ci-impacted-targets.sh hands CI every test target bazel query 'tests(//...)' finds, manual ones included, so a target that fails by design cannot be one. Each of the five rules that can print helm output has a _runner twin (same implementation, plain executable) for this.

The tests that stay on the upstream rule

79 of the 81 upstream tests in charts/aether now pass --set controller.webhook.spire=true (77 added, 2 already had it). Why that does not change what they check, measured: with and without the switch, at default values and with edge, the authz sidecar and telemetry on, exactly three template files differ (controller-deployment.yaml, controller-rbac.yaml, controller-webhook.yaml). For the tests keyed on controller-deployment.yaml, the diff of that file is the same 20 lines (the webhook-serving flags, one volume, one mount) under each of those tests' own options, and none of their patterns is about those lines.

Moved to the masked rule (2):

  • aether_template_test: it is the "default values render" test, so it cannot take the switch. It now also names the eleven objects the default render must hold.
  • aether_identity_gate_no_spire_test: it renders a mesh without SPIRE; adding the SPIRE-served webhook to that would be a contradiction.

Two guards keep this from regressing: aether_upstream_template_tests_render_no_secret_test fails any helm_template_test in that BUILD file whose opts list does not hold the option right after a "--set" (it has a self-test over calls that hold the text in a comment or another attribute), and aether_webhook_spire_no_secret_test (+ _all_enabled_test) prove the option renders no Secret. udsecho_no_secret_test does the second job for udsecho, whose one upstream test renders at default values.

Red, then green

  • The 25 new or moved chart tests: one temporary mutation per thing asserted (eviction grant under policy, a hard-coded binding namespace, a dropped verb, failurePolicy: Fail, a switch replaced by if true, a stray HTTPRoute, ...), all applied at once. All 25 failed, each on the line it is about; 118 other tests kept passing and 4 existing tests failed with them, as they should (aether_identity_gate_disabled_test, aether_reproducible_webhook_spire_test, aether_uds_csi_off_test, aether_webhook_cert_rotation_spire_test). Templates restored from git; 177 of 177 pass. Run twice, before and after the patterns were tidied.
  • The masking: with the mask switched off (secret = 0), template_rules_test fails with prints Secret data for five runners, under each awk.
  • The option guard: with the option removed from one test it fails and names that test.
  • The real chart: a temporary, deliberately failing match on the default aether render, aimed at the Secret, printed no base64 run of 40 or more characters (since the final version of the mask, a Secret shows only its identity lines).

Also run: bazel test //charts/... //bazel/helm/..., the lint build (--config=lint with fail_on_violation), make format-check, scripts/check-shell-lint.sh, scripts/check-chart-version-bump.sh.

Chart versions

scripts/check-chart-version-bump.sh diffs the whole charts/<name>/ directory, so a BUILD.bazel-only change needs a bump: aether 2.4.16 -> 2.4.17, udsecho 2.0.1 -> 2.0.2. crds and prober are not touched. No other open pull request touches either Chart.yaml.

On upgrade

Nothing to do. No pod rolls: the pod templates do not carry the chart version (#1363, aether_pod_template_version_test).

Not verified

  • macOS / BSD: the awk program ran under gawk, mawk and busybox awk, and bash's [[ =~ ]] under glibc only.
  • That CI's log upload no longer holds a key: inferred from the above, not read from a CI log.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Copilot AI balanced review requested due to automatic review settings October 8, 2026 11: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.

🟡 Changes recommended

Some valid failure paths can still expose unmasked Secret data.

2 open findings
What changed in this PR

Improves Helm chart testing by supporting multi-document templates and masking Secret data in failure logs.

Changes:

  • Adds document-scoped matching and bounded, masked diagnostics.
  • Expands Aether and udsecho chart coverage.
  • Adds regression fixtures, documentation, guards, and chart version bumps.
File Description
charts/​udsecho/​Chart.yaml Bumps chart version.
charts/​udsecho/​BUILD.bazel Adds document and Secret guards.
charts/​README.md Documents test-rule selection.
charts/​aether/​Chart.yaml Bumps chart version.
charts/​aether/​BUILD.bazel Adds multi-document tests and safer options.
bazel/​helm/​upstream_template_test_opts_test.sh Enforces Secret-free upstream tests.
bazel/​helm/​testdata/​secretchart/​values.yaml Defines masking fixtures.
bazel/​helm/​testdata/​secretchart/​templates/​multi.yaml Exercises multi-document Secrets.
bazel/​helm/​testdata/​secretchart/​templates/​list.yaml Exercises nested Secrets.
bazel/​helm/​testdata/​secretchart/​templates/​broken.yaml Exercises failed rendering.
bazel/​helm/​testdata/​secretchart/​Chart.yaml Defines the test chart.
bazel/​helm/​testdata/​secretchart/​BUILD.bazel Defines rule regression runners.
bazel/​helm/​template_rules_test.sh Validates bounded, masked diagnostics.
bazel/​helm/​render_lib.sh Adds rendering, splitting, and masking helpers.
bazel/​helm/​defs.bzl Extends Helm test rules.
bazel/​helm/​BUILD.bazel Wires shell helpers and regression tests.

🧠 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
Comment thread bazel/helm/render_lib.sh Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:27
@bpalermo
bpalermo force-pushed the test/chart-multidoc-masked-1371-1382 branch from b43a147 to b0095d6 Compare October 8, 2026 11:27

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

Valid flow-style YAML Secrets bypass the masker and can expose their data in test logs.

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.

Comment thread bazel/helm/render_lib.sh Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:34
@bpalermo
bpalermo force-pushed the test/chart-multidoc-masked-1371-1382 branch from b0095d6 to 4919113 Compare October 8, 2026 11:34

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

Valid Secret syntax and one assertion path can still expose Secret values, while flow-style documents cannot use the new per-document API.

3 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.

Comment thread bazel/helm/defs.bzl Resolved
Comment thread bazel/helm/render_lib.sh Resolved
Comment thread bazel/helm/render_lib.sh 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.

🟡 Changes recommended

Secret masking and its upstream-test guard still have bypasses that can expose rendered Secret data.

2 open findings
3 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/render_lib.sh Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:59
@bpalermo
bpalermo force-pushed the test/chart-multidoc-masked-1371-1382 branch from 436b60d to b158875 Compare October 8, 2026 11: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

Explicit YAML mapping keys can bypass Secret masking, and two new RBAC tests omit rendered grants.

3 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 bazel/helm/render_lib.sh Resolved
Comment thread charts/aether/BUILD.bazel Resolved
Comment thread charts/aether/BUILD.bazel Resolved
…template, and a failing test never prints Secret data (#1371, #1382)

rules_helm's helm_template_test keeps one document per template file, the one
helm prints last (helm sorts by kind), and its runner prints the whole render
into the test log whether the test passes or fails. With default values the
aether chart generates the webhook's private key at render time.

bazel/helm:
- helm_template_match_test gains document_patterns ({"<Kind>/<name>": [...]}):
  patterns matched inside one named document, wherever it is in its template.
- On a mismatch it prints the pattern, the document searched and at most 16
  lines from where the pattern stopped matching, from a copy of the render in
  which the data/stringData of every Secret document is masked. It never prints
  the render. helm_template_fail_test, _absent_test and _value_changes_test mask
  and bound what helm printed in the same way.
- render_lib.sh holds the shared shell (POSIX awk and bash [[ =~ ]] only).
- //bazel/helm:template_rules_test runs deliberately failing runners over a
  chart of Secrets in every shape and requires that no Secret byte is printed,
  with every awk the host has.

charts/aether (2.4.17), charts/udsecho (2.0.2): tests only.
- 25 new tests for the documents that were out of reach: agent, controller,
  registrar and edge RBAC, the two ServiceAccounts, the webhook Secret and both
  webhook configurations, the edge HTTPRoutes, udsecho's ServiceAccounts and
  the uds-cr-echo Deployment.
- Every rules_helm helm_template_test in charts/aether passes
  controller.webhook.spire=true (no Secret rendered; a guard test enforces it);
  the two that need the default webhook path moved to the masked rule.

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 12:14
@bpalermo
bpalermo force-pushed the test/chart-multidoc-masked-1371-1382 branch from b158875 to ff7e42b Compare October 8, 2026 12:14

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 masker exposes data from valid SecretList manifests.

1 open finding
3 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/render_lib.sh Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:17

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 masker can expose nested Secret data when the nested kind uses YAML anchors or similar properties.

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 bazel/helm/render_lib.sh Resolved
…s possibly Secret

Review on #1410. A SecretList printed its items' data (the kind is a plain
word, the items carry no kind line), and a plainly-kinded object carrying a
Secret whose nested kind had a YAML anchor was printed verbatim. A document is
now readable only if its top-level kind does not end in List and no kind key
anywhere inside it is Secret, a typed list, or written with an anchor, a tag
or an alias. Both shapes are fixtures; the rule's test printed their values
on 2 lines before the change.

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 12:25

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 masker can still expose an embedded Secret whose kind uses an indented explicit YAML key.

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.

Comment thread bazel/helm/render_lib.sh Resolved
…nreadable to the mask

Review on #1410. A plainly-kinded object could embed a Secret through an
indented explicit key (`? kind` / `: Secret`); only column 0 was checked.
Fixture added; the rule's test printed its value on 1 line before the change.

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 12:34

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 flow-style or JSON Secret in the first Helm stderr chunk bypasses masking and exposes its data.

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/render_lib.sh Resolved
Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:38

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 security-sensitive redaction boundary and broad Helm test-runner changes warrant final human review.

1 open finding

🧠 Review effort: Balanced


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

…as a flow document

Review on #1410. The stream mode printed its first chunk unmasked unless it
had a block-style manifest marker, so a JSON Secret on stderr printed its
data. An error message does neither; a bracketed tag such as [ERROR] still
prints. Regression check added, red against the previous library.

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 12:52

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

Security-sensitive redaction and extensive generated-runner changes warrant final human review despite strong regression coverage.

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 fb6d4ab into main Oct 8, 2026
31 checks passed
@bpalermo
bpalermo deleted the test/chart-multidoc-masked-1371-1382 branch October 8, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants