Repository navigation
Commit 40b2ecd
committed
fix: provision PostgreSQL as a non-root user (closes #984)
`mxcli run --local --ensure-db` could not provision PostgreSQL in a non-root
devcontainer. That is the environment mxcli itself generates: `mxcli init`
writes a devcontainer from mcr.microsoft.com/devcontainers/base:bookworm which
installs the postgresql server and runs as `vscode`, and wires
`run --local --setup --ensure-db` into the Claude Code SessionStart hook — so it
fired on every fresh session in an initialized project, not only when someone
typed the flag. Fixing it here rather than in the template also repairs projects
that have already been scaffolded.
Three independent defects sat on one path, each sufficient to block it:
- The service start was never elevated. Debian's /etc/init.d/postgresql runs
under `set -e` and calls create_socket_directory first, which chmods
/var/run/postgresql — refused for a non-root user, so the script aborts before
it looks at a single cluster. Now attempted with `sudo -n` first and
unprivileged second.
- The #823 user-owned-cluster fallback was inert on Debian and Ubuntu, which
wrap only the client tools into /usr/bin while initdb and pg_ctl live in
/usr/lib/postgresql/<major>/bin. The safety net for a failed service start
could never deploy on the platform that needs it most. Both tools are now
resolved from the same versioned directory, ranked numerically — a lexical
sort puts "9" above "16", and a data directory made by one major cannot be
started by another.
- The superuser was unreachable: `sudo -u postgres` is refused by the
devcontainer's own sudoers rule, `vscode ALL=(root) NOPASSWD:ALL`, which
permits root as the only target. Falls back to `sudo -n -- sudo -n -u
postgres`, since root may in turn target any account.
Everything stays non-interactive, so an unattended run cannot block on a
password prompt.
Separately, the readiness timeout discarded the service manager's own output,
which this package had already collected — the permission denial was in hand and
reported as a generic 20s timeout. A guard that names the wrong cause costs the
reader more than no guard at all, so the diagnostics now travel with the error.
Measured on Ubuntu 24.04 / PostgreSQL 16 with a real non-root user and the real
sudoers rule, against a harness calling EnsureDatabase directly: the shipped
build fails with `exec: "initdb": executable file not found in $PATH` and, once
the cluster is up, `no local PostgreSQL superuser available`; after the fix the
sudo path provisions in 2.6s and the no-sudo user-cluster path in 7.2s. Each of
the four fixes was reverted individually and its test re-run against the
reported symptom.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dp1syGhH8yr7Hve2wwjzqg1 parent 5071aa4 commit 40b2ecd
5 files changed
Lines changed: 393 additions & 44 deletions
File tree
- .claude/skills
- fix-issue/findings
- mendix/run-local
- cmd/mxcli/docker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
11 | 21 | | |
12 | 22 | | |
13 | 23 | | |
| |||
0 commit comments