# Build artifacts and provenance

Source: https://www.orga.bot/docs/build-artifacts

> How CI outputs move between your Mac and remote runners, why every artifact needs a signed grant and attestation, and how releases pin exact outputs.

Every CI output Orgabot handles, whether it was built on your Mac, in a local Docker job, on an enrolled native worker, or on a GitHub-hosted runner, is described by the same **immutable manifest** and travels with the same **provenance**. A consumer anywhere asks the same questions of it, and the answer never depends on a filename.

## What a manifest records

A manifest names the organization, project, target, pipeline run and attempt, the source commit and workflow-definition revision, the OS, architecture and toolchain, the identity that produced it, the content's sha256 digest, size, type, retention and access policy, and the digests of every input it was derived from.

The manifest's identity is the sha256 of its canonical JSON. Change any field and it is a different artifact. The `name` is a label only: two files called `Premail-Setup.exe` with different bytes are two artifacts, and nothing looks one up by name.

There is no update. Signing, notarizing, packaging and publishing each produce a **new** manifest whose input names the digest it came from, so a signed installer's lineage back to the unsigned build is recorded data.

## Artifact types and trust

Outputs are stored in separate namespaces per project, per trust class, and per type:

| Type | What it is |
| --- | --- |
| `cache` | Reusable build state. Never an input to signing, promotion or publishing |
| `test_report` | JUnit XML test output. Becomes verification evidence only after admission, and only when the project's verification policy names its producer as a trusted verifier. The pass or fail outcome and the check names are read from the report itself |
| `unsigned_build` | A build output before signing |
| `signed_release` | A signed or notarized asset |
| `published` | An asset that was published |

The trust class (`untrusted`, `trusted`, `privileged`) is decided by the controller from the observed source before the work is dispatched. Work from a fork is `untrusted`, and an untrusted artifact or any cache is refused for `sign`, `promote` and `publish`, directly or through any input in its provenance chain.

## Provenance: a hash alone proves nothing

A manifest and a matching hash only prove someone can hash. Orgabot requires two signatures:

1. **A dispatch grant**, signed by this Mac's controller key before the work runs. It names the exact run, source commit, workflow revision, the worker dispatched, the platform, the inputs by digest, the allowed output types, the highest trust class, and a time window.
2. **An attestation**, signed by the worker's own enrolled key after the work runs, binding the manifest digest to that grant.

An artifact whose producer was not the dispatched worker, whose inputs were not in the grant, whose trust exceeds the grant or the worker's enrollment, or that was signed outside the window, is refused.

The controller key is created on first use at `~/.orgabot/build-provenance-key.json` with owner-only permissions and never leaves the Mac. Remote targets receive only its public half.

```
orgabot build-artifacts identity show
orgabot build-artifacts identity enroll win-signer --public-key win-signer.pub.pem \
  --org my-org --project premail --platform windows/x64 --max-trust trusted --transform sign
orgabot build-artifacts identity list
orgabot build-artifacts identity revoke win-signer
orgabot build-artifacts identity anchors
```

Workers generate their own key pair; only the public key is enrolled. Re-enrolling an id with a different key is refused. Revoke it and enroll a new id. A revoked worker's attestations are refused from then on.

## The admission gate

Before an artifact is consumed, signed, promoted or published it passes one gate, the same on the controller and on a remote target:

| Refusal | Meaning |
| --- | --- |
| `unsafe_path` | The name is not one safe path segment on every platform |
| `cross_project` | It belongs to another organization or project |
| `unauthorized` | The consumer is not a live enrolled identity named in its access policy |
| `wrong_type`, `wrong_target` | Not the type or target expected |
| `too_large` | Over the size limit |
| `tampered` | The bytes or manifest do not match the requested digest |
| `wrong_platform` | Not the platform expected, or the binary header (PE, ELF, Mach-O, MSI) disagrees with the manifest |
| `stale` | Built from another commit, by a superseded attempt, or too long ago |
| `expired` | Its retention lapsed |
| `unattested`, `forged_grant`, `forged_attestation`, `unknown_identity`, `revoked_identity`, `out_of_scope`, `grant_mismatch`, `trust_exceeds_grant`, `unbound_input`, `outside_grant_window` | The provenance does not verify |
| `untrusted_promotion` | Untrusted work or a cache headed for privileged release work |
| `missing` | For `sign`, `promote` or `publish`: an input in its provenance chain was not supplied. A remote target must be handed every ancestor (manifest, bytes and provenance), and checks each one the same way the controller does |

