Repository navigation
feat: add HELMFILE_DISABLE_VALS env var to skip vals processing - #2471
Conversation
There was a problem hiding this comment.
Pull request overview
Adds environment-variable switches to disable Helmfile’s built-in vals secret resolution, enabling either pass-through of ref+ expressions (for external processing) or strict failure when unresolved ref+ expressions are present.
Changes:
- Introduces
HELMFILE_DISABLE_VALS(pass-through) andHELMFILE_DISABLE_VALS_STRICT(error onref+) gating inpkg/plugins/vals.go. - Updates
ValsInstance()to return avals.Evaluatorinterface and wires it into template secret expansion. - Adds unit tests and documents the new env vars in the docs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/plugins/vals.go | Adds pass-through/strict evaluators and env-var gating in ValsInstance(). |
| pkg/plugins/vals_test.go | Adds tests for disable/strict behavior and resets singleton between tests. |
| pkg/envvar/const.go | Defines the new env var names. |
| pkg/tmpl/expand_secret_ref.go | Adjusts secret expansion to use the updated ValsInstance() return type. |
| docs/remote-secrets.md | Documents the new env vars and conftest validation workflow. |
| docs/index.md | Adds the env vars to the “Useful internal Helmfile environment variables” list. |
| t.Fatal("strict mode should detect ref+ in arrays") | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
The new disable/strict tests don’t cover the []string input shape that existing callers use (e.g. renderValsSecrets passes map[string]any{"values": []string{...}}). As implemented, pass-through/strict evaluators will return []string unchanged and strict won’t detect ref+ inside it. Adding a test that calls evaluator.Eval(map[string]any{"values": []string{"ref+..."}}) (and asserts strict errors / pass-through returns []any) would prevent regressions.
| func TestDisableValsStrictArrayRefStringSlice(t *testing.T) { | |
| resetInstance() | |
| defer resetInstance() | |
| os.Setenv(envvar.DisableValsStrict, "true") | |
| defer os.Unsetenv(envvar.DisableValsStrict) | |
| evaluator, err := ValsInstance() | |
| if err != nil { | |
| t.Fatalf("unexpected error: %v", err) | |
| } | |
| // Should detect ref+ in arrays when the underlying type is []string, | |
| // which matches how renderValsSecrets passes values. | |
| input := map[string]any{ | |
| "values": []string{"normal", "ref+awssecrets://db/password"}, | |
| } | |
| _, err = evaluator.Eval(input) | |
| if err == nil { | |
| t.Fatal("strict mode should detect ref+ in []string arrays") | |
| } | |
| } | |
| func TestDisableValsPassThroughArrayStringSlice(t *testing.T) { | |
| resetInstance() | |
| defer resetInstance() | |
| // Enable pass-through mode and ensure strict mode is disabled. | |
| os.Setenv(envvar.DisableVals, "true") | |
| defer os.Unsetenv(envvar.DisableVals) | |
| os.Unsetenv(envvar.DisableValsStrict) | |
| evaluator, err := ValsInstance() | |
| if err != nil { | |
| t.Fatalf("unexpected error: %v", err) | |
| } | |
| input := map[string]any{ | |
| "values": []string{"normal", "ref+awssecrets://db/password"}, | |
| } | |
| out, err := evaluator.Eval(input) | |
| if err != nil { | |
| t.Fatalf("pass-through vals should not error: %v", err) | |
| } | |
| values, ok := out["values"].([]any) | |
| if !ok { | |
| t.Fatalf("expected out[\"values\"] to be []any, got %T", out["values"]) | |
| } | |
| if len(values) != 2 { | |
| t.Fatalf("expected 2 values, got %d", len(values)) | |
| } | |
| if values[0] != "normal" { | |
| t.Errorf("expected first element to be 'normal', got %v", values[0]) | |
| } | |
| if values[1] != "ref+awssecrets://db/password" { | |
| t.Errorf("expected second element to be the raw ref+, got %v", values[1]) | |
| } | |
| } |
| // passthroughEvaluator passes values through unchanged (for external vals) | ||
| type passthroughEvaluator struct{} | ||
|
|
||
| func (p *passthroughEvaluator) Eval(m map[string]any) (map[string]any, error) { | ||
| return m, nil | ||
| } | ||
|
|
||
| // strictEvaluator passes through values but errors if ref+ is detected | ||
| type strictEvaluator struct{} | ||
|
|
||
| func (s *strictEvaluator) Eval(m map[string]any) (map[string]any, error) { | ||
| if containsRefPlus(m) { | ||
| return nil, ErrValsDisabled | ||
| } | ||
| return m, nil | ||
| } |
There was a problem hiding this comment.
passthroughEvaluator.Eval/strictEvaluator.Eval currently return the input map unchanged. Some callers rely on vals' Eval normalizing slice types: e.g. pkg/state/state.go:4324 passes []string under {"values": input} and then asserts mapRendered["values"].([]any). With the new pass-through/strict evaluators, that value stays []string, so Helmfile will error even when vals is disabled (and strict mode will also miss ref+ inside []string). Consider updating the evaluators (and/or containsRefPlus) to handle []string (and potentially other typed slices) by converting to []any during traversal/return so existing callers keep working and strict detection is effective.
fc579b3 to
6f3a35a
Compare
| func containsRefPlus(v any) bool { | ||
| switch val := v.(type) { | ||
| case string: | ||
| return strings.Contains(val, "ref+") | ||
| case map[string]any: | ||
| for _, v := range val { | ||
| if containsRefPlus(v) { | ||
| return true | ||
| } | ||
| } | ||
| case []any: | ||
| for _, v := range val { | ||
| if containsRefPlus(v) { | ||
| return true | ||
| } | ||
| } | ||
| case []string: | ||
| for _, s := range val { | ||
| if strings.Contains(s, "ref+") { | ||
| return true | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
containsRefPlus doesn't traverse map[any]any values. Helmfile values often flow through YAML decoding as map[any]any (e.g., state code handles both map[any]any and map[string]any), so in HELMFILE_DISABLE_VALS_STRICT mode a ref+... nested inside a map[any]any can slip through without triggering ErrValsDisabled. Consider handling map[any]any (and/or map[string]interface{}) by iterating over the map values recursively so strict mode reliably blocks unresolved refs regardless of map key type.
| func TestDisableValsStrictNestedRef(t *testing.T) { | ||
| resetInstance() | ||
| defer resetInstance() | ||
|
|
||
| os.Setenv(envvar.DisableValsStrict, "true") | ||
| defer os.Unsetenv(envvar.DisableValsStrict) | ||
|
|
||
| evaluator, err := ValsInstance() | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| // Should detect nested ref+ | ||
| input := map[string]any{ | ||
| "outer": map[string]any{ | ||
| "inner": "ref+vault://secret", | ||
| }, | ||
| } | ||
| _, err = evaluator.Eval(input) | ||
| if err == nil { | ||
| t.Fatal("strict mode should detect nested ref+") | ||
| } | ||
| } |
There was a problem hiding this comment.
There isn't a test that exercises strict-mode detection when the input contains map[any]any (a common shape from YAML unmarshalling). Adding a regression test that passes a structure containing map[any]any{"k": "ref+..."} would help ensure HELMFILE_DISABLE_VALS_STRICT can’t be bypassed by map key type.
|
I'll try and address copilots issues. |
Signed-off-by: Jim Robinson <[email protected]>
6f3a35a to
6bae70b
Compare
| func containsRefPlus(v any) bool { | ||
| switch val := v.(type) { | ||
| case string: | ||
| return strings.Contains(val, "ref+") | ||
| case map[string]any: |
There was a problem hiding this comment.
containsRefPlus uses strings.Contains(val, "ref+"), which can produce false positives (e.g., a non-vals string containing "ref+" as part of other text/URLs). Since vals references are expected to be expressions starting with ref+, consider checking strings.HasPrefix(strings.TrimSpace(val), "ref+") (and applying the same logic in the []string branch) to avoid incorrectly erroring in strict mode.
There was a problem hiding this comment.
I'm not sure that copilot is correct here. I use the containsRefPlus to scan for ref+ when in STRICT mode. I'm searching the values not the keys for any ref+ mentions.
Testing vals with this:
prefixedValue: "foo - ref+echo://prefixed-test"
This works and renders to:
prefixedKey: "foo - prefixed-test"
So surely strings.HasPrefix() would be wrong?
@yxxhero thoughts?
There was a problem hiding this comment.
@yxxhero I also tested with:
prefixedValue: "fooref+echo://prefixed-test"
Which renders to:
prefixedKey: "fooprefixed-test"
So, I'm feeling like strings.Contains() is still OK? But I'm new to helmfile and vals, so I might be missing something.
|
@jimmyR ping |
|
@yxxhero Hi, sorry for delay, I'll resolve this weekend. |
|
@jimmyR thanks so much. |
|
@jimmyR fix review comments and conflcts. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
@copilot resolve the merge conflicts in this pull request |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
@jimmyR ping |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
@copilot resolve the merge conflicts in this pull request |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Resolve conflicts with current main: - pkg/plugins/vals.go: main replaced the sync.Once singleton with a mutex-guarded one and extracted buildValsOptions(); keep that structure and integrate the disabled-vals evaluators into it - pkg/envvar/const.go: keep new constants added alongside main's - docs: the env var list moved from docs/index.md to docs/templating.md on main, so document HELMFILE_DISABLE_VALS / HELMFILE_DISABLE_VALS_STRICT there instead Also apply review fixes to the feature: - detect refs with a regex mirroring vals' reference syntax (ref+<provider>:// and secretref+<provider>://) so plain strings containing "ref+" without a scheme no longer trigger false positives in strict mode - normalize nested []string/map[any]any recursively to match vals.Eval behavior - guard resetInstance() with the plugin mutex and restore env vars safely in tests - add tests for strict-mode precedence over pass-through, secretref+ detection, no-false-positive cases and nested type normalization Signed-off-by: yxxhero <[email protected]>
|
Hi @jimmyR — thanks for this PR! The feature and use case look solid. ✅ I pushed a merge commit ( Merge conflict resolution
Review fixes
Verified locally
I've also approved the fork CI workflows — happy to iterate further if you have any concerns about the changes. |
…#829) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [aqua:helmfile/helmfile](https://github.com/helmfile/helmfile) | tools | patch | `1.8.0` → `1.8.1` | --- ### Release Notes <details> <summary>helmfile/helmfile (aqua:helmfile/helmfile)</summary> ### [`v1.8.1`](https://github.com/helmfile/helmfile/releases/tag/v1.8.1) [Compare Source](helmfile/helmfile@v1.8.0...v1.8.1) #### What's Changed - feat: add HELMFILE\_DISABLE\_VALS env var to skip vals processing by [@​jimmyR](https://github.com/jimmyR) in [#​2471](helmfile/helmfile#2471) - build(deps): bump github.com/mattn/go-runewidth from 0.0.29 to 0.0.30 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2796](helmfile/helmfile#2796) - build(deps): bump golang.org/x/term from 0.45.0 to 0.46.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2795](helmfile/helmfile#2795) - build(deps): bump github.com/sashabaranov/go-openai from 1.42.0 to 1.42.1 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2792](helmfile/helmfile#2792) - fix: cancel kubedog-tracked helm subprocesses on SIGINT/SIGTERM by [@​vulragrag-star](https://github.com/vulragrag-star) in [#​2791](helmfile/helmfile#2791) - build(deps): bump github.com/hashicorp/go-getter/v2 from 2.2.3 to 2.2.4 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2793](helmfile/helmfile#2793) - build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.33.3 to 1.33.4 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2794](helmfile/helmfile#2794) - build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.111.0 to 1.113.1 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2797](helmfile/helmfile#2797) - build: update Go to 1.27.1 and modernize the codebase by [@​yxxhero](https://github.com/yxxhero) in [#​2798](helmfile/helmfile#2798) - build(deps): bump github.com/helmfile/chartify from 0.28.2 to 0.29.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2803](helmfile/helmfile#2803) - build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.33.4 to 1.33.5 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2801](helmfile/helmfile#2801) - build(deps): bump github.com/hashicorp/hcl/v2 from 2.24.0 to 2.25.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2802](helmfile/helmfile#2802) - feat: add per-release continue-on-error support by [@​Tsukoyachi](https://github.com/Tsukoyachi) in [#​2804](helmfile/helmfile#2804) - fix: remove partially extracted chart when helm pull fails by [@​schmidtjohannes](https://github.com/schmidtjohannes) in [#​2805](helmfile/helmfile#2805) - build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.113.1 to 1.113.2 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2808](helmfile/helmfile#2808) - build(deps): bump github.com/helmfile/vals from 0.46.1 to 0.47.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2806](helmfile/helmfile#2806) - ci: publish a signed packslip with each release by [@​jdx](https://github.com/jdx) in [#​2809](helmfile/helmfile#2809) - build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.113.2 to 1.113.4 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2811](helmfile/helmfile#2811) - build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.33.5 to 1.33.6 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2810](helmfile/helmfile#2810) - add --track-logs-interval flag by [@​pznamensky](https://github.com/pznamensky) in [#​2807](helmfile/helmfile#2807) - fix: drop leading dot from release condition error message by [@​Cayan](https://github.com/Cayan) in [#​2812](helmfile/helmfile#2812) #### New Contributors - [@​jimmyR](https://github.com/jimmyR) made their first contribution in [#​2471](helmfile/helmfile#2471) - [@​vulragrag-star](https://github.com/vulragrag-star) made their first contribution in [#​2791](helmfile/helmfile#2791) - [@​Tsukoyachi](https://github.com/Tsukoyachi) made their first contribution in [#​2804](helmfile/helmfile#2804) - [@​schmidtjohannes](https://github.com/schmidtjohannes) made their first contribution in [#​2805](helmfile/helmfile#2805) - [@​jdx](https://github.com/jdx) made their first contribution in [#​2809](helmfile/helmfile#2809) - [@​pznamensky](https://github.com/pznamensky) made their first contribution in [#​2807](helmfile/helmfile#2807) - [@​Cayan](https://github.com/Cayan) made their first contribution in [#​2812](helmfile/helmfile#2812) **Full Changelog**: <helmfile/helmfile@v1.8.0...v1.8.1> </details> --- ### Configuration 📅 **Schedule**: (in timezone Europe/London) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjEzMy4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.hayden.moe/hayden/phoebe/pulls/829
Summary
This PR adds two new environment variables to allow helmfile's built-in vals processing to be disabled. This enables a more secure pattern where
ref+expression resolution is separated from helmfile execution — allowing credential access to be tightly scoped, audited, and validated before manifests are applied.HELMFILE_DISABLE_VALS=true: Passesref+expressions through unchanged, allowing an external vals processing (with appropriately scoped credentials) to resolve them, or additional security validation.HELMFILE_DISABLE_VALS_STRICT=true: Returns an error if anyref+expressions are encountered, enforcing that all secret references have been resolved prior to helmfile executionUse Case
In some CI environments, vals resolution requires AWS credentials (e.g.
ref+tfstates3withaws_profile) that are not available during the helmfile execution phase. The vals processing can be run as a separate step with the appropriate credentials, and helmfile can then consume the pre-rendered values withHELMFILE_DISABLE_VALS=true. This is the case where one AWS profile is required to pull a chart from S3, but another is required to readref+tfstates3values.HELMFILE_DISABLE_VALS=truealso enables security validation ofref+expressions before they are resolved — using a policy tool such as conftest to enforce that only approved secret references are permitted in your helmfile values.HELMFILE_DISABLE_VALS_STRICT=trueis useful for environments whereref+expressions should never appear at helmfile execution time — it provides a safety net to catch accidental unresolved references.Changes
Core Implementation
HELMFILE_DISABLE_VALSandHELMFILE_DISABLE_VALS_STRICTconstants inpkg/envvar/const.gopkg/plugins/vals.go, controlled by the new env varsTests
pkg/plugins/vals_test.goDocumentation
docs/remote-secrets.mdBehaviour
ref+expressionHELMFILE_DISABLE_VALS=trueHELMFILE_DISABLE_VALS_STRICT=trueHELMFILE_DISABLE_VALS=trueTesting
All tests pass:
go test ./pkg/plugins/...passesValidation with conftest
HELMFILE_DISABLE_VALS=truecan be combined with conftest to validate thatref+expressions only reference approved tfstates3 URIs before processing:Example rego policy: