[edge] Proxy: Pingora data plane with SNI certs, forward-auth, header rules, health checks, ACME
This commit is contained in:
@@ -13,8 +13,8 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use ianitor_core::compile::{self, CompileOptions};
|
||||
use ianitor_core::{load, SourceFile, TlsMode};
|
||||
use ianitor_testkit::proc::{free_port, local, wait_for_port, ChildGuard, TempDir};
|
||||
use ianitor_core::{SourceFile, TlsMode, load};
|
||||
use ianitor_testkit::proc::{ChildGuard, TempDir, free_port, local, wait_for_port};
|
||||
use ianitor_testkit::tls::TestCa;
|
||||
use rustls::RootCertStore;
|
||||
|
||||
@@ -42,7 +42,12 @@ impl Edge {
|
||||
|
||||
/// Everything edge wrote or was given, except the credentials themselves.
|
||||
pub fn all_output(&self) -> String {
|
||||
format!("{}\n{}\n{}", self.stderr(), self.access_log(), self.config_text)
|
||||
format!(
|
||||
"{}\n{}\n{}",
|
||||
self.stderr(),
|
||||
self.access_log(),
|
||||
self.config_text
|
||||
)
|
||||
}
|
||||
|
||||
pub fn exited(&mut self) -> Option<std::process::ExitStatus> {
|
||||
@@ -60,7 +65,13 @@ pub struct EdgeSpec<'a> {
|
||||
|
||||
impl Default for EdgeSpec<'_> {
|
||||
fn default() -> Self {
|
||||
EdgeSpec { site: "", hosts: Vec::new(), secrets: Vec::new(), log_level: "info", extra_args: Vec::new() }
|
||||
EdgeSpec {
|
||||
site: "",
|
||||
hosts: Vec::new(),
|
||||
secrets: Vec::new(),
|
||||
log_level: "info",
|
||||
extra_args: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,14 +81,32 @@ pub fn spawn(spec: EdgeSpec<'_>) -> Edge {
|
||||
for d in ["certs", "state", "creds", "logs"] {
|
||||
std::fs::create_dir_all(dir.join(d)).unwrap();
|
||||
}
|
||||
let sources: Vec<SourceFile> = spec.hosts.iter().map(|(n, c)| SourceFile { name: n, contents: c }).collect();
|
||||
let model = load(&SourceFile { name: "ianitor.toml", contents: spec.site }, &sources).expect("valid routes");
|
||||
let sources: Vec<SourceFile> = spec
|
||||
.hosts
|
||||
.iter()
|
||||
.map(|(n, c)| SourceFile {
|
||||
name: n,
|
||||
contents: c,
|
||||
})
|
||||
.collect();
|
||||
let model = load(
|
||||
&SourceFile {
|
||||
name: "ianitor.toml",
|
||||
contents: spec.site,
|
||||
},
|
||||
&sources,
|
||||
)
|
||||
.expect("valid routes");
|
||||
|
||||
let ca = TestCa::new("Ianitor Test CA");
|
||||
for h in model.hosts() {
|
||||
if h.tls == TlsMode::Domi {
|
||||
let leaf = ca.issue(&[h.hostname.as_str()]);
|
||||
std::fs::write(dir.join(&format!("certs/{}.crt", h.hostname)), leaf.cert_pem).unwrap();
|
||||
std::fs::write(
|
||||
dir.join(&format!("certs/{}.crt", h.hostname)),
|
||||
leaf.cert_pem,
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(dir.join(&format!("certs/{}.key", h.hostname)), leaf.key_pem).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -105,15 +134,24 @@ pub fn spawn(spec: EdgeSpec<'_>) -> Edge {
|
||||
cmd.args(&spec.extra_args);
|
||||
cmd.env("CREDENTIALS_DIRECTORY", dir.join("creds"));
|
||||
cmd.env("IANITOR_LOG", spec.log_level);
|
||||
cmd.stdout(Stdio::from(stderr.try_clone().unwrap())).stderr(Stdio::from(stderr));
|
||||
cmd.stdout(Stdio::from(stderr.try_clone().unwrap()))
|
||||
.stderr(Stdio::from(stderr));
|
||||
let child = ChildGuard(cmd.spawn().expect("spawn ianitor-edge"));
|
||||
Edge { child, http, https, dir, ca, config_text }
|
||||
Edge {
|
||||
child,
|
||||
http,
|
||||
https,
|
||||
dir,
|
||||
ca,
|
||||
config_text,
|
||||
}
|
||||
}
|
||||
|
||||
/// Spawn and wait until both listeners accept connections.
|
||||
pub fn start(spec: EdgeSpec<'_>) -> Edge {
|
||||
let mut e = spawn(spec);
|
||||
let ok = wait_for_port(e.https, Duration::from_secs(20)) && wait_for_port(e.http, Duration::from_secs(5));
|
||||
let ok = wait_for_port(e.https, Duration::from_secs(20))
|
||||
&& wait_for_port(e.http, Duration::from_secs(5));
|
||||
if !ok || e.exited().is_some() {
|
||||
panic!("ianitor-edge did not start:\n{}", e.stderr());
|
||||
}
|
||||
@@ -121,5 +159,8 @@ pub fn start(spec: EdgeSpec<'_>) -> Edge {
|
||||
}
|
||||
|
||||
pub fn host_file(hostname: &str, body: &str) -> (String, String) {
|
||||
(format!("hosts/{hostname}.toml"), format!("hostname = \"{hostname}\"\ntls = \"domi\"\n{body}"))
|
||||
(
|
||||
format!("hosts/{hostname}.toml"),
|
||||
format!("hostname = \"{hostname}\"\ntls = \"domi\"\n{body}"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{host_file, start, EdgeSpec};
|
||||
use common::{EdgeSpec, host_file, start};
|
||||
use ianitor_testkit::authelia::MockAuthelia;
|
||||
use ianitor_testkit::client::{self, Req, WsOutcome};
|
||||
use ianitor_testkit::upstream::{closed_port, Echo, WsEcho};
|
||||
use ianitor_testkit::upstream::{Echo, WsEcho, closed_port};
|
||||
|
||||
fn site(auth_url: &str) -> String {
|
||||
format!("[forward_auth]\nurl = \"{auth_url}\"\n")
|
||||
@@ -29,8 +29,17 @@ async fn denial_never_reaches_the_upstream() {
|
||||
let edge = start(EdgeSpec {
|
||||
site: &site,
|
||||
hosts: vec![
|
||||
host_file("auth.test", &format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url())),
|
||||
host_file("wsauth.test", &format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", ws.url())),
|
||||
host_file(
|
||||
"auth.test",
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\nauth = \"forward-auth\"\n",
|
||||
echo.url()
|
||||
),
|
||||
),
|
||||
host_file(
|
||||
"wsauth.test",
|
||||
&format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", ws.url()),
|
||||
),
|
||||
],
|
||||
..Default::default()
|
||||
});
|
||||
@@ -48,7 +57,10 @@ async fn denial_never_reaches_the_upstream() {
|
||||
r.header("location"),
|
||||
Some("https://auth.test/?rd=https%3A%2F%2Fauth.test%2Fprivate%3Fx%3D1")
|
||||
);
|
||||
assert_eq!(r.header("set-cookie"), Some("authelia_flow=1; Path=/; HttpOnly"));
|
||||
assert_eq!(
|
||||
r.header("set-cookie"),
|
||||
Some("authelia_flow=1; Path=/; HttpOnly")
|
||||
);
|
||||
assert!(r.text().contains("302 Found"));
|
||||
|
||||
let r = go(Req::new("HEAD", "auth.test", "/")).await;
|
||||
@@ -60,7 +72,10 @@ async fn denial_never_reaches_the_upstream() {
|
||||
|
||||
let r = go(Req::get("auth.test", "/").header("authorization", "Bearer wrong")).await;
|
||||
assert_eq!(r.status, 401);
|
||||
assert_eq!(r.header("www-authenticate"), Some("Basic realm=\"Authorization Required\""));
|
||||
assert_eq!(
|
||||
r.header("www-authenticate"),
|
||||
Some("Basic realm=\"Authorization Required\"")
|
||||
);
|
||||
|
||||
let r = go(Req::get("auth.test", "/").header("cookie", "authelia_session=forbidden")).await;
|
||||
assert_eq!(r.status, 403);
|
||||
@@ -74,16 +89,38 @@ async fn denial_never_reaches_the_upstream() {
|
||||
.header("x-forwarded-for", "10.0.0.1"))
|
||||
.await;
|
||||
assert_eq!(r.status, 302);
|
||||
assert!(r.header("location").unwrap().contains("auth.test%2Fadmin"), "edge sends its own X-Forwarded-*");
|
||||
assert!(
|
||||
r.header("location").unwrap().contains("auth.test%2Fadmin"),
|
||||
"edge sends its own X-Forwarded-*"
|
||||
);
|
||||
|
||||
// A websocket upgrade without a session is denied before any upgrade happens.
|
||||
match client::websocket(edge.https, "wsauth.test", roots.clone(), "wsauth.test", "/socket", &[], "hi").await.unwrap() {
|
||||
match client::websocket(
|
||||
edge.https,
|
||||
"wsauth.test",
|
||||
roots.clone(),
|
||||
"wsauth.test",
|
||||
"/socket",
|
||||
&[],
|
||||
"hi",
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
WsOutcome::Refused(r) => assert_eq!(r.status, 302),
|
||||
WsOutcome::Upgraded { .. } => panic!("unauthenticated websocket was upgraded"),
|
||||
}
|
||||
|
||||
assert!(echo.proxied().is_empty(), "a denied request reached the upstream: {:?}", echo.proxied());
|
||||
assert_eq!(ws.connections(), 0, "a denied websocket reached the upstream");
|
||||
assert!(
|
||||
echo.proxied().is_empty(),
|
||||
"a denied request reached the upstream: {:?}",
|
||||
echo.proxied()
|
||||
);
|
||||
assert_eq!(
|
||||
ws.connections(),
|
||||
0,
|
||||
"a denied websocket reached the upstream"
|
||||
);
|
||||
|
||||
// What Authelia was told, per its proxy-authorization guide.
|
||||
let asked = authelia.requests();
|
||||
@@ -95,10 +132,22 @@ async fn denial_never_reaches_the_upstream() {
|
||||
assert_eq!(post.method, "GET", "the auth subrequest is a GET");
|
||||
assert_eq!(post.path, "/api/authz/forward-auth");
|
||||
assert_eq!(post.header("x-forwarded-proto"), Some(b"https".as_slice()));
|
||||
assert_eq!(post.header("x-forwarded-host"), Some(b"auth.test".as_slice()));
|
||||
assert_eq!(post.header("x-forwarded-uri"), Some(b"/submit?x=1".as_slice()));
|
||||
assert_eq!(post.header("x-forwarded-for"), Some(b"127.0.0.1".as_slice()));
|
||||
assert!(post.body.is_empty(), "the request body is not sent to the auth server");
|
||||
assert_eq!(
|
||||
post.header("x-forwarded-host"),
|
||||
Some(b"auth.test".as_slice())
|
||||
);
|
||||
assert_eq!(
|
||||
post.header("x-forwarded-uri"),
|
||||
Some(b"/submit?x=1".as_slice())
|
||||
);
|
||||
assert_eq!(
|
||||
post.header("x-forwarded-for"),
|
||||
Some(b"127.0.0.1".as_slice())
|
||||
);
|
||||
assert!(
|
||||
post.body.is_empty(),
|
||||
"the request body is not sent to the auth server"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
@@ -108,7 +157,13 @@ async fn allowed_request_carries_identity_from_the_auth_server_only() {
|
||||
let site = site(&authelia.url());
|
||||
let edge = start(EdgeSpec {
|
||||
site: &site,
|
||||
hosts: vec![host_file("auth.test", &format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url()))],
|
||||
hosts: vec![host_file(
|
||||
"auth.test",
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\nauth = \"forward-auth\"\n",
|
||||
echo.url()
|
||||
),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
let roots = edge.roots();
|
||||
@@ -131,10 +186,19 @@ async fn allowed_request_carries_identity_from_the_auth_server_only() {
|
||||
let up = &seen[0];
|
||||
assert_eq!(up.header("remote-user"), Some(b"alice".as_slice()));
|
||||
assert_eq!(up.header("remote-groups"), Some(b"admins,dev".as_slice()));
|
||||
assert_eq!(up.header("remote-email"), Some(b"alice@example.org".as_slice()));
|
||||
assert_eq!(
|
||||
up.header("remote-email"),
|
||||
Some(b"alice@example.org".as_slice())
|
||||
);
|
||||
assert_eq!(up.header("remote-name"), Some(b"Alice Example".as_slice()));
|
||||
assert_eq!(up.body, b"form=data", "the body still reaches the upstream");
|
||||
assert_eq!(up.headers.iter().filter(|(n, _)| n == "remote-user").count(), 1);
|
||||
assert_eq!(
|
||||
up.headers
|
||||
.iter()
|
||||
.filter(|(n, _)| n == "remote-user")
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
|
||||
// Allowed without identity: the client's own Remote-* headers are removed, not passed on.
|
||||
echo.clear();
|
||||
@@ -142,31 +206,52 @@ async fn allowed_request_carries_identity_from_the_auth_server_only() {
|
||||
edge.https,
|
||||
"auth.test",
|
||||
roots.clone(),
|
||||
&Req::get("auth.test", "/").header("cookie", "authelia_session=nameless").header("remote-user", "mallory"),
|
||||
&Req::get("auth.test", "/")
|
||||
.header("cookie", "authelia_session=nameless")
|
||||
.header("remote-user", "mallory"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 200);
|
||||
assert_eq!(echo.proxied()[0].header("remote-user"), None);
|
||||
|
||||
let r = client::https(edge.https, "auth.test", roots, &Req::get("auth.test", "/").header("authorization", "Bearer good"))
|
||||
.await
|
||||
.unwrap();
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"auth.test",
|
||||
roots,
|
||||
&Req::get("auth.test", "/").header("authorization", "Bearer good"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 200);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn unreachable_auth_server_fails_closed() {
|
||||
let echo = Echo::start("app").await;
|
||||
let site = site(&format!("http://127.0.0.1:{}/api/authz/forward-auth", closed_port()));
|
||||
let site = site(&format!(
|
||||
"http://127.0.0.1:{}/api/authz/forward-auth",
|
||||
closed_port()
|
||||
));
|
||||
let edge = start(EdgeSpec {
|
||||
site: &site,
|
||||
hosts: vec![host_file("auth.test", &format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url()))],
|
||||
hosts: vec![host_file(
|
||||
"auth.test",
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\nauth = \"forward-auth\"\n",
|
||||
echo.url()
|
||||
),
|
||||
)],
|
||||
..Default::default()
|
||||
});
|
||||
let r = client::https(edge.https, "auth.test", edge.roots(), &Req::get("auth.test", "/").header("cookie", "authelia_session=good"))
|
||||
.await
|
||||
.unwrap();
|
||||
let r = client::https(
|
||||
edge.https,
|
||||
"auth.test",
|
||||
edge.roots(),
|
||||
&Req::get("auth.test", "/").header("cookie", "authelia_session=good"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(r.status, 502);
|
||||
assert!(echo.proxied().is_empty());
|
||||
}
|
||||
|
||||
+120
-26
@@ -10,12 +10,15 @@
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{host_file, start, spawn, EdgeSpec};
|
||||
use common::{EdgeSpec, host_file, spawn, start};
|
||||
use ianitor_testkit::client::{self, Req, Resp, WsOutcome};
|
||||
use ianitor_testkit::upstream::{closed_port, Echo, WsEcho};
|
||||
use ianitor_testkit::upstream::{Echo, WsEcho, closed_port};
|
||||
|
||||
fn unique_secret() -> String {
|
||||
let nanos = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();
|
||||
let nanos = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
format!("sekret-{}-{nanos:x}-tail", std::process::id())
|
||||
}
|
||||
|
||||
@@ -26,7 +29,11 @@ fn assert_clean(what: &str, haystack: &[u8], secret: &str) {
|
||||
|
||||
fn assert_resp_clean(what: &str, r: &Resp, secret: &str) {
|
||||
for (n, v) in &r.headers {
|
||||
assert_clean(&format!("{what}: response header {n}"), v.as_bytes(), secret);
|
||||
assert_clean(
|
||||
&format!("{what}: response header {n}"),
|
||||
v.as_bytes(),
|
||||
secret,
|
||||
);
|
||||
}
|
||||
assert_clean(&format!("{what}: response body"), &r.body, secret);
|
||||
}
|
||||
@@ -36,13 +43,32 @@ async fn injected_secret_never_appears_in_a_response_or_log() {
|
||||
let secret = unique_secret();
|
||||
let echo = Echo::start("app").await;
|
||||
let ws = WsEcho::start().await;
|
||||
let rule = "[[request_headers]]\naction = \"set\"\nname = \"X-Api-Key\"\nsecret = \"api_key\"\n";
|
||||
let rule =
|
||||
"[[request_headers]]\naction = \"set\"\nname = \"X-Api-Key\"\nsecret = \"api_key\"\n";
|
||||
let edge = start(EdgeSpec {
|
||||
site: "secrets = [\"api_key\"]\n",
|
||||
hosts: vec![
|
||||
host_file("app.test", &format!("upstreams = [\"{}\"]\naccess_log = \"truncated\"\n{rule}", echo.url())),
|
||||
host_file("down.test", &format!("upstreams = [\"http://127.0.0.1:{}\"]\naccess_log = \"truncated\"\n{rule}", closed_port())),
|
||||
host_file("ws.test", &format!("upstreams = [\"{}\"]\naccess_log = \"truncated\"\n{rule}", ws.url())),
|
||||
host_file(
|
||||
"app.test",
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\naccess_log = \"truncated\"\n{rule}",
|
||||
echo.url()
|
||||
),
|
||||
),
|
||||
host_file(
|
||||
"down.test",
|
||||
&format!(
|
||||
"upstreams = [\"http://127.0.0.1:{}\"]\naccess_log = \"truncated\"\n{rule}",
|
||||
closed_port()
|
||||
),
|
||||
),
|
||||
host_file(
|
||||
"ws.test",
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\naccess_log = \"truncated\"\n{rule}",
|
||||
ws.url()
|
||||
),
|
||||
),
|
||||
],
|
||||
// systemd credentials usually end with a newline; it is not part of the value.
|
||||
secrets: vec![("api_key".into(), format!("{secret}\n").into_bytes())],
|
||||
@@ -57,20 +83,45 @@ async fn injected_secret_never_appears_in_a_response_or_log() {
|
||||
};
|
||||
|
||||
let mut responses = Vec::new();
|
||||
responses.push(("plain GET", go("app.test", Req::get("app.test", "/hello?token=abc")).await));
|
||||
responses.push(("POST", go("app.test", Req::new("POST", "app.test", "/submit").body(b"payload")).await));
|
||||
responses.push((
|
||||
"plain GET",
|
||||
go("app.test", Req::get("app.test", "/hello?token=abc")).await,
|
||||
));
|
||||
responses.push((
|
||||
"POST",
|
||||
go(
|
||||
"app.test",
|
||||
Req::new("POST", "app.test", "/submit").body(b"payload"),
|
||||
)
|
||||
.await,
|
||||
));
|
||||
responses.push((
|
||||
"client tries to set the header",
|
||||
go("app.test", Req::get("app.test", "/").header("x-api-key", "attacker")).await,
|
||||
go(
|
||||
"app.test",
|
||||
Req::get("app.test", "/").header("x-api-key", "attacker"),
|
||||
)
|
||||
.await,
|
||||
));
|
||||
responses.push((
|
||||
"upstream error status",
|
||||
go("app.test", Req::get("app.test", "/status/500")).await,
|
||||
));
|
||||
responses.push(("upstream error status", go("app.test", Req::get("app.test", "/status/500")).await));
|
||||
responses.push((
|
||||
"upstream reflects the secret in a header",
|
||||
go("app.test", Req::get("app.test", "/reflect?h=x-api-key")).await,
|
||||
));
|
||||
responses.push(("upstream down", go("down.test", Req::get("down.test", "/")).await));
|
||||
responses.push(("unknown host", go("app.test", Req::get("nope.test", "/")).await));
|
||||
let plain = client::http(edge.http, &Req::get("app.test", "/x?y=1")).await.unwrap();
|
||||
responses.push((
|
||||
"upstream down",
|
||||
go("down.test", Req::get("down.test", "/")).await,
|
||||
));
|
||||
responses.push((
|
||||
"unknown host",
|
||||
go("app.test", Req::get("nope.test", "/")).await,
|
||||
));
|
||||
let plain = client::http(edge.http, &Req::get("app.test", "/x?y=1"))
|
||||
.await
|
||||
.unwrap();
|
||||
responses.push(("plain HTTP redirect", plain));
|
||||
|
||||
for (what, r) in &responses {
|
||||
@@ -78,10 +129,24 @@ async fn injected_secret_never_appears_in_a_response_or_log() {
|
||||
}
|
||||
assert_eq!(responses[0].1.status, 200);
|
||||
assert_eq!(responses[4].1.status, 200);
|
||||
assert!(responses[4].1.header("x-reflected").is_none(), "edge strips a response header carrying a secret");
|
||||
assert!(
|
||||
responses[4].1.header("x-reflected").is_none(),
|
||||
"edge strips a response header carrying a secret"
|
||||
);
|
||||
assert_eq!(responses[5].1.status, 502);
|
||||
|
||||
match client::websocket(edge.https, "ws.test", roots.clone(), "ws.test", "/socket", &[], "ping").await.unwrap() {
|
||||
match client::websocket(
|
||||
edge.https,
|
||||
"ws.test",
|
||||
roots.clone(),
|
||||
"ws.test",
|
||||
"/socket",
|
||||
&[],
|
||||
"ping",
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
WsOutcome::Upgraded { status, echo } => {
|
||||
assert_eq!(status, 101);
|
||||
assert_eq!(echo, "ping");
|
||||
@@ -93,18 +158,38 @@ async fn injected_secret_never_appears_in_a_response_or_log() {
|
||||
let seen = echo.proxied();
|
||||
assert!(seen.len() >= 5, "{seen:?}");
|
||||
for r in &seen {
|
||||
assert_eq!(r.header("x-api-key"), Some(secret.as_bytes()), "upstream request {}", r.path);
|
||||
assert_eq!(
|
||||
r.header("x-api-key"),
|
||||
Some(secret.as_bytes()),
|
||||
"upstream request {}",
|
||||
r.path
|
||||
);
|
||||
}
|
||||
|
||||
// Give the access log a moment to flush, then check every output channel.
|
||||
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
|
||||
let access = edge.access_log();
|
||||
assert!(access.lines().count() >= 7, "access log has the requests:\n{access}");
|
||||
assert!(access.contains("\"127.0.0.0\""), "IPv4 truncated to /24:\n{access}");
|
||||
assert!(!access.contains("127.0.0.1"), "full client IP must not be logged:\n{access}");
|
||||
assert!(!access.contains("token=abc"), "query strings are not logged:\n{access}");
|
||||
assert!(
|
||||
access.lines().count() >= 7,
|
||||
"access log has the requests:\n{access}"
|
||||
);
|
||||
assert!(
|
||||
access.contains("\"127.0.0.0\""),
|
||||
"IPv4 truncated to /24:\n{access}"
|
||||
);
|
||||
assert!(
|
||||
!access.contains("127.0.0.1"),
|
||||
"full client IP must not be logged:\n{access}"
|
||||
);
|
||||
assert!(
|
||||
!access.contains("token=abc"),
|
||||
"query strings are not logged:\n{access}"
|
||||
);
|
||||
let stderr = edge.stderr();
|
||||
assert!(stderr.len() > 100, "trace logging produced output:\n{stderr}");
|
||||
assert!(
|
||||
stderr.len() > 100,
|
||||
"trace logging produced output:\n{stderr}"
|
||||
);
|
||||
assert_clean("stderr (trace level)", stderr.as_bytes(), &secret);
|
||||
assert_clean("access log", access.as_bytes(), &secret);
|
||||
assert_clean("compiled edge config", edge.config_text.as_bytes(), &secret);
|
||||
@@ -143,15 +228,24 @@ async fn malformed_secret_is_rejected_without_echoing_it() {
|
||||
site: "secrets = [\"api_key\"]\n",
|
||||
hosts: vec![host_file(
|
||||
"app.test",
|
||||
&format!("upstreams = [\"{}\"]\n[[request_headers]]\naction = \"set\"\nname = \"X-A\"\nsecret = \"api_key\"\n", echo.url()),
|
||||
&format!(
|
||||
"upstreams = [\"{}\"]\n[[request_headers]]\naction = \"set\"\nname = \"X-A\"\nsecret = \"api_key\"\n",
|
||||
echo.url()
|
||||
),
|
||||
)],
|
||||
// A newline inside the value would split the header: refused.
|
||||
secrets: vec![("api_key".into(), format!("{secret}\ninjected: yes\n").into_bytes())],
|
||||
secrets: vec![(
|
||||
"api_key".into(),
|
||||
format!("{secret}\ninjected: yes\n").into_bytes(),
|
||||
)],
|
||||
log_level: "trace",
|
||||
..Default::default()
|
||||
});
|
||||
let status = wait_exit(&mut edge);
|
||||
assert!(!status.success(), "edge must refuse a secret that is not a valid header value");
|
||||
assert!(
|
||||
!status.success(),
|
||||
"edge must refuse a secret that is not a valid header value"
|
||||
);
|
||||
assert_clean("stderr", edge.stderr().as_bytes(), &secret);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user