Using Vault to store LUKS keys – Part Two

This is a continuation from my previous two posts (Part Zero and Part One) about the need to have automated way of storing and pull LUKS keys for my servers.

In this post, we are going to setup the Vault servers.

I will preface this by saying, i really would not recommend using this setup in production without some major reworking. The internal comms are currently not using TLS for starters. That will be added very shortly, but at the moment this was more a proof of concept.

Setting up the Vault Servers

The configuration of the vault servers is done in 2 parts. First you need to install consul to run as an agent (rather than a server) to communicate with the consul cluster we setup previously. Then you need to install the vault server itself.

Setting up the Consul Agent

This is a very similar process to setting up the Consul servers, just with a change in the config.json.

Grab consul:


Unzip it:


Move it to /usr/local/bin

mv consul /usr/local/bin/

Set the owner to root

chown root:root /usr/local/bin/consul

Create the required directories:

mkdir /etc/consul
mkdir -p /var/consul/data

Now we need to create the consul client config, open the following file in your favourite text editor.

vim /etc/consul/client.json

Enter in the following:

  "server": false,
  "datacenter": "Haynet",
  "node_name": "vault1",
  "data_dir": "/var/consul/data",
  "bind_addr": "",
  "client_addr": "",
  "retry_join": ["", "", ""],
  "log_level": "DEBUG",
  "enable_syslog": true,
  "acl_enforce_version_8": false

You will need to set the ‘encrypt’ key to the same that you set in the Consul server setup above.

You will also need to set the bind_addr to the IP of the server and the ‘retry join’ to the IP’s of you consul servers.

Do this on both Vault servers, but change the ‘node_name’.

We are going to have consul run as its own user now. So lets add a consul system user:

useradd --system --home /etc/consul.d --shell /bin/false consul

Now we need to set the correct permissions on one of the directories we created:

chown consul:consul /var/consul -R

Next we need to create the service file to start the consul agent.

In your favourite text editor open the following file: /etc/systemd/system/consul-agent.service

and enter the following:

Description=Consul client agent

ExecStartPre=-/bin/mkdir -p /var/run/consul
ExecStartPre=/bin/chown -R consul:consul /var/run/consul
ExecStart=/usr/local/bin/consul agent \
    -config-file=/etc/consul/client.json \
ExecReload=/bin/kill -HUP $MAINPID


Finally lets get the agent started:

systemctl daemon-reload
systemctl enable consul-agent
systemctl start consul-agent

If you check back on your Consul UI, you should see the new hosts added on there.

Setting up Vault on the Vault servers

Now we need to setup vault on these servers. The process is very similar to the consul setup.

Grab the vault binary:


Unzip it:


Move it to /usr/local/bin:

mv vault /usr/local/bin/

Check it works:

[root@vault1 ~]# vault -h
Usage: vault <command> [args]

Common commands:
    read        Read data and retrieves secrets
    write       Write data, configuration, and secrets
    delete      Delete secrets and configuration
    list        List data or secrets

Now create the required directories:

mkdir /etc/vault
mkdir /var/log/vault

Create the following file and open it with you favourite text editor:

vim /etc/vault/config.json

And enter in the following details:

"listener": [{
"tcp": {
"address" : "",
"tls_disable" : 1
"api_addr": "",
"storage": {
   "consul" : {
      "address" : "",
      "path": "vault"
"max_lease_ttl": "10h",
"default_lease_ttl": "10h",

Remember to change the api_addr

Now to create the service file, create and open the following file in your favourite text editor

vim /etc/systemd/system/vault.service

and enter in the following details:

Description=vault service
ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json
ExecReload=/bin/kill -HUP $MAINPID

We are also going to need to open a bunch of firewall rules (some of these may not be needed – but for the purpose of this POC i have added all the consul ports and the vault port:

firewall-cmd --permanent --add-port=8200/tcp
firewall-cmd --permanent --add-port=8201/tcp
firewall-cmd --permanent --add-port=8300/tcp
firewall-cmd --permanent --add-port=8301/tcp
firewall-cmd --permanent --add-port=8301/udp
firewall-cmd --permanent --add-port=8302/tcp
firewall-cmd --permanent --add-port=8302/udp
firewall-cmd --permanent --add-port=8400/tcp
firewall-cmd --permanent --add-port=8500/tcp
firewall-cmd --permanent --add-port=8600/tcp
firewall-cmd --permanent --add-port=8600/udp
firewall-cmd --reload

Finally, lets get vault started:

systemctl daemon-reload
systemctl enable vault
systemctl start vault

Its worth checking that vault has come up, first run the following to add the vault address environment variable:

echo "export VAULT_ADDR=" >> ~/.bashrc

Then run the following to confirm vault is up

[root@vault1 ~]# vault status
Key             Value
---             -----
Seal Type       shamir
Initialized     true
Sealed          false
Total Shares    5
Threshold       3
Version         1.2.3
Cluster Name    vault-cluster-e093bfc5
Cluster ID      b3f75720-44b7-a057-bf58-d80e4d54932d
HA Enabled      true
HA Cluster
HA Mode         active

Note: Your output will be different, the above is with vaul unsealed.

That is it for the installation. Now its onto configuring Vault.

Head over to the next section to configure vault.