Connect from libpq service files and match the real Secret layout

The maintainer's login Secrets carry pg_service.conf ([evolution]),
pgpass and ca.crt. Add a strict read_pg_service (known keys only,
verify-full unless a local socket, bounded size) behind --pg-service in
evo-server and evo-world-clone, mount each login Secret whole in the
store Jobs instead of reading aevolution-db, and fix the migrate Job's
PGSERVICE to the [evolution] section. Record the store node choice,
per-environment databases and the backup plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-29 14:12:26 -04:00
co-authored by Claude Opus 5.5
parent 2d950060db
commit 8d594f28af
12 changed files with 221 additions and 31 deletions
+32
View File
@@ -26,7 +26,39 @@ std::string env(const char* key) {
throw std::runtime_error("missing test environment");
return value;
}
// M8.3: libpq service files are read strictly (section, keys, TLS mode, size).
void service_files() {
const auto path = env("PGHOST") + "/service-test.conf";
const auto parse = [&](const std::string& text, std::string_view section = "evolution") {
std::FILE* f = std::fopen(path.c_str(), "wb");
CHECK(f != nullptr);
CHECK(std::fwrite(text.data(), 1, text.size(), f) == text.size());
CHECK(std::fclose(f) == 0);
return read_pg_service(path, section);
};
auto good = parse("# comment\n[other]\nhost=elsewhere\n[evolution]\r\nhost=pg-forge-01\n"
"hostaddr=172.10.1.127\nport=5432\ndbname=aevolution\n"
"user=aevolution_runtime_dev\nsslmode=verify-full\n"
"sslrootcert=/run/postgres/ca.crt\nconnect_timeout=5\n");
CHECK(good && good->host == "pg-forge-01" && good->hostaddr == "172.10.1.127" &&
good->port == "5432" && good->database == "aevolution" &&
good->user == "aevolution_runtime_dev" && good->ca_file == "/run/postgres/ca.crt" &&
good->password_file.empty());
const std::string base = "[evolution]\nhost=h\nhostaddr=10.0.0.1\nport=1\ndbname=d\nuser=u\n";
for (const std::string& bad :
{base + "password=secret\n", base + "passfile=/x\n", base + "sslmode=require\n",
base + "options=-cx\n", base + "user=again\n", base + "[evolution]\nhost=h\n",
base + "connect_timeout=soon\n", base + "no-equals-sign\n", std::string("[evolution\n"),
std::string("[elsewhere]\nhost=h\n"), base + std::string(5000, '#')})
CHECK(!parse(bad) && parse(bad).error() == PgError::config);
CHECK(parse("[evolution]\nhost=/var/run\nsslmode=disable\n")); // Local socket only.
CHECK(!parse("[evolution]\nhost=remote\nsslmode=disable\n"));
CHECK(!read_pg_service(env("PGHOST") + "/no-such-file", "evolution"));
std::remove(path.c_str());
}
void run() {
service_files();
PgOptions options{env("PGHOST"), {}, env("PGPORT"), env("PGDATABASE"), env("PGUSER"), {}, {}};
auto made = Postgres::connect(options, 5s);
CHECK(made);
+15
View File
@@ -162,6 +162,21 @@ void check_store_qualifies_the_stores() {
const auto other = fresh("store-check-full");
auto full = check_store(other, runtime, {"--reserve-mib", "1048576"}, code);
CHECK(code == 4 && has(full, "probe refused full"));
// The same check through a libpq service file, as the cluster Jobs run it.
const auto service = root / "pg_service.conf";
{
std::FILE* f = std::fopen(service.c_str(), "wb");
CHECK(f != nullptr);
const auto text = "[evolution]\nhost=" + env("PGHOST") + "\nport=" + env("PGPORT") +
"\ndbname=" + env("PGDATABASE") + "\nuser=" + runtime +
"\nsslmode=disable\nconnect_timeout=5\n";
CHECK(std::fwrite(text.data(), 1, text.size(), f) == text.size());
CHECK(std::fclose(f) == 0);
}
Child via_service{{env("EVO_WORLD_CLONE_BIN"), "check-store", "--world", "7", "--region", "84",
"--pg-service", service.string(), "--objects", root.string()}};
CHECK(via_service.wait_exit(30s) == 0 && via_service.printed("probe verified digest=") &&
via_service.printed("database tables=denied functions=reachable"));
// An owner login can read tables: not an acceptable runtime identity.
auto owner_run = check_store(root, env("PGUSER"), {}, code);
CHECK(code == 3 && has(owner_run, "database tables=READABLE"));