Skip to content

Merge branch 'main' into dependabot/docker/docker-deps-33463fdea7 #3593

Merge branch 'main' into dependabot/docker/docker-deps-33463fdea7

Merge branch 'main' into dependabot/docker/docker-deps-33463fdea7 #3593

Workflow file for this run

name: Docker build
on:
workflow_dispatch:
push:
branches:
- "**"
tags:
- "v*"
pull_request:
branches:
- "main"
permissions:
contents: read
jobs:
docker:
name: Docker build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
security-events: write
pull-requests: write
attestations: write
outputs:
digest: ${{ steps.build-and-push.outputs.digest }}
steps:
- name: Harden runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.dso.docker.com:443
api.github.com:443
api.scout.docker.com:443
auth.docker.io:443
cdn01.quay.io:443
cdn02.quay.io:443
cdn03.quay.io:443
docker-images-prod.6aa30f8b08e16409b46e0173d6de2f56.r2.cloudflarestorage.com:443
files.pythonhosted.org:443
fulcio.sigstore.dev:443
get.anchore.io:443
ghcr.io:443
github.com:443
grype.anchore.io:443
hub.docker.com:443
index.docker.io:443
nodejs.org:443
objects.githubusercontent.com:443
pkg-containers.githubusercontent.com:443
production.cloudflare.docker.com:443
pypi.org:443
quay.io:443
raw.githubusercontent.com:443
registry-1.docker.io:443
registry.npmjs.org:443
registry.scout.docker.com:443
rekor.sigstore.dev:443
release-assets.githubusercontent.com:443
toolbox-data.anchore.io:443
tuf-repo-cdn.sigstore.dev:443
uploads.github.com:443
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Install Cosign
uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
with:
images: |
${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && ',index' || '' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
- name: Login to DockerHub
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: quay.io
username: ${{ vars.QUAY_ROBOT }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build-and-push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
platforms: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && 'linux/amd64,linux/arm64' || '' }}
push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
load: ${{ github.event_name == 'pull_request' || github.actor == 'dependabot[bot]' }}
sbom: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && 'generator=docker/scout-sbom-indexer:1.18.1@sha256:13c89fb6085aceb41f9556825c59d957917a3be670e3493598bd1f7f2a49f2fe' || '' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
annotations: ${{ steps.docker-meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate SBOM
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: anchore/sbom-action@da167eac915b4e86f08b264dbdbc867b61be6f0c # v0.20.5
with:
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
format: spdx-json
artifact-name: sbom-docker.spdx.json
output-file: sbom-docker.spdx.json
- name: Generate SBOM attestation for DockerHub
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-sbom@bd218ad0dbcb3e146bd073d1d9c6d78e08aa8a0b # v2.4.0
with:
subject-name: index.docker.io/${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
sbom-path: sbom-docker.spdx.json
push-to-registry: true
- name: Generate SBOM attestation for Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-sbom@bd218ad0dbcb3e146bd073d1d9c6d78e08aa8a0b # v2.4.0
with:
subject-name: quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
sbom-path: sbom-docker.spdx.json
push-to-registry: true
- name: Generate SBOM attestation for GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-sbom@bd218ad0dbcb3e146bd073d1d9c6d78e08aa8a0b # v2.4.0
with:
subject-name: ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
sbom-path: sbom-docker.spdx.json
push-to-registry: true
- name: Generate artifact attestation for DockerHub
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
with:
subject-name: index.docker.io/${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation for Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
with:
subject-name: quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation for GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
with:
subject-name: ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
- name: Sign the images with GitHub OIDC Token
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --recursive --yes ${images}
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.docker-meta.outputs.tags }}
- name: Analyze for critical and high CVEs with Docker Scout
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && github.actor != 'dependabot[bot]' }}
id: docker-scout-cves
continue-on-error: true
uses: docker/scout-action@f8c776824083494ab0d56b8105ba2ca85c86e4de # v1.16.0
with:
command: cves${{ !startsWith(github.ref, 'refs/tags/') && ',recommendations,compare' || '' }}
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw:${{ steps.docker-meta.outputs.version }}
sarif-file: sarif.output.json
organization: ${{ vars.DOCKERHUB_USERNAME }}
to: registry://${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw:1
- name: Upload Docker Scout scan result to GitHub Security tab
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && github.actor != 'dependabot[bot]' }}
continue-on-error: true
uses: github/codeql-action/upload-sarif@96f518a34f7a870018057716cc4d7a5c014bd61c # v3.29.5
with:
sarif_file: sarif.output.json
- name: Scan image with Grype
uses: anchore/scan-action@1638637db639e0ade3258b51db49a9a137574c3e # v6.5.1
id: grype-scan
continue-on-error: true
with:
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw:${{ steps.docker-meta.outputs.version }}
only-fixed: true
add-cpes-if-none: true
- name: Upload Grype scan result to GitHub Security tab
uses: github/codeql-action/upload-sarif@96f518a34f7a870018057716cc4d7a5c014bd61c # v3.29.5
continue-on-error: true
with:
sarif_file: ${{ steps.grype-scan.outputs.sarif }}
provenance-docker:
name: Generate SLSA Provenance for DockerHub
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
needs:
- docker
permissions:
actions: read
id-token: write
packages: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
digest: ${{ needs.docker.outputs.digest }}
private-repository: true
registry-username: ${{ vars.DOCKERHUB_USERNAME }}
secrets:
registry-password: ${{ secrets.DOCKERHUB_TOKEN }}
provenance-quay:
name: Generate SLSA Provenance for Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
needs:
- docker
permissions:
actions: read
id-token: write
packages: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
digest: ${{ needs.docker.outputs.digest }}
private-repository: true
registry-username: ${{ vars.QUAY_ROBOT }}
secrets:
registry-password: ${{ secrets.QUAY_TOKEN }}
provenance-ghcr:
name: Generate SLSA Provenance for GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
needs:
- docker
permissions:
actions: read
id-token: write
packages: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
digest: ${{ needs.docker.outputs.digest }}
private-repository: true
registry-username: ${{ github.repository_owner }}
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}