2023-07-08 16:00:11 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
2023-11-17 17:00:29 +01:00
|
|
|
export VAULT_ADDR=https://{{ inventory_hostname }}:{{ vault_services.api.port | default('8200') }}
|
2023-07-08 16:00:11 +02:00
|
|
|
VAULT_STATUS=$(vault status -format=json)
|
|
|
|
|
|
|
|
if [ "$(echo ${VAULT_STATUS} | jq .is_self)" != "true" ]; then
|
|
|
|
echo "We're not the active vault, exiting"
|
|
|
|
elif [ "$(echo ${VAULT_STATUS} | jq .sealed)" != "false" ]; then
|
|
|
|
echo "Vault is sealed, exiting"
|
|
|
|
elif [ "$(echo ${VAULT_STATUS} | jq .initialized)" != "true" ]; then
|
|
|
|
echo "Vault is not initialized yet, exiting"
|
|
|
|
else
|
|
|
|
echo Updating Vault certificate to access Nomad API
|
2024-10-24 12:00:41 +02:00
|
|
|
if [ -z "${VAULT_TOKEN}" -a -e /run/nomad/vault_config.env ]; then
|
2023-07-25 10:00:20 +02:00
|
|
|
echo "Using VAULT_TOKEN from Nomad agent"
|
2024-10-24 12:00:41 +02:00
|
|
|
export $(cat /run/nomad/vault_config.env)
|
2023-07-25 10:00:20 +02:00
|
|
|
fi
|
2023-07-09 17:00:09 +02:00
|
|
|
vault write {{ vault_agent_nomad.nomad_pki.cli.secret_path | default('nomad') }}/config/access \
|
2023-07-08 16:00:11 +02:00
|
|
|
ca_cert="$(cat {{ nomad_root_dir }}/tls/ca.crt)" \
|
|
|
|
client_cert="$(cat {{ nomad_root_dir }}/tls/cli.crt)" \
|
|
|
|
client_key="$(cat {{ nomad_root_dir }}/tls/cli.key)"
|
|
|
|
fi
|