Skip to content

Commit 39fd99d

Browse files
committed
ci: require an explicit database password outside pull requests
Template-side generate: expression can mint a new password on every oc process. If init is ever applied with overwrite, TEST/PROD lock out. Keep one-shot generation in the PR workflow only; merge must pass db_password.
1 parent b2a5edc commit 39fd99d

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎.github/workflows/.deploy.yml‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ on:
2121
type: string
2222

2323
secrets:
24+
db_password:
25+
description: Database password (required except on pull_request)
26+
required: false
2427
oc_namespace:
2528
description: OpenShift namespace
2629
required: true
@@ -42,8 +45,31 @@ jobs:
4245
triggered: ${{ steps.deploy.outputs.triggered }}
4346
runs-on: ubuntu-24.04
4447
steps:
48+
- name: Database password
49+
id: db
50+
env:
51+
EVENT_NAME: ${{ github.event_name }}
52+
DB_PASSWORD: ${{ secrets.db_password }}
53+
run: |
54+
if [ "${EVENT_NAME}" = "pull_request" ]; then
55+
password="$(openssl rand -hex 16)"
56+
if [ -z "${password}" ]; then
57+
echo "::error::openssl failed to generate a PR database password"
58+
exit 1
59+
fi
60+
else
61+
if [ -z "${DB_PASSWORD}" ]; then
62+
echo "::error::db_password GitHub secret is required for ${EVENT_NAME} deploys"
63+
exit 1
64+
fi
65+
password="${DB_PASSWORD}"
66+
fi
67+
echo "::add-mask::${password}"
68+
echo "password=${password}" >> "${GITHUB_OUTPUT}"
4569
- uses: bcgov/actions-openshift/deployer@75454b2b33edf37135f6f167775c77a3414207f6 # v0.3.0
4670
id: deploy
71+
env:
72+
DB_PASSWORD: ${{ steps.db.outputs.password }}
4773
with:
4874
file: common/openshift.init.yml
4975
oc_namespace: ${{ secrets.oc_namespace }}
@@ -53,7 +79,8 @@ jobs:
5379
# POSTGRES_PASSWORD after first boot; restamping the Secret desyncs Flyway.
5480
# New NetworkPolicy names still apply; existing NP specs do not update.
5581
overwrite: false
56-
parameters: -p ZONE="${{ inputs.target }}"
82+
parameters: -p DB_PASSWORD="$DB_PASSWORD"
83+
-p ZONE="${{ inputs.target }}"
5784
-p NAME="${{ github.event.repository.name }}"
5885
-p COMPONENT="backend-java"
5986
triggers: ${{ inputs.triggers }}

‎.github/workflows/merge.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
needs: [vars]
4343
uses: ./.github/workflows/.deploy.yml
4444
secrets:
45+
db_password: ${{ secrets.db_password }}
4546
oc_namespace: ${{ secrets.OC_NAMESPACE }}
4647
oc_token: ${{ secrets.OC_TOKEN }}
4748
with:
@@ -56,6 +57,7 @@ jobs:
5657
needs: [deploy-test, vars]
5758
uses: ./.github/workflows/.deploy.yml
5859
secrets:
60+
db_password: ${{ secrets.db_password }}
5961
oc_namespace: ${{ secrets.OC_NAMESPACE }}
6062
oc_token: ${{ secrets.OC_TOKEN }}
6163
with:

‎common/openshift.init.yml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ parameters:
1414
description: Deployment zone, e.g. pr-### or prod
1515
required: true
1616
- name: DB_PASSWORD
17-
description: Password for the PostgreSQL connection user. Generated on first process; overwrite=false keeps it.
18-
from: "[a-zA-Z0-9]{16}"
19-
generate: expression
17+
description: Password for the PostgreSQL connection user. Caller must pass it; never generated in this template.
18+
required: true
2019
objects:
2120
- apiVersion: v1
2221
kind: Secret

0 commit comments

Comments
 (0)