vault icon indicating copy to clipboard operation
vault copied to clipboard

Error creating Encryption Key using vault write -f

Open RohanKurane opened this issue 8 years ago • 5 comments

I am trying to create a new encryption key using vault write -f secret/hello

I get the following error Error writing data to secret/hello: Put https://127.0.0.1:8200/v1/secret/hello: http: server gave HTTP response to HTTPS client.

My config file has tls_disabled

I am using a file path as my storage backend.

vault version: 0.9.5

Another side question - when I write a secret using vault write secret/hello name=rohan

where does the secret get stored in my directory path specified in config.hcl ?

RohanKurane avatar Mar 03 '18 03:03 RohanKurane

The default address for the CLI uses https. You need to set the environment variable to http. See https://www.vaultproject.io/docs/commands/index.html#vault_addr.

export VAULT_ADDR=http://localhost:8200/

As for storage, the secrets will be stored under the path logical/ with a unique UUID to identify the mount at the secret's path.

chrishoffman avatar Mar 03 '18 03:03 chrishoffman

@chrishoffman Hey Chris, Thanks for that. 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 avatar Mar 03 '18 06:03 RohanKurane

@RohanKurane vault write -f <args> is meant only for those endpoints in which the arguments are optional. For the kv store, the arguments are not optional and hence the error.

Then when I try the same with sudo, I get a different error for port 8200 instead of 12357.

sudo, by design, doesn't pick up the environment variables of the calling shell and hence the CLI falls back to its default address.

vishalnayak avatar Mar 05 '18 12:03 vishalnayak

Thanks @vishalnayak

If you dont mind, I had a few questions for you if you could help answer and point me in the right direction -

  1. A vault server is started using the config.hcl file. Vault is then initialized and the unseal keys and root token are generated. The keys are used to unseal Vault and the root token is used to login the root and authenticate. I set VAULT_TOKEN=root_token and VAULT_ADDR=http://127.0.0.1:8200 Vault is now open to accept HTTP or CLI requests.

  2. Lets suppose my config.hcl file has a storage stanza of storage "file" { path = "/home/ubuntu/vaultdata" }

I use the kv secrets engine to write a secret at path secret/hello with key (day) and value (good). vault write secret/hello day=good

Question - where is this secret (key/value pair) written to and stored ? Is it written to the "path" above ? If so, in what directory (/logical ?) and how is it stored ? Is each secret stored in a separate file ? If I do a ls of the above "path/logical" I see something like this - ls ~/vaultdata/logical/ b610d7d5-c652-3c0a-e8a4-3e81f4ad7719 f3cd55a0-7139-5f25-1abd-79ae3f50fd2c

  1. Next I use AWS as a secrets engine to generate dynamic secrets and keep the backend storage the same as above. I get something along these lines -

vault read aws/creds/my-roleKey Value


lease_id aws/creds/my-role/37d0ac5b-0e5e-d2ec-5b01-d7d04a0443c2 lease_duration 768h lease_renewable true access_key AKIAJ7FDDSGVZJE5X45Q secret_key 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 security_token

Question: The access_key and secret_key are used for future access and lease_id can be used to revoke, renew lease. This information is returned back to client (for CLI and HTTP requests). Is this information also stored in the storage backend ? If yes, where and how is it stored ? If it is not stored in the backed, what is the backend storage here used for ?

  1. Question: When the client (via CLI or HTTP) sends a request to the Vault server, the vault server creates, reads, updates or deletes the secret. When does the server communicate with the storage backend ? And in what format does it store the secrets on the backend ?

I would really appreciate your help on these questions.

RohanKurane avatar Mar 06 '18 02:03 RohanKurane

Where is this secret (key/value pair) written to and stored?

All the data which Vault intends to persist will be stored in the configured storage backend. Each secret engine will have a respective directory for its contents. As you noted, it will be under vaultdata/logical. One of those directories represent the kv store. Each secret will be persisted under its directory as a separate file. The data supplied for each secret will be JSON encoded and encrypted (by default, aes256-gcm96) before persisting.

The access_key and secret_key are used for future access and lease_id can be used to revoke, renew lease. This information is returned back to client (for CLI and HTTP requests). Is this information also stored in the storage backend? If yes, where and how is it stored? If it is not stored in the backed, what is the backend storage here used for?

Vault stores just enough information for it to be able to revoke the secrets later. In the case of AWS secrets engine, a new username is created and the access_key/secret_key pair is generated against that username. Vault stores this username. This information will be stored as part of the secret's lease. The path for that is sys/expire/id/....

When the client (via CLI or HTTP) sends a request to the Vault server, the vault server creates, reads, updates or deletes the secret. When does the server communicate with the storage backend? And in what format does it store the secrets on the backend?

Whenever required :-). The format is always JSON.

Hope this helps!

vishalnayak avatar Mar 06 '18 13:03 vishalnayak