【问题标题】:Using Azure Key vault on Azure Logic App API Connection在 Azure 逻辑应用 API 连接上使用 Azure Key Vault
【发布时间】:2026-01-17 07:10:01
【问题描述】:

我在 Azure Logic App 上使用过 Azure Key Vault。但我无法访问 Azure Logic APP API Connection 的值。基本上我必须从 Azure Key Vault 获取 SQL 连接器的用户名和密码。如果您能提出建议,请欣赏我们如何实现这一目标。

【问题讨论】:

  • 其实API连接一旦创建就不会在里面存储任何敏感信息,所以你可以直接输入你的名字、密码等。
  • @JoyWang 是的。安全角度来看,是正确的。但我喜欢这样做,因为如果我更改 SQL 的凭据,它会自动刷新到 Logic APP
  • 您对使用 arm 模板的解决方案感兴趣吗?但如果您更改凭据,它不会自动刷新逻辑应用。
  • 好的。 @Thomas 告诉我 ARM 模板

标签: azure azure-logic-apps serverless azure-keyvault


【解决方案1】:

据我所知,Azure 逻辑应用程序无法访问门户中 api 连接中的密钥库。如果要访问密钥保管库,可以使用rest api 访问它。 您需要在逻辑应用程序中启用 msi(下面的链接显示我们可以在“工作流程设置”中进行 msi 修改,但目前它已更改,我们需要在逻辑应用程序的“身份”刀片中启用它)并使用 http 操作访问您的密钥保管库。

您可以参考此链接了解更多信息:https://devkimchi.com/2018/10/24/accessing-key-vault-from-logic-apps-with-managed-identity/

【讨论】:

    【解决方案2】:

    一旦创建连接 API 将不会输出任何敏感信息。
    使用 ARM 模板,您可以创建 API 连接,但在轮换凭据时它不会更新连接详细信息,您必须重新部署模板。

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "sqlConnectionAPIName": {
          "type": "string",
          "metadata": {
            "description": "The name of the connection api to access the service bus namepsace."
          }
        },
        "sqlserverName": {
          "type": "string",
          "metadata": {
            "description": "The Name of the SQL Server instance."
          }
        },
        "databaseName": {
          "type": "string",
          "metadata": {
            "description": "The name of the database."
          }
        }
      },
      "variables": {},
      "resources": [
        {
          "type": "Microsoft.Web/connections",
          "name": "[parameters('sqlConnectionAPIName')]",
          "apiVersion": "2018-07-01-preview",
          "location": "[resourceGroup().location]",
          "scale": null,
          "properties": {
            "displayName": "[parameters('sqlConnectionAPIName')]",
            "parameterValues": {
              "server": "[reference(resourceId('Microsoft.Sql/servers', parameters('sqlserverName')), '2015-05-01-preview').fullyQualifiedDomainName]",
              "database": "[parameters('databaseName')]",
              "username": "[reference(resourceId('Microsoft.Sql/servers', parameters('sqlserverName')), '2015-05-01-preview').administratorLogin]",
              "password": "[reference(resourceId('Microsoft.Sql/servers', parameters('sqlserverName')), '2015-05-01-preview').administratorLoginPassword]"
            },
            "api": {
              "id": "[concat('subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
            }
          },
          "dependsOn": []
        }
      ]
    }
    

    【讨论】: