# Self-hosted repositories and official signatures

> Build a repository from local qcow2 images and verify official Barn releases.

---

LLMS index: [llms.txt](/v1.5/llms.txt)

---

Share a lab repository by distributing its images and catalog. Barn 1.5.0 supports filename-based builds and ML-DSA-87 verification. Barn 1.4.0 uses `repo.yaml` for builds and Minisign for official catalogs.

## Create and use a lab repository {#user-repository}

Place your images under `repo/images/`, for example `lab-pg-1-arm64.qcow2`. Run these commands on a host with `qemu-img`:

```bash
barn repo build ./repo
barn up --repo ./repo -I lab-pg
```

The first command writes `catalog.json`. Barn takes the image name, version and architecture from each filename and defaults to UEFI. An existing `repo.yaml` still selects the repository contents. A local repository can be unsigned and use your original image files.

To share it, serve `catalog.json` and `images/` over HTTPS. Set the address on the client and activate the catalog. Run the same `barn update` when the repository changes.

```bash
export BARN_REPO=https://images.example.org/lab
barn update
barn up -I lab-pg
```

`barn update --repo ./repo` refreshes only that directory. Explicitly selected local and custom HTTPS repositories can be unsigned. Plain HTTP requires a valid ML-DSA-87 signature. Both 1.4 and 1.5 clients check image SHA-256 digests and byte counts from a schema 3 catalog.

## Official images and packages {#bootstrap}

Use `barn up` or `barn update` with the official repository as usual. New clients verify `catalog.json.sig` with their built-in key. The maintainer publishes a separate `catalog.json.minisig` over the same catalog for 1.4.0 clients.

Internal mirrors of the official repository should copy both signature files with the catalog. Users who cached that mirror’s catalog in Barn 1.4.0 can refresh it after upgrading with `barn update --repo <mirror>`.

Initial script installations rely on HTTPS. For independent verification, get the public key through a trusted channel and use OpenSSL 3.5 or later to check the release manifest. Then check the installer and platform archive against that manifest. Use your existing installation channel for upgrades.

```bash
openssl pkeyutl -verify -rawin -pubin -inkey /trusted/official-key.pem \
  -pkeyopt context-string:barn/release/v1 -in checksums.txt -sigfile checksums.txt.sig
shasum -a 256 -c checksums.txt --ignore-missing
```

## Generate and store the maintainer key {#maintainer-key}

Barn signs its official image catalogs and CLI release manifests with one ML-DSA-87 key. Run the Bash commands below from the Barn source root with OpenSSL 3.5 or later and ML-DSA support.

### First-time generation and public fingerprint {#generate}

The official key was generated on December 3, 2026. Restore the same key when moving to another machine. The commands below document initial provisioning and stop if the private key already exists. [Backup and recovery](#backup)

The private key is a passphrase-free PKCS#8 PEM. Anyone who can read it can sign as Barn. Keep it on the maintainer’s machine with disk encryption, a mode 0700 directory and a mode 0600 file. Only the exported public key goes into the source tree and build machines.

```bash
(
  set -eu
  umask 077
  keydir="$HOME/.config/barn/signing"
  install -d -m 0700 "$keydir"
  set -C
  openssl genpkey -algorithm ML-DSA-87 > "$keydir/official.pem"
  openssl pkey -in "$keydir/official.pem" -check -noout
  openssl pkey -in "$keydir/official.pem" -pubout -out internal/image/official-key.pem
  chmod 0644 internal/image/official-key.pem
)
```

Get the public key from a trusted release commit. This command calculates SHA-256 over its DER-encoded SubjectPublicKeyInfo. The fingerprint for the official key introduced on December 3, 2026 is `5b108c30d99f93a28184fef362367dc63d4f7c1c2e56c2e0d89c7e3e1f17a262`. New Barn clients display the short ID `583F7D5BAA0D16C5` in catalog state. [Public key in v1.5.0](https://github.com/pgsty/barn/blob/v1.5.0/internal/image/official-key.pem)

```bash
openssl pkey -pubin -in internal/image/official-key.pem -outform DER | openssl dgst -sha256
```

### Backup and recovery {#backup}

Keep a second copy of the private key on a separate encrypted removable volume. Unlock and mount it first, then replace `/Volumes/BarnBackup` with its actual mount point. Both `cmp` commands exit silently on success. They check that the backup is byte-identical and that it yields the public key embedded in the client. Eject the volume and store it offline.

```bash
(
  set -euo pipefail
  umask 077
  volume=/Volumes/BarnBackup
  key="$HOME/.config/barn/signing/official.pem"
  test -d "$volume"
  install -d -m 0700 "$volume/barn-signing"
  backup="$volume/barn-signing/official.pem"
  set -C
  cat "$key" > "$backup"
  cmp "$key" "$backup"
  openssl pkey -in "$backup" -pubout | cmp - internal/image/official-key.pem
)
```

To move to a new signing machine, obtain `internal/image/official-key.pem` from a trusted release commit and restore from the removable volume. The commands check the public key first and preserve any existing private key at the destination. Recover the original key from backup after a disk failure. A compromised key or loss of all copies requires distributing a client that trusts a replacement key.

```bash
(
  set -euo pipefail
  umask 077
  backup=/Volumes/BarnBackup/barn-signing/official.pem
  keydir="$HOME/.config/barn/signing"
  openssl pkey -in "$backup" -pubout | cmp - internal/image/official-key.pem
  install -d -m 0700 "$keydir"
  set -C
  cat "$backup" > "$keydir/official.pem"
  cmp "$backup" "$keydir/official.pem"
)
```

## Sign and publish as the maintainer {#maintainer-sign}

From the Barn source root, select the image repository and the signing directory. Recompute the image digests and check that the catalog matches the repository.

```bash
repo=../repo/barn
keydir="$HOME/.config/barn/signing"
barn repo verify "$repo"
```

Reuse an existing `catalog.json.minisig` if it verifies. When the repository changes, first increase the revision and run `barn repo build "$repo"`, then recreate the legacy signature with the original 1.4.0 key using `make catalog-sign CATALOG_KEY="$keydir/barn-catalog-active-20261126.key" CATALOG_FILE="$repo/catalog.json"`. The tool reads the legacy key’s passphrase from `CATALOGSIGN_PASSWORD`. Sign those same catalog bytes with the new key.

```bash
make catalog-verify CATALOG_PUBLIC_KEY="$keydir/barn-catalog-active-20261126.pub" CATALOG_FILE="$repo/catalog.json"
./packaging/official-sign.sh sign "$repo/catalog.json" "$keydir/official.pem"
./packaging/official-sign.sh verify "$repo/catalog.json"
```

Upload new images to both mirrors and verify their sizes and SHA-256 digests before publishing the same `catalog.json.sig`, `catalog.json.minisig` and `catalog.json` at each repository root. Synchronize the embedded catalog, revision, timestamp and `packaging/image-repository/repo.yaml`, then run `make catalog-check`. On each mirror it verifies both signatures, compares the remote catalog with the embedded bytes and checks every stable image’s length. Use `go run ./tools/catalogcheck -verify-bytes` to stream and hash every stable image on both mirrors.

Once the official CLI draft is ready, run `./packaging/sign-release.sh /absolute/draft "$HOME/.config/barn/signing/official.pem" /absolute/signed`. Upload the resulting `release.json`, `checksums.txt` and `checksums.txt.sig` together to that draft, then verify and publish it with `make release-publish RELEASE_TAG="$tag"`. [Release sequence](../../about/engineering/#release-outputs-and-gates)
