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

[Docker] Do not run container as root #5314

Merged
merged 5 commits into from
Jan 14, 2025

Conversation

janhoy
Copy link
Contributor

@janhoy janhoy commented Jan 8, 2025

Description

In Dockerfile, run under the nobody user instead of root. Also chown some directories.

Issues Resolved

Resolves #5311

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

build.gradle Show resolved Hide resolved
Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Thank you @janhoy for this contribution! I have one comment about the specific user.

release/docker/Dockerfile Outdated Show resolved Hide resolved
build.gradle Show resolved Hide resolved
@janhoy
Copy link
Contributor Author

janhoy commented Jan 8, 2025

So I think this is ready. Tested it in a k8s cluster using helm chart and this container security context:

securityContext:
  capabilities:
    drop:
    - ALL
  runAsNonRoot: true
  runAsUser: 1000
  runAsGroup: 1000

Prepper container ran as it should, under the new user.

I'll follow up with a PR to the helm chart repo to add this security context (commented-out). Only once a new docker image version is released can we make such config default.

EDIT: Well, such a commented section already exists, so guess there is no need for change until we can uncomment.

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Very nice! Thank you @janhoy !

@janhoy
Copy link
Contributor Author

janhoy commented Jan 14, 2025

Thanks for approving. Are the test failures related to the changes by any chance?

@dlvenable
Copy link
Member

@janhoy , No, these are flaky tests. We can merge this.

@dlvenable dlvenable merged commit 81be7e3 into opensearch-project:main Jan 14, 2025
72 of 79 checks passed
@janhoy janhoy deleted the run-as-non-root branch January 21, 2025 13:07
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.

[docker] Run as non root
2 participants