feat: guard engine UI gateway access with safe prefix fallback (#1091)
This commit is contained in:
@ -141,6 +141,7 @@ pub(super) async fn engines_page(
|
||||
)),
|
||||
None => None,
|
||||
};
|
||||
let statuses = state.runtime.engine_status().await;
|
||||
let rows = super::verwaltung::model_engine_names(&state);
|
||||
let mut summary = String::new();
|
||||
let mut searches = String::new();
|
||||
@ -158,7 +159,14 @@ pub(super) async fn engines_page(
|
||||
"<a href=\"/ui/modelle#modell-{}\">{}</a> ",
|
||||
super::verwaltung::dialog_id(model), esc(model)
|
||||
)).collect();
|
||||
summary.push_str(&format!("<tr><th>{}</th><td>{}</td></tr>", esc(&name),
|
||||
let status = statuses.iter().find(|s| s.name == name);
|
||||
let errors: u64 = models.iter().map(|m| state.runtime.metrics.model_errors(m)).sum();
|
||||
let health = status.map(|s| s.text()).unwrap_or_else(|| "nicht geprüft".into());
|
||||
let surface = if viewer.admin() && name != "ollama" && status.is_some_and(|s| s.reachable > 0)
|
||||
&& state.runtime.engine_ui_port(&name).is_some() {
|
||||
format!(" <a href=\"/ui/engine/{}/\">Engine-Oberfläche</a>", name.bytes().map(|b| if b.is_ascii_alphanumeric() || b"-._~".contains(&b) { (b as char).to_string() } else { format!("%{b:02X}") }).collect::<String>())
|
||||
} else { String::new() };
|
||||
summary.push_str(&format!("<tr><th>{}</th><td>{health} · Fehler seit Start: {errors}{surface}</td><td>{}</td></tr>", esc(&name),
|
||||
if links.is_empty() { "Keine Modelle registriert.".into() } else { links }));
|
||||
let installed = match &start.executable {
|
||||
Some(path) if path.exists() => {
|
||||
@ -225,8 +233,8 @@ pub(super) async fn engines_page(
|
||||
String::new()
|
||||
};
|
||||
let body = format!(
|
||||
"{notice}<section class=\"card\"><h2>Engines und Modelle</h2><table><thead><tr><th>Engine</th><th>Modelle</th></tr></thead><tbody>{summary}</tbody></table></section>\
|
||||
{cards}{search_section}<p class=\"klein\">Die Oberfläche der Engine hat keine eigene Anmeldung, das Gateway kontrolliert sie nicht.</p>",
|
||||
"{notice}<section class=\"card\"><h2>Engines und Modelle</h2><table><thead><tr><th>Engine</th><th>Status</th><th>Modelle</th></tr></thead><tbody>{summary}</tbody></table></section>\
|
||||
{cards}{search_section}<p class=\"klein\">Die Oberfläche der Engine hat meist keine eigene Anmeldung. Der Zugriff über das Gateway erfordert die Rolle admin. Die Unterstützung des Präfix-Pfads ist noch nicht bestätigt; in diesem Fall erscheint eine sichere Fehlerseite.</p>",
|
||||
notice = notice(query.as_deref()),
|
||||
);
|
||||
html(
|
||||
@ -234,3 +242,65 @@ pub(super) async fn engines_page(
|
||||
layout("Engines", "/ui/engines", &viewer, &body),
|
||||
)
|
||||
}
|
||||
|
||||
/// Noch keine Engine garantiert einen Präfix für HTML, API, SSE und WebSockets.
|
||||
/// Daher keine unvollständig umgeschriebenen Seiten unter der Gateway-Origin
|
||||
/// ausliefern. Der Zugang prüft bereits Rolle, laufende Instanz und Erreichbarkeit.
|
||||
pub(super) async fn engine_ui(
|
||||
State(state): State<Arc<AppState>>,
|
||||
axum::extract::Path(name): axum::extract::Path<String>,
|
||||
headers: HeaderMap,
|
||||
) -> Response {
|
||||
let Some(user) = viewer(&state, &headers) else {
|
||||
return redirect("/ui/login");
|
||||
};
|
||||
if !user.admin() {
|
||||
return super::refused(StatusCode::FORBIDDEN, "Dafür braucht es die Rolle admin.");
|
||||
}
|
||||
let statuses = state.runtime.engine_status().await;
|
||||
let Some(port) = state
|
||||
.runtime
|
||||
.engine_ui_port(&name)
|
||||
.filter(|_| statuses.iter().any(|s| s.name == name && s.reachable > 0))
|
||||
else {
|
||||
return super::refused(
|
||||
StatusCode::SERVICE_UNAVAILABLE,
|
||||
"Die Engine ist nicht geladen oder nicht erreichbar.",
|
||||
);
|
||||
};
|
||||
// Keine Cookies, Zugangsdaten, Client-Header, Query-Parameter oder Redirects
|
||||
// weitergeben. Das Ziel ist ausschließlich die lokale, verwaltete Instanz.
|
||||
let client = match reqwest::Client::builder()
|
||||
.no_proxy()
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.timeout(std::time::Duration::from_secs(3))
|
||||
.build()
|
||||
{
|
||||
Ok(client) => client,
|
||||
Err(_) => {
|
||||
return super::refused(
|
||||
StatusCode::BAD_GATEWAY,
|
||||
"Der Engine-Zugang ist nicht verfügbar.",
|
||||
);
|
||||
}
|
||||
};
|
||||
let upstream = client.get(format!("http://127.0.0.1:{port}/")).send().await;
|
||||
if !upstream.is_ok_and(|r| r.status().is_success()) {
|
||||
return super::refused(
|
||||
StatusCode::BAD_GATEWAY,
|
||||
"Die Engine liefert keine erreichbare Oberfläche. Die Unterstützung des Präfix-Pfads ist nicht bestätigt.",
|
||||
);
|
||||
}
|
||||
super::refused(
|
||||
StatusCode::BAD_GATEWAY,
|
||||
"Die Engine-Oberfläche kann noch nicht sicher über den Präfix-Pfad weitergeleitet werden. Absolute Pfade, Streaming und WebSockets sind für diese Engine nicht bestätigt. Es wurden keine Inhalte der Engine ausgeliefert.",
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) async fn engine_ui_asset(
|
||||
State(state): State<Arc<AppState>>,
|
||||
axum::extract::Path((name, _rest)): axum::extract::Path<(String, String)>,
|
||||
headers: HeaderMap,
|
||||
) -> Response {
|
||||
engine_ui(State(state), axum::extract::Path(name), headers).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user