Skip to content

Commit

Permalink
Remove sprig's env and expandenv functions
Browse files Browse the repository at this point in the history
Both Helm and ArgoCD remove access to these two due to security implications.
It's possible to retrieve the function's pod environmental values.
Some of these might be sensitive.

See more:

https://masterminds.github.io/sprig/os.html
argoproj/argo-workflows#5850
https://github.com/helm/helm/blob/e81f6140ddb22bc99a08f7409522a8dbe5338ee3/pkg/engine/funcs.go#L45

Also ran a go fmt.

Signed-off-by: Jakub Ciolek <[email protected]>
  • Loading branch information
jake-ciolek committed Feb 5, 2024
1 parent 1fbc444 commit 3be60dc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions function_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ func GetNewTemplateWithFunctionMaps(delims *v1beta1.Delims) *template.Template {
tpl.Funcs(f)
}
tpl.Funcs(template.FuncMap{
"include": initInclude(tpl),
"include": initInclude(tpl),
})
tpl.Funcs(sprig.FuncMap())
// Sprig's env and expandenv can lead to information leakage (injected tokens/passwords).
// Both Helm and ArgoCD remove these due to security implications.
// see: https://masterminds.github.io/sprig/os.html
sprigFuncs := sprig.FuncMap()
delete(sprigFuncs, "env")
delete(sprigFuncs, "expandenv")
tpl.Funcs(sprigFuncs)

return tpl
}
Expand Down Expand Up @@ -103,4 +109,4 @@ func initInclude(t *template.Template) func(string, interface{}) (string, error)
return buf.String(), err
}

}
}

0 comments on commit 3be60dc

Please sign in to comment.