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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user