Install Hashicorp Vault on a Credit Card Sized Computer - RaspberryPi
by Ashwani Kumar
-
-
posted in
Technical
|
Tagged as
security,hashicorp,vault
| Comments
We want to discuss about one of growing secret service, which can be used with most of cloud services and DevOps tools.
In this guide, will explain about How to Setup HashiCorp Vault on RaspberryPi.
In this blog, we're using the filesystem backend to store encrypted secrets on the local filesystem at ~/Hashicorp/vault-data.
This is suitable for local or single-server deployments that do not need to be replicated. This is not suitable for HA Setup.
Vault is an open-source tool that provides a secure, reliable way to store and distribute secrets like API keys, access tokens, and passwords. Software like Vault can be critically important when deploying applications that require the use of secrets or sensitive data.
To download latest vault package, Go to Hashicorp vault downloads page and download the latest package.
I am using this:
Finally, set a Linux capability flag on the binary. This adds extra security by letting the binary perform memory locking without unnecessarily elevating its privileges.
sudo vi /etc/systemd/system/vault.service
[Unit]
Description=HashiCorp Vault to manage secrets
Documentation=https://vaultproject.io/docs/
After=network.target
ConditionFileNotEmpty=/etc/vault.hcl
[Service]
User=vault
Group=vault
ExecStart=/usr/bin/vault server -config=/etc/vault.hcl
ExecReload=/usr/local/bin/kill --signal HUP $MAINPID
CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK
AmbientCapabilities=CAP_IPC_LOCK
SecureBits=keep-caps
NoNewPrivileges=yes
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
Start the service using following command
123
systemctl deamon-reload
systemctl start vault.service
systemctl status vault.service
Preparing to Administer Vault
Add the Vault bin directory to your PATH environment variable.
123456789101112
export PATH=$PATH:/opt/vault/bin
echo "export PATH=$PATH:/opt/vault/bin" >> ~/.bashrc
Set environment variables for Vault
export VAULT_ADDRESS=http://192.168.1.111:8200
echo "export VAULT_ADDR=http://192.168.1.111:8200" >> ~/.bashrc
And Probably
export VAULT_TOKEN=<token value>
**Start the command with a space. See Protip.
Attention: Be careful when you export sensitive data as environment variable using a command. ProTip: Start your command with a space, and it will not get recorded in the command history.
Initialize Vault
There are two pieces of information that Vault will expose at initialization time that will not be available at any other point, so make sure you noted some secure place,
Initial root token: This is equivalent to root permissions to your Vault deployment, which allows the management of all Vault policies, mounts, and so on.
Unseal keys: These are used to unseal Vault when the daemon starts, which permits the Vault daemon to decrypt the backend secret stor
1
vim /etc/systemd/system/vault.service
Seal/Unseal
Every initialized Vault server starts in the sealed state. From the configuration, Vault can access the physical storage, but it can't read any of it because it doesn't know how to decrypt it. The process of teaching Vault how to decrypt the data is known as unsealing the Vault.
Unsealing has to happen every time Vault starts. It can be done via the API and via the command line. To unseal the Vault, you must have the threshold number of unseal keys. In the output above, notice that the "key threshold" is 3. This means that to unseal the Vault, you need 3 of the 5 keys that were generated.
Note: Vault does not store any of the unseal key shards. Vault uses an algorithm known as Shamir's Secret Sharing to split the master key into shards. Only with the threshold number of keys can it be reconstructed and your data finally accessed.
vault operator unseal UBXbFKpvvytWeR3rUWi1k3xxxxxxxxxK8LIKtdMGvsjA
vault operator unseal 13sjixnJMSvNyANqwdxxxxxxxxE3OPd/izsg8nezTv3F
vault operator unseal RRqXVkJ7o0nSsYxxxxxxxFUvvONI2meiF+E+dhssnSdO
theashwanik@ashberrypi:~/hashicorp/vault $ vault operator unseal UBXbFKpvvytWeR3rUWi1k3xxxxxxxxxK8LIKtdMGvsjA
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed true
Total Shares 5
Threshold 3
Unseal Progress 1/3
Unseal Nonce 634a8b1a-6d15-d4a3-740f-f6b8f01a4a37
Version 1.4.3+ent
HA Enabled false
theashwanik@ashberrypi:~/hashicorp/vault $ vault operator unseal 13sjixnJMSvNyANqwdxxxxxxxxE3OPd/izsg8nezTv3F
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed true
Total Shares 5
Threshold 3
Unseal Progress 2/3
Unseal Nonce 634a8b1a-6d15-d4a3-740f-f6b8f01a4a37
Version 1.4.3+ent
HA Enabled false
theashwanik@ashberrypi:~/hashicorp/vault $ vault operator unseal RRqXVkJ7o0nSsYxxxxxxxFUvvONI2meiF+E+dhssnSdO
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed false
Total Shares 5
Threshold 3
Version 1.4.3+ent
Cluster Name vault-cluster-7944b651
Cluster ID 2573fdfa-01a5-19e1-8a20-0cd5fcc89df8
HA Enabled false
Check the status
1234567891011
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed false
Total Shares 5
Threshold 3
Version 1.4.3+ent
Cluster Name vault-cluster-7944b651
Cluster ID 2573fdfa-01a5-19e1-8a20-0cd5fcc89df8
HA Enabled false
Note: Every time you restart vault or if it gets restarted during server restarts, you need to perform the unseal operation using the same unseal key.
You can also access the vault UI on port 8200 of your vault server.
1
http://192.168.1.111:8200/ui/
Usage
Create secrets at the kv/my-secret path.
12
$ vault kv put kv/my-secret value="s3c(eT"
Success! Data written to: kv/my-secret
Read the secrets at kv/my-secret.
123456
$ vault kv get kv/my-secret
==== Data ====
Key Value
--- -----
value s3c(eT
Delete the secrets at kv/my-secret.
12
$ vault kv delete kv/my-secret
Success! Data deleted (if it existed) at: kv/my-secret
List existing keys at the kv path.
12345
$ vault kv list kv/
Keys
----
hello
Disable a Secrets Engine
When a secrets engine is no longer needed, it can be disabled. When a secrets engine is disabled, all secrets are revoked and the corresponding Vault data and configuration is removed.
12
$ vault secrets disable kv/
Success! Disabled the secrets engine (if it existed) at: kv/
Note that this command takes a PATH to the secrets engine as an argument, not the TYPE of the secrets engine.
vault path-help aws
DESCRIPTION
The AWS backend dynamically generates AWS access keys for a set of
IAM policies. The AWS access keys have a configurable lease set and
are automatically revoked at the end of the lease.
After mounting this backend, credentials to generate IAM keys must
be configured with the "root" path and policies must be written using
the "roles/" endpoints before any access keys can be generated.
PATHS
The following paths are supported by this backend. To view help for
any of the paths below, use the help command with any route matching
the path pattern. Note that depending on the policy of your auth token,
you may or may not be able to access certain paths.
^(creds|sts)/(?P<name>\w(([\w-.@]+)?\w)?)$
Generate AWS credentials from a specific Vault role.
^config/lease$
Configure the default lease information for generated credentials.
^config/root$
Configure the root credentials that are used to manage IAM.
^config/rotate-root$
Request to rotate the AWS credentials used by Vault
^roles/(?P<name>\w(([\w-.@]+)?\w)?)$
Read, write and reference IAM policies that access keys can be made for.
^roles/?$
List the existing roles in this backend
The token is created and displayed here as s.7vM3kUTFSNxxxxxxxxxf4f8R9. Each token that Vault creates is unique.
12345678910111213141516171819
vault login s.7vM3kUTFSNxxxxxxxxxf4f8R9
WARNING! The VAULT_TOKEN environment variable is set! This takes precedence
over the value set by this command. To use the value set by this command,
unset the VAULT_TOKEN environment variable or set it to the token displayed
below.
Success! You are now authenticated. The token information displayed below
is already stored in the token helper. You do NOT need to run "vault login"
again. Future Vault requests will automatically use this token.
Key Value
--- -----
token s.7vM3kUTFSNxxxxxxxxxf4f8R9
token_accessor Dtuk4LtxxxxxxxrEDNXiB5EZ
token_duration ∞
token_renewable false
token_policies ["root"]
identity_policies []
policies ["root"]
When a token is no longer needed it can be revoked.