Get-AzureKeyVaultSecret:操作返回无效状态代码 'Forbidden'
Get-AzureKeyVaultSecret : Operation returned an invalid status code 'Forbidden'
我有代码试图获取 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
我在我的网站上使用您的代码进行了测试,效果很好。
根据您提供的描述和错误消息,我假设您可能没有完全许可您的 Azure Key Vault。您可以参考以下步骤进行故障排除。
1.Add Azure AD 中的新应用注册。然后我们可以从Azure Portal获取tenantId, appId, secretKey,请参考这个article.
2.Add 对已注册应用的 "Key Vault" 权限。
3.In Key Vault 通道,您需要Add policies
到您注册的应用程序或用户。在 Access Control
中,您需要 add permission
到您注册的应用程序或用户。
更多细节,你可以参考这个。
最近导致 'Forbidden' 错误的另一个原因是您启用了 防火墙和虚拟网络 功能,但没有启用 "Allow trusted Microsoft services to bypass this firewall?" 选项,可在此处找到:
- 登录 Azure 门户
- 导航到您的 Key Vault
- 来自设置、select 防火墙和虚拟网络
- 向下滚动到标题为 Exception
的部分
确保您的 Azure CLI /Client public IP 允许 Key Vault 网络防火墙访问相关的 Key Vault(Azure Key Vault;网络;防火墙;IPv4 地址或 CIDR)以及具有权限update/modifying 密钥库。
通过使用确定您的 CLI public IP:
(Invoke-WebRequest -Uri https://myexternalip.com/raw -UseBasicParsing).Content
我有代码试图获取 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
我在我的网站上使用您的代码进行了测试,效果很好。
根据您提供的描述和错误消息,我假设您可能没有完全许可您的 Azure Key Vault。您可以参考以下步骤进行故障排除。
1.Add Azure AD 中的新应用注册。然后我们可以从Azure Portal获取tenantId, appId, secretKey,请参考这个article.
2.Add 对已注册应用的 "Key Vault" 权限。
3.In Key Vault 通道,您需要Add policies
到您注册的应用程序或用户。在 Access Control
中,您需要 add permission
到您注册的应用程序或用户。
更多细节,你可以参考这个
最近导致 'Forbidden' 错误的另一个原因是您启用了 防火墙和虚拟网络 功能,但没有启用 "Allow trusted Microsoft services to bypass this firewall?" 选项,可在此处找到:
- 登录 Azure 门户
- 导航到您的 Key Vault
- 来自设置、select 防火墙和虚拟网络
- 向下滚动到标题为 Exception 的部分
确保您的 Azure CLI /Client public IP 允许 Key Vault 网络防火墙访问相关的 Key Vault(Azure Key Vault;网络;防火墙;IPv4 地址或 CIDR)以及具有权限update/modifying 密钥库。
通过使用确定您的 CLI public IP:
(Invoke-WebRequest -Uri https://myexternalip.com/raw -UseBasicParsing).Content