Lanna Desk: logo, a public page at /, the back office at /desk, full sign-out
CI / secret scan (push) Successful in 5s
CI / fmt, clippy, tests (push) Successful in 44s
CI / release (push) Skipped

Logo: a Lanna gable whose crossed kalae horns stand over a desk, gold on
navy, with "Lanna Desk" and "Visas · stays · contracts" in Sarabun drawn
as outlines. static/brand/ has the mark, the logo for light and for dark
backgrounds and a one-color version; scripts/gen_logo.py makes them, the
favicon and the header's mark from forms/fonts/Sarabun-Bold/SemiBold
(SIL Open Font License, next to the Regular already there).

`/` is now lannadesk.com's public page (templates/landing.html,
static/landing.css): what Lanna Desk takes care of, how a client starts
(write, open the link, sign first, we keep the dates), how the data is
kept, contact@lannadesk.com and "Staff sign-in". It needs no session and
shows no records. The back office's first page, the deadlines, moves to
`/desk` (web::HOME): the header, the nav, the filter, the login's default
target and the messages' links follow.

Signing out now ends the session at id.cnx.network too. Kanidm names no
end_session_endpoint, but its GET /ui/logout ends the session and clears
its cookies (SameSite=Lax, so they come along on a top-level navigation).
The logout form may only lead to this site (CSP form-action 'self'), so
/signed-out sends the browser on with a refresh and offers the link as
well; providers that are not Kanidm keep the old page.

Checks: fmt, clippy, 109 unit and 57 integration tests (the public page
open and free of records, /desk behind the sign-in, the sign-out page
leading to the provider); the page at 1280 and 390 px; the header's mark
in both themes; the style check on the README, PLAN and the page.
This commit is contained in:
grabowski committed 2026-11-21 19:57:20 +07:00
1 parent e5e30c977c
commit eafe918bcc
22 files changed
+639 -44

No files matched your search

