【问题标题】:Warnings in Kubernetes "Storing keys in a directory '{path}' that may not be persisted outside of the container. "Kubernetes 中的警告“将密钥存储在目录 '{path}' 中,可能不会保留在容器之外。”
【发布时间】:2021-10-10 16:00:08
【问题描述】:

我们在 Kubernetes 中运行的 .Net Core Web API 服务的生产日志中收到警告。

将密钥存储在目录“{path}”中,可能不会在外部持久化 的容器。当容器被保护时,受保护的数据将不可用 已销毁。","@l":"Warning","path":"/root/.aspnet/DataProtection-Keys",SourceContext:"Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository"

我们没有在 StartUp 中明确调用 services.AddDataProtection(),但似乎我们收到了针对使用 .Net Core 3.1 和 .Net 5 的服务的警告。(不适用于 .Net Core 2.1) ,在 StartUp 中也有

services.AddAuthentication Or 
services.AddMvc()

(可能还有我遗漏的其他条件)。

我无法准确识别它的调用位置,但在本地我可以看到在从 XmlKeyManager 访问 DataProtection-Keys 之前加载的相关 DLL

 Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.19\Microsoft.Win32.Registry.dll'. 
 Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.19\System.Xml.XDocument.dll'. 
 Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.19\System.Private.Xml.Linq.dll'. 
 Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.19\System.Private.Xml.dll'. 
 Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.19\System.Resources.ResourceManager.dll'.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager:
Using 'C:\Users\..\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.

考虑到我们不明确使用 DataProtection、不长时间使用身份验证加密并且在测试期间我们没有发现任何问题,忽略此类警告是否安全?

或者这个错误意味着如果同一个客户端涉及到不同的pods,身份验证可能会失败,最好按照How to store Data Protection-keys outside of the docker container?中的建议做一些事情?

【问题讨论】:

  • 根据我的理解是直接和kubernetes连接的,这个警告说如果不使用persistent volume,重启容器/pod时所有数据都会丢失。但是,由于我不是 .net 开发人员,这可能意味着更多。

标签: asp.net-core kubernetes data-protection


【解决方案1】:

在分析我们的应用程序如何使用受保护数据(身份验证 cookie、CSRF 令牌等)后,我们的团队 决定,“当容器被销毁时,受保护的数据将不可用。”只是一个警告,不会对客户产生影响,所以我们忽略它。

但是YMMV.

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    相关资源
    最近更新 更多