Search code examples
c#vaulthashicorpvaultsharp

Vaultsharp : System.AggregateException: 'One or more errors occurred. ({"errors":["no handler for route 'kv-v2/data'


Can not seem to get pass this error. hashicorp vault is running on my k3s env. I can get to the vault UI fine. I can also curl vault [POST, GET] using the following :

curl --location --request POST 'http://192.168.8.110:31476/v1/niv/data/foo' 
--header 'X-Vault-Token: myroot' 
--header 'Content-Type: application/json' 
--data-raw '{
  "options": {
    "cas": 0
  },
  "data": {
    "foo": "bar",
    "zip": "zap"
  },
  "versions": [4]
}'
curl --location --request GET 'http://192.168.8.110:31476/v1/niv/data/foo?version=1' --header 'X-Vault-Token: myroot'

The above curl works fine.

When I try and run the below code using .net 5, I get the following exception even though the path is correct

using VaultSharp;
using VaultSharp.V1.AuthMethods;
using VaultSharp.V1.AuthMethods.Token;
IAuthMethodInfo authMethod = new TokenAuthMethodInfo("myroot");
var vaultClientSettings = new VaultClientSettings("http://192.168.8.110:31476/", authMethod);
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
var secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync("niv/data/foo").Result.Data;

I get the following exeception:

VaultApiException: {"errors":["no handler for route 'kv-v2/data/niv/data/foo'"]}


Solution

  • the path was wrong, the below path works fine

    var vaultSecrets = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync("/settings", 2, "niv").Result.Data.Data["name"];