Skip to content

Commit e93ce4a

Browse files
authored
fix: remove hard-coded default Postgres credentials from config (#501)
## Summary - Removes default `ogx` values for `POSTGRES_DB`, `POSTGRES_USER`, and `POSTGRES_PASSWORD` from `build/build.yaml` so the distributed config ships with empty defaults, forcing operators to supply credentials explicitly (CWE-798) - Adds `postgres_user`, `postgres_password`, `postgres_db` inputs (defaulting to `ogx`) to the `setup-postgres` and `setup-server` CI actions so existing tests continue using the same credentials - Parameterizes hard-coded `psql -U ogx -d ogx` calls in `tests/smoke.sh` to use shell variable expansion with `ogx` fallback defaults ## Test plan - [ ] `pre-commit run --all-files` passes (verified locally) - [ ] CI smoke tests pass (setup-postgres and setup-server actions supply `ogx` via input defaults) - [ ] CI integration tests pass (smoke.sh shell defaults fall back to `ogx`) - [ ] Deployers who relied on image defaults will now need to explicitly set `POSTGRES_DB`, `POSTGRES_USER`, and `POSTGRES_PASSWORD` env vars 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents c6da989 + bcdd090 commit e93ce4a

6 files changed

Lines changed: 57 additions & 29 deletions

File tree

.github/actions/setup-postgres/action.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
name: Setup PostgreSQL
22
description: Start PostgreSQL for ogx
3+
4+
inputs:
5+
postgres_user:
6+
description: 'PostgreSQL user'
7+
default: 'ogx'
8+
postgres_password:
9+
description: 'PostgreSQL password'
10+
default: 'ogx'
11+
postgres_db:
12+
description: 'PostgreSQL database name'
13+
default: 'ogx'
14+
315
runs:
416
using: "composite"
517
steps:
618
- name: Start PostgreSQL
719
shell: bash
20+
env:
21+
PG_USER: ${{ inputs.postgres_user }}
22+
PG_PASSWORD: ${{ inputs.postgres_password }}
23+
PG_DB: ${{ inputs.postgres_db }}
824
run: |
925
docker run -d \
1026
--name postgres \
1127
--net=host \
12-
-e POSTGRES_USER=ogx \
13-
-e POSTGRES_PASSWORD=ogx \
14-
-e POSTGRES_DB=ogx \
28+
-e "POSTGRES_USER=${PG_USER}" \
29+
-e "POSTGRES_PASSWORD=${PG_PASSWORD}" \
30+
-e "POSTGRES_DB=${PG_DB}" \
1531
pgvector/pgvector:pg17
1632
1733
# Wait for PostgreSQL to be ready
1834
echo "Waiting for PostgreSQL to be ready..."
1935
postgres_ready=false
2036
for i in {1..30}; do
21-
if docker exec postgres pg_isready -U ogx -d ogx; then
37+
if docker exec postgres pg_isready -U "${PG_USER}" -d "${PG_DB}"; then
2238
echo "PostgreSQL is ready!"
2339
postgres_ready=true
2440
break
@@ -36,7 +52,7 @@ runs:
3652
# pg_isready returns true before the database is fully initialized, so retry.
3753
echo "Enabling pgvector extension..."
3854
for i in {1..10}; do
39-
if docker exec postgres psql -U ogx -d ogx -c "CREATE EXTENSION IF NOT EXISTS vector;" 2>/dev/null; then
55+
if docker exec postgres psql -U "${PG_USER}" -d "${PG_DB}" -c "CREATE EXTENSION IF NOT EXISTS vector;" 2>/dev/null; then
4056
echo "pgvector extension enabled"
4157
break
4258
fi

.github/actions/setup-server/action.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ inputs:
1616
description: 'Volume mounts for docker run (one host:container:mode per line)'
1717
required: false
1818
default: ''
19+
postgres_user:
20+
description: 'PostgreSQL user'
21+
default: 'ogx'
22+
postgres_password:
23+
description: 'PostgreSQL password'
24+
default: 'ogx'
25+
postgres_db:
26+
description: 'PostgreSQL database name'
27+
default: 'ogx'
1928

2029
runs:
2130
using: "composite"
@@ -27,22 +36,25 @@ runs:
2736
IMAGE_TAG: ${{ inputs.image_tag }}
2837
INPUT_EXTRA_ENV: ${{ inputs.extra_env }}
2938
INPUT_VOLUMES: ${{ inputs.volumes }}
39+
PG_USER: ${{ inputs.postgres_user }}
40+
PG_PASSWORD: ${{ inputs.postgres_password }}
41+
PG_DB: ${{ inputs.postgres_db }}
3042
run: |
3143
docker pull "$IMAGE_NAME:$IMAGE_TAG"
3244
3345
docker_args=(
3446
-d --net=host --name ogx
3547
--env "POSTGRES_HOST=localhost"
3648
--env "POSTGRES_PORT=5432"
37-
--env "POSTGRES_DB=ogx"
38-
--env "POSTGRES_USER=ogx"
39-
--env "POSTGRES_PASSWORD=ogx"
49+
--env "POSTGRES_DB=${PG_DB}"
50+
--env "POSTGRES_USER=${PG_USER}"
51+
--env "POSTGRES_PASSWORD=${PG_PASSWORD}"
4052
--env "ENABLE_PGVECTOR=1"
4153
--env "PGVECTOR_HOST=localhost"
4254
--env "PGVECTOR_PORT=5432"
43-
--env "PGVECTOR_DB=ogx"
44-
--env "PGVECTOR_USER=ogx"
45-
--env "PGVECTOR_PASSWORD=ogx"
55+
--env "PGVECTOR_DB=${PG_DB}"
56+
--env "PGVECTOR_USER=${PG_USER}"
57+
--env "PGVECTOR_PASSWORD=${PG_PASSWORD}"
4658
--env "TRUSTYAI_LMEVAL_USE_K8S=False"
4759
)
4860

Containerfile

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/build.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,17 @@ storage:
221221
type: kv_postgres
222222
host: ${env.POSTGRES_HOST:=localhost}
223223
port: ${env.POSTGRES_PORT:=5432}
224-
db: ${env.POSTGRES_DB:=ogx}
225-
user: ${env.POSTGRES_USER:=ogx}
226-
password: ${env.POSTGRES_PASSWORD:=ogx}
224+
db: ${env.POSTGRES_DB:=}
225+
user: ${env.POSTGRES_USER:=}
226+
password: ${env.POSTGRES_PASSWORD:=}
227227
table_name: ${env.POSTGRES_TABLE_NAME:=ogx_kvstore}
228228
sql_default:
229229
type: sql_postgres
230230
host: ${env.POSTGRES_HOST:=localhost}
231231
port: ${env.POSTGRES_PORT:=5432}
232-
db: ${env.POSTGRES_DB:=ogx}
233-
user: ${env.POSTGRES_USER:=ogx}
234-
password: ${env.POSTGRES_PASSWORD:=ogx}
232+
db: ${env.POSTGRES_DB:=}
233+
user: ${env.POSTGRES_USER:=}
234+
password: ${env.POSTGRES_PASSWORD:=}
235235
stores:
236236
metadata:
237237
backend: kv_default

distribution/config.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/smoke.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function test_postgres_tables_exist {
175175

176176
# Retry for up to 10 seconds for tables to be created
177177
for i in {1..10}; do
178-
tables=$(docker exec postgres psql -U ogx -d ogx -t -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public';" 2>/dev/null | tr -d ' ' | tr '\n' ' ')
178+
tables=$(docker exec postgres psql -U "${POSTGRES_USER:-ogx}" -d "${POSTGRES_DB:-ogx}" -t -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public';" 2>/dev/null | tr -d ' ' | tr '\n' ' ')
179179
all_found=true
180180
for table in "${expected_tables[@]}"; do
181181
if ! echo "$tables" | grep -q "$table"; then
@@ -195,7 +195,7 @@ function test_postgres_tables_exist {
195195
echo "===> PostgreSQL tables not created after 10s :("
196196
echo "Expected tables: ${expected_tables[*]}"
197197
echo "Available tables: $tables"
198-
docker exec postgres psql -U ogx -d ogx -c "\dt" || true
198+
docker exec postgres psql -U "${POSTGRES_USER:-ogx}" -d "${POSTGRES_DB:-ogx}" -c "\dt" || true
199199
return 1
200200
}
201201

@@ -205,7 +205,7 @@ function test_postgres_populated {
205205
# Check that chat_completions table has data (retry for up to 10 seconds)
206206
echo "Waiting for inference_store table to be populated..."
207207
for i in {1..10}; do
208-
inference_count=$(docker exec postgres psql -U ogx -d ogx -t -c "SELECT COUNT(*) FROM inference_store;" 2>/dev/null | tr -d ' ')
208+
inference_count=$(docker exec postgres psql -U "${POSTGRES_USER:-ogx}" -d "${POSTGRES_DB:-ogx}" -t -c "SELECT COUNT(*) FROM inference_store;" 2>/dev/null | tr -d ' ')
209209
if [ -n "$inference_count" ] && [ "$inference_count" -gt 0 ]; then
210210
echo "===> inference_store table has $inference_count record(s)"
211211
break
@@ -216,9 +216,9 @@ function test_postgres_populated {
216216
if [ -z "$inference_count" ] || [ "$inference_count" -eq 0 ]; then
217217
echo "===> PostgreSQL inference_store table is empty or doesn't exist after 10s :("
218218
echo "Tables in database:"
219-
docker exec postgres psql -U ogx -d ogx -c "\dt" || true
219+
docker exec postgres psql -U "${POSTGRES_USER:-ogx}" -d "${POSTGRES_DB:-ogx}" -c "\dt" || true
220220
echo "inference_store table contents:"
221-
docker exec postgres psql -U ogx -d ogx -t -c "SELECT COUNT(*) FROM inference_store;" || true
221+
docker exec postgres psql -U "${POSTGRES_USER:-ogx}" -d "${POSTGRES_DB:-ogx}" -t -c "SELECT COUNT(*) FROM inference_store;" || true
222222
return 1
223223
fi
224224

0 commit comments

Comments
 (0)