How would you configure Kestrel to use a specific X.509 certificate for HTTPS, and what are the different ways to supply that certificate (file-based, certificate store, Azure Key Vault)?
Short answer
Kestrel's HTTPS configuration accepts a certificate via several sources: a PFX file with a password (common for development/simple deployments), the Windows/Linux certificate store referenced by thumbprint (common in enterprise/IIS-integrated scenarios), or a cloud secret…
Advertisement
AModel answer
Kestrel's HTTPS configuration accepts a certificate via several sources: a PFX file with a password (common for development/simple deployments), the Windows/Linux certificate store referenced by thumbprint (common in enterprise/IIS-integrated scenarios), or a cloud secret manager like Azure Key Vault (via a certificate provider integration, avoiding storing certificate files or passwords directly in configuration) -- production deployments increasingly favor Key Vault or a managed certificate service to avoid manual certificate file management and rotation.
// File-based (appsettings.json)
"Kestrel": { "Endpoints": { "Https": { "Url": "https://*:5001", "Certificate": { "Path": "cert.pfx", "Password": "secret" } } } }
// Certificate store by thumbprint (code)
builder.WebHost.ConfigureKestrel(options => {
options.ListenAnyIP(5001, o => o.UseHttps(StoreName.My, "A1B2C3...", StoreLocation.LocalMachine));
});
// Azure Key Vault integration
builder.Configuration.AddAzureKeyVault(vaultUri, credential);Real-world example
An enterprise deployment loads its production TLS certificate directly from Azure Key Vault at startup, with automatic rotation handled by Key Vault's own certificate lifecycle management, avoiding the operational burden of manually renewing and redeploying PFX certificate files before each expiration.
Likely follow-ups
- How do you implement zero-downtime certificate rotation without restarting the Kestrel process?
- What's the security risk of storing a PFX password directly in appsettings.json versus a secret manager?
Related topics