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

set default user to non-root #460

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

set default user to non-root #460

wants to merge 2 commits into from

Conversation

lkwg82
Copy link

@lkwg82 lkwg82 commented Apr 8, 2024

Runs the container as user different from root for security reasons.

See https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-2-set-a-user

@carlossg
Copy link
Owner

carlossg commented Apr 8, 2024

thanks, this was brought up previously with the Docker official images maintainers and the answer was to keep the default user as root, unfortunately I cannot find the issue where this was brought up

@lkwg82
Copy link
Author

lkwg82 commented Apr 9, 2024

Here it is: #8 (comment)

This would mean any user runs as root or need to inherit from this image to run as non-root.

What about to make it secure by default and open to run as root? (inverse the current behaviour + docs)

@carlossg
Copy link
Owner

this comment here from official images mantainers
docker-library/official-images#690 (comment)

@lkwg82
Copy link
Author

lkwg82 commented Apr 16, 2024

Hmm. Do you think of ur image rather a base image or an enduser image?

When you answer base image, I would offer to add an non-root image besides your base image.

@carlossg
Copy link
Owner

it is a base image, I could add a nonroot image, but would need to somehow be generated as I don't want to maintain 2x the images

@jglick
Copy link
Contributor

jglick commented Jun 4, 2024

Is there already some parameterization system in place which might allow this repo to publish an alternate set of tags that would switch to a nonroot user?

As it stands, this image is hard less than obvious how to use directly in a CI system which for example enforces K8s PSA at the restricted level. In Jenkins (edit as of jenkinsci/kubernetes-plugin#1571):

podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: maven
    image: maven
    command:
    - sleep
    args:
    - infinity
    securityContext:
      runAsUser: 1000
    env:
    - name: MAVEN_OPTS
      value: -Duser.home=/home/jenkins/agent
''') {
    node(POD_LABEL) {
        git 'https://github.com/jglick/simple-maven-project-with-tests'
        container('maven') {
            sh 'mvn -B -ntp compile'
        }
    }
}

or if you prefer

podTemplate(containers: [containerTemplate(name: 'maven', image: 'maven', command: 'sleep', args: 'infinity', runAsUser: '1000', envVars: [envVar(key: 'MAVEN_OPTS', value: '-Duser.home=/home/jenkins/agent')])]) {
    // … as before
}

@carlossg
Copy link
Owner

carlossg commented Jun 5, 2024

There is some code generation here
https://github.com/carlossg/docker-maven/blob/main/publish.sh#L19

Would need something to create new dies for the nonroot variants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants