Repository navigation
fix(fs): stop leaking fs credentials through companion lookup, run-with-secret, and the WebDAV bridge - #89
Conversation
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
A critical security issue remains because companion binary validation follows symlinks (os.Stat), potentially allowing a symlinked path to evade intended checks, and there’s also a minor doc/behavior mismatch around allowed group-writable binaries.
2 open issues
What changed in this PR
Hardens Drive9 companion execution and fs-vault run-with-secret to reduce credential exposure by validating companion binaries and ensuring child processes do not inherit Ti/Drive9 tokens.
Changes:
- Adds trusted companion resolution with explicit absolute-path overrides and safety validation of candidate binaries/directories.
- Refactors
fs-vault run-with-secretto fetch secrets via the companion but spawn the user command directly with a scrubbed environment. - Adds focused tests for companion trust rules and run-with-secret environment/exit-code behavior.
| File | Description |
|---|---|
| internal/fswrap/runner.go | Implements hardened companion discovery and validation logic to prevent PATH hijacking and executing untrusted companions with sensitive credentials. |
| internal/fswrap/runner_test.go | Adds unit tests covering acceptance/rejection of companion candidates under different path and permission scenarios. |
| internal/fswrap/owner_unix.go | Introduces Unix-specific helpers for file ownership and group membership checks used by companion trust validation. |
| internal/fswrap/owner_other.go | Provides non-Unix stubs for ownership/group helpers to keep builds portable across platforms. |
| internal/fs/vault.go | Updates run-with-secret execution to build a scrubbed child environment, validate injected fields, and propagate child failures consistently. |
| internal/fs/vault_secret_env_test.go | Adds end-to-end tests verifying credential env vars are scrubbed, secret fields are injected safely, and exit codes propagate. |
| internal/fs/drive9_companion.go | Changes run-with-secret to read secrets via the companion and execute the user command directly from ti rather than delegating the full run to the companion. |
| AGENTS.md | Documents stricter companion override requirements and the expected trust-validation behavior for companion binaries. |
Review effort: Balanced
a5cfe41 to
4aeb1ee
Compare
4aeb1ee to
5d78bc9
Compare
5d78bc9 to
25d45c2
Compare
mornyx
left a comment
There was a problem hiding this comment.
Review summary
This PR closes three real credential-exposure paths, and both findings from the earlier review pass (symlink resolution in companion validation, the group-writable doc mismatch) are verified fixed at this HEAD with targeted tests. Under a strict bar, two issues remain that sit inside the PR's own stated contract: the new companion trust validation is unconditionally broken on Windows — Go reports every normal writable file as mode 0666 and every directory as 0777 there, so the world-writable check rejects every default install — and the run-with-secret environment scrub misses TI_FS_AI_PROVIDER_API_KEY, a documented plaintext credential, contradicting the PR's stated TI_* scrubbing. Both are small, targeted fixes; the structural follow-ups below are strong but not merge-stopping.
What looks good
- Companion resolution never consults
$PATH, treats explicit configuration as terminal (fail rather than silently fall back), and validates the symlink-resolved binary in its real containing directory — the right posture for a credential-bearing exec, with a dense rejection test matrix. run-with-secretnow reads the secret through the companion and spawns the child directly from ti with a deterministic scrubbed + secret-injected environment, verified end-to-end against a real child process, including exit-code propagation. This removes the leak structurally instead of sanitizing a nested exec.- Deleting the unauthenticated loopback WebDAV bridge rather than authenticating it is the right call; the dead-code claim checks out, no references remain, and
--driver webdavkeeps working through the companion.
Blocking (please address before merge)
1. Companion validation rejects every default Windows install
internal/fswrap/runner.go:417 — the perm&0o002 world-writable checks in validateCompanionBinary (and validateCompanionDir at :458) run on all platforms, but on Windows os.Stat derives permission bits only from the read-only attribute: every normal writable file reports mode 0666 and every directory 0777 (see os/types_windows.go). So on Windows the check always trips: the default ~/.ti/bin/ti-drive9.exe staged by scripts/install.ps1 fails as "world writable (mode 0666)", and ~/.ti/bin itself fails as a world-writable parent. locateCompanion can never succeed, breaking every companion-routed command (ti fs, fs-vault, fs-git, fs-journal) on a platform .goreleaser.yaml ships and that CI (ubuntu-only) never exercises. The executable-bit check two lines below already carries runtime.GOOS != "windows", and owner_other.go already stubs ownership/group — the write-bit checks were left applying Unix semantics to bits that carry no such meaning on Windows.
Fix: move the permission/ownership validation behind the same platform seam the PR already created (Unix: perm + owner + group; non-Unix: not enforced, Windows ACLs are the real control there), keeping only the absolute/regular-file checks platform-neutral. Add GOOS=windows compile/test coverage in CI so the platform cannot silently regress again.
2. run-with-secret still passes TI_FS_AI_PROVIDER_API_KEY to the child
internal/fs/vault.go:556 — scrubTICredEnv is an exact-match list of 13 names and omits TI_FS_AI_PROVIDER_API_KEY, a documented plaintext provider secret read straight from the environment (internal/cli/commands.go:3265). A shell that has it exported — the documented way to configure extraction/embedding providers — hands the key to any run-with-secret child, contradicting both the PR description ("TI_* / TDC_* / DRIVE9_* credentials scrubbed") and the vaultSecretChildEnv comment ("ti's credential variables are removed"). Note that fswrap.drive9Env strips the DRIVE9_ family by prefix while this list scrubs exact names only — two scrub lists in two packages that have already drifted apart in this same PR.
Fix: scrub by prefix (TI_, TDC_, DRIVE9_, plus the TIDB_CLOUD_* pair) or share one canonical credential-env denylist between the two packages, and extend TestVaultSecretChildEnvScrubsCredentials with the provider key.
Should fix (non-blocking, strong)
3. Directory trust never checks ownership, while the docs claim "the same treatment"
internal/fswrap/runner.go:449 — validateCompanionDir checks only write-permission bits, never the owner uid, although the validateCompanionBinary doc says the containing directory "must pass the same treatment" — which per the binary checks includes owned-by-current-user-or-root. An unrelated user's 0755 directory containing a victim-owned binary passes validation, and its owner can still unlink/replace entries, leaving only the validate-to-exec race as protection (what is validated is not byte-for-byte what exec later resolves). Either enforce the same owner rule on Unix directories or scope the doc comment to what is actually enforced; walking the ancestor chain for the implicit candidates would also close the parent-rename swap window.
4. The dead-code deletion stops one third of the way
internal/fs/mount.go:501 — with the WebDAV branch gone, mountForeground has zero callers, which makes mountFUSEForeground and the entire in-process FUSE foreground runtime it anchors (~3k lines across fuse_mount.go, fuse_git.go, fuse_cache.go, fuse_writeback.go) unreachable — credential-bearing code that must keep compiling and keep being audited for nothing. mountVaultForeground, mountResult, autoUnpackMount, and pathErr (relocated into the new remotefs.go, which exists largely to keep this graph compiling) are equally dead. The PR's own justification for deleting the WebDAV bridge — "rather than authenticate dead code, it is removed" — removes this tree too. Deleting it here or as an immediate follow-up banks the simplification this change already paid for.
5. Stale --dry-run descriptions reference deleted components
internal/fs/mount.go:184 — the default description still says "normal execution starts a local ti fs FUSE runtime" and the webdav branch says "starts a local WebDAV bridge": this PR deletes the bridge, and normal execution always routes through the ti-drive9 companion. Dry-run output is ti's accuracy contract for planned mutations; replace both strings with one accurate companion-routed description.
Nits
internal/fswrap/runner.go:332— the exe-directory candidate is validated twice (the inlineos.Executableblock, then again as the first entry oftrustedCompanionDirs()), so an untrusted install reports the same candidate twice in the error;resolveExplicitCompanionalso stats the path and thenvalidateCompanionBinarystats it again.internal/fs/vault.go:694—vaultSecretChildEnvre-implements the merge body ofmergeEnv(~15 lines) instead of composingmergeEnv(scrubTICredEnv(base), secretEnv).internal/fswrap/runner_test.go:136— the "group-writable" rejection fixture uses mode 0o664, which is rejected by the not-executable check before the group check runs (and the fixture's group is the caller's own group), so the unrelated-group branch is never actually exercised anywhere.
Recommendation
Request changes. Two verified blockers — the Windows-breaking permission check and the TI_FS_AI_PROVIDER_API_KEY scrub gap — are small fixes inside this PR's own stated contract and should land before merge.
|
Thanks — both blockers were real. Pushed 1. Windows (blocking) — fixed. The POSIX mode and ownership rules now live behind the same Unix/non-Unix seam as the ownership helpers: 2. 3. Directory ownership — fixed. 4. Dead FUSE runtime — deferred, tracked. Opened #90 with the deadcode evidence and the acceptance criteria. I kept this PR scoped to the three security fixes as asked; #90 is the immediate follow-up. 5. Stale Nits: executable-directory candidate is validated once (the Local checks at |
mornyx
left a comment
There was a problem hiding this comment.
Review summary
Re-review at the new head. Everything from the previous round is verified resolved: the POSIX mode/ownership rules now live behind the unix/!unix seam (validateCompanionFileMode/validateCompanionDirMode) with the Unix checks preserved verbatim and Windows a deliberate no-op; the new internal/credentialenv package is a genuinely complete credential denylist (every environment variable the CLI reads was enumerated — no credential name falls outside the five families, and TI_FS_AI_PROVIDER_API_KEY is covered and tested) shared by both spawn paths so the two lists cannot drift again; directory ownership is enforced with real seam tests; the stale dry-run text and all nits are fixed; and the deferred native FUSE runtime is tracked in #90. No regressions were found in the fix commit — the scrub does not strip anything the companion path needs, and the unit/e2e suites pass. The declined ancestor-chain walk is accepted: with directory ownership enforced, the residual requires an attacker already positioned against the user's own home path, which already exposes ~/.ti/credentials. Two non-blocking items remain, both about Windows test gating, plus nits.
What looks good
- One canonical prefix-based denylist in
internal/credentialenv, consumed by both the companion environment and therun-with-secretchild environment, is the structurally right fix for the drift that let a credential variable slip through — futureTI_FS_*/TDC_*/DRIVE9_*names are covered automatically, and keepingTI_TEST_*inheritable shows the tradeoff was reasoned. - The platform seam is placed correctly: platform-neutral checks (absolute, regular file, symlink resolution, both parent directories) stay shared, only POSIX mode/ownership moved behind the build tags, and the Unix checks were strengthened (directory ownership) rather than weakened to make Windows pass.
- The ownership/group test seams exercise the real rules without chown privileges and without weakening assertions — fixtures are chosen so only the rule under test can reject (the old
0o664fixture that was rejected by the wrong check is gone).
Should fix (non-blocking, strong)
1. The world-writable rejection assertion will fail on Windows
internal/fswrap/runner_test.go:132 — the world-writable subcase of TestLocateCompanionRejectsUntrustedCandidates asserts fs.companion_untrusted for a 0o777 fixture with no platform guard. On Windows the new seam deliberately accepts that fixture (mode checks are a no-op there), so locateCompanion returns success and the assertion fails the moment anyone runs go test on Windows. The adjacent nonExecutable subcase and four other assertions in this file already carry the correct runtime.GOOS guard; this one was missed. It is latent only because CI runs tests on ubuntu and merely cross-compiles for Windows — and it encodes the exact always-reject behavior the platform fix removed. Wrap it in the same guard (or skip the subcase on Windows).
2. The cross-compile CI step never type-checks test files
.github/workflows/ci.yml:59 — the new "Cross-compile other platforms" step runs GOOS=windows GOARCH=amd64 go build ./... (and darwin), but go build does not compile _test.go files, so the Windows-guarded test code added in this PR is never even type-checked for those targets. Switching to GOOS=windows GOARCH=amd64 go vet ./... (darwin likewise) type-checks the tests too at the same cost. Note the interaction with item 1: compile gating cannot catch behavioral mismatches like that one — a future windows-latest test job (not required for this PR) is what would actually gate the no-op seam.
Nits
internal/fswrap/owner_unix.go:14—fileOwnerUID/fileGroupID/currentProcessGroupbecame mutable package-global function vars as test seams; pragmatic here, but the seam-swapping tests are silently incompatible witht.Parallel(nothing enforces that today). AnownerInfostruct injected intoRunnerwould remove the globals if it ever needs hardening.internal/fswrap/runner.go:365—errCompanionPathNotAbsoluteis effectively unreachable (resolveExplicitCompanionreturns its own typed error first; implicit candidates are built from absolute directories), and theread.(VaultReadSecretResult)assertion indrive9RunWithVaultSecretis always true givenFormat: "json"with no field. Drop them or leave a one-line comment that they guard future callers.
Recommendation
Comment. All previous blockers are verified fixed with no regressions; the two remaining items are Windows test-gating hardening that should not hold up this security fix.
|
Both Windows test-gating items are fixed in
Nits: the mutable Agreed that a |
qiffang
left a comment
There was a problem hiding this comment.
Reviewed exact head 9c5f41d87db1fe1415de04cbd97071c9acec57df against feb08c24f29f832b505a79df28336c45509f1fb4.
One blocking credential-isolation issue remains: Windows case variants bypass the new shared credential filter, so run-with-secret still passes ambient credentials to its child. See the inline finding.
The previously discussed Windows POSIX-mode rejection, provider-key omission, directory ownership, symlink target-directory check, and Windows test type-checking issues are addressed at this head. The removed WebDAV bridge has no remaining callers; relocated metadata helpers are unchanged. I also traced companion discovery, credential construction, vault read/validation/child execution, and runtime preflight.
Validation was static source and call-chain review, including the Go 1.26.5 environment implementation; no local target code or runtime tests were executed. git diff --check passed. Current CI test and license/cla checks are successful, but the CI runtime is Ubuntu and the new Windows vet step cannot catch this behavioral leak.
|
Good catch — fixed in
Two related touches:
Verification at Also noted for the record: the case-sensitivity bug would have been caught by a |
qiffang
left a comment
There was a problem hiding this comment.
Re-reviewed exact head cd97c009028eb7685ab170f7417d5c2e6bbebea6, including the complete four-file increment from 9c5f41d87db1fe1415de04cbd97071c9acec57df.
The previous P1 credential-leak finding is fixed and its thread is resolved. Both the vault child and companion/probe environment now use case-insensitive credential-family matching. Regression assertions cover lowercase/mixed-case credentials and preserve non-credential variables; the scoped HOME/USERPROFILE handling remains consistent. No remaining blocking findings.
Validation: static review of the changed source, both callers, and regression assertions; git diff --check passed. Current test and license/cla checks are successful. No local tests were rerun. CI executes tests on Ubuntu and type-checks Windows/Darwin; native Windows runtime testing remains an optional follow-up, not an approval blocker.
mornyx
left a comment
There was a problem hiding this comment.
Review summary
Third pass at the new head. Both items from the previous round are verified fixed — the platform-sensitive assertions in TestLocateCompanionRejectsUntrustedCandidates now sit behind runtime.GOOS guards with TestValidateCompanionBinaryRequiresAbsolutePath covering the relative-path branch, and the CI step is now GOOS=windows GOARCH=amd64 go vet ./... plus GOOS=darwin GOARCH=arm64 go vet ./..., which genuinely type-checks the _test.go files (both re-run clean at this head). The case-insensitive credential scrub is verified sound on both spawn paths: upper-casing keys in credentialenv.IsCredential closes the Windows case-variant leak with no reachable folding bypass, no legitimately inherited variable is newly scrubbed, and the case-insensitive HOME/USERPROFILE filter cannot collide with the scoped append. No blocking issues remain. Three non-blocking items should still be addressed before the new injection behavior solidifies.
What looks good
- One shared prefix-based denylist fixing both spawn paths in one place — and the case-insensitivity change additionally closes an ambient case-variant
DRIVE9_*/HOMEshadowing vector on the companion path, with a doc comment explaining the Windowsos.Environsemantics that motivate it. - Reading the secret in ti and spawning the child directly with a scrubbed, deterministic environment deletes the trust problem instead of papering over it, and it ships with a real-child leak test and exit-code propagation tests.
- Test discipline tracked the review exactly: the cross-vet step type-checks the platform-gated tests, the previously unreachable relative-path sentinel now has a direct caller, and the case-folding behavior is pinned at the
credentialenvboundary.
Should fix (non-blocking, strong)
1. On Windows, an ambient case-variant variable silently masks an injected secret field
internal/fs/vault.go:682 — vaultSecretChildEnv merges the scrubbed base environment with the secret fields via mergeEnv, which keys and sorts case-sensitively, and the merge is intended to let secret fields win over same-named inherited variables. On Windows, where environment names fold case-insensitively, an ambient db_url next to a secret field DB_URL survives the credential scrub and coexists in the merged slice; sort.Strings places the lowercase spelling after the uppercase secret, and Go's exec deduplication of cmd.Env on Windows preserves the last occurrence of a case-insensitively equal key — so the child resolves DB_URL to the ambient value, silently masking the secret. This is not a credential leak (the ambient value is the user's own), but it breaks the documented injection guarantee on Windows, and this PR is the change that introduced ti-side injection. Fix: drop base entries whose key strings.EqualFold-matches an override key before merging, so exactly one spelling — the secret's — reaches the child.
2. One field-to-env-key rule, three behaviors
internal/fs/vault.go:381 — create-secret accepts any non-empty field key (parseVaultFieldAssignments), read-secret --format env normalizes names into the env charset (normalizeVaultEnvKey: db_url → DB_URL), but run-with-secret now hard-fails the same secret with vault.invalid_env_key (validateVaultEnvFields enforces [A-Z_][A-Z0-9_]*), where the pre-PR companion delegation imposed no ti-side gate. A secret that two commands accept and one rejects — with two conversion rules for the same concept in one file — will drift further. Either route the injection through the same normalization (with collision detection), or enforce the env charset at create-secret/replace-secret time so non-conforming field names cannot be stored in the first place.
3. The rewritten run-with-secret service flow has no ordinary-CI coverage
internal/fs/drive9_companion.go:1215 — drive9RunWithVaultSecret grew from a four-line companion delegation into ~40 lines of orchestration (path parsing, companion vault get --json, field decode, vault.empty_secret guard, env-key validation wiring, exit-code propagation), and only the opt-in live e2e (e2e/live_test.go, requires cloud credentials) executes it. The env contract itself is well tested with a real child in vault_secret_env_test.go; it is the service glue that is untested, and the package already has a script-companion harness (drive9_companion_test.go) that covers other companion flows. Add one test through that harness: normal field map reaches the child with the scrubbed env; {} → vault.empty_secret; non-conforming keys → vault.invalid_env_key; child exit 7 → vault.command_failed.
Nits
internal/fs/remotefs.go:114—pathErrwas relocated from the deleted WebDAV bridge but has zero remaining callers; it can go now even if the rest of the file waits for the #90 native-FUSE cleanup, andmapWebDAVErroris a vestigial name for what is now a generic API-error mapping.internal/fswrap/runner_test.go:16— thedrive9Envboundary test uses only canonical spellings; one mixed-case ambient (ti_fs_token,Drive9_Server=…) would pin the case-insensitive strip at the boundary where it actually matters.
Recommendation
Comment. The credential-leak objective is verified fixed on both spawn paths with no reachable bypass, and both prior-round items are resolved; the three remaining items are Windows injection correctness, rule consistency, and test coverage — real, but not merge-stopping.
|
Third round addressed in
Nits: Verification at This PR still shows |
qiffang
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 7cd69c842e48a1035209dd7c4d59481651a2ca24, including the complete five-file increment from the previously approved cd97c009028eb7685ab170f7417d5c2e6bbebea6.
The previous credential-isolation P1 remains fixed. The new service-flow coverage, case-variant companion assertions, and removal of the unused helper are sound. However, the new environment merge and field-name conversion introduce two P2 correctness issues, detailed inline:
- Windows case-folding is applied on Unix too, deleting distinct, non-credential inherited variables.
- Injection does not actually share the normalization used by
read-secret --format env: ti iterates Unicode runes, whereas the companion iterates UTF-8 bytes, producing different keys and collision decisions.
These are new findings on this increment, not a reopening of the resolved credential leak. Please address both before approval. The deliberate change from strict field-name rejection to normalization should also be described in current user-facing documentation; the PR's test description still says invalid keys are rejected.
Validation: static review of the full increment, surrounding execution paths, regression assertions, and the companion source at the repository's pinned ref/drive9 commit ee40c65c6c966aff222f3aeff48d68127c4dc54e. git diff --check passed. Current CI test and license/cla checks are successful. No local target code or runtime tests were executed.
|
Both P2s are fixed in Preserve case-distinct inherited variables on Unix. The fold is now platform-aware ( Match the env-read normalization. Docs. README now describes the injection contract for Verification at |
87554f8 to
a4c1b3b
Compare
mornyx
left a comment
There was a problem hiding this comment.
Review summary
Re-review at the new head 6053136. All three should-fixes and all three nits from the previous round are verifiably fixed: the three new observed vectors were recomputed from an independent reimplementation of the derivation formula and all eight match exactly, with /aéb genuinely discriminating the per-rune label rule from a byte-wise one; the mount-audit extraction is a pure move (byte-identical except the three deliberate teardown changes and the new mountStopHint), reversing the growth of drive9_companion.go (1914 → 1727); mountStopHint resolves its advice from observed state — the ti-unmount advice appears only when a locator exists, and the no-locator advice computes the exact resource-scoped companion HOME the daemon actually runs under, so the guidance works on every reachable path; the dead defaultMountLocalRoot is deleted and the relative-XDG_CACHE_HOME error names the variable. The security posture of the whole PR holds at this head. One hardening gap remains — the load-bearing half of the new guidance has no test pinning it — plus three nits; nothing blocking.
What looks good
- The new vectors are chosen with real discrimination power:
/aébplaces a multi-byte rune between ASCII characters where the trim cannot erase the evidence, so a byte-wise refactor of the label sanitizer now fails the pin loudly;/.hiddenand/x.ypin the leading-trim vs interior-retention distinction. mountStopHintderives its advice from observed state (locator read) rather than assumptions, and its companion-HOME advice provably matches the daemon's environment derivation — the advice on every reachable path can actually work.- The file split is a genuinely pure move, verified line-by-line, landing the cohesive mount-security unit beside
mountroot.go/mount.goinstead of rearranging the giant companion file.
Should fix (non-blocking, strong)
1. The no-locator half of the new guidance is unpinned by tests
internal/fs/drive9_mount_audit.go:200 — the only umount-failure test (TestDrive9MountAuditCleanupFailureKeepsLocator) runs on the post-readiness path where the locator exists, and asserts only the "may still be running" + "unmount-file-system" message. Nothing covers the two new pre-locator double-failure branches (foreground mount failed with a clean audit + umount failed; locator write failed + umount failed) or mountStopHint itself, so a regression back to unconditional ti fs unmount-file-system advice — which verifiably cannot work without a locator (fs.mount_locator_not_found) — would pass the entire suite. That is the same green-suite-under-regression class this thread has consistently graded as a should-fix, and the fake companion already has the required knobs (TI_FAKE_DRIVE9_MOUNT_FAIL + TI_FAKE_UMOUNT_FAIL, plus TI_FAKE_MOUNT_ESCAPE_SYMLINK for the unsafe-audit variant). Add the two fake-companion tests (asserting the error contains the HOME=… ti-drive9 umount advice, not the ti unmount command), and a small table test for mountStopHint (locator present / absent) is a cheap third pin.
Nits
internal/fs/mountroot.go:24— the doc comment still says "ti's own default (defaultMountLocalRoot) is a different path", but this commit deleted that function; the sentence now names a symbol that no longer exists, in the file whose job is keeping the two derivations straight. Reword to reference-free phrasing.README.md:206— "If the mount cannot be stopped, the error says so and the mount locator is kept soti fs unmount-file-systemcan retry" is now true only for post-locator failures; in the new pre-locator paths there is no locator to keep and the error advises the companion's own umount with the scoped HOME. Add the clause.internal/fs/drive9_companion.go:1251—drive9MountVault's locator-write-failure branch still discards its umount error, so a vault mount whose locator write and umount both fail is left running with no stop guidance — the same shape just fixed for fs mounts, minus the unpack-audit security riding on it. Pre-existing and fine as a follow-up; noted so the pattern does not survive as the only swallowed teardown in the file.
Recommendation
Comment. Everything from the previous round is verifiably fixed and the security boundary holds — the code itself is in mergeable shape — but the locator-aware guidance added this round deserves its discriminating test (item 1) before this thread closes, per the same bar applied throughout.
|
All items are in 1. The no-locator guidance is now pinned.
Nits.
One unrelated doc correction while I was there: the AGENTS companion-parity paragraph still mentioned the removed plan9 cache branch, so it now lists only the shipped platforms and states the deliberate relative-XDG deviation. Verification at |
mornyx
left a comment
There was a problem hiding this comment.
Review summary
Re-review at the new head 546763a. The previous round's should-fix lands exactly as claimed on the fs side: the four new tests are genuinely discriminating pins — mutating the stop advice to unconditional ti-unmount or unconditional companion-unmount fails the suite in both directions — and they drive the real MountFileSystem path through the fake-companion subprocess rather than unit-calling internals. The mountStopHint parameterization is pure argument plumbing with no fs behavior change, the non-test hunks match the described items only, and the docs match the code. However, one of this round's claimed fixes does not materially work: the new vault teardown branch composes its message with fmt.Errorf("%w; …"), and the CLI renders errors through apperr.MessageFor, which extracts only the inner *apperr.Error message — so the "may still be running" warning and the stop hint never reach the user. That is the one merge-blocker; it is a one-line fix plus a test.
What looks good
- The four new tests are discriminating in both directions (verified by mutation, not assertion count), closing the green-suite-under-regression gap this thread has tracked since the locator-aware advice was introduced.
mountStopHintresolves the companion HOME through the sameService.homeDir+fscred.CompanionHomesource the runner actually uses, for both fs and vault mounts — the advice provably matches the daemon's environment.- Documentation discipline holds: the README/AGENTS pre-locator clause and the cache-root rewrite (plan9 branch removed from both code and AGENTS, deliberate relative-
XDG_CACHE_HOMEdeviation stated) match the code precisely.
Blocking (please address before merge)
1. The vault teardown message is composed so that the CLI never prints it
internal/fs/drive9_companion.go:1252 — the new vault locator-write-failure branch returns fmt.Errorf("%w; the vault mount at %q may still be running and could not be stopped (%v); %s", err, opts.MountPath, umountErr, s.mountStopHint(...)). The CLI boundary (cmd/ti/main.go:29) prints apperr.MessageFor(err), and MessageFor uses errors.As to return only the first embedded *apperr.Error's message — here the wrapped locator-write error, whose message is just write ti fs mount locator. Exercising the real MountVault path (fake companion, ~/.ti/mounts as a regular file to break the locator write, TI_FAKE_UMOUNT_FAIL=1) confirms it: MessageFor returns the bare locator-write message while the full composed text — including stop it with HOME=… ti-drive9 umount … — exists only in err.Error(). So the vault teardown surfacing claimed this round is not fixed in user-visible output: a running vault mount daemon holding a delegated vault token is left with no working stop advice, and the ti unmount command a user would guess fails with fs.mount_locator_not_found. Every sibling teardown branch in internal/fs/drive9_mount_audit.go builds its message with apperr.New(apperr.CodeFor(err), "runtime", 1, <full text>) precisely so the advice renders; this branch deviates. No test covers it — which is exactly how it slipped through, since the fs-side tests all assert through MessageFor on apperr-built errors.
Fix: mirror the sibling pattern — apperr.New(apperr.CodeFor(err), "runtime", 1, fmt.Sprintf("%v; the vault mount at %q may still be running and could not be stopped (%v); %s", err, opts.MountPath, umountErr, s.mountStopHint(opts.Profile, opts.MountPath, "ti fs-vault unmount-vault"))) — and add the vault-side analog of TestDrive9MountLocatorWriteFailureTeardownAdvisesCompanion, asserting through apperr.MessageFor that the message contains ti-drive9 umount and does not point at the locator-only command. That test would have caught this.
Recommendation
Request changes. Item 1 is a verified user-boundary defect in a fix this head claims to deliver (the branch's internal logic — one umount attempt, correct scoped HOME, correct pre-locator hint — is right; only the message never renders), and the fix is one line plus the missing vault-side test. Everything else from every prior round is verified intact at this head.
|
Fixed in Blocking: vault teardown advice never rendered. You are right — Added the vault-side analog you asked for: Verification at |
mornyx
left a comment
There was a problem hiding this comment.
Review summary
Re-review at the new head aac13de. The previous round's single blocker is fixed exactly as specified: the vault locator-write-failure teardown now composes its message with apperr.New(apperr.CodeFor(err), "runtime", 1, <full text>), identical in shape to all four sibling teardown branches, so the "may still be running" warning and the locator-aware stop hint render through apperr.MessageFor at the CLI boundary. The new TestDrive9VaultMountLocatorWriteFailureTeardownAdvisesCompanion drives the real MountVault path through the fake companion and asserts through MessageFor — the exact boundary that was broken — pinning both the presence of the ti-drive9 umount advice and the absence of the locator-dependent ti command. Reverting the one-line fix makes that test fail with precisely the originally reported symptom (only write ti fs mount locator rendered), confirming it would have caught the defect. The increment contains nothing else, the full suite and cross-platform vet are clean, and every fix from all prior rounds is verified intact at this head, including the whole security chain: hardened companion resolution, the shared credential denylist on both spawn paths, the WebDAV bridge deletion, the post-readiness overlay audit with its discriminating ordering test, the observed-vector-pinned companion root replica, and the now fully test-pinned teardown guidance on both fs and vault paths.
What looks good
- The fix is the minimal correct one — one line to the established sibling pattern, plus the exact test that was missing, with a comment explaining why the wrapper choice matters at the rendering boundary.
- Both user-facing failure boundaries (message composition and stop-advice selection) are now pinned by tests that were each verified to fail on the defect they guard.
- Across the whole review history the PR kept deleting and unifying rather than patching: the WebDAV bridge removed, eligibility collapsed to one owner, the mount-audit cluster extracted, and the derivation replica pinned by observed constants instead of trusted code.
Nits
- The teardown-composition shape now exists at five sites; this round's bug was a new site copying it with the wrong wrapper. A small shared helper beside
mountStopHintwould make the correct composition unavoidable — good follow-up material, not worth reopening this PR for. internal/fs/drive9_companion_test.gohas accumulated ~2000 lines of security pins; a domain split would keep it navigable. Also fine as a follow-up.
Recommendation
Approve. The one-line rendering fix is verified correct and mutation-tested, every finding from every prior round is resolved with test coverage at the exact boundaries that failed, and only optional follow-up nits remain.
|
Took both nits directly in Shared composition helper. Test file split.
Verification at I had opened #91 for exactly these two; it can be closed once this lands. |
…and WebDAV bridge Three secret-protection findings and one dead-code finding from the scanner. **Companion integrity (high).** The ti-drive9 companion runs with the TiDB Cloud private key, the filesystem bearer token, and delegated vault tokens, but it was resolved by bare name from $PATH with no integrity check, so any account able to write an earlier PATH entry could receive those credentials. $PATH is no longer consulted at all: the only implicit candidates are ti's own directory and the installer-managed ~/.ti/bin, and an explicit CompanionPath or TI_DRIVE9_BIN is terminal. A missing or insecure explicit path is an error instead of a cue to fall back to a different binary. Every candidate must be an absolute, regular, executable file owned by the current user or root, must not be world writable and must not be writable by a group the caller is not in; the directory that actually contains the binary is validated too, after resolving symlinks, so a link inside a trusted directory cannot point at a binary another account can replace. Group-writable binaries inside the caller's own groups stay accepted so a umask of 002 does not break every install, and refusals surface as fs.companion_untrusted with the offending path. The TI_ALLOW_STANDALONE_DRIVE9 test control is removed with the PATH fallback. **run-with-secret child environment (high).** ti asked the companion to spawn the child (`vault with ... -- <cmd>`), so the child inherited the companion environment including DRIVE9_API_KEY (the filesystem bearer token) and DRIVE9_VAULT_TOKEN; the existing scrubTICredEnv helper was never called. ti now reads the secret through the companion itself and spawns the user command from ti with an environment built from os.Environ() minus TI_*/TDC_*/DRIVE9_* credentials, plus the validated secret fields. Child exit codes propagate as vault.command_failed. **WebDAV bridge (high).** The native loopback WebDAV bridge was unreachable: Service.MountFileSystem routes unconditionally to the Drive9 companion and mountForeground had no callers. The bridge (webdavfs.go, the 127.0.0.1 server, the random URL prefix, and the mount_webdav exec that received that prefix in argv) is deleted rather than authenticated, and the driver abstraction keeps only validation because mounting belongs to the companion. The metadata helpers the FUSE code shares were kept in remotefs.go. Tests: companion resolution rejects relative, world-writable, unrelated-group-writable, non-executable, world-writable-directory, and symlink-to-writable-directory binaries while accepting a valid absolute override and a umask-002 group-writable install; a ti-drive9 planted on PATH is never executed. The run-with-secret helpers assert credentials are absent from a real child environment, secret fields are injected, invalid field keys are rejected, and exit codes propagate. The native mount tests were removed with the bridge.
Platform seam for companion trust. The POSIX mode and ownership checks now live behind the existing Unix/non-Unix seam. Windows derives permission bits from the read-only attribute (a normal file reports 0666 and a directory 0777), so the unconditional world-writable check rejected every legitimate install, including the default ~/.ti/bin/ti-drive9.exe staged by scripts/install.ps1. Unix keeps the full rule set, now including the directory owner the binary's doc comment already promised. One credential-env denylist. internal/credentialenv owns the TIDB_CLOUD_*, TDC_*, DRIVE9_*, TI_FS_* and TI_VAULT_* families, and both the companion environment builder and the run-with-secret child environment scrub through it. This closes TI_FS_AI_PROVIDER_API_KEY, which the previous exact-name list missed, and removes the two lists that had already drifted apart. Non-credential TI_ variables (TI_PROFILE, TI_REGION_CODE, test controls) are still inherited by the companion. Smaller review follow-ups: the executable-directory candidate is validated once instead of twice, resolveExplicitCompanion no longer stats the path twice, the dry-run mount descriptions now describe companion routing instead of a local FUSE/WebDAV runtime, and vaultSecretChildEnv composes mergeEnv. Tests: the unrelated-group rejection now runs the group rule (0o775 fixture with the group-membership seam) instead of being short-circuited by the not-executable check, a directory-owner rejection case is added, the child env and real-child assertions include TI_FS_AI_PROVIDER_API_KEY, and CI cross-compiles windows/amd64 and darwin/arm64 so the platform seam cannot silently regress.
…platform Two follow-ups from the re-review, both about Windows coverage rather than the security fix itself. The world-writable companion assertion now carries the same runtime.GOOS guard as the neighbouring non-executable case: POSIX mode bits are deliberately not enforced on Windows, so on that platform the seam accepts the fixture and the assertion encoded the always-reject behavior the platform fix removed. The cross-compile CI step now runs go vet instead of go build, so _test.go files are type-checked for windows/amd64 and darwin/arm64 at the same cost. A new direct test covers the relative-path guard that only a direct caller of validateCompanionBinary can reach, and the vault read type assertion documents why it stays.
Windows environment variable names are case-insensitive: a user can export the filesystem token as ti_fs_token (or have an ambient Tidb_Cloud_Private_Key), Go resolves it for os.LookupEnv, and os.Environ() preserves that spelling. The shared credentialenv predicate compared prefixes case-sensitively, so both the run-with-secret child environment and the companion probe environment kept those entries and still handed the real bearer token or organization key to the child. IsCredential now upper-cases the key before matching, which is safe on Unix (case variants are not valid ti names) and closes the Windows spelling gap. The companion HOME/USERPROFILE filter gets the same treatment so a differently cased ambient entry cannot shadow the scoped HOME. Tests cover lowercase and mixed-case spellings for the token families, and assert that non-credential names such as ti_profile and ti_test_runtime_record still pass through.
Third review round, all three items are in this commit.
Windows case folding in the merge. mergeEnv keys case-sensitively, so an ambient
db_url survived next to the injected DB_URL; Windows folds environment names and
keeps the last duplicate, so the ambient value would shadow the secret. The child
environment now drops inherited entries that match a secret field under
strings.EqualFold before merging, leaving exactly the injected spelling. There is
a unit case with an ambient db_url plus an injected DB_URL and the real-child test
asserts the folded ambient name is gone.
One field-to-env-key rule. Injection now normalizes field names through
normalizeVaultEnvKey, the same rule `read-secret --format env` already used, and
fails with vault.env_collision when two fields normalize to the same key. A secret
stored as db_url is therefore injectable as DB_URL instead of being rejected by a
second, stricter rule; the old vault.invalid_env_key gate is gone.
Service-flow coverage. The script-companion harness gained a `vault get` branch
and TestDrive9RunWithVaultSecretServiceFlow drives the whole rewritten path: the
companion returns a field map, the child receives it with the scrubbed environment,
`{}` maps to vault.empty_secret, colliding field names to vault.env_collision, and
child exit 7 to vault.command_failed.
Nits: dropped the relocated pathErr (no callers left); added mixed-case ambient
Drive9_Server and ti_fs_token to the drive9Env boundary test. The mapWebDAVError
rename waits for #90, where its last callers are deleted.
…key export
Two P2 findings on the previous increment.
Unix case-distinct variables. The Windows shadowing fix used
strings.EqualFold unconditionally, so on Linux/macOS an injected HTTP_PROXY
deleted an inherited http_proxy (the form curl reads) and any other case-distinct
name disappeared whenever a secret supplied a different casing. The comparison is
now platform-aware: Windows folds case, Unix compares exactly. Tests cover both
sides: the Windows fold drops the ambient db_url, Unix keeps http_proxy next to
the injected HTTP_PROXY, and the real-child assertion now checks the preservation
it previously asserted as deletion.
Companion-identical key conversion. read-secret --format env is exported by the
companion, whose normalizeSecretEnvKey walks UTF-8 bytes; ti's helper walked
runes, so "café" exported as CAF__ while injection produced CAF_, and "é" versus
"_" collided here but not in the companion. normalizeVaultEnvKey now walks bytes
with the same rules (upper-case ASCII letters, prefix a leading digit with '_',
every other byte becomes '_'), so both public commands agree on keys and on
collision decisions.
The new normalization behavior is documented in README: injected fields use the
same conversion as read-secret --format env, accented names produce one
underscore per UTF-8 byte, colliding fields fail with a usage error, and Windows
case-insensitive shadowing is described.
Tests: non-ASCII field coverage exists both at the helper boundary and through the
script-companion service flow ("café" -> CAF__ and "é" vs "_" staying distinct),
plus the Unix case-preservation cases.
- README now states the field-name rule exactly: digits and '_' are kept, a leading digit is prefixed with '_', and only bytes outside [A-Za-z0-9_] become '_'. The previous "every other byte" wording wrongly implied interior digits are replaced. - renderVaultEnv and validateVaultEnvFields share normalizedVaultFieldMap, so the normalize-and-detect-collisions skeleton has one implementation and the export and injection paths cannot drift. - The vault.env_collision message reports the colliding pair in sorted order, so the error text no longer depends on map iteration order. - Dropped the unreachable empty-key guard: every input byte writes at least one output byte, so a non-empty field can never normalize to an empty key. - The service-flow test pins the companion invocation arguments (`vault get demo --json`), and a new test repeats a colliding map to pin the deterministic message.
mount-file-system with a coding-agent/portable profile, --pack-path, or --unpack-archive-path lets the ti-drive9 companion unpack a remote archive into the local overlay, but it never ran the overlay symlink audit that unpack-file-system enforces. A pack whose links escape the overlay could therefore be unpacked at mount time and later write through to an arbitrary local file. ti now resolves the overlay the companion will write before the mount starts (explicit --local-root wins, otherwise the same derived default root the mount uses), passes that exact root to the companion so both sides agree, snapshots it, and audits it after the companion returns - including when the mount failed, because unpack is not atomic. Escaping links are removed, the mount is stopped before the error is reported, and an unpack target ti cannot resolve is refused with fs.mount_unpack_requires_profile instead of silently skipping the audit. Ordinary mounts keep their previous flag shape and pass no --local-root. Tests use the script companion to install an escaping symlink into the overlay and assert the command fails with fs.unsafe_pack_symlink, the link is removed, the escape target is untouched, and the mount is unmounted; a derived-root case proves auto-unpack without --local-root is audited; a no-profile unpack is refused; and a plain mount still passes no --local-root.
…ility Review follow-ups on the mount overlay audit. The audit now runs at the point unpack is observably finished. Mounts are background-only, so the foreground mount command can return before the companion daemon finishes unpacking; auditing right after it could miss a link installed during startup, and the ready-timeout path never audited at all while leaving the mount running. The audit moved after the readiness wait and also runs on the timeout path, with the same umount-and-remove-locator teardown on violation. Tests cover both the readable and the timed-out paths. Cleanup failures are no longer silent. If the unmount after an audit rejection fails, the error says the mount may still be running, names the unmount command, and the mount locator is kept so ti fs unmount-file-system can retry. Eligibility has one owner again. mountOverlayAudit no longer re-implements profile resolution: it calls mountOverlayInputs, so the live path and --dry-run reject the same combinations (for example --mount-profile none --pack-path), and --no-auto-unpack is part of the unpack predicate instead of being ignored. An explicit --unpack-archive-path still unpacks and is still audited. Docs now match the predicate: the audit covers mounts that actually unpack (auto-unpack with pack paths when --no-auto-unpack is not set, or an explicit --unpack-archive-path), and a mount that only names --local-root is not audited. Nits: the companion HOME/USERPROFILE case fold is Windows-only again, and credentialenv.Scrub drops non-KEY=VALUE entries to match mergeEnv instead of preserving dead behavior.
Review follow-ups on the mount overlay audit. The audit-ordering test now discriminates: the fake companion's mount command starts a detached worker that installs the escaping link only after the foreground command returned, and the readiness probe reports active only once that link exists. Under the previous ordering the mount would report success with the link installed; the test fails there now. Failure paths regained their guarantees. A companion mount failure plus an audit violation routes through stopMountAfterUnsafeAudit, so an ambiguously failed foreground command cannot leave a running daemon that the locator-only unmount cannot reach. The locator-write failure path audits before tearing down, so a link from a partial unpack is removed instead of being recorded as pre-existing state by the next mount's baseline. A clean audit at the ready-timeout point no longer leaves an unpack-capable mount running: readiness never completed, so unpack may still be in flight, and the mount is stopped as a documented exception to the leave-running contract. The rejection stays in mountOverlayInputs, so live and --dry-run agree on the none-profile unpack rule; --unpack-archive-path is trimmed at the boundary so the predicate, argv, and result see the same value. Docs narrow the coverage to the ti-side trigger (effective pack paths, which portable supplies by default) and record the three companion-parity assumptions plus the snapshot-attribution rule.
…g ti's The companion-parity questions are answered from the drive9 source and binary, and one answer changes the fix: drive9 derives a mount's default overlay root as os.UserCacheDir()/drive9/mounts/<safe-label(remote)>-<sha256(server + "\n" + remoteRoot + "\n" + credentialKey)[:8]> with the companion HOME, while ti's own defaultMountLocalRoot is ~/.ti/local/fs/<hash>. Passing ti's path as --local-root for an auto-unpack mount would relocate every existing overlay. ti now audits the companion's own default root and only forwards --local-root when the user set it. companionMountLocalRoot replicates drive9's derivation (including the safe label and the credential fingerprint), and the replica is pinned by a test using the value observed from the installed companion: server https://drive9.example, remote /, credential sk-test produce root-26d2b529bbcb6733. mountOverlayPolicy is the single eligibility owner for both the native inputs and the audit, so the audit path no longer creates ti's own overlay directory as a side effect. The other two assumptions hold in drive9: autoUnpack is overlayProfile && len(effectivePackPaths) > 0 && !*noAutoUnpack, so --no-auto-unpack is honored exactly, and the builtin coding-agent profile has no pack paths while portable supplies "/" (verified by running the companion with a temporary HOME: bare coding-agent did not fetch an archive, portable did).
Blocking review finding: companionCacheRoot applied XDG_CACHE_HOME on every platform and filtered it with TrimSpace/IsAbs, while os.UserCacheDir (which the companion inherits) honours it only on the default Unix branch, verbatim. On macOS with XDG_CACHE_HOME set, ti audited $XDG_CACHE_HOME/drive9/mounts/... while the companion unpacked into companionHome/Library/Caches/..., and because a missing overlay scans as clean the audit silently passed. The cache root now follows the stdlib decision tree: darwin always companionHome/Library/Caches, Windows os.UserCacheDir (LOCALAPPDATA untouched), plan9 companionHome/lib/cache, and the default Unix branch uses a non-empty XDG_CACHE_HOME verbatim (no trim, no absolute filter) so a relative value makes scanOverlayEntries reject the non-absolute root instead of auditing a wrong directory. Tests cover the XDG set/unset matrix per GOOS, the relative-XDG failure, and the observed derivation vectors are now hermetic. Also from the same review: companionMountLocalRoot returns fs.missing_profile instead of a silent empty string; the dry-run path no longer derives or creates ti's own overlay directory (mountOverlayInputs is gone, mountOverlayPolicy is the only eligibility owner); a failed foreground mount with a clean audit also stops the daemon when an unpack is possible; the timeout teardown errors no longer claim a stopped mount could not be stopped and no longer embed the stale stop hint; the unpack-file-system mount-path error points at the local_root reported by mount-file-system; and the derived-root test comment matches what it asserts.
…nt audit Review follow-ups on the mount overlay audit. The vector table now pins the per-rune label rule: a mid-segment accented rune (/aéb -> a-b) distinguishes the rune walk from a byte walk (a--b), which the previous trimmed vectors could not, and a leading-dot segment pins the hidden label handling. Both were captured from the installed companion. Teardown failures are no longer swallowed. The failed-foreground branch and the locator-write-failure branch report when the mount could not be stopped and say an unpack may still be in progress, and the stop hint is locator-aware: ti's unmount resolves through the locator, so before it exists the message names the companion's own umount with the resource-scoped HOME. The mount audit cluster (drive9MountFileSystem, the teardown helpers, and unpackAuditLocalRoot) moved to internal/fs/drive9_mount_audit.go, next to mountroot.go, leaving drive9_companion.go to the data-plane command adapters. Nits: ti's orphaned defaultMountLocalRoot is deleted so it cannot be confused with the companion replica; companionCacheRoot documents its deliberate XDG_CACHE_HOME deviation and only carries shipped-platform branches; a relative XDG_CACHE_HOME now fails at derivation with an actionable error naming the variable instead of reaching a generic overlay-audit message.
Review follow-up: the no-locator half of the stop guidance had no test, so a regression back to the ti unmount command (which fails with fs.mount_locator_not_found before a locator exists) would have stayed green. mountStopHint is now generic over the ti unmount command and profile, pinned by a table test covering both states (locator present -> ti unmount, absent -> companion umount with the resource-scoped HOME). Three fake-companion tests cover the pre-locator double failures: foreground mount failed with a clean audit and a failed umount, locator write failed with a failed umount, and the runErr + audit-violation branch whose teardown also failed. Each asserts the error names `ti-drive9 umount` and not the locator-only command. The same shaped teardown bug in drive9MountVault is fixed too: a vault mount whose locator write and umount both fail now reports that it may still be running and how to stop it, instead of discarding the umount error. Docs: the mountroot comment no longer names the deleted defaultMountLocalRoot; README and AGENTS describe the pre-locator advice.
The vault locator-write-failure branch composed its message with
fmt.Errorf("%w; ..."), but the CLI renders apperr.MessageFor, which returns only
the embedded apperr message. The running warning and the companion stop hint
therefore never reached the user, leaving a vault mount daemon holding a
delegated token with no working stop advice.
Compose the error with apperr.New(apperr.CodeFor(err), "runtime", 1, <full text>)
like every sibling teardown branch. TestDrive9VaultMountLocatorWriteFailure...
TeardownAdvisesCompanion drives the real MountVault path with the fake companion,
breaks the locator write, fails the umount, and asserts through apperr.MessageFor
that the message contains the running warning and `ti-drive9 umount` and does not
point at the locator-only unmount command.
…on tests
Applies the two follow-up nits from the approving review instead of leaving them
as issues.
mountError(cause, format, args...) now owns the composition every teardown and
stop message uses: apperr.New(apperr.CodeFor(cause), "runtime", 1,
fmt.Sprintf(...)). The last review round found a new site that used
fmt.Errorf("%w; ...") instead, which the CLI's apperr.MessageFor silently hides;
routing all six sites through one helper makes that mistake structurally
avoidable. TestMountErrorKeepsCauseCodeAndFullMessage pins the code preservation
and the rendered text.
drive9_companion_test.go is split by domain: the fake companion harness
(buildFakeDrive9 and its record/flag helpers) moved to
drive9_fake_companion_test.go, and the mount/vault mount audit pins moved to
drive9_mount_audit_test.go. The remaining file keeps the data-plane, layer,
vault command, dry-run, and pack/unpack tests. No test body changed apart from
imports.
2a6816e to
37a1606
Compare


Three scanner findings are fixed in this PR; the fourth is a drive9/FS service contract that ti cannot change from the client.
1. Companion resolved by bare name from
$PATHwith no integrity check (high)fswrap.Runner.locateCompanionusedexec.LookPath("ti-drive9")and ran the result while injecting the TiDB Cloud organization private key, the filesystem bearer token, and delegated vault tokens. Any account able to write an earlier$PATHentry could receive those credentials.Fix
$PATHis not consulted at all. The only implicit candidates are ti's own directory and the installer-managed~/.ti/bin;TI_ALLOW_STANDALONE_DRIVE9(the baredrive9PATH fallback) is removed.Runner.CompanionPath,TI_DRIVE9_BIN) is terminal and must be absolute; a missing or insecure explicit path fails withfs.companion_missing/fs.companion_untrustedinstead of falling back to another binary.2.
fs-vault run-with-secretleaked the FS bearer token and vault token to the child (high)ti fs-vault run-with-secretdelegated the whole operation to the companion (ti-drive9 vault with <path> -- <cmd>), so the child inherited the companion environment includingDRIVE9_API_KEY(filesystem bearer token) andDRIVE9_VAULT_TOKEN;scrubTICredEnvwas dead code.Fix
vault get <name> --json) and spawns the user command directly from ti.os.Environ()withTI_*/TDC_*/DRIVE9_*credentials scrubbed, then only the validated secret fields are injected. The filesystem bearer token and the vault token never reach the child.vault.command_failed.3. Native loopback WebDAV bridge with no authentication and its prefix in argv (high)
Service.MountFileSystemroutes unconditionally todrive9MountFileSystem, andmountForegroundhad no callers, so the native bridge was unreachable. Rather than authenticate dead code, it is removed.Fix
internal/fs/webdavfs.gois deleted: the unauthenticated127.0.0.1WebDAV server, the in-memory remote filesystem, and the random URL prefix are gone.mountWebDAVForeground,randomWebDAVPrefix, and the WebDAV branch ofmountForegroundare deleted, so nothing passes a URL/prefix as a process argument.mountdriverkeeps onlyName()andCheckPrerequisites(); themount_webdav/umountexec path with the mount URL in argv is deleted, because mounting belongs to the companion.internal/fs/remotefs.gounchanged.4. Organization private key sent to the drive9.ai service (not a ti-side fix)
Not changed here, with reasons:
tenant create/list/describe/delete, token minting, AI provider configuration) authenticates with the TiDB Cloud public/private key pair inX-TiDBCloud-*headers and digest challenges. That is the deployed service contract; deleting the header breaks every FS control-plane command. ti already uses only the built-in HTTPS endpoint mapping, never logs, persists, or telemetry-records the key, redacts it from errors and debug output, and never retries ambiguous mutations.Tests
internal/fswrap/runner_test.go,locate_test.go: relativeTI_DRIVE9_BIN, world-writable, unrelated-group-writable, non-executable, world-writable-parent, and symlink-to-a-writable-directory binaries are rejected withfs.companion_untrusted; a valid absolute override, a~/.ti/bin-style install, and a umask-002 group-writable install are accepted; ati-drive9placed onPATHis never executed and the resolution fails withfs.companion_missing.internal/fs/vault_secret_env_test.go: the child environment keeps safe variables and injected secret fields but dropsTI_FS_TOKEN,TI_VAULT_TOKEN,TIDB_CLOUD_PRIVATE_KEY,DRIVE9_API_KEY,TI_FS_AI_PROVIDER_API_KEYand case-variant spellings of all of them; a real child (/bin/sh -c env) is inspected end to end; field names are normalized with the same byte-wise rule the companion uses forread-secret --format env(café→CAF__,évs_stay distinct) and colliding names fail withvault.env_collision; Unix keeps case-distinct inherited names such ashttp_proxywhile Windows folds them; exit code 7 propagates asvault.command_failed.e2e/release_build_test.gono longer sets the removed standalone control.Verification
gofmtclean,go vet ./...clean,go build -tags ti_test_controls ./...cleango test -count=1 ./...pass (43 packages)bin/tiand a fake companion:TI_DRIVE9_BIN=<fake> ti fs list-files --path /runs the explicit companion and succeeds.PATHis never executed; ti exits 1 withti requires the Drive9 companion binary.ti fs-vault run-with-secret --secret-path /n/vault/demo -- envinjects onlyDB_URL/PASSWORD;DRIVE9_API_KEY,DRIVE9_VAULT_TOKEN,DRIVE9_PRIVATE_KEY,TIDB_CLOUD_PRIVATE_KEY, andTI_FS_TOKENare absent from the child environment.Review follow-ups (
1970e9c)windows/amd64anddarwin/arm64.internal/credentialenv) forTIDB_CLOUD_*,TDC_*,DRIVE9_*,TI_FS_*,TI_VAULT_*, shared by the companion env builder and therun-with-secretchild env. This closesTI_FS_AI_PROVIDER_API_KEY, which the previous exact-name list missed.resolveExplicitCompanion;vaultSecretChildEnvcomposesmergeEnv.--dry-runmount descriptions now describe companion routing instead of a local FUSE/WebDAV runtime.