From a5ceb54cafebf8e8c7e3a569f2af1122bf655ca3 Mon Sep 17 00:00:00 2001 From: John OConnor Date: Fri, 8 Jul 2022 15:39:42 -0700 Subject: [PATCH] only perform chown operation for non root users (#1250) --- pkg/container/docker_run.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index 7f0a577..faf11a8 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -130,7 +130,9 @@ func (cr *containerReference) Start(attach bool) common.Executor { cr.tryReadGID(), func(ctx context.Context) error { // If this fails, then folders have wrong permissions on non root container - _ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), cr.input.WorkingDir}, nil, "0", "")(ctx) + if cr.UID != 0 || cr.GID != 0 { + _ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), cr.input.WorkingDir}, nil, "0", "")(ctx) + } return nil }, ).IfNot(common.Dryrun), @@ -165,7 +167,9 @@ func (cr *containerReference) CopyDir(destPath string, srcPath string, useGitIgn cr.copyDir(destPath, srcPath, useGitIgnore), func(ctx context.Context) error { // If this fails, then folders have wrong permissions on non root container - _ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), destPath}, nil, "0", "")(ctx) + if cr.UID != 0 || cr.GID != 0 { + _ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), destPath}, nil, "0", "")(ctx) + } return nil }, ).IfNot(common.Dryrun)