[team] Team vaults: rustfmt on the files this change touches

This commit is contained in:
2026-11-17 12:15:18 +01:00
parent e3ede760bd
commit 3bb05bf6f1
8 changed files with 138 additions and 45 deletions
+6 -1
View File
@@ -227,7 +227,12 @@ pub fn eligible(policy: &Policy, roster: &[RosterMember], env: &str, author: &st
/// statements were already checked.
pub fn evaluate(policy: &Policy, roster: &[RosterMember], env: &str, author: &str, approvers: &[String]) -> Evaluation {
let Some(rule) = policy.rule(env) else {
return Evaluation { verdict: Verdict::UnknownEnv, eligible: vec![], counted: vec![], ignored: approvers.to_vec() };
return Evaluation {
verdict: Verdict::UnknownEnv,
eligible: vec![],
counted: vec![],
ignored: approvers.to_vec(),
};
};
let eligible = eligible(policy, roster, env, author).unwrap_or_default();
let mut counted: Vec<String> = Vec::new();
+6 -1
View File
@@ -180,7 +180,12 @@ pub struct Verified {
/// with it: both signatures, every approval (signature, roster, the request's own match code), the request and
/// envelope hashes, and the policy evaluated again. The clock is not consulted: a proof stays checkable after its
/// request expired.
pub fn verify_proof(proof: &Proof, identity: &[u8; 32], request_text: &str, envelope: &[u8]) -> Result<Verified, TeamError> {
pub fn verify_proof(
proof: &Proof,
identity: &[u8; 32],
request_text: &str,
envelope: &[u8],
) -> Result<Verified, TeamError> {
let sig: [u8; 64] = unb64(&proof.sig).and_then(|s| s.try_into().ok()).ok_or(TeamError::BadSignature)?;
if !verify_proof_sig(identity, &proof.text, &sig) {
return Err(TeamError::BadSignature);
+5 -4
View File
@@ -100,9 +100,8 @@ fn lower_hex(s: &str, len: usize) -> bool {
}
pub(crate) fn pub_key(s: &str) -> Result<[u8; 32], TeamError> {
let k: [u8; 32] = unb64(s)
.and_then(|v| v.try_into().ok())
.ok_or(TeamError::Invalid("pub is not base64 of 32 bytes"))?;
let k: [u8; 32] =
unb64(s).and_then(|v| v.try_into().ok()).ok_or(TeamError::Invalid("pub is not base64 of 32 bytes"))?;
if k == [0; 32] {
return Err(TeamError::Invalid("pub is all zeros"));
}
@@ -176,7 +175,9 @@ impl SignRequest {
return bad("artifact_digest has the wrong length for its format");
}
match self.format {
Format::Cosign => custos_sign::image_ok(&self.image).map_err(|_| TeamError::Invalid("image is not a repository"))?,
Format::Cosign => {
custos_sign::image_ok(&self.image).map_err(|_| TeamError::Invalid("image is not a repository"))?
}
_ if !self.image.is_empty() => return bad("image is for cosign only"),
_ => {}
}
+1 -2
View File
@@ -55,8 +55,7 @@ impl Statement {
}
let m = roster.iter().find(|m| m.id == self.member).ok_or(TeamError::NotAMember)?;
let id: [u8; 16] = unhex(&self.member).ok_or(TeamError::NotAMember)?;
let sig: [u8; 64] =
unb64(&self.sig).and_then(|s| s.try_into().ok()).ok_or(TeamError::BadSignature)?;
let sig: [u8; 64] = unb64(&self.sig).and_then(|s| s.try_into().ok()).ok_or(TeamError::BadSignature)?;
if !crate::member::verify(&m.ed25519, &message(&req.hash(), &self.code, &id, self.at), &sig) {
return Err(TeamError::BadSignature);
}
+24 -6
View File
@@ -74,7 +74,9 @@ fn every_size_environment_author_and_approver_under_the_default_policy() {
let r = roster(n);
for env in ["preview", "staging", "production", "qa"] {
// The author by handle (any case), by member id, someone outside the team, or nobody named.
for (author, is_member) in [("mnovak", true), ("MNOVAK", true), (id(0).as_str(), true), ("stranger", false), ("", false)] {
for (author, is_member) in
[("mnovak", true), ("MNOVAK", true), (id(0).as_str(), true), ("stranger", false), ("", false)]
{
for (what, set) in approver_sets(n) {
let got = evaluate(&policy, &r, env, author, &set);
let want = expected(n, env, is_member, &set);
@@ -119,9 +121,15 @@ fn several_approvals_others_and_approver_lists() {
let three = roster(3);
assert_eq!(evaluate(&p, &three, "production", "mnovak", &[id(1)]).verdict, Verdict::Need(1));
assert_eq!(evaluate(&p, &three, "production", "mnovak", &[id(0), id(1)]).verdict, Verdict::Need(1));
assert_eq!(evaluate(&p, &three, "production", "mnovak", &[id(1), id(2)]).verdict, Verdict::Allowed(KeyRole::Release));
assert_eq!(
evaluate(&p, &three, "production", "mnovak", &[id(1), id(2)]).verdict,
Verdict::Allowed(KeyRole::Release)
);
// Someone not named as the author (a release by a non-member): every member counts.
assert_eq!(evaluate(&p, &three, "production", "stranger", &[id(0), id(1)]).verdict, Verdict::Allowed(KeyRole::Release));
assert_eq!(
evaluate(&p, &three, "production", "stranger", &[id(0), id(1)]).verdict,
Verdict::Allowed(KeyRole::Release)
);
// Only member 1 may approve staging.
p.set_rule(EnvRule { env: "staging".into(), approvals: 1, others: false, approvers: vec![id(1)] }).unwrap();
@@ -138,7 +146,10 @@ fn several_approvals_others_and_approver_lists() {
q.set_rule(EnvRule { env: "staging".into(), approvals: 1, others: true, approvers: vec![id(0)] }).unwrap();
q
};
assert_eq!(evaluate(&solo_policy, &roster(1), "staging", "mnovak", &[id(0)]).verdict, Verdict::Allowed(KeyRole::Release));
assert_eq!(
evaluate(&solo_policy, &roster(1), "staging", "mnovak", &[id(0)]).verdict,
Verdict::Allowed(KeyRole::Release)
);
// A preview made strict.
p.set_rule(EnvRule { env: "preview".into(), approvals: 1, others: false, approvers: vec![] }).unwrap();
assert_eq!(evaluate(&p, &four, "preview", "mnovak", &[]).verdict, Verdict::Need(1));
@@ -163,7 +174,10 @@ fn the_policy_text_is_canonical_and_its_rules_are_checked() {
text.replace("\"approvers\":[]}]", "\"approvers\":[\"nope\"]}]"),
text.replace("{\"v\":1,", "{\"v\":2,"),
text.clone() + "\n",
text.replace("\"others\":false,\"approvers\":[]},{\"env\":\"staging\"", "\"others\":false,\"approvers\":[],\"x\":1},{\"env\":\"staging\""),
text.replace(
"\"others\":false,\"approvers\":[]},{\"env\":\"staging\"",
"\"others\":false,\"approvers\":[],\"x\":1},{\"env\":\"staging\"",
),
] {
assert!(Policy::parse(&bad).is_err(), "{bad}");
}
@@ -178,7 +192,11 @@ fn the_identity_signs_the_policy_and_nothing_else_passes_for_it() {
let text = Policy::default_for(TEAM).canonical();
let sig = identity.sign_policy(&text);
assert!(custos_team::member::verify_policy_sig(&identity.public(), &text, &sig));
assert!(!custos_team::member::verify_policy_sig(&identity.public(), &text.replace("\"approvals\":1,\"others\":true", "\"approvals\":0,\"others\":true"), &sig));
assert!(!custos_team::member::verify_policy_sig(
&identity.public(),
&text.replace("\"approvals\":1,\"others\":true", "\"approvals\":0,\"others\":true"),
&sig
));
// A proof signature is not a policy signature.
let proof_sig = identity.sign_proof(&text);
assert!(!custos_team::member::verify_policy_sig(&identity.public(), &text, &proof_sig));
+4 -1
View File
@@ -166,7 +166,10 @@ fn a_proof_verifies_only_for_its_request_signature_policy_and_identity() {
assert_eq!((v.role, v.signer.as_str(), v.approvers.clone()), (KeyRole::Release, b.id().as_str(), vec![b.id()]));
// Another identity, another envelope, another request.
assert_eq!(verify_proof(&good, &TeamIdentity::generate().public(), &req_text, &envelope), Err(TeamError::BadSignature));
assert_eq!(
verify_proof(&good, &TeamIdentity::generate().public(), &req_text, &envelope),
Err(TeamError::BadSignature)
);
assert!(verify_proof(&good, &identity.public(), &req_text, b"another signature").is_err());
let mut other = req.clone();
other.release = "0.7.1".into();