简体   繁体   English

Azure function 在 visual Studio 本地运行时可以访问 Key Vault 但在门户上运行时不能

[英]Azure function can access Key Vault when run locally in visual Studio but not when run on the portal

I am reading values from a key vault in an azure function. When running locally it works.我正在从 azure function 中的密钥保管库中读取值。在本地运行时它有效。 After deploying and running from the portal it give the error.从门户部署和运行后,它给出了错误。

This is how i am getting the data from key vault:这就是我从 Key Vault 获取数据的方式:

    var vaultUrl = Environment.GetEnvironmentVariable("KV_URL");
    var client = new SecretClient(vaultUri: new Uri(vaultUrl), credential: new DefaultAzureCredential());

    KeyVaultSecret graphSecret = client.GetSecret("val1");
    KeyVaultSecret tenantId = client.GetSecret("val2");
    KeyVaultSecret clientId = client.GetSecret("val3");

I have created a system assigned identity for the function in the portal and granted it read and list rights on the key vault secrets.我在门户中为 function 创建了一个系统分配标识,并授予它读取和列出密钥保管库机密的权限。

I dont have any logging set up in the function, which could possibly give more information.我没有在 function 中设置任何日志记录,这可能会提供更多信息。 Is application insights the only way to gather information from the function as it runs?应用程序洞察是从 function 运行时收集信息的唯一方法吗?

Here the Key Vault URL is defined in the local.settings.json so that you're getting that using Environment.GetEnvironmentVariable locally .这里的 Key Vault URL 在local.settings.json中定义,因此您可以在本地使用Environment.GetEnvironmentVariable获取它

When running in the Azure Portal, you have to store this Key Vault URI in the Azure Function App > Configuration > Application settings, then the same code works in Azure also .在 Azure 门户中运行时,您必须将此 Key Vault URI 存储在 Azure Function App > Configuration > Application settings 中,然后相同的代码也可以在 Azure 中运行

在此处输入图像描述

Refer here for a practical workaround.请参阅此处以获取实际的解决方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在本地运行 azure function(将数据上传到 cosmos)时,它会替换现有的 cosmos 数据吗? - When I run an azure function locally (which uploads a data to cosmos), does it replace the existing cosmos data? Web App Azure Portal - Key Vault Reference 显示未连接 - Web App Azure Portal - Key Vault Reference shows not connected 在本地运行时出现 firebase 模拟器 UI 问题 - Issue with firebase emulator UI when run locally 如何在 Visual Studio 2019 和 .NET 中的不同端口上运行 ISOLATED Azure Function 应用程序 5 隔离 - How to run ISOLATED Azure Function app on a different port in Visual Studio 2019 & .NET 5 Isolated Azure Key Vault 不允许在专用终结点连接中添加来自 azure 门户的机密 - Azure Key Vault not allow to add Secrets from azure portal while in a private endpoint connection Azure AKS/容器应用程序无法使用托管标识访问密钥保管库 - Azure AKS/Container App can't access Key vault using managed identity 在 Azure 中,公钥保管库可以管理私有存储帐户的访问密钥吗? - In Azure, can a public key vault manage access keys of a private storage account? 从 azure blob 存储(静态网站)访问 azure 密钥库 - Access azure key vault from azure blob storage (static website) 在本地运行 golang lambda 函数 - Run golang lambda function locally 通过 Azure 门户配置将 Key Vault 证书的指纹发送到服务总线主题 - Sending Thumbprint of a Key Vault Certificate to Service Bus topic through Azure Portal configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM