gpt4 book ai didi

azure - 我们可以在 ARM 部署脚本中使用 az rest 吗?

转载 作者:行者123 更新时间:2023-12-03 03:49:09 25 4
gpt4 key购买 nike

我正在使用 ARM 部署脚本 AzCli。我们可以在 ARM 部署脚本中使用 az rest 吗?我收到 Forbidden({"error":{"code":"Authorization_RequestDenied","message":"没有足够的权限来完成操作。"

最佳答案

我可以在我这边重现您的问题,这意味着您的用户分配身份 (MSI) 没有足够的权限通过租户中的 Microsoft Graph 创建 AD 应用程序。

要解决此问题,只需授予 AAD 管理员角色,例如应用程序管理员到您的 MSI 的服务主体,请按照以下步骤操作。

1.导航到门户中的 Azure Active Directory -> 角色和管理员 -> 单击应用程序管理员

enter image description here

2.点击添加分配 -> 选择成员 -> 搜索您的 MSI 名称 -> 添加它。

enter image description here

enter image description here

注意:您还可以将 Microsoft Graph 应用程序权限 Application.ReadWrite.All 授予 MSI,而不是应用程序管理员,不会的这里就不多说了,如果你有兴趣,请告诉我,我可以发布。

此外,如果您只想使用Azure CLI创建AD应用程序,实际上不需要手动使用azrest,您可以使用内置命令az ad app create直接。

测试示例:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"identity": {
"type": "string"
},
"utcValue": {
"type": "string",
"defaultValue": "[utcNow()]"
}
},
"resources": [
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "runAzureCLI",
"location": "[resourceGroup().location]",
"kind": "AzureCLI",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('identity')]": {
}
}
},
"properties": {
"forceUpdateTag": "[parameters('utcValue')]",
"AzCliVersion": "2.15.0",
"timeout": "PT30M",
"scriptContent": "landingPageApp=$(az rest --method POST --headers \"Content-Type=application/json\" --uri https://graph.microsoft.com/v1.0/applications --body '{\"displayName\": \"LandingpageAppARM\"}')",
"cleanupPreference": "OnSuccess",
"retentionInterval": "P1D"
}
}
]
}

enter image description here

enter image description here

关于azure - 我们可以在 ARM 部署脚本中使用 az rest 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67594030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com