python - 如何使用 Azure Cloud Function (python) 中的用户管理身份向 Azure KeyVault 发出请求?

标签 python azure azure-functions azure-managed-identity azure-function-app

我当前的设置:

我的 DevOps 人员已创建用户管理身份并将其添加到 Azure key 保管库的访问策略中。
我创建了一个函数应用 testing-01 并在平台设置下为其分配了 User-ManagedIdentity。
我使用 Python 3.6 作为运行时语言。

这是我的辅助方法,我用它来检查是否能够从 key 保管库访问 secret 。 我正在回复它的回复。

def cred_checker():
    credential = ManagedIdentityCredential()
    # credential = ManagedIdentityCredential(client_id='client_id 
    vault_name= "myvault"
    client = SecretClient(vault_url=f"https://{vault_name}.vault.azure.net/", credential=credential)
    username = client.get_secret(name="username")
    password= client.get_secret(name="password")

    return f"AKV client created successfully {client} .<br> name: {username},<br> pass: {password} " 

我能够毫无错误地创建客户端。但是当我尝试从中获取 secret 时,我收到此 ClientAuthenticationError :

Exception while executing function: Functions.HttpTriggerFunc <--- Result: Failure Exception: ClientAuthenticationError: Unexpected response '{'statusCode': 400, 'message': 'Unable to load requested managed identity.', 'correlationId': '92daf146-fed2-4a75-8359-9r955939815e'}'

最佳答案

当您使用用户分配的身份时,您需要指定 client_id ManagedIdentityCredential() 中的 MSI .

credential = ManagedIdentityCredential(client_id="xxxxxxxx")

要获取 client_id,请导航到您的函数应用 -> Identity -> 用户分配 -> 单击您的用户分配的身份 -> 复制 client_id

enter image description here

关于python - 如何使用 Azure Cloud Function (python) 中的用户管理身份向 Azure KeyVault 发出请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58765739/

相关文章:

azure - 每当将图像添加到另一个容器中时,触发Azure Function App创建容器

azure - 无法引用 Azure Functions 中的 Polly 或其他包

Python Zip 文件,通配符

azure - Blob 存储中的空图像

azure - 为什么w3wp内存不断增加?

azure - 创建 SSL 证书时出现意外错误 : certificate and private key does not have a matching public key: tls: private key does not match public key

python - 为什么我不能在某个时刻评估 SymPy 中实现的函数的组合?

python - 如何从 Python 的字典列表中删除基于选定键的重复字典?

python - 在 openshift 上的 Bottle.py 应用程序中加载静态文件

azure-functions - 创建 Sendgrid 帐户时部署验证失败