2

I have a Vault server running:

$ vault server --dev --dev-root-token-id="00000000-0000-0000-0000-000000000000"
$ export VAULT_ADDR=http://127.0.0.1:8200

The Spring artifact has the spring-cloud-starter-vault-config maven dependency. When using VaultTemplate, it writes and reads secrets without problem using the following methods:

VaultKeyValueOperations keyValue = vaultOperations
                    .opsForKeyValue("secret", VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
            keyValue.put("myPath", mySecretsObject);

and

VaultResponse response = vaultOperations
                    .opsForKeyValue("secret", VaultKeyValueOperationsSupport.KeyValueBackend.KV_2).get("myPath");

But, if I use write and read methods it throws errors:

vaultOperations.write("secret/myPath", mySecretsObject);

returns

{ "timestamp": "2019-11-19T18:22:52.156+0000", "status": 500, "error": "Internal Server Error", "message": "Status 404 Not Found [secret/myPath]: {\"request_id\":\"23062c09-f9cf-f170-930c-e6d60f98dd62\",\"lease_id\":\"\",\"renewable\":false,\"lease_duration\":0,\"data\":null,\"wrap_info\":null,\"warnings\":[\"Invalid path for a versioned K/V secrets engine. See the API docs for the appropriate API endpoints to use. If using the Vault CLI, use 'vault kv put' for this operation.\"],\"auth\":null}; nested exception is org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found", "path": "/vault/secrets/mySecrets" }

And for

VaultResponse response= vaultOperations.read("secret/" + environment);
            String stringResp = response.getData().toString();

response is null. There is no error for the read, but I get NullPointerException when trying to read response, as it is empty.

I have found a question related to the write error -Vault error while writing - but it's in the context of the Vault CLI. Can't find how to apply the solution in a Spring environment.

EMC
  • 95
  • 3
  • 11

1 Answers1

0

Spring Cloud Vault adds the data/ context between the mount path and the actual context path, have look: How to read Vault kv with java/spring boot

Try: "secret/data/myPath" where secrets is your Secret engine type kv

chomar.c
  • 61
  • 5