[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:
2026-11-17 12:44:54 +01:00
parent f95c768bfa
commit 98d56f4673
10 changed files with 167 additions and 26 deletions
+38 -1
View File
@@ -105,6 +105,13 @@ pub(crate) struct SignerJson {
by: String,
}
#[derive(Serialize, Deserialize)]
pub(crate) struct Ticket {
request: String,
ticket: SecretString,
at: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Seen {
request: String,
@@ -153,6 +160,9 @@ pub(crate) struct TeamJson {
signers: Vec<SignerJson>,
#[serde(default)]
seen: Vec<Seen>,
/// The deployment tickets of requests signed here (core 0.18.1), kept 25 hours.
#[serde(default)]
tickets: Vec<Ticket>,
#[serde(default)]
audit: Vec<TeamAuditEntry>,
}
@@ -196,6 +206,7 @@ pub(crate) struct TeamState {
targets: Vec<Target>,
signers: Vec<Signer>,
seen: Vec<Seen>,
tickets: Vec<Ticket>,
audit: Vec<TeamAuditEntry>,
}
@@ -291,6 +302,7 @@ impl TeamState {
targets,
signers,
seen: j.seen,
tickets: j.tickets,
audit: j.audit,
})
}
@@ -340,6 +352,15 @@ impl TeamState {
})
.collect(),
seen: self.seen.clone(),
tickets: self
.tickets
.iter()
.map(|t| Ticket {
request: t.request.clone(),
ticket: SecretString::new(t.ticket.expose().to_owned()),
at: t.at,
})
.collect(),
audit: self.audit.clone(),
}
}
@@ -604,6 +625,7 @@ impl Vault {
targets: Vec::new(),
signers: Vec::new(),
seen: Vec::new(),
tickets: Vec::new(),
audit: Vec::new(),
};
state.log(now, TeamAction::TeamCreated, &me.id(), Some(name.into()));
@@ -978,6 +1000,12 @@ impl Vault {
)));
}
let key = format!("target:{}:{}", target.id, req.deployment);
// Only the Fabrica that opened this deployment's signing reply holds its ticket (docs/TEAM.md).
let ticket: Option<[u8; 32]> =
t.tickets.iter().find(|x| x.request == req.deployment).and_then(|x| unhex(x.ticket.expose()));
if !ticket.is_some_and(|k| req.mac_ok(&k)) {
return Err(Error::Team("the request does not carry this deployment's ticket".into()));
}
if t.is_seen(&key) {
return Err(team_err(TeamError::Replayed));
}
@@ -1108,6 +1136,9 @@ impl Vault {
/// 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> {
let req = SignRequest::parse(text).map_err(team_err)?;
if self.team()?.is_seen(&req.hash_hex()) {
return Err(team_err(TeamError::Replayed));
}
let entry =
self.team_audit_entry(&req, Outcome::Refused, by, Some(reason.chars().take(200).collect()), None, &[], now);
self.signing.audit.push(entry);
@@ -1192,6 +1223,8 @@ impl Vault {
let eval = evaluate(&t.policy, &roster, &req.env, &req.author, &approvers);
let role = eval.clone().into_result()?;
let (key_id, envelope, payload, public) = self.team_envelope(&req, role, external, now_s)?;
let mut ticket = Zeroizing::new([0u8; 32]);
crypto::fill_random(ticket.as_mut());
let t = self.team.as_ref().expect("checked");
let (policy_text, policy_sig) = (t.policy.canonical(), t.policy_sig);
let proof = ProofBody {
@@ -1219,6 +1252,7 @@ impl Vault {
key: ReplyKey { id: key_id.clone(), public },
signer: ReplySigner { member: me.clone(), name: me_member.name.clone() },
proof,
ticket: Some(b64(ticket.as_ref())),
};
let outcome = if role == KeyRole::Release { Outcome::Approved } else { Outcome::Auto };
let mut entry = self.team_audit_entry(
@@ -1233,7 +1267,10 @@ impl Vault {
entry.key = key_id;
self.signing.audit.push(entry);
let hash = req.hash_hex();
self.team.as_mut().expect("checked").mark_seen(hash, now_s);
let t = self.team.as_mut().expect("checked");
t.tickets.retain(|x| x.at + MAX_AHEAD_SECS > now_s);
t.tickets.push(Ticket { request: hash.clone(), ticket: SecretString::new(hex(ticket.as_ref())), at: now_s });
t.mark_seen(hash, now_s);
Ok(reply)
}