agent-archive
aien-dev/agent-archive
Brought by drakestapleton
agent-archive / AUDIT_SCOPE.md
| 1 | # Audit scope |
| 2 | |
| 3 | Written for an outside, independent security audit. Revision described: |
| 4 | `e102eb6bf3434b0f510c595cbaad097c9e29a1ca` on `main`, 2026-10-26. Everything below is taken from the repository's own files at |
| 5 | that revision; items marked NOT_RUN were not executed while writing this document. |
| 6 | |
| 7 | ## What this repository is |
| 8 | |
| 9 | A single Rust binary that collects AI agent chats (Claude Code, Codex, OpenCode, Gemini or |
| 10 | Antigravity, Muse) on one host into plain JSONL records plus a verbatim raw mirror of the source |
| 11 | files. The only network access is a read-only `ssh` and `scp` pull from a second machine reached |
| 12 | through an ssh host alias. The repository holds the collector (`src/main.rs` 492 lines, |
| 13 | `src/collectors.rs` 351, `src/core.rs` 370, `src/pb.rs` 86) and three small fixtures |
| 14 | (`tests/fixtures/{claude,codex,muse}.jsonl`). The archive itself is outside the repository. Status: |
| 15 | in use. Licence AGPL-3.0-or-later. |
| 16 | |
| 17 | ## What to review, in priority order |
| 18 | |
| 19 | 1. `src/core.rs` private-file layer: `private_check`, `private_metadata`, `private_dir`, |
| 20 | `private_existing_dir`, `private_open`, `private_read_to_string`, `private_file`, |
| 21 | `private_append`, `private_copy`, `atomic_write`. README: archive directories `0700`, files |
| 22 | `0600`; symlinks, foreign owners and group or other access are refused on reads and writes. |
| 23 | Check for time-of-check to time-of-use gaps between the metadata check and the open, and that |
| 24 | every write path goes through these helpers. `libc` is used only for the effective user ID. |
| 25 | 2. `pull_macbook` in `src/collectors.rs`. Runs `ssh` with `BatchMode=yes`, `ConnectTimeout=5`, |
| 26 | and a ControlMaster socket at `/tmp/agent-archive-mac-%C`, executes a fixed remote `find ... stat` |
| 27 | script, then parses each output line by splitting on spaces into four fields (subdirectory, |
| 28 | path, size, mtime). The first field and the file name from the remote path are joined into the |
| 29 | local destination under `raw/gemini/macbook/`, and the remote path is passed to |
| 30 | `scp macbook:{path}`. Check: whether a hostile or compromised remote can choose a destination |
| 31 | outside the mirror (for example a first field containing `..`), whether remote paths are |
| 32 | interpreted by the remote shell during `scp`, and the use of a shared `/tmp` control socket path. |
| 33 | 3. Parsers: `parse_<agent>` in `src/collectors.rs`; protobuf decoding `fields` in `src/pb.rs` |
| 34 | (Gemini step blobs, field numbers inferred, not from a schema). Check bounds on varints and |
| 35 | length-delimited fields and behaviour on truncated input. |
| 36 | 4. SQLite access (OpenCode database, Gemini per-conversation `.db`): opened read-only per AGENTS.md. |
| 37 | Check the open flags and that copies are made before parsing live files. |
| 38 | 5. `Store` in `src/core.rs`: de-duplication on `(agent, host, session, role, src.path, src.pos)`, |
| 39 | state cursors in `state/<agent>.json`, `latest/` views rewritten with temp file plus rename. |
| 40 | `Record::date` slices `ts[..10]`; check that every `ts` reaching it is normalised. |
| 41 | 6. `query` in `src/main.rs`: takes a user regex (`--grep`) over archive records; check regex |
| 42 | resource limits. |
| 43 | 7. `tests/fixtures/`: confirm no secrets, host names, home paths or private conversation content |
| 44 | (AGENTS.md rule). |
| 45 | |
| 46 | `.github/workflows/ci.yml` (added by the audit-readiness change) runs `cargo build --locked |
| 47 | --all-targets` and `cargo test --locked` on a GitHub-hosted runner and publishes an SPDX SBOM |
| 48 | artifact; actions pinned by commit sha, read-only token. |
| 49 | |
| 50 | ## Trust boundaries |
| 51 | |
| 52 | - Untrusted input: the contents of agent chat stores (JSONL, SQLite, protobuf blobs), which hold |
| 53 | model and user text; the remote listing and files returned by the ssh pull. |
| 54 | - Trusted: the local user account that owns the archive root, the local ssh configuration and its |
| 55 | keys (not in the repository), OpenSSH and the bundled SQLite. |
| 56 | - Sensitive output: the archive holds full chat transcripts. README: raw chat never goes into |
| 57 | Cortex; only short digests and a pointer. |
| 58 | |
| 59 | ## Threat model summary |
| 60 | |
| 61 | - Assets: confidentiality of the archived transcripts; integrity of source chat stores. |
| 62 | - Attackers considered: another local user who tries to read the archive or swap a path with a |
| 63 | symlink; malformed source files; the remote machine in the pull. |
| 64 | - Defended: private modes and ownership checks on every archive path, with refusal instead of |
| 65 | silent fallback; read-only opens of source stores; `BatchMode=yes` ssh. |
| 66 | - Not defended / explicitly out of scope: a compromised local account that owns the archive; |
| 67 | the protobuf format is inferred and may mis-parse; README notes Mac `-shm` files are not pulled, |
| 68 | so uncommitted remote data may be missed. No encryption at rest is implemented. |
| 69 | |
| 70 | ## Build from source at a pin |
| 71 | |
| 72 | Needs a Rust toolchain (version not pinned; no `rust-toolchain.toml`). `rusqlite` 0.32 builds its |
| 73 | bundled SQLite, so no system SQLite is needed (AGENTS.md). `Cargo.lock` is committed (63 packages). |
| 74 | |
| 75 | ```sh |
| 76 | cargo build --release |
| 77 | ``` |
| 78 | |
| 79 | ## Run every test |
| 80 | |
| 81 | NOT_RUN while writing this document. |
| 82 | |
| 83 | ```sh |
| 84 | cargo test --release |
| 85 | ``` |
| 86 | |
| 87 | The unit tests live in the `tests` module of `src/main.rs` (15 `#[test]` functions), including |
| 88 | parser tests on the fixtures, a synthetic Gemini step, an OpenCode database the test builds itself, |
| 89 | incremental passes and de-duplication after state loss, the capped `latest` window, private modes |
| 90 | under a permissive umask, and refusal of unsafe roots, descendants, state files, duplicate records, |
| 91 | history records, and `query` or `status` on unsafe paths. Expected: `test result: ok`. |
| 92 | |
| 93 | `collect`, `once`, `status`, `query` and `debug-pb` read real chat stores and write the archive; |
| 94 | AGENTS.md says to run them only on the machine the archive belongs to. NOT_RUN on a plain host. |
| 95 | `once --no-mac` skips the ssh pull. |
| 96 | |
| 97 | ## Known limitations and NOT_RUN |
| 98 | |
| 99 | - Gemini protobuf field numbers are UNVERIFIED (README). |
| 100 | - The ssh pull path has no unit test. |
| 101 | - Deployed binary and on-disk permissions are not established by this repository (README). |
| 102 | - Existing archives created before the permission checks need a manual repair (README gives |
| 103 | `find` and `chmod` commands). |
| 104 | |
| 105 | ## Dependencies and provenance |
| 106 | |
| 107 | - `Cargo.lock` present. Direct dependencies: `serde_json` 1, `rusqlite` 0.32 (bundled SQLite), |
| 108 | `chrono` 0.4, `regex` 1, `libc` 0.2 (README: locked at 0.2.190). |
| 109 | - Fetched from crates.io at build time. |
| 110 | - At run time: `ssh` and `scp` for the optional pull. |
| 111 | - No GitHub Actions. No vendored code beyond the SQLite bundled by `rusqlite`. |
| 112 | |
| 113 | ## Evidence |
| 114 | |
| 115 | No receipts are stored in this repository. Archive records are append-only by design (AGENTS.md: |
| 116 | "Records are append-only ... Losing state may cause re-reads but never duplicates"). |