Repository navigation
Create the data directory so only this user can read it - #123
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andcreate_dir_allagainst 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 onD:\do not come along. Inheriting the one that grantsUsersread 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.
COand 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_allon 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 forTHINKWATCH_HOMEpointed somewhere likeD:\ThinkWatch, where the default grantsUsersread.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 anunnecessary_castbefore pushing, which is the same lint that got through last time when the cross-check was only runningcargo 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