Skip to content

Read real Windows ACLs in ai_tools fsutil.Stat - #50772

Draft
juan-fdz-hawa wants to merge 1 commit into
mainfrom
50703-ai_tools-world_writable-risk-flag-never-fires-on-windows
Draft

Read real Windows ACLs in ai_tools fsutil.Stat#50772
juan-fdz-hawa wants to merge 1 commit into
mainfrom
50703-ai_tools-world_writable-risk-flag-never-fires-on-windows

Conversation

@juan-fdz-hawa

@juan-fdz-hawa juan-fdz-hawa commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Resolves #50703

Stat() returned Perm{Known: false} unconditionally on Windows, so the world_writable risk flag on agent_instruction rows could never fire no matter what the file's real ACL was.

Split the permission read per platform: perm_unix.go keeps the mode-bit logic, perm_windows.go reads the DACL via GetSecurityInfo, and perm_acl.go holds the platform-neutral ACE decision rules so they are unit-testable anywhere. Known: false now means "could not determine" rather than "Windows".

Everyone (S-1-1-0) and Authenticated Users (S-1-5-11) count as world; BUILTIN\Users is excluded because standard locations grant it create rights by default.

Also adds ./orbit/pkg/table/ai_tools/... to the Windows CI package list, which otherwise never exercises this code.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

  • Timeouts are implemented and retries are limited to avoid infinite loops

  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes

Testing

For unreleased bug fixes in a release candidate, one of:

  • Confirmed that the fix is not expected to adversely impact load test results
  • Alerted the release DRI if additional load testing is needed

Database migrations

  • Checked schema for all modified table for columns that will auto-update timestamps during migration.
  • Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects.
  • Ensured the correct collation is explicitly set for character columns (COLLATE utf8mb4_unicode_ci).

New Fleet configuration settings

  • Setting(s) is/are explicitly excluded from GitOps

If you didn't check the box above, follow this checklist for GitOps-enabled settings:

  • Verified that the setting is exported via fleetctl generate-gitops
  • Verified the setting is documented in a separate PR to the GitOps documentation
  • Verified that the setting is cleared on the server if it is not supplied in a YAML file (or that it is documented as being optional)
  • Verified that any relevant UI is disabled when GitOps mode is enabled

fleetd/orbit/Fleet Desktop

  • Verified compatibility with the latest released version of Fleet (see Must rule)
  • If the change applies to only one platform, confirmed that runtime.GOOS is used as needed to isolate changes
  • Verified that fleetd runs on macOS, Linux and Windows
  • Verified auto-update works from the released version of component to the new version (see tools/tuf/test)

Summary by CodeRabbit

  • New Features

    • Added Windows permission inspection using file ACLs.
    • File permissions now report whether items are world-readable or world-writable, when determinable.
    • Added support for testing permission behavior across Windows and Unix systems.
  • Bug Fixes

    • Improved handling of missing files, unsupported permission entries, and indeterminate permission states.

Resolves #50703

Stat() returned Perm{Known: false} unconditionally on Windows, so the
world_writable risk flag on agent_instruction rows could never fire no
matter what the file's real ACL was.

Split the permission read per platform: perm_unix.go keeps the mode-bit
logic, perm_windows.go reads the DACL via GetSecurityInfo, and
perm_acl.go holds the platform-neutral ACE decision rules so they are
unit-testable anywhere. Known: false now means "could not determine"
rather than "Windows".

Everyone (S-1-1-0) and Authenticated Users (S-1-5-11) count as world;
BUILTIN\Users is excluded because standard locations grant it create
rights by default.

