- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要读取 Azure Active Directory 中的用户列表。客户已经创建了一个 Graph API 应用程序,但他们不想共享该应用程序的客户端 key ,而是要求我们使用 Key Vault。如何从 Node.js 应用程序访问 key 来检索用户列表?
我尝试了以下方法,但出现错误,并且我不知道如何进行身份验证。
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new DefaultAzureCredential();
const vaultName = "lsm-keyvault";
const url = `https://${vaultName}.vault.azure.net`;
const client = new SecretClient(url, credential);
const secretName = "Demo";
async function main() {
const result = await client.setSecret(secretName, "MySecretValue", {
enabled: false
});
console.log(result)
}
最佳答案
好吧,如果您在本地运行代码,DefaultAzureCredential
将自动使用环境变量。
因此,就您而言,您需要 register an application with Azure AD ,并得到 tenant id
, client id(i.e. application id)
, client secret(i.e. application secret)
,设置environmental variables , AZURE_CLIENT_ID
, AZURE_CLIENT_SECRET
,和AZURE_TENANT_ID
.
对于您遇到的 403 错误,我注意到您说 It added as a compound entity
,根据我的经验,您没有将与AD App相关的正确服务主体正确添加到 Access policies
的 keystore 。如果添加正确,它将显示为 APPLICATION
,不是COMPOUND IDENTITY
.
所以当你添加它时,你可以搜索 client Id(i.e. application Id)
或the name of your App Registration
直接,确保添加正确的。我在这个similar issue中给出了详细信息,你可以引用一下。
致retrieve the secret ,Get
权限足够了,代码应该是
const retrievedSecret = await client.getSecret(secretName);
我注意到你使用 client.setSecret
在您的代码中,它用于 save a secret ,要使用它,您可能需要Set
许可。
更多详情,请参阅 Quickstart: Azure Key Vault client library for Node.js (v4) .
更新:
I have to eventually need to deploy this but not in azure but in another environment. How do I set the environment variables and access it.
如果是这样,您需要更改代码进行身份验证,直接在代码中使用这三个值。
更改行
const { DefaultAzureCredential } = require("@azure/identity");
const credential = new DefaultAzureCredential();
至
const { ClientSecretCredential } = require("@azure/identity");
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
参见 - https://www.npmjs.com/package/@azure/identity/v/1.0.3#authenticating-as-a-service-principal
关于node.js - 使用nodejs从Azure Keyvault获取Secret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63343346/
我正在尝试找到某种方法将我的证书从一个 Azure 订阅中的 Key Vault 移动到另一个 Azure 订阅。有没有办法这样做> 最佳答案 下面是一种移动 Azure Key Vault 中创建的
在 ARM 模板中,我想在预先存在的 KeyVault 中写入一个 secret - 我尚未将其创建为当前模板的一部分。 我正在使用此代码 { "dependsOn": [
我在 VSTS 中使用以下 Azure Powershell 命令。 (Get-AzureKeyVaultSecret -vaultName "debugkv" -name "CoreConfig-S
这两个库似乎有相似的目的:安全地存储和控制对 token 、密码、API key 和其他 secret 的访问。 我一直在使用 Microsoft.Azure.KeyVault 并取得了一些成功,不是
我最近开始将 Microsoft.Azure.KeyVault 命名空间中的旧 Azure KeyVault 客户端替换为 Azure.Security.KeyVault 中的新客户端。 在获取 se
我最近开始将 Microsoft.Azure.KeyVault 命名空间中的旧 Azure KeyVault 客户端替换为 Azure.Security.KeyVault 中的新客户端。 在获取 se
我目前正在使用 Azure SDK for Go。一切都很顺利,直到我遇到以下问题: keyVault, err := client.Get(context.Background(), "NAME_O
我正在 Azure 中部署虚拟机。用户名和密码是自动创建的,并在部署时作为参数传递。部署虚拟机的资源组也作为参数传递,因此可以是任何内容。 我的Keyvault位于特定资源组中,虚拟机的用户名和密码应
这是一个与 keyvault 相关的问题。我在 keyvault 中存储了 pfx 证书(带有私钥)。从我的服务主体中,我尝试访问 keystore 以获取证书。我正在编写以下代码来检索 pfx 证书
我正在尝试配置 Key Vault 值的定期刷新。我由 Visual Studio 生成的原始代码如下所示 var keyvaultEndpoint = new Uri($"https://{vaul
我正在尝试配置 Key Vault 值的定期刷新。我由 Visual Studio 生成的原始代码如下所示 var keyvaultEndpoint = new Uri($"https://{vaul
我使用下面的代码从 Azure Key Vault 获取证书 private X509Certificate2 GetClientCertificate(string thumbprint)
我使用下面的代码从 Azure Key Vault 获取证书 private X509Certificate2 GetClientCertificate(string thumbprint)
创建新的 KeyVault 时出现以下错误 The subscription is not registered to use namespace 'Microsoft.KeyVault' 对于所有其
我们最近发现自己需要将每个 secret (名称和值)从一个 Azure KeyVault 复制到新创建的一个。我找到了从备份中恢复 secret 的方法,但我们没有备份。是否有一个 Powershe
我正在使用 .net core 2.1 和 OpenIdConnect 以及以下 AccessPolicies 创建 azure keyvault AccessPolicies = new List
与 Azure CLI一个使用 az keyvault secret 显示 读取 secret 值。 Azure Powershell/Az.KeyVault是怎么做到的? ? 我已尝试GetAzKe
与 Azure CLI一个使用 az keyvault secret 显示 读取 secret 值。 Azure Powershell/Az.KeyVault是怎么做到的? ? 我已尝试GetAzKe
2 个不同的租户(租户 A 中的订阅 A 和租户 B 中的订阅 B) 我们在 Azure 云中有一个订阅,并且我们已经设置了 Azure Keyvault。我们可以在那里创建 key 并使用其中一个
只是想知道如何使用新的 Azure.Security.KeyVault 库实现相同的目标: Azure.Security.KeyVault.Certificates https://learn.mic
我是一名优秀的程序员,十分优秀!