From 6c864c5959efe1132713ea206c88a9d3dd43bec6 Mon Sep 17 00:00:00 2001 From: "smart-ssh-coder[bot]" <338317697+smart-ssh-coder[bot]@users.noreply.github.com> Date: Sat, 5 Dec 2026 05:23:26 +0000 Subject: [PATCH 1/2] docs(adr): record data directory trust check decisions (#1749) Co-Authored-By: Claude Sonnet 5.5 --- ...66-data-directory-trust-check-decisions.md | 48 +++++++++++++++++++ docs/adr/INDEX.md | 1 + 2 files changed, 49 insertions(+) create mode 100644 docs/adr/0166-data-directory-trust-check-decisions.md diff --git a/docs/adr/0166-data-directory-trust-check-decisions.md b/docs/adr/0166-data-directory-trust-check-decisions.md new file mode 100644 index 000000000..84a44e63e --- /dev/null +++ b/docs/adr/0166-data-directory-trust-check-decisions.md @@ -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: they are shown where the app cannot yet rely on the translated UI (a refused override can prevent the instance from starting) and are logged for support; they carry no user data. +- Consequence: they are not localised. If the startup screen gets localisation for this error, the reasons become stable codes with texts in the UI layer. +- Rejected: translation keys now. The i18n layer is not available at that point of startup and the key set would have to be kept in sync with the check. + +## Consequences + +- The check only ever errs on the strict side; every relaxation above is justified by "no weaker than what the same principal can do anyway". +- Changing any of these four points loosens or changes the trust boundary and needs a new ADR that supersedes this one. diff --git a/docs/adr/INDEX.md b/docs/adr/INDEX.md index 2e0cbf769..ac8db08ea 100644 --- a/docs/adr/INDEX.md +++ b/docs/adr/INDEX.md @@ -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) | From 0f2e32962020bca66e6dd39275ff82b7683593cb Mon Sep 17 00:00:00 2001 From: "smart-ssh-coder[bot]" <338317697+smart-ssh-coder[bot]@users.noreply.github.com> Date: Sat, 5 Dec 2026 05:39:36 +0000 Subject: [PATCH 2/2] docs(adr): correct ADR 0166 decision 4 rationale and consequences (#1749) Co-Authored-By: Claude Sonnet 5.5 --- docs/adr/0166-data-directory-trust-check-decisions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/adr/0166-data-directory-trust-check-decisions.md b/docs/adr/0166-data-directory-trust-check-decisions.md index 84a44e63e..aaa062a01 100644 --- a/docs/adr/0166-data-directory-trust-check-decisions.md +++ b/docs/adr/0166-data-directory-trust-check-decisions.md @@ -38,11 +38,11 @@ Only access-allowed entries (plain, callback and object variants) count; deny an The reasons carried by `DataDirError` are plain English text, not translation keys. -- Rationale: they are shown where the app cannot yet rely on the translated UI (a refused override can prevent the instance from starting) and are logged for support; they carry no user data. -- Consequence: they are not localised. If the startup screen gets localisation for this error, the reasons become stable codes with texts in the UI layer. -- Rejected: translation keys now. The i18n layer is not available at that point of startup and the key set would have to be kept in sync with the check. +- 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 -- The check only ever errs on the strict side; every relaxation above is justified by "no weaker than what the same principal can do anyway". +- 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.