Skip to content

Enhance Docker Security: Run Container as a Non-Root User #2224

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

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

Conversation

shotgunner
Copy link

This update modifies the Dockerfile to address a Trivy security warning

Description

This PR updates the Dockerfile to improve security by running the container as a non-root user, preventing privilege escalation risks and addressing Trivy's HIGH severity warning (DS002).
Changes Implemented:

✅ Added a new system user (appuser) and group (appgroup).
✅ Set ownership of /app to the non-root user.
✅ Moved pip install before switching users to prevent permission issues.
✅ Switched to USER appuser to follow best security practices.

Why This Change?

🔹 Mitigates security risks associated with running containers as root.
🔹 Complies with Docker security best practices.
🔹 Fixes Trivy HIGH severity warning (DS002).
References:

📌 vulnerability database: aquasec
Testing & Validation:

✅ Builds and runs successfully with uvicorn.
✅ Verified application runs correctly as appuser.
✅ Passed security scans without issues.

Please review and merge to enhance security. 🚀

This update modifies the Dockerfile to address a Trivy security warning
@CLAassistant
Copy link

CLAassistant commented Feb 19, 2025

CLA assistant check
All committers have signed the CLA.

@deshraj
Copy link
Collaborator

deshraj commented Feb 19, 2025

Thanks for opening the PR. Changes look good.

@shotgunner
Copy link
Author

@deshraj could we merge it ? or I need to change something. I see some tests are failing. not sure maybe missed something 🤔

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.

4 participants