Skip to content

shipped · · 9 min

Shipping a Rust binary you can verify: eight targets, SBOMs, provenance, and least-privilege tokens

Every pdfblaze release is eight binaries and a C library for five platforms, with SHA-256 sums, a CycloneDX SBOM per file and signed build provenance that one gh command checks. The pipeline came with the engine I forked; what an audit found in it, how 1.4.2 split signing from building, and what fat LTO did to size and speed.

This is part 8 of the pdfblaze series. pdfblaze is a binary that a CRM downloads and runs on its servers, next to customer data. Anyone else who uses it does the same. So "is this the binary that the code in the repository builds?" is a question each user should be able to answer for themselves, without trusting me.

They can. Each release holds the binary for eight targets and the C library for five, a SHA256SUMS file, a CycloneDX SBOM per file, and a signed attestation of the build that made each one. One gh command checks a file against all of it. The pipeline that does this came with the engine I forked. What I changed is who in that pipeline holds which token: a security audit of 1.4.1 found that the jobs running other people's build scripts could also write the repository and sign, and 1.4.2 fixed that.

What a release holds

The release workflow builds:

TargetHow it is builtSize (1.4.3)
aarch64-linux-muslzig, static23.7 MB
aarch64-linux-gnuzig, against glibc 2.1724.3 MB
aarch64-apple-darwinmacOS runner26.7 MB
x86_64-linux-muslzig, static27.1 MB
x86_64-linux-gnuzig, against glibc 2.1727.8 MB
x86_64-apple-darwinmacOS runner29.3 MB
x86_64-freebsdin a FreeBSD VM on a Linux runner31.0 MB
x86_64-windowsWindows runner31.5 MB

The experimental C library comes as an archive per platform for five of those (Linux x64 and arm64 against glibc 2.17, macOS x64 and arm64, Windows x64), each 11.5–12.3 MB, with the header and the licences inside. musl gets none, because its static targets make no shared library.

Next to them: SHA256SUMS, a CycloneDX SBOM for every binary and archive (about 376–395 KB each), and THIRD-PARTY-NOTICES (421.7 KB), the licences of every crate in the binary. For 1.4.0, the first release of the fork, 26 files matched SHA256SUMS.

figure 1 · binary size
  • aarch64-linux-musl23.7 MB
  • aarch64-linux-gnu24.3 MB
  • aarch64-apple-darwin26.7 MB
  • x86_64-linux-musl27.1 MB
  • x86_64-linux-gnu27.8 MB
  • x86_64-apple-darwin29.3 MB
  • x86_64-freebsd31.0 MB
  • x86_64-windows31.5 MB

plus the C library: 11.5–12.3 MB archives for 5 targets

The 1.4.3 binaries run from 23.7 MB (arm64 Linux, musl) to 31.5 MB (Windows). Switch to LTO: optimising the whole program as one unit made the Apple silicon build 8% smaller, 28.0 MB rather than 30.5 MB.

What the engine already did

None of the build matrix is mine. The base engine already had it, and it is worth saying what it gets right, because most of this post is built on it.

  • glibc 2.17 through zig. Linux binaries are linked with cargo zigbuild against glibc 2.17, so one binary runs on every maintained distribution. musl builds are static, for Alpine.

  • FreeBSD without a FreeBSD runner. GitHub has none, so the binary is built natively inside a VM of the oldest supported FreeBSD release on a Linux runner, and a separate job runs it on the newest one before the release is drafted.

  • Every binary the runner can run, renders. Not just "it built":

    terminal
    echo '<h1>Pdfblaze</h1>' > probe.html
    "$binary" render probe.html -o probe.pdf
    test "$(head -c 5 probe.pdf)" = "%PDF-"
    

    A C program built against the header does the same for the library, on Linux x64 and macOS arm64.

  • Actions pinned by commit, with the version in a comment, and Dependabot to propose new commits weekly. A moved tag changes nothing.

  • An SBOM per target, from cargo cyclonedx --target, so the Windows SBOM lists the crates in the Windows binary and not the Linux one.

  • Attestations without a key. GitHub signs, through Sigstore, with the identity of the workflow run: this file, with this SHA-256, was built by this workflow at this commit. There is no signing key to leak, rotate or lose.

Checking a binary yourself

From SECURITY.md, with the current release:

terminal
gh release download v1.4.3 --repo sundarshahi/pdfblaze \
  -p pdfblaze-x86_64-unknown-linux-gnu -p SHA256SUMS
sha256sum --check --ignore-missing SHA256SUMS
gh attestation verify pdfblaze-x86_64-unknown-linux-gnu --repo sundarshahi/pdfblaze \
  --signer-workflow sundarshahi/pdfblaze/.github/workflows/release.yml

The two checks prove different things:

  • The sum proves the file is the one the release lists. On its own it proves little: whoever can change the file can change the list.
  • The attestation proves where the file came from: a run of release.yml in this repository, at a commit you can look up. --signer-workflow pins the workflow, so an attestation made by some other workflow in the same repository does not pass. The SBOM of each binary has its own attestation, so the list of crates is tied to the same build.

The CRM does a simpler version at deploy time: it pins the SHA-256 of the binary per platform, so a release that changes under the same tag fails the deploy.

What the audit found: one set of permissions for every job

The audit of 1.4.1 (part 4) rated the release workflow a Medium. Its top looked like this:

terminal
permissions:
  contents: write
  # Attestations: the OIDC token that Sigstore signs with, and writing them to the repository.
  id-token: write
  attestations: write

