We want to know if vault is healthy on a particular node.
The definition of "healthy" does not include whether the node is the primary or whether it is the standby, since standby nodes just forward the request onto the primary node via the
I had to modify the script to exit with code 2 to get consul's DNS to remove it:
curl -o /dev/stderr -A consul -sw '%{http_code}' --insecure http://localhost:8200/v1/sys/health | egrep -q '200|429' || exit 2
I then added two services, one for vault and one for vault-primary:
{
"services" : [
{
"check" : {
"interval" : "10s",
"name" : "Vault Health",
"script" : "curl -o /dev/stderr -A consul -sw '%{http_code}' --insecure http://localhost:8200/v1/sys/health | egrep -q '200|429' || exit 2"
},
"name" : "vault",
"port" : 8200
},
{
"port" : 8200,
"check" : {
"script" : "curl -o /dev/stderr -A consul -sw '%{http_code}' --insecure http://localhost:8200/v1/sys/health | grep 200 || exit 2",
"name" : "Primary Vault Health",
"interval" : "10s"
},
"name" : "vault-primary"
}
]
}
Vault can then be used at vault.service.us-west-1.consul, and if you hit a standby server it will forward the request on to the primary.
But then how do you seal the vaults elegantly?
If you don't have vault-primary, then when you try to seal vault.service.us-west-1.consul and you git a standby server, you'll get:
{"errors":["vault cannot seal when in standby mode; please restart instead"]}
With vault-primary:
curl -X PUT -H "X-Vault-Token: <TOKEN>" http://vault-primary.service.us-west-1.consul:8200/v1/sys/seal
Run this once per vault server (waiting for consul DNS to move onto the next vault primary server) and you can lock them all.
A down side to this method is that if you have 3 vault servers, two of them will be marked in consul as critical (because they're not primaries). I'm not sure how to do this gracefully quite yet, you could probably watch consul for the change of the primary node and then de-register the existing primary and register the new one.
I'm really new to vault, so the solution of adding vault-primary to make sealing as easy as possible may be overkill. It seems likely that you don't seal the vaults very often, and if you do, curling each vault server separately (or via 'vault seal' on the command line) is not very difficult. For example:
for count in `host vault.service.us-west-1.consul | cut -d ' ' -f 4` ; do
curl -X PUT -H "X-Vault-Token: <TOKEN>" $leader/v1/sys/seal
sleep 1
done
Pete