代码之家  ›  专栏  ›  技术社区  ›  Mrunal

如何在Azure函数中使用连接字符串的密钥保险库机密绑定事件中心?

  •  1
  • Mrunal  · 技术社区  · 7 年前

    EventHubTrigger . 基本代码如下:

    public static class MyEventHubTriggerFunction
    {
    
        [FunctionName("MyEventHubTriggerFunction")]
        public static async Task Run([EventHubTrigger("EventHubName",
            Connection = "EventHubConnectionString")] 
            string[] eventHubMessages, 
            TraceWriter log, 
            ExecutionContext context)
            { ... }
    }
    

    这是我的local.settings.json文件:

    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "EventHubName": "<myEventHubName>",
        "EventHubConnectionString": "<myEventHubConnectionString>"
      }
    }
    

    部署此应用程序时,它可以在计算机或Azure上正常工作。这里必须将EventHubConnectionString粘贴到json文件中。

    是否有任何方法可以使用MSI身份验证从KeyVault secret获取该值,并且该值应自动用于实例化 运行方法参数中的实例?

    我知道如何使用 KeyVaultClient 但是这里的函数触发器 run 方法本身需要连接字符串,因此我需要一种方法用KeyVault secret覆盖它。

    1 回复  |  直到 7 年前
        1
  •  2
  •   brettsam    7 年前

    今天不支持此操作。看到了吗 https://github.com/Azure/azure-webjobs-sdk/issues/746 .

    here )是使用ARM模板进行部署,并从KeyVault中注入密钥。

        2
  •  1
  •   Ola L Martins    6 年前

    如果有人(像我一样)偶然发现了这个问题,却没有发现这个问题( https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0b )

    在本地运行-在local.settings.json中设置

    注意! Azure函数必须具有访问密钥保管库的权限。文章中也对此进行了描述

    推荐文章