[vault] Approval: sign kind approval only by domi-approve (made with the release keys, signing_add_approve for older vaults), run on requests and in the audit, context version, signing_check_at; docs/SIGNING.md
This commit is contained in:
@@ -460,6 +460,19 @@ fn unprintable(c: char) -> bool {
|
||||
/// an hour later (docs/SIGNING.md). It is parsed, written again in canonical form and compared byte for byte, so
|
||||
/// any other spelling of the same values (key order, spaces, escapes, a trailing newline) is refused.
|
||||
pub fn approval_check(text: &str, now_secs: u64) -> Result<Approval, Error> {
|
||||
let a = approval_parse(text)?;
|
||||
if a.expires <= now_secs {
|
||||
return Err(Error::Approval("it has expired"));
|
||||
}
|
||||
if a.expires > now_secs.saturating_add(APPROVAL_MAX_AHEAD) {
|
||||
return Err(Error::Approval("it expires more than an hour from now"));
|
||||
}
|
||||
Ok(a)
|
||||
}
|
||||
|
||||
/// [`approval_check`] without the clock: the canonical form and every member's rule, not the expiry. For reading
|
||||
/// what a refused or expired request said; never enough to sign.
|
||||
pub fn approval_parse(text: &str) -> Result<Approval, Error> {
|
||||
let err = |why: &'static str| Err(Error::Approval(why));
|
||||
if text.len() > MAX_APPROVAL {
|
||||
return err("larger than 8 KiB");
|
||||
@@ -508,12 +521,6 @@ pub fn approval_check(text: &str, now_secs: u64) -> Result<Approval, Error> {
|
||||
if a.canonical() != text {
|
||||
return err("not in canonical form (key order, spaces or escaping)");
|
||||
}
|
||||
if a.expires <= now_secs {
|
||||
return err("it has expired");
|
||||
}
|
||||
if a.expires > now_secs.saturating_add(APPROVAL_MAX_AHEAD) {
|
||||
return err("it expires more than an hour from now");
|
||||
}
|
||||
Ok(a)
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +187,17 @@ fn approval_signs_only_a_valid_text_for_its_own_run() {
|
||||
assert!(approval(&k.secret, &k.key_id, &canonical(), NOW + 600, "r-42").is_err(), "expired at signing time");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_reads_the_form_without_the_clock() {
|
||||
// For the audit of a refused or expired request: everything but the expiry is checked.
|
||||
let a = approval_parse(&canonical()).unwrap();
|
||||
assert_eq!(a, approval_check(&canonical(), NOW).unwrap());
|
||||
assert!(approval_check(&canonical(), NOW + 10_000).is_err());
|
||||
assert_eq!(approval_parse(&canonical()).unwrap().expires, NOW + 600);
|
||||
assert!(approval_parse(&canonical().replace(',', ", ")).is_err());
|
||||
assert!(approval_parse(&with("\"run\":\"r-42\"", "\"run\":\"r 42\"")).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_ids_follow_the_rule() {
|
||||
for ok in ["r-42", "setup-1", "a.b_c", &"x".repeat(64)] {
|
||||
|
||||
Reference in New Issue
Block a user