我收到错误使用 C# 中的 VaultSharp 库从 Vault 服务请求机密时发送请求时出错。我可以从命令行获取我需要的访问令牌,因此我知道 Vault 地址和我的个人 Vault 令牌工作。
CLI 依赖于环境变量 VAULT_ADDR、VAULT_TOKEN 和 VAULT_CACERT。我看到 VaultSharpVaultClientSettings
使用前两个创建对象:地址和令牌信息——但我可以在 VaultSharp 的哪个位置指定 CA 证书路径?
这是我正在使用的代码,从https://github.com/rajanadar/VaultSharp/blob/master/README.md复制:
string vaultToken = Environment.GetEnvironmentVariable("VAULT_TOKEN");
VaultSharp.V1.AuthMethods.IAuthMethodInfo authMethod = new VaultSharp.V1.AuthMethods.Token.TokenAuthMethodInfo(vaultToken);
string vaultAddress = Environment.GetEnvironmentVariable("VAULT_ADDR");
var vaultClientSettings = new VaultSharp.VaultClientSettings(vaultAddress, authMethod);
VaultSharp.VaultClient vaultClient = new VaultSharp.VaultClient(vaultClientSettings);
string vaultRoute = Properties.Settings.Default.VaultRoute;
VaultSharp.V1.Commons.Secret<VaultSharp.V1.Commons.SecretData> kv2Secret = await vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(vaultRoute);
正是这最后一条语句ReadSecretAsync
引发了错误。
非常感谢您的帮助!