diff --git a/Server/src/SOR.Admin/Program.cs b/Server/src/SOR.Admin/Program.cs index ca57472..7c7820a 100644 --- a/Server/src/SOR.Admin/Program.cs +++ b/Server/src/SOR.Admin/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -127,9 +128,25 @@ builder.Services.AddChatDatabase(builder.Configuration); builder.Services.AddGameDatabase(builder.Configuration); builder.Services.AddSupportDatabase(builder.Configuration); +// ── Forwarded headers ───────────────────────────────────────────────────── +// The pod runs plain HTTP behind a TLS-terminating ingress. Without this, +// ASP.NET Core builds the OIDC redirect_uri as "http://..." which Keycloak +// rejects. Clearing KnownNetworks/KnownProxies trusts any upstream proxy — +// safe because the pod is only reachable from within the cluster. +builder.Services.Configure(options => +{ + options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost; + options.KnownNetworks.Clear(); + options.KnownProxies.Clear(); +}); + // ── HTTP pipeline ───────────────────────────────────────────────────────── var app = builder.Build(); +// Must come before UseAuthentication so the scheme/host are correct when +// the OIDC middleware constructs the redirect_uri. +app.UseForwardedHeaders(); + if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error");