gate ssh signing per agent: ssh permission, signing policy on the login role, ca key endpoint
This commit is contained in:
parent
aeb9317ad1
commit
910f9a6f50
3 changed files with 805 additions and 57 deletions
|
|
@ -13,3 +13,4 @@ pub mod limits;
|
|||
pub mod messages;
|
||||
pub mod permissions;
|
||||
pub mod schedules;
|
||||
pub mod ssh;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ pub struct Permissions {
|
|||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schema", schema(example = 0, minimum = 0, maximum = 100))]
|
||||
pub max_repos: Option<u32>,
|
||||
/// Whether the agent may get short-lived SSH certificates from the swarm's SSH
|
||||
/// CA. Absent in a `GET` means the swarm never set it, which counts as off.
|
||||
/// Absent in a `PUT` keeps the stored value. The agent's store login role
|
||||
/// takes the change within five minutes; a certificate already signed stays
|
||||
/// valid until it expires, at most three hours.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub ssh: Option<bool>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -56,6 +63,7 @@ mod tests {
|
|||
unrestricted_internet: None,
|
||||
internet_log: None,
|
||||
max_repos: None,
|
||||
ssh: None,
|
||||
},
|
||||
r#"{"permissions":[]}"#,
|
||||
),
|
||||
|
|
@ -65,6 +73,7 @@ mod tests {
|
|||
unrestricted_internet: Some(false),
|
||||
internet_log: None,
|
||||
max_repos: None,
|
||||
ssh: None,
|
||||
},
|
||||
r#"{"unrestricted_internet":false}"#,
|
||||
),
|
||||
|
|
@ -74,6 +83,7 @@ mod tests {
|
|||
unrestricted_internet: Some(false),
|
||||
internet_log: Some(true),
|
||||
max_repos: None,
|
||||
ssh: None,
|
||||
},
|
||||
r#"{"unrestricted_internet":false,"internet_log":true}"#,
|
||||
),
|
||||
|
|
@ -83,6 +93,7 @@ mod tests {
|
|||
unrestricted_internet: None,
|
||||
internet_log: None,
|
||||
max_repos: None,
|
||||
ssh: None,
|
||||
},
|
||||
r#"{"permissions":["messaging","manage_root_agent"]}"#,
|
||||
),
|
||||
|
|
@ -93,6 +104,13 @@ mod tests {
|
|||
},
|
||||
r#"{"max_repos":3}"#,
|
||||
),
|
||||
(
|
||||
Permissions {
|
||||
ssh: Some(true),
|
||||
..Permissions::default()
|
||||
},
|
||||
r#"{"ssh":true}"#,
|
||||
),
|
||||
] {
|
||||
assert_eq!(serde_json::to_string(&value).unwrap(), wire);
|
||||
assert_eq!(serde_json::from_str::<Permissions>(wire).unwrap(), value);
|
||||
|
|
|
|||
29
swarm-controller-api/src/ssh.rs
Normal file
29
swarm-controller-api/src/ssh.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
//! `/api/ssh/ca` — the public key of the SSH CA that signs the agents'
|
||||
//! certificates.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The CA's public key, one `authorized_keys`-style line. A public value: a
|
||||
/// machine puts it in its sshd config to trust the certificates the swarm
|
||||
/// signs.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
|
||||
pub struct SshCa {
|
||||
/// For example `ssh-ed25519 AAAA…`, with no trailing newline.
|
||||
pub public_key: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SshCa;
|
||||
|
||||
#[test]
|
||||
fn the_ca_round_trips() {
|
||||
let wire = r#"{"public_key":"ssh-ed25519 AAAA"}"#;
|
||||
let value = SshCa {
|
||||
public_key: "ssh-ed25519 AAAA".to_owned(),
|
||||
};
|
||||
assert_eq!(serde_json::to_string(&value).unwrap(), wire);
|
||||
assert_eq!(serde_json::from_str::<SshCa>(wire).unwrap(), value);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue