[control] Mark's UI decisions: Remote-Name shown with the proof, [ui] logout_url for Sign out, openssl signing files for the manual intermediate step, engine.not_ready, server sentences for the eight generic codes
This commit is contained in:
@@ -184,6 +184,7 @@ pub async fn overview(
|
||||
secrets: m.site().secrets.iter().map(|s| s.to_string()).collect(),
|
||||
watch_seconds: c.cfg.watch_secs,
|
||||
share_links_available: c.share_key.is_some() && c.engine_running() != "caddy",
|
||||
auth_logout_url: c.cfg.ui.as_ref().and_then(|u| u.logout_url.clone()),
|
||||
});
|
||||
let es = super::pki::engine_view(c);
|
||||
let on_caddy = es.running == "caddy";
|
||||
@@ -1339,7 +1340,7 @@ impl Modify for Bearer {
|
||||
get_undo, undo, restore, push_now, settings, list_tokens, create_token, rename_token, revoke_token,
|
||||
mint_share_link, list_share_links, stop_share_link, stop_all_share_links, health, openapi,
|
||||
super::pki::get_certs, super::pki::request_device, super::pki::get_request, super::pki::cancel_request,
|
||||
super::pki::get_csr, super::pki::put_certificate, super::pki::renew, super::pki::revoke_device,
|
||||
super::pki::get_csr, super::pki::get_ext, super::pki::put_certificate, super::pki::renew, super::pki::revoke_device,
|
||||
super::pki::make_bundle, super::pki::download_bundle, super::pki::get_engine, super::pki::switch_engine
|
||||
),
|
||||
components(schemas(
|
||||
|
||||
@@ -352,7 +352,8 @@ enum UiIdentity {
|
||||
Forged,
|
||||
/// The right proof but no usable `Remote-User`.
|
||||
NoUser,
|
||||
User(String),
|
||||
/// The Authelia user name, and the name to show (`Remote-Name` when it is usable).
|
||||
User(String, String),
|
||||
}
|
||||
|
||||
fn ui_identity(ctl: &Control, headers: &HeaderMap) -> UiIdentity {
|
||||
@@ -376,7 +377,16 @@ fn ui_identity(ctl: &Control, headers: &HeaderMap) -> UiIdentity {
|
||||
&& u.len() <= 64
|
||||
&& u.bytes().all(|c| c.is_ascii_graphic() && c != b':') =>
|
||||
{
|
||||
UiIdentity::User(u.to_owned())
|
||||
let display = headers
|
||||
.get("remote-name")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.map(str::trim)
|
||||
.filter(|n| {
|
||||
!n.is_empty() && n.chars().count() <= 64 && !n.chars().any(char::is_control)
|
||||
})
|
||||
.unwrap_or(u)
|
||||
.to_owned();
|
||||
UiIdentity::User(u.to_owned(), display)
|
||||
}
|
||||
_ => UiIdentity::NoUser,
|
||||
},
|
||||
@@ -434,7 +444,7 @@ async fn guard(State(st): State<Arc<AppState>>, mut req: Request, next: Next) ->
|
||||
Params::new(),
|
||||
));
|
||||
}
|
||||
UiIdentity::User(user) => {
|
||||
UiIdentity::User(user, display) => {
|
||||
// Cookie-based sign-in: every write carries the UI header, browser or not.
|
||||
if write && !ui {
|
||||
return Err(ApiError::new(
|
||||
@@ -450,7 +460,7 @@ async fn guard(State(st): State<Arc<AppState>>, mut req: Request, next: Next) ->
|
||||
})?;
|
||||
req.extensions_mut().insert(Actor {
|
||||
token_id: format!("user:{user}"),
|
||||
name: user,
|
||||
name: display,
|
||||
});
|
||||
return Ok(next.run(req).await);
|
||||
}
|
||||
@@ -601,6 +611,7 @@ pub fn router(st: Arc<AppState>) -> Router {
|
||||
get(pki::get_request).delete(pki::cancel_request),
|
||||
)
|
||||
.route("/api/v1/pki-requests/{id}/csr", get(pki::get_csr))
|
||||
.route("/api/v1/pki-requests/{id}/ext", get(pki::get_ext))
|
||||
.route(
|
||||
"/api/v1/pki-requests/{id}/certificate",
|
||||
axum::routing::put(pki::put_certificate),
|
||||
|
||||
@@ -86,6 +86,8 @@ pub struct PkiRequestView {
|
||||
pub message: String,
|
||||
/// The command that approves it on the server (manual approval).
|
||||
pub approve_command: Option<String>,
|
||||
/// Renewals: the base name of the files (`<base>.csr`, `<base>.ext`, `<base>.crt`).
|
||||
pub file_base: Option<String>,
|
||||
/// Why it failed, when it did.
|
||||
pub problem: Option<String>,
|
||||
}
|
||||
@@ -141,15 +143,24 @@ pub fn request_view(c: &Control, r: &Request) -> PkiRequestView {
|
||||
message: message_text,
|
||||
approve_command: (r.state == "waiting" && manual).then(|| {
|
||||
if r.kind == "intermediate" {
|
||||
"ianitor-control ca sign --root <offline root dir> --csr request.csr --out intermediate.crt; then ianitor-control pki install intermediate.crt".to_owned()
|
||||
ianitor_core::pki::openssl_sign_command(&file_base(r))
|
||||
} else {
|
||||
format!("ianitor-control pki approve {}", r.match_code)
|
||||
}
|
||||
}),
|
||||
file_base: (r.kind == "intermediate").then(|| file_base(r)),
|
||||
problem: r.error.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// `domi-intermediate-2026-11-07`, from the day the request was made.
|
||||
pub fn file_base(r: &Request) -> String {
|
||||
format!(
|
||||
"domi-intermediate-{}",
|
||||
rfc3339(r.created_at).get(..10).unwrap_or("request")
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, ToSchema)]
|
||||
pub struct IntermediateView {
|
||||
/// `ok`, `due` (≤ 30 days), `urgent` (≤ 7 days), `expired` or `missing`.
|
||||
@@ -384,19 +395,19 @@ pub async fn get_csr(State(st): Shared, Path(id): Path<String>) -> Result<Respon
|
||||
let csr = blocking(&st, move |c| {
|
||||
pki(c)?
|
||||
.request(&id, now())?
|
||||
.and_then(|r| r.csr_pem)
|
||||
.and_then(|r| r.csr_pem.clone().map(|c| (c, file_base(&r))))
|
||||
.ok_or(PkiFail::Code("pki.request_not_found"))
|
||||
})
|
||||
.await?;
|
||||
let (csr, base) = csr;
|
||||
let mut r = csr.into_response();
|
||||
r.headers_mut().insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("application/pkcs10"),
|
||||
);
|
||||
r.headers_mut().insert(
|
||||
header::CONTENT_DISPOSITION,
|
||||
HeaderValue::from_static("attachment; filename=\"ianitor-intermediate.csr\""),
|
||||
);
|
||||
if let Ok(v) = HeaderValue::from_str(&format!("attachment; filename=\"{base}.csr\"")) {
|
||||
r.headers_mut().insert(header::CONTENT_DISPOSITION, v);
|
||||
}
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
@@ -685,3 +696,30 @@ pub async fn switch_engine(
|
||||
log::info!(target: "ianitor::engine", "switch to {} asked by {}", engine_name(&target), actor.token_id);
|
||||
Ok(json(StatusCode::ACCEPTED, &engine_view(&st.ctl)))
|
||||
}
|
||||
|
||||
/// The openssl extensions file for signing a renewal by hand (the same profile Custos will
|
||||
/// use; docs/pki.md).
|
||||
#[utoipa::path(get, path = "/api/v1/pki-requests/{id}/ext", tag = "certs",
|
||||
responses((status = 200, description = "openssl -extfile"), (status = 404, body = super::views::ErrorEnvelope)), security(("bearer" = [])))]
|
||||
pub async fn get_ext(State(st): Shared, Path(id): Path<String>) -> Result<Response, ApiError> {
|
||||
if !plain_id(&id) {
|
||||
return Err(not_found("pki.request_not_found"));
|
||||
}
|
||||
let r = blocking(&st, move |c| {
|
||||
pki(c)?
|
||||
.request(&id, now())?
|
||||
.filter(|r| r.kind == "intermediate")
|
||||
.ok_or(PkiFail::Code("pki.request_not_found"))
|
||||
})
|
||||
.await?;
|
||||
let mut resp = ianitor_core::pki::INTERMEDIATE_OPENSSL_EXT.into_response();
|
||||
resp.headers_mut().insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("text/plain; charset=utf-8"),
|
||||
);
|
||||
if let Ok(v) = HeaderValue::from_str(&format!("attachment; filename=\"{}.ext\"", file_base(&r)))
|
||||
{
|
||||
resp.headers_mut().insert(header::CONTENT_DISPOSITION, v);
|
||||
}
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
@@ -513,6 +513,8 @@ pub struct SiteView {
|
||||
pub secrets: Vec<String>,
|
||||
pub watch_seconds: u64,
|
||||
pub share_links_available: bool,
|
||||
/// Authelia's logout address, for "Sign out" (`[ui] logout_url`); `null` hides the link.
|
||||
pub auth_logout_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, ToSchema)]
|
||||
|
||||
Reference in New Issue
Block a user