nixcfg/deploy_pki

34 lines
1.1 KiB
Text
Raw Normal View History

2022-04-20 11:01:51 +00:00
#!/usr/bin/env ./sshtool
2022-04-20 13:03:04 +00:00
PKI=deuxfleurs/cluster/$CLUSTER
2022-04-20 11:01:51 +00:00
YEAR=$(date +%Y)
cmd mkdir -p /var/lib/nomad/pki /var/lib/consul/pki
for file in consul-ca.crt consul$YEAR.crt consul$YEAR.key consul$YEAR-client.crt consul$YEAR-client.key; do
2022-04-20 13:03:04 +00:00
if pass $PKI/$file >/dev/null; then
write_pass $PKI/$file /var/lib/consul/pki/$file
2022-04-20 11:01:51 +00:00
cmd chown consul:root /var/lib/consul/pki/$file
fi
done
cmd systemctl restart consul
cmd sleep 10
2022-04-20 11:07:39 +00:00
for file in nomad-ca.crt nomad$YEAR.crt nomad$YEAR.key; do
2022-04-20 13:03:04 +00:00
if pass $PKI/$file >/dev/null; then
write_pass $PKI/$file /var/lib/nomad/pki/$file
2022-04-20 11:01:51 +00:00
fi
done
cmd systemctl restart nomad
set_env CONSUL_HTTP_ADDR=https://localhost:8501
set_env CONSUL_CACERT=/var/lib/consul/pki/consul-ca.crt
set_env CONSUL_CLIENT_CERT=/var/lib/consul/pki/consul$YEAR-client.crt
set_env CONSUL_CLIENT_KEY=/var/lib/consul/pki/consul$YEAR-client.key
cmd "consul kv put secrets/consul/consul-ca.crt - < /var/lib/consul/pki/consul-ca.crt"
cmd "consul kv put secrets/consul/consul-client.crt - < /var/lib/consul/pki/consul$YEAR-client.crt"
cmd "consul kv put secrets/consul/consul-client.key - < /var/lib/consul/pki/consul$YEAR-client.key"