我正在学习将 blazor 服务器应用程序加载到 docker 容器(aspnet 核心 3.0.201)。我已成功将图像加载到容器上。我能够创建一个应用程序来构建它,但是在运行 blazor 服务器应用程序时,我收到了这种警告:
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container.
Protected data will be unavailable when container is destroyed.
Run Code Online (Sandbox Code Playgroud)
这是一个警告,但我知道在容器上加载密钥不是一个好习惯,所以我想修复警告。任何指导表示赞赏。
您收到的警告是因为 ASP.NET Core DataProtection 将密钥存储在 HOME 目录 (/root/.aspnet/DataProtection-Keys) 中,因此当容器重新启动密钥丢失时,这可能会使服务崩溃。
这可以通过将密钥保持在以下位置来解决:
在持久位置(卷)保留密钥并将该卷挂载到 docker 容器
在 Azure 或 Redis 等外部密钥存储中保留密钥
有关 ASP.NET 数据保护的更多详细信息:
使用以下命令将外部卷 (C:/temp-keys) 挂载到 docker 容器卷 (/root/.aspnet/DataProtection-Keys)
docker run -d -v /c/temp-keys:/root/.aspnet/DataProtection-Keys container-name
此外,您需要更新您Starup.cs - ConfigureServices的配置数据保护策略
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(@"C:\temp-keys\"))
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7843 次 |
| 最近记录: |