GNMON-001 M6 abgenommen: Dashboard oeffentlich via mon.ghostnet.selfhost.eu (Keycloak-OIDC)

Kette: Browser -> https://mon.ghostnet.selfhost.eu (NPM CT-103 ID 14, LE-TLS,
Force SSL, WS-Support, X-Forwarded-Proto/Host + 32k-Puffer) -> 10.0.0.90:8080
(nftables gnmon_firewall: nur von 10.0.0.10) -> Blazor v0.3.2 -> Keycloak
Realm Ghost.net, Client gnai-dashboard, Rollen gnai-dashboard-user/-admin.

Neu/geaendert:
- Rolle gnmon_firewall (nftables auf ghostnet-ki, Policy ACCEPT, 8080 nur
  von NPM, Monitoring-Ports non-loopback-drop), Tag firewall in monitor.yml
- Dashboard-Bind 10.0.0.90:8080 (Assertion: LAN-Bind nur mit Firewall-Tag);
  Image v0.3.2; Playbook-Verifikation akzeptiert 200/302 mit Forwarded-Headern
- App: ClientId gnai-dashboard, Auth:AllowedRoles konfigurierbar,
  KnownNetworks/KnownProxies per .Clear() (leere Initializer = Loopback-Default),
  GetClaimsFromUserInfoEndpoint=true (realm-roles-Mapper-Flags im Realm unset),
  SaveTokens=true (Logout: id_token_hint), Cookie AccessDeniedPath
  /access-denied + Page (sonst Redirect-Loop), csproj PrunePackageData=false +
  Containerfile ohne --no-restore (sonst fehlt blazor.web.js im Image ->
  Blazor-Circuit startet nicht)
- KeycloakRealmRolesClaimTransformation auf ClaimTypes.Role + [gnmon-auth]-Log
- CT-100: Adoption 09.11. (pct exec), Split-DNS mon -> 10.0.0.10 live;
  Befunde gefixt: dns_pihole_hosts_records in allen 3 Inventaren gespiegelt,
  FTLCONF_dns_hosts als eine ';'-gejointe Environment-Zeile (systemd: letzter
  Key gewinnt); gnmon_alloy doppelte Key korrigiert
- Doku: GNMON-000 M6 abgenommen (alle Befunde), GNMON-001 v2.2, GNAI-000
  Monitoring/DNS-Zeilen, GNAI-006 v3.1 (Proxy-Host 14), GNAI-012 Stand

