Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller serves tls on tcp to the gateway client identity only, when configured

This commit is contained in:
atlas 2026-11-15 15:56:59 +01:00 • committed by mara
commit 17fffaae79

View file

@ -1,7 +1,8 @@
//! Swarm-level controller daemon. Runs as the unprivileged
//! `swarm-controller` user on whichever host the operator flips
//! `services.hyperhive.deploy.swarm-controller.enable` on, and serves HTTP over a
//! unix socket that the hive-gateway's nginx proxies to.
//! unix socket that the hive-gateway's nginx proxies to, and also over TLS on TCP when
//! `SWARM_CONTROLLER_TCP_LISTEN` is set (`tcp_tls`).
//!
//! Configuration is read-only and loaded once at startup from env vars the
//! NixOS module sets (`services.hyperhive.swarm.controller`) — see
@ -93,6 +94,7 @@ mod startup;
mod status;
mod store;
mod subagent_term;
mod tcp_tls;
mod term_stream;
#[cfg(test)]
mod test_nats;
@ -269,7 +271,14 @@ async fn main() -> Result<()> {
reviews: Arc::default(),
alerts: alerts::from_env(),
};
serve(listener, state, stop, health).await
serve(
listener,
tcp_tls::TcpTlsConfig::from_env()?,
state,
stop,
health,
)
.await
}
/// The value a startup step produced, or exit 0 when the stop signal ended the
@ -318,11 +327,14 @@ fn register_cert_gauges(provider: Option<&opentelemetry_sdk::metrics::SdkMeterPr
}
/// Start taking the queued review requests and answering the notification
/// router's, then serve `state` on `listener` until `stop` resolves. The
/// requests in hand finish for at most the drain; the review queue takes no
/// request after `stop`. `health` answers `/readyz` as the socket's does.
/// router's, then serve `state` on `listener`, and on `tcp` too when it is
/// configured, until `stop` resolves. Both answer from the same router and
/// both drain on `stop`. The requests in hand finish for at most the drain;
/// the review queue takes no request after `stop`. `health` answers `/readyz`
/// as the socket's does.
async fn serve(
listener: tokio::net::UnixListener,
tcp: Option<tcp_tls::TcpTlsConfig>,
state: AppState,
stop: impl Future<Output = ()> + Clone + Send + 'static,
health: swarm_secret_client::health::Health,
@ -331,10 +343,35 @@ async fn serve(
health.ready_when(routes::probe_condition(state.status.clone(), store));
review_classifier::review::spawn_queue(&state, stop.clone());
request_reviewer::spawn(&state);
let serving = axum::serve(listener, build_app(state)).with_graceful_shutdown(stop.clone());
swarm_secret_client::serve_bounded(stop, serving.into_future())
let app = build_app(state);
let socket = axum::serve(listener, app.clone()).with_graceful_shutdown(stop.clone());
let bound = stop.clone();
let serving = async move {
let Some(tcp) = tcp else {
return socket
.into_future()
.await
.context("serving swarm-controller");
};
let tcp = tcp_tls::bind(&tcp).await?;
let tcp = axum::serve(tcp, app).with_graceful_shutdown(stop);
tokio::try_join!(
async {
socket
.into_future()
.await
.context("serving swarm-controller on its socket")
},
async {
tcp.into_future()
.await
.context("serving swarm-controller on tcp")
},
)
.map(|_| ())
};
swarm_secret_client::serve_bounded(bound, serving)
.await
.transpose()
.context("serving swarm-controller")?;
.transpose()?;
Ok(())
}