Secret files: harden the open-recording tests and read_secret_file #42

Open
opened 2026-11-13 12:49:38 +00:00 by svc-agent-writer · 1 comment

Two reviews of PR #41 (issue #33, head 269ae77) found no blocker. They found the items below. None of them is a regression from #41.

The open-recording tests (tests/test_config_cli.py)

  1. The negative tests have no positive control. They assert that a secret path is not in the recording. If a later change makes the config resolve paths differently (for example /var against /private/var), the recorded string differs from str(secret) and the test passes without proving anything. Fix: in the same recording, assert that a file the verb does read (the key file) is recorded.
  2. The recorder compares exact strings. An open through dir_fd, a relative path, a symlink or a .. form escapes it. Fix: compare os.path.realpath on both sides, or compare (st_dev, st_ino).
  3. The audit hook sees only opens made in Python. An open in C (the SQLCipher library, a subprocess, a native extension) raises no open event. Say "opens made in Python" in the invariant, or add a check that covers those opens.
  4. No runtime test covers the guard in sync.py:252-254 (a None salt). Only mypy covers it. Add a test: sync_once with salt=None prints secret=error code=secret-missing at=store.tombstone_salt_file and returns 2.

read_secret_file (src/messages_mind_mcp/kit/secrets.py:21), from before #41

  1. os.open has no O_NOFOLLOW, so a secret path that is a symlink is followed.
  2. Nothing checks that the file owner is the process user (st_uid == os.geteuid()). A process that runs as root accepts a 0600 file that another user owns.
  3. os.open has no O_NONBLOCK. A FIFO at a secret path blocks the open before the regular-file check runs.

Fix sketch: open with O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC, then check S_ISREG, the mode and the owner on the descriptor.

Documents

  1. The README table and the api verb line say "never". Add one sentence under the table that points to the caveat in SECURITY.md: this is what the code does, not a permission boundary.
  2. When the directory of the Feeder token cannot be listed, api still stops with secret-dir-unlistable. This fails closed, but the README does not say it.
  3. tombstone_salt_file is required in every config, so a host that runs only api must still hold the salt file for check to pass. Least privilege holds per process, not per host. Decide whether the salt becomes optional on a host with no sync, or whether check takes a verb.

Decisions

  • Item 10: check takes an optional verb (api or sync) and opens only the secret files of that verb, from startup.SECRET_FILE_VERBS. Without a verb, check opens every secret file that the config names, as today. The config schema does not change.

Acceptance criteria

  • Each negative test asserts a positive control, and the recorder compares resolved paths.
  • read_secret_file refuses a symlink, a FIFO and a file that another user owns. A test proves each refusal.
  • A test covers the sync guard for a None salt.
  • The README and SECURITY.md state items 3, 8 and 9.
  • check with a verb opens only the secret files of that verb. A test proves it for each verb.

Human act

ruling: the operator sets svd:go to approve dispatch of this credential-path change (CONV-40)

Blocked by

  • none

Filed under: operator word "Grant" sha256:78b7d0379d5e

Two reviews of PR #41 (issue #33, head `269ae77`) found no blocker. They found the items below. None of them is a regression from #41. ## The open-recording tests (`tests/test_config_cli.py`) 1. The negative tests have no positive control. They assert that a secret path is **not** in the recording. If a later change makes the config resolve paths differently (for example `/var` against `/private/var`), the recorded string differs from `str(secret)` and the test passes without proving anything. Fix: in the same recording, assert that a file the verb does read (the key file) **is** recorded. 2. The recorder compares exact strings. An open through `dir_fd`, a relative path, a symlink or a `..` form escapes it. Fix: compare `os.path.realpath` on both sides, or compare `(st_dev, st_ino)`. 3. The audit hook sees only opens made in Python. An open in C (the SQLCipher library, a subprocess, a native extension) raises no `open` event. Say "opens made in Python" in the invariant, or add a check that covers those opens. 4. No runtime test covers the guard in `sync.py:252-254` (a `None` salt). Only mypy covers it. Add a test: `sync_once` with `salt=None` prints `secret=error code=secret-missing at=store.tombstone_salt_file` and returns 2. ## `read_secret_file` (`src/messages_mind_mcp/kit/secrets.py:21`), from before #41 5. `os.open` has no `O_NOFOLLOW`, so a secret path that is a symlink is followed. 6. Nothing checks that the file owner is the process user (`st_uid == os.geteuid()`). A process that runs as root accepts a `0600` file that another user owns. 7. `os.open` has no `O_NONBLOCK`. A FIFO at a secret path blocks the open before the regular-file check runs. Fix sketch: open with `O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC`, then check `S_ISREG`, the mode and the owner on the descriptor. ## Documents 8. The README table and the `api` verb line say "never". Add one sentence under the table that points to the caveat in `SECURITY.md`: this is what the code does, not a permission boundary. 9. When the directory of the Feeder token cannot be listed, `api` still stops with `secret-dir-unlistable`. This fails closed, but the README does not say it. 10. `tombstone_salt_file` is required in every config, so a host that runs only `api` must still hold the salt file for `check` to pass. Least privilege holds per process, not per host. Decide whether the salt becomes optional on a host with no `sync`, or whether `check` takes a verb. ## Decisions - Item 10: `check` takes an optional verb (`api` or `sync`) and opens only the secret files of that verb, from `startup.SECRET_FILE_VERBS`. Without a verb, `check` opens every secret file that the config names, as today. The config schema does not change. ## Acceptance criteria - Each negative test asserts a positive control, and the recorder compares resolved paths. - `read_secret_file` refuses a symlink, a FIFO and a file that another user owns. A test proves each refusal. - A test covers the `sync` guard for a `None` salt. - The README and `SECURITY.md` state items 3, 8 and 9. - `check` with a verb opens only the secret files of that verb. A test proves it for each verb. ## Human act ruling: the operator sets `svd:go` to approve dispatch of this credential-path change (CONV-40) ## Blocked by - none --- Filed under: operator word "Grant" sha256:78b7d0379d5e
Author
Member