E2E 09.11.2026: unauth -> 302 mit PAR request_uri; Direktzugriff 10.0.0.90:8080
gedroppt; blazor.web.js 200 text/javascript; Login ghost -> Dashboard 200 mit
Live-Daten, Unterseiten + WebSocket ok; testuser ohne Rollen -> saubere 403;
/logout ok; monitor.yml gesamt ok=84 changed=0. Server-Image-Store aufgeraeumt
(v0.3.2 + Rollback v0.2.0/v0.1.0).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-09 19:34:50 +01:00
parent 148104de4e
commit fd8e1a5559
25 changed files with 383 additions and 90 deletions
@@ -36,8 +36,14 @@ builder.Services.AddHttpClient<AlertmanagerClient>(client =>
// --- OIDC (GNMON-001 section 6, M6) ------------------------------------
// Auth is purely configuration-driven: disabled (workstation/local
// deployments) the DashboardAccess policy authorizes everyone; enabled
// the app requires a Keycloak login with the realm role dashboard-admin.
// the app requires a Keycloak login with a realm role ai-dashboard or
// ai-dashboard-admin (Betreiber-Namenskonvention im Realm Ghost.net).
var authEnabled = builder.Configuration.GetValue<bool>("Auth:Enabled");
// Realm roles that grant dashboard access (comma-separated, configurable
// so the Keycloak naming does not require an app rebuild).
var allowedRoles = (builder.Configuration["Auth:AllowedRoles"]
?? "ai-dashboard,ai-dashboard-admin")
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (authEnabled)
{
var authority = builder.Configuration["Auth:Authority"]
@@ -49,13 +55,16 @@ if (authEnabled)
var clientSecret = builder.Configuration["Auth:ClientSecret"]
?? throw new InvalidOperationException(
"Auth:Enabled requires the client secret via Auth:ClientSecret (environment)");
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
// Forbid after endpoint authorization lands on the COOKIE scheme
// (DefaultForbidScheme), so its AccessDeniedPath must point at the page —
// the OIDC default /Account/AccessDenied does not exist in this app and
// produced a redirect loop (Befund 09.11.2026).
.AddCookie(cookie => cookie.AccessDeniedPath = "/access-denied")
.AddOpenIdConnect(options =>
{
options.Authority = authority;
@@ -63,14 +72,31 @@ if (authEnabled)
options.ClientSecret = clientSecret;
options.ResponseType = "code"; // authorization code flow + PKCE
options.UsePkce = true;
options.SaveTokens = false;
options.GetClaimsFromUserInfoEndpoint = false;
// Keycloak realm roles live in realm_access.roles; map them onto
// role claims in addition to the claims transformation (the
// transformation also covers identities without a role claim).
options.TokenValidationParameters.RoleClaimType = "role";
// The redirect URI is derived from the request host; behind NPM the
// X-Forwarded-Host/X-Forwarded-Proto headers (see UseForwardedHeaders
// below) restore the external name mon.ghostnet.selfhost.eu, so the
// computed https://mon.ghostnet.selfhost.eu/signin-oidc matches the
// URI registered in Keycloak. .NET 10 has no RedirectUri property.
// SaveTokens is required so the OIDC sign-out redirect carries
// id_token_hint (Keycloak end_session rejects logout without it:
// "Missing parameters: id_token_hint", Befund 09.11.2026).
options.SaveTokens = true;
// Pull the full claim set (incl. realm_access.roles) from the
// userinfo endpoint: the realm-roles mapper's "Add to ID token" flag
// is not set in this realm, so the ID token alone carried no
// realm_access and authorization denied everyone (Befund 09.11.2026).
options.GetClaimsFromUserInfoEndpoint = true;
// Keycloak realm roles live in the realm_access.roles JSON claim;
// KeycloakRealmRolesClaimTransformation maps them onto role claims
// (ClaimTypes.Role, the default RoleClaimType — overriding it to
// "role" broke IsInRole because inbound claim mapping renames "role"
// to ClaimTypes.Role, Befund 09.11.2026).
options.Scope.Add("openid");
options.Scope.Add("profile");
// Clean 403 page instead of the default /Account/AccessDenied, which
// does not exist in this app and produced a redirect loop in the
// browser (Befund 09.11.2026).
options.AccessDeniedPath = "/access-denied";
});
builder.Services.AddSingleton<IClaimsTransformation, KeycloakRealmRolesClaimTransformation>();
@@ -82,8 +108,9 @@ builder.Services.AddAuthorization(options =>
{
if (authEnabled)
{
// Realm role from Ghost.net (see KeycloakRealmRolesClaimTransformation).
policy.RequireRole("dashboard-admin");
// Realm roles from Ghost.net (see KeycloakRealmRolesClaimTransformation),
// configurable via Auth:AllowedRoles.
policy.RequireRole(allowedRoles);
}
else
{
@@ -97,12 +124,21 @@ builder.Services.AddCascadingAuthenticationState();
var app = builder.Build();
// TLS terminates at NPM (CT-103); trust its forwarded headers so the
// OIDC redirect URIs and HTTPS checks see the external scheme/host.
app.UseForwardedHeaders(new ForwardedHeadersOptions
// TLS terminates at NPM (CT-103); trust its forwarded headers so the OIDC
// redirect URIs and HTTPS checks see the external scheme/host. Port 8080 is
// reachable only from 10.0.0.10 anyway (gnmon_firewall), so clearing the
// known-proxy lists is safe here. NOTE: KnownNetworks/KnownProxies must be
// .Clear()ed — a `{ }` collection initializer keeps the default loopback
// entry, non-loopback proxies are then rejected and the redirect_uri is
// computed from the internal 10.0.0.90:8080 host (PAR: "Invalid parameter:
// redirect_uri", Befund 09.11.2026).
var forwardedHeaders = new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
});
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost,
};
forwardedHeaders.KnownNetworks.Clear();
forwardedHeaders.KnownProxies.Clear();
app.UseForwardedHeaders(forwardedHeaders);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())