Expand description
Pinned, symlink-refusing write handles beneath <project>/.trusty-code/
(#7779).
Why: super::check_native_write_target answers “is this a legal write
target?”
against the filesystem as it looked when it was called. Every caller then
wrote through the same path STRING, so a directory swapped for a symlink at
any component between the two was followed and the write landed outside the
project — measured at 6 of 40 real tcode deploys against a 4 ms
skill-refs -> victim swap loop (#7779, PR #7773 review). A check a rename
can overtake is not a boundary.
What: NativeWriteDir opens the target directory ONCE, descending from the
canonical project root one component at a time with O_NOFOLLOW, and keeps
the resulting directory descriptor. Every later read, write, rename and lock
is openat-relative to that descriptor, so the kernel resolves it against
the pinned inode instead of re-walking the path — a symlink swapped in
afterwards cannot redirect it. Each write then re-checks the handle’s
identity against the path (NativeWriteDir::verify_pinned) so a swap
surfaces as a typed WriteTargetError::Unpinned instead of a deploy that
silently wrote into a directory nothing will ever read.
The write-boundary contract itself is unchanged: ADR-0044 restricts writes to
the product’s own configuration directory, and [super::anchor_native_root]
still decides membership. It decides it ONCE, and the path it returns is the
path pinned — a writer never re-resolves .trusty-code, so there is no
second answer for a rename to substitute (#7779 round 2).
§Symlinks beneath the config root are refused, never followed
Every entry this handle touches is opened O_NOFOLLOW, READS included. A
symlinked agents/pm.md, skill-refs/<skill>/SKILL.md or ledger is a typed
WriteTargetError::Unpinned that fails the whole deploy, where the
pre-#7779 code followed it and treated the target’s bytes as the deployed
file’s. This is deliberate, and it narrows deploy’s “a hand-edited deployed
file is authoritative” policy to REAL files: a link’s bytes cannot be bounded
by the handle that is supposed to bound them, and publishing over it with
renameat would silently replace the link rather than write where it points
— so the two would disagree about what the deploy just did. Point the link
the other way (keep the real file under .trusty-code/ and link to it from
elsewhere) or drop it. PR #7773’s review asked for this on the skill-refs
tree; it holds uniformly rather than per-directory.
Unix only, like the rest of this crate’s daemon transport — openat,
renameat and O_NOFOLLOW are what close the window and have no portable
equivalent.
Test: paths::write_dir_tests::*.
Structs§
- Native
Write Dir - A directory beneath
<project>/.trusty-code/, pinned to an open descriptor.