Repository navigation
Description
Goal
The settings that control safety behaviour and the list of trusted host keys get the same protection at rest as the rest of the app data: changing them on disk without the database key is either impossible or detected, instead of silently weakening confirmations or pre-trusting a host key.
Context
Spec 0101 encrypts the whole database with SQLCipher (page-level authentication with the database key). Two files next to it are plain JSON and are read without any integrity check (THREAT-MODEL.md section 3, table "Where data lives"; section 6 "Plaintext outside the database"):
settings.json(tauri-plugin-store) holds the keys listed as security keys incrates/app-shell/src/ui_preferences.rs:11-21:redRiskAlwaysConfirm,riskClassifierEnabled,riskClassifierProviderId,localServerTags,elevatedIdleTimeoutMinutes, and everymcpServer*key (mcpServerEnabled,mcpServerAllowedServerIds,mcpServerConfirmTimeoutSecs;crates/app-shell/src/mcp_settings.rs:28-36). They are read e.g. incrates/app-shell/src/risk_second_opinion.rs:51,225andcrates/app-shell/src/elevated_sftp/idle.rs:27. Editing the file flips these switches without the app noticing.host_keys.json(FileHostKeyStore::load,crates/app-logic/src/host_key_store.rs:137-158; written atomically with mode 0600,:219-241, ADR 0012) holds the trusted keys per host and port. An entry added to the file is trusted on the next connection without the host key dialog.
Today the threat model scopes encryption at rest to "someone who gets a copy of the data directory" and excludes malware running as the user. The weakness here is a party that can write these files but does not have the database key (a shared or synced data directory, a restored backup copy, another account where permissions allow it). The data directory ownership check is a separate issue (see Related Work).
Requirements
- Decided by maintainer: the security settings and the known host keys move into the encrypted database (integrity from SQLCipher, no new crypto). A one-time migration reads them from
settings.json/host_keys.json, writes them to the database, reads them back, compares, then removes them from the files and records "moved" in the database, following the MCP token move (Spec 0101 A12). Afterwards the files are never read for these values again. Milestone stays 0.8.1. - Security settings: one store in the database for the keys in
SECURITY_KEYS/SECURITY_KEY_PREFIXES(crates/app-shell/src/ui_preferences.rs); every reader and writer of these keys goes through it. Other UI preferences stay insettings.json. - Host keys:
HostKeyStoreimplementation backed by the database, same semantics asFileHostKeyStore(lookup per host, port and algorithm; replace on "trust anyway"; data change notifications, issue Data-changed event: one coalesced notification after committed changes to the data set #672;entries()for the backup snapshot). - The one-time migration is idempotent, with a "done" marker in the database; write, read back, compare, then remove from the file; a failure before "done" leaves the file untouched and is retried next start.
- After "done", a value for these keys found in
settings.json, or ahost_keys.jsonfile, is not read; it is logged once atwarn(without values) and the stale data is removed. - THREAT-MODEL.md section 3 table and section 6, Spec 0101 (new item next to A12), ADR 0012 superseded note.
Acceptance Criteria
- Test: start with security keys in
settings.jsonand no "done" marker → values in the database, removed from the file, marker set. - Test: after the marker is set, editing
redRiskAlwaysConfirmtofalseinsettings.jsonhas no effect on the effective setting. - Test: start with
host_keys.json→ entries in the database (same fingerprints), file removed or emptied, marker set; a laterhost_keys.jsonwith an extra entry does not make that host trusted. - Test: migration failure (injected write error) leaves
settings.jsonandhost_keys.jsonunchanged and no marker. - Existing host key tests (unknown, mismatch, trust anyway, jump hops, auto-reconnect) pass unchanged against the database store.
- Encrypted backup export/import round-trip still includes the host keys and the security settings.
- Relevant automated tests pass.
Technical Notes
- Security-critical: host key trust (Spec 0005, ADR 0012), confirmation settings, MCP allowlist. No path may trust a host key or relax a setting on a read error; a failing database read is an error, never "no setting" / "no known hosts".
- Data model change: new migration in
crates/persistence-sqlite. - Check the start-up order (Spec 0101, start sequence steps 1–9): every reader of these keys must run after the database is unlocked. A reader that runs earlier today (e.g. MCP auto-start) moves behind the unlock.
Files: crates/persistence-sqlite/src/ (migration, new stores), crates/app-logic/src/host_key_store.rs, crates/app-logic/src/backup/, crates/app-shell/src/ui_preferences.rs, crates/app-shell/src/risk_second_opinion.rs, crates/app-shell/src/mcp_settings.rs, crates/app-shell/src/elevated_sftp/idle.rs, crates/app-shell/src/local_server.rs, crates/app-shell/src/lib.rs, THREAT-MODEL.md, docs/specs/0101-database-encryption.md, docs/adr/
Spec impact: update 0101
Open questions
- Split into two pull requests (settings, host keys) if the change does not fit one run: settings first, host keys second. Recommended only if needed.
Related Work
- Integrity of local data at rest against modification without the database key #1720 (epic: integrity of local data at rest)
- Data directory override: refuse a pointer file or data directory that other users can modify #1717 (data directory ownership check)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity