Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/adr/0166-data-directory-trust-check-decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ADR 0166 — Data directory trust check: deliberate decisions

## Status

Accepted · Issue: #1749 · Follow-up of #1717 (PR #1734) · Spec 0115

## Context

A data directory override (and the pointer file that names it) holds everything of an instance: database, host keys, settings, key wrapping file. It only takes effect when other local accounts cannot place or change it. The trust check in `crates/persistence-sqlite/src/data_dir_trust.rs` refuses an override that others can modify, and never falls back to another directory. Four choices the spec leaves open were made on purpose and are recorded here.

## Decision

### 1. An Administrators-owned data directory is accepted on Windows

The owner must be the current user, or Administrators, SYSTEM or TrustedInstaller. There is no check of whether the current user is a member of Administrators.

- Rationale: an elevated process creates files owned by Administrators, and those principals can rewrite any ACL anyway, so an Administrators owner adds no attack surface beyond what an administrator already has. The DACL check (no write/modify/delete/ownership rights for Everyone, Authenticated Users, Users, Guests, Anonymous) still applies.
- Rejected: requiring group membership of the current user. It would refuse a legitimate directory created from an elevated shell and needs a token group lookup that can fail in more ways. It would not stop an administrator, who can take ownership regardless.
- Rejected: accepting only the current user as owner. It breaks the elevated-install case with no gain in protection.

### 2. A symlinked data directory is followed and the target is checked

The data directory is resolved through symbolic links; ownership and permissions are checked on the target. The pointer file itself must not be a symbolic link and must be a regular file.

- Rationale: users commonly place data on another volume via a link; the target is what holds the data and what another account would have to change. A link in the directory path does not widen access when the target passes the check. The pointer file is a single small file the app reads before anything else, so a link there would let whoever controls the link target redirect the instance.
- Rejected: refusing symlinked data directories. It breaks a common setup without making anything safer, since the target is checked anyway.
- Rejected: checking only the link. Link permissions say nothing about who can change the data.

### 3. Deny ACEs are ignored on Windows

Only access-allowed entries (plain, callback and object variants) count; deny and audit entries are skipped.

- Rationale: a deny entry can only remove access, so ignoring it can only make the check stricter, never weaker. Evaluating it would need a full effective-rights computation (ordering, inheritance, token groups) that is easy to get wrong in the permissive direction.
- Consequence: a directory protected only by a deny entry for a broad group, with a matching allow entry, is refused although effectively unwritable. The user can fix the ACL; the refusal is the safe side.
- Rejected: computing effective access (e.g. via `AccessCheck`). More code and more failure modes in a security check for no safety gain.

### 4. Refusal reasons are English strings

The reasons carried by `DataDirError` are plain English text, not translation keys.

- Rationale: `persistence-sqlite` has no language input, and the existing `DataDirError` reasons are English already. The startup error window is localised (English and German), but only its frame; the reason text inside stays English.
- Consequence: a refusal shows an English reason inside a localised dialog. Refusals are not logged, because the data directory is resolved before logging is initialised.
- Rejected: stable codes with English and German texts in `data_dir_error_messages`, so the reason could be localised in the UI layer. It would need a code set kept in sync with the check; it can be done later without changing the decisions above.

## Consequences

- Each of the four decisions is justified by "no weaker than what the same principal can do anyway" or errs on the strict side. This does not make the whole check strict: Spec 0115 §4.1 documents known limits (a group-writable directory is accepted on Unix; on Windows only the five broad groups listed above are checked).
- Changing any of these four points loosens or changes the trust boundary and needs a new ADR that supersedes this one.
1 change: 1 addition & 0 deletions docs/adr/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,4 @@
| 0163 | License change Apache-2.0 → GPL-3.0-only | Accepted | [0163-license-change-gpl-3-0-only.md](0163-license-change-gpl-3-0-only.md) |
| 0164 | ONNX Runtime license texts are committed, not taken from a crate | Accepted | [0164-onnx-runtime-license-texts-committed.md](0164-onnx-runtime-license-texts-committed.md) |
| 0165 | AI provider kinds contributed by the embedding application | Accepted | [0165-ai-provider-kinds-from-the-embedding-app.md](0165-ai-provider-kinds-from-the-embedding-app.md) |
| 0166 | Data directory trust check: deliberate decisions | Accepted | [0166-data-directory-trust-check-decisions.md](0166-data-directory-trust-check-decisions.md) |