root-user command validates that a container image is configured to run as a non-root user. This is a critical security best practice that prevents privilege escalation and limits the blast radius of security vulnerabilities.
Usage
Description
Theroot-user command checks the image’s USER configuration to ensure it’s not running as root (UID 0). Images without a USER instruction or with USER root will fail validation.
This check helps:
- Prevent privilege escalation attacks
- Limit container breakout impact
- Enforce principle of least privilege
- Comply with security best practices (CIS Benchmarks, PCI DSS)
- Meet Kubernetes Pod Security Standards
Flags
Output format:
text or jsonShort form: -oColor output mode:
auto, always, neverSet log level: trace, debug, info, warn, error, fatal, panic
Examples
Basic usage
Check custom image
Check OCI layout
Check Docker archive
JSON output
Output
Text Format
When validation passes:JSON Format
Exit Codes
| Code | Meaning | Example |
|---|---|---|
| 0 | Image runs as non-root | USER 1001 |
| 1 | Image runs as root or no user specified | USER root or no USER instruction |
| 2 | Execution error | Image not found |
Configuration
When using theall command, include root-user in your config file:
root-user check has no additional configuration options.
Implementation Details
- Reads the
USERfield from the image config - Passes if user is set to any value except “root” or empty string
- Fails if
config.Config.Useris empty (no USER instruction) - Fails if
config.Config.User == "root" - Works with both numeric UIDs (e.g.,
1001) and usernames (e.g.,appuser)
Common Issues
No USER instruction
USER instruction, so the container will run as root by default.
Solution: Add a USER instruction to your Dockerfile:
Explicit root user
USER root.
Solution: Remove or change the USER root instruction.
Base image runs as root
Many official images (nginx, postgres, etc.) run as root by default:Best Practices
Always run containers as non-root unless absolutely necessary
Use numeric UIDs (e.g., 1001) for better portability
Ensure the user has minimal permissions needed
Create a dedicated user for the application
Set appropriate file ownership before switching users
Dockerfile Examples
Create and use non-root user
Using existing user
Multi-stage build
User Format
TheUSER instruction accepts multiple formats:
| Format | Example | Notes |
|---|---|---|
| Numeric UID | USER 1001 | Recommended for portability |
| Username | USER appuser | Must exist in /etc/passwd |
| UID:GID | USER 1001:1001 | Specifies both user and group |
| Username:Groupname | USER appuser:appgroup | Both must exist |
Kubernetes Integration
Kubernetes Pod Security Standards require non-root containers in theRestricted policy:
check-image root-user in CI ensures your images comply with these policies.
Related Commands
all- Run all checks including root-user validationsecrets- Validate image doesn’t contain secretsentrypoint- Validate entrypoint configuration