[edge] Fixes: skip 1xx, enforce auth timeout, resolve upstreams per connect, all Upgrade tokens, strip Remote-*

This commit is contained in:
2026-11-07 15:48:18 +01:00
parent 60aee5d78a
commit a272e476b7
10 changed files with 509 additions and 115 deletions
+46 -11
View File
@@ -6,7 +6,7 @@
//! parsed header names, secrets loaded, certificates loaded. Built once at startup.
use std::collections::{BTreeSet, HashMap};
use std::net::{SocketAddr, ToSocketAddrs};
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicUsize};
@@ -27,7 +27,9 @@ pub enum Op {
}
pub struct UpstreamRt {
pub addr: SocketAddr,
/// Host name or IP literal (IPv6 without brackets).
pub host: String,
pub port: u16,
/// `host:port` as configured; the Host header of health checks.
pub authority: String,
pub tls: bool,
@@ -49,6 +51,8 @@ pub struct ForwardAuthRt {
pub upstream: UpstreamRt,
pub path_and_query: String,
pub copy_headers: Vec<HeaderName>,
/// Removed from every client request on a forward-auth host before anything else.
pub strip_headers: Vec<HeaderName>,
}
pub struct Runtime {
@@ -97,19 +101,25 @@ pub fn read_config(path: &Path) -> Result<EdgeConfig, EdgeError> {
}
fn upstream(u: &EdgeUpstream) -> Result<UpstreamRt, EdgeError> {
let err = |reason: String| EdgeError::Upstream {
let err = |reason: &str| EdgeError::Upstream {
address: u.address.clone(),
reason,
reason: reason.to_owned(),
};
// Resolved once at startup; Pingora peers need a socket address.
let addr = u
let (host, port) = u
.address
.to_socket_addrs()
.map_err(|e| err(format!("cannot resolve: {e}")))?
.next()
.ok_or_else(|| err("resolves to no address".into()))?;
.rsplit_once(':')
.ok_or_else(|| err("expected host:port"))?;
let port: u16 = port.parse().map_err(|_| err("bad port"))?;
let host = host
.strip_prefix('[')
.and_then(|h| h.strip_suffix(']'))
.unwrap_or(host);
if host.is_empty() {
return Err(err("empty host"));
}
Ok(UpstreamRt {
addr,
host: host.to_owned(),
port,
authority: u.address.clone(),
tls: u.tls,
sni: u.sni.clone(),
@@ -117,6 +127,26 @@ fn upstream(u: &EdgeUpstream) -> Result<UpstreamRt, EdgeError> {
})
}
impl UpstreamRt {
/// Addresses to try, in resolver order. Names are resolved at connect time (like Caddy's
/// dialer), so DNS changes and unresolvable names only affect requests, not startup.
pub async fn resolve(&self) -> std::io::Result<Vec<SocketAddr>> {
if let Ok(ip) = self.host.parse::<std::net::IpAddr>() {
return Ok(vec![SocketAddr::new(ip, self.port)]);
}
let addrs: Vec<SocketAddr> = tokio::net::lookup_host((self.host.as_str(), self.port))
.await?
.collect();
if addrs.is_empty() {
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"name resolves to no address",
));
}
Ok(addrs)
}
}
fn header_name(name: &str) -> Result<HeaderName, EdgeError> {
HeaderName::from_bytes(name.as_bytes()).map_err(|_| EdgeError::Header {
name: name.to_owned(),
@@ -225,6 +255,11 @@ pub fn build(cfg: EdgeConfig, credentials_dir: Option<&Path>) -> Result<Runtime,
.iter()
.map(|h| header_name(h))
.collect::<Result<_, _>>()?,
strip_headers: fa
.strip_headers
.iter()
.map(|h| header_name(h))
.collect::<Result<_, _>>()?,
}),
None => None,
};