Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 6 additions & 102 deletions .github/workflows/publish-crate.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
name: Prepare or publish reviewed Rust crate
name: Publish reviewed Rust crate

on:
workflow_dispatch:
inputs:
operation:
description: Prepare evidence or explicitly publish reviewed bytes
description: Publish the crates of a verified automatic source release
type: choice
options: [prepare, publish, automatic]
default: prepare
required: true
source_tag:
description: Reviewed published source tag
type: string
default: v2.8.0
options: [automatic]
default: automatic
required: true
source_revision:
description: Exact reviewed source revision
type: string
default: a47537790f5ea8a08adf7e6dffee4fa794cf3665
required: true
source_release_id:
description: Automatic source release ID
type: string
required: false
required: true
manifest_sha256:
description: Exact automatic release manifest digest
type: string
required: false
required: true

permissions:
contents: read
Expand All @@ -39,96 +33,6 @@ concurrency:
cancel-in-progress: false

jobs:
prepare:
if: github.repository == 'atrinik/protocol' && github.repository_id == '1327106950' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.operation == 'prepare'
runs-on: ubuntu-24.04
timeout-minutes: 20
env:
CARGO_HOME: /tmp/atrinik-crate-prepare-cargo
CARGO_TARGET_DIR: /tmp/atrinik-crate-prepare-target
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- run: rustup toolchain install 1.97.1 --profile minimal
- env:
SOURCE_TAG: ${{ inputs.source_tag }}
SOURCE_REVISION: ${{ inputs.source_revision }}
run: |
set -euo pipefail
python3 tools/crate_publication.py prepare --source-tag "$SOURCE_TAG" \
--source-revision "$SOURCE_REVISION" --output "$RUNNER_TEMP/crate-prepared"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: reviewed-crate-inputs
path: |
${{ runner.temp }}/crate-prepared/atrinik-protocol-0.2.0.crate
${{ runner.temp }}/crate-prepared/artifact.json
if-no-files-found: error
retention-days: 7

verify:
if: github.repository == 'atrinik/protocol' && github.repository_id == '1327106950' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.operation == 'publish'
runs-on: ubuntu-24.04
timeout-minutes: 20
outputs:
ready: ${{ steps.verify.outputs.ready_for_upload }}
env:
CARGO_HOME: /tmp/atrinik-crate-verify-cargo
CARGO_TARGET_DIR: /tmp/atrinik-crate-verify-target
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- run: rustup toolchain install 1.97.1 --profile minimal
- id: verify
env:
SOURCE_TAG: ${{ inputs.source_tag }}
SOURCE_REVISION: ${{ inputs.source_revision }}
run: |
set -euo pipefail
python3 tools/crate_publication.py verify-publish --source-tag "$SOURCE_TAG" \
--source-revision "$SOURCE_REVISION" --output "$RUNNER_TEMP/crate-verified"

publish:
needs: verify
if: github.repository == 'atrinik/protocol' && github.repository_id == '1327106950' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.operation == 'publish' && needs.verify.outputs.ready == 'true'
environment: crates-io-release
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- id: verify
env:
SOURCE_TAG: ${{ inputs.source_tag }}
SOURCE_REVISION: ${{ inputs.source_revision }}
run: |
set -euo pipefail
python3 tools/crate_publication.py verify-upload --source-tag "$SOURCE_TAG" \
--source-revision "$SOURCE_REVISION" --output "$RUNNER_TEMP/crate-verified"
- id: auth
if: steps.verify.outputs.ready_for_upload == 'true'
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
- id: upload
if: steps.verify.outputs.ready_for_upload == 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
CRATE_PUBLICATION_OPERATION: publish
run: python3 tools/crate_upload.py --crate "$RUNNER_TEMP/crate-verified/atrinik-protocol-0.2.0.crate"
- if: ${{ !cancelled() && (steps.upload.outcome == 'success' || steps.upload.outcome == 'failure') }}
run: python3 tools/crate_publication.py verify-registry

