[team] Team vaults: rustfmt on the files this change touches
This commit is contained in:
@@ -227,7 +227,12 @@ pub fn eligible(policy: &Policy, roster: &[RosterMember], env: &str, author: &st
|
|||||||
/// statements were already checked.
|
/// statements were already checked.
|
||||||
pub fn evaluate(policy: &Policy, roster: &[RosterMember], env: &str, author: &str, approvers: &[String]) -> Evaluation {
|
pub fn evaluate(policy: &Policy, roster: &[RosterMember], env: &str, author: &str, approvers: &[String]) -> Evaluation {
|
||||||
let Some(rule) = policy.rule(env) else {
|
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 eligible = eligible(policy, roster, env, author).unwrap_or_default();
|
||||||
let mut counted: Vec<String> = Vec::new();
|
let mut counted: Vec<String> = Vec::new();
|
||||||
|
|||||||
@@ -180,7 +180,12 @@ pub struct Verified {
|
|||||||
/// with it: both signatures, every approval (signature, roster, the request's own match code), the request and
|
/// 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
|
/// envelope hashes, and the policy evaluated again. The clock is not consulted: a proof stays checkable after its
|
||||||
/// request expired.
|
/// 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)?;
|
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) {
|
if !verify_proof_sig(identity, &proof.text, &sig) {
|
||||||
return Err(TeamError::BadSignature);
|
return Err(TeamError::BadSignature);
|
||||||
|
|||||||
@@ -100,9 +100,8 @@ fn lower_hex(s: &str, len: usize) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pub_key(s: &str) -> Result<[u8; 32], TeamError> {
|
pub(crate) fn pub_key(s: &str) -> Result<[u8; 32], TeamError> {
|
||||||
let k: [u8; 32] = unb64(s)
|
let k: [u8; 32] =
|
||||||
.and_then(|v| v.try_into().ok())
|
unb64(s).and_then(|v| v.try_into().ok()).ok_or(TeamError::Invalid("pub is not base64 of 32 bytes"))?;
|
||||||
.ok_or(TeamError::Invalid("pub is not base64 of 32 bytes"))?;
|
|
||||||
if k == [0; 32] {
|
if k == [0; 32] {
|
||||||
return Err(TeamError::Invalid("pub is all zeros"));
|
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");
|
return bad("artifact_digest has the wrong length for its format");
|
||||||
}
|
}
|
||||||
match self.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"),
|
_ if !self.image.is_empty() => return bad("image is for cosign only"),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ impl Statement {
|
|||||||
}
|
}
|
||||||
let m = roster.iter().find(|m| m.id == self.member).ok_or(TeamError::NotAMember)?;
|
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 id: [u8; 16] = unhex(&self.member).ok_or(TeamError::NotAMember)?;
|
||||||
let sig: [u8; 64] =
|
let sig: [u8; 64] = unb64(&self.sig).and_then(|s| s.try_into().ok()).ok_or(TeamError::BadSignature)?;
|
||||||
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) {
|
if !crate::member::verify(&m.ed25519, &message(&req.hash(), &self.code, &id, self.at), &sig) {
|
||||||
return Err(TeamError::BadSignature);
|
return Err(TeamError::BadSignature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,9 @@ fn every_size_environment_author_and_approver_under_the_default_policy() {
|
|||||||
let r = roster(n);
|
let r = roster(n);
|
||||||
for env in ["preview", "staging", "production", "qa"] {
|
for env in ["preview", "staging", "production", "qa"] {
|
||||||
// The author by handle (any case), by member id, someone outside the team, or nobody named.
|
// 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) {
|
for (what, set) in approver_sets(n) {
|
||||||
let got = evaluate(&policy, &r, env, author, &set);
|
let got = evaluate(&policy, &r, env, author, &set);
|
||||||
let want = expected(n, env, is_member, &set);
|
let want = expected(n, env, is_member, &set);
|
||||||
@@ -119,9 +121,15 @@ fn several_approvals_others_and_approver_lists() {
|
|||||||
let three = roster(3);
|
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(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(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.
|
// 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.
|
// Only member 1 may approve staging.
|
||||||
p.set_rule(EnvRule { env: "staging".into(), approvals: 1, others: false, approvers: vec![id(1)] }).unwrap();
|
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.set_rule(EnvRule { env: "staging".into(), approvals: 1, others: true, approvers: vec![id(0)] }).unwrap();
|
||||||
q
|
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.
|
// A preview made strict.
|
||||||
p.set_rule(EnvRule { env: "preview".into(), approvals: 1, others: false, approvers: vec![] }).unwrap();
|
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));
|
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("\"approvers\":[]}]", "\"approvers\":[\"nope\"]}]"),
|
||||||
text.replace("{\"v\":1,", "{\"v\":2,"),
|
text.replace("{\"v\":1,", "{\"v\":2,"),
|
||||||
text.clone() + "\n",
|
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}");
|
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 text = Policy::default_for(TEAM).canonical();
|
||||||
let sig = identity.sign_policy(&text);
|
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, &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.
|
// A proof signature is not a policy signature.
|
||||||
let proof_sig = identity.sign_proof(&text);
|
let proof_sig = identity.sign_proof(&text);
|
||||||
assert!(!custos_team::member::verify_policy_sig(&identity.public(), &text, &proof_sig));
|
assert!(!custos_team::member::verify_policy_sig(&identity.public(), &text, &proof_sig));
|
||||||
|
|||||||
@@ -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()]));
|
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.
|
// 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());
|
assert!(verify_proof(&good, &identity.public(), &req_text, b"another signature").is_err());
|
||||||
let mut other = req.clone();
|
let mut other = req.clone();
|
||||||
other.release = "0.7.1".into();
|
other.release = "0.7.1".into();
|
||||||
|
|||||||
@@ -565,7 +565,13 @@ impl Vault {
|
|||||||
|
|
||||||
/// A new team vault with `founder` as its only member, the default policy, and no keys yet
|
/// A new team vault with `founder` as its only member, the default policy, and no keys yet
|
||||||
/// ([`Vault::team_create_keys`]). The caller saves it where the team keeps it.
|
/// ([`Vault::team_create_keys`]). The caller saves it where the team keeps it.
|
||||||
pub fn create_team(name: &str, founder: &MemberKey, founder_name: &str, handles: &[String], now: i64) -> Result<Vault, Error> {
|
pub fn create_team(
|
||||||
|
name: &str,
|
||||||
|
founder: &MemberKey,
|
||||||
|
founder_name: &str,
|
||||||
|
handles: &[String],
|
||||||
|
now: i64,
|
||||||
|
) -> Result<Vault, Error> {
|
||||||
let name = name.trim();
|
let name = name.trim();
|
||||||
if !canon::text_ok(name, 64) || !canon::text_ok(founder_name.trim(), 64) || !handles_ok(handles) {
|
if !canon::text_ok(name, 64) || !canon::text_ok(founder_name.trim(), 64) || !handles_ok(handles) {
|
||||||
return Err(Error::Team("a team or member name is 1 to 64 printable characters".into()));
|
return Err(Error::Team("a team or member name is 1 to 64 printable characters".into()));
|
||||||
@@ -749,7 +755,13 @@ impl Vault {
|
|||||||
}
|
}
|
||||||
let gone = t.members.remove(at);
|
let gone = t.members.remove(at);
|
||||||
t.epoch = t.epoch.checked_add(1).ok_or(Error::Corrupted)?;
|
t.epoch = t.epoch.checked_add(1).ok_or(Error::Corrupted)?;
|
||||||
t.removed.push(RemovedMember { id: gone.id.clone(), name: gone.name.clone(), at: now, by: by.into(), epoch: t.epoch });
|
t.removed.push(RemovedMember {
|
||||||
|
id: gone.id.clone(),
|
||||||
|
name: gone.name.clone(),
|
||||||
|
at: now,
|
||||||
|
by: by.into(),
|
||||||
|
epoch: t.epoch,
|
||||||
|
});
|
||||||
if t.policy.envs.iter().any(|r| r.approvers.contains(&gone.id)) {
|
if t.policy.envs.iter().any(|r| r.approvers.contains(&gone.id)) {
|
||||||
for r in t.policy.envs.iter_mut() {
|
for r in t.policy.envs.iter_mut() {
|
||||||
r.approvers.retain(|a| *a != gone.id);
|
r.approvers.retain(|a| *a != gone.id);
|
||||||
@@ -793,7 +805,8 @@ impl Vault {
|
|||||||
return Err(Error::Team("an approver is not a member".into()));
|
return Err(Error::Team("an approver is not a member".into()));
|
||||||
}
|
}
|
||||||
let env = rule.env.clone();
|
let env = rule.env.clone();
|
||||||
let detail = format!("{env}: {} approval(s){}", rule.approvals, if rule.others { ", not the author" } else { "" });
|
let detail =
|
||||||
|
format!("{env}: {} approval(s){}", rule.approvals, if rule.others { ", not the author" } else { "" });
|
||||||
t.policy.set_rule(rule).map_err(team_err)?;
|
t.policy.set_rule(rule).map_err(team_err)?;
|
||||||
t.sign_policy();
|
t.sign_policy();
|
||||||
t.log(now, TeamAction::PolicySet, by, Some(detail));
|
t.log(now, TeamAction::PolicySet, by, Some(detail));
|
||||||
@@ -854,7 +867,12 @@ impl Vault {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An Android key for one project (`apk`), scoped to it. Slow: RSA-4096. The caller saves.
|
/// An Android key for one project (`apk`), scoped to it. Slow: RSA-4096. The caller saves.
|
||||||
pub fn team_create_android(&mut self, spec: &crate::signing::AndroidKey, by: &str, now: i64) -> Result<String, Error> {
|
pub fn team_create_android(
|
||||||
|
&mut self,
|
||||||
|
spec: &crate::signing::AndroidKey,
|
||||||
|
by: &str,
|
||||||
|
now: i64,
|
||||||
|
) -> Result<String, Error> {
|
||||||
self.team()?;
|
self.team()?;
|
||||||
let id = self.signing_create_android(spec, now)?;
|
let id = self.signing_create_android(spec, now)?;
|
||||||
self.team_mut()?.log(now, TeamAction::KeysCreated, by, Some(id.clone()));
|
self.team_mut()?.log(now, TeamAction::KeysCreated, by, Some(id.clone()));
|
||||||
@@ -876,7 +894,9 @@ impl Vault {
|
|||||||
|| new.secret.is_empty()
|
|| new.secret.is_empty()
|
||||||
|| new.secret.expose().len() > MAX_SECRET
|
|| new.secret.expose().len() > MAX_SECRET
|
||||||
{
|
{
|
||||||
return Err(Error::Team("a target needs a name, a project, an environment and a credential (≤ 64 KiB)".into()));
|
return Err(Error::Team(
|
||||||
|
"a target needs a name, a project, an environment and a credential (≤ 64 KiB)".into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let id = short_id();
|
let id = short_id();
|
||||||
let name = new.name.trim().to_owned();
|
let name = new.name.trim().to_owned();
|
||||||
@@ -927,7 +947,12 @@ impl Vault {
|
|||||||
/// request this team vault signed for the target's project and environment within 25 hours, and this
|
/// request this team vault signed for the target's project and environment within 25 hours, and this
|
||||||
/// (target, deployment) was never released before. Returns the plaintext to seal to the request's key.
|
/// (target, deployment) was never released before. Returns the plaintext to seal to the request's key.
|
||||||
/// The caller saves.
|
/// The caller saves.
|
||||||
pub fn team_target_release(&mut self, request: &str, by: &str, now: i64) -> Result<(Zeroizing<String>, TargetRequest), Error> {
|
pub fn team_target_release(
|
||||||
|
&mut self,
|
||||||
|
request: &str,
|
||||||
|
by: &str,
|
||||||
|
now: i64,
|
||||||
|
) -> Result<(Zeroizing<String>, TargetRequest), Error> {
|
||||||
let now_s = seconds(now);
|
let now_s = seconds(now);
|
||||||
let req = TargetRequest::check(request, now_s).map_err(team_err)?;
|
let req = TargetRequest::check(request, now_s).map_err(team_err)?;
|
||||||
let signed: Vec<(String, String, i64)> = self
|
let signed: Vec<(String, String, i64)> = self
|
||||||
@@ -1068,7 +1093,13 @@ impl Vault {
|
|||||||
|
|
||||||
/// A member approves without signing (the policy needs more): the statement to post. `shown_code` is the code
|
/// A member approves without signing (the policy needs more): the statement to post. `shown_code` is the code
|
||||||
/// the card showed.
|
/// the card showed.
|
||||||
pub fn team_approve(&self, text: &str, key: &MemberKey, shown_code: &str, now: i64) -> Result<Statement, TeamError> {
|
pub fn team_approve(
|
||||||
|
&self,
|
||||||
|
text: &str,
|
||||||
|
key: &MemberKey,
|
||||||
|
shown_code: &str,
|
||||||
|
now: i64,
|
||||||
|
) -> Result<Statement, TeamError> {
|
||||||
let req = self.team_check_request(text, now)?;
|
let req = self.team_check_request(text, now)?;
|
||||||
self.team_may_approve(&req, &key.id())?;
|
self.team_may_approve(&req, &key.id())?;
|
||||||
approve(key, &req, shown_code, seconds(now))
|
approve(key, &req, shown_code, seconds(now))
|
||||||
@@ -1077,7 +1108,8 @@ impl Vault {
|
|||||||
/// Records a refusal by `by`; the request is never signed here afterwards. The caller saves.
|
/// Records a refusal by `by`; the request is never signed here afterwards. The caller saves.
|
||||||
pub fn team_refuse(&mut self, text: &str, by: &str, reason: &str, now: i64) -> Result<(), Error> {
|
pub fn team_refuse(&mut self, text: &str, by: &str, reason: &str, now: i64) -> Result<(), Error> {
|
||||||
let req = SignRequest::parse(text).map_err(team_err)?;
|
let req = SignRequest::parse(text).map_err(team_err)?;
|
||||||
let entry = self.team_audit_entry(&req, Outcome::Refused, by, Some(reason.chars().take(200).collect()), None, &[], now);
|
let entry =
|
||||||
|
self.team_audit_entry(&req, Outcome::Refused, by, Some(reason.chars().take(200).collect()), None, &[], now);
|
||||||
self.signing.audit.push(entry);
|
self.signing.audit.push(entry);
|
||||||
let hash = req.hash_hex();
|
let hash = req.hash_hex();
|
||||||
self.team_mut()?.mark_seen(hash, seconds(now));
|
self.team_mut()?.mark_seen(hash, seconds(now));
|
||||||
@@ -1149,11 +1181,8 @@ impl Vault {
|
|||||||
let me = key.id();
|
let me = key.id();
|
||||||
let me_member = roster.iter().find(|m| m.id == me).ok_or(TeamError::NotAMember)?;
|
let me_member = roster.iter().find(|m| m.id == me).ok_or(TeamError::NotAMember)?;
|
||||||
let rule = t.policy.rule(&req.env).ok_or(TeamError::UnknownEnv)?;
|
let rule = t.policy.rule(&req.env).ok_or(TeamError::UnknownEnv)?;
|
||||||
let mut approvals: Vec<Statement> = statements
|
let mut approvals: Vec<Statement> =
|
||||||
.iter()
|
statements.iter().filter(|s| s.member != me && s.verify(&req, &roster).is_ok()).cloned().collect();
|
||||||
.filter(|s| s.member != me && s.verify(&req, &roster).is_ok())
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
if rule.approvals > 0 {
|
if rule.approvals > 0 {
|
||||||
let code = shown_code.ok_or(TeamError::WrongMatch)?;
|
let code = shown_code.ok_or(TeamError::WrongMatch)?;
|
||||||
may_approve(&t.policy, &roster, &req.env, &req.author, &me)?;
|
may_approve(&t.policy, &roster, &req.env, &req.author, &me)?;
|
||||||
|
|||||||
@@ -43,7 +43,11 @@ fn request(vault: &Vault, env: &str, author: &str, format: Format, fabrica: &cus
|
|||||||
env: env.into(),
|
env: env.into(),
|
||||||
author: author.into(),
|
author: author.into(),
|
||||||
format,
|
format,
|
||||||
artifact: Artifact { name: "Arca_0.7.0_x64-setup.exe".into(), size: 13, sha256: custos_sign::sha256_hex(b"the installer") },
|
artifact: Artifact {
|
||||||
|
name: "Arca_0.7.0_x64-setup.exe".into(),
|
||||||
|
size: 13,
|
||||||
|
sha256: custos_sign::sha256_hex(b"the installer"),
|
||||||
|
},
|
||||||
artifact_digest: digest.to_vec(),
|
artifact_digest: digest.to_vec(),
|
||||||
image: image.into(),
|
image: image.into(),
|
||||||
public: fabrica.public(),
|
public: fabrica.public(),
|
||||||
@@ -67,7 +71,9 @@ fn members_open_the_team_vault_and_outsiders_do_not() {
|
|||||||
assert!(matches!(Vault::open_team(&bytes, &MemberKey::generate()), Err(Error::NotAMember)));
|
assert!(matches!(Vault::open_team(&bytes, &MemberKey::generate()), Err(Error::NotAMember)));
|
||||||
// A team vault is not a two-factor vault, and a personal vault is not a team vault.
|
// A team vault is not a two-factor vault, and a personal vault is not a team vault.
|
||||||
assert!(Vault::factor_kinds(&bytes).unwrap().is_empty());
|
assert!(Vault::factor_kinds(&bytes).unwrap().is_empty());
|
||||||
let mut personal = Vault::create(&SecretString::from("pw"), custos_vault::KdfParams { m_cost_kib: 8, t_cost: 1, p_cost: 1 }).unwrap();
|
let mut personal =
|
||||||
|
Vault::create(&SecretString::from("pw"), custos_vault::KdfParams { m_cost_kib: 8, t_cost: 1, p_cost: 1 })
|
||||||
|
.unwrap();
|
||||||
assert!(matches!(Vault::open_team(&personal.to_bytes().unwrap(), &t.a), Err(Error::NotATeam)));
|
assert!(matches!(Vault::open_team(&personal.to_bytes().unwrap(), &t.a), Err(Error::NotATeam)));
|
||||||
// A changed header byte (a member slot moved to another epoch) does not open.
|
// A changed header byte (a member slot moved to another epoch) does not open.
|
||||||
let mut moved = bytes.clone();
|
let mut moved = bytes.clone();
|
||||||
@@ -171,7 +177,9 @@ fn contains(hay: &[u8], needle: &[u8]) -> bool {
|
|||||||
#[test]
|
#[test]
|
||||||
fn a_member_refuses_an_older_copy_or_another_identity() {
|
fn a_member_refuses_an_older_copy_or_another_identity() {
|
||||||
let mut t = team();
|
let mut t = team();
|
||||||
let mut own = Vault::create(&SecretString::from("pw"), custos_vault::KdfParams { m_cost_kib: 8, t_cost: 1, p_cost: 1 }).unwrap();
|
let mut own =
|
||||||
|
Vault::create(&SecretString::from("pw"), custos_vault::KdfParams { m_cost_kib: 8, t_cost: 1, p_cost: 1 })
|
||||||
|
.unwrap();
|
||||||
// Mark's own vault holds his member key; the team was made with the same key.
|
// Mark's own vault holds his member key; the team was made with the same key.
|
||||||
let c = MemberKey::generate();
|
let c = MemberKey::generate();
|
||||||
let code = c.public().join_code();
|
let code = c.public().join_code();
|
||||||
@@ -192,15 +200,29 @@ fn the_policy_is_set_per_environment_signed_and_kept() {
|
|||||||
let mut t = team();
|
let mut t = team();
|
||||||
let p = t
|
let p = t
|
||||||
.vault
|
.vault
|
||||||
.team_set_rule(EnvRule { env: "staging".into(), approvals: 1, others: true, approvers: vec![t.b.id()] }, &t.a.id(), NOW)
|
.team_set_rule(
|
||||||
|
EnvRule { env: "staging".into(), approvals: 1, others: true, approvers: vec![t.b.id()] },
|
||||||
|
&t.a.id(),
|
||||||
|
NOW,
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(p.rev, 2);
|
assert_eq!(p.rev, 2);
|
||||||
assert!(t.vault.team_set_rule(EnvRule { env: "staging".into(), approvals: 1, others: true, approvers: vec!["ab".repeat(16)] }, &t.a.id(), NOW).is_err());
|
assert!(
|
||||||
|
t.vault
|
||||||
|
.team_set_rule(
|
||||||
|
EnvRule { env: "staging".into(), approvals: 1, others: true, approvers: vec!["ab".repeat(16)] },
|
||||||
|
&t.a.id(),
|
||||||
|
NOW
|
||||||
|
)
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
let v = Vault::open_team(&t.vault.to_bytes().unwrap(), &t.b).unwrap();
|
let v = Vault::open_team(&t.vault.to_bytes().unwrap(), &t.b).unwrap();
|
||||||
let (text, sig) = v.team_policy_signed().unwrap();
|
let (text, sig) = v.team_policy_signed().unwrap();
|
||||||
assert!(custos_team::member::verify_policy_sig(&v.team_identity().unwrap(), &text, &sig));
|
assert!(custos_team::member::verify_policy_sig(&v.team_identity().unwrap(), &text, &sig));
|
||||||
assert_eq!(v.team_policy().unwrap().rule("staging").unwrap().approvers, vec![t.b.id()]);
|
assert_eq!(v.team_policy().unwrap().rule("staging").unwrap().approvers, vec![t.b.id()]);
|
||||||
assert!(v.team_audit().unwrap().iter().any(|e| e.detail.as_deref() == Some("staging: 1 approval(s), not the author")));
|
assert!(
|
||||||
|
v.team_audit().unwrap().iter().any(|e| e.detail.as_deref() == Some("staging: 1 approval(s), not the author"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mandatory: a signing request with a wrong or replayed match code is refused.
|
/// Mandatory: a signing request with a wrong or replayed match code is refused.
|
||||||
@@ -232,7 +254,10 @@ fn wrong_and_replayed_match_codes_are_refused() {
|
|||||||
assert!(eval.counted.is_empty());
|
assert!(eval.counted.is_empty());
|
||||||
// An expired request.
|
// An expired request.
|
||||||
let late = request(&t.vault, "staging", "mnovak", Format::Minisign, &fabrica);
|
let late = request(&t.vault, "staging", "mnovak", Format::Minisign, &fabrica);
|
||||||
assert_eq!(t.vault.team_sign(&late, &[], &t.a, Some(&code), None, NOW + 3_601_000).unwrap_err(), TeamError::Expired);
|
assert_eq!(
|
||||||
|
t.vault.team_sign(&late, &[], &t.a, Some(&code), None, NOW + 3_601_000).unwrap_err(),
|
||||||
|
TeamError::Expired
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -241,7 +266,13 @@ fn two_approvals_collect_statements_and_the_last_approver_signs() {
|
|||||||
let c = MemberKey::generate();
|
let c = MemberKey::generate();
|
||||||
let code = c.public().join_code();
|
let code = c.public().join_code();
|
||||||
t.vault.team_add_member(&c.public(), "Jan", &[], &t.a.id(), &code, NOW).unwrap();
|
t.vault.team_add_member(&c.public(), "Jan", &[], &t.a.id(), &code, NOW).unwrap();
|
||||||
t.vault.team_set_rule(EnvRule { env: "production".into(), approvals: 2, others: true, approvers: vec![] }, &t.a.id(), NOW).unwrap();
|
t.vault
|
||||||
|
.team_set_rule(
|
||||||
|
EnvRule { env: "production".into(), approvals: 2, others: true, approvers: vec![] },
|
||||||
|
&t.a.id(),
|
||||||
|
NOW,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let fabrica = custos_seal::Recipient::generate();
|
let fabrica = custos_seal::Recipient::generate();
|
||||||
let text = request(&t.vault, "production", "mnovak", Format::Minisign, &fabrica);
|
let text = request(&t.vault, "production", "mnovak", Format::Minisign, &fabrica);
|
||||||
let code = fabrica.match_code();
|
let code = fabrica.match_code();
|
||||||
@@ -382,7 +413,8 @@ fn a_target_credential_is_released_once_for_a_signed_deployment_of_its_project_a
|
|||||||
assert!(!format!("{:?}", t.vault.team_targets().unwrap()).contains("apiVersion"));
|
assert!(!format!("{:?}", t.vault.team_targets().unwrap()).contains("apiVersion"));
|
||||||
let team_id = t.vault.team_view().unwrap().id;
|
let team_id = t.vault.team_view().unwrap().id;
|
||||||
let fabrica = custos_seal::Recipient::generate();
|
let fabrica = custos_seal::Recipient::generate();
|
||||||
let ask = |deployment: &str| TargetRequest {
|
let ask = |deployment: &str| {
|
||||||
|
TargetRequest {
|
||||||
team: team_id.clone(),
|
team: team_id.clone(),
|
||||||
id: custos_team::new_id(),
|
id: custos_team::new_id(),
|
||||||
target: target.clone(),
|
target: target.clone(),
|
||||||
@@ -390,7 +422,8 @@ fn a_target_credential_is_released_once_for_a_signed_deployment_of_its_project_a
|
|||||||
public: fabrica.public(),
|
public: fabrica.public(),
|
||||||
expires: NOW_S + 600,
|
expires: NOW_S + 600,
|
||||||
}
|
}
|
||||||
.canonical();
|
.canonical()
|
||||||
|
};
|
||||||
// No signed deployment yet.
|
// No signed deployment yet.
|
||||||
let unsigned = "ab".repeat(32);
|
let unsigned = "ab".repeat(32);
|
||||||
assert!(t.vault.team_target_release(&ask(&unsigned), &t.b.id(), NOW).is_err());
|
assert!(t.vault.team_target_release(&ask(&unsigned), &t.b.id(), NOW).is_err());
|
||||||
|
|||||||
Reference in New Issue
Block a user