duendesoftware/duende-skills/identityserver-key-management

Claude Code and agent skill by duendesoftware/duende-skills

Trust tier 2
  • community
  • ext:[{"type":"plugin","description":"Custom plugin integration"}]
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Managing cryptographic signing keys in Duende IdentityServer, including automatic key management, KeyManagementOptions, data protection at rest, static key configuration, migration from static to automatic, and multi-instance deployment considerations, HSM/cloud KMS signing, key backup, and key-compromise response.

Install

npx vskill@latest install duendesoftware/duende-skills/identityserver-key-management

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-key-management.

Key Management and Signing

When to Use This Skill

  • Configuring automatic key management for signing token keys
  • Setting up static/manual signing keys from certificates or key vaults
  • Configuring key rotation intervals and key lifecycle
  • Migrating from static keys to automatic key management
  • Deploying IdentityServer in load-balanced or multi-instance environments
  • Protecting keys at rest using data protection
  • Configuring per-algorithm or per-resource signing
  • Troubleshooting key-related errors (CryptographicException, unprotecting key failures)
  • Integrating an HSM or cloud KMS (e.g. Azure Key Vault) for signing
  • Backing up signing keys and responding to a suspected key compromise

Docs: https://docs.duendesoftware.com/identityserver/fundamentals/key-management/

Core Concepts

IdentityServer issues cryptographically signed tokens: identity tokens, JWT access tokens, and logout tokens. These signatures require key material that can be managed automatically or manually (statically).

Supported Signing Algorithms

IdentityServer supports the RS, PS, and ES families:

FamilyAlgorithmsKey Type
RSRS256, RS384, RS512RSA
PSPS256, PS384, PS512RSA
ESES256, ES384, ES512ECDSA
Core Rotation Rule

Regardless of approach, safe rotation obeys one rule: publish a new public key in discovery (JWKS) BEFORE using it to sign tokens, and keep a RETIRED public key published until every token signed with it has expired. Automatic Key Management enforces this overlap for you (Announced → Signing → Retired phases). With static/manual keys you must perform the overlap yourself via phased rotation (see Manual Key Rotation).

Automatic Key Management (Recommended)

Automatic Key Management handles key creation, rotation, announcement, and retirement. It is enabled by default and is part of the Business and Enterprise editions (per the current licensing page: an add-on for the Standard edition, included in Advanced/Enterprise; the entry-level edition is now called Lite). In v8 a missing entitlement throws at startup.

Key Lifecycle

Keys move through four phases:

Announced --> Signing --> Retired --> Deleted
| | | |
|<--Propagation-->| | |
| |<--Rotation-->| |
| | |<--Retention-->|
PhaseDuration (default)Purpose
Announced14 days (PropagationTime)Published in discovery, not yet signing
Signing76 days (RotationInterval - PropagationTime)Active signing credential
Retired14 days (RetentionDuration)In discovery for token validation only
DeletedAfter retentionRemoved from discovery and optionally deleted

Default schedule: Keys rotate every 90 days, announced 14 days early, retained 14 days after rotation.

Configuration
csharp
// Program.cs
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
{
// Key rotates every 30 days
options.KeyManagement.RotationInterval = TimeSpan.FromDays(30);
// Announce new key 2 days in advance in discovery
options.KeyManagement.PropagationTime = TimeSpan.FromDays(2);
// Keep old key for 7 days in discovery for validation
options.KeyManagement.RetentionDuration = TimeSpan.FromDays(7);
// Don't delete keys after their retention period is over
options.KeyManagement.DeleteRetiredKeys = false;
});
KeyManagement Options Reference
PropertyDefaultDescription
EnabledtrueEnable automatic key management
SigningAlgorithms[RS256]Algorithms for which keys are managed
RsaKeySize2048RSA key size in bits
RotationInterval90 daysAge at which keys stop signing
PropagationTime14 daysTime for new keys to propagate to all servers and clients
RetentionDuration14 daysDuration retired keys remain in discovery
DeleteRetiredKeystrueDelete keys after retention period
KeyPath{ContentRootPath}/keysFile system path for default key store
DataProtectKeystrueEncrypt keys at rest using data protection
KeyCacheDuration24 hoursCache duration for keys from store
InitializationDuration5 minutesSynchronization window on first key creation
InitializationSynchronizationDelay5 secondsDelay between retries during initialization
Multiple Signing Algorithms

Configure multiple algorithms to serve clients with different requirements. The first algorithm in the list is the default for signing tokens.

csharp
options.KeyManagement.SigningAlgorithms = new[]
{
// RS256 for older clients (with X.509 wrapping)
new SigningAlgorithmOptions(SecurityAlgorithms.RsaSha256) { UseX509Certificate = true },
// PS256
new SigningAlgorithmOptions(SecurityAlgorithms.RsaSsaPssSha256),
// ES256
new SigningAlgorithmOptions(SecurityAlgorithms.EcdsaSha256)
};

Override the default on a per-client or per-resource basis:

csharp
// Client level
var client = new Client
{
AllowedIdentityTokenSigningAlgorithms = { SecurityAlgorithms.RsaSsaPssSha256 }
};
// API Resource level
var api = new ApiResource("invoice")
{
AllowedAccessTokenSigningAlgorithms = { SecurityAlgorithms.RsaSsaPssSha256 }
};

