From 7379fa6631181a43dc307997850ca701d6443761 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 19 Aug 2019 18:18:58 +0000 Subject: [PATCH] Remove the process default ENV With the change in #3542 it breaks $PATH handling for images becuase our default spec always sets a PATH on the process's .Env. This removes the default and adds an Opt to add this back. Signed-off-by: Michael Crosby --- oci/spec.go | 1 - oci/spec_opts.go | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/oci/spec.go b/oci/spec.go index 3e7b5492a..dad87411c 100644 --- a/oci/spec.go +++ b/oci/spec.go @@ -141,7 +141,6 @@ func populateDefaultUnixSpec(ctx context.Context, s *Spec, id string) error { Path: defaultRootfsPath, }, Process: &specs.Process{ - Env: defaultUnixEnv, Cwd: "/", NoNewPrivileges: true, User: specs.User{ diff --git a/oci/spec_opts.go b/oci/spec_opts.go index 4f81eaef2..bbd820082 100644 --- a/oci/spec_opts.go +++ b/oci/spec_opts.go @@ -151,6 +151,13 @@ func WithEnv(environmentVariables []string) SpecOpts { } } +// WithDefaultPathEnv sets the $PATH environment variable to the +// default PATH defined in this package. +func WithDefaultPathEnv(_ context.Context, _ Client, _ *containers.Container, s *Spec) error { + s.Process.Env = replaceOrAppendEnvValues(s.Process.Env, defaultUnixEnv) + return nil +} + // replaceOrAppendEnvValues returns the defaults with the overrides either // replaced by env key or appended to the list func replaceOrAppendEnvValues(defaults, overrides []string) []string {