Also adds ./orbit/pkg/table/ai_tools/... to the Windows CI package list,
which otherwise never exercises this code.
@juan-fdz-hawa

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change adds cross-platform permission detection for ai_tools instruction files. Unix systems inspect POSIX mode bits. Windows systems inspect DACL entries for world-readable and world-writable access. The Windows implementation handles missing files, NULL DACLs, bounded ACE traversal, and unsupported ACE types. Unit tests cover ACL evaluation, and Windows tests validate real ACL configurations. The Windows Go test workflow now includes the ai_tools package.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: Windows ACL support in ai_tools fsutil.Stat.
Description check ✅ Passed The description explains the fix, references issue #50703, and includes the required checklist and testing sections.
Linked Issues check ✅ Passed The changes address issue #50703 by reading Windows DACLs, detecting world permissions, and testing the resulting risk behavior.
Out of Scope Changes check ✅ Passed All changes support the linked issue, including platform-specific ACL logic, tests, and Windows CI coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 50703-ai_tools-world_writable-risk-flag-never-fires-on-windows

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go`:
- Around line 67-72: Update the ACL evaluation logic around the write decision
handling to track FILE_WRITE_DATA, FILE_APPEND_DATA, DELETE, WRITE_DAC, and
WRITE_OWNER independently rather than collapsing them through writeMask. Set
WorldWritable when any of these effective capabilities is allowed, while
preserving per-capability deny precedence; add a regression case covering DELETE
denied followed by FILE_WRITE_DATA allowed.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go`:
- Around line 11-19: Update the permission lookup around os.Lstat in the
relevant Unix permission function to reject non-regular files, including
symlinks, by returning Perm{Known: false} before evaluating mode bits. Only
compute WorldReadable and WorldWritable for regular files, matching the
OpenRegular behavior on Windows.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go`:
- Around line 42-45: In the DACL evaluation logic, make incomplete or
unsupported evaluation return an unknown posture: at the AceCount limit check,
return Perm{} when truncation would occur instead of evaluating a shortened ACL,
and in the non-inherit-only unsupported ACE branch return Perm{} rather than
skipping it. Add tests covering both cases and verify Known is false.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 538a6a5f-9195-44dd-ae22-247c041bda8f

📥 Commits

Reviewing files that changed from the base of the PR and between f656ac5 and 01e55fb.

📒 Files selected for processing (7)
  • .github/workflows/test-go-windows.yml
  • orbit/pkg/table/ai_tools/internal/fsutil/fsutil.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_test.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows_test.go

Comment on lines +67 to +72
if !readDecided && a.Mask&readMask != 0 {
read, readDecided = a.Allow, true
}
if !writeDecided && a.Mask&writeMask != 0 {
write, writeDecided = a.Allow, true
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Evaluate each write capability separately.

Lines 70-71 treat any deny that intersects writeMask as a denial of all write access. A DACL that denies DELETE and later allows FILE_WRITE_DATA still permits a world principal to change file content. The current code returns WorldWritable: false.

Track decisions for each effective capability, including FILE_WRITE_DATA, FILE_APPEND_DATA, DELETE, WRITE_DAC, and WRITE_OWNER. Set WorldWritable when any capability is allowed. Add a regression case for a deny of DELETE followed by an allow of FILE_WRITE_DATA.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go` around lines 67 - 72,
Update the ACL evaluation logic around the write decision handling to track
FILE_WRITE_DATA, FILE_APPEND_DATA, DELETE, WRITE_DAC, and WRITE_OWNER
independently rather than collapsing them through writeMask. Set WorldWritable
when any of these effective capabilities is allowed, while preserving
per-capability deny precedence; add a regression case covering DELETE denied
followed by FILE_WRITE_DATA allowed.

Comment on lines +11 to +19
fi, err := os.Lstat(path)
if err != nil {
return Perm{}
}
m := fi.Mode().Perm()
return Perm{
WorldReadable: m&0o044 != 0,
WorldWritable: m&0o022 != 0,
Known: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not classify symlink mode bits as file permissions.

os.Lstat returns the symlink mode. Those mode bits do not control access to the link and are commonly 0777. This marks a symlinked instruction file as world-readable and world-writable even when no user can modify its target.

Reject non-regular files with Known: false, consistent with the Windows OpenRegular path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go` around lines 11 - 19,
Update the permission lookup around os.Lstat in the relevant Unix permission
function to reject non-regular files, including symlinks, by returning
Perm{Known: false} before evaluating mode bits. Only compute WorldReadable and
WorldWritable for regular files, matching the OpenRegular behavior on Windows.

Comment on lines +42 to +45
count := int(dacl.AceCount)
if count > maxACEs {
count = maxACEs
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Return an unknown posture after incomplete DACL evaluation.

The implementation returns Known: true after it omits part of a DACL. This can hide an applicable world allow ACE and suppress the risk flag.

  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go#L42-L45: If AceCount exceeds maxACEs, return Perm{} instead of evaluating a truncated ACL.
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go#L56-L57: If a non-inherit-only ACE type is unsupported, return Perm{} instead of skipping it.

Add tests for both cases. This preserves the documented rule that Known is false when permission evaluation cannot determine the posture.

📍 Affects 1 file
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go#L42-L45 (this comment)
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go#L56-L57
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go` around lines 42 -
45, In the DACL evaluation logic, make incomplete or unsupported evaluation
return an unknown posture: at the AceCount limit check, return Perm{} when
truncation would occur instead of evaluating a shortened ACL, and in the
non-inherit-only unsupported ACE branch return Perm{} rather than skipping it.
Add tests covering both cases and verify Known is false.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.38%. Comparing base (3de43c8) to head (01e55fb).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...it/pkg/table/ai_tools/internal/fsutil/perm_unix.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #50772      +/-   ##
==========================================
+ Coverage   68.35%   68.38%   +0.03%     
==========================================
  Files        3957     3963       +6     
  Lines      254097   254959     +862     
  Branches    13530    13530              
==========================================
+ Hits       173681   174350     +669     
- Misses      64860    65015     +155     
- Partials    15556    15594      +38     
Flag Coverage Δ
backend 69.61% <90.90%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

ai_tools: world_writable risk flag never fires on Windows

1 participant