Skip to content

build-pg-focal: build unprivileged so RUN_TESTS=1 can run initdb - #1243

Merged
Kemal Büyükkaya (kemalbuyukkaya) merged 1 commit into
developfrom
users/kbuyukkaya/fix-pg-focal-tests-as-root
Oct 11, 2026
Merged

Kemal Büyükkaya (kemalbuyukkaya) merged 1 commit into
developfrom
users/kbuyukkaya/fix-pg-focal-tests-as-root

Conversation

@kemalbuyukkaya

Copy link
Copy Markdown
Contributor

Problem

Dispatching Build PostgreSQL core (focal) with run_tests=1 fails for every major (run 37929345256):

initdb: error: cannot be run as root

The builder container runs as root, and dpkg-buildpackage ran as root too. initdb refuses root, so check-world (PG14–16: src/test/postmaster; PG13: src/test/regress) bailed out at the first initdb. The job stopped before signing.

Fix

scripts/build_pg_focal keeps root only for apt / mk-build-deps. Before [6/6] it:

  1. creates an unprivileged builder user (override with BUILD_USER),
  2. chowns ${WORK} to it,
  3. runs dpkg-buildpackage through runuser.

When the build isn't run as root, dpkg-buildpackage uses fakeroot automatically to package the files, as Debian intends. The .deb contents stay root:root.

This applies with or without tests, so a tested build exercises the same path an untested one ships.

Validation

Ran locally with podman, using the image built from dockerfiles/focal-pg-builder and RUN_TESTS=1:

Major TAP suites passed pg_regress suites passed Failures .debs
13 29 68 0 23
14 36 74 0 23
15 40 78 0 23
16 43 all 0 23
  • The .deb contents are owned by root:root.
  • The PG16 package set is identical to the last successful CI build (run 37928058376).

The builder container runs as root, and dpkg-buildpackage ran as root too.
initdb refuses to run as root, so with RUN_TESTS=1 every major's
check-world bailed out at its first initdb ("initdb: error: cannot be run
as root"), failing the build before signing.

Keep root for apt / mk-build-deps, then hand the tree to an unprivileged
"builder" user and run dpkg-buildpackage through runuser; it gains root
via fakeroot only to assemble the .debs, as Debian intends. Do this with
or without tests so a tested build exercises the same path an untested
one ships.

Validated locally (podman, PG16, RUN_TESTS=1): check-world passes and the
produced package set is identical to the last CI build, with root:root
ownership inside the .debs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused change addresses the root-only test failure while preserving the existing packaging and artifact workflow.

0 open findings

What changed in this PR

Updates the focal PostgreSQL builder so regression tests can run initdb without root privileges.

Changes:

  • Creates or selects an unprivileged build user.
  • Transfers work-directory ownership and runs dpkg-buildpackage via runuser.
  • Preserves root access for dependency installation and artifact collection.
File Description
scripts/​build_pg_focal Runs package compilation and tests as an unprivileged user with fakeroot packaging.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kemalbuyukkaya
Kemal Büyükkaya (kemalbuyukkaya) merged commit 0ed7ac5 into develop Oct 11, 2026
108 of 109 checks passed
@kemalbuyukkaya
Kemal Büyükkaya (kemalbuyukkaya) deleted the users/kbuyukkaya/fix-pg-focal-tests-as-root branch October 11, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants