chore: add Trivy security scanning and fix non-root container users#3082
chore: add Trivy security scanning and fix non-root container users#3082tac0turtle wants to merge 3 commits intomainfrom
Conversation
Add `make trivy-scan` (filesystem + image) via dockerized Trivy. Fix DS-0002 (HIGH): run evm, testapp, and local-da containers as non-root `ev-node` user, consistent with the grpc Dockerfile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
Summary of ChangesHello @tac0turtle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the project's security by introducing automated vulnerability scanning with Trivy and hardening several Docker containers to run with reduced privileges. These changes aim to proactively identify and mitigate security risks, ensuring a more robust and secure application environment. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Claude finished @tac0turtle's task in 1m 17s —— View job Code Review
Good security hardening PR overall. The non-root user changes are correct and consistent, and the Trivy scanning setup is clean. A few issues worth addressing: Dockerfile Inconsistencies
Both Alpine Dockerfiles use # apps/evm/Dockerfile:21
# tools/local-da/Dockerfile:23
RUN addgroup -g 1000 ev-node && \
adduser -u 1000 -G ev-node -s /bin/sh -D ev-nodeWith
The
# apps/evm/Dockerfile:25-28
COPY --from=build-env /src/apps/evm/evm /usr/bin/evm
COPY apps/evm/entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod +x /usr/bin/entrypoint.sh && \
chown -R ev-node:ev-node /home/ev-nodeThe
|
| Area | Status |
|---|---|
| Non-root user security fix | Correct and consistent |
| Trivy filesystem scan | Good |
| Trivy image scan | Works, minor quoting issue |
trivy:latest pin |
Should be versioned |
Alpine -D flag pattern |
Minor inconsistency vs grpc |
EVM chown placement |
No-op, can be cleaned up |
| Migration guide | High quality |
| CHANGELOG entry | Appropriate for breaking change |
The core security objective (DS-0002 fix) is correctly implemented. The items above are refinements rather than blockers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3082 +/- ##
=======================================
Coverage 61.16% 61.16%
=======================================
Files 113 113
Lines 11444 11444
=======================================
Hits 7000 7000
Misses 3655 3655
Partials 789 789
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces Trivy security scanning capabilities and enhances container security by configuring evm, testapp, and local-da containers to run as a non-root ev-node user. The addition of scripts/security.mk provides a convenient way to perform filesystem and image scans. The changes to the Dockerfiles for evm, testapp, and local-da correctly implement the non-root user principle, which is a significant security improvement. There are minor opportunities for consistency and clarity in the Dockerfile user creation and the default image scanning configuration.
|
|
||
| WORKDIR /root | ||
| RUN addgroup -g 1000 ev-node && \ | ||
| adduser -u 1000 -G ev-node -s /bin/sh -D ev-node |
There was a problem hiding this comment.
The adduser command uses the -D flag, which prevents the creation of a home directory. However, the subsequent WORKDIR /home/ev-node implies that /home/ev-node is intended to be the user's home directory. For consistency with apps/testapp/Dockerfile and clearer intent, it's better to allow adduser to create the home directory by removing the -D flag, or explicitly create it if -D is strictly necessary for other reasons. Removing -D is the most straightforward approach to align with the WORKDIR and chown commands.
adduser -u 1000 -G ev-node -s /bin/sh ev-node
| TRIVY_CACHE_VOLUME := trivy-cache | ||
|
|
||
| # Docker images to scan (space-separated, override or extend as needed) | ||
| SCAN_IMAGES ?= evstack:local-dev |
There was a problem hiding this comment.
The SCAN_IMAGES variable defaults to evstack:local-dev. While the comment indicates it can be overridden, having a single specific image as the default might lead to other relevant images being missed during scans if the user doesn't explicitly configure this variable. Consider making this variable empty by default or providing a more generic placeholder, encouraging users to define the images they intend to scan, or adding a clear example of how to extend it for multiple images.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers bind mounts, named volumes, Kubernetes init containers, fsGroup, and docker-compose. Links from the changelog entry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Good call to improve the Dockerfiles. The test fail due to RO volumes now. |
Add
make trivy-scan(filesystem + image) via dockerized Trivy. Fix DS-0002 (HIGH): run evm, testapp, and local-da containers as non-rootev-nodeuser, consistent with the grpc Dockerfile.Overview
add container users