```
orgabot build-artifacts admit <manifestDigest> --org my-org --project premail \
  --consumer win-signer --purpose sign --type unsigned_build --platform windows/x64 \
  --repo MattSenter/premail --revision <full-sha>
```

## Moving artifacts without a tunnel into the Mac

Nothing connects into your Mac. Both sides connect out to an authenticated store and use short-lived credentials the controller mints. Each credential covers one object, one direction, one project and one expected digest, and lives at most 15 minutes.

```
orgabot build-artifacts staging-key
orgabot build-artifacts stage <manifestDigest> --org my-org --project premail --store <dir> --key-handle secret_...
orgabot build-artifacts fetch <manifestDigest> --org my-org --project premail --store <dir> --key-handle secret_...
```

`staging-key` stores the store's key in your secret store and prints only its handle. Share the store location, never the key.

The commands above use a staging directory both machines can reach, such as a shared drive on your network. A GitHub-hosted runner cannot reach a directory on your network, so the transfer engine also speaks to a cloud bucket over short-lived signed HTTPS URLs: downloads resume with range requests, and uploads use the resumable-upload protocol cloud storage provides. Connecting it to a specific bucket in your cloud account is not yet available as a command; see Known limitations below.

Outputs a GitHub-hosted runner uploaded as an Actions artifact are pulled through the governed GitHub App identity:

```
orgabot build-artifacts import-github MattSenter/premail <runId> --org my-org --project premail
```

The runner packs outputs as a bundle whose entries are `artifacts/<manifestDigest>/manifest.json`, `provenance.json` and `content`. The directory must match the manifest's own digest, and any other entry refuses the whole bundle. Zip entries that traverse, are absolute, are encrypted, fail their CRC, or expand past the size limit are refused.

### Interrupted and expired transfers

A transfer writes to a partial file and resumes from the bytes already on disk, including after the process is killed. An expired credential is re-minted and the transfer continues from where it stopped. A transient failure is retried at the same offset. The finished file is hashed, and a mismatch deletes it. Only a verified file can be ingested, and only an ingested, attested artifact can join a release, so an interrupted or swapped download never becomes part of a release.

Signed transfer URLs and credentials are never logged. Every transfer message is scrubbed of the credential value and of every URL query string.

The egress cap is policy, not a flag. It is the `artifactEgressBytes` setting in your CI policy, resolved organization, then project, then target, and never above the organization's `maxArtifactEgressBytes` ceiling. It caps the bytes a project may transfer in a 30-day window. A transfer that reaches the cap stops with its partial intact and resumes when the window allows. `--egress-limit-bytes` can only lower the cap for one command, never raise it.

## Outputs from local runs

A target in `scripts/ci/targets.json` can declare the files it produces with an `outputs` list (a name, a path inside the repository, and a type of `cache`, `test_report` or `unsigned_build`). `scripts/ci/run.mjs` checks a declared file after the step passes: a required output that is missing fails the step, and a symlink is refused. It records each file's size and SHA-256 in the result. Then attest and store them:

```
orgabot build-artifacts record-run .orgabot-run/ci/<result>.json --org my-org --project premail --repo MattSenter/premail
```

A file that changed between the run and this command is refused, and so is a result whose commit is not the commit checked out in `--root`. The result file is plain JSON that this command did not produce, so its outputs are stored as untrusted. Add `--trust trusted` only when you can vouch for the run that wrote it.

## Releases pin exact outputs

