-
Notifications
You must be signed in to change notification settings - Fork 261
chore: add Trivy security scanning and fix non-root container users #3082
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
7a15f82
f237083
d4b15fc
62e68bd
8cb45b0
517f2f4
5e5035d
e48a5ef
6dc069f
ecf19d7
cbb0185
bdd2dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # security.mk - Security scanning with Trivy (https://trivy.dev) | ||
|
|
||
| TRIVY_IMAGE := aquasec/trivy:latest | ||
| TRIVY_SEVERITY ?= CRITICAL,HIGH | ||
| TRIVY_CACHE_VOLUME := trivy-cache | ||
|
|
||
| # Docker images to scan (space-separated, override or extend as needed) | ||
| SCAN_IMAGES ?= evstack:local-dev | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| # Common docker run args for Trivy | ||
| TRIVY_RUN := docker run --rm \ | ||
| -v $(TRIVY_CACHE_VOLUME):/root/.cache/ \ | ||
| -e TRIVY_SEVERITY=$(TRIVY_SEVERITY) | ||
|
|
||
| ## trivy-scan: Run all Trivy security scans (filesystem + Docker images) | ||
| trivy-scan: trivy-scan-fs trivy-scan-image | ||
| .PHONY: trivy-scan | ||
|
|
||
| ## trivy-scan-fs: Scan repo for dependency vulnerabilities, misconfigs, and secrets | ||
| trivy-scan-fs: | ||
| @echo "--> Scanning repository filesystem with Trivy" | ||
| @$(TRIVY_RUN) \ | ||
| -v $(CURDIR):/workspace \ | ||
| $(TRIVY_IMAGE) \ | ||
| fs --scanners vuln,misconfig,secret \ | ||
| --severity $(TRIVY_SEVERITY) \ | ||
| /workspace | ||
| @echo "--> Filesystem scan complete" | ||
| .PHONY: trivy-scan-fs | ||
|
|
||
| ## trivy-scan-image: Scan built Docker images for vulnerabilities | ||
| trivy-scan-image: | ||
| @echo "--> Scanning Docker images with Trivy" | ||
| @for img in $(SCAN_IMAGES); do \ | ||
| echo "--> Scanning image: $$img"; \ | ||
| $(TRIVY_RUN) \ | ||
| -v /var/run/docker.sock:/var/run/docker.sock \ | ||
| $(TRIVY_IMAGE) \ | ||
| image --severity $(TRIVY_SEVERITY) \ | ||
| $$img; \ | ||
| done | ||
| @echo "--> Image scan complete" | ||
| .PHONY: trivy-scan-image | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
addusercommand uses the-Dflag, which prevents the creation of a home directory. However, the subsequentWORKDIR /home/ev-nodeimplies that/home/ev-nodeis intended to be the user's home directory. For consistency withapps/testapp/Dockerfileand clearer intent, it's better to allowadduserto create the home directory by removing the-Dflag, or explicitly create it if-Dis strictly necessary for other reasons. Removing-Dis the most straightforward approach to align with theWORKDIRandchowncommands.