Repository navigation
Description
Area
Platform / Windows ACL hardening
Goal
Avoid repeating an expensive recursive ACL mutation when a cheap read-only check can prove that a secret path already satisfies OpenCodex's Windows hardening policy.
This is separate from #1296, which tracks the misleading 401 authentication_error classification when ACL hardening fails. This issue owns the startup/performance optimisation that can avoid unnecessary ACL writes in the first place.
Problem
hardenSecretDir / hardenSecretPath currently run mutations such as:
icacls /grant:r <principal>:(OI)(CI)(F)
icacls /inheritance:r
On Windows, (OI)(CI) can propagate through descendants. The cost therefore scales with subtree size even when the root path already satisfies the desired policy.
Measured on the reporter's host:
| Descendants | /grant:r (OI)(CI) cost |
|---|---|
| 10 | 88 ms |
| 20,000 | 9,438 ms |
| 94,715 | about 45 s extrapolated |
Large trees can exceed the hardening budget and trigger the separate misclassification described in #1296.
Increasing the timeout only increases the allowed wait. It does not remove work that should have been a no-op.
Proposed behavior
Before mutating, optionally inspect the existing DACL using read-only icacls operations.
If the read proves the path already satisfies the policy exactly:
skip mutation -> success
If the read is missing, ambiguous, localized in an unexpected way, or otherwise cannot prove compliance:
fall through to existing hardening path
The optimisation must fail closed. It must never convert uncertainty into a security bypass.
Security requirements
The read-only verification must be strict:
- reject unparseable or incomplete ACL output;
- reject any inherited ACE, because inheritance still being active means hardening has work to do;
- parse the actual ACL structure rather than relying on one line-layout regex;
- handle the first ACE appearing on the same line as the echoed path;
- stop before localized summary text and never parse the summary as an ACE;
- compare principal names case-insensitively;
- preserve the effective-token SID identity contract from [Bug][Windows] ACL hardening trusts USERDOMAIN and rejects workgroup local accounts #1149;
- if the effective identity cannot be resolved safely, decline the optimisation and use the existing hardening path.
A specific identity trap must remain covered: the grant operation may use a SID while icacls lists the corresponding resolved account name. Verification therefore cannot assume the grant principal string and listing principal string are byte-identical.
Suggested rollout
An initial implementation may remain opt-in, for example behind the existing experimental direction:
OPENCODEX_ACL_VERIFY_EXISTING=1
The public configuration shape can follow repository conventions if this graduates beyond an experiment.
Expected result
For an already hardened secret path under a very large tree:
read DACL
↓
policy proven satisfied
↓
no propagating ACL write
↓
startup cost remains approximately independent of descendant count
For a new, changed, or unverifiable path, behavior remains the existing mutation path.
Acceptance criteria
- Already compliant paths can skip ACL mutation after a strict read-only proof.
- Verification cost does not scale with descendant count.
- Inherited ACEs are never accepted as fully hardened state.
- Single-ACE and multi-ACE
icaclsoutput are parsed correctly. - Localized summary lines do not create false positives.
- SID-to-resolved-name behavior is covered.
- Unknown/unparseable state falls back to mutation.
- [Bug][Windows] ACL hardening trusts USERDOMAIN and rejects workgroup local accounts #1149's effective-token identity guarantee is preserved.
- Existing hardening behavior for non-compliant paths does not regress.
- Regression tests use realistic
icaclsoutput shapes rather than only fabricated simplified strings.
Related
- [Bug]: a local Windows ACL hardening failure is returned to the client as
401 authentication_error#1296 - ACL hardening failure is misreported as401 authentication_error - [Bug][Windows] Native-main owner fails permanently closed when icacls is slow: 5s ACL-harden budget exhausted at startup, all native requests 503 (root cause of #1120?) #1156 - increased the hardening timeout envelope
- [Bug][Windows] ACL hardening trusts USERDOMAIN and rejects workgroup local accounts #1149 - effective-token SID identity hardening
Activity
github-actions commentedon Aug 8, 2026
Automated translation bookkeeping — detected language: unknown.
Ingwannu commentedon Aug 10, 2026
The measured performance problem and the proposed read-before-write shape are credible. The optimization is acceptable only as a strict proof of the complete target ACL policy, not as a best-effort heuristic.
A focused PR should preserve these boundaries:
/grant, preserving the effective-token SID contract from [Bug][Windows] ACL hardening trusts USERDOMAIN and rejects workgroup local accounts #1149;icaclsshapes, inheritance-only full control, broad principals, case variation, unreadable output, and very large synthetic descendant counts without traversing them;Please open the focused parser/verification PR you offered if you still have the real output fixtures. Keeping this issue open for that implementation.
brunoflma commentedon Aug 10, 2026
Two implementation notes I only learned by carrying this on 2.12.0, both of which cost me a regression and would cost an implementer the same. Adding them because the description alone would not have saved me.
1. The pre-check must consult the identity, not resolve it. The obvious shape — ask for the effective token SID, then read the DACL — quietly breaks the #1149 contract. When the SID cannot be resolved, upstream declines to touch the ACL at all: no
icacls, no timeout memo. A pre-check that resolves the identity through its own call can succeed where the harden path would have declined, then judge the DACL and report ok — relaxing a fail-closed guarantee it has no business relaxing.What worked: ask with a zero budget. Both resolvers answer from
cachedPrincipalbefore consulting the budget and decline without spawning once it is exhausted, so a zero budget is a cache read rather than a second lookup. Asking properly would have doubled identity spawns on the one path with no cache to hit — the failing one — and your own tests pin that count. The trade is that the first harden of a process always takes the full path and seeds the cache; every later one may use the pre-check. That is the right side of the trade, since the optimization is for repeated startups.I found this only by running the ACL suite with the feature flag set process-wide: three of your
effective Windows principal integrationcases went red. Under the flag-off default they stay green, so it is invisible unless you look for it.2. Since #1149 the grant principal is a SID, but a DACL listing echoes the resolved name. Measured here: granting
*S-1-5-21-...-1001lists back asDOMAIN\user:(F). Comparing the grant principal against a listing therefore never matches — and the failure mode is not a red test, it isfalseforever, so the optimization silently does nothing while still costing maintenance. The comparison needs the name form taken from the token (WindowsIdentity.GetCurrent().Name), never fromUSERDOMAIN/USERNAME, so #1149 holds; it is only ever used to read a DACL, never as a/granttarget.Fresh numbers on this host, now that the tree is pruned to 14,123 descendants: DACL read 31 ms,
findsid27 ms — both O(1) in subtree size, against a/grant:r (OI)(CI)that is linear in it. That asymmetry is the whole basis for the proposal and it holds up.Still happy to open a PR with the parser and its tests if the shape is welcome. The test material is the part I would most want reviewed — two of my own early regressions (accepting inheritance-only full control, and never matching single-ACE files) were caught only by reproducing real
icaclsoutput rather than fabricated output.lidge-jun commentedon Aug 19, 2026
리뷰 · 우선순위 48 / 80
Windows에서 비밀 경로 ACL이 이미 정책과 같으면, 비싼 재귀 icacls 쓰기를 건너뛰자는 시작 성능 요청입니다. #1296의 401 오분류와는 별개입니다. 큰 트리에서 grant가 초 단위로 늘면 하드닝 예산을 넘길 수 있습니다.
현재 dev의 src/lib/windows-secret-acl.ts는 hardenSecretDir/hardenSecretPath가 /grant:r와 /inheritance:r를 실행합니다. 주석은 상속 제거가 파괴적이라 오너 grant가 먼저여야 한다고 합니다. OPENCODEX_ACL_VERIFY_EXISTING나 읽기 전용으로 충족을 증명하고 쓰는 단계는 이 파일에 없습니다. #612 이후 일부 경로는 async라 이벤트 루프는 덜 막히지만, 불필요한 전파 쓰기는 그대로입니다.
원하는 계약은 읽기가 정책을 정확히 증명하면 성공으로 건너뛰고, 파싱 실패/상속 ACE/모호한 출력이면 지금 하드닝으로 떨어지는 것입니다. 불확실을 보안 우회로 바꾸면 안 됩니다. SID로 grant하고 icacls는 계정 이름을 보여 주는 경우도 같게 취급해야 하며, #1149 신원 계약을 깨면 안 됩니다.
해결방안: 읽기 전용 icacls로 DACL을 엄격히 파싱한 뒤, 증명이 될 때만 mutation을 건너뛰면 됩니다. 초기에는 실험 플래그 뒤에 두는 편이 안전합니다. 검증 비용이 자손 수에 비례하면 안 됩니다. 로케일 요약 줄을 ACE로 읽으면 거짓 양성이 납니다. 구현 세부 정규식은 여기서 쓰지 않겠습니다.
이 댓글은 grok-bot이 작성했습니다
brunoflma commentedon Aug 20, 2026
Update after validating the v2.28.0 migration (upstream base 5840591; local layer-I commit d775d4b83).
The read-only ACL pre-check remains a live local patch because the upstream tree still performs the propagating mutation path without an exact proof gate. The local implementation is now covered in the migration-focused ACL suite and the full migration validation remains clean (typecheck exit 0; 593 pass / 0 fail).
The strict boundary in this version is unchanged and worth preserving in any implementation:
The performance motivation is still material: the measured propagating grant was about 88 ms for 10 descendants and 9,438 ms for 20,000 descendants on the reporting host. The optimization is intended to make an already-compliant path a no-op without turning uncertainty into a security bypass.
Ingwannu commentedon Aug 20, 2026
Thanks for the v2.28.0 re-validation and the updated measurements. The issue remains valid, and the security boundary is unchanged: this optimization may skip mutation only after a complete read-only proof; every ambiguous, inherited, localized, unresolved, or unexpected ACL state must fall through to the existing hardening path.
The zero-budget cached-identity constraint and SID-to-resolved-name distinction are now part of the acceptance criteria for review. A focused PR should keep the first process harden on the full path, make the pre-check opt-in, use realistic
icaclsfixtures, and prove that verification cost is independent of descendant count without weakening #1149. I am keeping the issue open for that implementation; this update does not justify changing the current default by itself.lidge-jun commentedon Aug 30, 2026
Implemented on
devin dd3ff42 (#2963).Securing a secret path on Windows always ran the full mutation sequence --
/grant:r,/inheritance:r, broad-SID removal -- even when the DACL already matched policy exactly. There is now a read-only proof gate that skips the mutation when compliance can be proven.It is opt-in behind
OPENCODEX_ACL_VERIFY_EXISTING=1, and deliberately hard to satisfy: success requires explicit owner Full Control, inheritance disabled, and no unexpected principal. A parse failure, localizedicaclsoutput it cannot read, an inherited ACE, a broad principal, or an identity cache miss all fall through and mutate as before. A read-only success does not enter the post-mutation memo, and descendant cost stays constant.Default behavior with the variable unset is unchanged, which the tests assert directly.