这个Python脚本被部署为从Azure函数应用程序运行在Linux消费计划上,这个脚本被期望从Azure密钥库中读取机密。
除了代码部署之外,还进行了以下配置
import azure.functions as func
import os
from azure.identity import ManagedIdentityCredential
from azure.keyvault.secrets import SecretClient
def main(mytimer: func.TimerRequest) -> None:
identity = ManagedIdentityCredential()
secretClient = SecretClient(vault_url="https://vault-name.vault.azure.net/", credential=identity)
secret = secretClient.get_secret('secret-name').
print (secret.value)
azure-functions
azure-keyvault-secrets
azure-identity
Result: Failure Exception: HttpResponseError: (Forbidden) The user, group or application 'appid=6fb8XXXX-bba6-4fa7-8a76-a193XXXXd8d7;oid=e4c1XXXX-602d-44b7-a2e6-f646XXXXe360;iss=https://sts.windows.net/320bXXXX-7580-46ef-a61a-7f3fXXXXbe8f/' does not have secrets get permission on key vault 'vault-name;location=northcentralus'.
For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287 Stack:
File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py",
line 315, in _handle__invocation_request self.__run_sync_func, invocation_id, fi.func, args) File "/usr/local/lib/python3.7/concurrent/futures/thread.py",
line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py",
line 434, in __run_sync_func return func(**params) File "/home/site/wwwroot/FunctionAppName/__init__.py",
line 14, in main secret = secretClient.get_secret('secret-name') File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/tracing/decorator.py",
line 83, in wrapper_use_tracer return func(*args, **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/keyvault/secrets/_client.py",
line 71, in get_secret **kwargs File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/keyvault/secrets/_shared/_generated/v7_0/operations/_key_vault_client_operations.py",
line 1625, in get_secret map_error(status_code=response.status_code, response=response, error_map=error_map) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/exceptions.py",
line 102, in map_error raise error
此错误说明应用程序没有密钥库上的机密获取权限,但如上所述,将角色分配给在密钥库上具有阅读器角色的功能应用程序。
配置中可能出现的问题是什么?如何缓解?
为了读取机密,您实际上需要创建一个访问策略,并添加与Azure函数相关的托管标识:
我在过去为Azure函数使用了很多秘密,现在我试图使用一个密钥,RSA加密,4096位。这是一个私有的PuTTy.ppk键,我已经将其导出为。pem类型以满足Azure的要求。我有一个Python 3.7应用程序,我已经在其中部署了所需的功能,并尝试在应用程序设置中引用所需的键,下面的语句是: @microsoft.keyvault(secreturi=https://{thevault-addr
[Get-AzureKeyVaultSecret],PSInvalidOperationException FullyQualifiedErrorId:InvalidOperation,Microsoft.azure.commands.keyVault.GetAzureKeyVaultSecret 2018-04-14T17:45:00.709[Error]执行函数时出现异常:functions.
我无法从azure key vault检索到运行在azure windows VM中的.NET控制台应用程序的秘密。下面是我使用过的代码,我已经给了服务主体在密钥库中的所有权限。
理想的方法似乎是在中添加一个新的设置, 然后将逻辑添加到ParseImpl中,以便将表示秘密的KeyVault URL传递到该方法中,然后它将从那里查询密钥。 另一个选项是覆盖(以及类似的连接字符串设置),以便它查询KeyVault。