CloudConfigurationManager不会覆盖来自外部文件的设置

本文关键字:外部 文件 设置 覆盖 CloudConfigurationManager | 更新日期: 2023-09-27 18:02:35

我刚刚发现了CloudConfigurationManager的一个模糊但非常令人沮丧的bug。我正在寻找解决方案,以及(作为旁注)关于报告错误的最佳论坛的提示。我猜这将是一个相对较快的解决办法。

我有一个Azure应用程序服务,连接到DocumentDb的配置设置称为DocumentDB.EndpointDocumentDB.Key。这些是在f#中使用

拾取的
let endpoint = config.ReadConfigSetting<string>("DocumentDB.Endpoint")
let key = config.ReadConfigSetting<string>("DocumentDB.Key")

ReadConfigSetting方法是一个方便的方法,它执行相关的类型转换和默认赋值。在掩护下,它使用CloudConfigurationManager.GetSetting。出于我们的目的,将调用视为

let endpoint = CloudConfigurationManager.GetSetting("DocumentDB.Endpoint")
let key = CloudConfigurationManager.GetSetting("DocumentDB.Key")

我有一个webjob,在我的文档DB集合上执行cron作业。CloudConfigurationManager首先从应用程序服务设置中获取设置,如果在应用程序服务设置中没有找到密钥,它将查看我的webjob的app.config

在我的QA环境中,我的webjob正在选择正确的端点,但错误的键。这是因为DocumentDb.Endpoint直接在我的app.config文件中列出,但DocumentDb.Key在一个单独的文件中,即.gitignore d。我不想在Git repo中使用敏感密钥,即使它是私有的,并且凭据仅在app.config和我的外部文件中列出,方便我在本地运行作业。

这是我的设置:

App.config

<appSettings file="keys.config">
  <add key="agentUserName" value="<Everyone can read this>" />
  <add key="apiHost" value="<and this>" />
  <add key="DocumentDB.Endpoint" value="<points to my remote develpment copy of DocumentDB -- looking forward to when I can get a local repo>" />
</appSettings>

keys.config

<appSettings>
  <add key="DocumentDB.Key" value="<This is private, so it's in this gitignored file>" />
  <add key="agentPassword" value="<I'm not telling you>" />
  <add key="TestUserPassword" value="<I'd be an idiot to post this value in a SO question>" />
</appSettings>

你可以看到发生了什么。

CloudConfigurationManager查找DocumentDB值时的预期行为。关键

  1. 查看DocumentDB值的底层应用服务设置。关键
  2. 如果存在,使用
  3. 否则,查看App.config
  4. 如果没有,请查看keys.config

CloudConfigurationManager的实际行为

  1. keys.config有值吗?
  2. 然后查看应用服务设置
  3. 然后App.config .

我现在最好的解决办法是在我发布web作业时注释出keys.config中的值,但这很笨拙。有更好的方法吗?

哪里是最好的地方记录这个问题?

CloudConfigurationManager不会覆盖来自外部文件的设置

您看过Azure密钥库吗?以下是Azure密钥库的介绍:https://azure.microsoft.com/en-us/documentation/articles/key-vault-get-started/

如果您将DocumentDB秘密存储在Azure密钥库中,您可以将对秘密的访问权限授予应用程序级别。下面是另一篇文章,展示了如何在web应用程序中做到这一点:https://azure.microsoft.com/en-us/documentation/articles/key-vault-use-from-web-application/

希望对你有帮助。

谢谢。

Lengning