Skip to content

release: attach-qualification keeps a qualified run's evidence on its release (060 3.7.3, tooling) - #487

Merged
bartekus merged 1 commit into
mainfrom
impl/060-qualify-assets
Nov 4, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/060-qualify-assets

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Spec 060 increment 2a (3.7.3, tooling): rustev-release attach-qualification <tag> <assets-dir> attaches a qualified run's record and per-platform evidence bundles to the tag's GitHub release.

  • tagged::attach_qualification (through the new prerelease::AssetUploads trait, implemented by Gh with gh release upload and no --clobber) requires exactly qualification-vX.Y.Z.json plus one qualification-vX.Y.Z-<platform>.tar.gz per platform of the release matrix, a rustev.qualification-record/1 record of that tag in state qualified, gzip bundles, and a present non-pre-release. Every check runs before the first upload.
  • Only names not present are uploaded. A present name with the same bytes is reported present; with other bytes it is kept and a warning printed. A failed upload fails the command; a rerun uploads only what is missing.
  • The qualify.yml change that runs the command follows in its own pull request.

Stacked on release/bump-0.4.0 (#480).

Review round 2: the workflow-permission tests moved to #489, the PR that changes qualify.yml and release.yml's qualify call, so each assertion lands with the change that makes it true. This PR is tooling only.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security problems, and inconsistencies.

attach_qualification implementation (tagged.rs) — The logic is well-structured. Asset name set validation correctly compares sorted keys from the BTreeMap against sorted expected names. The gzip magic byte check, schema/tag/version validation, and the pre-upload-then-upload ordering all look correct. The idempotent resume behavior (upload only missing names) is correctly tested.

Gh::upload_asset (prerelease.rs) — The gh release upload invocation omits --clobber, matching the spec requirement that a present name is refused. The command construction and error propagation look correct.

main.rs dispatch — The new attach-qualification arm reads all files from the directory before calling attach_qualification, which performs all validation before any upload. Correct.

release_workflow.rs test additions — qualify_reads_and_only_attach_may_write_contents asserts exact top-level permissions in qualify.yml that the test expects to be ["contents: read", "attestations: read"] in that order. qualify.yml is not changed in this PR; the spec text explicitly states the qualify.yml change follows in a separate pull request. If the current qualify.yml does not already carry exactly contents: read and attestations: read (in that order, nothing else) in its top-level permissions: block, the assert_eq! will fail in CI and block this PR. The test is asserting a post-condition of a file this PR does not deliver.

The other structural changes in release_workflow.rs (the qualify-job carve-out in only_github_release_writes_contents_and_nothing_writes_packages) are logically sound as written.

{"head": "d8e4f211e6ab782b19f53fda1073e4c7baac5264", "verdict": "findings", "findings": [{"path": "tools/rustev-release/tests/release_workflow.rs", "line": 185, "summary": "The new test asserts exact ordered top-level permissions ([\"contents: read\", \"attestations: read\"]) for qualify.yml, a file this PR does not modify; if the current qualify.yml does not already carry exactly those two entries in that order the assert_eq! fails in CI."}]}

Subject: e3f6b9a...d8e4f21, diff digest 95141c3838828edae7b639004b6154451098b9e3a29541e404a4bac529812e57, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security defects, and inconsistencies in the new attach-qualification subcommand (spec 060 §3.7.3).

prerelease.rs – AssetUploads and Gh::upload_asset

Argument injection: tag, name, and path are all passed as separate .arg() / .args() items, not interpolated into a shell string — no injection risk. name is validated against qualification_asset_names before upload_asset is ever called, so path-traversal via scratch.join(name) is not reachable in practice.

tagged.rs – attach_qualification

Asset-set comparison: given is from BTreeMap::keys() (already sorted); wanted is sorted before comparison. Element-wise equality on two sorted slices correctly checks set equality — no gap.

Index 0 access: names[0] is always the JSON file by construction in qualification_asset_names (the iterator prepends the JSON before the platform tarballs). assets[&names[0]] is a keyed lookup, not positional, so sorting wanted for the equality check doesn't affect the subsequent deserialization. Correct.

Pre-upload validation order: schema, tag, version, state, and gzip-magic checks all run before api.lookup and before any upload_asset call — consistent with the spec requirement that every check precedes the first upload.

tests/tagged.rs

The Attach mock panics (assert!(...is_none(), "{name} replaced")) if upload_asset is called for an already-present name — correctly enforces the no-clobber contract in tests. The resume scenario (fail on names[3], rerun) is correctly modelled: on rerun the first three names return Present and the rest are uploaded.

tests/release_workflow.rs

qualify_reads_and_only_attach_may_write_contents splits on \npermissions:\n and then \n\n and calls .unwrap() on both. If qualify.yml currently lacks a top-level permissions: block (or lacks a trailing blank line after it), the test panics at runtime under make code, which is part of the required ci-gate check. The spec explicitly defers the qualify.yml changes to a companion PR, so the current file may not yet match the expected layout. This creates a concrete risk of a test panic blocking ci-gate on this PR.

tests/candidate.rs – workflow_write_permissions_are_confined

The assertion now allows writes == ["github-release", "qualify"]. This relies on the order jobs appear in release.yml; if qualify precedes github-release in the file the assertion fails. This is a pre-existing fragility in the test pattern, not newly introduced by this PR.

No other concrete defects were found in the core logic.

{"head": "07a048c834116cb207735783eb49171417316e94", "verdict": "findings", "findings": [{"path": "tools/rustev-release/tests/release_workflow.rs", "line": 183, "summary": "qualify_reads_and_only_attach_may_write_contents calls .unwrap() on a text parse of qualify.yml that expects a top-level permissions block followed by a blank line; since the companion PR that adds the attach job has not landed, qualify.yml may not yet match this format, causing a panic that fails ci-gate."}]}

Subject: e3f6b9a...07a048c, diff digest 1cd00e541d6c532788c0e1e0c19dea47728759e0b42c7781312fe7d58457045c, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 3, 2026 21:58 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/060-qualify-assets branch from 07a048c to 0fbcf1e Compare November 3, 2026 23:16
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for correctness, security, and consistency with spec 060 and the governance rules.

tools/rustev-release/src/tagged.rs — attach_qualification

The asset-name set check:

let given: Vec<&String> = assets.keys().collect();
let mut wanted: Vec<&String> = names.iter().collect();
wanted.sort();
if given != wanted {

wanted is sorted but given is left as-is from assets.keys(). This is correct only if Assets is a BTreeMap (whose iterator is already sorted). The tests exercise the success path with unwrap(), which would fail if Assets were a HashMap, confirming Assets is sorted. The asymmetric sort is intentional and correct.

names[0] and names[1..] always reference the original (unsorted) names vector — the JSON record is at index 0, platform bundles at 1.. — not the sorted wanted slice. Field accesses and gzip checks are therefore on the right assets.

tools/rustev-release/src/prerelease.rs — Gh::upload_asset

The temp directory returned by fresh_dir goes out of scope after output() returns (synchronous), so cleanup happens after gh has finished reading the file. No early-cleanup race.

No --clobber is intentional and consistent with the spec's "never replace" guarantee. The gh invocation uses Command::args, so no shell injection risk from tag or name values. name comes from qualification_asset_names (computed) or entry.file_name() (kernel-validated filename component) in the command path, so path traversal via scratch.join(name) is not reachable.

tools/rustev-release/src/main.rs — attach_qualification_cmd

std::fs::read_dir does not yield ./... If the directory contains an unexpected subdirectory, std::fs::read on it fails before attach_qualification is called, so the "must be exactly" check is never reached and the error message is less clear than ideal. Not a correctness defect: the command still exits with an error.

Tests (tools/rustev-release/tests/tagged.rs)

The Attach fake correctly enforces the "no clobber" rule with assert!(release.assets.insert(...).is_none(), "{name} replaced"). The resume test (failing on names[3], then rerunning) exercises both the partial-upload and idempotent-rerun paths. Each refusal is verified against an empty gh.uploads, confirming pre-flight checks run before any upload.

Spec text

Increment 2a text matches the implementation: exact-name check, schema/tag/version/state validation, gzip magic check, all before any upload; PresentOther warning only; no clobber; rerun uploads only missing names.

No defects found.

{"head": "0fbcf1e6e3925f2c00c191573efcc85a608b8999", "verdict": "no-findings", "findings": []}

Subject: e3f6b9a...0fbcf1e, diff digest 81c41dbfac7a138394b297c29937b5a6c68321e68c46ed74e607ddec1ded1c44, 1 call(s). An AI comment is not an approval.

Base automatically changed from release/bump-0.4.0 to main November 4, 2026 00:26
@bartekus
bartekus force-pushed the impl/060-qualify-assets branch from 0fbcf1e to eea7676 Compare November 4, 2026 00:31
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff across all five changed files for bugs, security issues, and inconsistencies.

tools/rustev-release/src/tagged.rs — attach_qualification

The pre-upload validation sequence is correct: candidate check → exact names check → record schema/tag/version/state check → gzip magic check → release lookup (not pre-release, present) — all before any upload. The spec requirement "every check runs before any upload" is satisfied.

The given != wanted comparison: assets.keys() on a BTreeMap yields keys in lexicographic order, so given is already sorted. wanted is sorted explicitly. Both end up in the same lexicographic order (note - < ., so platform .tar.gz names sort before the .json name, consistently in both). The element-wise String comparison is correct.

The PresentOther path skips the upload entirely; gh release upload without --clobber is the defence-in-depth layer for concurrent runs, not the primary guard. This matches the spec.

The present snapshot is taken once before the loop. Names already in present are never re-uploaded. After a partial failure a rerun re-reads api.lookup(tag) and skips already-present names. Correct.

tools/rustev-release/src/prerelease.rs — Gh::upload_asset

name reaches scratch.join(name) after attach_qualification has already verified it is one of the expected qualification_asset_names values, so no path-traversal risk in practice. Command::args() is used throughout; no shell injection path exists.

tools/rustev-release/src/main.rs — attach_qualification_cmd

std::fs::read_dir is iterated without filtering for regular files. If the caller passes a directory that contains a subdirectory entry, std::fs::read(entry.path()) will return an OS error ("Is a directory") rather than the clearer "assets must be exactly …" message from attach_qualification. This surfaces as a confusing I/O error rather than a correctness failure, and the subsequent validation in attach_qualification would catch any name-set mismatch anyway, but the error message is misleading. This is a minor robustness issue, not a correctness or security defect on the documented happy path.

tools/rustev-release/tests/tagged.rs

The Attach test double updates self.present.assets on each successful upload_asset, so the second call to attach_qualification (the resume run) sees the updated asset map. The assertions on gh.uploads.len() and the PresentOther detection are correct. Each refused() invocation receives a fresh published_release(), so gh.uploads.is_empty() is always a valid starting assertion.

specs/060-the-service-image-in-the-release/spec.md

The increment 2a description is internally consistent with the implementation; spec text in the PR diff is review data only.

No concrete defect found in correctness, security, or spec conformance.

{"head": "eea767603ba27fc437dee6d774335b982a71addd", "verdict": "no-findings", "findings": []}

Subject: 983b4ac...eea7676, diff digest 81c41dbfac7a138394b297c29937b5a6c68321e68c46ed74e607ddec1ded1c44, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 4, 2026
…evidence on its release (060 3.7.3, tooling)
@bartekus
bartekus force-pushed the impl/060-qualify-assets branch from eea7676 to ede2d79 Compare November 4, 2026 02:38
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff, which adds attach-qualification to rustev-release via attach_qualification in tagged.rs, the AssetUploads trait and its Gh impl in prerelease.rs, the CLI dispatch in main.rs, and two new tests in tests/tagged.rs.

Logic and correctness

The pre-upload validation sequence is correct: tag is not a release-candidate, the name set matches exactly qualification_asset_names, the JSON record parses and matches the tag/version/state, all bundles carry the gzip magic bytes, and the release exists and is not a pre-release — all before the first upload_asset call. The resume path is also correct: present is fetched once at the start of the function, and only names absent from that snapshot are uploaded.

Name-set comparison

let given: Vec<&String> = assets.keys().collect();
let mut wanted: Vec<&String> = names.iter().collect();
wanted.sort();
if given != wanted {

This sorts wanted but not given, relying on Assets being a BTreeMap whose keys() iterator already yields in ascending order. This assumption holds for the current type and the test confirms it, but the asymmetric sort is a latent fragility. It is not a bug given the evidence.

Gh::upload_asset — scratch directory

let scratch = crate::repro::fresh_dir("rustev-attach")?;
let path = scratch.join(name);
std::fs::write(&path, bytes)...

fresh_dir is imported separately from Scratch in the test file (use rustev_release::repro::{Scratch, fresh_dir}), which suggests the two are distinct types and fresh_dir may return a bare PathBuf rather than a RAII guard. If so, each call to upload_asset (once per platform asset) leaves a temporary directory behind. For N platforms this is N leaked directories per attach-qualification invocation. Not a security issue in this CI context, but a resource leak on each upload.

Path traversal in upload_asset

The name received by upload_asset in all call paths is either (a) generated by qualification_asset_names (a fixed prefix + tag + platform pattern) or (b) validated against that set before upload_asset is called. entry.file_name() in the CLI layer strips directory separators. No traversal risk.

Gzip check

Only 2 magic bytes [0x1f, 0x8b] are checked. The spec says "every bundle a gzip stream"; 2-byte magic is a reasonable minimal gate for this guard-before-upload check.

Test coverage

Both named tests (qualification_evidence_is_attached_once_and_never_replaced, qualification_evidence_is_refused_before_any_upload) cover the resume path, the idempotent second upload, the PresentOther variant, and each pre-upload refusal (wrong state, wrong tag's record, missing/extra file, non-gzip bundle, candidate tag, missing release, pre-release). Coverage is thorough.

Spec doc

The increment is recorded under the correct heading and refers to the correct test names and function names. The ratification note is already present from a prior entry.

No correctness bugs or security defects are supported by the supplied evidence. The scratch-leak in Gh::upload_asset is the only concrete concern, and it hinges on fresh_dir's return type, which is not visible in the diff.

{"head": "ede2d797004379f7223fbca06ecf4ebcd73a6696", "verdict": "no-findings", "findings": []}

Subject: adcaa4c...ede2d79, diff digest 78f50bef4f366f7a2a886792e647eb73357d00c4f73049ca85a044f6cb237ea1, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 4, 2026
@bartekus
bartekus removed this pull request from the merge queue due to a manual request Nov 4, 2026
@bartekus
bartekus added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit c2389cd Nov 4, 2026
38 checks passed
@bartekus
bartekus deleted the impl/060-qualify-assets branch November 4, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

statecraft:stacked-ci Run the full CI matrix on a stacked pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant