Skip to content

fix(private-storage): throttle the ACL repair sweep on Windows - #333

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/acl-sweep
Open

raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/acl-sweep

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

harden_private_tree re-walked the whole session tree on every client start and spawned one icacls per entry. On a mature tree that cost about 24 seconds before the interactive client could draw. Every path DeepCode creates is already restricted when it is created, so the sweep is a repair pass, not the write path.

Two bounds:

  1. The sweep runs at most once per week on Windows, recorded by a stamp inside the tree. force=True still requests an immediate repair.
  2. One restriction gets one 10 s budget for its three icacls calls (grant, strip inheritance, remove broad principals) instead of up to 20 s each. After a spawn stalls, the code stops paying that budget for 120 s — a degraded host keeps inherited ACLs (the documented fail-safe) rather than stalling every connect.

Changes

  • core/private_storage.py
    • _ACL_SWEEP_STAMP_NAME, _ACL_SWEEP_INTERVAL_SECONDS; _acl_sweep_is_fresh() / _mark_acl_sweep().
    • harden_private_tree(root, *, force=False) skips a fresh sweep and marks a completed one.
    • _run_icacls(..., abandon_after=None); _restrict_windows_acl shares a deadline across its three calls; a stalled spawn sets a 120 s cooldown.
  • tests/test_private_storage_acl_once.py — the throttle test (Windows-only) and **_kwargs in the three existing stubs.

Security Considerations

  • Attack surface changed: none added. No new parser, no new external input; the stamp is one file inside the already-private tree.
  • Why it is safe: the sweep is a repair of ACLs that were already applied at creation; skipping a repair for a week cannot widen access. Failures still leave inherited ACLs (access preserved, never escalated), which is the existing fail-safe direction.
  • Fail-safe defaults: force=True is available to callers that need an immediate pass; a missing/corrupt stamp only means the next start sweeps again.
  • What it does not do: it does not relax any permission decision, and it does not change the restriction applied to newly created files.

Tests

tests/test_private_storage_acl_once.py — 9 passed on this revision (the throttle case is skipped off Windows); pre-commit (ruff 0.15.21 + ruff-format) clean.

I could not add the security label or request a reviewer from a fork (no write access) — flagging here instead as the contributing guide asks, and requesting @Zongwei9888's security review in a comment.

`harden_private_tree` re-walked the whole session tree on every client start
and spawned one `icacls` per entry; a few hundred sessions took ~24 s before the
interactive client drew. Every path is already restricted when it is created, so
the sweep is a repair, not the write path: it now runs at most once per week
(a stamp inside the tree) and `force=True` still requests an immediate pass.

Also bound the three `icacls` calls of one restriction with a shared 10 s
budget, and stop paying that budget for 120 s after a spawn stalls — a degraded
host keeps inherited ACLs (the documented fail-safe) instead of stalling every
connect.

Tests: the throttle skips a fresh stamp and `force` bypasses it; the existing
ACL tests cover the fail-safe ordering.
@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

@Zongwei9888 requesting security review for this change (ACL repair sweep throttling). Security Considerations are in the PR description; happy to adjust the interval, the force path, or the spawn-stall budget if you prefer different defaults.

This branch has not been deployed

No deployments
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