Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47146a6ea2 | |||
| 98d56f4673 | |||
| f95c768bfa |
Generated
+14
-13
@@ -329,14 +329,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-browser"
|
name = "custos-browser"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-gen"
|
name = "custos-gen"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -348,7 +348,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-kdbx"
|
name = "custos-kdbx"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"argon2",
|
"argon2",
|
||||||
@@ -369,7 +369,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-keys"
|
name = "custos-keys"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
@@ -382,7 +382,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-native"
|
name = "custos-native"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-browser",
|
"custos-browser",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -392,11 +392,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-qr"
|
name = "custos-qr"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-seal"
|
name = "custos-seal"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
"hkdf",
|
"hkdf",
|
||||||
@@ -409,7 +409,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-share"
|
name = "custos-share"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
@@ -426,7 +426,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-sign"
|
name = "custos-sign"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2 0.10.6",
|
"blake2 0.10.6",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -446,12 +446,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-team"
|
name = "custos-team"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-seal",
|
"custos-seal",
|
||||||
"custos-sign",
|
"custos-sign",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
|
"hmac 0.13.0",
|
||||||
"minisign-verify",
|
"minisign-verify",
|
||||||
"rand 0.10.3",
|
"rand 0.10.3",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -463,7 +464,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-totp"
|
name = "custos-totp"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -476,7 +477,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-vault"
|
name = "custos-vault"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"bip39",
|
"bip39",
|
||||||
@@ -502,7 +503,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-wasm"
|
name = "custos-wasm"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-qr",
|
"custos-qr",
|
||||||
"custos-seal",
|
"custos-seal",
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ custos-seal = { path = "../custos-seal" }
|
|||||||
custos-sign = { path = "../custos-sign" }
|
custos-sign = { path = "../custos-sign" }
|
||||||
ed25519-dalek = { version = "2", default-features = false, features = ["std", "zeroize"] }
|
ed25519-dalek = { version = "2", default-features = false, features = ["std", "zeroize"] }
|
||||||
sha2.workspace = true
|
sha2.workspace = true
|
||||||
|
hmac.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
data-encoding.workspace = true
|
data-encoding.workspace = true
|
||||||
|
|||||||
@@ -244,8 +244,13 @@ pub fn evaluate(policy: &Policy, roster: &[RosterMember], env: &str, author: &st
|
|||||||
ignored.push(a.clone());
|
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 {
|
let verdict = if rule.approvals == 0 {
|
||||||
Verdict::Allowed(KeyRole::Test)
|
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 {
|
} else if counted.len() >= rule.approvals as usize {
|
||||||
Verdict::Allowed(KeyRole::Release)
|
Verdict::Allowed(KeyRole::Release)
|
||||||
} else if eligible.len() < rule.approvals as usize {
|
} 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) {
|
if rule.others && roster.len() >= 2 && me.is(author) {
|
||||||
return Err(TeamError::NotEligible("the release's author may not approve it here"));
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ pub struct SignReply {
|
|||||||
pub key: ReplyKey,
|
pub key: ReplyKey,
|
||||||
pub signer: ReplySigner,
|
pub signer: ReplySigner,
|
||||||
pub proof: Proof,
|
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 {
|
impl SignReply {
|
||||||
|
|||||||
@@ -258,6 +258,9 @@ pub struct TargetRequest {
|
|||||||
pub deployment: String,
|
pub deployment: String,
|
||||||
pub public: [u8; 32],
|
pub public: [u8; 32],
|
||||||
pub expires: u64,
|
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)]
|
#[derive(Deserialize)]
|
||||||
@@ -272,9 +275,50 @@ struct TargetJson {
|
|||||||
#[serde(rename = "pub")]
|
#[serde(rename = "pub")]
|
||||||
public: String,
|
public: String,
|
||||||
expires: u64,
|
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 {
|
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 {
|
pub fn canonical(&self) -> String {
|
||||||
let mut o = String::with_capacity(256);
|
let mut o = String::with_capacity(256);
|
||||||
o.push_str("{\"v\":1,\"op\":\"target.request\",\"team\":");
|
o.push_str("{\"v\":1,\"op\":\"target.request\",\"team\":");
|
||||||
@@ -289,6 +333,8 @@ impl TargetRequest {
|
|||||||
canon::string(&mut o, &b64(&self.public));
|
canon::string(&mut o, &b64(&self.public));
|
||||||
o.push_str(",\"expires\":");
|
o.push_str(",\"expires\":");
|
||||||
o.push_str(&self.expires.to_string());
|
o.push_str(&self.expires.to_string());
|
||||||
|
o.push_str(",\"mac\":");
|
||||||
|
canon::string(&mut o, &b64(&self.mac));
|
||||||
o.push('}');
|
o.push('}');
|
||||||
o
|
o
|
||||||
}
|
}
|
||||||
@@ -309,6 +355,9 @@ impl TargetRequest {
|
|||||||
deployment: j.deployment,
|
deployment: j.deployment,
|
||||||
public: pub_key(&j.public)?,
|
public: pub_key(&j.public)?,
|
||||||
expires: j.expires,
|
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) {
|
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"));
|
return Err(TeamError::Invalid("team, id, target and deployment are hex ids"));
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ fn expected(n: usize, env: &str, author_is_member: bool, set: &[String]) -> Verd
|
|||||||
}
|
}
|
||||||
"production" => {
|
"production" => {
|
||||||
// "1 by someone other than the release author when the team has 2+ members"
|
// "1 by someone other than the release author when the team has 2+ members"
|
||||||
|
// ... and the rule must know the author: someone no member is (or nobody named) cannot be excluded.
|
||||||
|
if n >= 2 && !author_is_member {
|
||||||
|
return Verdict::Unsatisfiable(
|
||||||
|
"the release's author is not a member the team knows, so the rule cannot exclude them",
|
||||||
|
);
|
||||||
|
}
|
||||||
let author_excluded = n >= 2 && author_is_member;
|
let author_excluded = n >= 2 && author_is_member;
|
||||||
let counted = distinct.iter().filter(|m| !(author_excluded && m.as_str() == id(0))).count();
|
let counted = distinct.iter().filter(|m| !(author_excluded && m.as_str() == id(0))).count();
|
||||||
if counted >= 1 { Verdict::Allowed(KeyRole::Release) } else { Verdict::Need(1) }
|
if counted >= 1 { Verdict::Allowed(KeyRole::Release) } else { Verdict::Need(1) }
|
||||||
@@ -125,11 +131,14 @@ fn several_approvals_others_and_approver_lists() {
|
|||||||
evaluate(&p, &three, "production", "mnovak", &[id(1), id(2)]).verdict,
|
evaluate(&p, &three, "production", "mnovak", &[id(1), id(2)]).verdict,
|
||||||
Verdict::Allowed(KeyRole::Release)
|
Verdict::Allowed(KeyRole::Release)
|
||||||
);
|
);
|
||||||
// Someone not named as the author (a release by a non-member): every member counts.
|
// Someone no member is, or nobody named: the rule cannot exclude the author, so it refuses (core 0.18.1).
|
||||||
assert_eq!(
|
for author in ["stranger", ""] {
|
||||||
evaluate(&p, &three, "production", "stranger", &[id(0), id(1)]).verdict,
|
assert!(matches!(
|
||||||
Verdict::Allowed(KeyRole::Release)
|
evaluate(&p, &three, "production", author, &[id(0), id(1)]).verdict,
|
||||||
);
|
Verdict::Unsatisfiable(_)
|
||||||
|
));
|
||||||
|
assert!(matches!(may_approve(&p, &three, "production", author, &id(1)), Err(TeamError::NotEligible(_))));
|
||||||
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
|
|||||||
@@ -105,6 +105,13 @@ pub(crate) struct SignerJson {
|
|||||||
by: String,
|
by: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub(crate) struct Ticket {
|
||||||
|
request: String,
|
||||||
|
ticket: SecretString,
|
||||||
|
at: u64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub(crate) struct Seen {
|
pub(crate) struct Seen {
|
||||||
request: String,
|
request: String,
|
||||||
@@ -153,6 +160,9 @@ pub(crate) struct TeamJson {
|
|||||||
signers: Vec<SignerJson>,
|
signers: Vec<SignerJson>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
seen: Vec<Seen>,
|
seen: Vec<Seen>,
|
||||||
|
/// The deployment tickets of requests signed here (core 0.18.1), kept 25 hours.
|
||||||
|
#[serde(default)]
|
||||||
|
tickets: Vec<Ticket>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
audit: Vec<TeamAuditEntry>,
|
audit: Vec<TeamAuditEntry>,
|
||||||
}
|
}
|
||||||
@@ -196,6 +206,7 @@ pub(crate) struct TeamState {
|
|||||||
targets: Vec<Target>,
|
targets: Vec<Target>,
|
||||||
signers: Vec<Signer>,
|
signers: Vec<Signer>,
|
||||||
seen: Vec<Seen>,
|
seen: Vec<Seen>,
|
||||||
|
tickets: Vec<Ticket>,
|
||||||
audit: Vec<TeamAuditEntry>,
|
audit: Vec<TeamAuditEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,6 +302,7 @@ impl TeamState {
|
|||||||
targets,
|
targets,
|
||||||
signers,
|
signers,
|
||||||
seen: j.seen,
|
seen: j.seen,
|
||||||
|
tickets: j.tickets,
|
||||||
audit: j.audit,
|
audit: j.audit,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -340,6 +352,15 @@ impl TeamState {
|
|||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
seen: self.seen.clone(),
|
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(),
|
audit: self.audit.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,6 +625,7 @@ impl Vault {
|
|||||||
targets: Vec::new(),
|
targets: Vec::new(),
|
||||||
signers: Vec::new(),
|
signers: Vec::new(),
|
||||||
seen: Vec::new(),
|
seen: Vec::new(),
|
||||||
|
tickets: Vec::new(),
|
||||||
audit: Vec::new(),
|
audit: Vec::new(),
|
||||||
};
|
};
|
||||||
state.log(now, TeamAction::TeamCreated, &me.id(), Some(name.into()));
|
state.log(now, TeamAction::TeamCreated, &me.id(), Some(name.into()));
|
||||||
@@ -978,6 +1000,12 @@ impl Vault {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let key = format!("target:{}:{}", target.id, req.deployment);
|
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) {
|
if t.is_seen(&key) {
|
||||||
return Err(team_err(TeamError::Replayed));
|
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.
|
/// 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)?;
|
||||||
|
if self.team()?.is_seen(&req.hash_hex()) {
|
||||||
|
return Err(team_err(TeamError::Replayed));
|
||||||
|
}
|
||||||
let entry =
|
let entry =
|
||||||
self.team_audit_entry(&req, Outcome::Refused, by, Some(reason.chars().take(200).collect()), None, &[], now);
|
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);
|
||||||
@@ -1192,6 +1223,8 @@ impl Vault {
|
|||||||
let eval = evaluate(&t.policy, &roster, &req.env, &req.author, &approvers);
|
let eval = evaluate(&t.policy, &roster, &req.env, &req.author, &approvers);
|
||||||
let role = eval.clone().into_result()?;
|
let role = eval.clone().into_result()?;
|
||||||
let (key_id, envelope, payload, public) = self.team_envelope(&req, role, external, now_s)?;
|
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 t = self.team.as_ref().expect("checked");
|
||||||
let (policy_text, policy_sig) = (t.policy.canonical(), t.policy_sig);
|
let (policy_text, policy_sig) = (t.policy.canonical(), t.policy_sig);
|
||||||
let proof = ProofBody {
|
let proof = ProofBody {
|
||||||
@@ -1219,6 +1252,7 @@ impl Vault {
|
|||||||
key: ReplyKey { id: key_id.clone(), public },
|
key: ReplyKey { id: key_id.clone(), public },
|
||||||
signer: ReplySigner { member: me.clone(), name: me_member.name.clone() },
|
signer: ReplySigner { member: me.clone(), name: me_member.name.clone() },
|
||||||
proof,
|
proof,
|
||||||
|
ticket: Some(b64(ticket.as_ref())),
|
||||||
};
|
};
|
||||||
let outcome = if role == KeyRole::Release { Outcome::Approved } else { Outcome::Auto };
|
let outcome = if role == KeyRole::Release { Outcome::Approved } else { Outcome::Auto };
|
||||||
let mut entry = self.team_audit_entry(
|
let mut entry = self.team_audit_entry(
|
||||||
@@ -1233,7 +1267,10 @@ impl Vault {
|
|||||||
entry.key = key_id;
|
entry.key = key_id;
|
||||||
self.signing.audit.push(entry);
|
self.signing.audit.push(entry);
|
||||||
let hash = req.hash_hex();
|
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)
|
Ok(reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,6 +240,8 @@ fn wrong_and_replayed_match_codes_are_refused() {
|
|||||||
assert!(matches!(t.vault.team_sign(&text, &[], &t.a, Some(&code), None, NOW), Err(TeamError::NotEligible(_))));
|
assert!(matches!(t.vault.team_sign(&text, &[], &t.a, Some(&code), None, NOW), Err(TeamError::NotEligible(_))));
|
||||||
// Petra with the right code signs.
|
// Petra with the right code signs.
|
||||||
let reply = t.vault.team_sign(&text, &[], &t.b, Some(&code), None, NOW).unwrap();
|
let reply = t.vault.team_sign(&text, &[], &t.b, Some(&code), None, NOW).unwrap();
|
||||||
|
// A refusal after the signature is refused too: nothing contradicts what was signed (core 0.18.1).
|
||||||
|
assert!(t.vault.team_refuse(&text, &t.a.id(), "late", NOW).unwrap_err().to_string().contains("replay"));
|
||||||
// The same request again (a replay): refused, by this vault, whoever asks.
|
// The same request again (a replay): refused, by this vault, whoever asks.
|
||||||
assert_eq!(t.vault.team_sign(&text, &[], &t.b, Some(&code), None, NOW).unwrap_err(), TeamError::Replayed);
|
assert_eq!(t.vault.team_sign(&text, &[], &t.b, Some(&code), None, NOW).unwrap_err(), TeamError::Replayed);
|
||||||
assert_eq!(t.vault.team_check_request(&text, NOW).unwrap_err(), TeamError::Replayed);
|
assert_eq!(t.vault.team_check_request(&text, NOW).unwrap_err(), TeamError::Replayed);
|
||||||
@@ -413,7 +415,10 @@ 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| {
|
let ticket_of = |r: &custos_team::reply::SignReply| -> [u8; 32] {
|
||||||
|
data_encoding::BASE64.decode(r.ticket.as_deref().unwrap().as_bytes()).unwrap().try_into().unwrap()
|
||||||
|
};
|
||||||
|
let ask = |deployment: &str, ticket: &[u8; 32]| {
|
||||||
TargetRequest {
|
TargetRequest {
|
||||||
team: team_id.clone(),
|
team: team_id.clone(),
|
||||||
id: custos_team::new_id(),
|
id: custos_team::new_id(),
|
||||||
@@ -421,18 +426,24 @@ fn a_target_credential_is_released_once_for_a_signed_deployment_of_its_project_a
|
|||||||
deployment: deployment.into(),
|
deployment: deployment.into(),
|
||||||
public: fabrica.public(),
|
public: fabrica.public(),
|
||||||
expires: NOW_S + 600,
|
expires: NOW_S + 600,
|
||||||
|
mac: [0; 32],
|
||||||
}
|
}
|
||||||
|
.sign_with(ticket)
|
||||||
.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, &[1; 32]), &t.b.id(), NOW).is_err());
|
||||||
// A staging deployment is not a production one.
|
// A staging deployment is not a production one.
|
||||||
let staging = request(&t.vault, "staging", "mnovak", Format::Minisign, &fabrica);
|
let staging = request(&t.vault, "staging", "mnovak", Format::Minisign, &fabrica);
|
||||||
let r = t.vault.team_sign(&staging, &[], &t.a, Some(&fabrica.match_code()), None, NOW).unwrap();
|
let r = t.vault.team_sign(&staging, &[], &t.a, Some(&fabrica.match_code()), None, NOW).unwrap();
|
||||||
assert!(t.vault.team_target_release(&ask(&r.request), &t.b.id(), NOW).is_err());
|
assert!(t.vault.team_target_release(&ask(&r.request, &ticket_of(&r)), &t.b.id(), NOW).is_err());
|
||||||
let prod = request(&t.vault, "production", "mnovak", Format::Minisign, &fabrica);
|
let prod = request(&t.vault, "production", "mnovak", Format::Minisign, &fabrica);
|
||||||
let r = t.vault.team_sign(&prod, &[], &t.b, Some(&fabrica.match_code()), None, NOW).unwrap();
|
let r = t.vault.team_sign(&prod, &[], &t.b, Some(&fabrica.match_code()), None, NOW).unwrap();
|
||||||
|
// Someone who knows the deployment's hash (the service, another connection) but not its ticket gets nothing.
|
||||||
|
let e = t.vault.team_target_release(&ask(&r.request, &[7; 32]), &t.b.id(), NOW).unwrap_err();
|
||||||
|
assert!(e.to_string().contains("ticket"), "{e}");
|
||||||
|
let ask = |deployment: &str| ask(deployment, &ticket_of(&r));
|
||||||
let (json, req) = t.vault.team_target_release(&ask(&r.request), &t.b.id(), NOW).unwrap();
|
let (json, req) = t.vault.team_target_release(&ask(&r.request), &t.b.id(), NOW).unwrap();
|
||||||
let released: TargetRelease = serde_json::from_str(&json).unwrap();
|
let released: TargetRelease = serde_json::from_str(&json).unwrap();
|
||||||
assert_eq!((released.secret.as_str(), released.env.as_str()), ("apiVersion: v1\nkind: Config\n", "production"));
|
assert_eq!((released.secret.as_str(), released.env.as_str()), ("apiVersion: v1\nkind: Config\n", "production"));
|
||||||
|
|||||||
+24
-3
@@ -1,4 +1,4 @@
|
|||||||
# Team vaults, policies and team signing (core 0.18.0)
|
# Team vaults, policies and team signing (core 0.18.0; review fixes 0.18.1)
|
||||||
|
|
||||||
A **team vault** is a `.custos` file that a small team (1 to 32 people) shares: the team's release-signing keys,
|
A **team vault** is a `.custos` file that a small team (1 to 32 people) shares: the team's release-signing keys,
|
||||||
its target credentials, its external-signer credentials and its approval policy. Each member opens it with the
|
its target credentials, its external-signer credentials and its approval policy. Each member opens it with the
|
||||||
@@ -159,7 +159,9 @@ its own production releases (the `others` rule needs two members); when a second
|
|||||||
1. No rule for `env`: `UnknownEnv`.
|
1. No rule for `env`: `UnknownEnv`.
|
||||||
2. `approvals == 0`: `Allowed { key_role: Test }`.
|
2. `approvals == 0`: `Allowed { key_role: Test }`.
|
||||||
3. Eligible = roster members in `approvers` (or all); minus the author when `others` and the roster has ≥ 2 members.
|
3. Eligible = roster members in `approvers` (or all); minus the author when `others` and the roster has ≥ 2 members.
|
||||||
The author is the member whose id equals `author` or whose handles contain it.
|
The author is the member whose id equals `author` or whose handles contain it. Under `others` with 2+ members,
|
||||||
|
an author no member is (or an empty one) is `Unsatisfiable` (core 0.18.1): the rule cannot exclude someone it
|
||||||
|
cannot recognise, so it refuses instead of letting anyone approve.
|
||||||
4. Counted = distinct eligible members among `approvers` given. Members not on the roster, ineligible members and
|
4. Counted = distinct eligible members among `approvers` given. Members not on the roster, ineligible members and
|
||||||
duplicates are not counted (and listed in `ignored`).
|
duplicates are not counted (and listed in `ignored`).
|
||||||
5. Counted ≥ `approvals`: `Allowed { key_role: Release }`. Eligible < `approvals`: `Unsatisfiable` (no set of
|
5. Counted ≥ `approvals`: `Allowed { key_role: Release }`. Eligible < `approvals`: `Unsatisfiable` (no set of
|
||||||
@@ -274,13 +276,32 @@ layer's bytes, which are this payload.
|
|||||||
|
|
||||||
A target credential is handed to the Fabrica server for one deployment: `team_target_release(target id, request,
|
A target credential is handed to the Fabrica server for one deployment: `team_target_release(target id, request,
|
||||||
deployment, now)` returns the plaintext to seal, only when the target's `project` and `env` equal the deployment's,
|
deployment, now)` returns the plaintext to seal, only when the target's `project` and `env` equal the deployment's,
|
||||||
and records `target-released` with the deployment's request hash. One release per (target, deployment): a second
|
**and the request's `mac` was made with that deployment's ticket** (core 0.18.1), and records `target-released`
|
||||||
|
with the deployment's request hash.
|
||||||
|
|
||||||
|
**The ticket.** `team_sign` makes 32 random bytes per signed request, keeps them in the team body (`tickets`, 25
|
||||||
|
hours) and puts them in the reply (`"ticket"`, base64), which only the requester can open. A `target.request` ends
|
||||||
|
with `"mac":"<base64>"`: HMAC-SHA256(ticket, `"custos team target v1\0"` ‖ the canonical request up to and including
|
||||||
|
`"expires":N`, without the closing brace). Knowing a deployment's hash (the service stores every request text; a
|
||||||
|
proof names it) is not enough: without the ticket nobody else, not the service and not another connection, can ask
|
||||||
|
for its credentials or use up its one release. One release per (target, deployment): a second
|
||||||
call is `Replayed`. The app seals it to the server's one-time key (`team-target:<id>`); the service hands the box
|
call is `Replayed`. The app seals it to the server's one-time key (`team-target:<id>`); the service hands the box
|
||||||
out once, to the caller that asked (Custos `docs/27_team_vault.md`).
|
out once, to the caller that asked (Custos `docs/27_team_vault.md`).
|
||||||
|
|
||||||
`kind`: `ssh-key` (an OpenSSH private key), `winrm` (user and password), `openssh` (user and password),
|
`kind`: `ssh-key` (an OpenSSH private key), `winrm` (user and password), `openssh` (user and password),
|
||||||
`registry` (a Docker registry token), `kubeconfig` (the kubeconfig text). `secret` ≤ 64 KiB.
|
`registry` (a Docker registry token), `kubeconfig` (the kubeconfig text). `secret` ≤ 64 KiB.
|
||||||
|
|
||||||
|
## Limits (known, not fixed in 0.18.x)
|
||||||
|
|
||||||
|
- **Every member holds the team's secrets in their Custos**: the team identity, the release keys and the credentials
|
||||||
|
are in the body every member decrypts. Custos never hands them out, but a member running a modified build of the
|
||||||
|
public core can copy them before they are removed, and then sign directly, write proofs, or build a fork at a higher
|
||||||
|
epoch for the remaining members, which `member_note_team` would accept as current. Removing a member you no longer
|
||||||
|
trust means a new team (new identity, new keys), not only a new epoch.
|
||||||
|
- **Any member can change the policy.** `team_set_rule` is one member's action (audited as `policy-set`, signed by the
|
||||||
|
identity). A member who loosens production and then signs their own release passes `verify_proof`. Policy changes
|
||||||
|
that need the current policy's approvals are future work; until then, review the team audit.
|
||||||
|
|
||||||
## Crates
|
## Crates
|
||||||
|
|
||||||
`custos-team` (pure): member keys, wrapping, policy, request, statements, proof, envelopes, on `ed25519-dalek`,
|
`custos-team` (pure): member keys, wrapping, policy, request, statements, proof, envelopes, on `ed25519-dalek`,
|
||||||
|
|||||||
Reference in New Issue
Block a user