-
Notifications
You must be signed in to change notification settings - Fork 253
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 all commits
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,37 @@ | ||
| # Security scanning with Trivy (https://trivy.dev) | ||
|
|
||
| trivy_image := "aquasec/trivy:latest" | ||
| trivy_severity := env("TRIVY_SEVERITY", "CRITICAL,HIGH") | ||
| trivy_cache_volume := "trivy-cache" | ||
| scan_images := env("SCAN_IMAGES", "evstack:local-dev") | ||
|
|
||
| trivy_run := "docker run --rm -v " + trivy_cache_volume + ":/root/.cache/ -e TRIVY_SEVERITY=" + trivy_severity | ||
|
|
||
| # Run all Trivy security scans (filesystem + Docker images) | ||
| trivy-scan: trivy-scan-fs trivy-scan-image | ||
|
|
||
| # Scan repo for dependency vulnerabilities, misconfigs, and secrets | ||
| trivy-scan-fs: | ||
| @echo "--> Scanning repository filesystem with Trivy" | ||
| @{{trivy_run}} \ | ||
| -v {{justfile_directory()}}:/workspace \ | ||
| {{trivy_image}} \ | ||
| fs --scanners vuln,misconfig,secret \ | ||
| --severity {{trivy_severity}} \ | ||
| --exit-code 1 \ | ||
| /workspace | ||
| @echo "--> Filesystem scan complete" | ||
|
|
||
| # 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}} \ | ||
| --exit-code 1 \ | ||
| $img; \ | ||
| done | ||
| @echo "--> Image scan complete" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,32 @@ | ||
| FROM golang:1.25-alpine AS build-env | ||
| FROM golang:1.26-bookworm AS build-env | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| COPY core core | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download | ||
|
|
||
| COPY . . | ||
|
|
||
| WORKDIR /src/apps/evm | ||
| RUN go mod tidy && CGO_ENABLED=0 GOOS=linux go build -o evm . | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| cd ./apps/evm && \ | ||
| CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags "-s -w" -o /out/evm . | ||
|
|
||
| FROM alpine:3.22.2 | ||
|
|
||
| #hadolint ignore=DL3018 | ||
| RUN apk --no-cache add ca-certificates curl | ||
| FROM busybox:1.36.1-musl AS busybox | ||
|
|
||
| WORKDIR /root | ||
| FROM scratch | ||
|
|
||
| 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 | ||
|
|
||
| ENTRYPOINT ["/usr/bin/entrypoint.sh"] | ||
| COPY --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
| COPY --from=build-env /out/evm /usr/bin/evm | ||
| COPY --from=build-env /src/apps/evm/entrypoint.sh /usr/bin/entrypoint.sh | ||
| COPY --from=busybox /bin/busybox /bin/busybox | ||
|
|
||
| ENV HOME=/home/ev-node | ||
| WORKDIR /home/ev-node | ||
| USER 10001:10001 | ||
|
|
||
| ENTRYPOINT ["/bin/busybox", "sh", "/usr/bin/entrypoint.sh"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,61 +1,34 @@ | ||
| # Build stage | ||
| FROM golang:1.25-alpine AS builder | ||
| FROM golang:1.26-bookworm AS builder | ||
|
|
||
| #hadolint ignore=DL3018 | ||
| RUN apk add --no-cache git gcc musl-dev linux-headers | ||
|
|
||
| # Set working directory | ||
| WORKDIR /ev-node | ||
|
|
||
| # Copy go mod files | ||
| COPY go.mod go.sum ./ | ||
| COPY apps/grpc/go.mod apps/grpc/go.sum ./apps/grpc/ | ||
| COPY core/go.mod core/go.sum ./core/ | ||
| COPY execution/grpc/go.mod execution/grpc/go.sum ./execution/grpc/ | ||
|
|
||
| # Download dependencies | ||
| RUN go mod download | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download | ||
|
|
||
| # Copy source code | ||
| COPY . . | ||
|
|
||
| # Build the application | ||
| WORKDIR /ev-node/apps/grpc | ||
| RUN go build -o evgrpc . | ||
|
|
||
| # Runtime stage | ||
| FROM alpine:3.22.2 | ||
|
|
||
| #hadolint ignore=DL3018 | ||
| RUN apk add --no-cache ca-certificates curl | ||
| RUN mkdir -p /home/ev-node | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| cd ./apps/grpc && \ | ||
| CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags "-s -w" -o /out/evgrpc . | ||
|
|
||
| # Create non-root user | ||
| RUN addgroup -g 1000 ev-node && \ | ||
| adduser -u 1000 -G ev-node -s /bin/sh -D ev-node | ||
| FROM scratch | ||
|
|
||
| # Set working directory | ||
| COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
| COPY --from=builder --chown=10001:10001 /home/ev-node /home/ev-node | ||
| WORKDIR /home/ev-node | ||
|
|
||
| # Copy binary from builder | ||
| COPY --from=builder /ev-node/apps/grpc/evgrpc /usr/local/bin/ | ||
| COPY --from=builder /out/evgrpc /usr/local/bin/evgrpc | ||
| USER 10001:10001 | ||
|
|
||
| # Create necessary directories | ||
| RUN mkdir -p /home/ev-node/.evgrpc && \ | ||
| chown -R ev-node:ev-node /home/ev-node | ||
|
|
||
| # Switch to non-root user | ||
| USER ev-node | ||
|
|
||
| # Expose ports | ||
| # P2P port | ||
| EXPOSE 26656 | ||
| # RPC port | ||
| EXPOSE 26657 | ||
| # Prometheus metrics | ||
| EXPOSE 26660 | ||
|
|
||
| # Set entrypoint | ||
| ENTRYPOINT ["evgrpc"] | ||
|
|
||
| # Default command | ||
| ENTRYPOINT ["/usr/local/bin/evgrpc"] | ||
| CMD ["start"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,19 @@ services: | |
| # Local DA service for development | ||
| local-da: | ||
| build: | ||
| context: ../../../ | ||
| context: ../../ | ||
| dockerfile: tools/local-da/Dockerfile | ||
| ports: | ||
| - "7980:7980" | ||
| environment: | ||
| - DA_NAMESPACE=00000000000000000000000000000000000000000000000000000000deadbeef | ||
| healthcheck: | ||
| test: ["CMD", "curl", "-f", "http://localhost:7980/health"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 5 | ||
| security_opt: | ||
| - no-new-privileges:true | ||
| cap_drop: | ||
| - ALL | ||
| read_only: true | ||
| tmpfs: | ||
| - /tmp | ||
|
|
||
| # Example gRPC execution service (replace with your implementation) | ||
| # execution-service: | ||
|
|
@@ -32,11 +34,11 @@ services: | |
| # Evolve node with gRPC execution client | ||
| evolve-grpc: | ||
| build: | ||
| context: ../../../ | ||
| context: ../../ | ||
| dockerfile: apps/grpc/Dockerfile | ||
| depends_on: | ||
| local-da: | ||
| condition: service_healthy | ||
| condition: service_started | ||
|
Comment on lines
39
to
+41
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. Removing healthcheck may cause startup race conditions. Changing from Consider adding a lightweight healthcheck back to 💡 Suggested healthcheck for local-da tmpfs:
- /tmp
+ healthcheck:
+ test: ["CMD-SHELL", "nc -z localhost 7980 || exit 1"]
+ interval: 5s
+ timeout: 3s
+ retries: 5Then revert the depends_on condition: depends_on:
local-da:
- condition: service_started
+ condition: service_healthy🤖 Prompt for AI Agents |
||
| # execution-service: | ||
| # condition: service_healthy | ||
| ports: | ||
|
|
@@ -48,17 +50,24 @@ services: | |
| - DA_NAMESPACE=00000000000000000000000000000000000000000000000000deadbeef | ||
| - GRPC_EXECUTOR_URL=http://host.docker.internal:50051 # Change to your execution service | ||
| volumes: | ||
| - evolve-data:/home/evolve/.evgrpc | ||
| - evolve-data:/home/ev-node/.evgrpc | ||
| command: | ||
| - start | ||
| - --root-dir=/home/evolve/.evgrpc | ||
| - --root-dir=/home/ev-node/.evgrpc | ||
| - --da.address=${DA_ADDRESS:-http://local-da:7980} | ||
| - --da.namespace=${DA_NAMESPACE} | ||
| - --grpc-executor-url=${GRPC_EXECUTOR_URL:-http://host.docker.internal:50051} | ||
| - --p2p.listen-address=/ip4/0.0.0.0/tcp/26656 | ||
| - --rpc.laddr=tcp://0.0.0.0:26657 | ||
| - --instrumentation.prometheus=true | ||
| - --instrumentation.prometheus-listen-addr=0.0.0.0:26660 | ||
| security_opt: | ||
| - no-new-privileges:true | ||
| cap_drop: | ||
| - ALL | ||
| read_only: true | ||
| tmpfs: | ||
| - /tmp | ||
|
|
||
| volumes: | ||
| evolve-data: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,27 @@ | ||
| FROM golang:1.25 AS base | ||
|
|
||
| #hadolint ignore=DL3018 | ||
| RUN apt-get update && \ | ||
| apt-get install -y --no-install-recommends \ | ||
| build-essential \ | ||
| ca-certificates \ | ||
| curl \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # enable faster module downloading. | ||
| ENV GOPROXY=https://proxy.golang.org | ||
|
|
||
| ## builder stage. | ||
| # | ||
| FROM base AS builder | ||
| FROM golang:1.26-bookworm AS builder | ||
|
|
||
| WORKDIR /ev-node | ||
|
|
||
| # Copy all source code first | ||
| COPY go.mod go.sum ./ | ||
| COPY apps/testapp/go.mod apps/testapp/go.sum ./apps/testapp/ | ||
| COPY core/go.mod core/go.sum ./core/ | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download | ||
|
|
||
| COPY . . | ||
| RUN mkdir -p /home/ev-node | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| cd ./apps/testapp && \ | ||
| CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags "-s -w" -o /out/testapp . | ||
|
|
||
| # Now download dependencies and build | ||
| RUN go mod download && cd apps/testapp && go install . | ||
| FROM scratch | ||
|
|
||
| ## prep the final image. | ||
| # | ||
| FROM base | ||
| COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
| COPY --from=builder --chown=10001:10001 /home/ev-node /home/ev-node | ||
| COPY --from=builder /out/testapp /usr/bin/testapp | ||
|
|
||
| COPY --from=builder /go/bin/testapp /usr/bin | ||
| WORKDIR /home/ev-node | ||
|
|
||
| WORKDIR /apps | ||
| USER 10001:10001 | ||
|
|
||
| ENTRYPOINT ["testapp"] | ||
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.
🧩 Analysis chain
🌐 Web query:
Trivy container image latest tag best practices CI/CD reproducibility💡 Result:
Recommendation: don’t use
:latestfor Trivy in CI/CD if you care about reproducibilitylatest(and other floating tags) can be retagged to different image contents over time, which breaks determinism. Docker explicitly recommends pinning by digest when you need fully repeatable builds/scans. [1]Best practices for reproducible Trivy container-image scanning
Pin the Trivy tool version (and ideally the image digest)
latest.version: latestorversion: vX.Y.Z; don’t uselatestfor reproducibility). [2]Control the vulnerability database lifecycle (this is a major source of “same image, different results”)
--skip-db-updateto prevent pulling a newer DB during the scan. [4]If you need strict repeatability across networks/regions, self-host or mirror the Trivy DB
Separate “reproducible security gate” from “continuously updated security signal”
Sources: Docker pinning/digest guidance for determinism [1]; Trivy Action supports explicit Trivy version pinning [2]; Trivy warns about canary builds [3]; Trivy DB update frequency + skip-update + caching [4]; Trivy DB distribution via GHCR / offline control concepts [5].
🏁 Script executed:
# Examine the .just/security.just file to understand context cat -n .just/security.justRepository: evstack/ev-node
Length of output: 1566
🏁 Script executed:
Repository: evstack/ev-node
Length of output: 693
Pin Trivy version and consider database update strategy.
Line 3 uses
:latest, which allows the Trivy vulnerability database to update automatically (~every 6 hours), causing identical image scans to produce different results. Pin an explicit Trivy version (and optionally the image digest) for reproducible security scans.The project already caches the Trivy database via
trivy_cache_volume, which helps. For further reproducibility, consider:aquasec/trivy:0.48.0) or digest--skip-db-updatein PR/gate scans to freeze results; enable DB updates only in scheduled/continuous jobs🔧 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents