Skip to content

Commit ff9a5dc

Browse files
authored
fix: support external database passwords with special characters (#2532)
## Summary - Add AWS RDS CA bundle for SSL certificate validation with `sslmode=require` - Fix supervisord `%` escaping (`%` must be `%%` for supervisord string interpolation) - Use `awk` instead of `sed` to handle special characters like `|` in database URLs - Remove unused credential extraction for external databases ## Test plan - [x] Tested with AWS RDS database using password with special characters (`?`, `|`, `~`, `]`) - [x] Verified `sslmode=require` works with AWS RDS CA bundle - [x] Verified backwards compatibility with internal PostgreSQL - [x] Verified simple passwords without special characters still work
1 parent 40c21e1 commit ff9a5dc

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

platform/Dockerfile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,21 @@ ENV ARCHESTRA_AUTH_DISABLE_INVITATIONS="false"
9999
ENV ARCHESTRA_SENTRY_FRONTEND_DSN=""
100100
ENV ARCHESTRA_SENTRY_ENVIRONMENT=""
101101

102+
# Cloud database CA bundle for SSL certificate validation
103+
# This allows sslmode=require to work with AWS RDS and Google Cloud SQL
104+
ENV NODE_EXTRA_CA_CERTS="/etc/ssl/certs/cloud-database-ca-bundle.pem"
105+
102106
RUN apk --no-cache upgrade && \
103107
# Install PostgreSQL 17, supervisord, and wget (needed for KinD download and health checks)
104108
apk add --no-cache postgresql17 postgresql17-contrib su-exec wget && \
109+
# Download cloud database CA bundles for SSL certificate validation
110+
# AWS RDS global CA bundle
111+
wget -qO /tmp/aws-rds-ca.pem https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem && \
112+
# Google Cloud SQL global CA bundle
113+
wget -qO /tmp/gcloud-sql-ca.pem https://storage.googleapis.com/cloudsql-ca-bundles/global.pem && \
114+
# Combine all CA bundles
115+
cat /tmp/aws-rds-ca.pem /tmp/gcloud-sql-ca.pem > /etc/ssl/certs/cloud-database-ca-bundle.pem && \
116+
rm -f /tmp/aws-rds-ca.pem /tmp/gcloud-sql-ca.pem && \
105117
# Remove NPM-related files and directories (as we do not use npm and it just brings extra dependencies/vulnerabilities)
106118
# See https://github.com/grafana/grafana-image-renderer/pull/625
107119
rm -rf /usr/local/lib/node_modules/npm && \
@@ -459,14 +471,15 @@ EOSQL
459471
fi
460472
else
461473
echo "Using external PostgreSQL database"
462-
# Extract credentials from DATABASE_URL if needed (postgresql://user:pass@host:port/db)
463-
POSTGRES_USER=$(echo "$EFFECTIVE_DATABASE_URL" | sed -n 's|.*://\([^:]*\):.*|\1|p')
464-
POSTGRES_PASSWORD=$(echo "$EFFECTIVE_DATABASE_URL" | sed -n 's|.*://[^:]*:\([^@]*\)@.*|\1|p')
465-
POSTGRES_DB=$(echo "$EFFECTIVE_DATABASE_URL" | sed -n 's|.*/\([^?]*\).*|\1|p')
474+
# Note: POSTGRES_USER/PASSWORD/DB extraction removed - not needed for external databases
475+
# The application uses EFFECTIVE_DATABASE_URL directly
466476
fi
467477

468478
# Update supervisord config with actual environment variables
469-
sed -i "s|DATABASE_URL=\"[^\"]*\"|DATABASE_URL=\"${EFFECTIVE_DATABASE_URL}\"|" /etc/supervisord.conf
479+
# Escape % as %% for supervisord (it uses % for string interpolation like %(ENV_VAR)s)
480+
# Then use awk to handle other special characters in DATABASE_URL (like |, &, \)
481+
ESCAPED_DATABASE_URL=$(echo "$EFFECTIVE_DATABASE_URL" | sed 's/%/%%/g')
482+
awk -v url="$ESCAPED_DATABASE_URL" '{gsub(/DATABASE_URL="[^"]*"/, "DATABASE_URL=\"" url "\""); print}' /etc/supervisord.conf > /etc/supervisord.conf.tmp && mv /etc/supervisord.conf.tmp /etc/supervisord.conf
470483

471484
# Propagate analytics setting to frontend (enabled by default, set to "disabled" to opt-out)
472485
if [ -n "$ARCHESTRA_ANALYTICS" ]; then

0 commit comments

Comments
 (0)