Give the local index and its export copy an explicit 0600 mode #188

Merged
clawbot merged 1 commits from issue-168-index-file-mode into next 2026-09-22 13:12:07 +02:00
Collaborator

Closes #168.

The local index lists every backed-up path and chunk hash, but its file mode was left to the SQLite driver and the umask. Under a typical 022 umask a fresh index — and the -wal/-shm files SQLite creates alongside it — landed world-readable, and the snapshot export copied the index to snapshot.db with the same permissive default.

What changed

  • provideDatabase now calls a new ensureIndexFileMode before opening the driver: it creates the index 0600 if missing and chmods an existing one to 0600, failing explicitly on error.
  • The export copy in snapshot.copyFile is now created 0600 via OpenFile instead of the umask-dependent Create.

What the diff does not show

The ordering is load-bearing: SQLite gives its -wal and -shm side files the mode of the main database file, so the mode must be set on the main file before the driver opens it — hence pre-creating the file in provideDatabase rather than chmodding after New. SQLite treats the resulting zero-byte file as an empty database, so pre-creating it is safe.

copyFile has a single production caller (the export), so tightening it there does not affect anything else.

Tests run under umask 022 and assert 0600 for a fresh index, an existing 0644 index in a 0755 directory, and the export copy. They use //nolint:paralleltest because syscall.Umask is process-global.

make check passes.

Model: opus-4-8

Closes https://git.eeqj.de/sneak/vaultik/issues/168. The local index lists every backed-up path and chunk hash, but its file mode was left to the SQLite driver and the umask. Under a typical 022 umask a fresh index — and the `-wal`/`-shm` files SQLite creates alongside it — landed world-readable, and the snapshot export copied the index to `snapshot.db` with the same permissive default. ## What changed - `provideDatabase` now calls a new `ensureIndexFileMode` before opening the driver: it creates the index `0600` if missing and chmods an existing one to `0600`, failing explicitly on error. - The export copy in `snapshot.copyFile` is now created `0600` via `OpenFile` instead of the umask-dependent `Create`. ## What the diff does not show The ordering is load-bearing: SQLite gives its `-wal` and `-shm` side files the mode of the main database file, so the mode must be set on the main file *before* the driver opens it — hence pre-creating the file in `provideDatabase` rather than chmodding after `New`. SQLite treats the resulting zero-byte file as an empty database, so pre-creating it is safe. `copyFile` has a single production caller (the export), so tightening it there does not affect anything else. Tests run under umask 022 and assert `0600` for a fresh index, an existing `0644` index in a `0755` directory, and the export copy. They use `//nolint:paralleltest` because `syscall.Umask` is process-global. `make check` passes. Model: opus-4-8
clawbot added the needs-review label 2026-09-22 13:00:47 +02:00
clawbot self-assigned this 2026-09-22 13:00:47 +02:00
clawbot added 1 commit 2026-09-22 13:00:47 +02:00
The local index lists every backed-up path and chunk hash, but its file
mode was left to the SQLite driver and the umask, so under a typical 022
umask a fresh index (and its -wal/-shm side files) landed world-readable.
The snapshot export copied the index to snapshot.db with a permissive
create as well.

provideDatabase now calls ensureIndexFileMode before opening the driver:
it creates the index 0600 if missing and chmods an existing one to 0600.
Doing this before the driver opens the file matters because SQLite gives
its -wal and -shm files the mode of the main database file. The export
copy is now created 0600 instead of via the umask-dependent default.

Tests under umask 022 cover a fresh index, an existing 0644 index in a
0755 directory, and the export copy, asserting each ends up 0600.

Model: opus-4-8
Author
Collaborator

PASS

Model: opus-4-8

PASS Model: opus-4-8
clawbot merged commit 548a7ae156 into next 2026-09-22 13:12:07 +02:00
clawbot deleted branch issue-168-index-file-mode 2026-09-22 13:12:07 +02:00
Sign in to join this conversation.