[edge] Fixes: skip 1xx, enforce auth timeout, resolve upstreams per connect, all Upgrade tokens, strip Remote-*
This commit is contained in:
@@ -266,7 +266,10 @@ async fn misbehaving_auth_answers_fail_closed() {
|
||||
site: &site,
|
||||
hosts: vec![host_file(
|
||||
"auth.test",
|
||||
&format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url()),
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\nauth = \"forward-auth\"\n",
|
||||
echo.url()
|
||||
),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
@@ -275,15 +278,26 @@ async fn misbehaving_auth_answers_fail_closed() {
|
||||
let addr = edge.https;
|
||||
async move {
|
||||
let cookie = format!("authelia_session={session}");
|
||||
client::https(addr, "auth.test", roots, &Req::get("auth.test", "/").header("cookie", &cookie)).await
|
||||
client::https(
|
||||
addr,
|
||||
"auth.test",
|
||||
roots,
|
||||
&Req::get("auth.test", "/").header("cookie", &cookie),
|
||||
)
|
||||
.await
|
||||
}
|
||||
};
|
||||
|
||||
// 100 Continue before the real answer is skipped, like any HTTP client does.
|
||||
let r = go("continue-ok").await.expect("edge answers after a 1xx from the auth server");
|
||||
let r = go("continue-ok")
|
||||
.await
|
||||
.expect("edge answers after a 1xx from the auth server");
|
||||
assert_eq!(r.status, 200);
|
||||
assert_eq!(echo.proxied().len(), 1);
|
||||
assert_eq!(echo.proxied()[0].header("remote-user"), Some(b"alice".as_slice()));
|
||||
assert_eq!(
|
||||
echo.proxied()[0].header("remote-user"),
|
||||
Some(b"alice".as_slice())
|
||||
);
|
||||
echo.clear();
|
||||
|
||||
// 101 is a final answer but not an allow: denied with 502.
|
||||
@@ -296,9 +310,15 @@ async fn misbehaving_auth_answers_fail_closed() {
|
||||
|
||||
// An auth server that never answers: 502 once the 10 s auth timeout passes.
|
||||
let t = std::time::Instant::now();
|
||||
let r = go("hang").await.expect("edge answers a hanging auth server");
|
||||
let r = go("hang")
|
||||
.await
|
||||
.expect("edge answers a hanging auth server");
|
||||
assert_eq!(r.status, 502);
|
||||
assert!(t.elapsed() < std::time::Duration::from_secs(14), "took {:?}", t.elapsed());
|
||||
assert!(
|
||||
t.elapsed() < std::time::Duration::from_secs(14),
|
||||
"took {:?}",
|
||||
t.elapsed()
|
||||
);
|
||||
assert!(echo.proxied().is_empty());
|
||||
|
||||
// Still serving afterwards.
|
||||
@@ -313,12 +333,18 @@ async fn remote_headers_are_stripped_even_with_a_custom_copy_list() {
|
||||
let echo = Echo::start("app").await;
|
||||
for copy in ["[]", "[\"Remote-User\"]"] {
|
||||
echo.clear();
|
||||
let site = format!("[forward_auth]\nurl = \"{}\"\ncopy_headers = {copy}\n", authelia.url());
|
||||
let site = format!(
|
||||
"[forward_auth]\nurl = \"{}\"\ncopy_headers = {copy}\n",
|
||||
authelia.url()
|
||||
);
|
||||
let edge = start(EdgeSpec {
|
||||
site: &site,
|
||||
hosts: vec![host_file(
|
||||
"auth.test",
|
||||
&format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url()),
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\nauth = \"forward-auth\"\n",
|
||||
echo.url()
|
||||
),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
+107
-22
@@ -23,15 +23,35 @@ async fn upstream_names_are_resolved_at_connect_time_trying_every_address() {
|
||||
let echo = Echo::start("app").await;
|
||||
let edge = start(EdgeSpec {
|
||||
hosts: vec![
|
||||
host_file("local.test", &format!("upstreams = [\"http://localhost:{}\"]\n", echo.addr.port())),
|
||||
host_file("gone.test", "upstreams = [\"http://no-such-host.invalid:8080\"]\n"),
|
||||
host_file(
|
||||
"local.test",
|
||||
&format!("upstreams = [\"http://localhost:{}\"]\n", echo.addr.port()),
|
||||
),
|
||||
host_file(
|
||||
"gone.test",
|
||||
"upstreams = [\"http://no-such-host.invalid:8080\"]\n",
|
||||
),
|
||||
],
|
||||
..Default::default()
|
||||
});
|
||||
let r = client::https(edge.https, "local.test", edge.roots(), &Req::get("local.test", "/")).await.unwrap();
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"local.test",
|
||||
edge.roots(),
|
||||
&Req::get("local.test", "/"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 200, "{}", edge.stderr());
|
||||
// An upstream that does not resolve is a 502 for that host, not a startup failure.
|
||||
let r = client::https(edge.https, "gone.test", edge.roots(), &Req::get("gone.test", "/")).await.unwrap();
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"gone.test",
|
||||
edge.roots(),
|
||||
&Req::get("gone.test", "/"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 502);
|
||||
}
|
||||
|
||||
@@ -52,14 +72,35 @@ async fn health_checks_survive_informational_answers() {
|
||||
let edge = start(EdgeSpec {
|
||||
hosts: vec![host_file(
|
||||
"hc.test",
|
||||
&format!("upstreams = [\"{}\"]\n[health_check]\npath = \"/healthz\"\ninterval_secs = 1\n", up.url()),
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\n[health_check]\npath = \"/healthz\"\ninterval_secs = 1\n",
|
||||
up.url()
|
||||
),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
tokio::time::sleep(Duration::from_millis(5500)).await;
|
||||
let r = client::https(edge.https, "hc.test", edge.roots(), &Req::get("hc.test", "/")).await.unwrap();
|
||||
assert_eq!(r.status, 503, "health checks kept running and marked the upstream down\n{}", edge.stderr());
|
||||
assert!(up.requests().iter().filter(|r| r.path == "/healthz").count() >= 4);
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"hc.test",
|
||||
edge.roots(),
|
||||
&Req::get("hc.test", "/"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
r.status,
|
||||
503,
|
||||
"health checks kept running and marked the upstream down\n{}",
|
||||
edge.stderr()
|
||||
);
|
||||
assert!(
|
||||
up.requests()
|
||||
.iter()
|
||||
.filter(|r| r.path == "/healthz")
|
||||
.count()
|
||||
>= 4
|
||||
);
|
||||
}
|
||||
|
||||
/// QC m4: every Upgrade header and every comma-separated token counts.
|
||||
@@ -67,37 +108,81 @@ async fn health_checks_survive_informational_answers() {
|
||||
async fn websocket_refusal_checks_every_upgrade_token() {
|
||||
let echo = Echo::start("app").await;
|
||||
let edge = start(EdgeSpec {
|
||||
hosts: vec![host_file("nows.test", &format!("upstreams = [\"{}\"]\nwebsockets = false\n", echo.url()))],
|
||||
hosts: vec![host_file(
|
||||
"nows.test",
|
||||
&format!("upstreams = [\"{}\"]\nwebsockets = false\n", echo.url()),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
let cases = [
|
||||
Req::get("nows.test", "/").header("connection", "upgrade").header("upgrade", "h2c").header("upgrade", "websocket"),
|
||||
Req::get("nows.test", "/").header("connection", "upgrade").header("upgrade", "websocket, h2c"),
|
||||
Req::get("nows.test", "/").header("connection", "upgrade").header("upgrade", "h2c , WebSocket"),
|
||||
Req::get("nows.test", "/")
|
||||
.header("connection", "upgrade")
|
||||
.header("upgrade", "h2c")
|
||||
.header("upgrade", "websocket"),
|
||||
Req::get("nows.test", "/")
|
||||
.header("connection", "upgrade")
|
||||
.header("upgrade", "websocket, h2c"),
|
||||
Req::get("nows.test", "/")
|
||||
.header("connection", "upgrade")
|
||||
.header("upgrade", "h2c , WebSocket"),
|
||||
];
|
||||
for req in &cases {
|
||||
let r = client::https(edge.https, "nows.test", edge.roots(), req).await.unwrap();
|
||||
let r = client::https(edge.https, "nows.test", edge.roots(), req)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 403, "{req:?}");
|
||||
}
|
||||
assert!(echo.proxied().is_empty());
|
||||
}
|
||||
|
||||
/// QC nit: absolute-form request targets are answered and routed by the URI's host
|
||||
/// (RFC 9112 §3.2.2), as Go/Caddy do.
|
||||
/// QC nit: absolute-form request targets are answered, never dropped. Pingora refuses a target
|
||||
/// whose authority differs from Host (400, on both listeners); a consistent one is routed and
|
||||
/// sent upstream in origin form.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn absolute_form_requests_are_answered() {
|
||||
let echo = Echo::start("app").await;
|
||||
let edge = start(EdgeSpec {
|
||||
hosts: vec![host_file("plain.test", &format!("upstreams = [\"{}\"]\n", echo.url()))],
|
||||
hosts: vec![host_file(
|
||||
"plain.test",
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]
|
||||
",
|
||||
echo.url()
|
||||
),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
let r = client::http(edge.http, &Req::get("plain.test", "http://evil.test/x")).await.unwrap();
|
||||
assert_eq!(r.status, 404, "plain HTTP");
|
||||
let r = client::https(edge.https, "plain.test", edge.roots(), &Req::get("plain.test", "https://evil.test/x"))
|
||||
let r = client::http(edge.http, &Req::get("plain.test", "http://evil.test/x"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 404, "HTTPS");
|
||||
let r = client::http(edge.http, &Req::get("evil.test", "http://plain.test/x?y")).await.unwrap();
|
||||
assert_eq!(r.status, 308);
|
||||
assert_eq!(r.status, 400, "plain HTTP, Host differs from the target");
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"plain.test",
|
||||
edge.roots(),
|
||||
&Req::get("plain.test", "https://evil.test/x"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 400, "HTTPS, Host differs from the target");
|
||||
assert!(echo.proxied().is_empty());
|
||||
|
||||
let r = client::http(edge.http, &Req::get("plain.test", "http://plain.test/x?y"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 308);
|
||||
assert_eq!(
|
||||
r.header("location"),
|
||||
Some(format!("https://plain.test:{}/x?y", edge.https.port()).as_str())
|
||||
);
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"plain.test",
|
||||
edge.roots(),
|
||||
&Req::get("plain.test", "https://plain.test/abs?q=1"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 200);
|
||||
assert!(r.text().contains("\"path\":\"/abs\""), "{}", r.text());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user