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
7 changes: 6 additions & 1 deletion deploy/private/image_demo/hello.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

fn main() {
println!("hello from an oci image");
Expand Down
75 changes: 34 additions & 41 deletions deploy/private/install/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]
#![cfg_attr(
test,
expect(
Expand All @@ -7,7 +12,7 @@
)
)]

use std::fmt::{self, Write as _};
use std::fmt;
use std::io;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -440,15 +445,13 @@ pub fn verify(request: &VerifyArgs, verifier: &dyn Verifier) -> Result<String, I
let binary = PathBuf::from(&request.binary);
let bundle = PathBuf::from(&request.bundle);
check_inputs(request, verifier, &binary, &bundle)?;
writeln!(out, "dx_verify: trust root {TRUST_ROOT} (Sigstore TUF public-good; verifiers bootstrapped from the trust root, never alongside the binary)").ok();
out.push_str(&format!("dx_verify: trust root {TRUST_ROOT} (Sigstore TUF public-good; verifiers bootstrapped from the trust root, never alongside the binary)\n"));
let method = verify_binary(request, verifier, &binary, &bundle, &mut out)?;
verify_sbom(request, verifier, &mut out)?;
verify_notice_files(request, verifier, &mut out)?;
writeln!(
out,
"dx_verify: OK (verified via {method}; nothing installed, binary never executed)"
)
.ok();
out.push_str(&format!(
"dx_verify: OK (verified via {method}; nothing installed, binary never executed)\n"
));
Ok(out)
}

Expand All @@ -463,33 +466,27 @@ fn verify_binary(
let gh = verifier.gh_bin();
let method: &'static str;
if verifier.have(&cosign) {
writeln!(
out,
"dx_verify: verifying {} against bundle via {cosign} verify-blob",
out.push_str(&format!(
"dx_verify: verifying {} against bundle via {cosign} verify-blob\n",
binary.display()
)
.ok();
));
if verifier.cosign_verify(&cosign, bundle, &request.identity, &request.issuer, binary) {
method = "cosign";
writeln!(
out,
"dx_verify: cosign publisher-identity OK (identity={} issuer={})",
out.push_str(&format!(
"dx_verify: cosign publisher-identity OK (identity={} issuer={})\n",
request.identity, request.issuer
)
.ok();
));
} else {
return Err(InstallError::CosignFailed);
}
} else if !request.attestation.is_empty() && verifier.have(&gh) {
if request.owner.is_empty() {
return Err(InstallError::OwnerRequired);
}
writeln!(
out,
"dx_verify: verifying {} against attestation via {gh} attestation verify",
out.push_str(&format!(
"dx_verify: verifying {} against attestation via {gh} attestation verify\n",
binary.display()
)
.ok();
));
let attestation = PathBuf::from(&request.attestation);
if verifier.gh_verify(
&gh,
Expand All @@ -500,12 +497,10 @@ fn verify_binary(
&request.owner,
) {
method = "gh-attestation";
writeln!(
out,
"dx_verify: attestation publisher-identity OK (identity={} issuer={} owner={})",
out.push_str(&format!(
"dx_verify: attestation publisher-identity OK (identity={} issuer={} owner={})\n",
request.identity, request.issuer, request.owner
)
.ok();
));
} else {
return Err(InstallError::AttestationFailed);
}
Expand All @@ -530,12 +525,10 @@ fn verify_sbom(
cosign,
});
}
writeln!(
out,
"dx_verify: verifying SBOM {} via {cosign} verify-blob",
out.push_str(&format!(
"dx_verify: verifying SBOM {} via {cosign} verify-blob\n",
sbom.display()
)
.ok();
));
if verifier.cosign_verify(
&cosign,
&sbom_bundle,
Expand Down Expand Up @@ -566,12 +559,10 @@ fn verify_notice_files(
cosign,
});
}
writeln!(
out,
"dx_verify: verifying NOTICE {} via {cosign} verify-blob",
out.push_str(&format!(
"dx_verify: verifying NOTICE {} via {cosign} verify-blob\n",
notice_path.display()
)
.ok();
));
if verifier.cosign_verify(
&cosign,
&notice_bundle,
Expand Down Expand Up @@ -602,7 +593,7 @@ fn verify_notice_files(
.read_text(&manifest_path)
.map_err(unreadable("notice manifest", &request.notice_manifest))?;
let count = verify_notice(&notice_text, &manifest_text)?;
writeln!(out, "dx_verify: NOTICE OK ({count} entries bundled)").ok();
out.push_str(&format!("dx_verify: NOTICE OK ({count} entries bundled)\n"));
}
Ok(())
}
Expand Down Expand Up @@ -733,8 +724,10 @@ mod tests {
.files
.get(path)
.ok_or_else(|| read_error(io::ErrorKind::NotFound, "missing file"))?;
String::from_utf8(data.clone())
.map_err(|_| read_error(io::ErrorKind::InvalidData, "not UTF-8"))
String::from_utf8(data.clone()).map_err(|error| PathIoError::Read {
path: path.to_path_buf(),
source: io::Error::new(io::ErrorKind::InvalidData, error),
})
}
}

