gpt4 book ai didi

azure - 如何从 Nodejs 堆栈上的 Azure Function App 中的 Azure key 保管库中提取 key

转载 作者:行者123 更新时间:2023-12-02 23:13:48 25 4
gpt4 key购买 nike

我在 Nodejs 版本 12 中创建了一个 Azure Function 应用程序。我的托管环境是 Windows。捕获保存在我的函数内的 Azure key 保管库中的用户名和密码的最简单方法是什么。另外,我正在使用内联代码编辑器,因此应该如何捕获代码中的凭据。

谢谢

最佳答案

上述答案中使用的节点 SDK 将被弃用,并且不会有新功能和版本。相反,新版本在此处发布:

https://www.npmjs.com/package/@azure/keyvault-secrets

以下是获取 secret 值的详细步骤,供您引用。

1.在您的函数中启用系统分配的托管身份。

enter image description here

2. 将此服务主体添加到您的 key 保管库的访问策略中。

enter image description here

3.安装函数的依赖项。

  "dependencies": {
"@azure/identity": "^1.0.3",
"@azure/keyvault-secrets": "^4.0.4"
}

4.这是我的测试函数代码

module.exports = async function (context, req) {

const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const keyVaultName = "tonykeyvault20190801";
const KVUri = "https://" + keyVaultName + ".vault.azure.net";

const credential = new DefaultAzureCredential();
const client = new SecretClient(KVUri, credential);

const retrievedSecret = await client.getSecret("username");
const username=retrievedSecret.value;
context.log(username);
context.res = {
body: username
};
}

5.执行结果。

enter image description here

关于azure - 如何从 Nodejs 堆栈上的 Azure Function App 中的 Azure key 保管库中提取 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62518433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com