# Signs what a release hands people, so anyone can check the bytes were built # from this repository at that commit and not pasted in by hand. The plugin's # three files, and the server's four binaries. # # It rebuilds them here rather than attesting whatever was uploaded, because an # attestation over a file of unknown origin says only that this workflow saw it. # The rebuilt files replace the uploaded ones, so what the release holds is what # was attested. # # On release rather than on tag: the tag is pushed first and the release is made # afterwards, so a tag trigger would fire before there was anything to upload to. # # The release is created as a draft and this publishes it (R16), and it is # started by hand rather than by an event (R29). # # The old order put the assets in front of the checks: `release.sh` printed a # `gh release create`, the operator ran it, the files were public immediately, # and only then did this workflow ask whether CI had passed, rebuild them and # replace them with `--clobber`. If CI had failed the unchecked bytes stayed # downloadable, and if the rebuild differed whoever downloaded first got # something nobody else would. # # A draft fixes that and cannot be the trigger. GitHub excludes draft releases # from the `created`, `edited` and `deleted` release events, so listening for # `created` meant the documented flow produced a draft and started nothing at # all: worse than before, because it looks like it is working. `published` is # no use either, since publishing is the thing this is supposed to do last. # # So `release.sh` prints the dispatch beside the draft and this runs on # `workflow_dispatch`. One command more, and the ordering is real: validate, # rebuild, attest, checksum, publish. A run that fails leaves a draft, which is # the right thing to leave. name: attest on: workflow_dispatch: inputs: tag: description: The release tag to build, attest and publish required: true # One run per release, and a later one waits rather than interleaving (R39). # # Both upload steps use `--clobber`, so two runs against one tag can replace # each other's assets while a third step publishes: a public release whose # checksums describe files it does not have. The group is per tag, because two # different releases have nothing to do with each other. concurrency: group: attest-${{ inputs.tag }} cancel-in-progress: false permissions: contents: write # replaces the release assets with the attested build id-token: write # OIDC, which is what the attestation is signed against attestations: write # records it jobs: # Nothing is published from a commit CI has not passed on (I21). The reasons # and the waiting are in scripts/ci-passed.sh, which all three publishing # workflows call so there is one answer to "was this checked" rather than # three that can drift. checked: name: CI passed on this commit # `github.token` gets only what the workflow declares, and reading another # workflow's runs is not in the default set. permissions: actions: read # `write`, for a job that only reads, and the reason is GitHub's: a draft # release is visible only to a token with push access, so `contents: read` # makes `gh release view` answer "release not found" for the very thing # this job exists to check. Narrowing this to `read` was part of adding # the publish gate, and no release happened between then and now, so the # tightening that was supposed to make publishing safer had quietly # broken the check that makes it safe. contents: write runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: refuse to publish from an unchecked commit env: GH_TOKEN: ${{ github.token }} run: ./scripts/ci-passed.sh "${{ github.repository }}" "${{ inputs.tag }}" # And that the release is still private, before anything touches an asset # (R39). # # Everything below rebuilds the files and replaces them with `--clobber`. # That is safe against a draft, which nobody can download, and it is not # safe against anything else: a rerun against a published release swaps # the bytes people are downloading right now, and a rebuild that differs # or an upload that fails partway leaves a public release whose checksums # describe files it does not have. The draft-only ordering was the whole # of R16 and nothing established it. # # In this job, which both upload jobs need, so it is one question asked # once and asked before the first mutation rather than beside it. - name: refuse a release that is already public env: GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} run: | set -euo pipefail draft=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft --jq .isDraft) [ "$draft" = "true" ] || { echo "$TAG is already published, and this replaces a release's files before it" >&2 echo "publishes them. Re-attesting public bytes is not something this does: make a" >&2 echo "new release, or delete this one and create it again as a draft." >&2 exit 1 } echo "$TAG is a draft, so nothing below is downloadable until the last step" plugin: name: plugin needs: checked runs-on: ubuntu-latest # Plugin releases only, which are the ones tagged with a bare version. # Every other line is prefixed, so a slash means this is not one. The tag # and manifest check below fails closed for anything that slips past. if: ${{ !contains(inputs.tag, '/') }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ inputs.tag }} - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 with: bun-version: 1.4.1 - name: install working-directory: client run: bun install --frozen-lockfile - name: build working-directory: client run: bun run build # Exactly the three files Obsidian downloads, and nothing else. The # build already puts all three in dist/plugin. - name: gather run: | mkdir -p attested cp client/dist/plugin/main.js attested/ cp client/dist/plugin/manifest.json attested/ cp client/dist/plugin/styles.css attested/ ls -l attested # A release whose manifest says one version and whose tag says another # would be attested happily, so check before signing anything. - name: the tag and the manifest agree env: TAG: ${{ inputs.tag }} run: | want="${TAG#v}" got=$(node -p "require('./attested/manifest.json').version") if [ "$want" != "$got" ]; then echo "release $TAG carries manifest version $got" >&2 exit 1 fi # And that the repository at this tag says which Obsidian can run it. # # Obsidian reads versions.json from the repository at the tag, not from # the release, and looks up the newest version an install is allowed. A # missing entry is not an error anybody sees: current Obsidian installs # the plugin from the manifest and every older one is told there is # nothing it can run, which looks like the plugin not existing. The entry # therefore has to be in the commit the tag points at, and a commit is not # something a release can add afterwards. # # scripts/release.sh checks this too. That check only runs for somebody # who used it; this one runs before the release is made downloadable, # which is the last moment it can still be fixed by moving a tag. - name: versions.json at this tag says what runs it env: TAG: ${{ inputs.tag }} run: | version=$(node -p "require('./attested/manifest.json').version") minapp=$(node -p "require('./attested/manifest.json').minAppVersion") entry=$(node -p "(require('./versions.json')['$version'] || '')") if [ -z "$entry" ]; then echo "versions.json at $TAG has no entry for $version." >&2 echo "Every Obsidian older than the current one will be told there is" >&2 echo "nothing it can run. scripts/release.sh --prepare writes it, and it" >&2 echo "has to be committed before the tag." >&2 exit 1 fi if [ "$entry" != "$minapp" ]; then echo "versions.json says $version needs Obsidian $entry, the manifest says $minapp" >&2 exit 1 fi echo "$version needs Obsidian $minapp, and versions.json at $TAG agrees" - uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 with: subject-path: | attested/main.js attested/manifest.json attested/styles.css # Written here, over the rebuilt files, for the reason the server's are # (R16). The three assets were replaced with `--clobber` and the # `SHA256SUMS` beside them was left as the laptop had written it, so a # rebuild that differed by a byte left a checksum file that described # bytes nobody could download. - name: checksums working-directory: attested run: | shasum -a 256 main.js manifest.json styles.css > SHA256SUMS cat SHA256SUMS - name: upload env: GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} run: | gh release upload "$TAG" \ attested/main.js attested/manifest.json attested/styles.css attested/SHA256SUMS \ --clobber --repo "$GITHUB_REPOSITORY" # Last, and only now (R16). Everything above has run against a draft: # nothing was downloadable, and a failure anywhere leaves it that way. - name: publish env: GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} run: | gh release edit "$TAG" --draft=false --latest=true --repo "$GITHUB_REPOSITORY" echo "$TAG is public, with the files that were just checked and signed" server: name: server needs: checked runs-on: ubuntu-latest # The server's own tag line. Without this the binaries were the one thing a # release shipped with no provenance at all: built on a laptop, checksummed # by the same script from the same bytes, and uploaded. SHA256SUMS generated # beside them proves the download was not corrupted in transit and nothing # whatsoever about where the bytes came from. if: ${{ startsWith(inputs.tag, 'server/v') }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ inputs.tag }} - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version-file: server/go.mod # The same four targets and the same flags as scripts/release.sh, because # the point is to rebuild what was uploaded rather than to build something # near it. Go stamps the commit into the binary itself, so this is # reproducible per commit: rebuilding server/v0.1.4 from a clean worktree # gave the published bytes exactly, which is what makes --clobber safe. - name: build env: TAG: ${{ inputs.tag }} run: | set -euo pipefail version="${TAG#server/v}" # Keep every build output outside the checkout until all targets # finish, so earlier binaries do not mark later builds as modified. build_dir=$(mktemp -d "$RUNNER_TEMP/basalt-attest.XXXXXX") trap 'rm -rf "$build_dir"' EXIT for target in linux/amd64 linux/arm64 darwin/arm64 darwin/amd64; do goos="${target%/*}" goarch="${target#*/}" ( cd server && CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" \ go build -trimpath -ldflags "-s -w -X main.version=$version" \ -o "$build_dir/basaltd-$goos-$goarch" ./cmd/basaltd ) done mkdir -p attested cp "$build_dir"/basaltd-* attested/ ls -l attested # Generated here rather than uploaded from a laptop, so it says something # about the binaries beside it instead of about itself. - name: checksums working-directory: attested run: | shasum -a 256 basaltd-* > SHA256SUMS cat SHA256SUMS # A binary that reports a version other than the tag it ships under is # the same lie the plugin's manifest check refuses. - name: the tag and the binary agree env: TAG: ${{ inputs.tag }} run: | want="${TAG#server/v}" got=$(./attested/basaltd-linux-amd64 version | awk '{print $2}') if [ "$want" != "$got" ]; then echo "release $TAG carries a binary calling itself $got" >&2 exit 1 fi - uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 with: subject-path: attested/basaltd-* - name: upload env: GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} run: | gh release upload "$TAG" attested/basaltd-* attested/SHA256SUMS \ --clobber --repo "$GITHUB_REPOSITORY" # Last, and only now (R16). See the plugin job. - name: publish env: GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} run: | gh release edit "$TAG" --draft=false --latest=false --repo "$GITHUB_REPOSITORY" echo "$TAG is public, with the files that were just checked and signed"