From 546a1d1b8bc3cbfc651d428fd4883999d63b23fa Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Fri, 13 Nov 2026 09:49:44 +0100 Subject: [PATCH 1/2] ci: publish the signed image and Helm chart on each release On every v* release tag, build the container image with ko (linux/amd64 and linux/arm64, on the non-root Chainguard static base the chart's security context expects) and push it to ghcr.io/devantler-tech/bookkeeper. Then pin that exact digest in the chart's values, package the chart with the release version, and push it to oci://ghcr.io/devantler-tech/charts. Both are signed keylessly with cosign and verified against this workflow's identity before the run succeeds. Only the workflow's own GITHUB_TOKEN is used. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yaml | 98 ++++++++++++++++++++++++++++++++++ .ko.yaml | 3 ++ AGENTS.md | 2 +- 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 .ko.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..7ca0e77 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,98 @@ +--- +# Publishes what the Helm chart installs, on every release tag: the container image and the chart +# itself, both to GHCR and both signed keylessly by this workflow. The packaged chart pins the +# exact image digest it was released with. +name: Publish image and chart +on: + push: + tags: + - "v*" + +permissions: {} + +concurrency: + group: publish-${{ github.ref }} + cancel-in-progress: false + +jobs: + publish: + name: Publish signed image and chart + runs-on: ubuntu-latest + permissions: + contents: read # check out the tagged source + packages: write # push the image and the chart to GHCR + id-token: write # sign both with the workflow's keyless Sigstore identity + steps: + - name: 📑 Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: ⚙️ Setup Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + # No module cache in a release job, so a poisoned cache cannot reach the image. + cache: false + + - name: 📦 Setup ko + uses: ko-build/setup-ko@61b4d1d396f5b2e7d6bb6fefdce3dc38d1a13445 # v0.10 + with: + version: v0.19.1 + + - name: 🔏 Install Cosign + uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3 + + - name: 🚀 Build, sign and publish + env: + GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GHCR_USER: ${{ github.actor }} + RELEASE_TAG: ${{ github.ref_name }} + run: | + set -euo pipefail + if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error::not a release tag: $RELEASE_TAG" + exit 1 + fi + version="${RELEASE_TAG#v}" + identity="https://github.com/${GITHUB_WORKFLOW_REF}" + issuer="https://token.actions.githubusercontent.com" + printf '%s' "$GHCR_TOKEN" | cosign login ghcr.io --username "$GHCR_USER" --password-stdin + printf '%s' "$GHCR_TOKEN" | helm registry login ghcr.io --username "$GHCR_USER" --password-stdin + + # The image, for both architectures. setup-ko points KO_DOCKER_REPO at this repository. + image=$(ko build . --bare --tags "$version" --platform linux/amd64,linux/arm64 \ + --image-label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}") + digest="${image##*@}" + if [[ "${image%%@*}" != "ghcr.io/devantler-tech/bookkeeper:${version}" ]] || + [[ ! "$digest" =~ ^sha256:[a-f0-9]{64}$ ]]; then + echo "::error::ko did not return the tagged image with its digest" + exit 1 + fi + image="ghcr.io/devantler-tech/bookkeeper@${digest}" + cosign sign --yes "$image" + cosign verify --certificate-identity "$identity" --certificate-oidc-issuer "$issuer" "$image" >/dev/null + + # The chart, pinned to exactly that image. + DIGEST="$digest" yq -i '.image.digest = strenv(DIGEST)' charts/bookkeeper/values.yaml + if [[ "$(yq '.image.digest' charts/bookkeeper/values.yaml)" != "$digest" ]]; then + echo "::error::could not pin the image digest in the chart" + exit 1 + fi + helm package charts/bookkeeper --version "$version" --app-version "$version" + push_output=$(helm push "bookkeeper-${version}.tgz" oci://ghcr.io/devantler-tech/charts 2>&1) + printf '%s\n' "$push_output" + chart_digest=$(printf '%s\n' "$push_output" | awk '$1 == "Digest:" {print $2}') + if [[ ! "$chart_digest" =~ ^sha256:[a-f0-9]{64}$ ]]; then + echo "::error::helm push returned no chart digest" + exit 1 + fi + chart="ghcr.io/devantler-tech/charts/bookkeeper@${chart_digest}" + cosign sign --yes "$chart" + cosign verify --certificate-identity "$identity" --certificate-oidc-issuer "$issuer" "$chart" >/dev/null + + { + echo "### Published ${RELEASE_TAG}" + echo "- Image: \`${image}\`" + echo "- Chart: \`oci://ghcr.io/devantler-tech/charts/bookkeeper\` ${version} (\`${chart_digest}\`)" + } >>"$GITHUB_STEP_SUMMARY" diff --git a/.ko.yaml b/.ko.yaml new file mode 100644 index 0000000..11abd4b --- /dev/null +++ b/.ko.yaml @@ -0,0 +1,3 @@ +# ko builds the release image straight from the Go source. The base runs as the non-root user +# 65532, which the chart's security context expects. +defaultBaseImage: cgr.dev/chainguard/static diff --git a/AGENTS.md b/AGENTS.md index f26468d..eab48de 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,7 +22,7 @@ the owner. Booking, reconciliation and VAT stay in Numina. - `charts/bookkeeper` — the Helm chart (CronJob, ServiceAccount, values schema). - `CLAUDE.md` / `GEMINI.md` — exact one-line `@AGENTS.md` shims; never copy guidance into them. - `.claude/skills/maintain/SKILL.md` — the maintenance skill card; it defers to *Maintenance* below. -- `.github/workflows/` — `ci.yaml` (required checks), `cd.yaml` (GoReleaser on `v*` tags), `release.yaml`, `template-sync.yaml` (weekly sync of template-owned plumbing from `devantler-tech/go-template`, honouring `.templatesyncignore`), `todos.yaml`, `stale-issues.yaml`. +- `.github/workflows/` — `ci.yaml` (required checks), `cd.yaml` (GoReleaser binaries on `v*` tags), `publish.yaml` (on `v*` tags: the ko-built image and the Helm chart to GHCR, both signed keylessly, the chart pinned to the image digest; `.ko.yaml` sets the base image), `release.yaml`, `template-sync.yaml` (weekly sync of template-owned plumbing from `devantler-tech/go-template`, honouring `.templatesyncignore`), `todos.yaml`, `stale-issues.yaml`. ## Validation From 4b2fa8354bd18839d7ff5a9bcfae380a2bb7de95 Mon Sep 17 00:00:00 2001 From: Nikolai Emil Damm Date: Fri, 13 Nov 2026 10:03:00 +0100 Subject: [PATCH 2/2] ci: keep shell-built URLs and the OIDC issuer out of the link check Build the workflow and repository URLs from GITHUB_SERVER_URL, so lychee finds no variable-shaped link, and list the Actions OIDC issuer, which cosign verifies against and which is no web page, in .lycheeignore. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yaml | 4 ++-- .lycheeignore | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .lycheeignore diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 7ca0e77..357c78e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -55,14 +55,14 @@ jobs: exit 1 fi version="${RELEASE_TAG#v}" - identity="https://github.com/${GITHUB_WORKFLOW_REF}" + identity="${GITHUB_SERVER_URL}/${GITHUB_WORKFLOW_REF}" issuer="https://token.actions.githubusercontent.com" printf '%s' "$GHCR_TOKEN" | cosign login ghcr.io --username "$GHCR_USER" --password-stdin printf '%s' "$GHCR_TOKEN" | helm registry login ghcr.io --username "$GHCR_USER" --password-stdin # The image, for both architectures. setup-ko points KO_DOCKER_REPO at this repository. image=$(ko build . --bare --tags "$version" --platform linux/amd64,linux/arm64 \ - --image-label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}") + --image-label "org.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}") digest="${image##*@}" if [[ "${image%%@*}" != "ghcr.io/devantler-tech/bookkeeper:${version}" ]] || [[ ! "$digest" =~ ^sha256:[a-f0-9]{64}$ ]]; then diff --git a/.lycheeignore b/.lycheeignore new file mode 100644 index 0000000..813489f --- /dev/null +++ b/.lycheeignore @@ -0,0 +1,3 @@ +# lychee checks every URL it finds. This one is the GitHub Actions OIDC token issuer that cosign +# verifies signatures against in .github/workflows/publish.yaml: an identity, not a web page. +^https://token\.actions\.githubusercontent\.com/?$