Repository navigation
fix(instances): make the gateway run dir owner-only on Windows - #8164
Conversation
Open PR relationship auditThis is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion. Relationship findings
No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit. |
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days with CI green but PR Readiness stuck pending. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author. Assessment: All CI is green on head If you'd prefer I don't touch this PR, add the |
`_run_dir` tightened `<config_dir>/run` with `os.chmod(d, 0o700)`. A mode is meaningless on Windows, so the directory keeps the inherited DACL — measured with `icacls`, that is `BUILTIN\Users:(RX)` plus `NT AUTHORITY\Authenticated Users:(M)`. The directory holds the gateway credential, the pid a client checks before trusting a port, and the marker naming an executable mint execs. Route it through `platform_compat.restrict_dir_to_owner`, which is the same `chmod(0o700)` on POSIX and an owner-only DACL on Windows. Its grants carry `(OI)(CI)`, so the `.pid` and `.bin` sidecars written by `atomic_write(mode=0o600)` — a no-op mode on Windows — inherit owner-only too. The helper is fail-loud, but `_run_dir` is reached through `secret_path()` on the dashboard's startup path, so the raise is absorbed and logged: the existing tighten-if-possible contract is what callers depend on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
a167be8 to
e12135a
Compare
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca] Rebase-only push: Why: all CI was green on the old head, but the five Stage-2 fork review lanes (GPT/Opus/Design/First Principles/UX) completed as The rebase applied cleanly (no conflicts). Local gates on the rebased head: isort ✅ flake8 ✅ mypy ✅ (1413 files) |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Real Windows DACL gap, fixed with the exact helper the repo's own platform-compat table prescribes; POSIX behavior and the best-effort contract are preserved and pinned by tests. Suggestions
[DESIGN-REVIEWED] e12135a |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of All lenses complete. The fix is real (measured DACL reproduction, mandated by the platform-compat doc table), the failure premise checks out in-repo ( First-Principles-Verdict: CONCERNS The mkdir + try/except body hand-rolls Not justified as shipped
What this change shipsInventory (3 items) — 2 justifiedIntent: make the gateway's
WatchOne counted unfixed sibling: Subtractions
[FIRST-PRINCIPLES-REVIEWED] e12135a |
cixuuz
left a comment
There was a problem hiding this comment.
Reviewed at e12135a. The change replaces a Windows-no-op POSIX mode with the established owner-only DACL helper while preserving POSIX behavior and the existing best-effort startup contract. The inherited sidecar protection is demonstrated on Windows, focused regression coverage is present, and required checks are green.
…otdev#8164) `_run_dir` tightened `<config_dir>/run` with `os.chmod(d, 0o700)`. A mode is meaningless on Windows, so the directory keeps the inherited DACL — measured with `icacls`, that is `BUILTIN\Users:(RX)` plus `NT AUTHORITY\Authenticated Users:(M)`. The directory holds the gateway credential, the pid a client checks before trusting a port, and the marker naming an executable mint execs. Route it through `platform_compat.restrict_dir_to_owner`, which is the same `chmod(0o700)` on POSIX and an owner-only DACL on Windows. Its grants carry `(OI)(CI)`, so the `.pid` and `.bin` sidecars written by `atomic_write(mode=0o600)` — a no-op mode on Windows — inherit owner-only too. The helper is fail-loud, but `_run_dir` is reached through `secret_path()` on the dashboard's startup path, so the raise is absorbed and logged: the existing tighten-if-possible contract is what callers depend on. Co-authored-by: Leon Lai <laputaca@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Problem / Motivation
<config_dir>/runis the gateway's private sidecar directory. It holds:gateway-<port>.secret— the local API credential (cli_serverreads it viarun_marker.read_secret);gateway-<port>.pid— perread_pid's own docstring, "the identity a clientchecks before trusting the port";
gateway-<port>.bin— the launcher path the SSH token mint execs.run_marker._run_dirtightened it withos.chmod(d, 0o700). A POSIX mode ismeaningless on Windows, so the directory simply keeps the DACL it inherited.
Measured on Windows 11 with a data home on a non-profile volume:
Any authenticated account holds Modify on the directory and on the sidecars
created inside it.
The gap is not uniform even within this one directory:
dashboard/server.py's_write_secret_filedeliberately callsplatform_compat.restrict_to_owneronthe
.secretfile ("on Windows an owner-only DACL … a raw fchmod would be asilent no-op"), while
write_markerwrites the.pidand.binwithatomic_write(..., mode=0o600), whose mode is exactly that silent no-op. So thecredential is protected and the two files that decide which gateway a client
trusts are not.
Why it matters
On Windows the run directory and its
.pid/.binsidecars are writable byany authenticated local account.
read_pidis the ownership proofcli_serverchecks before trusting a port, and
prune_markersuses the same recorded pid todecide which sibling gateway's marker and credential it must not reap. A
tampered sidecar therefore steers a client's port trust and can direct the live
gateway's prune at a sibling's files.
The exposure is bounded by where the data home sits: under the default
%USERPROFILE%\.kiro, the profile's own ACL still keeps other users out. It isreal wherever
KIROCREW_HOMEpoints outside the profile — a data drive, ashared volume, a service account's working area — which the measurement above
reproduces.
restrict_dir_to_ownerexists precisely so this does not depend onwhere the data home was placed.
What changed (motivation → approach → change)
Symptom: an "owner-only" directory that is not owner-only on Windows. Root
cause: the wrong half of
AGENTS.md's cross-platform pair —platform_compat)restrict_dir_to_owner(path)restrict_to_owner(path)on a directory (its Windows grants carry no(OI)(CI)…)Change:
_run_dircallsplatform_compat.restrict_dir_to_owner(d). On POSIXthat helper is
os.chmod(path, 0o700), so nothing about Linux or macOSbehaviour moves — including the
nosemgrepsuppression, which now lives insidethe helper where it belongs. On Windows it applies the owner-only DACL.
The
(OI)(CI)inheritance is what makes this one call sufficient: files createdin the directory from then on inherit owner-only, so the
.pidand.binsidecars are covered without touching
write_markeror wideningatomic_write's contract. It is not a retrofit — as the helper's docstringnotes, a file that already exists keeps its own DACL — so an existing install
tightens on the next file write, not on the next
_run_dircall.The one deliberate difference from the helper's own contract is failure
handling.
restrict_dir_to_owneris fail-loud by design, but_run_dirisreached through
secret_path()fromdashboard/server.py's startup path, whichdoes not guard it; a directory that cannot be tightened (owned by another uid,
an unresolvable SID) must not take the gateway down. The pre-existing
best-effort contract is kept, with the swallowed error now logged rather than
silently
passed.Tests
Two tests in
test/test_instances.py::TestRunMarker:test_run_dir_lockdown_is_the_directory_helper—_run_dir()routes itstightening through
platform_compat.restrict_dir_to_ownerfor that exactpath. Red on
997d59421:assert [] == ['…\\run']. It re-patches the symbolover
conftest's session-wide Windows stub, so the assertion is not vacuouson the Windows matrix.
test_run_dir_lockdown_failure_is_best_effort— a raising lockdown stillreturns a usable directory, pinning the contract
secret_path()'s callerdepends on. This one passes before and after by construction; it exists so a
later change to the fail-loud helper cannot silently start taking the gateway
down at startup.
Green:
test_instances.py298 passed, 5 skipped (the single failure,test_no_anchored_pattern_uses_a_dollar_anchor, is a pre-existingcp950decode failure on this Windows box and reproduces identically on
997d59421).Siblings that consume the run marker —
test_cli_restart_marker_fallback.py,test_instance_credential_pairing.py,test_mcp_api_port_resolution.py,test_governance_self_protection.py— 215 passed, 1 skipped.Manual verification
The
icaclstable under Problem / Motivation is the manual verification:both directories created on the same Windows 11 host on a non-profile volume,
one tightened the old way and one through the helper, each with a
gateway-8080.pidcreated afterwards so the(OI)(CI)inheritance is shownrather than asserted. Unit coverage pins the call routing; only a real DACL read
can show what the call is worth.
Related Issues
None — found by auditing
AGENTS.md'splatform_compat"use this / NOT that"table against current
main.Pattern harvest
Rule candidate:
semgrepPattern:
os.chmod(dir, 0o700)(oros.chmod(file, 0o600)) used as a securitycontrol on a path that also exists on Windows, where the mode is a silent no-op.
The greppable shape is a raw
os.chmodwith an owner-only mode outsideplatform_compat, on a path under the data home; the fix isrestrict_dir_to_ownerfor directories andrestrict_to_ownerfor files. Thetell that it is worth a rule rather than a one-off: this repository already
carries the correct call in
mcp_gateway/apps.py, indashboard/server.py::_write_secret_file, and in theAGENTS.mdtable — theknowledge was present and the site still drifted.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code