Skip to content

Commit 3b63cec

Browse files
fix: support external database passwords with special characters (#2532) (#2539)
## 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 Co-authored-by: Ildar Iskhakov <[email protected]>
1 parent d2867b5 commit 3b63cec

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
@@ -98,9 +98,21 @@ ENV ARCHESTRA_AUTH_DISABLE_INVITATIONS="false"
9898
ENV ARCHESTRA_SENTRY_FRONTEND_DSN=""
9999
ENV ARCHESTRA_SENTRY_ENVIRONMENT=""
100100

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

457467
# Update supervisord config with actual environment variables
458-
sed -i "s|DATABASE_URL=\"[^\"]*\"|DATABASE_URL=\"${EFFECTIVE_DATABASE_URL}\"|" /etc/supervisord.conf
468+
# Escape % as %% for supervisord (it uses % for string interpolation like %(ENV_VAR)s)
469+
# Then use awk to handle other special characters in DATABASE_URL (like |, &, \)
470+
ESCAPED_DATABASE_URL=$(echo "$EFFECTIVE_DATABASE_URL" | sed 's/%/%%/g')
471+
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
459472

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

0 commit comments

Comments
 (0)