Skip to content

fix: skip permission-denied paths instead of crashing on directory walk (#3258)#4880

Open
tjhub1983 wants to merge 1 commit into
anchore:mainfrom
tjhub1983:fix-excluded-paths-permission-v2
Open

fix: skip permission-denied paths instead of crashing on directory walk (#3258)#4880
tjhub1983 wants to merge 1 commit into
anchore:mainfrom
tjhub1983:fix-excluded-paths-permission-v2

Conversation

@tjhub1983

@tjhub1983 tjhub1983 commented May 4, 2026

Copy link
Copy Markdown

Summary

Fixes #3258.

When scanning a directory with excluded paths, syft would crash if it encountered permission-denied directories (e.g., /boot/grub2 owned by root) during the ancestor path walk, even when those paths were excluded.

Before: unable to index ancestor path="/boot/grub2": permission denied → syft exits with error
After: Permission-denied paths are skipped and logged, scan continues

The fix adds r.isFileAccessErr(targetPath, err) check at line 218 of directory_indexer.go. When os.Lstat fails with a file access error, the ancestor walk continues instead of returning an error. This matches the behavior of filepath.Walk which skips permission errors.

Changes

  • syft/internal/fileresolver/directory_indexer.go: Skip file access errors in indexBranch ancestor walk instead of returning an error

Test

$ sudo -u nobody syft / --exclude ./boot --exclude ./web
# Previously: crash on permission denied
# Now: logs warning and continues

Related

This was discussed in syft#3258 with the suggestion that excluded paths should not be accessed at all. While the ideal long-term fix would prevent access to excluded paths entirely, this change provides immediate relief by making permission errors non-fatal.

…lk (anchore#3258)

Signed-off-by: tjhub1983 <tjhub1983@users.noreply.github.com>
@tjhub1983 tjhub1983 changed the title test fix: skip permission-denied paths instead of crashing on directory walk (#3258) May 4, 2026
@tjhub1983

Copy link
Copy Markdown
Author

Hi @anchore/syft-maintainers!

This PR fixes #3258 — a crash when scanning directories with excluded paths that contain permission-denied directories (e.g., /boot/grub2).

The CI workflow runs are showing action_required status, which likely means the custom runs-on.com runner needs maintainer approval for fork PRs.

Could you please approve the CI runs for this PR? Happy to make any adjustments needed.

Thank you!

// file access errors (e.g. permission denied on restricted directories like /boot/grub2)
// should not stop the walk -- skip and continue, matching filepath.Walk behavior.
// Only fail for truly unexpected errors (ErrSkipPath and fs.SkipDir are expected/safe).
if r.isFileAccessErr(targetPath, err) {

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.

Is there some way to add a test for this that isn't too convoluted to set up?

@wagoodman wagoodman self-assigned this May 4, 2026
// file access errors (e.g. permission denied on restricted directories like /boot/grub2)
// should not stop the walk -- skip and continue, matching filepath.Walk behavior.
// Only fail for truly unexpected errors (ErrSkipPath and fs.SkipDir are expected/safe).
if r.isFileAccessErr(targetPath, err) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@kzantow Thanks for the review!

Regarding the test: a reliable permission-denied test typically requires OS-level permission manipulation which can be flaky across platforms (especially Windows). The existing unit tests cover the core logic paths (walkWithExclusion, walkDir), but testing the permission-denied scenario at the integration level requires either:

  1. Using os.Chmod to make a directory unreadable (platform-dependent, may not work reliably on Windows)
  2. A mock filesystem approach

I'm happy to add a test using approach #1 if you think it's worth the added complexity, or handle it as a follow-up issue. Let me know how you'd like to proceed.

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.

This needs to have a test. The test can create a filesystem with this scenario.

@tjhub1983

Copy link
Copy Markdown
Author

Hi @anchore/syft-maintainers!

All CI checks have passed:

  • Unit tests ✅
  • Integration tests ✅
  • CLI tests (Linux) ✅
  • Acceptance tests (Linux/Mac) ✅
  • Static analysis ✅
  • Build snapshot artifacts ✅

Is there anything else needed to move this forward? This PR fixes the crash when scanning directories with excluded paths that contain permission-denied directories (e.g., /boot/grub2 on Linux).

@tjhub1983

Copy link
Copy Markdown
Author

Hi maintainers! All CI checks have passed. Is there anything blocking this from being merged? Happy to address any feedback!

@tjhub1983

Copy link
Copy Markdown
Author

Just checking in again - is there anything else needed to move this forward? All CI checks are green and kzantow reviewed previously. Happy to make any adjustments! @anchore/syft-maintainers

@tjhub1983

Copy link
Copy Markdown
Author

Just checking - is there anything needed from my side to move this forward?

@tjhub1983

Copy link
Copy Markdown
Author

ping @kzantow - PR #4880 has CI passing and your comments. Could you please review/approve so we can get this merged? Thanks!

@tjhub1983

Copy link
Copy Markdown
Author

?? Hi maintainers! Just checking in on this PR. Is there anything else needed from my side to move forward? Thanks!

@tjhub1983

Copy link
Copy Markdown
Author

?? Hi maintainers! Just checking in on this PR. Is there anything else needed? Thanks for your time!

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.

Excluded paths are still scanned and cause syft to crash.

3 participants