Expand Down
7 changes: 6 additions & 1 deletion deploy/private/install/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

// LCOV_EXCL_START - reason: thin shim, issue: 1055, policy: docs/cli/commands/build-test-coverage.md
fn run(argv: &[String]) -> i32 {
Expand Down
7 changes: 6 additions & 1 deletion deploy/private/offline/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! Installs Bazel and vendored advisory snapshots from an offline bundle.

#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use std::fmt;
use std::io;
Expand Down
3 changes: 1 addition & 2 deletions deploy/private/offline/bootstrap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
reason = "tests run local programs under the Bazel test timeout"
)]
use dx_testing::env_file;
use std::fmt::Write as _;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -127,7 +126,7 @@ fn manifest(dir: &Path, names: &[String], trailing_newline: bool) {
for name in names {
let digest = dx_digest::sha256_file_hex(&dir.join(name))
.unwrap_or_else(|error| panic!("hash {name}: {error}"));
write!(text, "{digest} {name}\n").ok();
text.push_str(&format!("{digest} {name}\n"));
}
if !trailing_newline && text.ends_with('\n') {
text.pop();
Expand Down
7 changes: 6 additions & 1 deletion deploy/private/release/src/bin_bcr_ledger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use dx_release_tools::{bcr_submit_record, ledger_exit, render_ledger};

Expand Down
11 changes: 8 additions & 3 deletions deploy/private/release/src/bin_bump_version.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use dx_atomic_fs::path_io::{self, PathIoError};
use dx_process::capture::{DEFAULT_TIMEOUT, RunError, run_checked};
use std::fmt::{self, Write as _};
use std::fmt;
use std::path::{Path, PathBuf};

const USAGE: &str = "usage: bazel run //deploy/private/release:bump_version -- <version> [--workflow-ref <commit>]\n\nSets the rules_dx version, the starter workflow pin and the assert-no-secret and remote-cache-helper action pins in every file that carries them and refreshes tools/ci/starter_pin.sha256 from the workflows in the checkout.\n--workflow-ref defaults to origin/main, must have the affected_on_pr input and must carry the assert-no-secret and remote-cache-helper actions.";
Expand Down Expand Up @@ -217,7 +222,7 @@ fn redigest(root: &Path, record: &str) -> Result<String, BumpError> {
line: line.to_owned(),
})?;
let bytes = path_io::read(&root.join(path)).map_err(BumpError::DigestInput)?;
writeln!(out, "{} {path}", dx_digest::sha256_hex(&bytes)).ok();
out.push_str(&format!("{} {path}\n", dx_digest::sha256_hex(&bytes)));
}
Ok(out)
}
Expand Down
7 changes: 6 additions & 1 deletion deploy/private/release/src/bin_publish_dry_run_check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use std::path::{Path, PathBuf};

Expand Down
7 changes: 6 additions & 1 deletion deploy/private/release/src/bin_release_cell.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use dx_release_tools::ReleaseError;
use dx_release_tools::cell::{self, CellRecord, Verdict};
Expand Down
7 changes: 6 additions & 1 deletion deploy/private/release/src/bin_release_deploy_tool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

// LCOV_EXCL_START - reason: process shim, issue: 1055, policy: docs/cli/commands/build-test-coverage.md
fn main() {
Expand Down
26 changes: 11 additions & 15 deletions deploy/private/release/src/bin_release_driver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use std::collections::BTreeMap;
use std::ffi::OsString;
Expand Down Expand Up @@ -457,10 +462,9 @@ mod tests {
#[cfg(unix)]
#[test]
fn failed_tag_check_uploads_nothing() {
let dir = std::env::temp_dir().join(format!("rd-noup-{}", std::process::id()));
let dir = dx_testing::scratch_dir("rd-noup");
let mark = dir.join("called");
let asset = dir.join("a.bin");
std::fs::create_dir_all(&dir).expect("dir");
std::fs::write(&asset, b"x").expect("asset");
let backend = GhBackend {
program: fake_gh(&dir.join("bin"), &format!("touch {}", mark.display())),
Expand All @@ -480,7 +484,6 @@ mod tests {
assert_eq!(code, 1);
assert_eq!(states(&text), [("tag-local".into(), "failed".into())]);
assert!(!mark.exists());
std::fs::remove_dir_all(&dir).ok();
}

#[test]
Expand Down Expand Up @@ -514,9 +517,8 @@ mod tests {
#[cfg(unix)]
#[test]
fn gh_failure_output_never_leaks_the_token() {
let dir = std::env::temp_dir().join(format!("rd-leak-{}", std::process::id()));
let dir = dx_testing::scratch_dir("rd-leak");
let asset = dir.join("a.bin");
std::fs::create_dir_all(&dir).expect("dir");
std::fs::write(&asset, b"x").expect("asset");
let backend = GhBackend {
program: fake_gh(&dir.join("bin"), "echo \"token s3cret-token\" >&2; exit 1"),
Expand All @@ -532,15 +534,13 @@ mod tests {
assert_eq!(code, 1);
assert!(!text.contains("s3cret-token"));
assert!(text.contains("***"));
std::fs::remove_dir_all(&dir).ok();
}

#[cfg(unix)]
#[test]
fn matching_draft_release_validates_and_publish_stays_unauthorized() {
let dir = std::env::temp_dir().join(format!("rd-ok-{}", std::process::id()));
let dir = dx_testing::scratch_dir("rd-ok");
let asset = dir.join("a.bin");
std::fs::create_dir_all(&dir).expect("dir");
std::fs::write(&asset, b"x").expect("asset");
let sha = dx_digest::sha256_file_hex(&asset).expect("sha");
let json = format!(
Expand All @@ -560,13 +560,12 @@ mod tests {
assert_eq!(code, 0);
assert!(text.contains("\"state\": \"validated\""));
assert!(text.contains("\"operation\": \"publish\""));
std::fs::remove_dir_all(&dir).ok();
}

#[cfg(unix)]
#[test]
fn view_lists_releases_and_filters_by_tag() {
let dir = std::env::temp_dir().join(format!("rd-view-{}", std::process::id()));
let dir = dx_testing::scratch_dir("rd-view");
let args = dir.join("args");
let backend = GhBackend {
program: fake_gh(
Expand Down Expand Up @@ -595,15 +594,13 @@ mod tests {
".[] | select(.tag_name == \"v1.2.3\")",
]
);
std::fs::remove_dir_all(&dir).ok();
}

#[cfg(unix)]
#[test]
fn view_without_a_matching_release_fails_naming_the_tag() {
let dir = std::env::temp_dir().join(format!("rd-none-{}", std::process::id()));
let dir = dx_testing::scratch_dir("rd-none");
let asset = dir.join("a.bin");
std::fs::create_dir_all(&dir).expect("dir");
std::fs::write(&asset, b"x").expect("asset");
let backend = GhBackend {
program: fake_gh(&dir.join("bin"), "exit 0"),
Expand All @@ -623,7 +620,6 @@ mod tests {
);
assert_eq!(code, 1);
assert!(text.contains("no release for v1.2.3"), "{text}");
std::fs::remove_dir_all(&dir).ok();
}

#[test]
Expand Down
7 changes: 6 additions & 1 deletion deploy/private/release/src/bin_release_tool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

// LCOV_EXCL_START - reason: process shim, issue: 1055, policy: docs/cli/commands/build-test-coverage.md
fn main() {
Expand Down
7 changes: 6 additions & 1 deletion deploy/private/release/src/bin_source_archive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![deny(clippy::indexing_slicing, clippy::string_slice)]
#![deny(
clippy::indexing_slicing,
clippy::map_err_ignore,
clippy::string_slice,
clippy::unused_result_ok
)]

use std::ffi::OsString;
use std::path::PathBuf;
Expand Down
Loading
Loading