Key Storage

Default: File System

The default FileSystemKeyStore writes keys to the KeyPath directory (defaults to {ContentRootPath}/keys). This directory must be:

  • Excluded from source control
  • Accessible (read/write) to all load-balanced instances if using file-based storage
csharp
// Program.cs
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
{
options.KeyManagement.KeyPath = "/home/shared/keys";
});
EntityFramework Store

Use the EF operational store for database-backed key storage:

csharp
// Program.cs
builder.Services.AddIdentityServer()
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlServer(connectionString);
});
Duende Storage Store (preview)

AddStorage(...) + AddOperationalStorage() stores signing keys through the Duende Storage layer (ISigningKeyStore). See identityserver-duende-storage.

Custom Store

Implement ISigningKeyStore for custom storage (e.g., Azure Key Vault, AWS KMS):

csharp
// Program.cs
builder.Services.AddIdentityServer()
.AddSigningKeyStore<YourCustomStore>();

The store interface methods:

  • LoadKeysAsync - load all keys (cached for KeyCacheDuration)
  • StoreKeyAsync - persist a new key
  • DeleteKeyAsync - remove a retired key

HSM and Cloud KMS

IdentityServer has no built-in HSM/KMS provider. Options depend on how the key is exposed:

  • HSM key exposed to .NET (X509Certificate2/RSA/ECDsa backed by CNG/PKCS#11): register as a static credential with AddSigningCredential; signing happens inside the HSM, no private-key export.
  • Remote KMS signing via API: custom CryptoProviderFactory + SignatureProvider attached to the SecurityKey (signing is synchronous, so async KMS calls block), or subclass DefaultTokenCreationService and override CreateJwtAsync to call the KMS async signing API.
  • Custom `ISigningKeyStore` only changes where automatic key management stores its (exportable) keys, e.g. a vault. It is not a way to use non-exportable keys.
Async remote KMS signing (Azure Key Vault example)

All JWTs (access, identity, JWT introspection) go through ITokenCreationService.

csharp
// KeyVaultTokenCreationService.cs
public class KeyVaultTokenCreationService(
CryptographyClient crypto, TimeProvider timeProvider, IKeyMaterialService keys,
IdentityServerOptions options, ILogger<DefaultTokenCreationService> logger)
: DefaultTokenCreationService(timeProvider, keys, options, logger)
{
protected override async Task<string> CreateJwtAsync(Token token, string payload,
Dictionary<string, object> headerElements, CancellationToken ct)
{
var credential = await Keys.GetSigningCredentialsAsync(token.AllowedSigningAlgorithms, ct);
headerElements.TryAdd("typ", "JWT");
headerElements["alg"] = credential.Algorithm;
headerElements["kid"] = credential.Key.KeyId;
var header = Base64UrlEncoder.Encode(JsonSerializer.Serialize(headerElements));
var body = Base64UrlEncoder.Encode(payload);
var signingInput = $"{header}.{body}";
var result = await crypto.SignDataAsync(
new SignatureAlgorithm(credential.Algorithm), Encoding.UTF8.GetBytes(signingInput), ct);
return $"{signingInput}.{Base64UrlEncoder.Encode(result.Signature)}";
}
}
csharp
// Program.cs: register the KMS *public* key as the signing credential and disable automatic key management
var publicKey = new RsaSecurityKey(kmsKey.Key.ToRSA(includePrivateParameters: false)) { KeyId = kmsKey.Properties.Version };
builder.Services.AddIdentityServer(o => o.KeyManagement.Enabled = false)
.AddSigningCredential(new SigningCredentials(publicKey, SecurityAlgorithms.RsaSha256));
builder.Services.AddSingleton(new CryptographyClient(kmsKey.Id, azureCredential));
builder.Services.AddTransient<ITokenCreationService, KeyVaultTokenCreationService>();

Caveats: IdentityServer still needs a signing credential (algorithm for at_hash/c_hash, id_token_signing_alg_values_supported, JWKS publishing), so use AddSigningCredential, not only AddValidationKey. Rotation is your job: publish the new public key ahead of time with AddValidationKey, keep the old one until tokens expire. SAML signing does not use `ITokenCreationService`; it reads the credential directly and needs a private key, so this approach doesn't cover SAML. Each token costs a KMS network call (latency/rate limits/availability). v7 differences: IClock instead of TimeProvider, no CancellationToken on CreateJwtAsync, GetSigningCredentialsAsync takes only the algorithms.

Backing Up Signing Keys

With automatic key management, stored keys are encrypted with ASP.NET Core Data Protection by default, so a key-store backup is only usable together with the Data Protection keys: back up and restore both. The restored key ring is only readable with the same application name (SetApplicationName) and access to whatever protects it at rest (certificate / Key Vault). With static keys, back up the certificate and private key with the same protections.

Responding to a Key Compromise

Rotate immediately; don't wait for the schedule:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
9
Repository forks
3
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Extension points

  • pluginCustom plugin integration

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/duendesoftware/duende-skills/identityserver-key-management/badge)](https://verified-skill.com/skills/duendesoftware/duende-skills/identityserver-key-management)

Something wrong with this skill or its page? Tell us.