Kubernetes + Redis:无法解密防伪令牌

问题描述 投票:0回答:1

我正在使用Redis数据库进行Kubernetes上.net core 3.0上的数据保护,但是仍然出现以下错误。有什么想法吗?

失败:Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery [7]反序列化令牌时引发异常。 Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException:反伪造令牌无法解密。 ->System.Security.Cryptography.CryptographicException:密钥在钥匙圈中找不到{ffb146a1-0e5e-4f96-8566-425f7c2eb99a}。在Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte []protectedData,布尔allowOperationsOnRevokedKeys,UnprotectStatus&状态)Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte []protectedData,布尔值ignoreRevocationErrors,布尔值&requireMigration,Boolean&wasRevoked)Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte []protectedData)位于Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(StringserializedToken)-内部异常堆栈跟踪的结尾-在Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(StringserializedToken)在Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContexthttpContext)

var redis = ConnectionMultiplexer.Connect(Environment.GetEnvironmentVariable("REDIS_CONNSTR"));
services.AddDataProtection().PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
services.AddMvc(options =>
{
    options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
c# asp.net-core kubernetes antiforgerytoken
1个回答
0
投票

根据下面文章中的文档,需要设置应用程序名称。

services.AddDataProtection()
    .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys")
    .SetApplicationName("product");

默认情况下,数据保护系统将应用程序彼此隔离基于他们的内容根路径,即使他们共享相同的根路径物理密钥库。这会阻止应用了解对方的有效载荷。

要在应用之间共享受保护的有效负载:

  • 在每个应用程序中使用相同的值配置SetApplicationName。

https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-3.0

© www.soinside.com 2019 - 2024. All rights reserved.