Get-AzureKeyVaultSecret:操作返回了无效的状态码“禁止”

时间:2018-08-21 11:08:02

标签: azure powershell azure-active-directory azure-powershell

我有一些代码,试图获取azurevaultsecret并将其秘密保存在一个变量中。在运行代码时,我得到禁止的错误。请分享宝贵的解决方案。

   $ssAADKey = ConvertTo-SecureString $AADKey -AsPlainText -Force
$psCredential = New-Object System.Management.Automation.PSCredential($AADAppID, $ssAADKey)
Connect-AzureRmAccount -ServicePrincipal -Credential $psCredential -TenantId $TenantId
$myApp = Get-AzureADApplication -Filter "DisplayName eq '$($AppName)'"  -ErrorAction SilentlyContinue

$Secrets   = Get-AzureKeyVaultSecret -VaultName "TestVault1" -name "TestSecret1" -ErrorAction Stop
$password =$Secrets.SecretValueText

3 个答案:

答案 0 :(得分:2)

我在您的网站上测试了您的代码,效果很好。

根据您提供的描述和错误消息,我认为您可能不会完全授权您的Azure Key Vault 。您可以参考以下步骤进行故障排除。

1。在Azure AD中添加新的应用程序注册。然后,我们可以从Azure门户获取tenantId,appId,secretKey,请参阅此article

2。使用“ Key Vault”向已注册的应用添加权限。 enter image description here

3。在Key Vault通道中,您需要Add policies到注册的应用程序或用户。在Access Control中,您需要add permission到您注册的应用程序或用户。 enter image description here enter image description here

有关更多详细信息,您可以参考此SO thread

答案 1 :(得分:0)

最近一次导致“禁止”错误的原因是您启用了防火墙和虚拟网络功能,并且尚未启用“允许受信任的Microsoft服务绕过此功能”防火墙?” 选项,可在此处找到:

  1. 登录 Azure门户网站
  2. 导航到您的密钥保险库
  3. 设置中,选择防火墙和虚拟网络
  4. 向下滚动到标题为 Exception
  5. 的部分

答案 2 :(得分:0)

确保您的 Azure CLI /客户端公共 IP 除了有权更新/修改密钥外,还允许 Key Vault 网络防火墙访问相关密钥保管库(Azure Key Vault;网络;防火墙;IPv4 地址或 CIDR)保险库。

通过使用确定您的 CLI 公共 IP:

(Invoke-WebRequest -Uri https://myexternalip.com/raw -UseBasicParsing).Content