Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0eee7632ae | |||
| 6588461438 | |||
| e533a38883 | |||
| 47146a6ea2 | |||
| 98d56f4673 |
Generated
+14
-13
@@ -329,14 +329,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-browser"
|
name = "custos-browser"
|
||||||
version = "0.18.0"
|
version = "0.19.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-gen"
|
name = "custos-gen"
|
||||||
version = "0.18.0"
|
version = "0.19.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.19.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.19.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.19.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.19.1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-seal"
|
name = "custos-seal"
|
||||||
version = "0.18.0"
|
version = "0.19.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.19.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.19.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.19.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.19.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.19.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.19.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.19.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();
|
||||||
|
|||||||
@@ -829,6 +829,29 @@ mod tests {
|
|||||||
assert_eq!(full.standing_rules()[0].uses, u64::MAX);
|
assert_eq!(full.standing_rules()[0].uses, u64::MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_broken_android_grant_makes_the_vault_refuse_to_open() {
|
||||||
|
let mut v = vault();
|
||||||
|
v.android_grant_set(&["mnovak/*".to_string()], "Marek Novak", "CZ", NOW).unwrap();
|
||||||
|
let json = body_json(&v);
|
||||||
|
assert!(Vault::open(&with_body(&v, &json), &SecretString::from("pw")).is_ok());
|
||||||
|
let from = r#""repos":["mnovak/*"],"o":"Marek Novak","c":"CZ""#;
|
||||||
|
assert!(json.contains(from), "{json}");
|
||||||
|
for to in [
|
||||||
|
r#""repos":["*/*"],"o":"Marek Novak","c":"CZ""#,
|
||||||
|
r#""repos":["*"],"o":"Marek Novak","c":"CZ""#,
|
||||||
|
r#""repos":[],"o":"Marek Novak","c":"CZ""#,
|
||||||
|
r#""repos":["mnovak/*","mnovak/*"],"o":"Marek Novak","c":"CZ""#,
|
||||||
|
r#""repos":["mnovak/*"],"o":"","c":"CZ""#,
|
||||||
|
r#""repos":["mnovak/*"],"o":"Marek Novak","c":"Czech""#,
|
||||||
|
r#""repos":["mnovak/*"],"o":"Marek Novak","c":"CZ","made":["Not An Id"]"#,
|
||||||
|
] {
|
||||||
|
let bad = json.replacen(from, to, 1);
|
||||||
|
let r = Vault::open(&with_body(&v, &bad), &SecretString::from("pw"));
|
||||||
|
assert!(matches!(r, Err(Error::Corrupted)), "{to}: {r:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_broken_standing_approval_makes_the_vault_refuse_to_open() {
|
fn a_broken_standing_approval_makes_the_vault_refuse_to_open() {
|
||||||
let v = vault_with_a_standing_approval();
|
let v = vault_with_a_standing_approval();
|
||||||
|
|||||||
@@ -203,6 +203,35 @@ pub struct StandingRule {
|
|||||||
/// At most this many standing approvals in a vault.
|
/// At most this many standing approvals in a vault.
|
||||||
pub const STANDING_MAX: usize = 256;
|
pub const STANDING_MAX: usize = 256;
|
||||||
|
|
||||||
|
/// The Android grant (core 0.19.0, docs/SIGNING.md "The Android grant"): Mark's one answer for every Domi app's
|
||||||
|
/// release APK. It signs an app key's APKs from this PC's pipe, its first signature included, and makes the key when
|
||||||
|
/// the app's first release asks. Nothing in it is secret.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct AndroidGrant {
|
||||||
|
/// `owner/name` or `owner/*`, 1 to [`ANDROID_PATTERNS_MAX`].
|
||||||
|
pub repos: Vec<String>,
|
||||||
|
/// The organisation and country in the certificates of the keys it makes.
|
||||||
|
pub o: String,
|
||||||
|
pub c: String,
|
||||||
|
/// Unix milliseconds: when Mark granted it, or last changed it.
|
||||||
|
pub granted: i64,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub last_used: Option<i64>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub uses: u64,
|
||||||
|
/// The ids of the keys it made, oldest first.
|
||||||
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
|
pub made: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The one pipeline the Android grant covers.
|
||||||
|
pub const ANDROID_PIPELINE: &str = "release";
|
||||||
|
/// At most this many repository patterns in the Android grant.
|
||||||
|
pub const ANDROID_PATTERNS_MAX: usize = 64;
|
||||||
|
/// At most this many keys the Android grant remembers making.
|
||||||
|
const ANDROID_MADE_MAX: usize = 256;
|
||||||
|
|
||||||
/// A signature handed back to the build.
|
/// A signature handed back to the build.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Signed {
|
pub struct Signed {
|
||||||
@@ -269,6 +298,7 @@ pub(crate) struct Store {
|
|||||||
pub(crate) keys: Vec<Key>,
|
pub(crate) keys: Vec<Key>,
|
||||||
pub(crate) audit: Vec<AuditEntry>,
|
pub(crate) audit: Vec<AuditEntry>,
|
||||||
standing: Vec<StandingRule>,
|
standing: Vec<StandingRule>,
|
||||||
|
android: Option<AndroidGrant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -303,6 +333,9 @@ pub(crate) struct StoreJson {
|
|||||||
/// Standing approvals (core 0.16.0); absent while there are none.
|
/// Standing approvals (core 0.16.0); absent while there are none.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
standing: Vec<StandingRule>,
|
standing: Vec<StandingRule>,
|
||||||
|
/// The Android grant (core 0.19.0); absent while there is none. Older cores ignore and drop it.
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
android: Option<AndroidGrant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn b64(bytes: &[u8]) -> String {
|
fn b64(bytes: &[u8]) -> String {
|
||||||
@@ -330,7 +363,7 @@ fn unhex8(s: &str) -> Option<[u8; 8]> {
|
|||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
pub(crate) fn is_empty(&self) -> bool {
|
pub(crate) fn is_empty(&self) -> bool {
|
||||||
self.keys.is_empty() && self.audit.is_empty() && self.standing.is_empty()
|
self.keys.is_empty() && self.audit.is_empty() && self.standing.is_empty() && self.android.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_json(j: StoreJson) -> Option<Store> {
|
pub(crate) fn from_json(j: StoreJson) -> Option<Store> {
|
||||||
@@ -389,7 +422,10 @@ impl Store {
|
|||||||
if j.standing.len() > STANDING_MAX || !j.standing.iter().all(rule_ok) {
|
if j.standing.len() > STANDING_MAX || !j.standing.iter().all(rule_ok) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Store { keys, audit: j.audit, standing: j.standing })
|
if j.android.as_ref().is_some_and(|g| !grant_ok(g)) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(Store { keys, audit: j.audit, standing: j.standing, android: j.android })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn json(&self) -> Option<StoreJson> {
|
pub(crate) fn json(&self) -> Option<StoreJson> {
|
||||||
@@ -418,7 +454,12 @@ impl Store {
|
|||||||
repos: k.repos.clone(),
|
repos: k.repos.clone(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Some(StoreJson { keys, audit: self.audit.clone(), standing: self.standing.clone() })
|
Some(StoreJson {
|
||||||
|
keys,
|
||||||
|
audit: self.audit.clone(),
|
||||||
|
standing: self.standing.clone(),
|
||||||
|
android: self.android.clone(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get(&self, id: &str) -> Option<&Key> {
|
pub(crate) fn get(&self, id: &str) -> Option<&Key> {
|
||||||
@@ -514,6 +555,64 @@ fn rule_words(r: &StandingRule) -> String {
|
|||||||
format!("{} {} {} pipeline {} {}{targets}", r.repo, r.key, kind_word(r.kind), r.pipeline, via_word(r.via))
|
format!("{} {} {} pipeline {} {}{targets}", r.repo, r.key, kind_word(r.kind), r.pipeline, via_word(r.via))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `owner/name`, each 1 to 64 of `A-Z a-z 0-9 . _ -`: the owner and the name, or `None`.
|
||||||
|
fn repo_parts(repo: &str) -> Option<(&str, &str)> {
|
||||||
|
let part =
|
||||||
|
|x: &str| (1..=64).contains(&x.len()) && x.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-".contains(&b));
|
||||||
|
let (owner, name) = repo.split_once('/')?;
|
||||||
|
(part(owner) && part(name)).then_some((owner, name))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The app key of a repository (core 0.19.0): `mnovak/Culina` is `culina-android` (the name in lower case, `.` and
|
||||||
|
/// `_` as `-`); `None` for anything that is not `owner/name` or an id longer than 64.
|
||||||
|
pub fn android_key_id(repo: &str) -> Option<String> {
|
||||||
|
let (_, name) = repo_parts(repo)?;
|
||||||
|
let id: String = name.chars().map(|c| if c == '.' || c == '_' { '-' } else { c.to_ascii_lowercase() }).collect();
|
||||||
|
let id = format!("{id}-android");
|
||||||
|
(id.len() <= 64).then_some(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A pattern of the Android grant: `owner/name`, or `owner/*` for every repository of that owner.
|
||||||
|
fn grant_pattern_ok(p: &str) -> bool {
|
||||||
|
match p.strip_suffix("/*") {
|
||||||
|
Some(owner) => repo_parts(&format!("{owner}/x")).is_some(),
|
||||||
|
None => repo_parts(p).is_some(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn grant_covers(g: &AndroidGrant, repo: &str) -> bool {
|
||||||
|
let Some((owner, _)) = repo_parts(repo) else { return false };
|
||||||
|
g.repos.iter().any(|p| p == repo || p.strip_suffix("/*") == Some(owner))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The certificate's O (1 to 64, no control characters) and C (two ASCII capitals) for the keys the grant makes.
|
||||||
|
fn grant_subject_ok(o: &str, c: &str) -> bool {
|
||||||
|
(1..=64).contains(&o.chars().count())
|
||||||
|
&& !o.chars().any(char::is_control)
|
||||||
|
&& o.trim() == o
|
||||||
|
&& c.len() == 2
|
||||||
|
&& c.bytes().all(|b| b.is_ascii_uppercase())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A stored grant is what [`Vault::android_grant_set`] could have written; anything else makes the vault refuse to
|
||||||
|
/// open.
|
||||||
|
fn grant_ok(g: &AndroidGrant) -> bool {
|
||||||
|
let id_ok = |id: &String| {
|
||||||
|
(1..=64).contains(&id.len()) && id.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-')
|
||||||
|
};
|
||||||
|
(1..=ANDROID_PATTERNS_MAX).contains(&g.repos.len())
|
||||||
|
&& g.repos.iter().all(|p| grant_pattern_ok(p))
|
||||||
|
&& g.repos.iter().enumerate().all(|(i, p)| !g.repos[..i].contains(p))
|
||||||
|
&& grant_subject_ok(&g.o, &g.c)
|
||||||
|
&& g.made.len() <= ANDROID_MADE_MAX
|
||||||
|
&& g.made.iter().all(id_ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the grant says, for the security audit: names only.
|
||||||
|
fn grant_words(g: &AndroidGrant) -> String {
|
||||||
|
format!("Android releases: {} pipeline {ANDROID_PIPELINE}, keys made on first use", g.repos.join(", "))
|
||||||
|
}
|
||||||
|
|
||||||
fn in_scope(list: &[String], what: &str) -> bool {
|
fn in_scope(list: &[String], what: &str) -> bool {
|
||||||
list.iter().any(|x| x == "*" || x == what)
|
list.iter().any(|x| x == "*" || x == what)
|
||||||
}
|
}
|
||||||
@@ -846,7 +945,9 @@ impl Vault {
|
|||||||
return Err(r);
|
return Err(r);
|
||||||
}
|
}
|
||||||
let rule = self.standing_rule_for(req, now).map(|r| r.id);
|
let rule = self.standing_rule_for(req, now).map(|r| r.id);
|
||||||
if approval == Approval::Standing && rule.is_none() {
|
// A standing approval first; the Android grant only where none fits (core 0.19.0).
|
||||||
|
let by_grant = approval == Approval::Standing && rule.is_none() && self.android_grant_fits(req, now);
|
||||||
|
if approval == Approval::Standing && rule.is_none() && !by_grant {
|
||||||
let r = Refusal::NeedsApproval(req.key.clone());
|
let r = Refusal::NeedsApproval(req.key.clone());
|
||||||
self.signing_record(req, Outcome::Refused, Some(r.to_string()), None, now);
|
self.signing_record(req, Outcome::Refused, Some(r.to_string()), None, now);
|
||||||
return Err(r);
|
return Err(r);
|
||||||
@@ -902,6 +1003,10 @@ impl Vault {
|
|||||||
r.uses = r.uses.saturating_add(1);
|
r.uses = r.uses.saturating_add(1);
|
||||||
r.last_used = Some(now);
|
r.last_used = Some(now);
|
||||||
}
|
}
|
||||||
|
if by_grant && let Some(g) = self.signing.android.as_mut() {
|
||||||
|
g.uses = g.uses.saturating_add(1);
|
||||||
|
g.last_used = Some(now);
|
||||||
|
}
|
||||||
Ok(Signed { bytes, sha256 })
|
Ok(Signed { bytes, sha256 })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,6 +1196,131 @@ impl Vault {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The Android grant, if Mark gave it (core 0.19.0, docs/SIGNING.md "The Android grant").
|
||||||
|
pub fn android_grant(&self) -> Option<AndroidGrant> {
|
||||||
|
self.signing.android.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stores the Android grant, or replaces its patterns and subject (its counts and the keys it made stay), and
|
||||||
|
/// writes `standing-granted`. Refused while *Sign only with a card* is ticked. Call it only from Mark's own
|
||||||
|
/// click. The caller saves.
|
||||||
|
pub fn android_grant_set(&mut self, repos: &[String], o: &str, c: &str, now: i64) -> Result<AndroidGrant, Error> {
|
||||||
|
if self.security.is_ticked(crate::security::Item::CardSigning) {
|
||||||
|
return Err(Error::Signing("Sign only with a card is ticked".into()));
|
||||||
|
}
|
||||||
|
let mut patterns: Vec<String> = Vec::new();
|
||||||
|
for p in repos.iter().map(|p| p.trim()).filter(|p| !p.is_empty()) {
|
||||||
|
if !grant_pattern_ok(p) {
|
||||||
|
return Err(Error::Signing(format!(
|
||||||
|
"`{p}` is not a repository (owner/name) or every repository of an owner (owner/*)"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if !patterns.iter().any(|x| x == p) {
|
||||||
|
patterns.push(p.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if patterns.is_empty() || patterns.len() > ANDROID_PATTERNS_MAX {
|
||||||
|
return Err(Error::Signing(format!("the grant names 1 to {ANDROID_PATTERNS_MAX} repositories")));
|
||||||
|
}
|
||||||
|
if !grant_subject_ok(o, c) {
|
||||||
|
return Err(Error::Signing(
|
||||||
|
"the certificates need an organisation (1-64 characters) and a two-letter country code".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let old = self.signing.android.clone();
|
||||||
|
let grant = AndroidGrant {
|
||||||
|
repos: patterns,
|
||||||
|
o: o.into(),
|
||||||
|
c: c.into(),
|
||||||
|
granted: now,
|
||||||
|
last_used: old.as_ref().and_then(|g| g.last_used),
|
||||||
|
uses: old.as_ref().map_or(0, |g| g.uses),
|
||||||
|
made: old.map(|g| g.made).unwrap_or_default(),
|
||||||
|
};
|
||||||
|
self.security.standing_note(crate::security::Action::StandingGranted, &grant_words(&grant), now);
|
||||||
|
self.signing.android = Some(grant.clone());
|
||||||
|
Ok(grant)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the Android grant (`standing-revoked`); the keys it made stay. False when there is none. The caller
|
||||||
|
/// saves.
|
||||||
|
pub fn android_grant_revoke(&mut self, now: i64) -> bool {
|
||||||
|
let Some(g) = self.signing.android.take() else { return false };
|
||||||
|
self.security.standing_note(crate::security::Action::StandingRevoked, &grant_words(&g), now);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether `req` is signed by the Android grant: an `apk` from this PC's pipe with a run, in the key's scope, for
|
||||||
|
/// a repository the grant covers and pipeline `release`, by that repository's own app key (scoped to exactly it
|
||||||
|
/// and `release`, role release), while *Sign only with a card* is not ticked. A key's first signature fits.
|
||||||
|
pub fn android_grant_fits(&self, req: &Request, now: i64) -> bool {
|
||||||
|
let Some(g) = &self.signing.android else { return false };
|
||||||
|
let Ok((view, _)) = self.check(req, now) else { return false };
|
||||||
|
req.kind == SignKind::Apk
|
||||||
|
&& req.via == Via::Local
|
||||||
|
&& req.run.is_some()
|
||||||
|
&& !self.security.is_ticked(crate::security::Item::CardSigning)
|
||||||
|
&& view.kind == KeyKind::Android
|
||||||
|
&& view.role == Role::Release
|
||||||
|
&& req.context.pipeline == ANDROID_PIPELINE
|
||||||
|
&& grant_covers(g, &req.context.repo)
|
||||||
|
&& android_key_id(&req.context.repo).as_deref() == Some(req.key.as_str())
|
||||||
|
&& view.repos == [req.context.repo.clone()]
|
||||||
|
&& view.pipelines == [ANDROID_PIPELINE.to_string()]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Makes `repo`'s app key under the Android grant, when its first release asks (`custos-sign apk`): the grant
|
||||||
|
/// covers `repo`, `pipeline` is `release`, `via` is local, *Sign only with a card* is not ticked, and there is
|
||||||
|
/// no key under that id. RSA-4096, `CN=<Name>`, the grant's O and C, scoped to exactly `repo` and `release`.
|
||||||
|
/// Writes `standing-granted` with `Android grant made <id> for <repo> pipeline release`: a value every core since
|
||||||
|
/// 0.16.0 reads, so the phone and the web vault still open the vault (core 0.19.1). The caller saves. Slow: one
|
||||||
|
/// RSA-4096 key.
|
||||||
|
pub fn android_grant_make_key(&mut self, repo: &str, pipeline: &str, via: Via, now: i64) -> Result<String, Error> {
|
||||||
|
let no = |why: String| Err(Error::Signing(why));
|
||||||
|
let Some(g) = self.signing.android.clone() else { return no("there is no Android grant".into()) };
|
||||||
|
let (Some((_, name)), Some(id)) = (repo_parts(repo), android_key_id(repo)) else {
|
||||||
|
return no(format!("`{repo}` is not a repository (owner/name)"));
|
||||||
|
};
|
||||||
|
if via != Via::Local {
|
||||||
|
return no("the server runner never makes a key".into());
|
||||||
|
}
|
||||||
|
if pipeline != ANDROID_PIPELINE {
|
||||||
|
return no(format!("the Android grant makes keys for the pipeline `{ANDROID_PIPELINE}` only"));
|
||||||
|
}
|
||||||
|
if self.security.is_ticked(crate::security::Item::CardSigning) {
|
||||||
|
return no("Sign only with a card is ticked".into());
|
||||||
|
}
|
||||||
|
if !grant_covers(&g, repo) {
|
||||||
|
return no(format!("the Android grant does not cover `{repo}`"));
|
||||||
|
}
|
||||||
|
if self.signing.get(&id).is_some() {
|
||||||
|
return no(format!("there is a key `{id}` already"));
|
||||||
|
}
|
||||||
|
let mut cn = name.to_string();
|
||||||
|
if let Some(first) = cn.get_mut(0..1) {
|
||||||
|
first.make_ascii_uppercase();
|
||||||
|
}
|
||||||
|
let spec = AndroidKey {
|
||||||
|
id: id.clone(),
|
||||||
|
name: format!("{cn} Android"),
|
||||||
|
cn,
|
||||||
|
o: g.o.clone(),
|
||||||
|
c: g.c.clone(),
|
||||||
|
role: Role::Release,
|
||||||
|
pipelines: vec![ANDROID_PIPELINE.into()],
|
||||||
|
repos: vec![repo.into()],
|
||||||
|
};
|
||||||
|
self.signing_create_android(&spec, now)?;
|
||||||
|
if let Some(g) = self.signing.android.as_mut()
|
||||||
|
&& g.made.len() < ANDROID_MADE_MAX
|
||||||
|
{
|
||||||
|
g.made.push(id.clone());
|
||||||
|
}
|
||||||
|
let words = format!("Android grant made {id} for {repo} pipeline {ANDROID_PIPELINE}");
|
||||||
|
self.security.standing_note(crate::security::Action::StandingGranted, &words, now);
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Every request any key was named in, oldest first.
|
/// Every request any key was named in, oldest first.
|
||||||
pub fn signing_audit(&self) -> &[AuditEntry] {
|
pub fn signing_audit(&self) -> &[AuditEntry] {
|
||||||
&self.signing.audit
|
&self.signing.audit
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,266 @@
|
|||||||
|
//! The Android grant (core 0.19.0, docs/SIGNING.md "The Android grant"): one answer for every Domi app's release
|
||||||
|
//! APK. It signs a request for a repository's own app key (`<name>-android`, scoped to exactly that repository and
|
||||||
|
//! `release`) from this PC's pipe, its first signature included, and makes that key when the app's first release
|
||||||
|
//! asks. Everything else still needs a card.
|
||||||
|
|
||||||
|
use custos_vault::security::{Action, Auth, Item};
|
||||||
|
use custos_vault::signing::{
|
||||||
|
AndroidKey, Approval, Context, KeyKind, Outcome, Refusal, Request, Role, SignKind, Via, android_key_id,
|
||||||
|
};
|
||||||
|
use custos_vault::{KdfParams, SecretString, Vault};
|
||||||
|
|
||||||
|
const FAST: KdfParams = KdfParams { m_cost_kib: 64, t_cost: 1, p_cost: 1 };
|
||||||
|
const NOW: i64 = 1_793_750_000_000;
|
||||||
|
const COMMIT: &str = "6925d0cb08b9e0c5c3a4a7a2c37b7f2a9f7ed3b1";
|
||||||
|
|
||||||
|
fn s(v: &[&str]) -> Vec<String> {
|
||||||
|
v.iter().map(|x| x.to_string()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vault() -> Vault {
|
||||||
|
let mut v = Vault::create(&SecretString::from("pw"), FAST).unwrap();
|
||||||
|
v.signing_create(Role::Release, &s(&["release"]), &s(&["mnovak/Culina"]), NOW).unwrap();
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
fn granted(repos: &[&str]) -> Vault {
|
||||||
|
let mut v = vault();
|
||||||
|
v.android_grant_set(&s(repos), "Marek Novak", "CZ", NOW).unwrap();
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apk(key: &str, repo: &str, pipeline: &str, run: Option<&str>) -> Request {
|
||||||
|
Request {
|
||||||
|
key: key.into(),
|
||||||
|
kind: SignKind::Apk,
|
||||||
|
digest: vec![5; 64],
|
||||||
|
manifest: None,
|
||||||
|
approval: None,
|
||||||
|
run: run.map(Into::into),
|
||||||
|
context: Context {
|
||||||
|
repo: repo.into(),
|
||||||
|
commit: COMMIT.into(),
|
||||||
|
pipeline: pipeline.into(),
|
||||||
|
step: "sign-apk".into(),
|
||||||
|
trigger: "tag".into(),
|
||||||
|
file: "Culina-1.2.0.apk".into(),
|
||||||
|
size: 9_400_000,
|
||||||
|
sha256: "c4995c6e2e0c20fec7e8dcb05d70144da58f42d379c6705df66edb42abafb8a3".into(),
|
||||||
|
version: "1.2.0".into(),
|
||||||
|
},
|
||||||
|
via: Via::Local,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn culina(run: &str) -> Request {
|
||||||
|
apk("culina-android", "mnovak/Culina", "release", Some(run))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn notes(v: &Vault, action: Action) -> Vec<String> {
|
||||||
|
v.security_view(NOW + 1_000)
|
||||||
|
.audit
|
||||||
|
.into_iter()
|
||||||
|
.filter(|e| e.action == action)
|
||||||
|
.map(|e| e.detail.unwrap_or_default())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_app_key_is_named_by_its_repository() {
|
||||||
|
assert_eq!(android_key_id("mnovak/Culina").as_deref(), Some("culina-android"));
|
||||||
|
assert_eq!(android_key_id("mnovak/domi-office").as_deref(), Some("domi-office-android"));
|
||||||
|
assert_eq!(android_key_id("mnovak/Domi.Office_2").as_deref(), Some("domi-office-2-android"));
|
||||||
|
for bad in ["Culina", "mnovak/", "/Culina", "mnovak/*", "a/b/c", "mnovak/Cu lina", "mnovak/Čulina", ""] {
|
||||||
|
assert_eq!(android_key_id(bad), None, "{bad}");
|
||||||
|
}
|
||||||
|
assert_eq!(android_key_id(&format!("mnovak/{}", "x".repeat(57))), None, "the id would be longer than 64");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_grant_makes_an_apps_key_and_signs_its_first_apk_without_a_card() {
|
||||||
|
let mut v = granted(&["mnovak/*"]);
|
||||||
|
assert!(!v.android_grant_fits(&culina("r-1"), NOW + 1), "no key yet");
|
||||||
|
|
||||||
|
let id = v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW + 1).unwrap();
|
||||||
|
assert_eq!(id, "culina-android");
|
||||||
|
let k = v.signing_keys().into_iter().find(|k| k.id == id).unwrap();
|
||||||
|
assert_eq!((k.kind, k.role, k.name.as_str()), (KeyKind::Android, Role::Release, "Culina Android"));
|
||||||
|
assert_eq!((k.pipelines.clone(), k.repos.clone()), (s(&["release"]), s(&["mnovak/Culina"])));
|
||||||
|
let cert = String::from_utf8_lossy(k.cert.as_ref().unwrap()).into_owned();
|
||||||
|
assert!(cert.contains("Culina") && cert.contains("Marek Novak"), "the certificate names the app and Mark");
|
||||||
|
|
||||||
|
// Its first signature: no card, recorded as `standing`, counted on the grant.
|
||||||
|
assert!(v.android_grant_fits(&culina("r-1"), NOW + 2));
|
||||||
|
assert!(v.standing_rule_for(&culina("r-1"), NOW + 2).is_none(), "the grant is not a per-key rule");
|
||||||
|
let signed = v.signing_sign(&culina("r-1"), Approval::Standing, NOW + 2);
|
||||||
|
assert!(signed.is_ok(), "{signed:?}");
|
||||||
|
assert_eq!(v.signing_audit().last().unwrap().outcome, Outcome::Standing);
|
||||||
|
assert_eq!(v.signing_audit().last().unwrap().context.file, "Culina-1.2.0.apk");
|
||||||
|
v.signing_sign(&culina("r-2"), Approval::Standing, NOW + 3).unwrap();
|
||||||
|
let g = v.android_grant().unwrap();
|
||||||
|
assert_eq!((g.uses, g.last_used, g.made.clone()), (2, Some(NOW + 3), s(&["culina-android"])));
|
||||||
|
|
||||||
|
// Granting, then the key it made: both `standing-granted`, a value cores since 0.16.0 read (core 0.19.1).
|
||||||
|
let granted_note = notes(&v, Action::StandingGranted);
|
||||||
|
assert_eq!(granted_note.len(), 2, "{granted_note:?}");
|
||||||
|
assert!(granted_note[0].contains("Android releases") && granted_note[0].contains("mnovak/*"), "{granted_note:?}");
|
||||||
|
assert_eq!(granted_note[1], "Android grant made culina-android for mnovak/Culina pipeline release");
|
||||||
|
// The public note call cannot write it.
|
||||||
|
assert!(v.security_note(Action::StandingGranted, "x", NOW).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_grant_never_makes_a_key_it_does_not_cover() {
|
||||||
|
let mut v = granted(&["mnovak/Culina", "mnovak/Liber"]);
|
||||||
|
for (repo, pipeline, via, why) in [
|
||||||
|
("mnovak/Postea", "release", Via::Local, "a repository no pattern matches"),
|
||||||
|
("someone/Culina", "release", Via::Local, "another owner"),
|
||||||
|
("mnovak/Culina", "ci", Via::Local, "another pipeline"),
|
||||||
|
("mnovak/Culina", "release", Via::Remote, "the server runner"),
|
||||||
|
("Culina", "release", Via::Local, "not owner/name"),
|
||||||
|
] {
|
||||||
|
assert!(v.android_grant_make_key(repo, pipeline, via, NOW + 1).is_err(), "{why}");
|
||||||
|
}
|
||||||
|
assert!(v.signing_keys().iter().all(|k| k.kind != KeyKind::Android), "nothing was made");
|
||||||
|
v.android_grant_make_key("mnovak/Liber", "release", Via::Local, NOW + 2).unwrap();
|
||||||
|
assert!(v.android_grant_make_key("mnovak/Liber", "release", Via::Local, NOW + 3).is_err(), "made once");
|
||||||
|
|
||||||
|
v.security_tick(Item::CardSigning, NOW + 4);
|
||||||
|
assert!(v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW + 5).is_err(), "paused");
|
||||||
|
v.security_untick(Item::CardSigning, Auth::Hello, NOW + 6);
|
||||||
|
assert!(v.android_grant_revoke(NOW + 7));
|
||||||
|
assert!(v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW + 8).is_err(), "no grant");
|
||||||
|
assert_eq!(v.android_grant().map(|g| g.made), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn only_the_repositorys_own_app_key_in_its_own_scope_from_this_pc_with_a_run_fits() {
|
||||||
|
let mut v = granted(&["mnovak/*"]);
|
||||||
|
v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW).unwrap();
|
||||||
|
// A key of the right name with a wider scope, and one for the wrong repository, made by hand.
|
||||||
|
let wide = AndroidKey {
|
||||||
|
id: "liber-android".into(),
|
||||||
|
name: "Liber Android".into(),
|
||||||
|
cn: "Liber".into(),
|
||||||
|
o: "Marek Novak".into(),
|
||||||
|
c: "CZ".into(),
|
||||||
|
role: Role::Release,
|
||||||
|
pipelines: s(&["release"]),
|
||||||
|
repos: s(&["*"]),
|
||||||
|
};
|
||||||
|
v.signing_create_android(&wide, NOW).unwrap();
|
||||||
|
v.signing_create_android(
|
||||||
|
&AndroidKey { id: "other-android".into(), repos: s(&["mnovak/Rosea"]), ..wide.clone() },
|
||||||
|
NOW,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
v.signing_create_android(&AndroidKey { id: "domi-test-android".into(), role: Role::Test, ..wide.clone() }, NOW)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut remote = culina("r-1");
|
||||||
|
remote.via = Via::Remote;
|
||||||
|
let mut minisign = culina("r-1");
|
||||||
|
minisign.kind = SignKind::Minisign;
|
||||||
|
minisign.key = "domi-release".into();
|
||||||
|
minisign.digest = vec![7; 64];
|
||||||
|
for (req, why) in [
|
||||||
|
(remote, "the server runner"),
|
||||||
|
(apk("culina-android", "mnovak/Culina", "release", None), "no run"),
|
||||||
|
(apk("liber-android", "mnovak/Liber", "release", Some("r-1")), "a key with a wider scope"),
|
||||||
|
(apk("other-android", "mnovak/Rosea", "release", Some("r-1")), "not the repository's app key"),
|
||||||
|
(apk("domi-test-android", "mnovak/Liber", "release", Some("r-1")), "a test key"),
|
||||||
|
(minisign, "another kind"),
|
||||||
|
] {
|
||||||
|
assert!(!v.android_grant_fits(&req, NOW + 1), "{why}");
|
||||||
|
assert!(v.signing_sign(&req, Approval::Standing, NOW + 1).is_err(), "{why}: never signed without a card");
|
||||||
|
assert_ne!(v.signing_audit().last().unwrap().outcome, Outcome::Standing, "{why}");
|
||||||
|
}
|
||||||
|
assert_eq!(v.android_grant().unwrap().uses, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_explicit_list_covers_only_its_repositories_and_bad_patterns_are_refused() {
|
||||||
|
let mut v = granted(&["mnovak/Culina"]);
|
||||||
|
v.signing_create_android(
|
||||||
|
&AndroidKey {
|
||||||
|
id: "liber-android".into(),
|
||||||
|
name: "Liber Android".into(),
|
||||||
|
cn: "Liber".into(),
|
||||||
|
o: "Marek Novak".into(),
|
||||||
|
c: "CZ".into(),
|
||||||
|
role: Role::Release,
|
||||||
|
pipelines: s(&["release"]),
|
||||||
|
repos: s(&["mnovak/Liber"]),
|
||||||
|
},
|
||||||
|
NOW,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let liber = apk("liber-android", "mnovak/Liber", "release", Some("r-1"));
|
||||||
|
assert!(!v.android_grant_fits(&liber, NOW + 1), "not in the list");
|
||||||
|
// Editing the list keeps the counts and covers the new repository; a key made by hand in that shape is covered.
|
||||||
|
v.android_grant_set(&s(&["mnovak/Culina", "mnovak/Liber", "mnovak/Liber"]), "Marek Novak", "CZ", NOW + 2).unwrap();
|
||||||
|
assert_eq!(v.android_grant().unwrap().repos, s(&["mnovak/Culina", "mnovak/Liber"]));
|
||||||
|
assert!(v.android_grant_fits(&liber, NOW + 3));
|
||||||
|
|
||||||
|
for bad in [&[][..], &["mnovak"], &["*/*"], &["*"], &["mnovak/*/x"], &["mn ovak/*"], &["mnovak/Cu*"]] {
|
||||||
|
assert!(v.android_grant_set(&s(bad), "Marek Novak", "CZ", NOW + 4).is_err(), "{bad:?}");
|
||||||
|
}
|
||||||
|
let many: Vec<String> = (0..65).map(|i| format!("mnovak/app{i}")).collect();
|
||||||
|
assert!(v.android_grant_set(&many, "Marek Novak", "CZ", NOW + 4).is_err(), "at most 64");
|
||||||
|
assert!(v.android_grant_set(&s(&["mnovak/*"]), "Marek Novak", "Czech", NOW + 4).is_err(), "a two-letter country");
|
||||||
|
assert!(v.android_grant_set(&s(&["mnovak/*"]), "", "CZ", NOW + 4).is_err(), "an organisation");
|
||||||
|
assert_eq!(
|
||||||
|
v.android_grant().unwrap().repos,
|
||||||
|
s(&["mnovak/Culina", "mnovak/Liber"]),
|
||||||
|
"a refused edit changes nothing"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sign_only_with_a_card_pauses_the_grant_and_revoking_ends_it() {
|
||||||
|
let mut v = granted(&["mnovak/*"]);
|
||||||
|
v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW).unwrap();
|
||||||
|
v.security_tick(Item::CardSigning, NOW + 1);
|
||||||
|
assert!(!v.android_grant_fits(&culina("r-1"), NOW + 2));
|
||||||
|
assert!(matches!(v.signing_sign(&culina("r-1"), Approval::Standing, NOW + 2), Err(Refusal::NeedsApproval(_))));
|
||||||
|
assert!(v.android_grant_set(&s(&["mnovak/*"]), "Marek Novak", "CZ", NOW + 2).is_err(), "no grant while ticked");
|
||||||
|
assert!(v.android_grant().is_some(), "kept, paused");
|
||||||
|
v.security_untick(Item::CardSigning, Auth::Hello, NOW + 3);
|
||||||
|
assert!(v.android_grant_fits(&culina("r-1"), NOW + 4));
|
||||||
|
|
||||||
|
assert!(v.android_grant_revoke(NOW + 5));
|
||||||
|
assert!(!v.android_grant_revoke(NOW + 6), "once");
|
||||||
|
assert!(!v.android_grant_fits(&culina("r-2"), NOW + 7));
|
||||||
|
assert!(matches!(v.signing_sign(&culina("r-2"), Approval::Standing, NOW + 7), Err(Refusal::NeedsApproval(_))));
|
||||||
|
// Mark still signs it on a card, and the key stays.
|
||||||
|
assert!(v.signing_sign(&culina("r-2"), Approval::Mark, NOW + 8).is_ok());
|
||||||
|
let revoked = notes(&v, Action::StandingRevoked);
|
||||||
|
assert_eq!(revoked.len(), 1);
|
||||||
|
assert!(revoked[0].contains("Android releases"), "{revoked:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_standing_rule_for_the_same_request_is_used_first() {
|
||||||
|
let mut v = granted(&["mnovak/*"]);
|
||||||
|
v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW).unwrap();
|
||||||
|
v.signing_sign(&culina("r-1"), Approval::Mark, NOW + 1).unwrap();
|
||||||
|
v.standing_grant(&culina("r-2"), NOW + 2).unwrap();
|
||||||
|
v.signing_sign(&culina("r-2"), Approval::Standing, NOW + 2).unwrap();
|
||||||
|
assert_eq!(v.standing_rules()[0].uses, 1);
|
||||||
|
assert_eq!(v.android_grant().unwrap().uses, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_grant_and_its_counts_survive_a_reopen() {
|
||||||
|
let mut v = granted(&["mnovak/*", "domi/*"]);
|
||||||
|
v.android_grant_make_key("mnovak/Culina", "release", Via::Local, NOW).unwrap();
|
||||||
|
v.signing_sign(&culina("r-1"), Approval::Standing, NOW + 1).unwrap();
|
||||||
|
|
||||||
|
let mut back = Vault::open(&v.to_bytes().unwrap(), &SecretString::from("pw")).unwrap();
|
||||||
|
assert_eq!(back.android_grant(), v.android_grant());
|
||||||
|
assert!(back.signing_sign(&culina("r-2"), Approval::Standing, NOW + 2).is_ok());
|
||||||
|
assert_eq!(back.android_grant().unwrap().uses, 2);
|
||||||
|
assert!(back.android_grant_revoke(NOW + 3));
|
||||||
|
let again = Vault::open(&back.to_bytes().unwrap(), &SecretString::from("pw")).unwrap();
|
||||||
|
assert_eq!(again.android_grant(), None);
|
||||||
|
}
|
||||||
@@ -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"));
|
||||||
|
|||||||
+5
-2
@@ -149,7 +149,10 @@ of kind `android` and an audit entry of kind `apk` (docs/SIGNING.md); a vault th
|
|||||||
core before 0.14.0. Core 0.16.0 adds the `signing` audit outcome `standing` and the `security` actions
|
core before 0.14.0. Core 0.16.0 adds the `signing` audit outcome `standing` and the `security` actions
|
||||||
`standing-granted` and `standing-revoked` (docs/SIGNING.md, "Standing approvals"): a vault in which a standing
|
`standing-granted` and `standing-revoked` (docs/SIGNING.md, "Standing approvals"): a vault in which a standing
|
||||||
approval was ever granted does not open in a core before 0.16.0. The rules themselves (`signing.standing`) are a
|
approval was ever granted does not open in a core before 0.16.0. The rules themselves (`signing.standing`) are a
|
||||||
member older cores ignore and drop.
|
member older cores ignore and drop. Core 0.19.0 adds the member `signing.android` (the Android grant, docs/SIGNING.md "The Android
|
||||||
|
grant"), which older cores ignore and drop (the grant is lost, never widened). It adds no closed-list value:
|
||||||
|
a key the grant makes is `standing-granted` in the security audit (core 0.19.1), so a vault with the grant still
|
||||||
|
opens in every core since 0.16.0, as the phone app and the web vault may be.
|
||||||
|
|
||||||
### The provision audit (core 0.11.0)
|
### The provision audit (core 0.11.0)
|
||||||
|
|
||||||
@@ -213,7 +216,7 @@ an outcome; a code the server then refuses (its exit 10) is not seen by Custos,
|
|||||||
| `finished` | optional: when that window ended, by *Finish setup*, or `until` once its expiry was noticed |
|
| `finished` | optional: when that window ended, by *Finish setup*, or `until` once its expiry was noticed |
|
||||||
| `ticked` | the checklist items that are ticked: `totp-on-phone`, `hello-approvals`, `narrow-scope`, `rotate-setup`, `no-ssh`, `phone-approves`, and (core 0.13.0) `no-auto-connect`, `no-unattended`, `card-signing` |
|
| `ticked` | the checklist items that are ticked: `totp-on-phone`, `hello-approvals`, `narrow-scope`, `rotate-setup`, `no-ssh`, `phone-approves`, and (core 0.13.0) `no-auto-connect`, `no-unattended`, `card-signing` |
|
||||||
| `keptScope` | optional: the server scope prefixes *Narrow the server scope* replaced (`ask`, `offer`: at most 64 each, 1–200 characters, no control characters), kept for its undo |
|
| `keptScope` | optional: the server scope prefixes *Narrow the server scope* replaced (`ask`, `offer`: at most 64 each, 1–200 characters, no control characters), kept for its undo |
|
||||||
| `audit` | `{at, action, item?, auth?, detail?}`; `action` is `setup-started`, `setup-finished`, `setup-expired`, `ticked`, `unticked`, `ssh-connected`, `totp-moved`, or (core 0.13.0) `auto-connected`, `unattended-stored`, `setup-item-removed`, `unattended-signed`, `taken-over`, or (core 0.16.0) `standing-granted`, `standing-revoked`, or (core 0.17.0) `recovery-created`, `recovery-removed`, `recovered` (docs/FACTORS.md, "The recovery key"; their `detail` is the key's id); `item` a checklist item (with `ticked`, `unticked`); `auth` is `hello` or `password` (with `unticked`); `detail` (core 0.13.0, the four notes; core 0.16.0, the two standing actions) names what happened, never a value: 1–500 characters, no control characters |
|
| `audit` | `{at, action, item?, auth?, detail?}`; `action` is `setup-started`, `setup-finished`, `setup-expired`, `ticked`, `unticked`, `ssh-connected`, `totp-moved`, or (core 0.13.0) `auto-connected`, `unattended-stored`, `setup-item-removed`, `unattended-signed`, `taken-over`, or (core 0.16.0) `standing-granted`, `standing-revoked` (also for the Android grant and the keys it makes), or (core 0.17.0) `recovery-created`, `recovery-removed`, `recovered` (docs/FACTORS.md, "The recovery key"; their `detail` is the key's id); `item` a checklist item (with `ticked`, `unticked`); `auth` is `hello` or `password` (with `unticked`); `detail` (core 0.13.0, the four notes; core 0.16.0, the two standing actions) names what happened, never a value: 1–500 characters, no control characters |
|
||||||
|
|
||||||
The **level** is computed, never stored:
|
The **level** is computed, never stored:
|
||||||
|
|
||||||
|
|||||||
+60
-1
@@ -1,4 +1,4 @@
|
|||||||
# Signing keys (core 0.9.0; deploy approvals 0.12.0; Android APKs 0.14.0; standing approvals 0.16.0; teams 0.18.0)
|
# Signing keys (core 0.9.0; deploy approvals 0.12.0; Android APKs 0.14.0; standing approvals 0.16.0; teams 0.18.0; the Android grant 0.19.0)
|
||||||
|
|
||||||
Custos signs releases for Fabrica Domi · Artifex without a private key ever leaving the vault. A build asks for a
|
Custos signs releases for Fabrica Domi · Artifex without a private key ever leaving the vault. A build asks for a
|
||||||
signature over a **digest**; Custos checks who may ask, Mark approves with a match code, and the vault signs and
|
signature over a **digest**; Custos checks who may ask, Mark approves with a match code, and the vault signs and
|
||||||
@@ -249,6 +249,59 @@ Never covered by a rule, by construction: another repository, key, kind, pipelin
|
|||||||
key's scope; a request without a run; a key's first signature; a deploy to a target the rule was not granted for;
|
key's scope; a request without a run; a key's first signature; a deploy to a target the rule was not granted for;
|
||||||
a release signature the server runner asks for; creating a key.
|
a release signature the server runner asks for; creating a key.
|
||||||
|
|
||||||
|
## The Android grant (core 0.19.0)
|
||||||
|
|
||||||
|
A standing approval is one repository's one key, and never a key's first signature. Mark has a dozen Domi apps, each
|
||||||
|
with its own Android key (`<app>-android`), each new: that is a card to make the key's first signature and another to
|
||||||
|
store the rule, per app. **The Android grant** is one answer for all of them: "sign my apps' release APKs, and make
|
||||||
|
each app's key when its first release asks". One grant per vault, in `signing.android`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"android": { "repos": ["mnovak/*"], "o": "Marek Novak", "c": "CZ", "granted": 1794000000000,
|
||||||
|
"lastUsed": 1794100000000, "uses": 3, "made": ["culina-android"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
- `repos`: 1 to 64 patterns, each `owner/name` or `owner/*` (every repository of that owner, never another
|
||||||
|
owner's); owner and name are 1 to 64 of `A-Z a-z 0-9 . _ -`.
|
||||||
|
- `o`, `c`: the certificate subject's organisation and country for the keys it makes.
|
||||||
|
- `uses`, `lastUsed`: as on a standing approval. `made`: the ids of the keys it made, oldest first (at most 256).
|
||||||
|
|
||||||
|
**An app's key** is named by its repository: `android_key_id("mnovak/Culina")` is `culina-android` (the name in
|
||||||
|
lower case, `.` and `_` as `-`). The grant only ever deals in that key, and only when its scope is exactly that
|
||||||
|
repository and the pipeline `release`, with the role `release`: a key with a wider scope (or `*`) is never the
|
||||||
|
grant's, and a key the grant did not make but that has this shape (`postea-android`) is covered too.
|
||||||
|
|
||||||
|
**A request fits the grant** (`android_grant_fits`) when all of these hold:
|
||||||
|
|
||||||
|
- `signing_check` passes (scope as always: the grant never widens a key's scope);
|
||||||
|
- the kind is `apk` and `via` is `local`: an APK the server runner asks for never fits;
|
||||||
|
- the request names a run;
|
||||||
|
- the pipeline is `release` and the repository matches one of the patterns;
|
||||||
|
- the key is that repository's app key, as above;
|
||||||
|
- `card-signing` (*Sign only with a card*) is not ticked.
|
||||||
|
|
||||||
|
A key's first signature fits too: that is the point of the grant. `signing_sign(req, Approval::Standing, now)` signs
|
||||||
|
a request that fits a standing approval or the grant (a standing approval first), records the outcome `standing`,
|
||||||
|
and counts the use on whichever fitted.
|
||||||
|
|
||||||
|
**Making a key** (`android_grant_make_key(repo, pipeline, via, now)`): the grant covers the repository, the
|
||||||
|
pipeline is `release`, `via` is `local`, `card-signing` is not ticked, and the vault has no key under that id. It
|
||||||
|
makes the RSA-4096 key with the certificate `CN=<Name>` (the repository's name, first letter upper case), `O` and `C`
|
||||||
|
from the grant, named `<Name> Android`, scoped to exactly that repository and `release`, adds the id to `made`, and
|
||||||
|
writes `standing-granted` to the security audit (`Android grant made <id> for <repo> pipeline release`). Core 0.19.0
|
||||||
|
wrote a new action, `android-key-made`, which older cores refuse; 0.19.1 keeps to the values every core since 0.16.0
|
||||||
|
reads, because the phone app and the web vault open the same vault. It is a key like any other: not exportable,
|
||||||
|
removed only as any key is.
|
||||||
|
|
||||||
|
**Granting** (`android_grant_set(repos, o, c, now)`) stores or replaces the grant (the counts and `made` stay) and
|
||||||
|
writes `standing-granted` with `Android releases: <patterns> pipeline release, keys made on first use`. It is
|
||||||
|
refused while `card-signing` is ticked. `android_grant_revoke` removes it (`standing-revoked`). Neither asks
|
||||||
|
anyone: the app calls them only from Mark's own click.
|
||||||
|
|
||||||
|
Never covered by the grant: another kind, the server runner, a pipeline other than `release`, a repository no pattern
|
||||||
|
matches, a key that is not the repository's app key, a request without a run, anything while *Sign only with a card*
|
||||||
|
is ticked.
|
||||||
|
|
||||||
## The audit log
|
## The audit log
|
||||||
|
|
||||||
`audit` is append-only: there is no function that edits or removes an entry. Every request a key is named in gets
|
`audit` is append-only: there is no function that edits or removes an entry. Every request a key is named in gets
|
||||||
@@ -302,6 +355,12 @@ Vault::standing_grant(&request, now) -> StandingRule //
|
|||||||
Vault::standing_rule_for(&request, now) -> Option<StandingRule>
|
Vault::standing_rule_for(&request, now) -> Option<StandingRule>
|
||||||
Vault::standing_rules() -> [StandingRule]
|
Vault::standing_rules() -> [StandingRule]
|
||||||
Vault::standing_revoke(id, now) -> bool
|
Vault::standing_revoke(id, now) -> bool
|
||||||
|
android_key_id(repo) -> Option<String> (core 0.19.0)
|
||||||
|
Vault::android_grant() -> Option<AndroidGrant>
|
||||||
|
Vault::android_grant_set(repos, o, c, now) -> Result<AndroidGrant, Error>
|
||||||
|
Vault::android_grant_revoke(now) -> bool
|
||||||
|
Vault::android_grant_fits(req, now) -> bool
|
||||||
|
Vault::android_grant_make_key(repo, pipeline, via, now) -> Result<String, Error>
|
||||||
```
|
```
|
||||||
|
|
||||||
No function returns a `secret`. The views and the audit entries print and serialise without one; there is a test.
|
No function returns a `secret`. The views and the audit entries print and serialise without one; there is a test.
|
||||||
|
|||||||
+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