[team] Review fixes: a deployment ticket and a MAC on target.request, an unknown author is unsatisfiable under others, a signed request cannot be refused afterwards; TEAM.md limits; v0.18.1
This commit is contained in:
@@ -244,8 +244,13 @@ pub fn evaluate(policy: &Policy, roster: &[RosterMember], env: &str, author: &st
|
||||
ignored.push(a.clone());
|
||||
}
|
||||
}
|
||||
// `others` needs to know who the author is (core 0.18.1): an empty author, or one no member is, would let the
|
||||
// author approve their own release under a name the rule cannot see.
|
||||
let unknown_author = rule.others && roster.len() >= 2 && !roster.iter().any(|m| m.is(author));
|
||||
let verdict = if rule.approvals == 0 {
|
||||
Verdict::Allowed(KeyRole::Test)
|
||||
} else if unknown_author {
|
||||
Verdict::Unsatisfiable("the release's author is not a member the team knows, so the rule cannot exclude them")
|
||||
} else if counted.len() >= rule.approvals as usize {
|
||||
Verdict::Allowed(KeyRole::Release)
|
||||
} else if eligible.len() < rule.approvals as usize {
|
||||
@@ -278,5 +283,8 @@ pub fn may_approve(
|
||||
if rule.others && roster.len() >= 2 && me.is(author) {
|
||||
return Err(TeamError::NotEligible("the release's author may not approve it here"));
|
||||
}
|
||||
if rule.approvals > 0 && rule.others && roster.len() >= 2 && !roster.iter().any(|m| m.is(author)) {
|
||||
return Err(TeamError::NotEligible("the release's author is not a member the team knows"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ pub struct SignReply {
|
||||
pub key: ReplyKey,
|
||||
pub signer: ReplySigner,
|
||||
pub proof: Proof,
|
||||
/// The deployment ticket (core 0.18.1): 32 random bytes, base64, for the `mac` of this deployment's
|
||||
/// `target.request`s. Secret: it travels only inside the sealed reply; never log it.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub ticket: Option<String>,
|
||||
}
|
||||
|
||||
impl SignReply {
|
||||
|
||||
@@ -258,6 +258,9 @@ pub struct TargetRequest {
|
||||
pub deployment: String,
|
||||
pub public: [u8; 32],
|
||||
pub expires: u64,
|
||||
/// HMAC-SHA256 with the deployment's ticket (core 0.18.1): only the Fabrica that opened the signing reply has the
|
||||
/// ticket, so only it can ask for the deployment's credentials.
|
||||
pub mac: [u8; 32],
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -272,9 +275,50 @@ struct TargetJson {
|
||||
#[serde(rename = "pub")]
|
||||
public: String,
|
||||
expires: u64,
|
||||
mac: String,
|
||||
}
|
||||
|
||||
/// The domain of a target request's MAC.
|
||||
pub const TARGET_MAC_DOMAIN: &[u8] = b"custos team target v1\0";
|
||||
|
||||
impl TargetRequest {
|
||||
/// The text the MAC covers: the canonical request without `mac`.
|
||||
fn unsigned(&self) -> String {
|
||||
let mut o = String::with_capacity(256);
|
||||
o.push_str("{\"v\":1,\"op\":\"target.request\",\"team\":");
|
||||
canon::string(&mut o, &self.team);
|
||||
o.push_str(",\"id\":");
|
||||
canon::string(&mut o, &self.id);
|
||||
o.push_str(",\"target\":");
|
||||
canon::string(&mut o, &self.target);
|
||||
o.push_str(",\"deployment\":");
|
||||
canon::string(&mut o, &self.deployment);
|
||||
o.push_str(",\"pub\":");
|
||||
canon::string(&mut o, &b64(&self.public));
|
||||
o.push_str(",\"expires\":");
|
||||
o.push_str(&self.expires.to_string());
|
||||
o
|
||||
}
|
||||
|
||||
fn mac_over(&self, ticket: &[u8; 32]) -> hmac::Hmac<sha2::Sha256> {
|
||||
use hmac::KeyInit;
|
||||
let mut m = <hmac::Hmac<sha2::Sha256> as KeyInit>::new_from_slice(ticket).expect("any key length");
|
||||
hmac::Mac::update(&mut m, TARGET_MAC_DOMAIN);
|
||||
hmac::Mac::update(&mut m, self.unsigned().as_bytes());
|
||||
m
|
||||
}
|
||||
|
||||
/// Sets `mac` with the deployment's ticket (from the sealed `sign.reply`).
|
||||
pub fn sign_with(mut self, ticket: &[u8; 32]) -> TargetRequest {
|
||||
self.mac = hmac::Mac::finalize(self.mac_over(ticket)).into_bytes().into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether `mac` was made with this ticket (constant time).
|
||||
pub fn mac_ok(&self, ticket: &[u8; 32]) -> bool {
|
||||
hmac::Mac::verify_slice(self.mac_over(ticket), &self.mac).is_ok()
|
||||
}
|
||||
|
||||
pub fn canonical(&self) -> String {
|
||||
let mut o = String::with_capacity(256);
|
||||
o.push_str("{\"v\":1,\"op\":\"target.request\",\"team\":");
|
||||
@@ -289,6 +333,8 @@ impl TargetRequest {
|
||||
canon::string(&mut o, &b64(&self.public));
|
||||
o.push_str(",\"expires\":");
|
||||
o.push_str(&self.expires.to_string());
|
||||
o.push_str(",\"mac\":");
|
||||
canon::string(&mut o, &b64(&self.mac));
|
||||
o.push('}');
|
||||
o
|
||||
}
|
||||
@@ -309,6 +355,9 @@ impl TargetRequest {
|
||||
deployment: j.deployment,
|
||||
public: pub_key(&j.public)?,
|
||||
expires: j.expires,
|
||||
mac: unb64(&j.mac)
|
||||
.and_then(|m| m.try_into().ok())
|
||||
.ok_or(TeamError::Invalid("mac is not base64 of 32 bytes"))?,
|
||||
};
|
||||
if !id_ok(&r.team) || !id_ok(&r.id) || !lower_hex(&r.target, 16) || !lower_hex(&r.deployment, 64) {
|
||||
return Err(TeamError::Invalid("team, id, target and deployment are hex ids"));
|
||||
|
||||
Reference in New Issue
Block a user