feat(dashboard): a link back to the platform portal
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m11s
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m11s
The sidebar links to the customer's workspace in the portal (<PORTAL_URL>/<tenant_slug>/dashboard). PORTAL_URL is read at runtime, since staging and production share an image; the slug comes from the access token's tenant_slug claim at login and is kept in the session. Without PORTAL_URL the link is hidden. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
1 parent
d7316dc403
commit
d36c3e92ab
10 files changed
+142
-2
No files matched your search
@@ -104,6 +104,11 @@ AGENT_API_URL=http://localhost:3001
|
||||
# with `openssl rand -hex 64`. Required in staging/production; unset in dev
|
||||
# means sessions end when the dashboard restarts.
|
||||
DASHBOARD_SESSION_KEY=
|
||||
# The platform portal, for the sidebar's "Zur Plattform" link to the user's
|
||||
# workspace (<PORTAL_URL>/<tenant_slug>/dashboard). Staging:
|
||||
# https://app-stage.breakpilot.com, production: https://app.breakpilot.com.
|
||||
# Unset hides the link.
|
||||
# PORTAL_URL=
|
||||
|
||||
# MCP Server
|
||||
MCP_ENDPOINT_URL=http://localhost:8090
|
||||
|
||||
@@ -11,4 +11,8 @@ pub struct AuthInfo {
|
||||
pub email: String,
|
||||
pub name: String,
|
||||
pub avatar_url: String,
|
||||
/// The link back to the platform portal (the workspace's dashboard
|
||||
/// there); empty when no portal is configured.
|
||||
#[serde(default)]
|
||||
pub portal_url: String,
|
||||
}
|
||||
@@ -278,6 +278,20 @@ code {
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
/* Back to the platform portal: above the product's own navigation. */
|
||||
.nav-item.portal-link {
|
||||
margin: 8px 8px 0;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.nav-item.portal-link:hover {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
/* Breakpilot mark + wordmark */
|
||||
.brand-mark {
|
||||
width: 26px;
|
||||
|
||||
@@ -92,6 +92,9 @@ pub fn Sidebar() -> Element {
|
||||
// With the trailing slash: the docs route matches /docs/*, and a plain
|
||||
// /docs lands on the dashboard's "route not found" page.
|
||||
let docs_url = option_env!("DOCS_URL").unwrap_or("/docs/");
|
||||
// Back to the customer's workspace in the platform portal; hidden when
|
||||
// the dashboard is not configured with one (local development).
|
||||
let portal_url = use_context::<Signal<AuthInfo>>()().portal_url;
|
||||
|
||||
let sidebar_class = if collapsed() {
|
||||
"sidebar collapsed"
|
||||
@@ -112,6 +115,17 @@ pub fn Sidebar() -> Element {
|
||||
}
|
||||
}
|
||||
}
|
||||
if !portal_url.is_empty() {
|
||||
a {
|
||||
href: "{portal_url}",
|
||||
class: "nav-item portal-link",
|
||||
title: nav::PORTAL.get(lang),
|
||||
Icon { icon: BsArrowLeft, width: 18, height: 18 }
|
||||
if !collapsed() {
|
||||
span { {nav::PORTAL.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
div { class: "sidebar-nav",
|
||||
for item in nav_items {
|
||||
{
|
||||
|
||||
@@ -71,6 +71,10 @@ pub mod nav {
|
||||
de: "Pentest",
|
||||
en: "Pentest",
|
||||
};
|
||||
pub const PORTAL: Text = Text {
|
||||
de: "Zur Plattform",
|
||||
en: "Back to the platform",
|
||||
};
|
||||
pub const DOCS: Text = Text {
|
||||
de: "Dokumentation",
|
||||
en: "Docs",
|
||||
|
||||
@@ -16,7 +16,7 @@ use url::Url;
|
||||
use super::{
|
||||
error::DashboardError,
|
||||
server_state::ServerState,
|
||||
user_state::{User, UserStateInner},
|
||||
user_state::{tenant_slug_from_token, User, UserStateInner},
|
||||
};
|
||||
|
||||
pub const LOGGED_IN_USER_SESS_KEY: &str = "logged-in-user";
|
||||
@@ -240,8 +240,10 @@ pub async fn auth_callback(
|
||||
.or(userinfo.preferred_username)
|
||||
.unwrap_or_default();
|
||||
|
||||
let tenant_slug = tenant_slug_from_token(&tokens.access_token);
|
||||
let user_state = UserStateInner {
|
||||
sub: userinfo.sub,
|
||||
tenant_slug,
|
||||
access_token: tokens.access_token,
|
||||
refresh_token: tokens.refresh_token.unwrap_or_default(),
|
||||
user: User {
|
||||
|
||||
@@ -10,7 +10,7 @@ use dioxus::prelude::*;
|
||||
pub async fn check_auth() -> Result<AuthInfo, ServerFnError> {
|
||||
use super::auth::LOGGED_IN_USER_SESS_KEY;
|
||||
use super::server_state::ServerState;
|
||||
use super::user_state::UserStateInner;
|
||||
use super::user_state::{portal_link, UserStateInner};
|
||||
use dioxus_fullstack::FullstackContext;
|
||||
|
||||
let state: ServerState = FullstackContext::extract().await?;
|
||||
@@ -20,6 +20,7 @@ pub async fn check_auth() -> Result<AuthInfo, ServerFnError> {
|
||||
return Ok(AuthInfo {
|
||||
authenticated: true,
|
||||
name: "Local User".into(),
|
||||
portal_url: portal_link(state.portal_url.as_deref(), ""),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
@@ -34,6 +35,7 @@ pub async fn check_auth() -> Result<AuthInfo, ServerFnError> {
|
||||
match user_state {
|
||||
Some(u) => Ok(AuthInfo {
|
||||
authenticated: true,
|
||||
portal_url: portal_link(state.portal_url.as_deref(), &u.tenant_slug),
|
||||
sub: u.sub,
|
||||
email: u.user.email,
|
||||
name: u.user.name,
|
||||
|
||||
@@ -58,6 +58,11 @@ pub fn server_start(app: fn() -> Element) -> Result<(), DashboardError> {
|
||||
.map(|v| v.trim().to_string())
|
||||
.filter(|v| !v.is_empty());
|
||||
|
||||
let portal_url = std::env::var("PORTAL_URL")
|
||||
.ok()
|
||||
.map(|v| v.trim().to_string())
|
||||
.filter(|v| !v.is_empty());
|
||||
|
||||
// Sessions survive a redeploy: signed with a key from the
|
||||
// environment, stored sealed in Mongo (#260).
|
||||
let key = load_session_key(app_env)?;
|
||||
@@ -76,6 +81,7 @@ pub fn server_start(app: fn() -> Element) -> Result<(), DashboardError> {
|
||||
config,
|
||||
keycloak,
|
||||
mcp_health_url,
|
||||
portal_url,
|
||||
}
|
||||
.into();
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ pub struct ServerStateInner {
|
||||
/// probe derives the URL from each server's endpoint (see
|
||||
/// `infrastructure::mcp::mcp_health_url_candidates`).
|
||||
pub mcp_health_url: Option<String>,
|
||||
/// The platform portal (`PORTAL_URL`), for the link back to it. It
|
||||
/// differs between staging and production, which share one image, so it
|
||||
/// is read at runtime. `None` hides the link.
|
||||
pub portal_url: Option<String>,
|
||||
}
|
||||
|
||||
impl From<ServerStateInner> for ServerState {
|
||||
|
||||
@@ -7,6 +7,10 @@ pub struct UserStateInner {
|
||||
pub access_token: String,
|
||||
pub refresh_token: String,
|
||||
pub user: User,
|
||||
/// The workspace's slug (`tenant_slug` claim), for the link back to the
|
||||
/// portal. Empty in sessions from before it was stored.
|
||||
#[serde(default)]
|
||||
pub tenant_slug: String,
|
||||
}
|
||||
|
||||
/// Basic user profile stored alongside the session.
|
||||
@@ -16,3 +20,84 @@ pub struct User {
|
||||
pub name: String,
|
||||
pub avatar_url: String,
|
||||
}
|
||||
|
||||
/// The `tenant_slug` claim of a Keycloak access token, or `""` without one.
|
||||
///
|
||||
/// The signature is not checked: the token comes straight from Keycloak's
|
||||
/// token endpoint, and the slug only builds a link.
|
||||
pub fn tenant_slug_from_token(access_token: &str) -> String {
|
||||
use base64::Engine;
|
||||
|
||||
access_token
|
||||
.split('.')
|
||||
.nth(1)
|
||||
.and_then(|payload| {
|
||||
base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(payload.trim_end_matches('='))
|
||||
.ok()
|
||||
})
|
||||
.and_then(|json| serde_json::from_slice::<serde_json::Value>(&json).ok())
|
||||
.and_then(|claims| claims.get("tenant_slug")?.as_str().map(str::to_owned))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The link back to the platform: the workspace's portal dashboard, or the
|
||||
/// portal's start page when the slug is unknown. Empty without a portal URL.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `portal_url` - the portal's base URL (`PORTAL_URL`), if configured
|
||||
/// * `tenant_slug` - the workspace's slug; used only if it is a plain slug
|
||||
pub fn portal_link(portal_url: Option<&str>, tenant_slug: &str) -> String {
|
||||
let Some(base) = portal_url.map(|u| u.trim_end_matches('/')) else {
|
||||
return String::new();
|
||||
};
|
||||
// Slugs are lowercase letters, digits and dashes; anything else would
|
||||
// change the path, so the start page is the safe fallback.
|
||||
let plain = !tenant_slug.is_empty()
|
||||
&& tenant_slug
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-');
|
||||
if plain {
|
||||
format!("{base}/{tenant_slug}/dashboard")
|
||||
} else {
|
||||
format!("{base}/")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use base64::Engine;
|
||||
|
||||
fn token(claims: &serde_json::Value) -> String {
|
||||
let payload = base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(claims.to_string());
|
||||
format!("eyJhbGciOiJSUzI1NiJ9.{payload}.signature")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_slug_is_read_from_the_access_token() {
|
||||
let with = token(&serde_json::json!({ "sub": "u1", "tenant_slug": "faller" }));
|
||||
let without = token(&serde_json::json!({ "sub": "u1" }));
|
||||
|
||||
assert_eq!(tenant_slug_from_token(&with), "faller");
|
||||
assert_eq!(tenant_slug_from_token(&without), "");
|
||||
assert_eq!(tenant_slug_from_token("not-a-jwt"), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_link_goes_to_the_workspace_when_the_slug_is_plain() {
|
||||
let portal = Some("https://app-stage.breakpilot.com/");
|
||||
|
||||
assert_eq!(
|
||||
portal_link(portal, "faller-gmbh"),
|
||||
"https://app-stage.breakpilot.com/faller-gmbh/dashboard"
|
||||
);
|
||||
assert_eq!(portal_link(portal, ""), "https://app-stage.breakpilot.com/");
|
||||
assert_eq!(
|
||||
portal_link(portal, "../admin"),
|
||||
"https://app-stage.breakpilot.com/"
|
||||
);
|
||||
assert_eq!(portal_link(None, "faller"), "");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user