[control] Design review: Caddy differences per host in fallback_ready, active apply kind, hosts and watch end, capped device end date, CSR fingerprint for signing by hand, crash points exit without SIGABRT
This commit is contained in:
@@ -124,6 +124,41 @@ fn replay(st: &AppState, s: Stored) -> Response {
|
||||
|
||||
// ---------------------------------------------------------------- overview and hosts
|
||||
|
||||
/// What is known to differ on Caddy for these routes (decision Q3: switch allowed, the
|
||||
/// differences listed). Control cannot run the differential suite at runtime; these are the
|
||||
/// suite's known differences (tests/diff, KD-*) applied to the hosts that use the feature.
|
||||
/// Returns (hosts compared, hosts that behave the same, sentences).
|
||||
pub fn fallback_differences(m: &ianitor_core::Model) -> (u32, u32, Vec<String>) {
|
||||
let mut out = Vec::new();
|
||||
let mut matched = 0u32;
|
||||
for h in m.hosts() {
|
||||
let before = out.len();
|
||||
if h.share_links {
|
||||
out.push(format!(
|
||||
"{}: share links do not work; visitors with a link get the normal sign-in.",
|
||||
h.hostname
|
||||
));
|
||||
}
|
||||
if h.auth == ianitor_core::AuthMode::ForwardAuth {
|
||||
out.push(format!(
|
||||
"{}: if Authelia's answer is broken or cut off, Pingora refuses the visit; Caddy goes by its status alone.",
|
||||
h.hostname
|
||||
));
|
||||
}
|
||||
if out.len() == before {
|
||||
matched += 1;
|
||||
}
|
||||
}
|
||||
if !m.hosts().is_empty() {
|
||||
out.push(
|
||||
"Every host: Caddy adds its own Server and Via headers to answers, and a Content-Type when your service sends none."
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
let n = u32::try_from(m.hosts().len()).unwrap_or(u32::MAX);
|
||||
(n, matched, out)
|
||||
}
|
||||
|
||||
/// Everything the main screen shows, in one call. Answers 304 to a matching If-None-Match.
|
||||
#[utoipa::path(get, path = "/api/v1/overview", tag = "overview",
|
||||
responses((status = 200, body = Overview), (status = 304, description = "Unchanged since the ETag"), (status = 401, body = ErrorEnvelope)),
|
||||
@@ -173,6 +208,9 @@ pub async fn overview(
|
||||
state: r.state.clone(),
|
||||
summary: r.summary.clone(),
|
||||
seconds_left: r.watch.as_ref().map(|w| w.ends.saturating_sub(now())),
|
||||
kind: r.kind.clone(),
|
||||
hosts: r.hosts.clone(),
|
||||
watch_ends_at: r.watch.as_ref().map(|w| rfc3339(w.ends)),
|
||||
queued: c.queued_count(),
|
||||
});
|
||||
let site = tree
|
||||
@@ -219,9 +257,19 @@ pub async fn overview(
|
||||
running: es.running,
|
||||
target: es.target,
|
||||
switchable: es.switchable,
|
||||
fallback_ready: Some(FallbackReady {
|
||||
built_at: caddy_built,
|
||||
current: caddy_current,
|
||||
fallback_ready: Some({
|
||||
let (compared, matched, differences) = tree
|
||||
.as_ref()
|
||||
.and_then(|t| t.model().ok())
|
||||
.map(|m| fallback_differences(&m))
|
||||
.unwrap_or_default();
|
||||
FallbackReady {
|
||||
built_at: caddy_built,
|
||||
current: caddy_current,
|
||||
compared,
|
||||
matched,
|
||||
differences,
|
||||
}
|
||||
}),
|
||||
last_error: es.last_error,
|
||||
notes: es.notes,
|
||||
|
||||
@@ -79,6 +79,9 @@ pub struct PkiRequestView {
|
||||
pub name: Option<String>,
|
||||
/// Renewals: the request to sign offline (also `GET /pki-requests/{id}/csr`).
|
||||
pub csr_pem: Option<String>,
|
||||
/// Renewals: SHA-256 of the request (DER, lowercase hex), what
|
||||
/// `openssl req -in X.csr -outform DER | openssl dgst -sha256` prints on the offline computer.
|
||||
pub csr_sha256: Option<String>,
|
||||
/// Renewals, once installed: the new intermediate's expiry.
|
||||
pub not_after: Option<String>,
|
||||
/// What to tell the user now (`pki.waiting.manual`, `pki.renew.manual`, `pki.denied`, …).
|
||||
@@ -138,6 +141,11 @@ pub fn request_view(c: &Control, r: &Request) -> PkiRequestView {
|
||||
device_id: r.device_id.clone(),
|
||||
name: r.name.clone(),
|
||||
csr_pem: r.csr_pem.clone(),
|
||||
csr_sha256: r
|
||||
.csr_pem
|
||||
.as_deref()
|
||||
.and_then(|c| ianitor_core::pki::csr_der(c).ok())
|
||||
.map(|d| ianitor_core::pki::sha256_hex(&d)),
|
||||
not_after: r.not_after.map(|t| rfc3339(t.max(0) as u64)),
|
||||
message_code,
|
||||
message: message_text,
|
||||
@@ -247,6 +255,9 @@ pub struct CertsView {
|
||||
pub root: RootView,
|
||||
pub devices: Vec<DeviceView>,
|
||||
pub device_lifetime_days: u32,
|
||||
/// When a device certificate issued now would end: a year, but never past the
|
||||
/// intermediate's end (decision Q7). None without an intermediate.
|
||||
pub device_valid_until: Option<String>,
|
||||
pub server_lifetime_days: u32,
|
||||
/// `manual` (on the server, until Custos can) or `custos`.
|
||||
pub approval: String,
|
||||
@@ -283,6 +294,11 @@ pub async fn get_certs(State(st): Shared) -> Result<Response, ApiError> {
|
||||
.map(|d| device_view(d, t))
|
||||
.collect(),
|
||||
device_lifetime_days: ianitor_core::pki::DEVICE_DAYS,
|
||||
device_valid_until: p.intermediate_info().map(|i| {
|
||||
let end = (t as i64 + i64::from(ianitor_core::pki::DEVICE_DAYS) * 86_400)
|
||||
.min(i.not_after);
|
||||
rfc3339(end.max(0) as u64)
|
||||
}),
|
||||
server_lifetime_days: ianitor_core::pki::SERVER_DAYS,
|
||||
approval: c
|
||||
.cfg
|
||||
|
||||
@@ -463,6 +463,12 @@ pub struct FallbackReady {
|
||||
pub built_at: Option<String>,
|
||||
/// caddy.json is the compiled current tree.
|
||||
pub current: bool,
|
||||
/// Hosts in the current routes, and how many of them behave the same on Caddy as far as
|
||||
/// Ianitor knows (the differential tests' known differences, applied to these hosts).
|
||||
pub compared: u32,
|
||||
pub matched: u32,
|
||||
/// What is different on Caddy, in plain English (per host first, then for every host).
|
||||
pub differences: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, ToSchema)]
|
||||
@@ -494,6 +500,11 @@ pub struct ActiveApply {
|
||||
pub state: String,
|
||||
pub summary: String,
|
||||
pub seconds_left: Option<u64>,
|
||||
/// `add`, `edit`, `remove`, `undo`, `restore`, `share_links`: the UI writes the heading.
|
||||
pub kind: String,
|
||||
pub hosts: Vec<String>,
|
||||
/// When the health watch ends (only while watching), for a local countdown.
|
||||
pub watch_ends_at: Option<String>,
|
||||
pub queued: usize,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user