Fixed Java container installing gnupg - #45
Conversation
| @@ -0,0 +1,12 @@ | |||
| FROM mcr.microsoft.com/devcontainers/java:1-21-bookworm | |||
There was a problem hiding this comment.
Semgrep identified an issue in your code:
By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that a USER directive is defined in the Dockerfile.
To resolve this comment:
✨ Commit fix suggestion
-
Keep the base image as-is, but add a
USERdirective in the Dockerfile so the container does not start asroot. -
Place the
USERdirective after theRUNsteps that need package installation, becauseapt-getusually requires root privileges. -
Switch to a non-root account that already exists in this base image, if available. For Microsoft devcontainer images, that is commonly
vscode, so addUSER vscodenear the end of the Dockerfile. -
Update file ownership before switching users if later steps need write access to application directories. For example, use
RUN chown -R vscode:vscode /path/to/appbeforeUSER vscode. -
Alternatively, if this image does not already include a non-root user, create one first and then switch to it with
USER appuser. For example, addRUN useradd -m -u 10001 appuserand thenUSER appuser. Running as a non-root user limits what an attacker can do inside the container.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by missing-user-definition.
🛟 Help? Slack #semgrep-help or go/semgrep-help.
Resolution Options:
- Fix the code
- Reply
/fp $reason(if security gap doesn’t exist) - Reply
/ar $reason(if gap is valid but intentional; add mitigations/monitoring) - Reply
/other $reason(e.g., test-only)
You can view more details about this finding in the Semgrep AppSec Platform.
There was a problem hiding this comment.
/ar as these containers run in GitHub's infra or in Instruqt, never on Atlas this "risk" is harmless. They can destroy the container if they want.
The container failed while starting, complains about OpenSSH, added GNUPG to avoid it.