-
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 11 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" | ||||||
|
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. 🧩 Analysis chain🌐 Web query:
💡 Result: Recommendation: don’t use
|
||||||
| trivy_image := "aquasec/trivy:latest" | |
| trivy_image := env("TRIVY_IMAGE", "aquasec/trivy:0.48.0") |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.just/security.just at line 3, The Trivy image is pinned to "latest" via the
trivy_image variable which allows non-reproducible scans; change trivy_image to
a specific release tag or digest (e.g., aquasec/trivy:0.48.0 or the
image@sha256:...) to lock the tool version, and update any scan invocations
(where Trivy is run) to optionally include --skip-db-update for PR/gate scans
while reserving DB updates for scheduled jobs; update the trivy_image variable
and adjust the scan invocation logic that references trivy_image to implement
these changes.
| 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 | ||
| CMD ["start"] | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| 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"] | ||
Uh oh!
There was an error while loading. Please reload this page.