【发布时间】:2023-03-24 21:22:02
【问题描述】:
我在 azure 中有一个 Web 应用程序,我想确保只有我的构建服务器(或同一子网中的任何其他 VM)是唯一能够访问 SCM 站点的服务器。我认为最明显的事情是创建一个访问限制规则,事实上这很有效,我可以毫无问题地从门户创建它。
但是,当我尝试使用 powershell 自动执行此操作时,就会出现问题。我的构建服务器子网位于与我的 Web 应用程序不同的订阅上。
我正在执行以下 powershell 脚本:
$subnetId = "/subscriptions/$VNETSubscriptionId/resourceGroups/$VNETResourceGroup/providers/Microsoft.Network/virtualNetworks/$buildServerVNET/subnets/$buildServerSubNet"
Add-AzWebAppAccessRestrictionRule -ResourceGroup $webAppRg -WebAppName $webAppname -Name VNETAccess -Priority 1000 -Action Allow -SubnetId $subnetId
我收到以下错误:
Add-AzWebAppAccessRestrictionRule : The client '{{my user credential}}' with object id '81fa4eb1-5553-4daa-af44-3c717b19eda2' does not have authorization to perform action 'Microsoft.Network/virtualNetworks/subnets/read' over scope '/subscriptions/{{websiteSubscriptionId}}/resour
ceGroups/{{VNETResourceGroup}}/providers/Microsoft.Network/virtualNetworks/{{buildServerVNET}}/subnets/{{buildServerSubNet}}' or
the scope is invalid. If access was recently granted, please refresh your credentials.
该错误似乎表明该 cmdlet 正在搜索与网站相同的订阅 id 上的子网,而不是子网所在的订阅,因为错误消息中返回的 resourceId 字符串有错误的订阅ID。它使用的是网站所在的位置,而不是构建服务器所在的位置。
为了通过powershell创建这个规则还需要做什么?
【问题讨论】:
标签: azure powershell azure-web-app-service azure-powershell