diff --git a/.github/scripts/kernel-headers-vex.sh b/.github/scripts/kernel-headers-vex.sh new file mode 100755 index 0000000000..3a24c30e1a --- /dev/null +++ b/.github/scripts/kernel-headers-vex.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Writes an OpenVEX document marking every linux-libc-dev CVE found in the given Trivy JSON +# reports as not_affected. linux-libc-dev holds only the kernel's userspace API headers, which +# build-essential needs to compile C; a container runs on its host's kernel, so a kernel CVE +# reported against this package never applies to the image. The product carries no version or +# qualifiers so one statement covers every architecture and package version. +# +# usage: kernel-headers-vex.sh ... > vex.openvex.json +set -euo pipefail + +id="$1" +shift + +jq -s --arg id "$id" --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" ' + [.[].Results[]? | (.Vulnerabilities // [])[] | select(.PkgName == "linux-libc-dev") | .VulnerabilityID] + | unique + | { + "@context": "https://openvex.dev/ns/v0.2.0", + "@id": $id, + author: "Windmill Labs", + timestamp: $ts, + version: 1, + statements: map({ + vulnerability: { name: . }, + products: [{ "@id": "pkg:deb/debian/linux-libc-dev" }], + status: "not_affected", + justification: "vulnerable_code_not_present", + impact_statement: "linux-libc-dev contains only the Linux userspace API headers used to compile C code. The image ships no kernel: containers run on the host kernel, which this package does not affect." + }) + } +' "$@" diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index c046a7d101..a5823ef19c 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -435,39 +435,125 @@ jobs: --certificate-identity "https://github.com/windmill-labs/windmill/.github/workflows/docker-image.yml@${GITHUB_REF}" \ "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-ee:${GITHUB_REF_NAME#v}" - verify_ee_image_vulnerabilities: + # Scans the digests this run built, never a tag: :main and :latest race with concurrent main + # builds. Release artifacts are uploaded before the gate so a failing gate still publishes them. + scan_release_images: runs-on: ubicloud - needs: [tag_latest_ee] - if: startsWith(github.ref, 'refs/tags/v') && (github.event_name != 'workflow_dispatch') + needs: [build, build_ee, build_slim, build_ee_slim] + if: startsWith(github.ref, 'refs/tags/v') && github.event_name == 'push' + strategy: + fail-fast: false + matrix: + include: + - image: windmill + suffix: "" + digest: ${{ needs.build.outputs.digest }} + - image: windmill-ee + suffix: "-ee" + digest: ${{ needs.build_ee.outputs.digest }} + - image: windmill-slim + suffix: "-slim" + digest: ${{ needs.build_slim.outputs.digest }} + - image: windmill-ee-slim + suffix: "-ee-slim" + digest: ${{ needs.build_ee_slim.outputs.digest }} + env: + # 0.69.3, pinned by digest so a republished tag cannot change what runs with release credentials. + TRIVY_IMAGE: aquasec/trivy@sha256:bcc376de8d77cfe086a917230e818dc9f8528e3c852f7b1aff648949b6258d1c steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Analyze for critical and high CVEs - id: docker-scout-cves - if: ${{ github.event_name != 'pull_request_target' }} + - uses: actions/checkout@v4 + + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Image reference + run: echo "IMAGE_REF=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ matrix.suffix }}@${{ matrix.digest }}" >> "$GITHUB_ENV" + + # The VEX must be built from an unfiltered scan: a statement covers only the CVEs listed in it. + # amd64 only: both arches install the same package versions from the same sources. + - name: Trivy scan + run: | + mkdir -p scan + trivy() { docker run --rm -v "$RUNNER_TEMP/trivy-cache:/root/.cache/trivy" -v "$PWD/scan:/out" "$TRIVY_IMAGE" "$@"; } + trivy image -q --platform linux/amd64 \ + --scanners vuln --format json -o /out/full.json "$IMAGE_REF" + .github/scripts/kernel-headers-vex.sh \ + "https://github.com/windmill-labs/windmill/releases/tag/${GITHUB_REF_NAME}#${{ matrix.image }}" \ + scan/full.json > "scan/${{ matrix.image }}.openvex.json" + trivy image -q --platform linux/amd64 \ + --scanners vuln --vex "/out/${{ matrix.image }}.openvex.json" \ + --format json -o "/out/${{ matrix.image }}.trivy.json" "$IMAGE_REF" + trivy convert --format table \ + --severity CRITICAL,HIGH -o "/out/${{ matrix.image }}.cves.txt" "/out/${{ matrix.image }}.trivy.json" + + - name: Attach scan results to the release + uses: softprops/action-gh-release@v2 + with: + files: | + scan/${{ matrix.image }}.openvex.json + scan/${{ matrix.image }}.trivy.json + scan/${{ matrix.image }}.cves.txt + + - uses: sigstore/cosign-installer@v4.1.2 + with: + cosign-release: "v2.6.5" + + # Lets `trivy image --vex oci` apply the statements without the release page. `cosign + # attest` has no --recursive, and a scanner may resolve either the index or the platform + # manifest, so each digest gets its own attestation. + - name: Attest VEX + run: | + repo="${IMAGE_REF%@*}" + digests="${{ matrix.digest }} $(docker buildx imagetools inspect --raw "$IMAGE_REF" \ + | jq -r '.manifests[]? | select(.platform.os != "unknown") | .digest')" + for d in $digests; do + for attempt in 1 2 3; do + cosign attest --yes --type openvex \ + --predicate "scan/${{ matrix.image }}.openvex.json" "$repo@$d" && continue 2 + echo "::warning::cosign attest of $d failed (attempt $attempt/3)" + [ "$attempt" -lt 3 ] && sleep $((attempt * 30)) + done + exit 1 + done + + - name: Docker Scout report uses: docker/scout-action@v1 with: command: cves only-severities: critical,high - image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-ee:main - sarif-file: sarif.output.json + image: ${{ env.IMAGE_REF }} + sarif-file: scout.sarif.json summary: true dockerhub-user: windmilllabs dockerhub-password: ${{ secrets.DOCKER_PAT }} - # Filed under main, not under the release tag this job runs on. The scanned image is - # `-ee:main` and the Security tab only reads the default branch, so tag-only uploads - # left main's last Docker Scout result at 2025-01-29: the tool showed as failing and - # its alerts could never close. `sha` is the release commit, which is on main. + # Filed under main: the Security tab only reads the default branch, so tag-only uploads + # never close their alerts. `sha` is the release commit, which is on main. - name: Upload SARIF result - id: upload-sarif - if: ${{ github.event_name != 'pull_request_target' }} uses: github/codeql-action/upload-sarif@v4 with: - sarif_file: sarif.output.json + sarif_file: scout.sarif.json + category: docker-scout-${{ matrix.image }} ref: refs/heads/main sha: ${{ github.sha }} + # Gates on the VEX-filtered report attached to the release, so the gate and the published + # results agree on what is not_affected. + - name: Fail on fixable critical CVEs + run: | + fixable="$(jq -r '.Results[]? | (.Vulnerabilities // [])[] + | select(.Severity == "CRITICAL" and .Status == "fixed") + | "\(.VulnerabilityID) \(.PkgName) \(.InstalledVersion) -> \(.FixedVersion)"' \ + "scan/${{ matrix.image }}.trivy.json" | sort -u)" + if [ -n "$fixable" ]; then + echo "$fixable" | sed 's/^/::error::fixable critical CVE: /' + exit 1 + fi + # docker_scout_ee: # runs-on: ubicloud # needs: [tag_latest_ee] @@ -582,6 +668,8 @@ jobs: if: ${{ startsWith(github.ref, 'refs/tags/v') }} needs: [build] runs-on: ubicloud + outputs: + digest: ${{ steps.docker_build.outputs.digest }} steps: - uses: actions/checkout@v4 with: @@ -636,6 +724,8 @@ jobs: needs: [build_ee] runs-on: ubicloud if: (github.event_name != 'pull_request') && ((github.event_name != 'workflow_dispatch') || (github.event.inputs.ee || github.event.inputs.slim)) + outputs: + digest: ${{ steps.docker_build.outputs.digest }} steps: - uses: actions/checkout@v4 diff --git a/Dockerfile b/Dockerfile index 3aa6cbd952..9072838c4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -199,7 +199,7 @@ RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmo RUN if [ "$WITH_GIT" = "true" ]; then \ apt-get update -y \ - && apt-get install -y git \ + && apt-get install -y --no-install-recommends git openssh-client less \ && apt-get clean \ && rm -rf /var/lib/apt/lists/*; \ else echo 'Building the image without git'; fi; @@ -235,6 +235,26 @@ RUN if [ "$WITH_KUBECTL" = "true" ]; then \ install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl; \ else echo 'Building the image without kubectl'; fi +# The official bundle, not Debian's awscli: that package lags upstream by years and pulls in +# python3-* libraries (urllib3, cryptography, ...) that nothing else in the image uses. Bumping the +# version means updating both checksums (the zips are signed by the AWS CLI key, FB5DB77F...4672475C). +ARG WITH_AWSCLI=true +ARG AWSCLI_VERSION=2.39.1 +ARG AWSCLI_SHA256_X86_64=5b6c10e0a8ccdcf30c84bd643fea511f103d257a4787a7cef878691d63169804 +ARG AWSCLI_SHA256_AARCH64=5adf0b5052843e542b55a846d49ba2a2b3f3fb4960f35c11df9ac7c395cffaaf +RUN if [ "$WITH_AWSCLI" = "true" ]; then \ + case "$(dpkg --print-architecture)" in \ + amd64) aws_arch=x86_64; aws_sha="$AWSCLI_SHA256_X86_64" ;; \ + arm64) aws_arch=aarch64; aws_sha="$AWSCLI_SHA256_AARCH64" ;; \ + *) echo >&2 "error: unsupported arch for awscli"; exit 1 ;; \ + esac; \ + curl -fsSL -o /tmp/awscli.zip "https://awscli.amazonaws.com/awscli-exe-linux-${aws_arch}-${AWSCLI_VERSION}.zip" \ + && echo "${aws_sha} /tmp/awscli.zip" | sha256sum -c - \ + && unzip -q /tmp/awscli.zip -d /tmp/awscli \ + && /tmp/awscli/aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli \ + && rm -rf /tmp/awscli /tmp/awscli.zip; \ + else echo 'Building the image without awscli'; fi + RUN set -eux; \ arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \ @@ -268,7 +288,7 @@ RUN UV_CACHE_DIR=/tmp/build_cache/uv UV_PYTHON_INSTALL_DIR=/tmp/build_cache/py_r RUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION%%.*}.x | bash - -RUN apt-get -y update && apt-get install -y --no-install-recommends curl procps nodejs=${NODE_VERSION}-1nodesource1 awscli && apt-get clean \ +RUN apt-get -y update && apt-get install -y --no-install-recommends curl procps nodejs=${NODE_VERSION}-1nodesource1 && apt-get clean \ && rm -rf /var/lib/apt/lists/* # The npm bundled with nodejs is replaced by a pinned one: it is what `//npm` scripts install with