k8s/scripts/nextcloud-vault.sh

20 lines
618 B
Bash
Raw Normal View History

2023-07-11 17:38:32 +00:00
#!/bin/bash
cat << EOH > nextcloud.hcl
path "kv/data/nextcloud" {
capabilities = ["read"]
}
EOH
vault policy write nextcloud nextcloud.hcl
rm nextcloud.hcl
HOST_IP=$(ip addr show eth0 | grep -Po 'inet \K[\d.]+')
TOKEN="$(kubectl get secret serviceaccounttoken -n nextcloud -o go-template='{{ .data.token }}' | base64 -d)"
vault write auth/${VAULT_AUTH_NAMESPACE}/role/nextcloud \
bound_service_account_names=nextcloud \
bound_service_account_namespaces=nextcloud \
policies=nextcloud \
ttl=24h
vault write auth/${VAULT_AUTH_NAMESPACE}/login role=nextcloud jwt=${TOKEN} iss=https://${HOST_IP}:6443