尝试在 Runbook 中使用托管标识创建 SQL Server 资源会产生禁止的结果

问题描述 投票:0回答:1

我正在尝试在 PowerShell Runbook 中创建 Azure SQL Server。我正在使用托管身份,我已将贡献者角色分配给我尝试在其中创建它的订阅。

这是代码行:

New-AzSqlServer -ResourceGroupName $rgName -ServerName $newServerName -Location $location -AssignIdentity -EnableActiveDirectoryOnlyAuthentication -ExternalAdminName $adminAccount

我收到这样的回复:

操作返回无效状态代码“禁止”

在有问题的线路之前,我按如下方式连接:

Disable-AzContextAutosave -Scope Process
$context = (Connect-AzAccount -Identity -AccountId "<account-client-id>").context 
Select-AzSubscription -SubscriptionId $subscriptionId
$context = Set-AzContext -SubscriptionName $context.Subscription -DefaultProfile $context

我曾经有一个更简单的版本,但在检查了 Microsoft 文档后,这是推荐的方法。当它连接时,一切似乎都就位,租户、订阅、托管身份客户端 ID...

azure azure-sql-database azure-managed-identity azure-runbook
1个回答
0
投票

我有一个名为

srimanaged
的托管身份,并在订阅下分配了 Contributor 角色,如下所示:

enter image description here

现在,我在我的自动化帐户下添加了这个托管身份

enter image description here

当我在我的环境中运行你的代码时,我得到了同样的错误,如下所示:

Disable-AzContextAutosave -Scope Process
$context = (Connect-AzAccount -Identity -AccountId "<account-client-id>").context 
$subscriptionId = "subId"
Select-AzSubscription -SubscriptionId $subscriptionId
$context = Set-AzContext -SubscriptionName $context.Subscription -DefaultProfile $context

$rgName = "Sri"
$newServerName = "sqlserver0711"
$location = "Central US"
$adminAccount = "Testuser"
New-AzSqlServer -ResourceGroupName $rgName -ServerName $newServerName -ServerVersion "12.0" -Location $location -AssignIdentity -EnableActiveDirectoryOnlyAuthentication -ExternalAdminName $adminAccount

回复:

enter image description here

要解决错误,请尝试将 User Administrator

角色分配给目录下的托管身份

转到 Azure 门户 -> Microsoft Entra ID -> 角色和管理员 -> 所有角色 -> 选择“用户管理员” -> 添加分配

enter image description here

当我分配该角色后再次运行

相同的脚本时,我得到了响应,如下所示:

Disable-AzContextAutosave -Scope Process $context = (Connect-AzAccount -Identity -AccountId "<account-client-id>").context $subscriptionId = "subId" Select-AzSubscription -SubscriptionId $subscriptionId $context = Set-AzContext -SubscriptionName $context.Subscription -DefaultProfile $context $rgName = "Sri" $newServerName = "sqlserver0711" $location = "Central US" $adminAccount = "Testuser" New-AzSqlServer -ResourceGroupName $rgName -ServerName $newServerName -ServerVersion "12.0" -Location $location -AssignIdentity -EnableActiveDirectoryOnlyAuthentication -ExternalAdminName $adminAccount

回复:

enter image description here

为了

确认,我在门户中检查了相同的内容,其中 SQL Server 创建成功,具有以下属性:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.