+71 -18
View File
@@ -7,13 +7,14 @@ use axum::Extension;
use axum::extract::{Query, State};
use axum::http::{HeaderMap, HeaderValue, StatusCode, header};
use axum::response::{IntoResponse, Redirect, Response};
use minijinja::context;
use tracing::{info, warn};
use super::{AppError, AppState, message, safe_next};
use super::{AppError, AppState, HOME, message, render, safe_next};
use crate::audit::{self, Action, Entity, Entry};
use crate::config::Auth;
use crate::oidc;
use crate::session::{self, FLOW_COOKIE, SESSION_COOKIE, User};
use crate::{embedded, oidc};
fn cookie_header(value: &str) -> HeaderValue {
HeaderValue::from_str(value).expect("cookie values are base64url")
@@ -31,7 +32,7 @@ pub async fn login(
Query(q): Query<HashMap<String, String>>,
) -> Response {
let Auth::Oidc(oc) = &st.cfg.auth else {
return Redirect::to("/").into_response();
return Redirect::to(HOME).into_response();
};
let Some(provider) = st.provider() else {
return message(
@@ -40,7 +41,7 @@ pub async fn login(
"The login service is not reachable yet",
"Lanna Desk fetches id.cnx.network's settings when it starts and keeps \
trying. Try again in a minute.",
("/", "Try again"),
(HOME, "Try again"),
);
};
let Some(flow) = st.flows.start(safe_next(q.get("next"))) else {
@@ -49,7 +50,7 @@ pub async fn login(
StatusCode::TOO_MANY_REQUESTS,
"Too many logins at once",
"Wait a few minutes and try again.",
("/", "Try again"),
(HOME, "Try again"),
);
};
let url = match provider.authorize_url(
@@ -67,7 +68,7 @@ pub async fn login(
StatusCode::BAD_GATEWAY,
"The login service sent unusable settings",
"The server log has the details.",
("/", "Try again"),
(HOME, "Try again"),
);
}
};
@@ -89,7 +90,7 @@ pub async fn callback(
Query(q): Query<HashMap<String, String>>,
) -> Result<Response, AppError> {
let Auth::Oidc(oc) = &st.cfg.auth else {
return Ok(Redirect::to("/").into_response());
return Ok(Redirect::to(HOME).into_response());
};
if let Some(err) = q.get("error") {
let detail = q.get("error_description").cloned().unwrap_or_default();
@@ -108,7 +109,7 @@ pub async fn callback(
},
oc.group
),
("/", "Try again"),
(HOME, "Try again"),
));
}
let (Some(code), Some(state)) = (q.get("code"), q.get("state")) else {
@@ -117,7 +118,7 @@ pub async fn callback(
StatusCode::BAD_REQUEST,
"Incomplete login answer",
"The address lacks the code or the state. Start again.",
("/", "Start again"),
(HOME, "Start again"),
));
};
if session::cookie_value(&headers, FLOW_COOKIE).as_deref() != Some(state.as_str()) {
@@ -126,7 +127,7 @@ pub async fn callback(
StatusCode::BAD_REQUEST,
"This login was started elsewhere",
"The login answer does not belong to this browser. Start again.",
("/", "Start again"),
(HOME, "Start again"),
));
}
let (Some(flow), Some(provider)) = (st.flows.take(state), st.provider()) else {
@@ -135,7 +136,7 @@ pub async fn callback(
StatusCode::BAD_REQUEST,
"The login took too long",
"Logins must finish within ten minutes. Start again.",
("/", "Start again"),
(HOME, "Start again"),
));
};
let redirect_uri = st.cfg.redirect_uri();
@@ -156,7 +157,7 @@ pub async fn callback(
StatusCode::BAD_GATEWAY,
"The login could not be finished",
"id.cnx.network's answer did not check out. The server log says why.",
("/", "Start again"),
(HOME, "Start again"),
));
}
};
@@ -216,7 +217,7 @@ pub async fn logout(
headers: HeaderMap,
) -> Result<Response, AppError> {
if user.local {
return Ok(Redirect::to("/").into_response());
return Ok(Redirect::to(HOME).into_response());
}
if let Some(id) = session::cookie_value(&headers, SESSION_COOKIE) {
session::remove(&st.db, &id).await?;
@@ -242,13 +243,65 @@ pub async fn logout(
Ok(resp)
}
/// The provider's own sign-out page, which ends the browser's session there
/// too, so the next sign-in asks for the password again. Kanidm names no
/// `end_session_endpoint`; its `GET /ui/logout` ends the session and clears
/// its cookies (SameSite=Lax, so they come along on this top-level
/// navigation). For an issuer `https://id.cnx.network/oauth2/openid/<client>`
/// that is `https://id.cnx.network/ui/logout`; other providers get none.
pub fn provider_logout(issuer: &str) -> Option<String> {
let (origin, _) = issuer.split_once("/oauth2/openid/")?;
(origin.starts_with("https://") && !origin[8..].contains('/'))
.then(|| format!("{origin}/ui/logout"))
}
/// After the app's session is gone, the browser goes on to the provider's
/// sign-out (`provider_logout`) from this page: the logout form may only
/// lead to this site (CSP form-action), a page's refresh may go anywhere.
pub async fn signed_out(State(st): State<Arc<AppState>>) -> Response {
message(
let next = match &st.cfg.auth {
Auth::Oidc(oc) => provider_logout(&oc.issuer),
_ => None,
};
let (text, link) = match &next {
Some(url) => (
"You are signed out of Lanna Desk. Signing you out of id.cnx.network too, so \
the next sign-in asks for your password.",
(url.as_str(), "Sign out of id.cnx.network"),
),
None => (
"You are signed out of Lanna Desk. Your session at the login service stays \
open until you sign out there.",
(HOME, "Sign in again"),
),
};
render(
&st,
"message.html",
context! {
title => "Signed out",
text => text,
href => link.0,
link => link.1,
refresh => next,
v => embedded::STATIC_HASH,
},
StatusCode::OK,
"Signed out",
"You are signed out of Lanna Desk. Your session at id.cnx.network stays open \
until you sign out there.",
("/", "Sign in again"),
)
}
#[cfg(test)]
mod tests {
use super::provider_logout;
#[test]
fn kanidm_issuers_have_a_sign_out_page() {
assert_eq!(
provider_logout("https://id.cnx.network/oauth2/openid/visa-web").as_deref(),
Some("https://id.cnx.network/ui/logout")
);
assert_eq!(provider_logout("https://accounts.example.com"), None);
assert_eq!(provider_logout("http://id.test/oauth2/openid/x"), None);
assert_eq!(provider_logout("https://a.test/sub/oauth2/openid/x"), None);
}
}
+4 -4
View File
@@ -27,7 +27,7 @@ use crate::{companies, countries, dates, records};
use super::people::{PersonView, load_person};
use super::records::options;
use super::{AppState, Res, message, not_found_page, page};
use super::{AppState, HOME, Res, message, not_found_page, page};
/// The largest file taken.
pub const FILE_LIMIT: usize = 20 * 1024 * 1024;
@@ -502,7 +502,7 @@ fn files_off(st: &AppState) -> Response {
"Documents are switched off",
"This server has no files directory and file key (VISA_FILES_DIR, VISA_FILES_KEY_FILE), \
so it neither takes nor shows documents.",
("/", "Open the app"),
(HOME, "Open the app"),
)
}
@@ -517,7 +517,7 @@ fn too_large(st: &AppState) -> Response {
FILE_LIMIT / (1024 * 1024),
UPLOAD_LIMIT / (1024 * 1024)
),
("/", "Open the app"),
(HOME, "Open the app"),
)
}
@@ -531,7 +531,7 @@ fn broken_upload(st: &AppState, e: &MultipartError) -> Response {
StatusCode::BAD_REQUEST,
"The upload was cut short",
"The files did not arrive whole. Go back and send them again.",
("/", "Open the app"),
(HOME, "Open the app"),
)
}
+31 -8
View File
@@ -133,7 +133,8 @@ pub fn router(st: Arc<AppState>) -> Router {
use companies as c;
use people as p;
let mut r = Router::new()
.route("/", get(dashboard::page_handler))
.route("/", get(landing))
.route(HOME, get(dashboard::page_handler))
.route("/people", get(p::list).post(p::create))
.route("/people/new", get(p::new_form))
.route(
@@ -389,12 +390,17 @@ pub fn router(st: Arc<AppState>) -> Router {
.with_state(st)
}
/// Paths open without a session: the client's pages (`/c/<token>`, which
/// check their link themselves) among them.
/// Paths open without a session: the public page at `/`, and the client's
/// pages (`/c/<token>`, which check their link themselves) among them.
fn is_public(path: &str) -> bool {
matches!(
path,
"/healthz" | "/version" | "/login" | "/auth/callback" | "/signed-out" | "/favicon.ico"
"/" | "/healthz"
| "/version"
| "/login"
| "/auth/callback"
| "/signed-out"
| "/favicon.ico"
) || path.starts_with("/static/")
|| path.starts_with("/c/")
}
@@ -422,7 +428,7 @@ async fn gate(State(st): State<Arc<AppState>>, mut req: Request, next: Next) ->
.uri()
.path_and_query()
.map(|p| p.as_str().to_string())
.unwrap_or_else(|| "/".into());
.unwrap_or_else(|| HOME.into());
let login = format!("/login?next={}", percent_encode(&target));
if req.headers().contains_key("hx-request") {
let mut resp = StatusCode::OK.into_response();
@@ -455,7 +461,7 @@ async fn forms_guard(State(st): State<Arc<AppState>>, req: Request, next: Next)
StatusCode::FORBIDDEN,
"Refused",
"This form was sent from another site. Open lannadesk.com and try again there.",
("/", "Open the app"),
(HOME, "Open the app"),
);
}
let Some(user) = req.extensions().get::<User>().cloned() else {
@@ -530,7 +536,7 @@ pub fn expired(st: &AppState) -> Response {
"The form has expired",
"The page was older than your current session. Go back, reload the page and send the \
form again.",
("/", "Open the app"),
(HOME, "Open the app"),
)
}
@@ -631,7 +637,7 @@ pub fn safe_next(next: Option<&String>) -> String {
{
n.clone()
}
_ => "/".into(),
_ => HOME.into(),
}
}
@@ -696,6 +702,23 @@ pub fn message(
)
}
/// The back office's first page, the deadlines; `/` is the public page.
pub const HOME: &str = "/desk";
/// The address on the public page that people write to.
pub const CONTACT: &str = "contact@lannadesk.com";
/// lannadesk.com's public page: what Lanna Desk does and how to reach it,
/// with the way into the back office. Open without a session.
async fn landing(State(st): State<Arc<AppState>>) -> Response {
render(
&st,
"landing.html",
context! { v => embedded::STATIC_HASH, home => HOME, contact => CONTACT },
StatusCode::OK,
)
}
pub fn not_found_page(st: &AppState) -> Response {
message(
st,