Skip to content

fix(diff): stop leaking secretref+ values into diff output - #2844

Merged
yxxhero merged 2 commits into
helmfile:mainfrom
sergioperezcheco:fix/issue-2738-secretref-diff-leak
Oct 24, 2026
Merged

yxxhero merged 2 commits into
helmfile:mainfrom
sergioperezcheco:fix/issue-2738-secretref-diff-leak

Conversation

@sergioperezcheco

Copy link
Copy Markdown
Contributor

Fixes #2738

Problem

helmfile diff resolves all vals references before writing temporary values files, so values declared with secretref+... are expanded to their plaintext secret values and shown directly in the diff output. --show-secrets only controls the flag passed to the helm-diff plugin — it has no effect on the file-based values that helmfile itself renders, so there is no way to diff a release without exposing secrets.

Root cause

Two independent Eval sites resolve refs into temporary values files:

  • prepareReleaseValuesEntries unconditionally evaluates the release's inline values via st.valsRuntime.Eval
  • renderValuesFileToBytesWithData evaluates a whole values file after template rendering (the ref+ regexp matches the secretref+ prefix as a substring, so file-based values are always fully resolved)

Fix

Add a second cached vals evaluator built with vals' ExcludeSecret option (vals ≥ v0.38): under that evaluator secretref+... entries are left unresolved while plain ref+... entries still expand. The diff path threads this through the existing option pipeline:

  • DiffOpts.ExcludeSecrets is set to !showSecrets in prepareDiffReleases
  • flagsForDiff passes it down namespaceAndValuesFlags → generateValuesFiles → generateVanillaValuesFiles so both Eval sites use the exclude-secret evaluator
  • every non-diff path (template, upgrade, lint, WriteReleasesValues) keeps false, so rendered values are unchanged there

--show-secrets continues to work as before: with the flag set, secrets are resolved and shown.

Testing

  • New table-driven tests cover both Eval sites and the generated temporary values files: with exclusion on, secretref+... stays literal (while ref+... still expands); with exclusion off, secrets resolve as before
  • go build ./..., go vet on the touched packages, gofmt clean
  • go test -p=1 ./pkg/state/ ./pkg/plugins/ ./pkg/app/ pass, including the new tests under -race

One note for reviewers: an end-to-end diff against a live cluster isn't part of the automated tests (needs a real backend), so the tests exercise the rendering pipeline up to the temporary values files.

@yxxhero yxxhero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed — thanks for tackling #2738. The restructure of the two Eval sites (values files and inline values) is correct: I verified plain ref+:// entries still resolve while secretref+... entries stay unresolved in diff output unless --show-secrets is passed.

However, I found a third leak path the patch didn't cover: --set / --set-string (and set.values) entries go through setFlags/setStringFlags, which used the regular vals runtime unconditionally — so secretref+... set values were still expanded to plaintext on the diff command line and output, bypassing excludeSecrets entirely.

I've pushed b25d23f to this branch:

  • consolidates the evaluator choice into valsEvaluator(excludeSecrets bool) (replacing valsRuntimeWithoutSecrets),
  • threads excludeSecrets through namespaceAndValuesFlags → setFlags/setStringFlags, so --set, --set-string, and set.values stay unresolved while diffing without --show-secrets,
  • the chartify path (PrepareChartify) explicitly evaluates with false since chart rendering needs resolved values,
  • adds TestSetFlags_SecretExclusion covering both modes for --set and --set-string (unresolved secretref+echo://... vs resolved plaintext, plain ref+ always resolved),
  • documents the diff semantics in docs/remote-secrets.md, including the caveat that helm-diff now compares the literal secretref+... string against what's in the cluster (which may report changes for charts that render the referenced secret into non-Secret manifests) and that --show-secrets restores the previous resolving behavior for debugging.

CI on the new commit is running (lint and DCO already green).

B Candidate and others added 2 commits October 23, 2026 21:15
`helmfile diff` resolves vals `secretref+...` entries to their plaintext
secret values while writing temporary values files, so secrets leak into
the diff output. The --show-secrets flag only controls the flag passed to
the helm-diff plugin and never reached the values-file rendering pipeline.

- add plugins.ValsInstanceExcludeSecret(): a cached vals evaluator created
  with vals' ExcludeSecret option, which expands plain `ref+...` entries
  but leaves `secretref+...` entries unresolved
- wire it through StateCreator into HelmState
- thread showSecrets from prepareDiffReleases into the values generation
  pipeline (flagsForDiff -> namespaceAndValuesFlags -> generateValuesFiles
  -> prepareReleaseValuesEntries / renderValuesFileToBytesWithData) and use
  the exclude-secret evaluator at both vals.Eval call sites when diffing
  without --show-secrets
- --show-secrets keeps the previous plaintext behavior; template, upgrade,
  lint and chartify paths are unchanged

Fixes helmfile#2738

Signed-off-by: B Candidate <[email protected]>
…de-secret runtime

- Wire App.valsExcludeSecretRuntime into the desiredStateLoader constructed in
  loadDesiredStateFromYamlWithBaseDir: the field was never set in the
  production loader, so the whole exclude-secret diff fix was a no-op in the
  built binary.
- Also exclude secretref+ resolution from --set/--set-string values while
  diffing without --show-secrets, closing the same leak via helm-diff command
  line arguments; template/upgrade/chartify keep full resolution.
- Add TestSetFlags_SecretExclusion covering both flag generators.
- Document the new --show-secrets diff semantics in docs/remote-secrets.md.

Signed-off-by: yxxhero <[email protected]>
@yxxhero
yxxhero force-pushed the fix/issue-2738-secretref-diff-leak branch from b25d23f to ca3de32 Compare October 23, 2026 13:15
@yxxhero
yxxhero merged commit 27e786d into helmfile:main Oct 24, 2026
17 checks passed
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.

Vals secretref rendered when running helmfile diff

2 participants