加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.net-core – 存储Azure Vault客户端ID和客户端密钥

发布时间:2020-12-16 06:34:35 所属栏目:asp.Net 来源:网络整理
导读:我正在使用.NET Core 2.0和ASP.NET Core 2.0进行应用程序开发. “test”应用程序是.NET Core Console应用程序.我写的核心代码是一个类库.一旦正确测试.我选择这样做,因为我不会暂时使用它(它正在替换旧的ASPNET代码). 无论如何,由于我必须使用大量的API密钥
我正在使用.NET Core 2.0和ASP.NET Core 2.0进行应用程序开发. “test”应用程序是.NET Core Console应用程序.我写的核心代码是一个类库.一旦正确测试.我选择这样做,因为我不会暂时使用它(它正在替换旧的ASPNET代码).

无论如何,由于我必须使用大量的API密钥来处理各种服务,所以我决定使用Microsoft Azure Key Vault来存储密钥.我有这个设置,并了解它是如何工作的.测试应用程序使用测试Azure帐户,因此它并不重要.由于这是替换遗留代码并且它处于起步阶段,我是唯一的开发人员.

基本上,我遇到了这个问题.从我所看到的Azure Key Vault上没有太多信息.很多示例都将客户端ID和密钥存储在纯文本json文件中(例如:https://www.humankode.com/asp-net-core/how-to-store-secrets-in-azure-key-vault-using-net-core).我真的不明白这是如何安全的.如果有人要获得这些密钥,他们可以轻松访问Azure存储的信息,对吧?

Microsoft MSDN有一个授权访问的powershell命令(我丢失了原始链接,这是我能找到的最接近的链接:https://www.red-gate.com/simple-talk/cloud/platform-as-a-service/setting-up-and-configuring-an-azure-key-vault/)我的开发操作系统是Windows 10,我的主服务器操作系统是Debian.

我该如何处理?

解决方法

是的,你是对的,纯文本配置文件只能在开发期间使用,不能用于生产目的.通常,可用选项取决于您托管应用程序的位置和方式.

如果您有Azure Web App,则至少有下一个内置选项(from the documentation):

  • add the ClientId and ClientSecret values for the AppSettings in the Azure portal. By doing this,the actual values will not be in the web.config but protected via the Portal where you have separate access control capabilities. These values will be substituted for the values that you entered in your web.config. Make sure that the names are the same.

  • authenticate an Azure AD application is by using a Client ID and a Certificate instead of a Client ID and Client Secret. Following are the steps to use a Certificate in an Azure Web App:

    • Get or Create a Certificate
    • Associate the Certificate with an Azure AD application
    • Add code to your Web App to use the Certificate
    • Add a Certificate to your Web App

您还可以找到一种使用env变量来存储凭据的方法.只有在可以保证不能在prod机器上执行env变量的快照时,这可能没问题.请查看Environment Variables Considered Harmful for Your Secrets了解更多详情.

最后一件事:还有一种基于这个想法的技术,你需要存储/传递ClientSecret值,而ClientId应该根据托管App的机器/容器细节构建(例如docker container id) .我找到了一个Hashicorp Vault和一个在AWS上托管的应用程序的示例,但总的想法是相同的:Secret management with Vault

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读