v0.40.0
This commit is contained in:
1 parent
3b5fc8dce1
commit
748fe1d146
23 files changed
+2901
-40
No files matched your search
+140
-2
@@ -124,7 +124,11 @@ enum ConfigCommand {
|
||||
Get,
|
||||
Reload,
|
||||
Apply { file: PathBuf },
|
||||
Validate { file: PathBuf },
|
||||
Validate {
|
||||
file: PathBuf,
|
||||
#[command(flatten)]
|
||||
tls: Box<HeadlessTlsArgs>,
|
||||
},
|
||||
}
|
||||
#[derive(Subcommand)]
|
||||
enum BackupCommand {
|
||||
@@ -193,6 +197,139 @@ struct ServeOptions {
|
||||
allow_remote_admin: bool,
|
||||
#[arg(long, env = "RUST_PROXY_HEALTH_LISTEN")]
|
||||
health_listen: Option<SocketAddr>,
|
||||
#[command(flatten)]
|
||||
headless_tls: Box<HeadlessTlsArgs>,
|
||||
}
|
||||
|
||||
/// Headless-only TLS sources: certificate files and automatic ACME (DV) certificates.
|
||||
#[derive(Args, Clone, Default)]
|
||||
struct HeadlessTlsArgs {
|
||||
/// Certificate chain (PEM) to serve; pair each with --tls-key-file (headless only, repeatable)
|
||||
#[arg(long = "tls-cert-file", env = "RUST_PROXY_TLS_CERT_FILE", value_delimiter = ',', value_name = "PEM")]
|
||||
tls_cert_file: Vec<PathBuf>,
|
||||
/// Private key (PEM) for the --tls-cert-file at the same position
|
||||
#[arg(long = "tls-key-file", env = "RUST_PROXY_TLS_KEY_FILE", value_delimiter = ',', value_name = "PEM")]
|
||||
tls_key_file: Vec<PathBuf>,
|
||||
/// Directory with certificate/key pairs, e.g. /etc/letsencrypt/live (headless only, repeatable)
|
||||
#[arg(long = "tls-cert-dir", env = "RUST_PROXY_TLS_CERT_DIR", value_delimiter = ',', value_name = "DIR")]
|
||||
tls_cert_dir: Vec<PathBuf>,
|
||||
/// Names of one ACME certificate, comma-separated (repeat for more certificates; ';' in the environment)
|
||||
#[arg(long = "acme-domains", env = "RUST_PROXY_ACME_DOMAINS", value_delimiter = ';', value_name = "NAMES")]
|
||||
acme_domains: Vec<String>,
|
||||
/// Contact e-mail for the ACME account
|
||||
#[arg(long = "acme-email", env = "RUST_PROXY_ACME_EMAIL")]
|
||||
acme_email: Option<String>,
|
||||
/// Accept the ACME CA terms of service (Let's Encrypt Subscriber Agreement)
|
||||
#[arg(long = "acme-agree-tos", env = "RUST_PROXY_ACME_AGREE_TOS", action = clap::ArgAction::SetTrue,
|
||||
value_parser = clap::builder::BoolishValueParser::new())]
|
||||
acme_agree_tos: bool,
|
||||
/// Use the Let's Encrypt staging CA (untrusted test certificates, high rate limits)
|
||||
#[arg(long = "acme-staging", env = "RUST_PROXY_ACME_STAGING", action = clap::ArgAction::SetTrue,
|
||||
value_parser = clap::builder::BoolishValueParser::new())]
|
||||
acme_staging: bool,
|
||||
/// Challenge: http01 (default) or DNS-01 via cloudflare, ovh, rfc2136 (required for wildcards)
|
||||
#[arg(long = "acme-provider", env = "RUST_PROXY_ACME_PROVIDER",
|
||||
value_parser = ["http01", "cloudflare", "ovh", "rfc2136"])]
|
||||
acme_provider: Option<String>,
|
||||
/// Certbot-style INI file with DNS provider credentials (mode 0600)
|
||||
#[arg(long = "acme-dns-credentials", env = "RUST_PROXY_ACME_DNS_CREDENTIALS", value_name = "INI")]
|
||||
acme_dns_credentials: Option<PathBuf>,
|
||||
/// DNS-01 propagation wait in seconds [default: 60]
|
||||
#[arg(long = "acme-propagation-seconds", env = "RUST_PROXY_ACME_PROPAGATION_SECONDS",
|
||||
value_parser = clap::value_parser!(u64).range(10..=900))]
|
||||
acme_propagation_seconds: Option<u64>,
|
||||
/// Renew when this many days or fewer remain [default: 30]
|
||||
#[arg(long = "acme-renew-days", env = "RUST_PROXY_ACME_RENEW_DAYS",
|
||||
value_parser = clap::value_parser!(u64).range(1..=60))]
|
||||
acme_renew_days: Option<u64>,
|
||||
/// Also issue certificates for every vhost host that no other certificate covers
|
||||
#[arg(long = "acme-auto", env = "RUST_PROXY_ACME_AUTO", action = clap::ArgAction::SetTrue,
|
||||
value_parser = clap::builder::BoolishValueParser::new())]
|
||||
acme_auto: bool,
|
||||
/// Vhost without a configuration file: HOSTS=URLS, e.g. app.example.com=http://127.0.0.1:3000
|
||||
/// (repeatable; ';' between routes in the environment)
|
||||
#[arg(long = "route", env = "RUST_PROXY_ROUTES", value_delimiter = ';', value_name = "HOSTS=URLS")]
|
||||
route: Vec<String>,
|
||||
/// Redirect plain HTTP to HTTPS for --route vhosts (308)
|
||||
#[arg(long = "force-https", env = "RUST_PROXY_FORCE_HTTPS", action = clap::ArgAction::SetTrue,
|
||||
value_parser = clap::builder::BoolishValueParser::new())]
|
||||
force_https: bool,
|
||||
/// Reload automatically when the configuration or certificate files change
|
||||
#[arg(long = "watch", env = "RUST_PROXY_WATCH", action = clap::ArgAction::SetTrue,
|
||||
value_parser = clap::builder::BoolishValueParser::new())]
|
||||
watch: bool,
|
||||
}
|
||||
|
||||
impl HeadlessTlsArgs {
|
||||
fn requested(&self) -> bool {
|
||||
!self.tls_cert_file.is_empty()
|
||||
|| !self.tls_key_file.is_empty()
|
||||
|| !self.tls_cert_dir.is_empty()
|
||||
|| !self.acme_domains.is_empty()
|
||||
|| self.acme_auto
|
||||
|| !self.route.is_empty()
|
||||
|| self.watch
|
||||
}
|
||||
|
||||
/// Command-line headless options. ACME settings are validated when the
|
||||
/// configuration is loaded, because they may be completed by the
|
||||
/// `"headless"` section of the file.
|
||||
fn resolve(self, headless: bool) -> Result<rust_proxy::runtime::HeadlessOptions> {
|
||||
if !self.requested() {
|
||||
return Ok(Default::default());
|
||||
}
|
||||
ensure!(
|
||||
headless,
|
||||
"--tls-cert-file, --tls-cert-dir, --acme-*, --route and --watch are headless options; in panel mode use the panel"
|
||||
);
|
||||
ensure!(
|
||||
self.tls_cert_file.len() == self.tls_key_file.len(),
|
||||
"every --tls-cert-file needs a matching --tls-key-file (in the same order)"
|
||||
);
|
||||
let cwd = std::env::current_dir()?;
|
||||
let absolute = |path: PathBuf| if path.is_absolute() { path } else { cwd.join(path) };
|
||||
let cert_files = self
|
||||
.tls_cert_file
|
||||
.into_iter()
|
||||
.zip(self.tls_key_file)
|
||||
.map(|(cert, key)| (absolute(cert), absolute(key)))
|
||||
.collect();
|
||||
let cert_dirs = self.tls_cert_dir.into_iter().map(absolute).collect();
|
||||
let acme = rust_proxy::runtime::HeadlessAcmeSettings {
|
||||
domains: self
|
||||
.acme_domains
|
||||
.into_iter()
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.map(rust_proxy::runtime::HeadlessNames::Text)
|
||||
.collect(),
|
||||
auto: self.acme_auto,
|
||||
email: self.acme_email,
|
||||
agree_tos: self.acme_agree_tos,
|
||||
staging: self.acme_staging,
|
||||
provider: self.acme_provider,
|
||||
dns_credentials: self.acme_dns_credentials.map(absolute),
|
||||
propagation_seconds: self.acme_propagation_seconds,
|
||||
renew_days: self.acme_renew_days,
|
||||
};
|
||||
let routes = self
|
||||
.route
|
||||
.iter()
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.map(|value| rust_proxy::runtime::HeadlessRoute::parse(value))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let mut ids = std::collections::HashSet::new();
|
||||
for route in &routes {
|
||||
ensure!(ids.insert(route.id()), "--route lists the same hosts twice");
|
||||
}
|
||||
Ok(rust_proxy::runtime::HeadlessOptions {
|
||||
cert_files,
|
||||
cert_dirs,
|
||||
acme,
|
||||
routes,
|
||||
force_https: self.force_https,
|
||||
watch: self.watch,
|
||||
})
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
fn disable_transparent_huge_pages() {
|
||||
@@ -335,12 +472,13 @@ async fn application() -> Result<()> {
|
||||
signal_headless_reload(&resolve_installed_data_dir(cli.data_dir, data_dir_explicit))
|
||||
}
|
||||
Command::Config {
|
||||
action: ConfigCommand::Validate { file },
|
||||
action: ConfigCommand::Validate { file, tls },
|
||||
} if cli.headless => {
|
||||
validate_headless_file(
|
||||
resolve_installed_data_dir(cli.data_dir, data_dir_explicit),
|
||||
cli.admin_listen,
|
||||
file,
|
||||
tls.resolve(true)?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user