[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:
2026-11-17 13:46:33 +01:00
parent 83270e0746
commit fc9e16f1b2
21 changed files with 1677 additions and 43 deletions
+19 -2
View File
@@ -109,9 +109,13 @@ fn check_options(o: &CompileOptions) -> Result<(), CompileError> {
Ok(())
}
/// Paths end up inside JSON strings and Caddy `{file.*}` placeholders.
/// Paths end up inside JSON strings and Caddy `{file.*}` placeholders. Absolute: `/…` on
/// Linux, or a drive path with forward slashes on Windows (`C:/ProgramData/Ianitor/…`, which
/// Caddy and Go read as is; control writes backslashes as `/`, see [`windows_path`]).
fn check_path(p: &str) -> Result<(), &'static str> {
if !p.starts_with('/') {
let drive =
p.len() >= 3 && p.as_bytes()[0].is_ascii_alphabetic() && &p.as_bytes()[1..3] == b":/";
if !p.starts_with('/') && !drive {
return Err("it must be an absolute path");
}
if p.len() > 1024 {
@@ -126,6 +130,19 @@ fn check_path(p: &str) -> Result<(), &'static str> {
Ok(())
}
/// A Windows path as the compilers take it: `C:\ProgramData\Ianitor` → `C:/ProgramData/Ianitor`.
/// Anything that is not a drive path is returned unchanged (and a Linux path with a backslash
/// is still refused by the option check).
pub fn windows_path(p: &str) -> String {
let b = p.as_bytes();
if b.len() >= 3 && b[0].is_ascii_alphabetic() && b[1] == b':' && (b[2] == b'\\' || b[2] == b'/')
{
p.replace('\\', "/")
} else {
p.to_owned()
}
}
/// Identity headers never accepted from clients on forward-auth hosts: Authelia's four, then
/// any other configured copy header (case-insensitive, no duplicates).
fn strip_headers(fa: &crate::ForwardAuth) -> Vec<String> {
+2 -2
View File
@@ -32,8 +32,8 @@ use ring::rand::{SecureRandom, SystemRandom};
pub use domi_pki::{
CertInfo, DEVICE_DAYS, EkuInfo, INTERMEDIATE_DAYS, INTERMEDIATE_OPENSSL_EXT, KeyPair,
KeyUsageInfo, ORG, ROOT_CN, ROOT_DAYS, SERVER_DAYS, SERVER_RENEW_DAYS, der_to_pem,
match_code, openssl_sign_command, sha256_hex,
KeyUsageInfo, ORG, ROOT_CN, ROOT_DAYS, SERVER_DAYS, SERVER_RENEW_DAYS, der_to_pem, match_code,
openssl_sign_command, sha256_hex,
};
/// Subject CN of the intermediate. Signers refuse a CSR whose CN does not start with this.
+5 -1
View File
@@ -124,7 +124,11 @@ fn part(shown: &str, original: &str, max: usize, min: usize) -> String {
cut.pop();
}
let h = short_hash(original);
if cut.is_empty() { h } else { format!("{cut}-{h}") }
if cut.is_empty() {
h
} else {
format!("{cut}-{h}")
}
}
/// The DNS label of a branch's preview.