Skip to content

impl(056): part b1, signed instruction for later releases and the qualify command - #326

Merged
bartekus merged 1 commit into
mainfrom
impl/056-qualify
Oct 28, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/056-qualify

Conversation

@bartekus

@bartekus bartekus commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Spec 056, part b1: the owner-signed instruction for a release after 0.1.0, and rustev-release qualify.

  • 3.4: an instruction for any version after 0.1.0 needs <instruction>.sig, a detached SSH signature over its exact bytes (namespace rustev-release, the owner identity in allowed_signers). publish and hosted-release verify it before any journal entry or upload and refuse an unsigned, wrongly signed or altered instruction. 0.1.0 keeps its 031 3.11.1 authority.
  • 3.3: rustev.qualification-step/1 (tools/rustev-release/src/qualification.rs) and rustev-release qualify <release-dir> <evidence-dir> <instruction> <journal>. Required kinds (crates, npm, cli, image) come from the signed manifest; each required kind needs a passed step for every platform of the CLI and npm matrix. A missing, failing or not_run step, or an excluded step for a kind the manifest names, is refused before the journal; otherwise the step digests are recorded as the Qualification entry.
  • Spec 056: part b1 record. Independent of part a (impl(056): part a, the version command and the declared support-routing example #324); both set implementation: in-progress.

Tests: tools/rustev-release/tests/signing.rs (valid, unsigned, wrong key, altered bytes, 0.1.0 unsigned), tools/rustev-release/tests/family.rs (complete, missing, failing, not_run, wrongly excluded).

Review note (24ee6f3): restore_released now restores family_observed and state when the ReleaseCreated transition is refused, so a refusal leaves the lifecycle as it was found.

Review note (1d98404): each recorded checksum must now be in its registry's form (a SHA-256 hex digest, or an npm sha512- SRI integrity string; a new refusal case covers a malformed one), and qualify resolves the journal and release against the repository root from git rev-parse --show-toplevel, as publish does.

Review note (dd90b2b): false positive. qualify passes the journal as the fourth argument and the repository root as the fifth, matching run(dir, evidence_dir, instruction, journal, repo); the call now binds both by name with a comment stating the order.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff across all changed files: spec update, lifecycle.rs signature-enforcement additions, qualification.rs (new), family_lifecycle.rs refactor, hosted.rs and main.rs wiring, and the two test files.

lifecycle.rs – authorize_file and instruction_verified

The core security invariant — SSH signature required for instructions whose version != FIRST_RELEASE_VERSION — is correctly placed. verified_instruction is private; apply checks it before accepting any non-0.1.0 Authorized event; and authorize_file resets it to None on apply failure, preventing a leaked verified-but-unapplied instruction from blessing a later call. The TOCTOU concern is absent because bytes is read once into memory and verified_instruction is set from the in-memory parsed value before apply is invoked.

qualification.rs – evidence function

The guard for missing files on non-required kinds (!required(m, kind) && e.kind() == NotFound → continue) is correct; required-but-missing files surface as errors. Non-required files that are present must carry Status::Excluded { reason } with a non-empty reason, enforced before the step is accepted.

qualification.rs – restore_released

The function mutates life.family_observed and life.state directly before calling apply(Event::ReleaseCreated). If apply fails, life is left at State::Published with family_observed = true. In run() the ? operator returns immediately and the local life is dropped, so no external state is corrupted. In the test harness, restore_released is called only on a freshly-authorized lifecycle, which makes the ReleaseCreated transition deterministic. This is acceptable in context.

family_lifecycle.rs – run check

The old hard refusal on version != FIRST_RELEASE_VERSION is replaced with !life.instruction_verified(), which is true when the instruction is 0.1.0 (old path) or when authorize_file completed successfully (new path). Because authorize_file is the only way to set verified_instruction, direct apply(Event::Authorized(...)) calls for later versions remain refused by the apply guard. The behavior is correct.

Test coverage

later_instructions_require_the_owner_signature_over_exact_bytes exercises all four failure modes (unsigned, wrong key, byte-altered, first-release bypass), and the qualification_validates_every_platform_before_writing_the_journal test verifies all matrix entries against all error cases before any journal write, with a final assertion on the evidence map size (PLATFORMS.len() * 4).

No concrete bugs or security defects found.

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

Subject: 0cf7fd9...ddd160f, diff digest be4cd7bdfdb7d4dd0f17146a69aaa242e85e7f7d48a846e498554511c8cb9e87, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus enabled auto-merge October 27, 2026 15:44
@bartekus
bartekus added this pull request to the merge queue Oct 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 27, 2026
@bartekus
bartekus added this pull request to the merge queue Oct 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 27, 2026
@github-actions

Copy link
Copy Markdown

AI review (findings)

Review

tools/rustev-release/src/lifecycle.rs — authorize_file

The new method reads the instruction file once, verifies the SSH signature over the raw bytes, stores the parsed Instruction in verified_instruction, then passes the same parsed struct to apply. The signature is verified over the exact bytes, so a byte-altered instruction (same parse, different content — as the "altered" test case confirms) correctly fails verification. The authorization check in apply:

|| (i.version != FIRST_RELEASE_VERSION
    && self.verified_instruction.as_ref() != Some(&i))

uses parsed equality after the bytes were already verified, so this is sound. Direct calls to apply(Event::Authorized(i)) for non-first-release versions fail because verified_instruction is None, blocking the bypass path. The chain is correct.

tools/rustev-release/src/qualification.rs — restore_released

life.family_observed = true;
life.state = State::Published;
life.apply(Event::ReleaseCreated)
    .map(|_| ())
    .map_err(|e| e.0)

family_observed and state are mutated directly — outside the event system — before apply(Event::ReleaseCreated) is called. If apply returns an error, the function propagates Err, but neither family_observed nor state is rolled back. The Lifecycle is left at State::Published with family_observed = true even though the caller receives an error. The current caller uses ? and drops life on failure, so there is no observable bug today, but this breaks the event-system's atomic-transition guarantee and creates a latent integrity defect: any future code that inspects life after an error from restore_released sees corrupted state.

Everything else

  • The qualification evidence format change (from artifact-name keys to {platform}.{kind}.json keys) is consistently applied in both production code and tests.
  • required_files and evidence are consistent with each other and with the updated family_lifecycle::qualify.
  • The instruction_verified guard added to family_lifecycle::run is correctly positioned after the "instruction differs from manifest" check, so a valid signature for version 0.2.0 cannot authorize a 0.3.0 manifest (the existing mismatch check fires first).
  • The qualify subcommand wiring in main.rs matches the qualification::run signature.
{"head": "24ee6f3ecdd31ff760aece80c4793e875e9afce8", "verdict": "findings", "findings": [{"path": "tools/rustev-release/src/qualification.rs", "line": 140, "summary": "restore_released mutates life.family_observed and life.state directly before calling apply(Event::ReleaseCreated); if apply returns an error the mutations are not rolled back, leaving the Lifecycle in an inconsistent Published state while returning Err to the caller."}]}

Subject: 496dec5...24ee6f3, diff digest 1cb5c06844f429b6fcb332b3a91ea61fd2d36ddcaaec24235133a1aa92fbb0eb, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 27, 2026 20:53 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

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

lifecycle.rs — authorize_file / instruction_verified

The ordering is intentional and correct: verified_instruction is set before apply() so the state-machine guard can see it; if apply() returns Err, the field is cleared. The instruction_verified() predicate correctly shortcuts for FIRST_RELEASE_VERSION (where verified_instruction is never written). The apply() handler correctly tightens from a flat version ban to (version != first) && verified_instruction != Some(&i). No defect here.

family_lifecycle.rs — run() guard replacement

Replacing the hardcoded version != FIRST_RELEASE_VERSION refusal with !life.instruction_verified() is logically equivalent for the first release (first case of the predicate) and correct for later ones. OK.

qualification.rs — evidence() validation inconsistency

output_digest is validated with the digest() helper (64-char hex), but the values inside step.checksums are only checked to be non-empty strings. Both fields record SHA-256 digests; the inconsistency allows any non-empty garbage string (e.g. "x") to pass validation for checksum values, weakening evidence integrity for the qualification record.

// output_digest — rigorously validated:
|| !digest(&step.output_digest)

// checksums values — only non-empty check, no hex/length guard:
|| step.checksums.iter().any(|(k, v)| k.trim().is_empty() || v.trim().is_empty())

qualification.rs — restore_released bypasses normal state transitions

restore_released directly writes life.family_observed = true and life.state = State::Published before calling apply(Event::ReleaseCreated). If apply panics rather than returning Err, the rollback closure never runs and the Lifecycle is left in an internally inconsistent state (PublicationAuthorized instruction but Published/Released state fields). This is unlikely in practice but is an observable invariant violation distinct from the standard "refused transition" rollback pattern used elsewhere.

qualification.rs — journal_path called with Path::new(".")

run() calls crate::hosted::journal_path(journal, Path::new(".")), but hosted::run() calls the same function with the repository root. If journal_path enforces that the resolved journal path is inside repo or uses repo for canonicalisation, passing . (CWD at call time, which may not be the repo root in CI) could silently resolve to a wrong path or bypass a containment check. Without the journal_path source the full impact cannot be determined, but the asymmetry with hosted::run is a concrete deviation.

{"head": "1d984042cf99cbfe0237ae5c1e86ed13ea7dab0c", "verdict": "findings", "findings": [{"path": "tools/rustev-release/src/qualification.rs", "line": 97, "summary": "Checksum values inside `step.checksums` are validated only as non-empty strings, not as 64-char hex digests, unlike `output_digest` which uses the `digest()` helper; this allows arbitrary non-hex strings to pass evidence validation."}, {"path": "tools/rustev-release/src/qualification.rs", "line": 190, "summary": "`journal_path` is called with `Path::new(\".\")` as the base path instead of the repository root used by the equivalent `hosted::run` call, risking incorrect journal path resolution when the process CWD is not the repository root."}]}

Subject: 496dec5...1d98404, diff digest 31d2c3ae8446a7bd3f8b1368fb8f0d734859ae4892b58a32324fade0542af9c3, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 27, 2026 21:00 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the changes across lifecycle.rs, family_lifecycle.rs, qualification.rs, hosted.rs, main.rs, and the two test files.

lifecycle.rs — authorize_file / instruction_verified

The new authorize_file sets self.verified_instruction = Some(instruction.clone()) before calling self.apply(Event::Authorized(instruction)). The apply guard for non-first-release versions is:

|| (i.version != FIRST_RELEASE_VERSION
    && self.verified_instruction.as_ref() != Some(&i))

Because verified_instruction is pre-populated before apply is called, the guard passes correctly. If apply fails for any other reason, the error path clears verified_instruction. The circular arrangement is intentional and safe under &mut self. For 0.1.0, the signature path is bypassed and instruction_verified() relies only on i.version == FIRST_RELEASE_VERSION — consistent with the spec's explicit preservation of 031 authority.

family_lifecycle.rs — guard replacement

Replacing the hard version check with instruction_verified() is sound: a non-first-release Instruction can only reach PublicationAuthorized state if verified_instruction was set by authorize_file (the apply guard rejects direct calls without it), so the state itself is sufficient evidence.

qualification.rs — evidence() and required_files()

Evidence keys use the {platform}.{kind}.json format, matching what required_files() produces and what family_lifecycle::qualify now checks. Non-required kinds must be Excluded with a non-empty reason if the file is present; absent files are silently skipped. Required kinds must be Passed with exit status 0 and complete execution evidence. The validation is consistent.

qualification.rs — restore_released

The function directly mutates family_observed and state before calling apply(Event::ReleaseCreated), with a rollback on failure. This bypasses the normal event for family_observed, but the field is pub(crate) precisely for this use. The pre-condition check (State::PublicationAuthorized) is sufficient because reaching that state without a valid signature is structurally impossible for non-0.1.0 versions.

main.rs — qualify subcommand

qualification::run creates its own signers file internally from manifest::ALLOWED_SIGNERS, so no ambient signers variable is needed from main. publish_cmd and hosted::run pass &signers to authorize_file — that variable would have been defined in pre-existing code (both paths already called SSH-verification routines for manifest/artifact signatures before this PR).

Tests

signing.rs: the "unsigned" case produces "instruction requires an owner signature (<instruction>.sig)" which satisfies contains("instruction") && contains("signature"). The "altered"/"wrong-key" cases rely on ssh_verify emitting "signature" in its error — standard SSH tooling does. The journal-unchanged assertion after a failed authorize_file is vacuously true (the method never touches the journal) but serves as a contract check that authorize_file is journal-agnostic.

family.rs: uses authorized() with 0.1.0 manifests (consistent with fixture()), so apply(Event::Authorized(i)) directly is still valid under the new guard. The evidence.len() == PLATFORMS.len() * 4 assertion holds because qualification_steps creates files for all four KINDS (excluded ones are still included in the evidence map).

No concrete defects found.

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

Subject: 496dec5...eee935f, diff digest e71f4ba4cca59bf0ef80335cea21b7a82f981bcca58a13f35302f060a30f5082, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus enabled auto-merge October 27, 2026 21:10
@bartekus
bartekus marked this pull request as draft October 27, 2026 22:09
auto-merge was automatically disabled October 27, 2026 22:09

Pull request was converted to draft

@bartekus
bartekus marked this pull request as ready for review October 27, 2026 22:10
@bartekus
bartekus enabled auto-merge October 27, 2026 22:10
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

I reviewed the diff carefully, focusing on the SSH-signature enforcement for post-0.1.0 instructions, the new qualify subcommand, and the state-machine changes in lifecycle.rs.

lifecycle.rs – authorize_file / instruction_verified

The chicken-and-egg is resolved correctly: verified_instruction is set from the verified bytes before apply checks it, and cleared on apply failure. For FIRST_RELEASE_VERSION the field is never set, and instruction_verified accepts it via the version == FIRST_RELEASE_VERSION branch. A direct apply(Event::Authorized(_)) for a later version without going through authorize_file correctly fails because verified_instruction is None. The cleanup path in authorize_file is sound for the normal error case.

family_lifecycle.rs – run gate

The old hard-coded version != FIRST_RELEASE_VERSION refusal is replaced by instruction_verified(), which is the right instrument. No authorization bypass is introduced: a later-version instruction without a matching verified_instruction is still refused by the apply predicate.

qualification.rs – restore_released

The function saves and restores only family_observed and state. The apply contract ("refuse it and leave the state unchanged") means the function is correct as long as apply is atomic on refusal, which the contract requires. The test qualification_refuses_incomplete_or_conflicting_publication confirms the rollback is observed correctly.

evidence function

Non-required kinds are accepted absent (skip) or present-and-excluded; required kinds must be Passed with exit code 0 and full execution fields. The deny_unknown_fields attribute on Step ensures the "unknown" test case is caught by the deserializer, not silently ignored.

Test assertions

assert_eq!(evidence.len(), fa::PLATFORMS.len() * 4) holds because qualification_steps creates files for every platform × kind combination, and evidence inserts both passed and excluded steps.

main.rs usage string

Updated to include qualify <release-dir> <evidence-dir> <instruction> <journal>, consistent with the four-argument handler.

No concrete bugs or security defects found.

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

Subject: 496dec5...eee935f, diff digest e71f4ba4cca59bf0ef80335cea21b7a82f981bcca58a13f35302f060a30f5082, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, I'll check the key areas: signature verification logic, qualification evidence handling, and the new CLI dispatch.

lifecycle.rs — authorize_file and instruction_verified

The flow is sound. verified_instruction is set only after ssh_verify succeeds, then apply checks it. If apply refuses, verified_instruction is cleared. For FIRST_RELEASE_VERSION, no signature is required and instruction_verified returns true based on the version match. The guard in the modified apply condition correctly requires verified_instruction to match for non-first-release versions, preventing direct apply(Event::Authorized(...)) bypass.

qualification.rs — evidence validation and restore_released

Evidence validation is thorough; all fields are checked before the map is built. restore_released directly mutates life.family_observed and life.state to fast-forward the lifecycle through journal evidence rather than replaying uploads — a deliberate design that's guarded by the leading PublicationAuthorized state check and rolled back on error.

main.rs — qualify command argument order

The function signature is:

pub fn run(dir, evidence_dir, instruction, journal, repo)

The call in main.rs is:

rustev_release::qualification::run(
    Path::new(dir),
    Path::new(evidence),
    Path::new(instruction),
    Path::new(&top),     // ← repo root passed as `journal`
    Path::new(journal),  // ← user-supplied journal path passed as `repo`
)

The 4th and 5th arguments are swapped. top (the git repo root) is passed as the journal parameter, and journal (the user-supplied path) is passed as the repo parameter. The usage string qualify <release-dir> <evidence-dir> <instruction> <journal> and the comment ("The journal lives outside Git … as publish does") both confirm that journal should be the 4th positional argument and top should be the 5th. At runtime this would cause journal_path(top, journal) — wrong direction — producing a path validation failure or silently operating on the wrong journal.

{"head": "dd90b2bfe7df837f348408e90978d1b6c214444a", "verdict": "findings", "findings": [{"path": "tools/rustev-release/src/main.rs", "line": 1101, "summary": "The `qualify` command passes `top` (git repo root) as the `journal` parameter and `journal` (user-supplied path) as the `repo` parameter to `qualification::run`, swapping the 4th and 5th arguments relative to the function signature."}]}

Subject: 2d6b70b...dd90b2b, diff digest e71f4ba4cca59bf0ef80335cea21b7a82f981bcca58a13f35302f060a30f5082, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception October 27, 2026 23:24 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff across all changed paths.

lifecycle.rs — authorize_file / instruction_verified

The verified_instruction field is set to Some(instruction.clone()) before apply(Event::Authorized(instruction)) is called (line ~150). This is necessary: the apply guard reads self.verified_instruction to allow later-release instructions through. On error, the cleanup self.verified_instruction = None is correct. The private visibility of verified_instruction (no pub qualifier) means only authorize_file can populate it — a sound boundary.

The instruction_verified() predicate correctly short-circuits on FIRST_RELEASE_VERSION so verified_instruction = None is not required for 0.1.0.

qualification.rs — evidence()

  • File-absent handling is correct: non-required + NotFound → continue; required + any error → hard error.
  • Status::Excluded is required for non-required kinds that exist on disk; Status::Passed + exit_status == Some(0) for required kinds. Consistent with the required_files filter.
  • The checksum() validator correctly accepts both 64-char hex digests and sha512-<88-char base64> SRI strings.
  • deny_unknown_fields on Step makes the "unknown" test case correctly rejected at deserialization.

qualification.rs — restore_released

Directly manipulates life.family_observed and life.state (both pub(crate)) to replay the publish path from journal evidence rather than re-running live events. The guard family_lifecycle::bound() + per-item Lookup::Visible check provides the necessary evidence. State is rolled back on any error. The approach is deliberate and the rollback is correct.

qualify subcommand in main.rs

Argument order in the match arm matches qualification::run's signature (dir, evidence_dir, instruction, journal, repo). The repo is obtained from git rev-parse --show-toplevel. The usage string is updated to include the new subcommand.

required_files redesign

The old family_lifecycle::qualify required "crates-subsets" plus per-artifact names; the new design requires "{platform}.{kind}.json" for each platform × required kind. The test at line 247 (family_reaches_released_only_after...) is updated consistently. Since this is the first real qualification implementation (no prior qualifications exist), no backward compatibility issue arises.

signing.rs — "altered" test case

Signs the original bytes, then appends \n before writing the altered file back. authorize_file reads the altered bytes and passes them to ssh_verify, which correctly rejects the mismatched signature. The test assertion error.contains("instruction") && error.contains("signature") matches the format!("instruction: {e}") wrapper around the SSH verify error.

No concrete defects found.

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

Subject: 2d6b70b...a1f97c2, diff digest 1ac78654085caeb79913e76e074c5c5d24c1094074b908c4a50352c6ef75e107, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 36ff0c9 Oct 28, 2026
34 checks passed
@bartekus
bartekus deleted the impl/056-qualify branch October 28, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant