[control] UI socket: with [ui] socket control also serves the API on a 0660 Unix socket and trusts the proof only there; a socket upstream is refused unless it is the admin host on control's own socket; probes under Caddy reach it too

This commit is contained in:
2026-11-10 21:06:56 +01:00
parent 1f5e4a59a0
commit d249bcf9f2
7 changed files with 160 additions and 8 deletions
+12 -3
View File
@@ -345,6 +345,10 @@ pub(crate) fn host_allowed(ctl: &Control, headers: &HeaderMap) -> bool {
.any(|a| a.eq_ignore_ascii_case(host))
}
/// Marks a request that came in on control's UI socket (`[ui] socket`).
#[derive(Debug, Clone, Copy)]
pub struct ViaUiSocket;
enum UiIdentity {
/// No sign-in headers: an API-token request.
None,
@@ -356,7 +360,7 @@ enum UiIdentity {
User(String, String),
}
fn ui_identity(ctl: &Control, headers: &HeaderMap) -> UiIdentity {
fn ui_identity(ctl: &Control, headers: &HeaderMap, via_socket: bool) -> UiIdentity {
let names_user = headers.keys().any(|k| k.as_str().starts_with("remote-"));
let proof = headers.get("x-ianitor-proof");
if !names_user && proof.is_none() {
@@ -366,7 +370,11 @@ fn ui_identity(ctl: &Control, headers: &HeaderMap) -> UiIdentity {
(Some(p), Some(want)) => crate::util::ct_eq(p.as_bytes(), want),
_ => false,
};
if !ok {
// With a UI socket (G14 option b) the proof counts only there: the loopback port is open
// to every local process, and one that learned the proof (say, by taking control's port
// while it restarted and reading what edge sent) must not be able to use it.
let socket_only = ctl.cfg.ui.as_ref().is_some_and(|u| u.socket.is_some());
if !ok || (socket_only && !via_socket) {
return UiIdentity::Forged;
}
let users: Vec<&HeaderValue> = headers.get_all("remote-user").iter().collect();
@@ -428,7 +436,8 @@ async fn guard(State(st): State<Arc<AppState>>, mut req: Request, next: Next) ->
// The web UI, through edge on the admin host (docs/api.md, "Sign-in"): only a request
// with the per-boot proof edge adds is identified by its Remote-User. Any other
// request that names a user is refused, so a local process cannot claim to be one.
match ui_identity(&st.ctl, req.headers()) {
let via_socket = req.extensions().get::<ViaUiSocket>().is_some();
match ui_identity(&st.ctl, req.headers(), via_socket) {
UiIdentity::None => {}
UiIdentity::Forged => {
return Err(ApiError::new(