为什么不应该将密码保存在 appsettings.json in ASP.NET Core 中?

Why shouldn't passwords be saved inside of appsettings.json in ASP.NET Core?

official documentation lists以下做法appsettings.json:

  • Never store passwords or other sensitive data in configuration provider code or in plain text configuration files.
  • Don't use production secrets in development or test environments.
  • Specify secrets outside of the project so that they can't be accidentally committed to a source code repository.

据我所知,当您在 IIS 上托管应用程序时,不会提供 appsettings.json,因此无法从 Web 访问。我们也自己托管源代码(即在我们自己的服务器上)。据我所知,唯一真正的危险是当有人设法破坏整个系统并实际访问 appsettings.json 本身时。

但是还有其他原因将敏感数据保存在 appsettings.json 之外吗?还有其他我忽略的安全方面吗?

我知道有几个问题问 如何 来保证 appsettings.json 的安全,但不知道实际风险是什么。

原因有很多,但您已经提到的主要原因是:

  • 访问源代码通常比访问受到严密保护的秘密(例如 Azure Vault)要容易得多
  • 泄露秘密要容易得多,可能是意外(通过日志,或有人偷看你,或有人有权访问 CI 服务器)
  • 你通常不会知道你泄露了它们,因为通常没有审计或比使用适当的保密系统少得多
  • 无法限制有权访问特定环境的特定机密的人员
  • 就我个人而言,我也不喜欢在我的开发设置附近有特别的 生产 秘密。如果我 运行 作为开发人员编写代码,我想 100% 确定我永远不会在生产环境中 运行 意外 ("oops, I tested that mass-delete feature...vs production")。如果产品秘密 只是不存在 那么就不会犯错
  • 可能还有更多原因...

基本上,限制错误和安全漏洞的表面积将限制出现问题的机会,即使目前没有合理的因素组合会导致错误或安全漏洞发生了。