[core] Proxy socket: compile option proxy_socket gives both engines a 0660 Unix socket for the front proxy (edge in its config, Caddy a third server with trusted_proxies_unix); listeners change only with a restart

This commit is contained in:
2026-11-10 20:59:57 +01:00
parent 4150848842
commit ffffa62999
15 changed files with 117 additions and 20 deletions
+26 -4
View File
@@ -19,6 +19,7 @@ use crate::{
const ACCESS_LOGGER: &str = "ianitor_access";
const HTTPS_SERVER: &str = "ianitor_https";
const HTTP_SERVER: &str = "ianitor_http";
const PROXY_SERVER: &str = "ianitor_proxy";
pub(super) fn compile(model: &Model, o: &CompileOptions) -> Value {
let hosts = model.hosts();
@@ -77,6 +78,23 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> Value {
.collect();
policies.push(json!({}));
// ---- The front proxy's socket: the same routes in plain HTTP, its peer trusted (edge:
// `client_ip` on the socket). No TLS here, so no certificates are managed for it.
let mut proxy = o.proxy_socket.as_ref().map(|sock| {
let mut p = Map::new();
p.insert(
"listen".into(),
json!([format!("unix//{}|0660", sock.trim_start_matches('/'))]),
);
p.insert("routes".into(), Value::Array(routes.clone()));
p.insert("automatic_https".into(), json!({ "disable": true }));
p.insert("protocols".into(), json!(["h1"]));
p.insert("trusted_proxies_unix".into(), json!(true));
p.insert("client_ip_headers".into(), json!(["X-Forwarded-For"]));
p.insert("trusted_proxies_strict".into(), json!(1));
p
});
let mut https = Map::new();
https.insert("listen".into(), json!([o.https_listen.to_string()]));
https.insert("routes".into(), Value::Array(routes));
@@ -106,10 +124,11 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> Value {
.iter()
.map(|h| (h.hostname.to_string(), json!([ACCESS_LOGGER])))
.collect();
https.insert(
"logs".into(),
json!({ "logger_names": names, "skip_unmapped_hosts": true }),
);
let logs = json!({ "logger_names": names, "skip_unmapped_hosts": true });
if let Some(p) = proxy.as_mut() {
p.insert("logs".into(), logs.clone());
}
https.insert("logs".into(), logs);
}
// ---- HTTP server: redirect known hosts to HTTPS (ACME HTTP-01 is answered by Caddy itself).
@@ -142,6 +161,9 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> Value {
let mut servers = Map::new();
servers.insert(HTTPS_SERVER.into(), Value::Object(https));
servers.insert(HTTP_SERVER.into(), http);
if let Some(p) = proxy {
servers.insert(PROXY_SERVER.into(), Value::Object(p));
}
let mut tls = Map::new();
if !domi.is_empty() {