feat(qbzd): default control-plane and login binds to 0.0.0.0 for LAN-first posture
cc
This commit is contained in:
4 files changed
+63
-59
No files matched your search
@@ -129,13 +129,17 @@ pub fn foreign_qbzd(addr: &str) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
/// LAN-exposure warning (02 §6.3, verbatim) — printed by the daemon at boot when
|
||||
/// bound to a non-loopback address, and by the TUI Network screen (T13).
|
||||
pub fn lan_bind_warning(addr: &str) -> String {
|
||||
/// LAN-first posture note (FB6, successor to the old 02 §6.3 LAN-exposure
|
||||
/// warning) — one INFO line logged by the daemon at boot when the control API
|
||||
/// is NOT loopback-only. Since FB6 the default bind is `0.0.0.0`, so this
|
||||
/// fires on every default boot; it is deliberately informational, not a
|
||||
/// `warning:` — an open LAN renderer (Sonos/Chromecast posture) is the
|
||||
/// intended default, the Origin shield already guards browsers, and this line
|
||||
/// just orients the operator toward the two ways to restrict it further.
|
||||
/// `addr` is the bound `ip:port`.
|
||||
pub fn lan_posture_note(addr: &str) -> String {
|
||||
format!(
|
||||
"warning: control API is bound to {addr} — reachable from your network
|
||||
anyone on your LAN can control playback (like Sonos or Chromecast)
|
||||
→ set [server] token in qbzd.toml to require a shared secret"
|
||||
"control plane listening on {addr} — anyone on your network can control playback (set [server] bind = \"127.0.0.1\" or [server] token in qbzd.toml to restrict)"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ pub struct MprisCfg {
|
||||
impl Default for ServerCfg {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bind: "127.0.0.1".into(),
|
||||
bind: "0.0.0.0".into(), // LAN-first posture (FB6): Sonos/Chromecast-style
|
||||
// open renderer; the Origin shield still guards browsers and
|
||||
// `[server] token` remains the opt-in restriction for powerusers.
|
||||
port: 8182,
|
||||
token: None, // open by default (02 §3.1.2)
|
||||
}
|
||||
@@ -123,10 +125,12 @@ mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn defaults_match_spec() {
|
||||
// 01-architecture.md §10.1
|
||||
// 01-architecture.md §10.1 (FB6: default bind widened to 0.0.0.0 for
|
||||
// LAN-first control — restrict via [server] bind or token to opt back
|
||||
// into loopback-only).
|
||||
let (c, warns) = QbzdConfig::from_str("").unwrap();
|
||||
assert_eq!(c.config_version, 1);
|
||||
assert_eq!(c.server.bind, "127.0.0.1");
|
||||
assert_eq!(c.server.bind, "0.0.0.0");
|
||||
assert_eq!(c.server.port, 8182);
|
||||
assert_eq!(c.log.level, "info");
|
||||
assert!(c.mpris.enabled);
|
||||
|
||||
@@ -67,9 +67,10 @@ pub async fn run(roots: ProfileRoots, cfg: QbzdConfig, warns: Vec<String>) -> Re
|
||||
}
|
||||
};
|
||||
if !bind_addr.ip().is_loopback() {
|
||||
// §6.3 verbatim — reachable-from-LAN warning (also shown by the TUI).
|
||||
eprintln!("{}", crate::cli::copy::lan_bind_warning(&bind_addr.to_string()));
|
||||
log::warn!("control API bound to non-loopback {bind_addr}");
|
||||
// FB6: the default bind is now 0.0.0.0 — LAN-first posture (Sonos/
|
||||
// Chromecast parity), not a misconfiguration. One INFO line, not a
|
||||
// stderr warning; loopback binds stay silent.
|
||||
log::info!("{}", crate::cli::copy::lan_posture_note(&bind_addr.to_string()));
|
||||
}
|
||||
|
||||
// 6.-9. compose stores + runtime + restore credentials + restore session.
|
||||
|
||||
+42
-47
@@ -466,51 +466,29 @@ pub(crate) fn nudge_host(roots: &ProfileRoots) -> String {
|
||||
format!("127.0.0.1:{port}")
|
||||
}
|
||||
|
||||
/// FB1: bind the one-shot login listener on an EPHEMERAL port.
|
||||
/// FB6: bind the one-shot login listener WIDE by default, on an EPHEMERAL
|
||||
/// port — the LAN-first posture applies to the login listener too, so the
|
||||
/// OAuth redirect lands regardless of which address on the box is actually
|
||||
/// reachable. This is independent of `redirect_host` (the resolved
|
||||
/// `--callback-host` > `SSH_CONNECTION` > `127.0.0.1` value embedded in the
|
||||
/// URL, unchanged): the listener no longer binds that specific address.
|
||||
///
|
||||
/// - Loopback (`127.0.0.1` / `::1`) binds that loopback address, no
|
||||
/// fallback — the local-laptop case is untouched.
|
||||
/// - Any other IP-literal host (explicit `--callback-host` or an
|
||||
/// SSH-auto-detected LAN address) binds that SPECIFIC address first —
|
||||
/// tighter than the old unconditional `0.0.0.0` — and only falls back to
|
||||
/// the FAMILY-MATCHED wildcard (`0.0.0.0` for v4, `::` for v6), with a
|
||||
/// log line, if that specific bind fails (e.g. the env lied about a
|
||||
/// locally-reachable address). A v4 wildcard under a v6 redirect URL (or
|
||||
/// vice versa) would guarantee a 300 s timeout in exactly the rescue case.
|
||||
/// - Non-IP input (a hostname in `--callback-host`) is NEVER handed to
|
||||
/// `TcpListener::bind` — that would do a blocking DNS lookup this path
|
||||
/// never had. It goes straight to the `0.0.0.0` wildcard with a log line;
|
||||
/// the URL still embeds the raw value the operator gave (embedding is
|
||||
/// their call; binding stays local and synchronous).
|
||||
/// - Family-aware only: an explicit IPv6 `redirect_host` binds the IPv6
|
||||
/// wildcard `::` (so a bracketed IPv6 redirect URL still lands — a v4
|
||||
/// wildcard under a v6 URL would guarantee a 300 s timeout).
|
||||
/// - Everything else — loopback, a v4 LAN IP, or non-IP input (a hostname
|
||||
/// in `--callback-host`, never handed to `TcpListener::bind` to avoid a
|
||||
/// blocking DNS lookup) — binds the IPv4 wildcard `0.0.0.0`.
|
||||
fn bind_login_listener(redirect_host: &str) -> Result<TcpListener, LoginError> {
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
let fail = |e: std::io::Error| {
|
||||
LoginError::Failed(format!("could not bind the login listener: {e}"))
|
||||
};
|
||||
match redirect_host.parse::<IpAddr>() {
|
||||
Ok(ip) if ip.is_loopback() => TcpListener::bind((ip, 0)).map_err(fail),
|
||||
Ok(ip) => match TcpListener::bind((ip, 0)) {
|
||||
Ok(listener) => Ok(listener),
|
||||
Err(e) => {
|
||||
let wildcard: IpAddr = match ip {
|
||||
IpAddr::V4(_) => Ipv4Addr::UNSPECIFIED.into(),
|
||||
IpAddr::V6(_) => Ipv6Addr::UNSPECIFIED.into(),
|
||||
};
|
||||
log::warn!(
|
||||
"could not bind the login listener on {redirect_host}: {e} — \
|
||||
falling back to {wildcard}"
|
||||
);
|
||||
TcpListener::bind((wildcard, 0)).map_err(fail)
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
log::warn!(
|
||||
"callback host {redirect_host:?} is not an IP literal — \
|
||||
binding the login listener on 0.0.0.0 (no DNS lookup)"
|
||||
);
|
||||
TcpListener::bind((Ipv4Addr::UNSPECIFIED, 0)).map_err(fail)
|
||||
}
|
||||
}
|
||||
let wildcard: IpAddr = match redirect_host.parse::<IpAddr>() {
|
||||
Ok(IpAddr::V6(_)) => Ipv6Addr::UNSPECIFIED.into(),
|
||||
_ => Ipv4Addr::UNSPECIFIED.into(),
|
||||
};
|
||||
TcpListener::bind((wildcard, 0)).map_err(fail)
|
||||
}
|
||||
|
||||
fn read_stdin_line() -> Result<String, LoginError> {
|
||||
@@ -732,21 +710,38 @@ mod tests {
|
||||
assert!(!auto);
|
||||
}
|
||||
|
||||
// ---------------------- bind_login_listener (FB1) ----------------------
|
||||
// ---------------------- bind_login_listener (FB6) ----------------------
|
||||
|
||||
#[test]
|
||||
fn bind_login_listener_loopback_v4_binds_loopback() {
|
||||
fn bind_login_listener_loopback_v4_host_binds_the_v4_wildcard() {
|
||||
// FB6: LAN-first posture — even a loopback-resolved redirect host
|
||||
// binds the wide listener now; only the embedded URL stays loopback.
|
||||
let l = bind_login_listener("127.0.0.1").unwrap();
|
||||
assert!(l.local_addr().unwrap().ip().is_loopback());
|
||||
let addr = l.local_addr().unwrap();
|
||||
assert!(addr.ip().is_unspecified(), "{addr}");
|
||||
assert!(addr.is_ipv4(), "{addr}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bind_login_listener_treats_v6_loopback_as_loopback() {
|
||||
// Minor fold: "::1" takes the loopback fast-path (no wildcard fallback).
|
||||
fn bind_login_listener_v4_lan_host_binds_the_v4_wildcard() {
|
||||
// An explicit/SSH-detected LAN v4 host also binds wide, not that
|
||||
// specific address.
|
||||
let l = bind_login_listener("192.168.1.50").unwrap();
|
||||
let addr = l.local_addr().unwrap();
|
||||
assert!(addr.ip().is_unspecified(), "{addr}");
|
||||
assert!(addr.is_ipv4(), "{addr}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bind_login_listener_v6_host_binds_the_v6_wildcard() {
|
||||
// Family-aware: an explicit IPv6 host binds the IPv6 wildcard `::`.
|
||||
match bind_login_listener("::1") {
|
||||
Ok(l) => assert!(l.local_addr().unwrap().ip().is_loopback()),
|
||||
// A box with IPv6 disabled can't bind ::1 at all — the error path
|
||||
// (no silent wildcard rescue for loopback) is the assertion then.
|
||||
Ok(l) => {
|
||||
let addr = l.local_addr().unwrap();
|
||||
assert!(addr.ip().is_unspecified(), "{addr}");
|
||||
assert!(addr.is_ipv6(), "{addr}");
|
||||
}
|
||||
// A box with IPv6 disabled can't bind `::` at all.
|
||||
Err(e) => assert!(e.to_string().contains("could not bind"), "{e}"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user