```
orgabot build-artifacts release create v1-4-0 --org my-org --project premail --repo MattSenter/premail --revision <full-sha>
orgabot build-artifacts release add v1-4-0 windows-installer <signedDigest> --org my-org --project premail --type signed_release --platform windows/x64
orgabot build-artifacts release seal v1-4-0 --org my-org --project premail
orgabot build-artifacts release verify v1-4-0 --org my-org --project premail
```

A release belongs to one source commit. Adding an output runs the full gate for `promote` against that commit and walks its whole provenance chain. Each dependency records its manifest digest, content digest, platform, producer, grant, every digest in its chain, and, for a signed asset, the unsigned input it was derived from. A role, once bound to a digest, is never rebound to another.

Sealing re-checks every dependency and signs the record with the controller key. A sealed release is immutable, and `release verify` re-checks the seal and every byte later, so an output altered on disk after sealing shows up as a problem.

## Publishing and deploying a release

A product release policy lists every asset a release must carry before it ships, and which ones must be signed or notarized:

```json
{
  "product": "premail",
  "requiredAssets": [
    { "role": "windows-installer", "platform": { "os": "windows", "arch": "x64" }, "signature": true },
    { "role": "macos-app", "platform": { "os": "macos", "arch": "arm64" }, "notarization": true }
  ],
  "updater": { "format": "tauri_updater_json", "feedUrl": "https://updates.example.com/updater.json", "appId": "com.example.app" }
}
```

```
orgabot build-artifacts release check v1-4-0 --org my-org --project premail --policy premail-release.json
orgabot build-artifacts release seal v1-4-0 --org my-org --project premail --policy premail-release.json
```

`release check` lists each required asset as present, absent, unsigned, not notarized, or the wrong platform. With `--policy`, `release seal` refuses an incomplete release and leaves it open. A missing Windows installer therefore blocks the release without losing anything: the macOS output and the unsigned Windows build stay pinned in the open release, and the signer run that was missing completes the same release. A partial release ships only when the policy has a `partialRelease` entry naming the optional roles, and only for an asset that is absent. An unsigned asset never counts.

A promotion delivers the sealed release by digest, never by branch name, so nothing is rebuilt on the way out. Before anything changes, the promotion checks that:

- the release is sealed and still verifies;
- every required asset is present and signed;
- the destination writes the same updater format, feed URL, app id and update-signing key as before;
- an approver listed on the destination's environment approved this exact release digest. The identity doing the delivery cannot approve its own delivery;
- the release came from a ref the environment accepts, such as `v*`;
- a production destination with a rollback path has a passing rollback test on record.

Each delivery holds a lease on its destination and on its release. A second controller, a re-run workflow, or a duplicate tag event for the same release does not publish twice: it reports that the release is already delivered or still in flight. When a destination's response is lost, or a run is canceled before it confirms anything, the delivery is recorded as `outcome_unknown`. It is not retried on that destination or any fallback until Orgabot can prove what happened. Proof is either a lookup that finds the operation, or a destination that can show the operation never arrived. If neither is available, you record the evidence yourself:

```
orgabot build-artifacts release deliveries --org my-org --project premail
orgabot build-artifacts release resolve '<deliveryKey>' 1 not_happened --evidence "releases page shows no v1.4.0 assets"
orgabot build-artifacts release rollback-test github-release ok --evidence "re-pointed updater.json at v1.3.9 and back on staging"
```

To promote, describe the destination: the workflow that publishes it, what it changes, its environment, and the updater it writes. The workflow receives the release id, the release digest, the source revision and every asset digest as inputs.

```json
{
  "id": "github-release",
  "workflow": "MattSenter/premail:publish.yml@main",
  "sideEffects": ["release_publish", "updater_metadata"],
  "production": true,
  "environment": "production",
  "updater": { "format": "tauri_updater_json", "feedUrl": "https://updates.example.com/updater.json", "appId": "com.example.app" }
}
```

