Basics of Hashicorp Vault
Starting Vault server
Most documentations give an example of using Hashicorp Consul / AWS S3 / GCS storage as the backend of Vault server. But vault server could also run with local file system as its backend.
Config used to start the server : config.hcl
|
|
Make sure that the path /mnt/vault/
is owned / accessible by the Linux user which is used to host Vault server.
Do NOT start vault server with sudo permission. It’s a security best practice. That is why disable_mlock
in the config is set to true. If not, then the server needs sudo permission to run.
To start the server use the following command (config.hcl
contains the above content) :
|
|
Initializing Vault
Check if the command vault status works. If no, then debug the network connection.
Initialize the vault using the following command
|
|
The above command will create 5 unseal tokens in which any 3 should be used every time to unseal vault.
To initialize with a single unseal token, use
|
|
In both the above commands you would get a initial root token along with unseal token(s).
Vault is sealed by default. Unseal it using the unseal tokens.
|
|
It prompts for unseal token. Enter the unseal token which you got when initializing vault server. By default, you have to execute the command 3 times and provide 3 different unseal tokens.
How to login to Vault server from client
|
|
Enter the root token when prompted
How to revoke root token
Do not worry. Root tokens can be regenerated. But you should have unseal token with you to regenerate root token.
Login to vault using vault login and provide the root token. To delete the root token:
|
|
How to generate vault root token
Generate OTP
|
|
Use the generated OTP with the following command. In use the OTP y6fqSf9uen3JGBbB0t0Examp13
as example.
|
|
You would require unseal token for the next command. Enter the unseal token when prompted.
|
|
If the above command is successful, you would get a new “Encoded Token”. Let’s say the encoded token is ChgAHgE/DDlSKEozLSgqIQBaDShaHdOtio4
. For the next command pass both the generated OTP and the encoded token.
|
|
This is give the new root token. Use vault login to login as root with the new user token.
Create Vault server audit logs
Create a log file (/var/log/vault_audit.log) and make sure it’s accessible by the Linux user account which is used to host vault server.
|
|
Enable audit logging
|
|
Other Useful Resources
- Vault’s website: https://www.vaultproject.io/
- Vault Audit Logs: https://www.vaultproject.io/docs/audit/