Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(executor): Allow PNS to runAsNonRoot with injected sidecar. Fixes #6030 #6032

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/argoexec/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ func NewRootCommand() *cobra.Command {
func initExecutor() *executor.WorkflowExecutor {
version := argo.GetVersion()
executorType := os.Getenv(common.EnvVarContainerRuntimeExecutor)
log.WithFields(log.Fields{"version": version.Version, "executorType": executorType}).Info("Starting Workflow Executor")
groups, _ := os.Getgroups()
log.WithField("version", version.Version).
WithField("executorType", executorType).
WithField("groups", groups).
WithField("gid", os.Getgid()).
WithField("uid", os.Getuid()).
WithField("pid", os.Getpid()).
Info("Starting Workflow Executor")
config, err := clientConfig.ClientConfig()
checkErr(err)
config = restclient.AddUserAgent(config, fmt.Sprintf("argo-workflows/%s argo-executor/%s", version.Version, executorType))
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/run_as_not_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func (s *RunAsNonRootSuite) TestRunAsNonRootWorkflow() {
WaitForWorkflow(fixtures.ToBeSucceeded)
}

func (s *RunAsNonRootSuite) TestRunAsNonRootSidecarInjectedWorkflow() {
s.Need(fixtures.None(fixtures.Docker))
s.Given().
Workflow("@testdata/runasnonroot-sidecar-injected-workflow.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded)
}

func (s *RunAsNonRootSuite) TestRunAsNonRootWithOutputParams() {
s.Need(fixtures.None(fixtures.Docker, fixtures.K8SAPI, fixtures.Kubelet))
s.Given().
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/testdata/runasnonroot-sidecar-injected-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: runasnonroot-sidecar-injected-
spec:
entrypoint: main
securityContext:
runAsNonRoot: true
runAsUser: 8737
podSpecPatch: |
terminationGracePeriodSeconds: 3
containers:
- name: wait
- name: main
- name: sidecar
image: argoproj/argosay:v1
command:
- sh
- -c
args:
- "sleep 999"
templates:
- name: main
container:
image: argoproj/argosay:v1
7 changes: 5 additions & 2 deletions workflow/executor/pns/pns.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,11 @@ func (p *PNSExecutor) getContainerPID(containerName string) int {
}

func containerNameForPID(pid int) (string, error) {
anonymousName := fmt.Sprintf("%s%d", anonymousPIDPrefix, pid) // we give all a "container name", including a fake name for injected sidecars
data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/environ", pid))
if err != nil {
if os.IsPermission(err) {
return anonymousName, nil
} else if err != nil {
return "", err
}
prefix := common.EnvVarContainerName + "="
Expand All @@ -299,7 +302,7 @@ func containerNameForPID(pid int) (string, error) {
return strings.TrimPrefix(l, prefix), nil
}
}
return fmt.Sprintf("%s%d", anonymousPIDPrefix, pid), nil // we give all a "container name", including a fake name for injected sidecars
return anonymousName, nil
}

func (p *PNSExecutor) secureRootFiles() error {
Expand Down