add security scan for docker

This commit is contained in:
Graham McIntire 2025-06-15 10:43:38 -05:00
parent 1ce7f91eed
commit 1df2f4a716
2 changed files with 71 additions and 3 deletions

View file

@ -0,0 +1,61 @@
name: Docker Security Scan
on:
push:
branches: [ "main" ]
paths:
- 'Dockerfile'
- '.github/workflows/docker-security-scan.yml'
- 'mix.exs'
- 'mix.lock'
pull_request:
branches: [ "main" ]
paths:
- 'Dockerfile'
- '.github/workflows/docker-security-scan.yml'
- 'mix.exs'
- 'mix.lock'
schedule:
- cron: '0 0 * * 0' # Run weekly on Sundays at midnight
workflow_dispatch: # Allow manual triggers
jobs:
scan:
name: Security Scan
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
packages: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t aprs:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: aprs:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
timeout: '10m'
scanners: 'vuln,config,secret'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
category: 'Trivy Scan'
- name: Fail on CRITICAL vulnerabilities
if: ${{ failure() }}
run: |
echo "Critical vulnerabilities found in the Docker image."
echo "Please review the scan results in the Security tab."
exit 1

View file

@ -10,6 +10,7 @@
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20250113-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.18.2-erlang-27.2-debian-bullseye-20250113-slim
# - https://hub.docker.com/r/aquasec/trivy - for security scanning
#
ARG ELIXIR_VERSION=1.18.2
ARG OTP_VERSION=27.2
@ -18,7 +19,7 @@ ARG DEBIAN_VERSION=bullseye-20250113-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} as builder
FROM ${BUILDER_IMAGE} AS builder
# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
@ -68,8 +69,8 @@ RUN mix release
FROM ${RUNNER_IMAGE}
RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
@ -95,3 +96,9 @@ USER nobody
# ENTRYPOINT ["/tini", "--"]
CMD ["/app/bin/server"]
# Security scan stage
FROM aquasec/trivy:latest AS trivy
WORKDIR /workspace
COPY --from=builder /app/_build/prod/rel/aprs ./
RUN trivy filesystem --no-progress --exit-code 1 --severity HIGH,CRITICAL ./