```
orgabot build-artifacts release promote v1-4-0 --org my-org --project premail --policy premail-release.json --destination github-release.json --controls premail-controls.json --source-ref refs/tags/v1.4.0 --request-approval
orgabot build-artifacts release promote v1-4-0 --org my-org --project premail --policy premail-release.json --destination github-release.json --controls premail-controls.json --source-ref refs/tags/v1.4.0 --approval apr_1234abcd
orgabot build-artifacts release promote v1-4-0 --org my-org --project premail --policy premail-release.json --destination github-release.json --shadow
```

The approval is read from Orgabot's approval store. It counts only when it was approved, has not been used up, and names this exact release digest, destination and environment. The approver is whoever decided it.

A failed rollback test blocks production promotion until a later test passes. An asset that has been published, or may have been, is never re-signed in place. Cut a new release instead.

A side-effecting job inside a pipeline that names its release and destination takes the same two leases before it runs, and holds them until it settles. An in-pipeline deployment and a release delivery of the same destination or release therefore wait for each other instead of racing; the job reports itself blocked, not failed. Once a release has been published, signing admission refuses its bytes, so a published asset is never re-signed in place; cut a new release instead.

A rollback restores the release that was on a destination before the current one, by delivering that release's original digests again. Nothing is rebuilt or re-signed. It needs a rollback path in the controls, takes the same leases and approval gate as a delivery, and is not held by a failed rollback test, since it is the recovery. A preview teardown removes a preview deployment under the same leases, only on a destination that is not production and only where the controls declare a teardown.

A destination that builds from source itself, such as Firebase App Hosting, is reported as external compute. `release deliveries` shows the provider's build and the exact revision it built. A build of any other revision leaves the delivery `outcome_unknown` instead of delivered.

A shadow run validates without publishing. In a shadow pipeline, build and test jobs run as usual, and every signing, publish, deploy or promotion job is skipped with the reason shown. A shadow delivery never counts as a production one.

## Retention, cleanup and diagnosis

Retention is set when an output is produced. The number of days is the `artifactRetentionDays` setting in your CI policy (90 by default, never above the organization's `maxArtifactRetentionDays`), and `release` outputs do not lapse. Anything a release references, and every input in its chain, is kept while the release exists.

```
orgabot build-artifacts gc --dry-run
orgabot build-artifacts gc
orgabot build-artifacts diagnose <manifestDigest> --org my-org --project premail
```

Cleanup leaves a record behind, so `diagnose` can say an artifact was collected, and when and why, rather than just "missing". It also distinguishes never stored, stored in another project, bytes gone, expired, and refused. A GitHub artifact past its GitHub retention is reported as expired at GitHub. Each project's storage budget is its `artifactStorageBytes` policy setting (never above `maxArtifactStorageBytes`); `--storage-budget-bytes` can only lower it. When pinned content alone exceeds the storage budget, cleanup reports the project as over budget rather than deleting a pin.

## Known limitations

- **No command binds a cloud bucket yet.** The signed-URL bucket backend is built and tested against a real HTTP server, but there is no `orgabot` command that connects it to a bucket in your account. Until there is, `stage` and `fetch` use a shared staging directory.
- **`release promote` drives a GitHub Actions workflow, optionally with App Hosting.** Add `"type": "app_hosting"` plus `firebaseProject`, `location` and `backend` to the destination file and the workflow becomes the trigger: Orgabot then watches the App Hosting build for the exact revision with the read-only Firebase credential (`GOOGLE_APPLICATION_CREDENTIALS` or `FIREBASE_ACCESS_TOKEN`) and reports it as external compute. An app store submission, rollback and preview teardown exist as delivery operations inside Orgabot but have no command of their own yet. Each project's own destinations are connected when that project moves onto the provider-neutral pipeline. Until then, its existing release workflow still publishes it.
- **A real Windows signer is not connected.** The signing flow is built and tested with test keys, but no production signing identity is enrolled, so no Windows installer is signed for release until you enroll one.
- **Outputs from a run on a real remote Windows runner have not been observed.** The local, local Docker, native worker and GitHub Actions adapters all record their outputs through these manifests and grants, and every job that names an artifact is checked by the admission gate before it starts. A live run on a GitHub-hosted Windows runner still needs a provisioned bucket and a dispatch identity with `actions:write`.
