Skip to content

Commit ce3506f

Browse files
authored
WPB:18722: Remove Postgres and smtp hard coded passwords (#817)
* patch the postgresql password to the k8s cluster * Update demo setup script and secrets example * add changelog * Add label specfic build for the CI * Remove conditional logics form dependent steps * hand wire-server chart installation with k8s pg password * refactor the pg secret name * update the secret reference * Utilize sync script to sync k8s postgres secret with wire helm secret
1 parent 5d26fef commit ce3506f

File tree

5 files changed

+103
-16
lines changed

5 files changed

+103
-16
lines changed

.github/workflows/offline.yml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Offline Build Workflow
2+
#
3+
# This workflow builds offline deployment artifacts for different profiles:
4+
# - default: Production deployment (includes external charts, ansible, terraform)
5+
# - demo: Demo/WIAB deployment (includes databases-ephemeral)
6+
# - min: Minimal deployment
7+
#
8+
# Build Optimization via PR Labels:
9+
# - No label: Builds default + demo + min (all profiles)
10+
# - 'demo-only': Builds only demo profile
11+
# - 'min-only': Builds only min profile
12+
# - 'build-all': Explicitly builds all profiles (useful for workflow changes)
13+
#
14+
# Push to master/develop: Always builds all profiles regardless of labels
15+
#
116
on:
217
push:
318
branches: [master, develop]
@@ -14,7 +29,12 @@ jobs:
1429
# Build default profile and create local assets
1530
build-default:
1631
name: Build default profile
17-
if: "!contains(github.event.head_commit.message, 'skip ci')"
32+
if: |
33+
!contains(github.event.head_commit.message, 'skip ci') &&
34+
(github.event_name == 'push' ||
35+
contains(github.event.pull_request.labels.*.name, 'build-all') ||
36+
(!contains(github.event.pull_request.labels.*.name, 'demo-only') &&
37+
!contains(github.event.pull_request.labels.*.name, 'min-only')))
1838
runs-on:
1939
group: wire-server-deploy
2040
outputs:
@@ -54,7 +74,6 @@ jobs:
5474
# Upload to S3 in parallel with deployment
5575
upload-s3:
5676
name: Upload default build to S3
57-
if: "!contains(github.event.head_commit.message, 'skip ci')"
5877
needs: build-default
5978
runs-on:
6079
group: wire-server-deploy
@@ -81,7 +100,6 @@ jobs:
81100
# Deploy to Hetzner in parallel with S3 upload
82101
deploy-hetzner:
83102
name: Deploy default build to Hetzner
84-
if: "!contains(github.event.head_commit.message, 'skip ci')"
85103
needs: build-default
86104
runs-on:
87105
group: wire-server-deploy
@@ -118,7 +136,6 @@ jobs:
118136
# Build container in parallel
119137
build-container:
120138
name: Build container
121-
if: "!contains(github.event.head_commit.message, 'skip ci')"
122139
needs: build-default
123140
runs-on:
124141
group: wire-server-deploy
@@ -144,7 +161,12 @@ jobs:
144161
# Build demo profile
145162
build-demo:
146163
name: Build demo profile
147-
if: "!contains(github.event.head_commit.message, 'skip ci')"
164+
if: |
165+
!contains(github.event.head_commit.message, 'skip ci') &&
166+
(github.event_name == 'push' ||
167+
contains(github.event.pull_request.labels.*.name, 'build-all') ||
168+
contains(github.event.pull_request.labels.*.name, 'demo-only') ||
169+
!contains(github.event.pull_request.labels.*.name, 'min-only'))
148170
runs-on:
149171
group: wire-server-deploy
150172
steps:
@@ -185,7 +207,12 @@ jobs:
185207
# Build min profile
186208
build-min:
187209
name: Build min profile
188-
if: "!contains(github.event.head_commit.message, 'skip ci')"
210+
if: |
211+
!contains(github.event.head_commit.message, 'skip ci') &&
212+
(github.event_name == 'push' ||
213+
contains(github.event.pull_request.labels.*.name, 'build-all') ||
214+
contains(github.event.pull_request.labels.*.name, 'min-only') ||
215+
!contains(github.event.pull_request.labels.*.name, 'demo-only'))
189216
runs-on:
190217
group: wire-server-deploy
191218
steps:

bin/demo-setup.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,53 @@ for chart in "${phase_1_charts_pre[@]}"; do
9696
fi
9797
done
9898

99+
# Retrieve PostgreSQL password from databases-ephemeral for later use
100+
echo "######################################################"
101+
echo "Retrieving PostgreSQL password..."
102+
echo "######################################################"
103+
if command -v kubectl &> /dev/null; then
104+
if kubectl get secret wire-postgresql-secret -n "${NAMESPACE}" &>/dev/null; then
105+
PG_PASSWORD_B64=$(kubectl get secret wire-postgresql-secret -n "${NAMESPACE}" -o jsonpath='{.data.password}')
106+
if [ -n "$PG_PASSWORD_B64" ]; then
107+
echo "✓ PostgreSQL password retrieved successfully"
108+
# Decode password for use in helm --set
109+
PG_PASSWORD_PLAIN=$(echo "$PG_PASSWORD_B64" | base64 -d)
110+
export PG_PASSWORD_B64
111+
export PG_PASSWORD_PLAIN
112+
else
113+
echo "⚠️ Warning: PostgreSQL secret exists but password is empty"
114+
fi
115+
else
116+
echo "⚠️ Warning: PostgreSQL secret 'wire-postgresql-secret' not found in namespace '${NAMESPACE}'"
117+
echo " PostgreSQL password will need to be synced manually"
118+
fi
119+
else
120+
echo "⚠️ Warning: kubectl not found, PostgreSQL password will need to be synced manually"
121+
fi
122+
echo ""
123+
99124
echo "Installing wire-server, this may take a long time, and take a long time before reporting errors. (timeout of $timeout seconds.) You may check for potential problems with 'kubectl -n $NAMESPACE get pods -w' or 'kubectl -n $NAMESPACE get all' and look for errors/pending."
100125
for chart in "${phase_2_charts_main[@]}"; do
101126
valuesfile="${DIR}/values/${chart}/${valuesfilename}"
102127
secretsfile="${DIR}/values/${chart}/${secretsfilename}"
128+
129+
# Build helm command with PostgreSQL password injection if available
130+
HELM_EXTRA_ARGS=""
131+
if [ -n "${PG_PASSWORD_PLAIN:-}" ]; then
132+
HELM_EXTRA_ARGS="--set brig.secrets.pgPassword=${PG_PASSWORD_PLAIN} --set galley.secrets.pgPassword=${PG_PASSWORD_PLAIN}"
133+
echo "Injecting PostgreSQL password into brig and galley secrets"
134+
fi
135+
103136
if [ -f "$secretsfile" ]; then
104137
helm upgrade --install --namespace "${NAMESPACE}" "${NAMESPACE}-${chart}" "${DIR}/charts/${chart}" \
105138
-f "$valuesfile" \
106139
-f "$secretsfile" \
140+
${HELM_EXTRA_ARGS} \
107141
--wait --timeout 900
108142
else
109143
helm upgrade --install --namespace "${NAMESPACE}" "${NAMESPACE}-${chart}" "${DIR}/charts/${chart}" \
110144
-f "$valuesfile" \
145+
${HELM_EXTRA_ARGS} \
111146
--wait --timeout 900
112147
fi
113148
done

bin/wiab-demo/offline_deploy_k8s.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ COTURN_NODE="K8S_COTURN_NODE"
1717
# keeping it empty to be replaced
1818
HOST_IP="WIRE_IP"
1919

20-
# it creates the values.yaml from prod-values.example.yaml and secrets.yaml from prod-secrets.example.yaml, it works on the directory $BASE_DIR"/values/ in the bundle
21-
process_charts() {
22-
20+
# Creates values.yaml from demo-values.example.yaml and secrets.yaml from demo-secrets.example.yaml
21+
# This script is for WIAB/demo deployments only
22+
# Works on all chart directories in $BASE_DIR/values/
23+
process_charts() {
24+
2325
ENV=$1
2426

25-
if [ "$ENV" != "prod" ] && [ "$ENV" != "demo" ]; then
26-
echo "ENV is neither prod nor demo"
27+
if [ "$ENV" != "demo" ]; then
28+
echo "Error: This script only supports demo deployments. ENV must be 'demo', got: '$ENV'"
2729
exit 1
28-
fi
30+
fi
2931

3032
for chart_dir in "$BASE_DIR"/values/*/; do
3133

@@ -83,7 +85,7 @@ process_values() {
8385
"$BASE_DIR/values/ingress-nginx-controller/values.yaml" > "$TEMP_DIR/ingress-nginx-controller-values.yaml"
8486
if ! grep -q "kubernetes.io/hostname: $NGINX_K8S_NODE" "$TEMP_DIR/ingress-nginx-controller-values.yaml"; then
8587
echo -e " nodeSelector:\n kubernetes.io/hostname: $NGINX_K8S_NODE" >> "$TEMP_DIR/ingress-nginx-controller-values.yaml"
86-
fi
88+
fi
8789

8890
# Fixing SFTD hosts and setting the cert-manager to http01
8991
sed -e "s/webapp.example.com/webapp.$TARGET_SYSTEM/" \
@@ -161,6 +163,22 @@ deploy_charts() {
161163
helm_command+=" --values $secrets_file"
162164
fi
163165

166+
# handle wire-server to inject PostgreSQL password from databases-ephemeral
167+
if [[ "$chart" == "wire-server" ]]; then
168+
169+
echo "Retrieving PostgreSQL password from databases-ephemeral for wire-server deployment..."
170+
if kubectl get secret wire-postgresql-secret &>/dev/null; then
171+
# Usage: sync-k8s-secret-to-wire-secrets.sh <secret-name> <secret-key> <yaml-file> <yaml-path's>
172+
"$BASE_DIR/bin/sync-k8s-secret-to-wire-secrets.sh" \
173+
wire-postgresql-secret password \
174+
"$BASE_DIR/values/wire-server/secrets.yaml" \
175+
.brig.secrets.pgPassword .galley.secrets.pgPassword
176+
else
177+
echo "⚠️ Warning: PostgreSQL secret 'wire-postgresql-secret' not found, skipping secret sync"
178+
echo " Make sure databases-ephemeral chart is deployed before wire-server"
179+
fi
180+
fi
181+
164182
echo "Deploying $chart as $helm_command"
165183
eval "$helm_command"
166184
done
@@ -192,7 +210,7 @@ deploy_calling_services() {
192210

193211
# if required, this function can be run manually
194212
run_manually() {
195-
# process_charts can process demo or prod values
213+
# process_charts processes demo values for WIAB deployment
196214
process_charts "demo"
197215
process_values
198216
# deploying cert manager to issue certs, by default letsencrypt-http01 issuer is configured
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed: Remove hardcoded PostgreSQL passwords from demo-secrets.example.yaml and automatically inject passwords from databases-ephemeral chart during deployment. Updated demo-setup.sh and bin/wiab-demo/offline_deploy_k8s.sh to retrieve and inject PostgreSQL passwords using --set flags. Add PR label-based build optimization to offline.yml workflow (use 'demo-only' or 'min-only' labels to skip unnecessary builds)

values/wire-server/demo-secrets.example.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ brig:
2424
rabbitmq:
2525
username: wire-server
2626
password: verysecurepassword
27-
pgPassword: verysecurepassword
27+
# PostgreSQL password is synced with the wire-postgresql-secret from k8s cluster
28+
# To extract the secret from an existing Kubernetes cluster:
29+
# kubectl get secret wire-postgresql-secret -n postgresql -o jsonpath='{.data.password}' | base64 -d
30+
pgPassword: dummyPassword # gets replaced by the actual secret
2831
setTwilio: |-
2932
sid: "dummy"
3033
token: "dummy"
@@ -57,7 +60,10 @@ galley:
5760
# these only need to be changed if using real AWS services
5861
awsKeyId: dummykey
5962
awsSecretKey: dummysecret
60-
pgPassword: verysecurepassword
63+
# PostgreSQL password is synced with the wire-postgresql-secret from k8s cluster
64+
# To extract the secret from an existing Kubernetes cluster:
65+
# kubectl get secret wire-postgresql-secret -n postgresql -o jsonpath='{.data.password}' | base64 -d
66+
pgPassword: dummyPassword # gets replaced by the actual secret
6167
rabbitmq:
6268
username: wire-server
6369
password: verysecurepassword

0 commit comments

Comments
 (0)