v0.38.0
This commit is contained in:
1 parent
df0e39b899
commit
21aef61dd5
35 files changed
+1360
-100
No files matched your search
+131
-40
@@ -5,11 +5,34 @@ async fn run(
|
||||
file_config: Option<PathBuf>,
|
||||
startup_locks: rust_proxy::settings::StartupLocks,
|
||||
update_check: rust_proxy::update_check::Config,
|
||||
headless: bool,
|
||||
) -> Result<()> {
|
||||
ensure!(
|
||||
startup_admin_addr.port() > 0 && options.proxy_listen.port() > 0,
|
||||
"listener ports must be nonzero"
|
||||
);
|
||||
if headless {
|
||||
ensure!(
|
||||
file_config.is_some(),
|
||||
"--headless requires --config /absolute/path/config.json (or RUST_PROXY_CONFIG)"
|
||||
);
|
||||
ensure!(!options.demo, "--headless cannot be combined with --demo");
|
||||
rust_proxy::runtime::enable_headless(rust_proxy::settings::Listeners::from_startup(
|
||||
options.proxy_listen,
|
||||
options.tls_listen,
|
||||
));
|
||||
}
|
||||
if let Some(health) = options.health_listen {
|
||||
ensure!(
|
||||
health.port() > 0
|
||||
&& health.port() != options.proxy_listen.port()
|
||||
&& options
|
||||
.tls_listen
|
||||
.is_none_or(|tls| tls.port() != health.port())
|
||||
&& (headless || health.port() != startup_admin_addr.port()),
|
||||
"health listener port must be nonzero and differ from the other listeners"
|
||||
);
|
||||
}
|
||||
ensure!(
|
||||
(1..=4096).contains(&options.max_connections) && (1..=4096).contains(&options.max_inflight),
|
||||
"limits must be 1..4096"
|
||||
@@ -22,14 +45,14 @@ async fn run(
|
||||
"timeouts must be positive"
|
||||
);
|
||||
ensure!(
|
||||
startup_admin_addr.port() != options.proxy_listen.port(),
|
||||
headless || startup_admin_addr.port() != options.proxy_listen.port(),
|
||||
"admin and proxy ports must differ"
|
||||
);
|
||||
if let Some(tls) = options.tls_listen {
|
||||
ensure!(
|
||||
tls.port() > 0
|
||||
&& tls.port() != options.proxy_listen.port()
|
||||
&& tls.port() != startup_admin_addr.port(),
|
||||
&& (headless || tls.port() != startup_admin_addr.port()),
|
||||
"TLS listener port must be nonzero and differ from HTTP/admin"
|
||||
);
|
||||
}
|
||||
@@ -75,10 +98,13 @@ async fn run(
|
||||
let store = Store::open(&data_dir.join("config.sqlite3"), &initial).await?;
|
||||
let mut saved = store.load().await?;
|
||||
let external = if let Some(path) = file_config {
|
||||
Some((
|
||||
path.clone(),
|
||||
rust_proxy::runtime::external_config::read(&path)?,
|
||||
))
|
||||
let loaded = match rust_proxy::runtime::headless_listeners() {
|
||||
Some(listeners) => {
|
||||
rust_proxy::runtime::external_config::read_headless(&path, listeners)?
|
||||
}
|
||||
None => rust_proxy::runtime::external_config::read(&path)?,
|
||||
};
|
||||
Some((path.clone(), loaded))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -87,6 +113,9 @@ async fn run(
|
||||
if let Some((_, (config, _))) = &external {
|
||||
saved.config = config.clone();
|
||||
}
|
||||
if headless {
|
||||
rust_proxy::runtime::ensure_headless_supported(&saved.config)?;
|
||||
}
|
||||
startup_locks.ensure_config(&mut saved.config);
|
||||
let changed_on_disk =
|
||||
external.is_some() && serde_json::to_value(&saved.config)? != stored_document;
|
||||
@@ -100,15 +129,16 @@ async fn run(
|
||||
.config
|
||||
.administration
|
||||
.resolved_listen(startup_admin_addr);
|
||||
let admin_tls_enabled = saved.config.administration.tls;
|
||||
let remote_admin =
|
||||
validate_admin_binding(admin_addr, admin_tls_enabled, options.allow_remote_admin)?;
|
||||
let admin_tls_enabled = saved.config.administration.tls && !headless;
|
||||
let remote_admin = !headless
|
||||
&& validate_admin_binding(admin_addr, admin_tls_enabled, options.allow_remote_admin)?;
|
||||
ensure!(
|
||||
admin_addr.port() != options.proxy_listen.port()
|
||||
&& options
|
||||
.tls_listen
|
||||
.is_none_or(|tls| tls.port() != admin_addr.port())
|
||||
&& (!options.demo || options.demo_listen.port() != admin_addr.port()),
|
||||
headless
|
||||
|| admin_addr.port() != options.proxy_listen.port()
|
||||
&& options
|
||||
.tls_listen
|
||||
.is_none_or(|tls| tls.port() != admin_addr.port())
|
||||
&& (!options.demo || options.demo_listen.port() != admin_addr.port()),
|
||||
"active administration port conflicts with another startup listener"
|
||||
);
|
||||
let resolved_policy = ValidationPolicy {
|
||||
@@ -154,7 +184,9 @@ async fn run(
|
||||
);
|
||||
}
|
||||
rust_proxy::logging::configure_error_log(snapshot.envelope.config.error_log.clone());
|
||||
let admin_tls_config = {
|
||||
let admin_tls_config = if headless {
|
||||
None
|
||||
} else {
|
||||
let tls = snapshot.envelope.config.tls.clone();
|
||||
let administration = snapshot.envelope.config.administration.clone();
|
||||
let cert_dir = policy.cert_dir.clone();
|
||||
@@ -165,7 +197,7 @@ async fn run(
|
||||
};
|
||||
let setup_required = store.admin_record().await?.is_none();
|
||||
let authentication = auth::Auth::new(store.clone(), data_dir.clone()).await?;
|
||||
if !setup_required {
|
||||
if !setup_required || headless {
|
||||
authentication.remove_bootstrap_files().await;
|
||||
}
|
||||
let renewal_observations = store.load_certificate_renewals().await?;
|
||||
@@ -175,6 +207,10 @@ async fn run(
|
||||
geoip_format,
|
||||
) {
|
||||
Ok(database) => std::sync::Arc::new(database),
|
||||
Err(error) if headless && !snapshot.envelope.config.geoip_updates.enabled => {
|
||||
tracing::debug!(%error, "GeoIP country database not installed");
|
||||
std::sync::Arc::new(rust_proxy::geoip::Database::empty())
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "GeoIP country database unavailable; country allow lists fail closed");
|
||||
std::sync::Arc::new(rust_proxy::geoip::Database::empty())
|
||||
@@ -273,9 +309,23 @@ async fn run(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let admin_listener = TcpListener::bind(admin_addr)
|
||||
.await
|
||||
.context("cannot bind admin listener")?;
|
||||
let admin_listener = if headless {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
TcpListener::bind(admin_addr)
|
||||
.await
|
||||
.context("cannot bind admin listener")?,
|
||||
)
|
||||
};
|
||||
let health_listener = match options.health_listen {
|
||||
Some(address) => Some(
|
||||
TcpListener::bind(address)
|
||||
.await
|
||||
.with_context(|| format!("cannot bind health listener {address}"))?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
let demo_listener = if options.demo {
|
||||
Some(
|
||||
TcpListener::bind(options.demo_listen)
|
||||
@@ -287,7 +337,9 @@ async fn run(
|
||||
};
|
||||
state.start_geoip_updates();
|
||||
state.start_dns_acl_updates();
|
||||
state.start_update_check(update_check);
|
||||
if !headless {
|
||||
state.start_update_check(update_check);
|
||||
}
|
||||
let shutdown = state.shutdown.clone();
|
||||
let grace = Duration::from_secs(options.shutdown_timeout_secs);
|
||||
let mut tasks = JoinSet::new();
|
||||
@@ -332,26 +384,46 @@ async fn run(
|
||||
metrics,
|
||||
));
|
||||
}
|
||||
if let Some(tls) = admin_tls_config {
|
||||
tasks.spawn(rust_proxy::server::serve_tls_with_plain_redirect(
|
||||
admin_listener,
|
||||
rust_proxy::admin::router(state.clone()),
|
||||
rust_proxy::admin::https_redirect_router(),
|
||||
shutdown.clone(),
|
||||
32,
|
||||
grace,
|
||||
tls,
|
||||
));
|
||||
} else {
|
||||
if let Some(listener) = health_listener {
|
||||
tasks.spawn(rust_proxy::server::serve(
|
||||
admin_listener,
|
||||
rust_proxy::admin::router(state.clone()),
|
||||
listener,
|
||||
rust_proxy::runtime::health_router(state.clone()),
|
||||
shutdown.clone(),
|
||||
32,
|
||||
16,
|
||||
grace,
|
||||
None,
|
||||
));
|
||||
}
|
||||
let _pid_file = if headless {
|
||||
Some(HeadlessPidFile::create(&data_dir)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if headless {
|
||||
tasks.spawn(headless_reload_loop(state.clone(), shutdown.clone()));
|
||||
}
|
||||
if let Some(admin_listener) = admin_listener {
|
||||
if let Some(tls) = admin_tls_config {
|
||||
tasks.spawn(rust_proxy::server::serve_tls_with_plain_redirect(
|
||||
admin_listener,
|
||||
rust_proxy::admin::router(state.clone()),
|
||||
rust_proxy::admin::https_redirect_router(),
|
||||
shutdown.clone(),
|
||||
32,
|
||||
grace,
|
||||
tls,
|
||||
));
|
||||
} else {
|
||||
tasks.spawn(rust_proxy::server::serve(
|
||||
admin_listener,
|
||||
rust_proxy::admin::router(state.clone()),
|
||||
shutdown.clone(),
|
||||
32,
|
||||
grace,
|
||||
None,
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(listener) = metrics_listener {
|
||||
tasks.spawn(rust_proxy::server::serve(
|
||||
listener,
|
||||
@@ -403,10 +475,26 @@ async fn run(
|
||||
stream.id
|
||||
);
|
||||
}
|
||||
println!(
|
||||
" Panel: {}://{admin_addr}",
|
||||
if admin_tls_enabled { "https" } else { "http" }
|
||||
);
|
||||
if headless {
|
||||
if let Some(path) = state
|
||||
.config_file
|
||||
.lock()
|
||||
.await
|
||||
.as_ref()
|
||||
.map(|(path, _)| path.clone())
|
||||
{
|
||||
println!(" Mode: headless, configuration {}", path.display());
|
||||
}
|
||||
println!(
|
||||
" Reload: systemctl reload rustproxy, kill -HUP {}, or rust-proxy --headless reload",
|
||||
std::process::id()
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
" Panel: {}://{admin_addr}",
|
||||
if admin_tls_enabled { "https" } else { "http" }
|
||||
);
|
||||
}
|
||||
if remote_admin && !admin_tls_enabled {
|
||||
tracing::warn!(
|
||||
"REMOTE ADMIN ENABLED OVER PLAIN HTTP: credentials and session cookies can be exposed; restrict access with a firewall/private network and prefer a protected tunnel"
|
||||
@@ -418,7 +506,10 @@ async fn run(
|
||||
state.active_prometheus.listen, state.active_prometheus.path
|
||||
);
|
||||
}
|
||||
if setup_required {
|
||||
if let Some(address) = options.health_listen {
|
||||
println!(" Health: http://{address}/healthz");
|
||||
}
|
||||
if !headless && setup_required {
|
||||
println!(
|
||||
" Setup: rust-proxy --data-dir {} admin setup-token",
|
||||
data_dir.display()
|
||||
@@ -427,7 +518,7 @@ async fn run(
|
||||
" Or: rust-proxy --data-dir {} admin init --username YOUR_NAME",
|
||||
data_dir.display()
|
||||
);
|
||||
} else {
|
||||
} else if !headless {
|
||||
println!(" Sign in with your administrator account.");
|
||||
}
|
||||
println!(" Source: https://git.linuxiarz.pl/gru/RustProxy");
|
||||
|
||||
Reference in new issue
Block a user