Repository navigation
feat(osx): run PostgreSQL 16 for the Mac's fleet account, yielding to its owner - #250
Conversation
… its owner mise installs the server in the fleet account. Its crontab starts it through the runners' starter, and a gate starts it only while the Mac is idle and stops it fast when the owner returns. Peer on a private socket, scram over localhost, password in the account's .pgpass.
A .pgpass line kept from a hand edit or an earlier task version could carry a short or empty password that the gate then applies on every start. The play now asserts the stored password is at least as long as the generated one.
A role or password step that failed right after the server started was never tried again until the next restart. The gate now repeats it on each pass until it succeeds once.
|
@cubic-dev-ai review this PR |
@inkatze cubic can't start this review because your workspace has reached its free monthly review limit. cubic has reviewed 40,041 of the 40,000 allowed lines of code this month. Reviews resume on 2 December 2026 (in 21 days). Paid plans include much higher monthly review limits. Upgrade now to resume reviews. To help optimise your usage, you can tune cubic to get the most out of your usage limits:
|
|
PR-Agent run 43618666473.1 on 1f2ee84: success |
PR Reviewer Guide 🔍(Review updated until commit 1f2ee84)Here are some key observations to aid the review process:
✅ Resolved findingsroles/osx/files/runner/postgres-gate.sh:42-46Incorrect .pgpass unescaping pgpass_password reverses pgpass escaping with two sed passes: first \ -> , then \: -> :. A password that literally contains a backslash followed by a colon is encoded in .pgpass as three backslashes and a colon (e.g. \\:).... roles/osx/files/runner/postgres-gate.sh:42-46Incorrect .pgpass unescaping pgpass_password reverses pgpass escaping with two sed passes: first \\ -> \, then \: -> :. A password that literally contains a backslash followed by a colon is encoded in .pgpass as three backslashes and a colon (e.g. \:). The first pass collapses the doubled backslash before the colon escape is handled, so the decoded password is corrupted. The gate then sets the role password to a different string than the one stored in ~/.pgpass, and psql reading .pgpass fails to authenticate over TCP. roles/osx/tasks/offload-postgres.yml:60-72Insecure ~/.pgpass permissions The lineinfile task that writes ~/.pgpass sets mode 0600 only when it creates the file. If a .pgpass already exists with looser permissions (for example from a hand edit or an earlier setup), those permissions are left unchanged, leaving the generated PostgreSQL password readable by group/other. Add a task that enforces 0600 on every run. |
The write sets the mode only when it runs, so an existing file that already held the role's line, or one edited loose by hand, kept its mode.
…to the PostgreSQL branch
…e superuser and mise-env prose; drop a vacuous kill check
|
Persistent review updated to latest commit 598916a |
|
Declined: the two-pass sed in |
|
Declined: an empty value cannot reach this check. |
|
Persistent review updated to latest commit 42b084d |
…ses as command-line options The gate starts PostgreSQL with these settings as options and writes no configuration file, so the no-managed-config guard exempts that one file.
…e config files A later write to pg_hba.conf or postgresql.conf from the gate would still fail the guard; the header and scope comments now name the exception.
… other config route The exemption now allows only that value and still rejects pg_hba, postgresql.conf and postgresql.auto.conf, ALTER SYSTEM, hba_file and config_file; widening the bound address fails the guard.
… option spellings
|
Persistent review updated to latest commit 497f431 |
Main added the Mac runner service and the offload git config; both sides changed the osx offload guard suite and the runner starter suite, so each conflict keeps both sides' checks. - osx-offload-guard-test.sh: the no-sudo sweep covers offload-postgres.yml and offload-git.yml; the postgres and git sections both stay. - runner-start-test.sh: main's caffeinate, work-directory and refresh checks come first, then the postgres prefix check. The prefix check waits for start 6, not 5: main's caffeinate stub execs "-i", so that start never logs, and the count stands at 5 when the postgres gate starts as the 6th.
…feinate above them The shared starter now runs every gate under caffeinate -i, so the pid file holds caffeinate, not the gate. The runner section already said to stop the gate too; the postgres and redis sections still told the operator to kill the pid file alone, which leaves the gate and its server running. Both now say so and note the gate holds off idle system sleep.
…when present The wrapper added to the starter means the pid file holds caffeinate, not the gate; the header still said it names the gate, inviting an edit to running() or a kill of the wrong process.
A pattern wrapped across a source line copies with a newline inside the quotes, so pkill matches nothing and says so silently.
|
@cubic-dev-ai review this PR |
@inkatze cubic can't start this review because your workspace has reached its free monthly review limit. cubic has reviewed 40,041 of the 40,000 allowed lines of code this month. Reviews resume on 2 December 2026 (in 19 days). Paid plans include much higher monthly review limits. Upgrade now to resume reviews. To help optimise your usage, you can tune cubic to get the most out of your usage limits:
|
|
Persistent review updated to latest commit 1f2ee84 |
Guard change for review
roles/osx/files/runner/postgres-gate.shis exempted from the "no PostgreSQL configuration" check inscripts/services-declaration-test.sh, which now scans it with a stricter, file-specific pattern. The gate passeslisten_addresses=localhostas a command-line option and writes no config file; the exemption allows only that exact value and still rejectspg_hba,postgresql.conf,postgresql.auto.conf,alter system, and the hba, config and ident file options.Merge after #258: both touch scripts/runner-start-test.sh; this PR syncs onto main once #258 lands.
Gives the Mac's fleet account a PostgreSQL 16 server for test suites, installed and run entirely inside that account, and stopping whenever the Mac's owner is using it.
What it does
postgresis pinned in the offload mise file next to the other tools, built from source with no icu, readline, openssl or uuid so it needs nothing from the owner's Homebrew. No sudo, nothing in the owner's account or settings.osx_postgres_data), created withinitdbonly when the directory has noPG_VERSION.runner-start.sh, now told by two variables which gate to run and what to name its pid file). A newpostgres-gate.shruns niced and does nothing if one is already running.~/.pgpass(0600, never printed or logged, kept if a line exists) and set on the role through a peer connection with the statement on stdin, so no process list shows it. The play fails if a stored password is shorter than the 32 characters it generates. Thefleetrole is created withcreateuser -sonly if missing, which covers any databases a suite creates.max_connectionsis sized from the Mac's cores, a partition count (default 4) and headroom, never below 100.How it yields to the owner
The gate starts the server only when the Mac is free by the runners' own rule: keyboard and mouse idle for the configured time and the one-minute load under the cap. When input arrives it runs
pg_ctl stop -m fast: sessions are disconnected and their open transactions rolled back, committed data is flushed, and nothing is killed mid-write. A test run in flight fails and is re-run. It starts again at the next idle check. Load alone never stops it, since a test run loads the Mac through the server it is using; this differs from the runner, which lets a running job finish.Checks
scripts/postgres-gate-test.sh(new) covers start, fast stop, load-only, role creation and password handling, and refused settings;runner-start-test.shcovers the new pid-file prefix;osx-offload-guard-test.shcovers the new tasks, including running the.pgpassexpressions through jinja2. All pass locally, with yamllint, ansible-lint and shellcheck.--checkand anything on the Mac itself (out of scope for this change; the Mac was in use). The build on the Mac, and peer authentication over the socket there, are unverified until the first run.Docs:
docs/offload-host.md, new PostgreSQL section, including how a suite connects over the socket or TCP.CI fix: the gate doubled single quotes in the role password with a bash 4 only escape, which bash 3.2 (the Mac's
/bin/bash) leaves as backslashes; it now uses a variable holding the quote.scripts/postgres-gate-test.shpasses on Linux and on the Mac under/bin/bash.Sync with main
Merged main into this branch (a merge commit) after the Mac runner service and the git config task landed. The only conflicts were two test suites, and both kept both sides' checks: the offload guard suite now sweeps
offload-postgres.ymlandoffload-git.ymlforbecomeand keeps the postgres and git sections, and the runner starter suite keeps main's caffeinate, work-directory and refresh checks before the postgres prefix check (which waits for the 6th logged start: main's caffeinate stub never logs one). The runner starter now wraps every gate incaffeinate -i, so the pid file names caffeinate; the docs now say to stop the postgres and redis gates withpkill -fas well, and the starter's header says so. Review: polish and panel-review (gemini) over the merge delta, PR-Agent as the bot review (cubic refused again on quota).Step records
Run
000001Steps at
pre-implementation(run000001)Ended on
488246ded015.Steps at
pre-ci(run000001)Ended on
17db4ba91fb1.Steps at
convergence(run000001)Ended on
4f51bc414934.Steps at
pre-pr(run000001)Ended on
4f51bc414934.Steps at
post-pr(run000001)Ended on
4f51bc414934.Run
000002Run
000003Steps at
pre-implementation(run000003)Ended on
851271d6494b.Steps at
convergence(run000003)Ended on
598916a0543c.Steps at
pre-pr(run000003)Ended on
598916a0543c.Steps at
post-pr(run000003)Ended on
598916a0543c.Run
000004Steps at
post-pr(run000004)Ended on
598916a0543c.Run
000005Steps at
pre-implementation(run000005)Ended on
598916a0543c.Steps at
pre-ci(run000005)Ended on
1a2d76fcd6a9.Steps at
convergence(run000005)Ended on
42b084d65956.Steps at
pre-pr(run000005)Ended on
42b084d65956.Run
000006Steps at
pre-implementation(run000006)Ended on
42b084d65956.Steps at
pre-ci(run000006)Ended on
e4f773ce0340.Steps at
convergence(run000006)Ended on
497f4314d22d.Steps at
pre-pr(run000006)Ended on
497f4314d22d.Steps at
post-pr(run000006)Ended on
497f4314d22d.Ended on
497f4314d22d.Run
000007Steps at
pre-implementation(run000007)Ended on
6a21df5a6458.Steps at
pre-ci(run000007)Ended on
6a21df5a6458.Steps at
convergence(run000007)Ended on
1f2ee84dc4cb.Steps at
pre-pr(run000007)Ended on
1f2ee84dc4cb.Steps at
post-pr(run000007)Ended on
1f2ee84dc4cb.Summary by cubic
Runs a PostgreSQL 16 server in the Mac's fleet account so test suites have a real database, installed and run entirely inside that account and stopping fast when the Mac's owner starts using it. It starts only while the Mac is free by the runners' idle rule; load alone never stops it, since a test run loads the Mac through the server it uses.
Access
~/.pgpassand set on the role through stdin (its escapes hold on the Mac's bash 3.2);~/.pgpassis held to 0600 on every run, and the play fails when a stored password is shorter.fleetrole is created as a superuser only when missing, in the same pass the server starts, so a client arriving as it opens finds it.Keeping it running
postgresis pinned in the offload mise file, built from source without icu, readline, openssl or uuid so it needs nothing from the owner's Homebrew; no sudo.RUNNER_GATEandRUNNER_PID_PREFIX; the gate keeps its pid and logs under its own prefix, runs from the account's home so the mise shim finds its config, and runs undercaffeinate -iso its idle waits are not cut short by system sleep.postgresas command-line options, and the no-managed-config guard exempts only that file and onlylisten_addresses=localhost, still rejectingpg_hba.conf,postgresql.conf,postgresql.auto.confandALTER SYSTEM.postgres-gate-test.shcovers start, fast stop, role creation and password handling; the runner-start, offload-guard and services-declaration suites were extended.docs/offload-host.mdgained a PostgreSQL section, including how to stop the server for good.Written for commit 1f2ee84. Summary will update on new commits.