recipe_alpine_postgres.ts view source
(options: AlpinePostgresSetupOptions): AlpinePostgresSetupScript import {alpine_postgres_setup} from '@fuzdev/zap/recipe_alpine_postgres.js'; Build the postgres-cluster-init script's check/run for Alpine.
run initializes the data cluster via the OpenRC setup action (Alpine's
apk install does not, unlike Debian's apt), then closes the trust rules
that action's initdb writes into the new pg_hba.conf: local lines become
peer (the OS account named like the role) and host lines scram-sha-256 (a
password), so no account on the machine connects as any role, postgres
included, without a credential. Debian's cluster starts with those methods. The
rewrite runs as postgres, which owns the file and its directory (sed -i stages
its copy there), and the script fails if a trust rule is left. A
server already running is told to reload (rc-service --ifstarted), so the new
rules are in force.
check passes once the cluster's PG_VERSION marker exists and its pg_hba.conf
holds no trust rule. So a run that failed after setup is retried on the next
apply, and that run skips setup (the cluster is there) and goes straight to the
rewrite; a cluster set up before this recipe, trust rules and all, is rewritten
the same way.
A client that relied on a trust rule stops connecting. Every trust line in the
file is rewritten, not only initdb's: a service that reaches PostgreSQL over TCP
with no password is refused once the rewrite is in force, and one on the socket is
admitted only as the OS account named like its role. Move such a client to the
socket as its own account (fuz_app_env_base's DATABASE_URL), or give it a
password, before this runs on an existing cluster. Sequence it before the
postgresql service (the setup action requires the server stopped) and before any
zap.database.
options
returns
AlpinePostgresSetupScript the script check/run pair.