identityserver4 - 具有来自 AzureKeyvault 的签名凭据的 IdentityServer4 的多个实例
问题描述
我的 identityserver4 部署到 AKS 中,副本数为 1。但是当我将副本数设置为大于 1 时,我开始看到问题。
有时身份验证验证有效,有时无效。根据 IdentityServer4 门户网站的文档,如果我们使用多个正在运行的身份服务器实例,那么我们必须确保在所有实例中使用相同的签名凭据。我已使用 Azure keyvault Keys 来签署本文之后的凭据。但我仍然面临这个问题。我还确保即使根据此链接运行多个实例,发现 url 也是相同的。请指教。
用于从 Azure keyVault 获取密钥的示例启动代码 -
var keyClient = new KeyClient(
new Uri(""), // e.g. https://scottbrady91-test.vault.azure.net/
new ClientSecretCredential(
tenantId: "",
clientId: "",
clientSecret: ""));
Response<KeyVaultKey> response = keyClient.GetKey(""); // e.g. IdentityServerSigningKeyEcc
AsymmetricSecurityKey key;
string algorithm;
if (response.Value.KeyType == KeyType.Ec)
{
ECDsa ecDsa = response.Value.Key.ToECDsa();
key = new ECDsaSecurityKey(ecDsa) {KeyId = response.Value.Properties.Version};
// parse from curve
if (response.Value.Key.CurveName == KeyCurveName.P256) algorithm = "ES256";
else if (response.Value.Key.CurveName == KeyCurveName.P384) algorithm = "ES384";
else if (response.Value.Key.CurveName == KeyCurveName.P521) algorithm = "ES521";
else throw new NotSupportedException();
}
else if (response.Value.KeyType == KeyType.Rsa)
{
RSA rsa = response.Value.Key.ToRSA();
key = new RsaSecurityKey(rsa) {KeyId = response.Value.Properties.Version};
// you define
algorithm = "PS256";
}
else
{
throw new NotSupportedException();
}
services.AddIdentityServer()
.AddTestUsers(TestUsers.Users)
.AddInMemoryIdentityResources(Config.Ids)
.AddInMemoryApiResources(Config.Apis)
.AddInMemoryClients(Config.Clients)
.AddSigningCredential(key, algorithm);
解决方案
可能给您带来问题的另一件事是数据保护 API,它负责保护所涉及的会话 cookie。如果您希望会话 cookie 在实例之间有效,那么它们需要共享相同的加密密钥(密钥环)。
我也在这里写过关于这个的博客: Storing the ASP.NET Core Data Protection Key Ring in Azure Key Vault
推荐阅读
- compiler-construction - 漂亮的打印模棱两可的语法
- google-photos - 使用 API 将照片整理到相册中
- wcf - WCF 服务主机找不到任何服务元数据。请检查元数据是否启用
- spring-boot - 无法在 Spring Boot 中停止并发会话(Keycloak 身份验证服务器)
- parsing - LR(1) 使用 epsilon 产生式解析表
- c# - 字符串 Text.ToUpper() 在 C# Visual Studio 2017 版本 15.1.1 中的 Linq 查询中运行缓慢
- php - PHP:2个存储过程称为-“表名已经存在”
- angular - 如何以角度 4 从 asp.net web api 加载图像?
- r - 在 R 中的同一图中绘制两个条形图
- angular - rxjs6 ActivatedRoute 订阅 observable