From 07a95100e564d57b702bda545cdfe26e09287ab6 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 05:29:25 +0000 Subject: [PATCH] Images: hadolint in the security job and the hook; Trivy on the built images (app gates pull requests, renderer reports until sc-9674); the app image takes Debian's security updates; the live app image scanned daily (sc-9611) The pinned debian:trixie-slim (Debian's newest) has fixable HIGH CVEs in openssl and zstd: the app's runtime stage now runs apt-get upgrade, with today's date as a build arg so BuildKit's cache never keeps old packages. FROM lines keep tags: CI pins them by digest through build-contexts (amd64-only digests would break local arm64 builds). --- .github/workflows/audit.yml | 27 +++++++++++++++++++++++++++ .github/workflows/ci.yml | 30 +++++++++++++++++++++++++++++- .hadolint.yaml | 7 +++++++ AGENTS.md | 7 +++++++ docker/app.Dockerfile | 6 +++++- lefthook.yml | 4 ++++ mise.toml | 1 + 7 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .hadolint.yaml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 10ae1c446..f6876b5ba 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -54,3 +54,30 @@ jobs: dir=$RUNNER_TEMP/sprockets && mkdir -p "$dir" cp clients/gallery/ruby/examples/rails/Gemfile.sprockets.lock "$dir/Gemfile.lock" trivy fs --scanners vuln --ignore-unfixed --exit-code 1 --ignorefile .trivyignore.yaml "$dir" + + # The app image production runs (the commit https://api.visualci.com/status reports), daily and by hand: CI's scan of + # an image only gates pull requests, so a CVE published after a deploy is caught here. + live-image: + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + packages: read + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 + with: + install_args: trivy + - run: | + commit=$(curl -fsS --retry 3 --max-time 10 https://api.visualci.com/status | jq -r '.commit // empty') + [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::no commit from https://api.visualci.com/status"; exit 1; } + trivy image --scanners vuln --ignore-unfixed --severity HIGH,CRITICAL --exit-code 1 --ignorefile .trivyignore.yaml \ + "ghcr.io/docspring/visualci-app:$commit" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 783e8574c..a9faa98c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,8 +173,11 @@ jobs: fetch-depth: 0 - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 with: - install_args: actionlint shellcheck zizmor betterleaks + install_args: actionlint shellcheck zizmor betterleaks hadolint - run: actionlint + # The renderer's two warnings (a `cd` and a pipe in the PDFBox download step) wait for its next rebuild: any edit + # to renderer.Dockerfile rebuilds the renderer image (its inputs hash), so it isn't touched for lint alone. + - run: hadolint docker/app.Dockerfile && hadolint --ignore DL3003 --ignore DL4006 docker/renderer.Dockerfile # The online audits only on pull requests: a new advisory against a pinned action shouldn't turn main red, which # holds back the CLI release (release.yml waits for a green CI on main) with no code change. - run: if [ "$EVENT" = pull_request ]; then zizmor --no-progress .; else zizmor --no-progress --offline .; fi @@ -726,6 +729,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | echo "renderer=$(cat docker/renderer.version)" >>"$GITHUB_OUTPUT" + echo "date=$(date -u +%F)" >>"$GITHUB_OUTPUT" # The CLI release the app's add-to-CI snippets install (frontend/scripts/cli-version.mjs): a build arg, so a # new release rebuilds the cached frontend layer cli=$(gh api repos/DocSpring/visualci/releases/latest --jq .tag_name) @@ -761,7 +765,10 @@ jobs: node:24-trixie-slim=docker-image://ghcr.io/docspring/visualci/mirror/node:24-trixie-slim@sha256:efb444a6c8b45a1ebdd70974912147dc2be917714174f52334e236aa23c0e3a6 debian:trixie-slim=docker-image://ghcr.io/docspring/visualci/mirror/debian:trixie-slim@sha256:ab3b3c8c5159eebfca4376430132d53c4d425f869c765ecbe47177a030da575d push: ${{ env.PUSH == 'true' }} + # Pull requests load it into the runner's Docker for the Trivy scan below; main pushes it. + load: ${{ env.PUSH != 'true' }} build-args: | + SECURITY_UPDATES_DATE=${{ steps.version.outputs.date }} BUILD_SHA=${{ github.sha }} RENDERER_VERSION=${{ steps.version.outputs.renderer }} VISUALCI_ANALYTICS=1 @@ -814,6 +821,27 @@ jobs: env: DIGEST: ${{ steps.renderer_inputs.outputs.existing || steps.renderer_build.outputs.digest }} run: echo "digest=$DIGEST" >>"$GITHUB_OUTPUT" + # Trivy on the images: fixable HIGH and CRITICAL vulnerabilities (ignores with an expiry in .trivyignore.yaml), + # and forbidden licences (AGPL and the like). It gates pull requests. On main it only reports, so a CVE published + # today never holds back a deploy; the Audit workflow scans the live app image daily and fails there. + - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 + with: + install_args: trivy + cache: false + - name: Trivy (app image) + continue-on-error: ${{ env.PUSH == 'true' }} + env: + IMAGE: ghcr.io/docspring/visualci-app:${{ github.sha }} + run: | + trivy image --scanners vuln --ignore-unfixed --severity HIGH,CRITICAL --exit-code 1 --ignorefile .trivyignore.yaml "$IMAGE" + trivy image --scanners license --severity CRITICAL --exit-code 1 "$IMAGE" + # The renderer only reports for now: fixing what it finds means rebuilding it (fresh Debian packages, which can + # move pixels, and a renderer.version bump), done on purpose in its own change (sc-9674). + - name: Trivy (renderer image, report only) + continue-on-error: true + env: + IMAGE: ${{ steps.renderer_inputs.outputs.tag }} + run: trivy image --scanners vuln --ignore-unfixed --severity HIGH,CRITICAL --exit-code 1 --ignorefile .trivyignore.yaml "$IMAGE" deploy: needs: [images, site] diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 000000000..72f2947eb --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,7 @@ +# hadolint (Dockerfile lint), run by CI's security job and the pre-commit hook. Fails on warnings and errors. +failure-threshold: warning +ignored: + # Pin apt package versions: Debian's archive drops a superseded version, so a pinned `pkg=1.2-3` stops installing at + # the next security update. The base image is pinned by digest instead (CI's build-contexts, .github/mirror.txt), + # and the app's image takes Debian's security updates on every build. + - DL3008 diff --git a/AGENTS.md b/AGENTS.md index a935bcdda..cde44841a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -29,6 +29,13 @@ design is in `docs/design.md`; read it before changing the architecture, and upd with a `statement` and an `expired_at` at most six months out. A new dependency licence goes into `deny.toml`'s allow list only after a look (no copyleft in the CLI or the images). In `deny.toml`, ignores and licences nothing uses any more fail the job: remove them. +- **Images are linted and scanned.** hadolint checks the Dockerfiles (`.hadolint.yaml`), and Trivy scans the built + images in CI's images job: fixable HIGH/CRITICAL vulnerabilities and forbidden licences fail a pull request (on main + they only report, and the Audit workflow scans the live app image daily). The Dockerfiles' `FROM` lines keep plain + tags: CI replaces each with the digest-pinned mirror copy (`build-contexts`, `.github/mirror.txt`), whose digests + are linux/amd64 only, so pinning them in `FROM` would break local builds on arm64. The app's runtime stage takes + Debian's security updates on every build. Editing `docker/renderer.Dockerfile` rebuilds the renderer (fresh + packages, which can move pixels): bump `docker/renderer.version` and check renders when you do. - **Hold the merge lock from the final rebase to the merge.** A PR must be up to date with `main` before it merges, so a merge by one agent sends every other agent's PR back through CI. Take Fleetlayer's lock, one per repository, around the last rebase, the CI run and the merge, in one script, and only for one PR at a time: diff --git a/docker/app.Dockerfile b/docker/app.Dockerfile index 6c34c0a29..81b490ab4 100644 --- a/docker/app.Dockerfile +++ b/docker/app.Dockerfile @@ -52,7 +52,11 @@ FROM scratch AS bin COPY --from=build /src/target/release/visualci-app /visualci-app FROM debian:trixie-slim -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* \ +# Debian's security updates on top of the pinned base image (CI scans the result with Trivy). CI passes today's date, +# so BuildKit's layer cache never keeps yesterday's packages. +ARG SECURITY_UPDATES_DATE= +RUN apt-get update && apt-get upgrade -y --no-install-recommends \ + && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* \ && useradd --uid 10001 --create-home visualci WORKDIR /app COPY --from=bin /visualci-app /usr/local/bin/visualci-app diff --git a/lefthook.yml b/lefthook.yml index e452c7446..58e4b0530 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -25,6 +25,10 @@ pre-commit: zizmor: glob: "{.github/workflows/*,.github/actions/**/*,.github/zizmor.yml,clients/github-action/action.yml}" run: zizmor --offline --no-progress . + # The Dockerfiles (.hadolint.yaml). The renderer's two ignores wait for its next rebuild (ci.yml's security job). + hadolint: + glob: "docker/*Dockerfile" + run: hadolint docker/app.Dockerfile && hadolint --ignore DL3003 --ignore DL4006 docker/renderer.Dockerfile # Secrets in the staged changes (.betterleaks.toml allows the made-up ones). betterleaks: run: betterleaks git --pre-commit --staged --no-banner --config .betterleaks.toml . diff --git a/mise.toml b/mise.toml index 204579df6..28035cf94 100644 --- a/mise.toml +++ b/mise.toml @@ -11,3 +11,4 @@ oxfmt = "0.81.0" hugo = "0.171.0" cargo-deny = "0.22.3" trivy = "0.77.0" +hadolint = "2.15.1"