[edge] Listeners: a request header must be complete within 60 s (--header-timeout), pipelined requests are answered in order, and --proxy-socket serves the front proxy on a 0660 Unix socket whose X-Forwarded-For is believed

This commit is contained in:
2026-11-10 20:46:28 +01:00
parent 7a2aee20eb
commit 39dd8f0f47
6 changed files with 82 additions and 22 deletions
+27
View File
@@ -59,6 +59,10 @@ pub struct Options {
pub credentials_dir: Option<PathBuf>,
/// The overall deadline for a request header; default [`deadline::HEADER_TIMEOUT`].
pub header_timeout: Option<std::time::Duration>,
/// A Unix socket (mode 0660) on which edge serves the HTTPS hosts in plain HTTP to a front
/// proxy that terminated TLS (Caddy beside Ianitor). Only the socket's owner and group can
/// connect, so its `X-Forwarded-For` is believed (Unix only).
pub proxy_socket: Option<PathBuf>,
}
impl Options {
@@ -143,6 +147,9 @@ pub fn server(shared: Arc<Shared>, opts: &Options) -> Result<Server, EdgeError>
https
.endpoints()
.set_pre_tls_callback(Arc::new(tls::HandshakeStart));
if let Some(path) = &opts.proxy_socket {
add_proxy_socket(&mut https, path)?;
}
let mut http = Service::new(
"ianitor http".to_owned(),
@@ -193,6 +200,26 @@ pub fn server(shared: Arc<Shared>, opts: &Options) -> Result<Server, EdgeError>
Ok(server)
}
/// The front proxy's socket on the HTTPS service: plain HTTP, mode 0660.
#[cfg(unix)]
fn add_proxy_socket<A>(svc: &mut Service<A>, path: &Path) -> Result<(), EdgeError> {
use std::os::unix::fs::PermissionsExt;
let p = path.to_str().ok_or_else(|| EdgeError::Listen {
address: path.display().to_string(),
reason: "the proxy socket path is not UTF-8".into(),
})?;
svc.add_uds(p, Some(std::fs::Permissions::from_mode(0o660)));
Ok(())
}
#[cfg(not(unix))]
fn add_proxy_socket<A>(_svc: &mut Service<A>, path: &Path) -> Result<(), EdgeError> {
Err(EdgeError::Listen {
address: path.display().to_string(),
reason: "a proxy socket needs a Unix system".into(),
})
}
/// Run until `stop` resolves (or is dropped). For running edge inside a test process.
#[cfg(unix)]
pub fn run_until(server: Server, stop: tokio::sync::oneshot::Receiver<()>) {