IdentityServer 7 - Token validation fails after scaling out (multi-instance) - "Key was not found in the key ring" #368
Replies: 2 comments 5 replies
-
The error you're seeing ( I'll attempt to answer each of your questions:
|
Beta Was this translation helpful? Give feedback.
-
I add this private static void LogXmlEncryptorType(IHost host)
{
using var scope = host.Services.CreateScope();
var options = scope.ServiceProvider.GetRequiredService<IOptions<KeyManagementOptions>>().Value;
var logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Data protection encryptor type: {EncryptorType}",
options.XmlEncryptor is null ? "None" : options.XmlEncryptor.GetType().FullName);
} Data protection encryptor type: None |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We're using Duende IdentityServer (or IdentityServer7) hosted in Azure App Service with scale-out to 2+ instances.
✅ Current Setup:
We're using StackExchange.Redis to persist Data Protection keys:
Redis connection is shared and confirmed to be reachable by all instances.
We're not using Azure Blob or file system persistence.
IdentityServer is configured with:
🧪 Problem:
After deployment or during scaling events, we sometimes get the following error:
Logs show exceptions like:
🔍 What We've Tried:
Both Redis and a SQL database,
but still seeing key-related issues like:
❌ CryptographicException: The key {guid} was not found in the key ring
Verified Redis key presence (DataProtection-Keys*) via Redis CLI — keys exist.
Ensured same Redis connection string across all nodes.
Added logging to preload keys at startup using ISigningCredentialStore.
No fallback to blob storage is configured.
❓ What We Want to Know:
Why would a properly configured Redis key store still result in "key not found" errors across instances?
Are we missing a configuration to ensure all nodes load the key ring before token issuance/validation?
Is there a race condition with Duende’s in-memory caching of keys per instance?
What’s the best pattern to warm up key loading in a multi-instance Redis setup?
Can we configure IdentityServer or Data Protection to fail-fast if keys aren't loaded?
Beta Was this translation helpful? Give feedback.
All reactions