Spring Vault VaultTemplate.read() returns null



我有一个正在运行的Vault服务器:

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

Spring工件具有spring-cloud-starter-vault-configmaven依赖关系。当使用VaultTemplate时,它可以使用以下方法毫无问题地写入和读取机密:

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

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

但是,如果我使用writeread方法,它会抛出错误:

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

返回

{"时间戳":"2019-11-19T18:22:52.156+0000","状态":500,"error":"内部服务器错误","message":"状态404未找到[secret/myPath]:{\"request_id\":\"23062c09-f9cf-f170-930c-e6d60f98dd62\",\"lease_id\":\"\",\"可再生\":false,\"lease_duration\":0,\"data\":null,\"wrap_info\":null,\"warnings\":[\"版本的K/V机密引擎的路径无效。有关使用适当的API端点。如果使用Vault CLI,请使用"Vaultkv投入运行\"],\"auth\":null};嵌套异常为org.springframework.web.client.HttpClientErrorException$NotFound:404找不到","path":"/vulture/secrets/mySecrets"}

对于

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

response为空。读取没有错误,但我在尝试读取response时得到NullPointerException,因为它是空的。

我发现了一个与写入错误有关的问题—写入时出现Vault错误—但它是在Vault CLI的上下文中出现的。找不到如何在Spring环境中应用该解决方案。

Spring Cloud Vault在装载路径和实际上下文路径之间添加数据/上下文,请查看:如何使用java/spring-boot 读取Vault kv

尝试:"secret/data/myPath"其中secrets是您的秘密引擎类型kv

最新更新