This was generated by AI during triage.

Triage

  • Confirmed on main: read_secret_file opens without O_NOFOLLOW or O_NONBLOCK, and it does not check the file owner.
  • The Blocked by #33 edge is removed: #33 closed when #41 merged.
  • The operator ruled item 10: check takes a verb. The body records it under ## Decisions. Option (b), an optional salt, would change the config schema; (a) is additive.
  • CONV-40 rule 2 fires (bounded), and rule 3 also fires, because this code reads credentials. Rule 3 overrides rule 2. State: ready-for-human. The human act is the operator's dispatch approval (svd:go).

Brief

Category: bug
Summary: read_secret_file refuses a symlink, a FIFO and a file that another user owns; the open-recording tests prove what they claim; check takes a verb.

Why a human gates it: the change is on the path that reads every secret file. The design is settled; the operator approves the dispatch.

Current behavior:

  • read_secret_file follows a symlink, blocks on a FIFO before its regular-file check, and accepts an owner-only file that another user owns.
  • The negative open-recording tests assert only that a path is absent. A change in path form (for example /var against /private/var) makes them pass without proof.
  • check opens every secret file that the config names, so a host that runs only api must hold the salt file.

Desired behavior:

  • read_secret_file opens with O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC. On the descriptor it checks S_ISREG, the owner-only mode, and st_uid == os.geteuid(). Each refusal has a coded error.
  • Each negative open-recording test also asserts a positive control: a file that the verb does read is recorded. The recorder compares resolved paths.
  • The invariant says "opens made in Python", or a check covers opens made outside Python.
  • A test covers the sync guard for a None salt: the output is secret=error code=secret-missing at=store.tombstone_salt_file and the status is 2.
  • check api and check sync open only the secret files of that verb. check without a verb keeps today's behavior.
  • The README and SECURITY.md state items 3, 8 and 9 of the body.

Key interfaces:

  • read_secret_file in the Kit secrets module, and its error codes.
  • startup.SECRET_FILE_VERBS, the map from a verb to its secret files.
  • The check verb of the CLI.

Acceptance criteria: the list in the body.

Out of scope:

  • The Swift Feeder's token checks (#9).
  • The deploy files of #18. After this change, #18 can run check api in the api container without the salt.
> *This was generated by AI during triage.* ## Triage - Confirmed on `main`: `read_secret_file` opens without `O_NOFOLLOW` or `O_NONBLOCK`, and it does not check the file owner. - The `Blocked by #33` edge is removed: #33 closed when #41 merged. - The operator ruled item 10: `check` takes a verb. The body records it under `## Decisions`. Option (b), an optional salt, would change the config schema; (a) is additive. - CONV-40 rule 2 fires (bounded), and rule 3 also fires, because this code reads credentials. Rule 3 overrides rule 2. State: `ready-for-human`. The human act is the operator's dispatch approval (`svd:go`). ## Brief **Category:** bug **Summary:** `read_secret_file` refuses a symlink, a FIFO and a file that another user owns; the open-recording tests prove what they claim; `check` takes a verb. **Why a human gates it:** the change is on the path that reads every secret file. The design is settled; the operator approves the dispatch. **Current behavior:** - `read_secret_file` follows a symlink, blocks on a FIFO before its regular-file check, and accepts an owner-only file that another user owns. - The negative open-recording tests assert only that a path is absent. A change in path form (for example `/var` against `/private/var`) makes them pass without proof. - `check` opens every secret file that the config names, so a host that runs only `api` must hold the salt file. **Desired behavior:** - `read_secret_file` opens with `O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC`. On the descriptor it checks `S_ISREG`, the owner-only mode, and `st_uid == os.geteuid()`. Each refusal has a coded error. - Each negative open-recording test also asserts a positive control: a file that the verb does read is recorded. The recorder compares resolved paths. - The invariant says "opens made in Python", or a check covers opens made outside Python. - A test covers the `sync` guard for a `None` salt: the output is `secret=error code=secret-missing at=store.tombstone_salt_file` and the status is `2`. - `check api` and `check sync` open only the secret files of that verb. `check` without a verb keeps today's behavior. - The README and `SECURITY.md` state items 3, 8 and 9 of the body. **Key interfaces:** - `read_secret_file` in the Kit secrets module, and its error codes. - `startup.SECRET_FILE_VERBS`, the map from a verb to its secret files. - The `check` verb of the CLI. **Acceptance criteria:** the list in the body. **Out of scope:** - The Swift Feeder's token checks (#9). - The deploy files of #18. After this change, #18 can run `check api` in the api container without the salt.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/messages-mind-mcp#42
No description provided.