Skip to content

[Feature]: skip the propagating ACL mutation when a read-only check proves the path already satisfies the policy #1298

Closed

Description

@brunoflma

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 icacls output 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 icacls output shapes rather than only fabricated simplified strings.

Related

Activity

  1. github-actions commented on Aug 8, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: unknown.

  2. added
    enhancement
    platform
    service
    on Aug 8, 2026
  3. Ingwannu commented on Aug 10, 2026

    @Ingwannu
    Owner

    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:

    • any command failure, localization ambiguity, unparsed ACE, inherited ACE, unresolved effective-token identity, or unexpected principal falls through to the existing mutation path;
    • compare the resolved read identity separately from the SID used for /grant, preserving the effective-token SID contract from [Bug][Windows] ACL hardening trusts USERDOMAIN and rejects workgroup local accounts #1149;
    • never memoize a successful verification as though a mutation occurred, and keep the existing timeout/failure behavior for the fallback path;
    • test real first-line and localized icacls shapes, inheritance-only full control, broad principals, case variation, unreadable output, and very large synthetic descendant counts without traversing them;
    • keep the optimization opt-in initially and document that it changes startup cost, not the resulting ACL policy.

    Please open the focused parser/verification PR you offered if you still have the real output fixtures. Keeping this issue open for that implementation.

  4. brunoflma commented on Aug 10, 2026

    @brunoflma
    Author

    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 cachedPrincipal before 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 integration cases 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-...-1001 lists back as DOMAIN\user:(F). Comparing the grant principal against a listing therefore never matches — and the failure mode is not a red test, it is false forever, so the optimization silently does nothing while still costing maintenance. The comparison needs the name form taken from the token (WindowsIdentity.GetCurrent().Name), never from USERDOMAIN/USERNAME, so #1149 holds; it is only ever used to read a DACL, never as a /grant target.

    Fresh numbers on this host, now that the tree is pruned to 14,123 descendants: DACL read 31 ms, findsid 27 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 icacls output rather than fabricated output.

  5. lidge-jun commented on Aug 19, 2026

    @lidge-jun
    Owner

    리뷰 · 우선순위 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이 작성했습니다

  6. brunoflma commented on Aug 20, 2026

    @brunoflma
    Author

    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:

    • only skip mutation after proving the complete target policy;
    • any command failure, localization ambiguity, unparsed or inherited ACE, unexpected principal, or unresolved effective-token identity falls through to the existing hardening path;
    • do not resolve identity with a fresh budget in the pre-check, because that would weaken the [Bug][Windows] ACL hardening trusts USERDOMAIN and rejects workgroup local accounts #1149 fail-closed contract;
    • preserve the existing timeout and failure semantics on the fallback path.

    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.

  7. Ingwannu commented on Aug 20, 2026

    @Ingwannu
    Owner

    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 icacls fixtures, 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.

  8. lidge-jun commented on Aug 30, 2026

    @lidge-jun
    Owner

    Implemented on dev in 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, localized icacls output 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplatformservice

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions