Enhance Docker Security: Run Container as a Non-Root User
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. 🚀
Thanks for opening the PR. Changes look good.
@deshraj could we merge it ? or I need to change something. I see some tests are failing. not sure maybe missed something 🤔