From 8ef0f40dc3df8fb873e3a67891cb417f5c8e1d7f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 6 Oct 2026 01:55:37 +1100 Subject: [PATCH] fix(setup): keep the generated database password out of config.toml --- docker-compose.yml | 4 ++-- internal/infrastructure/configuration/setup/setup.go | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 017f516df..5769c8b5d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,9 +25,9 @@ services: image: postgres:18 environment: POSTGRES_USER: archie - # archied setup generates this into ~/.config/archie/env; the fallback is + # archied setup generates PGPASSWORD into ~/.config/archie/env; the fallback is # the dev password deployments/dev.toml uses. - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-archie} + POSTGRES_PASSWORD: ${PGPASSWORD:-archie} POSTGRES_DB: archie # postgres:18 moved its default PGDATA under a versioned path; pin the # classic location so the named volume keeps working across image updates. diff --git a/internal/infrastructure/configuration/setup/setup.go b/internal/infrastructure/configuration/setup/setup.go index 42a82b75e..5c7f9a83f 100644 --- a/internal/infrastructure/configuration/setup/setup.go +++ b/internal/infrastructure/configuration/setup/setup.go @@ -144,8 +144,9 @@ func RunParams(ctx context.Context, p Prompter, discovery ModelDiscovery, secret } // stepDatabase returns the PostgreSQL URL. A blank answer on a fresh install -// means the bundled Compose database with a generated password, which goes to -// the env file as POSTGRES_PASSWORD for Compose to initialise it with. +// means the bundled Compose database with a generated password. The password +// goes only to the env file as PGPASSWORD, which pgx and Compose both read, so +// config.toml holds no secret. func stepDatabase(ctx context.Context, p Prompter, secrets SecretSink, existing, param string) (string, error) { if strings.TrimSpace(param) != "" { return param, nil @@ -166,8 +167,8 @@ func stepDatabase(ctx context.Context, p Prompter, secrets SecretSink, existing, return "", fmt.Errorf("setup: generate database password: %w", err) } password := hex.EncodeToString(pw) - if err := secrets.Put("env", "POSTGRES_PASSWORD", password); err != nil { + if err := secrets.Put("env", "PGPASSWORD", password); err != nil { return "", fmt.Errorf("setup: store database password: %w", err) } - return "postgres://archie:" + password + "@127.0.0.1:5432/archie?sslmode=disable", nil + return "postgres://archie@127.0.0.1:5432/archie?sslmode=disable", nil }