mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-12 02:02:13 +03:00
Incident 2026-07-05 on the self-hosted release runner (VM 113): the integration test 'POST /cert: installs trust when cert exists' exercised the REAL install path, wrote a 105-byte fake PEM (FakeMITMCertForTestingOnly) into /usr/local/share/ca-certificates and update-ca-certificates baked the invalid entry into ca-certificates.crt — breaking ALL system TLS on the VM (curl error 77, apt cert failures, and the intermittent gzip-corrupted next-build artifacts that failed 6/9 e2e shards in run 28754447912). Hosted runners are ephemeral, so the same mutation went unnoticed for months. - installCert/uninstallCert: skip the OS dispatch under OMNIROUTE_SKIP_SYSTEM_TRUST=1 — AFTER the input checks, so the #4546 environment-skip contract (missing file throws -> structured skip) and the already-installed/not-installed early returns are preserved. - installTproxyCa/uninstallTproxyCa: same guard, only when no run dep is injected (DI'd tests keep exercising the full command sequence with mocks). - tests/_setup/isolateDataDir.ts sets the env for every node:test process; ci.yml/quality.yml/nightly-release-green.yml set it workflow-wide (e2e runs the real app outside the test setup). TDD: tests/unit/system-trust-test-guard.test.ts (guard exported to every test process; guarded install resolves on a real file without touching the OS; missing-file contract preserved). 82/82 across the affected cert/tproxy/ agent-bridge suites.
43 lines
2.0 KiB
TypeScript
43 lines
2.0 KiB
TypeScript
// Guard: the test suite must NEVER touch the OS trust store. On 2026-07-05 the
|
|
// integration test "POST /cert: installs trust when cert exists" ran the REAL
|
|
// install path on a persistent self-hosted runner and wrote a 105-byte fake PEM
|
|
// into /usr/local/share/ca-certificates — update-ca-certificates then baked the
|
|
// invalid entry into ca-certificates.crt and broke ALL system TLS on the VM
|
|
// (curl error 77, apt cert failures, corrupted artifact downloads). Hosted
|
|
// runners are ephemeral, so the same write went unnoticed for months.
|
|
//
|
|
// OMNIROUTE_SKIP_SYSTEM_TRUST=1 (set globally in tests/_setup/isolateDataDir.ts)
|
|
// makes installCert/uninstallCert no-ops before any filesystem/spawn work.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { installCert } from "../../src/mitm/cert/install.ts";
|
|
|
|
test("isolateDataDir setup exports the system-trust guard for every test process", () => {
|
|
assert.equal(process.env.OMNIROUTE_SKIP_SYSTEM_TRUST, "1");
|
|
});
|
|
|
|
test("installCert under the guard skips the OS mutation but keeps input contracts", async () => {
|
|
// Contract preserved: a missing cert file still throws (agent-bridge fallback
|
|
// #4546 depends on it to build the environment-skip result).
|
|
await assert.rejects(() => installCert("", "/nonexistent/omniroute-guard-test.pem"));
|
|
|
|
// With a REAL (fake-content) cert file, the un-guarded path would go on to
|
|
// sudo/update-ca-certificates — under the guard it must resolve without
|
|
// mutating the OS trust store (this exact write bricked the VM's TLS).
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-trust-guard-"));
|
|
const pem = path.join(dir, "omniroute-guard-test.pem");
|
|
fs.writeFileSync(
|
|
pem,
|
|
"-----BEGIN CERTIFICATE-----\nMIIBpDCCAQ2gAwIBAgIUFakeGuardCertXX==\n-----END CERTIFICATE-----\n"
|
|
);
|
|
try {
|
|
await installCert("", pem);
|
|
} finally {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|