From e4ddd801e3f8f393719606ba6951ba5f45238104 Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 4 Apr 2026 13:34:44 -0400 Subject: [PATCH] Store DataProtection keys in Redis to fix cross-pod cookie decryption Without shared key storage, pod A's cookies were unreadable by pod B, causing an infinite OIDC redirect loop that appeared as access denied. Keys are now persisted under SOR.Admin:DataProtection-Keys in the existing Redis instance. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Server/Directory.Packages.props | 2 ++ Server/src/SOR.Admin/Program.cs | 22 +++++++++++++++------- Server/src/SOR.Admin/SOR.Admin.csproj | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Server/Directory.Packages.props b/Server/Directory.Packages.props index 8acb406..ecbb97b 100644 --- a/Server/Directory.Packages.props +++ b/Server/Directory.Packages.props @@ -25,6 +25,8 @@ + + diff --git a/Server/src/SOR.Admin/Program.cs b/Server/src/SOR.Admin/Program.cs index 463c235..6d6d538 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.DataProtection; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Identity; @@ -141,13 +142,20 @@ builder.Services.AddIdentityCore(options => builder.Services.AddRazorPages(); // ── Redis ────────────────────────────────────────────────────────────────── -builder.Services.AddSingleton(_ => -{ - var redisConnectionString = builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379"; - var redisOptions = ConfigurationOptions.Parse(redisConnectionString); - redisOptions.AbortOnConnectFail = false; - return ConnectionMultiplexer.Connect(redisOptions); -}); +// Create the connection eagerly so it can be shared with DataProtection below. +var redisConnectionString = builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379"; +var redisConfig = ConfigurationOptions.Parse(redisConnectionString); +redisConfig.AbortOnConnectFail = false; +var redis = ConnectionMultiplexer.Connect(redisConfig); +builder.Services.AddSingleton(redis); + +// ── DataProtection (Redis-backed) ───────────────────────────────────────── +// Persist DataProtection keys in Redis so all pod replicas share the same key +// ring. Without this, cookies set by pod A cannot be decrypted by pod B, +// causing a redirect loop: OIDC flow completes → cookie set → redirect → +// different pod → cookie unreadable → user appears anonymous → loop. +builder.Services.AddDataProtection() + .PersistKeysToStackExchangeRedis(redis, "SOR.Admin:DataProtection-Keys"); // ── CDN client ──────────────────────────────────────────────────────────── builder.Services.AddCdnClient(builder.Configuration); diff --git a/Server/src/SOR.Admin/SOR.Admin.csproj b/Server/src/SOR.Admin/SOR.Admin.csproj index a96dde5..6fb93fa 100644 --- a/Server/src/SOR.Admin/SOR.Admin.csproj +++ b/Server/src/SOR.Admin/SOR.Admin.csproj @@ -15,6 +15,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive +