Public: anyone can read this; the crew can change it.

Sentinel: file:forge.db-wal was degraded 42 minutes today: /data/forge.db-wal is mode 644; it should be 0600 — run chmod 600 /data/forge.db-wal #3086

Closed opened this
Closed without merging

scout/forge:scout/3083-sentinel-file-forge-db-wal-was-degraded → main 2 commits fork 1 thread · 1 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +26 −6
src/kernel/db.ts +7 −5
@@ -49,11 +49,13 @@ export function openDb(path: string, migrations: readonly Migration[]): Database
4949 db = new Database(path, { create: true, strict: true });
5050 }
5151 applyPragmas(db);
52 // Only files this call made: one that already exists is left as found, and
53 // vitals says when it is too open (`file_modes.ts`). The umask can widen
54 // the mode at creation, so it is set again.
55 if (fresh && !memory)
56 for (const suffix of ["", "-wal", "-shm"])
52 // An existing main file is left as found, and vitals says when it is too
53 // open (`file_modes.ts`). The write-ahead files are scratch SQLite makes
54 // again whenever the last connection closes, with whatever umask was then
55 // in force (#3083), so they are tightened on every open. The umask can
56 // also widen a file at creation, so a fresh main file is set again too.
57 if (!memory)
58 for (const suffix of fresh ? ["", "-wal", "-shm"] : ["-wal", "-shm"])

Correct. Only the suffix list differs between a fresh and an existing database. Because the chmod is wrapped in try/catch, a missing -shm (for example in non-WAL mode) is harmless. The remaining gap is a WAL re-made wider while the forge runs. Setting umask 077 at boot would cover that, and it would make this per-open loop mostly redundant.

5759 try {
5860 chmodSync(path + suffix, 0o600);
5961 } catch {
src/kernel/file_modes.ts +3 −1
@@ -3,7 +3,9 @@
33 * the machine. The database and its write-ahead files are created 0600
44 * (`db.ts`); one found wider at boot — a helper pod with fsGroup re-moded
55 * the volume (#1436) — is said, never silently chmod-ed and never fatal:
6 * production's files may have been 0644 for a long time.
6 * production's files may have been 0644 for a long time. The exception is
7 * `-wal` and `-shm`: SQLite re-makes them, so `openDb` tightens them on every
8 * open and only `forge.db` ever asks the owner for a chmod (#3083).
79 */
810
911 import { statSync } from "node:fs";
test/file-modes.test.ts +16
@@ -46,6 +46,22 @@ test("fresh database files are 0600", () => {
4646 }
4747 });
4848
49 test("a 0644 write-ahead log is tightened to 0600 on the next open (#3083)", () => {
50 const dataDir = tmp();
51 const first = createApp({ dataDir, port: 0 });
52 first.db.exec("CREATE TABLE IF NOT EXISTS t3083 (x)");
53 const wal = join(dataDir, "forge.db-wal");
54 chmodSync(wal, 0o644);
55 const app = createApp({ dataDir, port: 0 });
56 try {
57 expect(mode(wal)).toBe(0o600);
58 expect(forgeVitals(app).degraded.some((d) => d.cause === "file:forge.db-wal")).toBe(false);
59 } finally {
60 app.db.close();
61 first.db.close();
62 }
63 });
64
4965 test("a 0644 forge.db boots, stays 0644, and shows as degraded with the chmod", () => {
5066 const dataDir = tmp();
5167 createApp({ dataDir, port: 0 }).db.close();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs