diff --git a/src/bin/slop-broker.rs b/src/bin/slop-broker.rs index 429d7ef..bc06630 100644 --- a/src/bin/slop-broker.rs +++ b/src/bin/slop-broker.rs @@ -46,7 +46,7 @@ async fn main() { let name = args.first().and_then(|a| a.rsplit('/').next()).unwrap_or_default().to_owned(); let result = if name == "slop-approve" { - approve_cli(); + restore_sigpipe(); match remote::address(Role::Approver, approve::DEFAULT_ADDRESS) { Ok(address) => approve::main(&address, &args.split_off(1)).await, Err(error) => Err(error), @@ -55,7 +55,7 @@ async fn main() { match Command::parse() { Command::Serve { config } => serve(&config).await, Command::Approve { broker, args } => { - approve_cli(); + restore_sigpipe(); match broker.map_or_else(|| remote::address(Role::Approver, approve::DEFAULT_ADDRESS), Ok) { Ok(address) => approve::main(&address, &args).await, Err(error) => Err(error), @@ -72,9 +72,10 @@ async fn main() { } } -/// Lets `slop-approve … | head` end quietly, like other command-line tools. Not for the daemon, -/// which must survive peers closing sockets. -fn approve_cli() { +/// Restores the default `SIGPIPE` action, which Rust's runtime ignores, so `slop-approve … | head` +/// ends quietly like other command-line tools. Not for the daemon, which must survive peers +/// closing sockets. +fn restore_sigpipe() { let _ = unsafe { signal(Signal::SIGPIPE, SigHandler::SigDfl) }; } @@ -113,18 +114,31 @@ async fn serve(path: &Path) -> Result<()> { None => None, }; + // One task per listener. Each accepts connections and handles every one in a task of its own, + // so a request waiting for approval holds up nothing else. let broker = Arc::new(Broker::new(config)?); let mut tasks = tokio::task::JoinSet::new(); + + // Approvers on this box: `slop-approve` tasks.spawn(approve::listen(broker.clone(), approve_listener)); + + // Requesters on this box, identified by UID if let Some(listener) = request_listener { tasks.spawn(server::listen_unix(broker.clone(), listener)); } + + // Requesters and approvers on other boxes, through `slop-broker remote` behind `sshd`, which + // names the key's owner if let Some((listener, uid)) = remote_listener { tasks.spawn(remote::listen(broker.clone(), listener, uid)); } + + // The agents' VMs, identified by CID if let Some(port) = broker.config.vsock_port { tasks.spawn(server::listen_vsock(broker.clone(), port)); } + + // The approvals web app, which also sends Web Push notifications if let Some((settings, secret)) = web { tasks.spawn(web::run(broker.clone(), settings, secret)); } diff --git a/src/config.rs b/src/config.rs index 14ca399..12996ac 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,6 +13,7 @@ use crate::queue::parse_duration; #[derive(Debug, Clone, Deserialize)] #[serde(deny_unknown_fields)] pub struct Config { + // Who may ask, what they may do, and how long they wait pub requesters: BTreeMap, /// Named policies; several requesters can share one. #[serde(default)] @@ -23,28 +24,44 @@ pub struct Config { /// Pending requests across all requesters. #[serde(default = "default_max_pending")] pub max_pending: usize, + + // Where requests arrive #[serde(default)] pub vsock_port: Option, /// Unix socket for local requesters, identified by UID. #[serde(default)] pub request_socket: Option, + /// Requesters and approvers on other boxes, over SSH. + #[serde(default)] + pub remote: Option, + + // Where approvers answer pub approve_socket: PathBuf, /// Group whose members may answer requests. pub approver_group: String, #[serde(default)] - pub audit_log: Option, + pub web: Option, + + // Operations, each enabled by its section #[serde(default)] pub ssh: Option, #[serde(default)] - pub remote: Option, - #[serde(default)] pub deploy: Option, #[serde(default)] pub cache: Option, #[serde(default)] - pub web: Option, - #[serde(default)] pub secrets: Option, + + #[serde(default)] + pub audit_log: Option, +} + +fn default_timeout() -> u64 { + 300 +} + +fn default_max_pending() -> usize { + 64 } /// Age secrets (see [`crate::ops::secret`]). Needs `deploy`, whose builder reads the main branch. @@ -74,6 +91,7 @@ pub struct WebConfig { pub listen: std::net::SocketAddr, /// Public URL of the app, like `https://approve.example.org`. pub url: String, + /// OpenID Connect issuer. pub issuer: String, pub client_id: String, @@ -81,6 +99,7 @@ pub struct WebConfig { pub client_secret: PathBuf, /// Only members of this group (the ID token's `groups` claim) may sign in. pub group: String, + /// How long a session lasts without being used. #[serde(default = "default_session", deserialize_with = "duration")] pub session: u64, @@ -131,14 +150,6 @@ pub struct RemoteConfig { pub approvers: Vec, } -fn default_timeout() -> u64 { - 300 -} - -fn default_max_pending() -> usize { - 64 -} - #[derive(Debug, Clone, Deserialize)] #[serde(deny_unknown_fields)] pub struct Requester {