在 DevOps 中从 ARM 模板部署逻辑应用程序时,如何创建与 Azure KeyVault 的 API 连接
How can I create API connection to Azure KeyVault when deploying Logic App from ARM template in DevOps
我在 DevOps 中通过 ARM 模板部署逻辑应用程序工作流,效果很好。当我需要在工作流中连接到 Blob 存储或存储队列时,我可以预先在 ARM 中创建这两个 API 连接然后使用它们,但是如何创建到 KeyVault 的连接?连接模板的(我相信只需要)连接参数是 vaultName
和 token
,如下所示。整个模板在this gist.
"connectionParameters": {
"vaultName": {
"type": "string",
"uiDefinition": {
"displayName": "Vault name",
"description": "Name of the vault",
"tooltip": "Provide name of the vault",
"constraints": {
"required": "true"
}
}
},
"token": {
"type": "oauthSetting",
"oAuthSettings": {
"identityProvider": "aadcertificate",
"clientId": "7ab7862c-4c57-491e-8a45-d52a7e023983",
"scopes": [],
"redirectMode": "Direct",
"redirectUrl": "https://logic-apis-westeurope.consent.azure-apim.net/redirect",
"properties": {
"IsFirstParty": "True"
},
"customParameters": {
"tenantId": {},
"resourceUri": {
"value": "https://vault.azure.net"
},
"loginUriAAD": {
"value": "https://login.windows.net"
}
}
}
},
// <other input parameters>
}
但是我在哪里可以 get/find 令牌?是否有可能以某种方式使用 DevOps 用于部署基础设施的令牌?或者以任何其他非交互方式获取令牌,例如从 powershell 脚本?
任何指针将不胜感激。
我建议使用 Managed Identity (MSI) for Logic App
本质上,这将在您的 Azure Active Directory 中为应用程序创建一个身份,从而消除令牌过程。此身份在 azure 中分配了一个指纹,因此如果它被销毁并重新创建,将重新创建身份的指纹。如果通过 ARM 部署,只需将标识部分添加到您的逻辑应用程序:
{
"apiVersion": "2016-06-01",
"type": "Microsoft.logic/workflows",
"name": "[variables('logicappName')]",
"location": "[resourceGroup().location]",
"identity": {
"type": "SystemAssigned"
}
对于 Key Vault,如果通过相同的 ARM 模板部署,您可以为资源 ID 添加访问策略,如下所示(特别是 objectID 部分)。我建议使用概述的依赖语句,以便在创建 MSI 之前不会分配访问策略。
"accessPolicies": [
{
"tenantID": "[subscription().tenantId]",
"objectId": "[reference(resourceId('Microsoft.Web/sites', variables('webSiteName')), '2018-02-01', 'Full').identity.principalId]",
"permissions": {
"secrets": [
"get"
],
"keys": [
"get"
],
"certificates": [
"import"
]
},
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('WebsiteName'))]"
]
}
]
完成此操作后,您的逻辑应用应该可以访问 Key Vault 中的秘密w/o任何其他配置。
如果托管标识支持尚未添加到 Key Vault 连接器,则有一个解决方法。您可以将 HTTP 连接器与托管身份一起使用,并使用 Key Vault REST API 来获取机密。
这个博客 post 中的示例对此进行了解释:https://blog.eldert.net/retrieve-azure-key-vault-secrets-from-logic-apps-using-managed-identity/
托管身份支持已添加到 Key Vault 连接器。更多详细信息可以在以下博客中找到 post - https://aztoso.com/logic-app/keyvault-connector-with-managed-identity/
我在 DevOps 中通过 ARM 模板部署逻辑应用程序工作流,效果很好。当我需要在工作流中连接到 Blob 存储或存储队列时,我可以预先在 ARM 中创建这两个 API 连接然后使用它们,但是如何创建到 KeyVault 的连接?连接模板的(我相信只需要)连接参数是 vaultName
和 token
,如下所示。整个模板在this gist.
"connectionParameters": {
"vaultName": {
"type": "string",
"uiDefinition": {
"displayName": "Vault name",
"description": "Name of the vault",
"tooltip": "Provide name of the vault",
"constraints": {
"required": "true"
}
}
},
"token": {
"type": "oauthSetting",
"oAuthSettings": {
"identityProvider": "aadcertificate",
"clientId": "7ab7862c-4c57-491e-8a45-d52a7e023983",
"scopes": [],
"redirectMode": "Direct",
"redirectUrl": "https://logic-apis-westeurope.consent.azure-apim.net/redirect",
"properties": {
"IsFirstParty": "True"
},
"customParameters": {
"tenantId": {},
"resourceUri": {
"value": "https://vault.azure.net"
},
"loginUriAAD": {
"value": "https://login.windows.net"
}
}
}
},
// <other input parameters>
}
但是我在哪里可以 get/find 令牌?是否有可能以某种方式使用 DevOps 用于部署基础设施的令牌?或者以任何其他非交互方式获取令牌,例如从 powershell 脚本? 任何指针将不胜感激。
我建议使用 Managed Identity (MSI) for Logic App
本质上,这将在您的 Azure Active Directory 中为应用程序创建一个身份,从而消除令牌过程。此身份在 azure 中分配了一个指纹,因此如果它被销毁并重新创建,将重新创建身份的指纹。如果通过 ARM 部署,只需将标识部分添加到您的逻辑应用程序:
{
"apiVersion": "2016-06-01",
"type": "Microsoft.logic/workflows",
"name": "[variables('logicappName')]",
"location": "[resourceGroup().location]",
"identity": {
"type": "SystemAssigned"
}
对于 Key Vault,如果通过相同的 ARM 模板部署,您可以为资源 ID 添加访问策略,如下所示(特别是 objectID 部分)。我建议使用概述的依赖语句,以便在创建 MSI 之前不会分配访问策略。
"accessPolicies": [
{
"tenantID": "[subscription().tenantId]",
"objectId": "[reference(resourceId('Microsoft.Web/sites', variables('webSiteName')), '2018-02-01', 'Full').identity.principalId]",
"permissions": {
"secrets": [
"get"
],
"keys": [
"get"
],
"certificates": [
"import"
]
},
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('WebsiteName'))]"
]
}
]
完成此操作后,您的逻辑应用应该可以访问 Key Vault 中的秘密w/o任何其他配置。
如果托管标识支持尚未添加到 Key Vault 连接器,则有一个解决方法。您可以将 HTTP 连接器与托管身份一起使用,并使用 Key Vault REST API 来获取机密。
这个博客 post 中的示例对此进行了解释:https://blog.eldert.net/retrieve-azure-key-vault-secrets-from-logic-apps-using-managed-identity/
托管身份支持已添加到 Key Vault 连接器。更多详细信息可以在以下博客中找到 post - https://aztoso.com/logic-app/keyvault-connector-with-managed-identity/