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/emissary): fix nonroot sidecars + input/output params & artifacts #6403

Merged
merged 4 commits into from
Jul 26, 2021

Conversation

Bobgy
Copy link
Contributor

@Bobgy Bobgy commented Jul 22, 2021

This fully fixes emissary + nonroot.
I've tested sidecars, input/output parameters and artifacts

Checklist:

Tips:

  • Your PR needs to pass the required checks before it can be approved. If the check is not required (e.g. E2E tests) it does not need to pass
  • Sign-off your commits to pass the DCO check: git commit --signoff.
  • Run make pre-commit -B to fix codegen or lint problems.
  • Say how how you tested your changes. If you changed the UI, attach screenshots.

if err := os.MkdirAll(varRunArgo+"/ctr/"+containerName, 0o700); err != nil {
// default umask can be 022
// setting umask as 0 allow granting write access to other non-root users
syscall.Umask(0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I put this into os_specific?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syscall.Umask(0) is not available on Windows. So you'll need to move this command into os_specific. The Windows implementation can be a no-op.

@codecov
Copy link

codecov bot commented Jul 22, 2021

Codecov Report

Merging #6403 (2ca568a) into master (4da8fd9) will decrease coverage by 0.01%.
The diff coverage is 25.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6403      +/-   ##
==========================================
- Coverage   48.81%   48.80%   -0.02%     
==========================================
  Files         253      253              
  Lines       18153    18155       +2     
==========================================
- Hits         8861     8860       -1     
- Misses       8324     8327       +3     
  Partials      968      968              
Impacted Files Coverage Δ
workflow/executor/emissary/emissary.go 0.00% <0.00%> (ø)
cmd/argoexec/commands/emissary.go 50.35% <40.00%> (+0.35%) ⬆️
workflow/metrics/server.go 15.78% <0.00%> (-3.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4da8fd9...2ca568a. Read the comment docs.

@Bobgy
Copy link
Contributor Author

Bobgy commented Jul 22, 2021

Hi @alexec, I wonder whether you have any docs or examples for how to add workflows as tests?
I think it'll be a lot more confident checking in workflows to verify the fix and make sure we don't break it in the future.

@Bobgy
Copy link
Contributor Author

Bobgy commented Jul 22, 2021

nonroot sidecar example:

#### sidecar example ####
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: nonroot-sidecar-
spec:
  serviceAccountName: pipeline-runner
  entrypoint: sidecar-example
  templates:
  - name: sidecar-example
    container:
      image: alpine:latest
      command: [sh, -c]
      args: ["
        apk update &&
        apk add curl &&
        until curl 'http:https://127.0.0.1:8080'; do sleep 5; done &&
      "]
    sidecars:
    - name: http-echo
      image: mendhak/http-https-echo:19
      command: ['docker-entrypoint.sh']
      args: ['node', './index.js']
      envs:
      - name: HTTP_PORT
        value: 8080

nonroot parameter passing

#### parameter passing test workflow for non-root ####
# Output parameters provide a way to use the contents of a file,
# as a parameter value in a workflow. In that regard, they are
# similar in concept to script templates, with the difference being
# that the output parameter values are obtained via file contents
# instead of stdout (as with script templates). Secondly, there can
# be multiple 'output.parameters.xxx' in a single template, versus
# a single 'output.result' from a script template.
# 
# In this example, the 'whalesay' template produces an output
# parameter named 'hello-param', taken from the file contents of
# /tmp/hello_world.txt. This parameter is passed to a subsequent
# step as an input parameter to the template, 'print-message'.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: nonroot-parameter-
spec:
  serviceAccountName: pipeline-runner
  entrypoint: output-parameter
  templates:
  - name: output-parameter
    steps:
    - - name: generate-parameter
        template: whalesay
    - - name: consume-parameter
        template: print-message
        arguments:
          parameters:
          - name: message
            value: "{{steps.generate-parameter.outputs.parameters.hello-param}}"

  - name: whalesay
    container:
      image: curlimages/curl:latest
      command: [sh, -c]
      args: ["sleep 1; echo -n hello world > /tmp/hello_world.txt"]
    outputs:
      parameters:
      - name: hello-param
        valueFrom:
          default: "Foobar"   # Default value to use if retrieving valueFrom fails. If not provided workflow will fail instead
          path: /tmp/hello_world.txt

  - name: print-message
    inputs:
      parameters:
      - name: message
    container:
      image: curlimages/curl:latest
      command: [sh, -c]
      args: ["echo {{inputs.parameters.message}}"]

non root hello world workflow:

#### one step test workflow for non-root ####
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: nonroot-helloworld-
spec:
  serviceAccountName: pipeline-runner
  entrypoint: hw
  templates:
  - name: hw
    container:
      image: curlimages/curl:latest
      command: [sh, -c, "echo hello"]

nonroot artifact passing workflow:

#### artifact passing test workflow for non-root ####
# This example demonstrates the ability to pass artifacts
# from one step to the next.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: nonroot-artifact-
spec:
  serviceAccountName: pipeline-runner
  entrypoint: artifact-example
  templates:
  - name: artifact-example
    steps:
    - - name: generate-artifact
        template: whalesay
    - - name: consume-artifact
        template: print-message
        arguments:
          artifacts:
          - name: message
            from: "{{steps.generate-artifact.outputs.artifacts.hello-art}}"

  - name: whalesay
    container:
      image: curlimages/curl:latest
      command: [sh, -c]
      args: ["sleep 1; echo hello world | tee /tmp/hello_world.txt"]
    outputs:
      artifacts:
      - name: hello-art
        path: /tmp/hello_world.txt

  - name: print-message
    inputs:
      artifacts:
      - name: message
        path: /tmp/message
    container:
      image: curlimages/curl:latest
      command: [sh, -c]
      args: ["cat /tmp/message"]

Copy link
Contributor

@alexec alexec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff! you're correct about Umask - this needs to go into os_specific

if err := os.MkdirAll(varRunArgo+"/ctr/"+containerName, 0o700); err != nil {
// default umask can be 022
// setting umask as 0 allow granting write access to other non-root users
syscall.Umask(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syscall.Umask(0) is not available on Windows. So you'll need to move this command into os_specific. The Windows implementation can be a no-op.

@alexec alexec added this to the v3.1 milestone Jul 22, 2021
@Bobgy
Copy link
Contributor Author

Bobgy commented Jul 24, 2021

@alexec thanks for the review! Updated to os specific

@Bobgy
Copy link
Contributor Author

Bobgy commented Jul 24, 2021

Any guidance for this?

Hi @alexec, I wonder whether you have any docs or examples for how to add workflows as tests?
I think it'll be a lot more confident checking in workflows to verify the fix and make sure we don't break it in the future.

@Bobgy Bobgy changed the title fix(executor): emissary works with nonroot sidecars + input/output params & artifacts fix(executor/emissary): fix nonroot sidecars + input/output params & artifacts Jul 24, 2021

import "syscall"

func CallUmask(mask int) (oldmask int) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor - you ignore the return value and you only ever pass in zero - so how about:

func UmaskZero() {
// ...
}

What might be even better is name it after you intent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GrantWriteAccessToNonRootUsers

??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about AllowGrantingAccessToEveryone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, updated

Signed-off-by: Yuan Gong <[email protected]>
@alexec alexec enabled auto-merge (squash) July 26, 2021 15:37
@alexec
Copy link
Contributor

alexec commented Jul 26, 2021

@sarabala1979 this needs to be back-ported to v3.1. Do you think we should do another patch release this week?

@alexec alexec merged commit 30e2518 into argoproj:master Jul 26, 2021
@sarabala1979 sarabala1979 mentioned this pull request Jul 27, 2021
39 tasks
sarabala1979 pushed a commit that referenced this pull request Jul 27, 2021
@sarabala1979 sarabala1979 mentioned this pull request Aug 2, 2021
49 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Argo workflow 3.2
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

2 participants