Skip to content

Use the hardened image's Postgres client and allow choosing PGDG - #77914

Open
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:prefer-hardened-postgres-client
Open

potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:prefer-hardened-postgres-client

Conversation

@potiuk

@potiuk potiuk commented Dec 1, 2026

Copy link
Copy Markdown
Member

Image builds on the new hardened base images fail while installing the Postgres client, as seen on the v3-4-test CI-environment upgrade (#77855):

dpkg: error processing archive postgresql-client-common_297.pgdg13+1_all.deb:
  trying to overwrite '/usr/bin/clusterdb', which is also in package postgresql-client-18 (18.7-3+dhi)

The CI dev dependencies install the hardened repository's (dhi.io) postgresql-client-18, which puts psql, clusterdb etc. straight into /usr/bin. install_postgres.sh then adds PGDG at priority 1001, PGDG has moved to PostgreSQL 19, and its postgresql-client-common wrappers collide with those files.

The client now comes from the hardened repository by default, the one that follows the base image's security updates:

  • INSTALL_POSTGRES_CLIENT_SOURCE=hardened (default) installs the newest versioned dhi.io client. dhi.io's unversioned postgresql-client maps to postgresql-client-17, which leaves nothing on PATH. It falls back to PGDG when dhi.io has no client, the install fails, psql is not on PATH afterwards, or an earlier build already set the image up from PGDG.
  • INSTALL_POSTGRES_CLIENT_SOURCE=pgdg always installs PGDG's newest client, e.g. for a pg_dump that matches a newer server.
  • Before installing from PGDG, dhi.io clients with files on disk, including ones a failed install left unpacked or half-configured, are removed so the two never collide.

The new build arg is part of the OS-dependencies marker inputs and is documented in the build-arg reference. The pinned OS-dependencies images and regular builds both use the default, so their markers still match.

Testing:

  • scripts/tests/docker/test_install_postgres.py covers the client selection, the fallback triggers, the cleanup across dpkg states, and rejection of unknown sources, using stubbed apt/dpkg.
  • Manually, in containers on the new hardened base image (3.13, sha256:4faac7ac…): CI and PROD paths with both sources, legacy debian:trixie-slim, a dhi.io client left unpacked, a rebuild on a PGDG-configured image, and a simulated broken dhi.io package. The old script reproduces the clusterdb failure on the same image.
  • Not run locally: breeze build-docs docker-stack, because image builds are unavailable in my environment.

Once merged, the same change goes to v3-4-test so #77855 can build.

related: #77855


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Claude Opus 5)

Generated-by: Claude Code (Claude Opus 5) following the guidelines

Image builds on the new hardened base images fail: the CI dev dependencies
install dhi.io's postgresql-client-18, which puts psql and clusterdb straight
into /usr/bin, and then PGDG, now on PostgreSQL 19, tries to install
postgresql-client-common's wrappers at the same paths and dpkg refuses. The
hardened repository's client is the one meant to receive the base image's
security updates, so it is the better default; PGDG remains the fallback for
the legacy flavor or a broken dhi.io package, and stays available on request
for anyone who needs the newest client, e.g. a pg_dump matching a newer server.

Generated-by: Claude Opus 5

@aaron-y-chen aaron-y-chen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I built the CI image's OS-dependencies stage (--target ci-os-deps) locally, from scratch on the default hardened base image (3.14.10-debian13-dev, linux/arm64). From this PR's base commit it fails with the same conflict:

dpkg: error processing archive .../postgresql-client-common_297.pgdg13+1_all.deb (--unpack):
 trying to overwrite '/usr/bin/clusterdb', which is also in package postgresql-client-18 (18.7-3+dhi)

With this PR it builds: psql, pg_dump and pg_config are 18.7 from dhi.io, libpq5 and libpq-dev are 18.7-3+dhi, dpkg --audit is clean, and psycopg2 builds from source against that libpq-dev.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools area:production-image Production image improvements and fixes backport-to-v3-4-test Backport to v3-4-test kind:documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants