[control] Previews: POST/GET/DELETE /api/v1/previews, tokens scoped to previews only, the upstream allow list, expiry; Windows drive paths in compile options (tests first)
This commit is contained in:
@@ -58,6 +58,61 @@ pub struct Config {
|
||||
/// Switching between Pingora and the Caddy fallback at runtime.
|
||||
#[serde(default)]
|
||||
pub engine: Option<EngineConfig>,
|
||||
/// Branch previews for Fabrica (`POST /api/v1/previews`); off without it.
|
||||
#[serde(default)]
|
||||
pub previews: Option<PreviewsConfig>,
|
||||
}
|
||||
|
||||
/// `[previews]`: where branch previews live and what they may point at.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct PreviewsConfig {
|
||||
/// Previews are `<branch>--<project>.<domain>`; a wildcard DNS record points here.
|
||||
pub domain: String,
|
||||
/// `domi` (the Domi CA, internal) or `letsencrypt` (public; one certificate per preview).
|
||||
#[serde(default = "default_preview_tls")]
|
||||
pub tls: String,
|
||||
/// `none` (anyone with the address) or `forward-auth` (behind the site's sign-in).
|
||||
#[serde(default = "default_preview_auth")]
|
||||
pub auth: String,
|
||||
/// Where previews may send traffic: `10.0.0.0/8`, `127.0.0.1:20000-29999`, `app.internal`,
|
||||
/// `*.svc.internal:8080`. Nothing else is accepted; control's own port and Caddy's admin
|
||||
/// port never are. Empty: every preview is refused.
|
||||
#[serde(default)]
|
||||
pub upstreams: Vec<String>,
|
||||
#[serde(default = "default_preview_ttl")]
|
||||
pub default_ttl_secs: u64,
|
||||
#[serde(default = "default_preview_min_ttl")]
|
||||
pub min_ttl_secs: u64,
|
||||
#[serde(default = "default_preview_max_ttl")]
|
||||
pub max_ttl_secs: u64,
|
||||
#[serde(default = "default_preview_max")]
|
||||
pub max_previews: usize,
|
||||
/// How often expired previews are looked for.
|
||||
#[serde(default = "default_preview_sweep")]
|
||||
pub sweep_secs: u64,
|
||||
}
|
||||
|
||||
fn default_preview_tls() -> String {
|
||||
"domi".into()
|
||||
}
|
||||
fn default_preview_auth() -> String {
|
||||
"none".into()
|
||||
}
|
||||
fn default_preview_ttl() -> u64 {
|
||||
72 * 3600
|
||||
}
|
||||
fn default_preview_min_ttl() -> u64 {
|
||||
300
|
||||
}
|
||||
fn default_preview_max_ttl() -> u64 {
|
||||
30 * 86_400
|
||||
}
|
||||
fn default_preview_max() -> usize {
|
||||
100
|
||||
}
|
||||
fn default_preview_sweep() -> u64 {
|
||||
30
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -120,13 +175,14 @@ pub struct Compile {
|
||||
|
||||
impl Compile {
|
||||
pub fn options(&self) -> CompileOptions {
|
||||
use ianitor_core::compile::windows_path as w;
|
||||
CompileOptions {
|
||||
http_listen: self.http_listen,
|
||||
https_listen: self.https_listen,
|
||||
cert_dir: self.cert_dir.clone(),
|
||||
state_dir: self.state_dir.clone(),
|
||||
access_log: self.access_log.clone(),
|
||||
caddy_credentials_dir: self.caddy_credentials_dir.clone(),
|
||||
cert_dir: w(&self.cert_dir),
|
||||
state_dir: w(&self.state_dir),
|
||||
access_log: w(&self.access_log),
|
||||
caddy_credentials_dir: w(&self.caddy_credentials_dir),
|
||||
caddy_admin: self.caddy_admin,
|
||||
caddy_admin_socket: self.caddy_admin_socket.clone(),
|
||||
trusted_proxies: self.trusted_proxies.clone(),
|
||||
@@ -240,6 +296,9 @@ impl Config {
|
||||
"pki.kdf_iterations must be at least {MIN_KDF_ITERATIONS}"
|
||||
)));
|
||||
}
|
||||
if let Some(p) = &self.previews {
|
||||
crate::previews::check_config(p, self).map_err(ConfigError::Invalid)?;
|
||||
}
|
||||
if let Some(m) = empty_model() {
|
||||
for c in std::iter::once(&self.compile).chain(self.compile_caddy.as_ref()) {
|
||||
ianitor_core::compile::edge(&m, &c.options())
|
||||
|
||||
Reference in New Issue
Block a user