Skip to content

[Docker] Do not run container as root#5314

Merged
dlvenable merged 5 commits intoopensearch-project:mainfrom
janhoy:run-as-non-root
Jan 14, 2025
Merged

[Docker] Do not run container as root#5314
dlvenable merged 5 commits intoopensearch-project:mainfrom
janhoy:run-as-non-root

Conversation

@janhoy
Copy link
Copy Markdown
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.

Fixes opensearch-project#5311

Signed-off-by: Jan Høydahl <janhoy@users.noreply.github.com>
Copy link
Copy Markdown
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.

janhoy added 4 commits January 8, 2025 19:51
Signed-off-by: Jan Høydahl <janhoy@users.noreply.github.com>
Signed-off-by: Jan Høydahl <janhoy@users.noreply.github.com>
Signed-off-by: Jan Høydahl <janhoy@users.noreply.github.com>
Signed-off-by: Jan Høydahl <janhoy@users.noreply.github.com>
@janhoy
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

janhoy commented Jan 14, 2025

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

@dlvenable
Copy link
Copy Markdown
Member

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

@dlvenable dlvenable merged commit 81be7e3 into opensearch-project:main Jan 14, 2025
@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