[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:
@@ -60,10 +60,6 @@ pub struct Options {
|
||||
pub credentials_dir: Option<PathBuf>,
|
||||
/// The overall deadline for a request header; default [`deadline::HEADER_TIMEOUT`].
|
||||
pub header_timeout: Option<std::time::Duration>,
|
||||
/// A Unix socket (mode 0660) on which edge serves the HTTPS hosts in plain HTTP to a front
|
||||
/// proxy that terminated TLS (Caddy beside Ianitor). Only the socket's owner and group can
|
||||
/// connect, so its `X-Forwarded-For` is believed (Unix only).
|
||||
pub proxy_socket: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
@@ -148,8 +144,8 @@ pub fn server(shared: Arc<Shared>, opts: &Options) -> Result<Server, EdgeError>
|
||||
https
|
||||
.endpoints()
|
||||
.set_pre_tls_callback(Arc::new(tls::HandshakeStart));
|
||||
if let Some(path) = &opts.proxy_socket {
|
||||
add_proxy_socket(&mut https, path)?;
|
||||
if let Some(path) = &rt.cfg.proxy_socket {
|
||||
add_proxy_socket(&mut https, Path::new(path))?;
|
||||
}
|
||||
|
||||
let mut http = Service::new(
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//! `ianitor-edge --config <edge.json> [--check] [--admin-socket <path>] [--trial-config <path>]
|
||||
//! [--share-revocations <path>] [--acme-root <ca.pem>] [--header-timeout <secs>]
|
||||
//! [--proxy-socket <path>]`
|
||||
//! [--share-revocations <path>] [--acme-root <ca.pem>] [--header-timeout <secs>]`
|
||||
//!
|
||||
//! Secrets come from `$CREDENTIALS_DIRECTORY`; the log level from `$IANITOR_LOG`
|
||||
//! (error, warn, info, debug, trace; libraries are capped at info).
|
||||
@@ -24,7 +23,6 @@ fn parse_args() -> Result<(Options, bool), EdgeError> {
|
||||
Some("--config") => config = args.next().map(PathBuf::from),
|
||||
Some("--acme-root") => opts.acme_root = args.next().map(PathBuf::from),
|
||||
Some("--admin-socket") => opts.admin_socket = args.next().map(PathBuf::from),
|
||||
Some("--proxy-socket") => opts.proxy_socket = args.next().map(PathBuf::from),
|
||||
Some("--trial-config") => opts.trial_config = args.next().map(PathBuf::from),
|
||||
Some("--share-revocations") => opts.share_revocations = args.next().map(PathBuf::from),
|
||||
Some("--header-timeout") => {
|
||||
@@ -42,7 +40,7 @@ fn parse_args() -> Result<(Options, bool), EdgeError> {
|
||||
println!(
|
||||
"usage: ianitor-edge --config <edge.json> [--check] [--admin-socket <path>] \
|
||||
[--trial-config <path>] [--share-revocations <path>] [--acme-root <ca.pem>] \
|
||||
[--header-timeout <secs>] [--proxy-socket <path>]"
|
||||
[--header-timeout <secs>]"
|
||||
);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,10 @@ pub struct Shared {
|
||||
}
|
||||
|
||||
fn same_listeners(a: &Runtime, b: &Runtime) -> Result<(), EdgeError> {
|
||||
if a.cfg.http_listen != b.cfg.http_listen || a.cfg.https_listen != b.cfg.https_listen {
|
||||
if a.cfg.http_listen != b.cfg.http_listen
|
||||
|| a.cfg.https_listen != b.cfg.https_listen
|
||||
|| a.cfg.proxy_socket != b.cfg.proxy_socket
|
||||
{
|
||||
return Err(EdgeError::Config {
|
||||
path: PathBuf::from("<new config>"),
|
||||
message: "the listen addresses can only change with a restart".into(),
|
||||
|
||||
@@ -112,6 +112,8 @@ pub struct EdgeSpec<'a> {
|
||||
pub files: Vec<(String, Vec<u8>)>,
|
||||
/// Peers whose X-Forwarded-For edge believes.
|
||||
pub trusted_proxies: Vec<std::net::IpAddr>,
|
||||
/// The front proxy's Unix socket.
|
||||
pub proxy_socket: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for EdgeSpec<'_> {
|
||||
@@ -125,6 +127,7 @@ impl Default for EdgeSpec<'_> {
|
||||
http_port: None,
|
||||
files: Vec::new(),
|
||||
trusted_proxies: Vec::new(),
|
||||
proxy_socket: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,6 +198,7 @@ pub fn spawn(spec: EdgeSpec<'_>) -> Edge {
|
||||
caddy_admin: None,
|
||||
caddy_admin_socket: None,
|
||||
trusted_proxies: spec.trusted_proxies.clone(),
|
||||
proxy_socket: spec.proxy_socket.clone(),
|
||||
};
|
||||
let config_text = compile_with(&dir, &ca, &opts, spec.site, &spec.hosts);
|
||||
std::fs::write(dir.join("edge.json"), &config_text).unwrap();
|
||||
|
||||
@@ -147,10 +147,14 @@ mod unix {
|
||||
let echo = Echo::start("app").await;
|
||||
let dir = ianitor_testkit::proc::TempDir::new("proxy-sock");
|
||||
let sock = dir.join("proxy.sock");
|
||||
let edge = app_edge(
|
||||
&echo,
|
||||
vec!["--proxy-socket".into(), sock.to_string_lossy().into()],
|
||||
);
|
||||
let edge = start(EdgeSpec {
|
||||
hosts: vec![host_file(
|
||||
"app.test",
|
||||
&format!("upstreams = [\"{}\"]\n", echo.url()),
|
||||
)],
|
||||
proxy_socket: Some(sock.to_string_lossy().into()),
|
||||
..Default::default()
|
||||
});
|
||||
for _ in 0..100 {
|
||||
if sock.exists() {
|
||||
break;
|
||||
@@ -221,7 +225,7 @@ mod unix {
|
||||
devices_ca.issue(&["a-device"]).cert_pem.into_bytes(),
|
||||
),
|
||||
],
|
||||
extra_args: vec!["--proxy-socket".into(), sock.to_string_lossy().into()],
|
||||
proxy_socket: Some(sock.to_string_lossy().into()),
|
||||
..Default::default()
|
||||
});
|
||||
for _ in 0..100 {
|
||||
|
||||
Reference in New Issue
Block a user