automatic-verify:
if: github.repository == 'atrinik/protocol' && github.repository_id == '1327106950' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.operation == 'automatic'
runs-on: ubuntu-24.04
Expand Down
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@
semantics and milestone gates. Do not copy M1-M6 schedules into this guide.
- Treat registry publication as an irreversible external operation. Version
`0.1.0` completed the one-use bootstrap; its workflow, secret and token stay
retired. Version 0.2.0 is confirmed in the registry; preserve its separately
pinned manual path and original source/archive lineage as historical evidence. Future reviewed version changes publish automatically through
retired. Version 0.2.0 is confirmed in the registry; its manual publication
path is removed and its source/archive lineage stays pinned in
`policy/crate-release.json` as historical evidence. Reviewed version changes publish only through
Trusted Publishing in the main-only `crates-io-release` environment, without
required reviewers or wait timers. One-time environment/registration setup
remains an owner operation, tracked in `github-settings`.
Expand Down
100 changes: 22 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ Git revision.

## Rust registry publication

Protocol 0.2.0 is published. Future reviewed Cargo version bumps use the
[automatic library release contract](#automatic-rust-library-releases). The
manual procedure below records the original 0.2.0 publication and its pinned
artifact; it does not govern later versions. The manifest allows only crates.io.
Every Cargo version after 0.2.0 is published only through the
[automatic library release contract](#automatic-rust-library-releases); there is
no manual publication operation. The manifest allows only crates.io.

Crate `atrinik-protocol` version `0.1.0` is registered on crates.io with
SHA-256
Expand Down Expand Up @@ -143,82 +142,27 @@ Read [CONTRIBUTING.md](CONTRIBUTING.md) and [PROVENANCE.md](PROVENANCE.md)
before proposing contract material. The cross-repository roadmap is
[atrinik/atrinik#168](https://github.com/atrinik/atrinik/issues/168).

## Reviewed access-token crate candidate
## Historical 0.2.0 publication

Crate 0.2.0 was published by the separately authorized
[publication run](https://github.com/atrinik/protocol/actions/runs/38156755961).
The public API, sparse index and downloaded archive agree on the checksum below.
`policy/rust-crate-candidate.json` retains its historical preparation declaration;
`policy/rust-crate-next.json` marks the reviewed artifact `ready-for-publication`
and pins its prepared source release `v2.8.0`,
revision `a47537790f5ea8a08adf7e6dffee4fa794cf3665`, asset
`atrinik-protocol-0.2.0.crate` and SHA-256
Crate 0.2.0 was published once by a separately authorized manual
[publication run](https://github.com/atrinik/protocol/actions/runs/38156755961)
from source release `v2.8.0`, revision
`a47537790f5ea8a08adf7e6dffee4fa794cf3665`, asset
`atrinik-protocol-0.2.0.crate`, SHA-256
`cda65c3c322993cfab378454fb9b1182df8a000216f4abd1170e53cdfdc3b3bb`.
The approved preparation [run](https://github.com/atrinik/protocol/actions/runs/37225929702)
packaged that clean source twice, and an isolated local reproduction matched.
The immutable published 0.1.0 policy remains unchanged. Later source releases omit these historical registry crates; they cannot
regenerate or replace the prepared bytes. Future reviewed version bumps use
the automatic publication contract below.

## Preparing and publishing the reviewed Rust crate

The manual `publish-crate.yml` workflow has explicit `prepare` and `publish`
operations. Its default is `prepare`, which requests no OIDC token and only emits
an Actions artifact. A preparation approval never authorizes publication. Inputs
for publication must match the exact reviewed tag and revision above. Both
operations run only on main in repository ID 1327106950; checkout uses the fixed
workflow-run revision, while packaging uses the separately pinned source release.
Never package activation HEAD as a substitute for the prepared source.

The one-time publication attached the exact prepared archive to
[v2.8.0](https://github.com/atrinik/protocol/releases/tag/v2.8.0), then verify its
public asset digest. The verifier refuses a missing or mismatched asset; it cannot
substitute an Actions artifact. GitHub reports the source release as mutable, so
repeated tag, provenance and asset-digest checks detect drift rather than claiming
GitHub release immutability. Attaching a new asset also requires a separately
reviewed complete checksum-inventory update; never leave an unchecked extra asset
or silently alter an existing contract/source archive.

A credential-free `verify` job reproduces the pinned source twice and validates
its release asset, public package/owner identity and registry API/sparse-index
state. Missing or conflicting evidence stops before the protected publication
job. An already published identical version is an idempotent success; different
bytes or an indeterminate registry state stop without upload.

The publication job requires `operation=publish`, that successful preflight and
the `crates-io-release` environment. The automatic environment is main-only with zero required reviewers, zero wait
time, and no registry secrets or variables. Reviewed merges and successful
checks authorize each release after one-time owner setup.
Environment and crates.io Trusted Publisher setup are separately authorized owner
operations, tracked in [github-settings#86](https://github.com/atrinik/github-settings/pull/86).
Trusted Publishing binds `atrinik/protocol`, `publish-crate.yml` and that exact
environment. Only this job grants `id-token: write`, which gives every step OIDC
request authority. It never installs a toolchain or runs Cargo, package builds,
proc macros or dependency code. After environment admission, `verify-upload` fetches
the exact public release archive as inert bytes and checks its reviewed digest,
inventory and provenance. It freshly checks the workflow checkout, pinned source
ancestry, public tag/release, complete release inventory, owner and registry state
before token exchange. It writes the same checked archive snapshot for upload.
All reproduction remains in the credential-free jobs; packaging also refuses
OIDC request authority at runtime. Only the upload step receives the short-lived
token from the pinned official action; its post step revokes the token. No long-lived registry credential is allowed.

The bounded uploader verifies the archive snapshot and public state again, then
sends those exact archive bytes using the documented
[Cargo registry publish API](https://doc.rust-lang.org/cargo/reference/registry-web-api.html#publish).
It does not invoke `cargo publish`, which would repackage the source. The request
uses a fixed HTTPS endpoint, refuses redirects, never retries an uncertain write,
and never logs the token or response body. After an attempted upload, the
credential-free verifier checks public package/owner identity and agreement
between the registry API and sparse-index checksum, including when the uploader
fails. It skips cancelled runs and skipped uploads; a matching checksum does not
turn a failed upload step into workflow success. An uncertain result requires
inspection before another separately authorized publication attempt.

The historical 0.2.0 publication is confirmed by the registry evidence above.
Consumers still require the production registry release and normal dependency-lock
validation; source workflow success alone does not establish registry readiness.
See the [official token action](https://github.com/rust-lang/crates-io-auth-action).
`policy/crate-release.json` keeps that coordinate as immutable historical
lineage. The manual `prepare` and `publish` workflow operations and their tooling
have since been removed; later source releases omit the historical registry
crates and cannot regenerate or replace their bytes.

The `crates-io-release` environment is main-only with zero required reviewers,
zero wait time, and no registry secrets or variables. Trusted Publishing binds
`atrinik/protocol`, `publish-crate.yml` and that exact environment; environment
and Trusted Publisher setup are separately authorized owner operations, tracked
in [github-settings#86](https://github.com/atrinik/github-settings/pull/86). The
upload step receives only a short-lived token from the pinned
[official token action](https://github.com/rust-lang/crates-io-auth-action); no
long-lived registry credential is allowed.


## Automatic Rust library releases
Expand Down
12 changes: 0 additions & 12 deletions policy/rust-crate-next.json

This file was deleted.

15 changes: 2 additions & 13 deletions tools/check-crate-release-policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
BOOTSTRAP_CHECK = ROOT / "tools" / "check-crate-publication.py"
SOURCE_WORKFLOW = WORKFLOWS / "release.yml"
EXPECTED_SOURCE_WORKFLOW_SHA256 = "13b592fd367f87ebc8c4926a514f110faadf4804206b8a2fd1e19c57b07d17c9"
EXPECTED_PUBLICATION_WORKFLOW_SHA256 = "e1e02758989a4c8432dbcf8422e440041c7604980bb99fb04c003cfb01524a3b"
EXPECTED_PUBLICATION_WORKFLOW_SHA256 = "b0491b93c39cb1b58e73afff2ac49a9aea8854a53c1de2df04a66ca639ffe58a"
EXPECTED_WORKFLOWS = {
"dependency-review.yml", "pr-title.yml", "release.yml", "validate.yml",
"publish-crate.yml", "crate-release-reconcile.yml",
Expand Down Expand Up @@ -63,7 +63,7 @@ def main() -> None:
expected_candidate = {
"schema_version": 1, "name": release["name"],
"version": workspace_version, "base_published_version": release["version"],
"status": "unpublished", "publication": ("reviewed-manual-publication" if workspace_version == "0.2.0" else "reviewed-automatic-publication"),
"status": "unpublished", "publication": "reviewed-automatic-publication",
}
if candidate != expected_candidate or not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", workspace_version):
raise SystemExit("unpublished crate candidate policy changed")
Expand Down Expand Up @@ -92,17 +92,6 @@ def main() -> None:
if publishing != expected:
raise SystemExit("reviewed Rust registry policy changed")

next_policy = load_json(ROOT / "policy/rust-crate-next.json")
expected_next = {"schema_version": 1, "name": release["name"],
"version": "0.2.0", "status": "ready-for-publication",
"artifact": {
"repository_release": "2.8.0",
"revision": "a47537790f5ea8a08adf7e6dffee4fa794cf3665",
"asset": "atrinik-protocol-0.2.0.crate",
"sha256": "cda65c3c322993cfab378454fb9b1182df8a000216f4abd1170e53cdfdc3b3bb",
}}
if next_policy != expected_next:
raise SystemExit("reviewed next-crate artifact pins changed")
if not PUBLISH_WORKFLOW.is_file():
raise SystemExit("reviewed publication workflow is required")
# Fence the complete reviewed job/step/permission graph, not substrings that
Expand Down
56 changes: 56 additions & 0 deletions tools/crate_archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""Check a packaged crate archive against the reviewed inventory and sources."""
import io
import json
from pathlib import Path
import tarfile
import tomllib

NAME = 'atrinik-protocol'
MAX_BYTES = 16 * 1024 * 1024


def require(condition, message):
if not condition:
raise ValueError(message)


def verify_crate(path, revision, inventory, version):
with (tarfile.open(fileobj=io.BytesIO(path), mode='r:gz') if isinstance(path, bytes) else tarfile.open(path, 'r:gz')) as archive:
members = []
total = 0
for member in archive:
total += member.size
require(len(members) < 256 and total <= MAX_BYTES, 'crate archive exceeds bound')
members.append(member)
prefix = f'{NAME}-{version}/'
names = []
for member in members:
require(member.isfile() and member.name.startswith(prefix), 'unexpected archive member')
name = member.name[len(prefix):]
require(name and '..' not in Path(name).parts and not name.startswith('/'), 'unsafe archive path')
names.append(name)
require(len(names) == len(set(names)) and set(names) == set(inventory), 'crate file inventory mismatch')
def read(name):
return archive.extractfile(prefix + name).read()
vcs = json.loads(read('.cargo_vcs_info.json'))
require(vcs == {'git': {'sha1': revision}, 'path_in_vcs': 'crates/atrinik-protocol'}, 'crate VCS provenance mismatch')
manifest = tomllib.loads(read('Cargo.toml').decode())
package = manifest['package']
require(package['name'] == NAME and package['version'] == version and package.get('publish') == ['crates-io'], 'crate is not the publishable reviewed version')
def no_source_override(value):
if isinstance(value, dict):
require('path' not in value and 'git' not in value, 'unapproved crate dependency source')
for child in value.values():
no_source_override(child)
elif isinstance(value, list):
for child in value:
no_source_override(child)
for key in ('dependencies', 'dev-dependencies', 'build-dependencies', 'target'):
no_source_override(manifest.get(key, {}))
lock = tomllib.loads(read('Cargo.lock').decode())
for package in lock['package']:
if package['name'] == NAME and package['version'] == version:
require('source' not in package, 'unexpected root crate source')
else:
require(package.get('source') == 'registry+https://github.com/rust-lang/crates.io-index', 'unapproved locked dependency source')
Loading
Loading