Skip to content

Create the data directory so only this user can read it - #123

Merged
fylorn merged 1 commit into
mainfrom
feat/windows-private-dir
Sep 23, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/windows-private-dir

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

The configuration holds API keys in plain text — this file has never pretended otherwise, and there is no keychain.

On unix what protects them is each file's own 0600. The directory being 0755 only lets someone list names, and create_dir_all against a default umask produces 0755 anyway — tightening it there would lock out every existing user on their next start.

Windows has no mode bits. A file's permissions are inherited from the directory, which makes the directory's ACL the whole of that protection. That asymmetry is why this has one real implementation and a no-op.

Set at creation, not audited afterwards

This reverses what the plan originally recorded, and the reason is that I had the costs backwards.

Auditing can only refuse to start — the problem stays where it is and the user has to go fix an ACL by hand. And doing it accurately means walking the DACL, comparing every ACE against the Everyone / Users / Authenticated Users SIDs, and decoding access masks: more than twice this code, to achieve less.

The SDDL, entry by entry

D:P(A;OICI;FA;;;<user>)(A;OICI;FA;;;SY)

  • D:P — a protected DACL, so entries on D:\ do not come along. Inheriting the one that grants Users read is precisely what this exists to prevent.
  • OICI — passes both entries down to the files inside, which is where the keys actually are.
  • SY — SYSTEM alongside the user, or backup and indexing services start reporting errors on the directory.

The SID comes from the process token rather than an SDDL shorthand. CO and friends are placeholders meant for inheritable entries; on an object's own DACL they do not stand for "whoever created this".

One creation site

The lock file, the control-plane socket and the token file each call create_dir_all on their way past. Whoever gets there first decides the ACL — which is to say, decides whether another user on the machine can read the keys. So the directory is now created in exactly one place, before anything else touches it.

Scope

Default locations were already fine: %APPDATA% sits under the user's profile and inherits a restrictive ACL. This is for THINKWATCH_HOME pointed somewhere like D:\ThinkWatch, where the default grants Users read.

It does not touch a directory that already exists. No Windows release has shipped, so there is nothing existing yet; covering that case would be the startup audit this deliberately avoids.

Verified

Host: clippy clean, full suite green, smoke 53/0, three new tests (creates it, creating an existing one is not an error and does not disturb its contents, missing parents are created).

Windows: this module is self-contained, so it cross-checks against both MSVC targets with cargo clippy --all-targets -- -D warnings — the flags CI uses. That caught an unnecessary_cast before pushing, which is the same lint that got through last time when the cross-check was only running cargo check.

The ACL itself is not asserted anywhere. Reading it back would mean writing the DACL walk this PR argues against, and a CI runner's own token is not representative. It is reasoned, not measured — saying so rather than implying otherwise.

🤖 Generated with Claude Code

The configuration holds API keys in plain text -- this file has never
pretended otherwise, and there is no keychain. On unix what protects them
is each file's own `0600`; the directory being 0755 only lets someone list
names, and `create_dir_all` against a default umask produces 0755 anyway,
so tightening it there would lock out every existing user on their next
start.

Windows has no mode bits. A file's permissions are inherited from the
directory, which makes the directory's ACL the whole of that protection.
That asymmetry is why this has one implementation and a no-op.

It is set when the directory is created rather than audited afterwards.
Auditing can only refuse to start -- the problem stays where it is and the
user has to go fix an ACL -- and doing it accurately means walking the
DACL, comparing every ACE against the Everyone / Users / Authenticated
Users SIDs and decoding access masks, which is more than twice this code.

`D:P` makes the DACL protected, so the entries on `D:\` do not come along;
inheriting the one that grants `Users` read is precisely what this exists
to prevent. `OICI` passes the two entries down to the files inside. SYSTEM
gets full access alongside the user, or backup and indexing services start
reporting errors on the directory.

The SID comes from the process token rather than an SDDL shorthand.
`CO` and friends are placeholders meant for inheritable entries; on an
object's own DACL they do not stand for "whoever created this".

The directory is created in exactly one place, before anything else
touches it. The lock, the control-plane socket and the token file all call
`create_dir_all` on their way past, and whoever gets there first decides
the ACL -- which is to say, decides whether another user on the machine
can read the keys.

Default locations were already fine: `%APPDATA%` sits under the user's
profile and inherits a restrictive ACL. This is for `THINKWATCH_HOME`
pointed somewhere like `D:\ThinkWatch`, where the default grants `Users`
read. It does not touch a directory that already exists -- no Windows
release has shipped, so there is nothing existing yet; covering that would
be the startup check this deliberately avoids.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 2941d72 into main Sep 23, 2026
1 check passed
@fylorn
fylorn deleted the feat/windows-private-dir branch September 23, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant