[control] QC minors: device install links open a page and download on POST (never listed), approve and install failures show on the request and the CLI waits, PBKDF2 floor, private pki dirs or an error, trusted_proxies for a proxy in front, a placeholder keeps the device allow list from being empty (Caddy refuses that)

This commit is contained in:
2026-11-08 11:02:50 +01:00
parent bc336d1188
commit 3bf5fa0e1a
27 changed files with 548 additions and 46 deletions
+4
View File
@@ -110,6 +110,8 @@ pub struct EdgeSpec<'a> {
pub http_port: Option<u16>,
/// Extra files written into the edge directory before it starts (path relative to it).
pub files: Vec<(String, Vec<u8>)>,
/// Peers whose X-Forwarded-For edge believes.
pub trusted_proxies: Vec<std::net::IpAddr>,
}
impl Default for EdgeSpec<'_> {
@@ -122,6 +124,7 @@ impl Default for EdgeSpec<'_> {
extra_args: Vec::new(),
http_port: None,
files: Vec::new(),
trusted_proxies: Vec::new(),
}
}
}
@@ -191,6 +194,7 @@ pub fn spawn(spec: EdgeSpec<'_>) -> Edge {
caddy_credentials_dir: "/run/credentials/caddy-fallback.service".into(),
caddy_admin: None,
caddy_admin_socket: None,
trusted_proxies: spec.trusted_proxies.clone(),
};
let config_text = compile_with(&dir, &ca, &opts, spec.site, &spec.hosts);
std::fs::write(dir.join("edge.json"), &config_text).unwrap();
+84
View File
@@ -0,0 +1,84 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! `trusted_proxies` (off by default): behind a proxy on loopback (Caddy beside Ianitor), the
//! client named in X-Forwarded-For is the one edge forwards and logs; without the option a
//! client-sent X-Forwarded-For is ignored.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
#[cfg(unix)]
mod common;
#[cfg(not(unix))]
#[test]
fn skipped_on_windows() {
eprintln!(
"SKIPPED on Windows: {} needs Linux (Pingora runner); run it in WSL2, see CLAUDE.md",
file!()
);
}
#[cfg(unix)]
mod unix {
use crate::common::{EdgeSpec, host_file, start};
use ianitor_testkit::client::{self, Req};
use ianitor_testkit::upstream::Echo;
async fn forwarded_for(trusted: Vec<std::net::IpAddr>, xff: &str) -> (String, String) {
let echo = Echo::start("app").await;
let edge = start(EdgeSpec {
hosts: vec![host_file(
"app.test",
&format!(
"upstreams = [\"{}\"]\naccess_log = \"truncated\"\n",
echo.url()
),
)],
trusted_proxies: trusted,
..Default::default()
});
let r = client::https(
edge.https,
"app.test",
edge.roots(),
&Req::get("app.test", "/").header("x-forwarded-for", xff),
)
.await
.unwrap();
assert_eq!(r.status, 200);
let seen = echo.proxied();
let got = String::from_utf8(seen[0].header("x-forwarded-for").unwrap().to_vec()).unwrap();
// The access line is written after the response; give it a moment.
let mut log = String::new();
for _ in 0..50 {
log = edge.access_log();
if log.contains("app.test") {
break;
}
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
}
(got, log)
}
#[tokio::test(flavor = "multi_thread")]
async fn without_the_option_a_client_sent_forwarded_for_is_ignored() {
let (xff, log) = forwarded_for(Vec::new(), "203.0.113.7").await;
assert_eq!(xff, "127.0.0.1");
assert!(!log.contains("203.0.113"), "{log}");
}
#[tokio::test(flavor = "multi_thread")]
async fn a_trusted_proxy_names_the_client_rightmost_first() {
// The leftmost entry is what a client could forge; the rightmost untrusted one counts.
let (xff, log) = forwarded_for(
vec!["127.0.0.1".parse().unwrap()],
"198.51.100.9, 203.0.113.7, 127.0.0.1",
)
.await;
assert_eq!(xff, "203.0.113.7");
assert!(log.contains("203.0.113.0"), "the real /24 is logged: {log}");
assert!(!log.contains("198.51.100"), "{log}");
}
}