[edge] Proxy: Pingora data plane with SNI certs, forward-auth, header rules, health checks, ACME

This commit is contained in:
2026-11-07 14:57:36 +01:00
parent 4fe041082d
commit 17e1df8320
24 changed files with 2316 additions and 123 deletions
+52 -11
View File
@@ -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}"),
)
}