fix(setup): keep the generated database password out of config.toml

This commit is contained in:
sam committed 2026-10-06 01:55:37 +11:00
1 parent 1d02c7e3e6
commit 17b6fa7245
2 files changed
+7 -6

No files matched your search

+2 -2
View File
@@ -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.
@@ -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
}