我正在运行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-config
maven依赖性。
使用VaultTemplate时,它可以使用以下方法毫无问题地写入和读取机密:
VaultKeyValueOperations keyValue = vaultOperations
.opsForKeyValue("secret",VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
keyValue.put("myPath",mySecretsobject);
和
VaultResponse response = vaultOperations
.opsForKeyValue("secret",VaultKeyValueOperationsSupport.KeyValueBackend.KV_2).get("myPath");
但是,如果我使用write
和read
方法,则会引发错误:
vaultOperations.write("secret/myPath",mySecretsobject);
返回
{ “ timestamp”:“ 2019-11-19T18:22:52.156 + 0000”, “状态”:500, “错误”:“内部服务器错误”, “消息”:“状态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文档以获取有关 适当的API端点来使用。如果使用Vault CLI,请使用'vault \“],\” auth \“:null};嵌套的异常是 org.springframework.web.client.HttpClientErrorException $ NotFound:404 未找到”, “ path”:“ / vault / secrets / mySecrets”}
还有
VaultResponse response= vaultOperations.read("secret/" + environment);
String stringResp = response.getData().toString();
response
为空。读取没有错误,但是尝试读取NullPointerException
时得到response
,因为它为空。
我发现了与写入错误有关的问题-Vault error while writing-但这是在Vault CLI的上下文中。找不到如何在Spring环境中应用该解决方案。