Error creating encryption keys using vault write -f
@chrishoffman
Hey Chris, Thanks for that. I opened a new issue because I wasnt sure if you would get notified on a closed one (made a similar comment there)
Here is the latest (I want to use 12357 for the tcp port)
VAULT_ADDR="http://127.0.0.1:12357" VAULT_TOKEN="c5b8be1c-30d2-e5ce-cced-0a0eeb59cf5f" --> from cat $HOME/.vault_token
cat config.hcl storage "file" { path = "/home/ubuntu/vaultdata" }
disable_mlock=true
listener "tcp" { address = "127.0.0.1:12357" tls_disable = 1 }
ubuntu@penguin:~$ vault write -f secret/hello Error writing data to secret/hello: Error making API request.
URL: PUT http://127.0.0.1:12357/v1/secret/hello Code: 400. Errors:
** missing data fields**
Then when I try the same with sudo, I get a different error for port 8200 instead of 12357. sudo vault write -f secret/hello Error writing data to secret/hello: Put https://127.0.0.1:8200/v1/secret/hello: dial tcp 127.0.0.1:8200: getsockopt: connection refused @RohanKurane
Attach files by dragging & dropping,
, or pasting from the clipboard. Styling with Markdown is supported
perhaps 'vault write -f" is not supported for the kv secrets engine ?
I enabled a transit secrets engine
vault secrets enable -path=transit transit
vault write -f transit/keys/my-key Success! Data written to: transit/keys/my-key
When I do a read vault read transit/keys/my-key
The key is not listed (I assume because its an encrypted key). How do I read the encryption key 'my-key' generated above ?
vault read transit/keys/my-key
Key Value
allow_plaintext_backup false deletion_allowed false derived false exportable false keys map[1:1520061706] latest_version 1 min_decryption_version 1 min_encryption_version 0 name my-key supports_decryption true supports_derivation true supports_encryption true supports_signing false type aes256-gcm96
So kv secrets engine writes secrets using vault write and the transit engine uses vault write -f ? What is the difference here ?
When you write to secret/hello, Vault is expecting input data to encrypted and then stored there. That's why vault write -f doesn't work -- you're not passing any data to be encrypted.
The transit engine operates differently. When you write to transit/keys/my-key, you're telling Vault to generate a brand new encryption key called my-key. You can then encrypt information by writing it to transit/encrypt/my-key -- that's analogous to writing to secret/hello, except that in the transit engine, Vault doesn't store it and instead just returns the encrypted data back to you.
Vault won't return the actual key material when reading from transit/keys/my-key, and it sounds like that's what you're expecting. If you want the actual key material, you'll need to flag the key as exportable/backup-able when creating the key or updating the key then use the export or backup method -- however, I strongly advise against doing this unless you really need to. There's a lot of security benefit in knowing that the key material has never left Vault -- it forces any decryptions to go through Vault, which is logged and auditable, and access can be controlled and revoked.
Also, RE:
Then when I try the same with sudo, I get a different error for port 8200 instead of 12357. sudo vault write -f secret/hello Error writing data to secret/hello: Put https://127.0.0.1:8200/v1/secret/hello: dial tcp 127.0.0.1:8200: getsockopt: connection refused
That's because sudo drops a bunch of environment variables by default, and so it's dropping your VAULT_ADDR environment variable, causing the Vault client to default to https://12.0.0.1:8200
However, there's virtually no reason why running under sudo would make a difference in this case -- the Vault CLI essentially just does a bunch of HTTP commands for you to the Vault API, and running under sudo wouldn't really change anything in what Vault sees.
@joelthompson Thanks Joel. I have a few questions (labelled A thru G) below that I need help with if you can.
- The 'kv' secrets engine needs data (key=value) on the write command. This will encrypt the data (value) and store encrypted data in the storage backend.
A. What is the secret used here by the kv engine ? I assume it is 'key' here and is stored at path secret/hello in this case ? ( vault write secret/hello key=value ). If it is, then kv engine is a static secret engine i.e does not generate secrets on the fly ?
B. Is the secret ('key') written to the storage backend as well (or by doing exportable=true if I want to write to a storage backend) ?
C. Or maybe I am confusing the keys, secrets and encryption keys terminology here. Can you please help clarify ?
The 'transit' secrets engine generates a new encryption key (using -f flag). Then when you do a vault write to it, the transit engine encrypts the data using the encryption key generated and returns the encrypted data back to user. It does not store the encrypted data. Correct ?
- No need to run under sudo. Without sudo my port 12357 should be honored as in the config.hcl file.
I have some absolute basic questions regarding how Vault works with its secret engine and storage backend. Can you please help clarify ?
Secrets engine are the ones that create, update, delete secrets. There are a bunch of secrets engine currently supported by Vault including kv, transit, AWS etc).
Storage backend is where the secrets, encrypted data etc are stored. There are a bunch of built-in storage backends supported by Vault including filesystem, AWS, Database etc.
I am trying to integrate Vault with my application. My application provides a storage backend. The storage backend is really a directory on local disk.
D. I assume I can use storage: "file" as my backend so all secrets and encrypted data gets written to that directory on disk ?
E. So essentially doing a 'vault write secret/hello day=Sunday' will store the encrypted data to the directory created by my application (as specified by path in the config.hcl file). Again what encryption key is used here by the kv engine and will it be stored along with the encrypted data in the local disk directory ?
F. In case of AWS which generates dynamic secrets, are the secrets written to the backend storage as well ?
G. Or do I need to look into the 'plugin storage backend' section to add my local disk directory ?
Closing this; it's both old and the vast majority of the questions are already answered by simply reading documentation.