name: Signed container release on: release: types: [published] workflow_dispatch: permissions: contents: read concurrency: group: release-${{ github.ref }} cancel-in-progress: false jobs: policy: name: Release policy runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 with: node-version-file: .nvmrc - name: Verify package and local image release identity run: node scripts/check-release-identity.mjs - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7 with: python-version: '3.12' - run: python -m pip install -r scripts/requirements-checks.txt - name: Verify release component coverage run: scripts/check-release-components.sh - name: Validate vulnerability waivers run: node scripts/check-trivy-waivers.mjs - name: Require a clean commit release run: test -z "$(git status --porcelain --untracked-files=all)" image: name: ${{ matrix.component }} needs: policy runs-on: ubuntu-latest permissions: contents: read packages: write id-token: write attestations: write strategy: fail-fast: false matrix: include: - component: backend image: meshcore-backend context: . file: Dockerfile.backend build_args: '' - component: tagger-worker image: meshcore-tagger-worker context: tagger-worker file: tagger-worker/Dockerfile build_args: '' - component: combined image: meshcore-combined context: . file: Dockerfile build_args: VITE_APP_HOSTNAME=app.ukmesh.com - component: app image: meshcore-app context: . file: Dockerfile.app build_args: | VITE_APP_HOSTNAME=app.ukmesh.com VITE_NETWORK=ukmesh VITE_SITE=ukmesh VITE_RF_COVERAGE_ENABLED=true - component: website image: meshcore-website context: . file: Dockerfile.website build_args: | VITE_APP_HOSTNAME=app.ukmesh.com VITE_SITE=ukmesh - component: website-dev image: meshcore-website-dev context: . file: Dockerfile.website build_args: | VITE_APP_HOSTNAME=test.ukmesh.com VITE_BUILD_TARGET=dev-website VITE_NETWORK=test VITE_SITE=dev VITE_SITE_DISPLAY_NAME=UK Mesh Test VITE_SITE_FOOTER_NAME=UK Mesh Test VITE_SITE_APP_URL=https://test.ukmesh.com VITE_SITE_HOME_URL=https://test.ukmesh.com - component: rf-worker image: meshcore-rf-worker context: viewshed-worker file: viewshed-worker/Dockerfile build_args: '' - component: hopreach image: meshcore-hopreach context: third_party/hopreach file: third_party/hopreach/Dockerfile build_args: | VERSION=v0.1.32-ukmesh.5 SOURCE_REVISION=${{ github.sha }} SOURCE_REPOSITORY=https://github.com/gadgethd/ukmesh - component: mosquitto-reloader image: meshcore-mosquitto-reloader context: . file: Dockerfile.mosquitto-reloader build_args: '' - component: corescope image: ukmesh-corescope context: third_party/corescope file: Dockerfile.corescope companion_path: third_party/corescope build_args: '' - component: beacon-server image: ukmesh-beacon-server context: third_party/beacon-server file: Dockerfile.beacon-server companion_path: third_party/beacon-server build_args: '' - component: beacon-web image: ukmesh-beacon-web context: third_party/beacon-web file: Dockerfile.beacon-web companion_path: third_party/beacon-web build_args: '' - component: health-check image: meshcore-health-check context: . file: Dockerfile.mesh-health-check build_args: '' env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository_owner }}/${{ matrix.image }} SOURCE_REVISION: ${{ github.sha }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 with: node-version-file: .nvmrc - name: Read validated release identity id: identity run: node scripts/check-release-identity.mjs >> "$GITHUB_OUTPUT" - name: Check out the pinned Health Check source if: matrix.component == 'health-check' id: health_source run: | git submodule update --init -- third_party/meshcore-health-check revision=$(bash scripts/healthcheck-source.sh --verify) printf 'revision=%s\n' "$revision" >> "$GITHUB_OUTPUT" - name: Check out the pinned companion source if: matrix.companion_path id: companion env: SOURCE_PATH: ${{ matrix.companion_path }} run: | git submodule update --init --depth 1 -- "$SOURCE_PATH" expected=$(git rev-parse "HEAD:$SOURCE_PATH") test "$(git -C "$SOURCE_PATH" rev-parse HEAD)" = "$expected" printf 'revision=%s\n' "$expected" >> "$GITHUB_OUTPUT" - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} labels: | org.opencontainers.image.revision=${{ env.SOURCE_REVISION }} ${{ (steps.companion.outputs.revision || steps.health_source.outputs.revision) && format('io.ukmesh.companion.revision={0}', steps.companion.outputs.revision || steps.health_source.outputs.revision) || '' }} io.ukmesh.release.version=${{ steps.identity.outputs.version }} ${{ matrix.component == 'hopreach' && 'org.opencontainers.image.source=https://github.com/gadgethd/ukmesh' || '' }} ${{ matrix.component == 'hopreach' && 'org.opencontainers.image.licenses=AGPL-3.0-only WITH Commons-Clause' || '' }} tags: | type=sha,format=long type=ref,event=tag - id: build name: Build and push immutable image uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 with: context: ${{ matrix.context }} file: ${{ matrix.file }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | SOURCE_REVISION=${{ env.SOURCE_REVISION }} UKMESH_VERSION=${{ steps.identity.outputs.version }} ${{ matrix.component == 'health-check' && format('MESH_HEALTH_CHECK_REF={0}', steps.health_source.outputs.revision) || '' }} ${{ matrix.companion_path && format('COMPANION_REVISION={0}', steps.companion.outputs.revision) || '' }} ${{ matrix.build_args }} provenance: false sbom: false cache-from: type=gha,scope=${{ matrix.component }} cache-to: type=gha,mode=max,scope=${{ matrix.component }} - name: Gate exact digest on critical vulnerabilities uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: scan-type: image image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }} format: json output: trivy-${{ matrix.component }}.json exit-code: '1' severity: CRITICAL ignore-unfixed: false trivyignores: .trivyignore.yaml - name: Retain vulnerability results even when the gate rejects an image if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: name: scan-${{ github.sha }}-${{ matrix.component }} path: trivy-${{ matrix.component }}.json if-no-files-found: warn retention-days: 90 - name: Generate SPDX SBOM for exact digest uses: anchore/sbom-action@dfcb83b97731532d72be422cbc51ee64adb6fd56 # v0.24.4 with: image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }} format: spdx-json output-file: sbom-${{ matrix.component }}.spdx.json upload-artifact: false # Keyless signing is deliberately not part of this job: it lives in the # `sign` job below, which is restricted to version tags and gated by the # protected `release-signing` environment. Branch dispatches still build, # scan, and publish images; they simply cannot produce a release signature. - id: provenance name: Publish registry provenance uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4 with: subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} subject-digest: ${{ steps.build.outputs.digest }} push-to-registry: true - name: Write release inventory env: DIGEST: ${{ steps.build.outputs.digest }} COMPANION_REVISION: ${{ steps.companion.outputs.revision || steps.health_source.outputs.revision }} ATTESTATION_URL: ${{ steps.provenance.outputs.attestation-url }} run: | jq -n \ --arg component "${{ matrix.component }}" \ --arg source_revision "$SOURCE_REVISION" \ --arg companion_revision "$COMPANION_REVISION" \ --arg release_revision "$GITHUB_SHA" \ --arg image "${REGISTRY}/${IMAGE_NAME}@${DIGEST}" \ --arg sbom "sbom-${{ matrix.component }}.spdx.json" \ --arg scan "trivy-${{ matrix.component }}.json" \ --arg signature "signature-${{ matrix.component }}.json" \ --arg provenance "$ATTESTATION_URL" \ '{ format: "meshcore-release-inventory-v1", component: $component, source_revision: $source_revision, release_revision: $release_revision, image: $image, sbom: $sbom, scan: $scan, signature: $signature, provenance: $provenance } + (if $companion_revision == "" then {} else {companion_revision: $companion_revision} end)' > "inventory-${{ matrix.component }}.json" - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: name: release-${{ github.sha }}-${{ matrix.component }} if-no-files-found: error retention-days: 90 path: | inventory-${{ matrix.component }}.json sbom-${{ matrix.component }}.spdx.json trivy-${{ matrix.component }}.json sign: name: Sign ${{ matrix.component }} needs: image # Only a version tag may produce a release signature. `workflow_dispatch` # is unqualified, so this guard is the control that keeps a branch run from # minting a signature that verifies against a release identity. if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest # Required reviewers are configured on this environment in repository # settings: the job blocks until an approver releases it. The environment # also scopes any secrets used for signing to tagged releases only. environment: name: release-signing url: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }} permissions: contents: read packages: write id-token: write strategy: fail-fast: false matrix: include: - component: backend - component: tagger-worker - component: combined - component: app - component: website - component: website-dev - component: rf-worker - component: hopreach - component: mosquitto-reloader - component: corescope - component: beacon-server - component: beacon-web - component: health-check steps: - name: Download the image job's release evidence uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: release-${{ github.sha }}-${{ matrix.component }} path: evidence - name: Require the inventory to name an immutable digest id: image run: | set -euo pipefail image="$(jq -r '.image' "evidence/inventory-${{ matrix.component }}.json")" if ! [[ "$image" =~ ^ghcr\.io/[A-Za-z0-9._/-]+@sha256:[a-f0-9]{64}$ ]]; then echo "release inventory does not name an immutable image digest: $image" >&2 exit 65 fi printf 'image=%s\n' "$image" >> "$GITHUB_OUTPUT" - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3 - name: Sign and attest the approved digest env: IMAGE: ${{ steps.image.outputs.image }} COMPONENT: ${{ matrix.component }} run: | set -euo pipefail # Defence in depth: the job-level guard is the primary control, and # this keeps signing impossible if that guard is ever edited away. case "$GITHUB_REF" in refs/tags/v*) ;; *) echo "refusing to sign a non-tag ref: $GITHUB_REF" >&2; exit 65 ;; esac cosign sign --yes "$IMAGE" cosign attest --yes \ --predicate "evidence/sbom-${COMPONENT}.spdx.json" \ --type spdxjson "$IMAGE" cosign verify "$IMAGE" \ --certificate-identity-regexp "^https://github.com/${GITHUB_REPOSITORY}/.github/workflows/release.yml@" \ --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ > "signature-${COMPONENT}.json" jq -e 'length > 0' "signature-${COMPONENT}.json" >/dev/null - name: Publish signature evidence uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: name: release-signature-${{ github.sha }}-${{ matrix.component }} if-no-files-found: error retention-days: 90 path: signature-${{ matrix.component }}.json