feat(agent): configure dedicated PostgreSQL runtime roles
This commit is contained in:
1 parent
9499c2ac8d
commit
e7a9d4a1a6
8 files changed
+114
-4
No files matched your search
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
namespace="${1:?usage: $0 <namespace> <site> <app-username>}"
|
||||
site="${2:?usage: $0 <namespace> <site> <app-username>}"
|
||||
app_username="${3:?usage: $0 <namespace> <site> <app-username>}"
|
||||
|
||||
: "${AGENT_POSTGRES_ADMIN_PASSWORD:?set AGENT_POSTGRES_ADMIN_PASSWORD}"
|
||||
: "${AGENT_POSTGRES_APP_PASSWORD:?set AGENT_POSTGRES_APP_PASSWORD}"
|
||||
|
||||
database_name="agent-db-${site}"
|
||||
postgres_host="agent-${site}-postgres-service"
|
||||
secret_name="agent-${site}-postgres-credentials"
|
||||
escaped_app_password=${AGENT_POSTGRES_APP_PASSWORD//\"/\"\"}
|
||||
connection_string="Host=${postgres_host};Port=5432;Username=${app_username};Password=\"${escaped_app_password}\";Database=${database_name}"
|
||||
|
||||
credentials_directory=$(mktemp -d)
|
||||
trap 'rm -rf -- "${credentials_directory}"' EXIT
|
||||
chmod 700 "${credentials_directory}"
|
||||
printf '%s' "${AGENT_POSTGRES_ADMIN_PASSWORD}" > "${credentials_directory}/admin-password"
|
||||
printf '%s' "${AGENT_POSTGRES_APP_PASSWORD}" > "${credentials_directory}/app-password"
|
||||
printf '%s' "${connection_string}" > "${credentials_directory}/connection-string"
|
||||
|
||||
kubectl --namespace "${namespace}" create secret generic "${secret_name}" \
|
||||
--from-file=admin-password="${credentials_directory}/admin-password" \
|
||||
--from-file=app-password="${credentials_directory}/app-password" \
|
||||
--from-file=connection-string="${credentials_directory}/connection-string" \
|
||||
--dry-run=client \
|
||||
--output=yaml \
|
||||
| kubectl apply --filename=-
|
||||
|
||||
echo "Updated ${namespace}/${secret_name}; restart the Agent Deployment to consume changed values."
|
||||
Reference in new issue
Block a user