Permissions at the workflow level apply to every job that does not set its own. So the build and library jobs, 13 of them, ran with a token that could push to the repository and an OIDC token that could sign attestations. Those are exactly the jobs that run the most code nobody in this repository wrote:

  • every dependency's build.rs, during cargo build;
  • cargo-zigbuild and cargo-cyclonedx, installed from crates.io;
  • zig itself, installed from PyPI with pip install, with no hash;
  • a third-party action that boots the FreeBSD VM.

On top of that, actions/checkout keeps the token in .git/config by default, so it sat on disk for the whole job.

The failure this opens is quiet. A compromised build script does not need to break the build. It can build a different binary, attest it with the workflow's own identity, and the attestation would verify, because the workflow really did make it. Signed provenance is only as good as the job that holds the signing token.

The fix in 1.4.2

Three changes, each small.

The workflow reads by default. The top-level permission is now one line, and the jobs that need more say so themselves:

terminal
# The jobs that build run the build scripts of every dependency, so they only read.
# Signing (`attest`) and drafting the release (`release`) get their own jobs,
# which build nothing.
permissions:
  contents: read

Signing moved to a job that builds nothing. A new attest job, one per artifact, downloads what the builds uploaded and attests it. It checks out no code and runs no build script. It holds id-token: write and attestations: write, and only reads the repository. The release job, which drafts the release, is the only one that can write, and it runs gh and pinned actions, nothing from crates.io.

terminal
attest:
  needs: [build, library]
  permissions:
    contents: read
    id-token: write
    attestations: write
  steps:
    - uses: actions/download-artifact@… # pinned
    - uses: actions/attest-build-provenance@… # pinned
      with:
        subject-path: dist/*

No token on disk, and zig by hash. Every checkout sets persist-credentials: false. zig comes from a requirements file that pins its SHA-256 for both Linux architectures, installed with pip install --require-hashes -r .github/requirements-zig.txt.

figure 2 · who holds which token
  1. build · 8 targets

    runs every dependency's build script; zig; a third-party FreeBSD VM action

    • writes the repository (risk)
    • signs attestations (risk)
    • token kept in the checkout (risk)
    • zig from pip, no hashes (needed)

    library · 5 targets

    runs every dependency's build script; zig

    • writes the repository (risk)
    • signs attestations (risk)
    • token kept in the checkout (risk)
    • zig from pip, no hashes (needed)
  2. freebsd-15

    runs the FreeBSD binary, in a VM

    • reads only (ok)
  3. release

    runs gh and pinned actions

    • writes the repository (needed)
    • signs SHA256SUMS (needed)
    • token kept in the checkout (risk)

more than the job needs · needed by this job · least access

In 1.4.1 the permissions sat at the top of the workflow, so the jobs that run other people's build scripts could also write the repository and sign. In 1.4.2 those jobs only read; signing has a job of its own that builds nothing, and only the release job writes.

The FreeBSD VM action is still third-party and still runs in the build job. What changed is what it can reach: a token that only reads, which is not in the checkout.

Smaller and faster: fat LTO

One change to the release profile, in commit d095c5b: link-time optimisation from thin to fat. codegen-units = 1 was already set.

terminal
[profile.release]
lto = "fat"
codegen-units = 1

Medians on Apple silicon:

CaseThin LTOFat LTO
One-page quote19.9 ms19.0 ms
500 rows104.7 ms100.7 ms
2,000 rows348.5 ms331.9 ms
Binary30.5 MB28.0 MB
Build time59.88 s59.99 s

4–5% faster and 8% smaller, for no change in build time on that machine. Fat LTO is usually expected to cost build time; here it did not, so there was nothing to trade.

A patched dependency is a supply-chain decision too

The audit's first High was a PDF used as an image that crashed the process (part 5). The fix lives in hayro-syntax 0.8, but the PDF writer the engine uses still depends on 0.7. So the repository carries hayro-syntax 0.7.2 with the 0.8 depth limit backported, under vendor/, and points Cargo at it:

terminal
[patch.crates-io]
hayro-syntax = { path = "vendor/hayro-syntax" }

That is fine for the binary, which is built from this workspace. It is not free for anyone using pdfblaze as a Rust library: [patch] only applies in the top-level workspace, so their build would quietly use crates.io's 0.7 unless they copy the patch. docs/rust.md says so. The patch comes out once the PDF writer depends on hayro-syntax 0.8 or later.

Less to ship

The fork dropped the PHP and Laravel package in commit 501fd13: 147 files, +1,825 / −15,388 lines. pdfblaze is the binary, the worker protocol, the Rust crate and the C library. Every other language calls the binary. A package for one language is a second release process to keep safe, and every other language already called the binary. The docs check that was a PHP script became cargo xtask check-docs.

What I'd do differently, and what's still open

  • Provenance is not safety. An attestation says which workflow at which commit built a file. It says nothing about whether that commit is safe, or whether a dependency in it is. The SBOM is what lets you check the second; nobody is checking it for you.
  • Releases are drafts, published by hand. The workflow drafts the release; I download it, check the sums, run the binary, then tag and publish. That is a step where a human can be wrong. It is also the step where a human can notice something.
  • Reproducible builds are unchecked. I have not tested whether two runs of the workflow give the same bytes, and nothing in it promises that. The engine's gates already check that its PDFs are the same bytes on every platform; doing the same for the binaries, so a user can rebuild and compare, is the next step up from provenance.
  • The C library was out of the audit's scope, along with fuzzing and the Linux sandbox. It ships with SBOMs and attestations like the binaries, but nobody has attacked it.
  • I should have read the workflow before the first release, not after the audit. The permissions block sat at the top of a file I had already shipped two releases from. The fix was small; noticing it took an audit.

Working through something like this? I help teams ship AI and cloud systems that hold up, and cost what they should.