diff --git a/kyaml/fn/runtime/container/container.go b/kyaml/fn/runtime/container/container.go index 9b4d43876..590232d11 100644 --- a/kyaml/fn/runtime/container/container.go +++ b/kyaml/fn/runtime/container/container.go @@ -195,7 +195,7 @@ func (c *Filter) getCommand() (string, []string) { // export the local environment vars to the container for _, pair := range os.Environ() { items := strings.Split(pair, "=") - if items[0] == "" || items[1] == "" { + if items[0] == "" || items[1] == "" || shouldEnvIgnored(items[0]) { continue } args = append(args, "-e", items[0]) @@ -203,3 +203,15 @@ func (c *Filter) getCommand() (string, []string) { a := append(args, c.Image) return "docker", a } + +// shouldEnvIgnored returns true if the environment variable key should be ignored +// by the container runtime. +func shouldEnvIgnored(envKey string) bool { + ignoreEnvKey := []string{"TMPDIR"} + for _, k := range ignoreEnvKey { + if k == envKey { + return true + } + } + return false +} diff --git a/kyaml/fn/runtime/container/container_test.go b/kyaml/fn/runtime/container/container_test.go index 2e054f945..1c465c7d2 100644 --- a/kyaml/fn/runtime/container/container_test.go +++ b/kyaml/fn/runtime/container/container_test.go @@ -210,3 +210,20 @@ func TestFilter_ExitCode(t *testing.T) { t.FailNow() } } + +func TestIgnoreEnv(t *testing.T) { + ignoredEnvKey := []string{"TMPDIR"} + for _, key := range ignoredEnvKey { + os.Setenv(key, "") + } + + fltr := Filter{Image: "example.com:version"} + _, args := fltr.getCommand() + for _, arg := range args { + for _, key := range ignoredEnvKey { + if arg == key { + t.Fatalf("%s should not be exported to container", key) + } + } + } +}