|
| 1 | +# Container security |
| 2 | +# |
| 3 | +# Purpose: the Docker image is how most people run Odysseus, so it is part of |
| 4 | +# the attack surface. Two checks: |
| 5 | +# |
| 6 | +# - hadolint: lints the Dockerfile for mistakes and insecure patterns |
| 7 | +# (running as root longer than needed, unpinned base image, bad apt usage). |
| 8 | +# Blocking. |
| 9 | +# - Trivy: builds the image and scans it for known-vulnerable OS and Python |
| 10 | +# packages. Advisory only -- it reports findings to the repo's Security tab |
| 11 | +# without blocking a merge, because the image inevitably contains |
| 12 | +# already-known CVEs in upstream packages that are not this project's bug. |
| 13 | +# |
| 14 | +# Note: a separate open PR (#120) proposes a local `scripts/scan_image.py`. |
| 15 | +# This job is complementary -- it is a CI gate plus Security-tab integration, |
| 16 | +# not a script a contributor has to remember to run. |
| 17 | + |
| 18 | +name: Container scan |
| 19 | + |
| 20 | +on: |
| 21 | + pull_request: |
| 22 | + push: |
| 23 | + branches: [main] |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +permissions: {} |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: container-scan-${{ github.workflow }}-${{ github.ref }} |
| 30 | + cancel-in-progress: true |
| 31 | + |
| 32 | +jobs: |
| 33 | + hadolint: |
| 34 | + name: hadolint (Dockerfile lint) |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + steps: |
| 39 | + - name: Checkout repository |
| 40 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 41 | + with: |
| 42 | + persist-credentials: false |
| 43 | + |
| 44 | + - name: Lint Dockerfile |
| 45 | + uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0 |
| 46 | + with: |
| 47 | + dockerfile: Dockerfile |
| 48 | + # DL3008: pinning apt package versions is impractical on a -slim base |
| 49 | + # image. Debian purges old package versions from its repos, so a |
| 50 | + # pinned version breaks future rebuilds. The base image itself is |
| 51 | + # what should be pinned (tracked by Dependabot's docker ecosystem). |
| 52 | + ignore: DL3008 |
| 53 | + |
| 54 | + trivy: |
| 55 | + name: Trivy (image scan, advisory) |
| 56 | + runs-on: ubuntu-latest |
| 57 | + # Advisory: a CVE in an upstream package must not block unrelated PRs. |
| 58 | + continue-on-error: true |
| 59 | + permissions: |
| 60 | + contents: read |
| 61 | + security-events: write # upload SARIF to the Security tab (push only) |
| 62 | + steps: |
| 63 | + - name: Checkout repository |
| 64 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 65 | + with: |
| 66 | + persist-credentials: false |
| 67 | + |
| 68 | + - name: Set up Buildx |
| 69 | + uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 |
| 70 | + |
| 71 | + # Build without pushing so a broken Dockerfile is caught here, and the |
| 72 | + # exact image we ship is what gets scanned. |
| 73 | + - name: Build image |
| 74 | + uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + push: false |
| 78 | + load: true |
| 79 | + tags: odysseus:ci |
| 80 | + |
| 81 | + - name: Scan image with Trivy |
| 82 | + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 |
| 83 | + with: |
| 84 | + image-ref: odysseus:ci |
| 85 | + format: sarif |
| 86 | + output: trivy-results.sarif |
| 87 | + ignore-unfixed: true |
| 88 | + env: |
| 89 | + # Pin the vuln DB source to GHCR to avoid rate-limited Docker Hub |
| 90 | + # mirrors that flake on shared runners. |
| 91 | + TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db:2 |
| 92 | + |
| 93 | + # Upload only on push to main. Pull requests from forks get a read-only |
| 94 | + # token that cannot write to the Security tab, so skipping there avoids a |
| 95 | + # confusing failure; the main-branch scan keeps the tab populated. |
| 96 | + - name: Upload Trivy results |
| 97 | + if: github.event_name == 'push' |
| 98 | + uses: github/codeql-action/upload-sarif@03e4368ac7daa2bd82b3e85262f3bf87ee112f57 # v3.36.0 |
| 99 | + with: |
| 100 | + sarif_file: trivy-results.sarif |
| 101 | + category: trivy-image |
0 commit comments