Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vault (HashiCorp) - curl equivalent of "vault read"

Small question regarding Hashicorp Vault please.

I have a secret in Vault, under cubbyhole/mytestkey

If I log in to the web UI, I can see the key mytestkey and its value under cubbyhole

If I use the Vault CLI, running vault read /cubbyhole/mytestkey, I do get the result.

vault read /cubbyhole/mytestkey
Key     Value
---     -----
mytestkey    mytestvalue

However, when I use via curl (The token should be correct, since I used it to connect to Vault web UI), I get:

curl -vik -H "X-Vault-Token: token" https://remote-vault/cubbyhole/mytestkey
HTTP 404

May I ask what is the issue with my curl command? A path issue? And the correct one would be?

Thank you

like image 465
PatPatPat Avatar asked Oct 20 '25 11:10

PatPatPat


2 Answers

Spend hours trying to figure out how to get the correct URL.

My key/values are stored in kv / myapp / database

Key         value 
server      10.10.10.1

To get the CURL url use -output-curl-string flag.

vault kv get -output-curl-string -mount=kv -field=server myapp/database

Result

curl -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" http://vaultserver.dev:8200/v1/kv/data/myapp/database

source: https://discuss.hashicorp.com/t/kv-secrets-engine-via-curl/30629

like image 76
JenonD Avatar answered Oct 22 '25 03:10

JenonD


Your REST API endpoint is missing the port and the version of the API. You can update it to:

curl -vik -H "X-Vault-Token: token" https://remote-vault:8200/v1/cubbyhole/mytestkey

and modify the port if running on the non-default 8200.

You can find more information in the relevant documentation.

like image 41
Matt Schuchard Avatar answered Oct 22 '25 04:10

Matt Schuchard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!