简体   繁体   English

在非Azure生产环境中,ASP.NET核心中的用户机密存储的推荐解决方案是什么?

[英]What is the recommended solution for user secrets storage in ASP.NET core in non-Azure production environment?

I am working on a .net core project, which needs to read some user secrets. 我正在开发一个.net核心项目,它需要读取一些用户机密。 I read the following two articles. 我读了以下两篇文章。

I am wondering if there is a similar solution for a non-Azure production environment, eg one that would work in AWS. 我想知道是否有非Azure生产环境的类似解决方案,例如可以在AWS中使用的解决方案。

.NET Core allows you to store your secrets in various places of the configuration system. .NET Core允许您将秘密存储在配置系统的各个位置。

There are many different configuration providers listed in the documentation : 文档中列出了许多不同的配置提供程序:

  • File formats (INI, JSON, and XML). 文件格式(INI,JSON和XML)。
  • Command-line arguments. 命令行参数。
  • Environment variables. 环境变量。
  • In-memory .NET objects. 内存中的.NET对象。
  • The unencrypted Secret Manager storage. 未加密的秘密管理器存储。
  • An encrypted user store, such as Azure Key Vault. 加密的用户存储,例如Azure Key Vault。
  • Custom providers (installed or created). 自定义提供程序(已安装或创建)。

It's convenient to manage the user secret with Microsoft.Extensions.SecretManager.Tools on the command line and then use Microsoft.Extensions.Configuration.UserSecrets to get the secrets from your app's configuration. 在命令行上使用Microsoft.Extensions.SecretManager.Tools管理用户密钥很方便,然后使用Microsoft.Extensions.Configuration.UserSecrets从应用程序的配置中获取机密。

However, you should encrypt the stored information yourself, wherever you store it, eg. 但是,您应该自己加密存储的信息,无论您在何处存储它,例如。 the appsettings.production.json. appsettings.production.json。

To do so you can make use of a custom configuration provider to encrypt and decrypt your secrets. 为此,您可以使用自定义配置提供程序来加密和解密您的机密。 Your custom provider should inherit from the ConfigurationProvider class as shown here . 您的自定义供应商应该从ConfigurationProvider类继承如图所示这里

public class CustomConfigProvider : ConfigurationProvider
{
    public CustomConfigProvider() { }

    public override void Load()
    {
        Data = MyEncryptUtils.DecryptConfiguration();
    }
}

See also: Encrypted Configuration in ASP.NET Core 另请参阅: ASP.NET Core中的加密配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测.NET应用程序是在Azure中还是在非Azure环境中运行 - Detecting if a .NET app is running in Azure or on a non-Azure environment 无法访问 ASP.net 核心 3.0 中的用户机密 - Can't access User Secrets in ASP.net core 3.0 在 asp.net core 项目中禁用用户机密 - Disabling user secrets in asp.net core project 如何在“生产”环境中Web部署ASP.NET Core应用程序? - How to WebDeploy an ASP.NET Core application in “Production” environment? 在 ASP.NET Core Web API 设置生产环境的launchurl - Set launchurl for production environment in ASP.NET Core Web API .NET 不在 Azure 上托管时,生产服务器上的核心机密 - .NET Core secrets on a production server when not hosting on Azure 使用ASP.Net core2在Azure存储中下载文件 - Download file in azure storage using ASP.Net core2 Stream 视频来自 Azure blob 存储和 ASP.NET 核心 3 - Stream videos from Azure blob storage and ASP.NET Core 3 使用 Azure KeyVault 和 Visual Studio 管理用户机密不适用于 ASP .Net Core - Managing User Secrets with Azure KeyVault and Visual Studio not working for ASP .Net Core 调试 IIS 网站时,ASP.NET Core 2 Web 应用程序未加载用户机密 - ASP.NET Core 2 web application isn't loading user secrets when debugging IIS website
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM