Skip to content

feat: support disabling insecure template functions only#2689

Open
fabiobaiao wants to merge 1 commit into
helmfile:mainfrom
fabiobaiao:feat/disable-insecure-template-functions
Open

feat: support disabling insecure template functions only#2689
fabiobaiao wants to merge 1 commit into
helmfile:mainfrom
fabiobaiao:feat/disable-insecure-template-functions

Conversation

@fabiobaiao

Copy link
Copy Markdown

Adds support to disable insecure template functions only, still allowing remote charts

Closes #2687

@fabiobaiao fabiobaiao force-pushed the feat/disable-insecure-template-functions branch from 56d7470 to 1aa2144 Compare July 6, 2026 18:25
@yxxhero yxxhero requested a review from Copilot July 6, 2026 22:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new environment variable gate to disable only “insecure” template functions (exec/readFile/readDir, etc.) while preserving the existing broader HELMFILE_DISABLE_INSECURE_FEATURES behavior, supporting safer templating without necessarily blocking other functionality like remote charts.

Changes:

  • Introduces HELMFILE_DISABLE_INSECURE_TEMPLATE_FUNCTIONS env var and wires it into template function-map creation.
  • Renames the error type/variable used when insecure template functions are disabled.
  • Adds/updates unit tests for both disable modes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pkg/tmpl/context_funcs.go Adds new env-var flag and applies it to disabling insecure template functions; updates error type/name.
pkg/tmpl/context_funcs_test.go Updates existing test expectations and adds a new test for the new env-var gate.
pkg/envvar/const.go Adds the new HELMFILE_DISABLE_INSECURE_TEMPLATE_FUNCTIONS constant.

Comment thread pkg/tmpl/context_funcs.go Outdated
type Values = map[string]any

var DisableInsecureFeaturesErr = DisableInsecureFeaturesError{envvar.DisableInsecureFeatures + " is active, insecure function calls are disabled"}
var DisableInsecureFunctionsErr = DisableInsecureFunctionsError{envvar.DisableInsecureFeatures + "/" DisableInsecureTemplateFunctions + " is active, insecure function calls are disabled"}
Comment thread pkg/tmpl/context_funcs.go
Comment on lines 95 to 100
funcMap["readDir"] = func(string) ([]string, error) {
return nil, DisableInsecureFeaturesErr
return nil, DisableInsecureFunctionsErr
}
funcMap["readDirEntries"] = func(string) ([]string, error) {
return nil, DisableInsecureFeaturesErr
return nil, DisableInsecureFunctionsErr
}
Comment on lines +49 to +64
func TestCreateFuncMap_DisabledInsecureTemplateFunctions(t *testing.T) {
currentVal := disableInsecureFunctions

{
disableInsecureFunctions = true
ctx := &Context{basePath: "."}
funcMaps := ctx.createFuncMap()
args := make([]any, 0)
_, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
require.ErrorIs(t, err1, DisableInsecureFunctionsErr)
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
require.ErrorIs(t, err2, DisableInsecureFunctionsErr)
}

disableInsecureFunctions = currentVal
}
@fabiobaiao fabiobaiao force-pushed the feat/disable-insecure-template-functions branch from 1aa2144 to 03b91b1 Compare July 7, 2026 08:45
@yxxhero yxxhero requested a review from Copilot July 7, 2026 09:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread pkg/tmpl/context_funcs.go Outdated
Comment on lines 27 to 31
var DisableInsecureFunctionsErr = DisableInsecureFunctionsError{envvar.DisableInsecureFeatures + " or " DisableInsecureTemplateFunctions + " is active, insecure function calls are disabled"}

type DisableInsecureFeaturesError struct {
type DisableInsecureFunctionsError struct {
err string
}
Comment on lines +49 to +64
func TestCreateFuncMap_DisabledInsecureTemplateFunctions(t *testing.T) {
currentVal := disableInsecureTemplateFunctions

{
disableInsecureTemplateFunctions = true
ctx := &Context{basePath: "."}
funcMaps := ctx.createFuncMap()
args := make([]any, 0)
_, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
require.ErrorIs(t, err1, DisableInsecureFunctionsErr)
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
require.ErrorIs(t, err2, DisableInsecureFunctionsErr)
}

disableInsecureTemplateFunctions = currentVal
}
@fabiobaiao fabiobaiao force-pushed the feat/disable-insecure-template-functions branch from 03b91b1 to 5927eb0 Compare July 7, 2026 09:14
@yxxhero yxxhero requested a review from Copilot July 8, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread pkg/tmpl/context_funcs.go
Comment on lines +27 to 31
var DisableInsecureFunctionsErr = DisableInsecureFunctionsError{envvar.DisableInsecureFeatures + " or " + envvar.DisableInsecureTemplateFunctions + " is active, insecure function calls are disabled"}

type DisableInsecureFeaturesError struct {
type DisableInsecureFunctionsError struct {
err string
}
Comment thread pkg/tmpl/context_funcs.go
Comment on lines 95 to 100
funcMap["readDir"] = func(string) ([]string, error) {
return nil, DisableInsecureFeaturesErr
return nil, DisableInsecureFunctionsErr
}
funcMap["readDirEntries"] = func(string) ([]string, error) {
return nil, DisableInsecureFeaturesErr
return nil, DisableInsecureFunctionsErr
}
Comment thread pkg/tmpl/context_funcs.go Outdated

func init() {
disableInsecureFeatures, _ = strconv.ParseBool(os.Getenv(envvar.DisableInsecureFeatures))
disableInsecureFeatures, _ = strconv.ParseBool(os.Getenv(envvar.DisableInsecureFeatures))
Comment on lines 40 to +43
_, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
require.ErrorIs(t, err1, DisableInsecureFeaturesErr)
require.ErrorIs(t, err1, DisableInsecureFunctionsErr)
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
require.ErrorIs(t, err2, DisableInsecureFeaturesErr)
require.ErrorIs(t, err2, DisableInsecureFunctionsErr)
Comment on lines +49 to +64
func TestCreateFuncMap_DisabledInsecureTemplateFunctions(t *testing.T) {
currentVal := disableInsecureTemplateFunctions

{
disableInsecureTemplateFunctions = true
ctx := &Context{basePath: "."}
funcMaps := ctx.createFuncMap()
args := make([]any, 0)
_, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
require.ErrorIs(t, err1, DisableInsecureFunctionsErr)
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
require.ErrorIs(t, err2, DisableInsecureFunctionsErr)
}

disableInsecureTemplateFunctions = currentVal
}
@fabiobaiao fabiobaiao force-pushed the feat/disable-insecure-template-functions branch from 1f5cccb to 77b4377 Compare July 8, 2026 09:47
Signed-off-by: fabiobaiao <53570695+fabiobaiao@users.noreply.github.com>
@yxxhero yxxhero force-pushed the feat/disable-insecure-template-functions branch from 77b4377 to 98ca978 Compare July 8, 2026 13:40
@yxxhero yxxhero requested a review from Copilot July 8, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread pkg/tmpl/context_funcs.go
Comment on lines +27 to +29
var DisableInsecureFunctionsErr = DisableInsecureFunctionsError{envvar.DisableInsecureFeatures + " or " + envvar.DisableInsecureTemplateFunctions + " is active, insecure function calls are disabled"}

type DisableInsecureFeaturesError struct {
type DisableInsecureFunctionsError struct {
Comment thread pkg/tmpl/context_funcs.go
Comment on lines 98 to 100
funcMap["readDirEntries"] = func(string) ([]string, error) {
return nil, DisableInsecureFeaturesErr
return nil, DisableInsecureFunctionsErr
}
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.

2 participants