我需要从 keyvault 中检索秘密。到目前为止,这是我的代码:
from azure.mgmt.keyvault import KeyVaultManagementClient
from azure.common.credentials import ServicePrincipalCredentials
subscription_id = 'x'
# See above for details on creating different types of AAD credentials
credentials = ServicePrincipalCredentials(
client_id = 'x',
secret = 'x',
tenant = 'x'
)
kv_client = KeyVaultManagementClient(credentials, subscription_id)
for vault in kv_client.vaults.list():
print(vault)
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
msrestazure.azure_exceptions.CloudError:Azure 错误:AuthorizationFailed 消息:对象 ID 为“x”的客户端“x”无权在范围“/subscriptions/x”上执行操作“Microsoft.Resources/subscriptions/resources/read”。
现在我可以使用 C# 代码/ POwershell 使用相同的凭据访问相同的 keyvault,因此授权肯定没有问题。不知道为什么它不能使用 SDK 工作。请帮忙。