Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing/fstest: TestFS: relax check ReadDir based on perms #63707

Open
dolmen opened this issue Oct 24, 2023 · 4 comments
Open

testing/fstest: TestFS: relax check ReadDir based on perms #63707

dolmen opened this issue Oct 24, 2023 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@dolmen
Copy link
Contributor

dolmen commented Oct 24, 2023

TL;DR

Drop one false positive case in testing/fstest.TestFS: it is ok for ReadDir to return ErrPermission if the fs.FileMode of the file says some users are not allowed to read the directory.

Context

With io/fs.FS, there is no way to select which permission bits (fs.FileMode) apply when reading a file. So fstest.TestFS has no way to enforce that given a FileMode's file/directory based on user/group/others permission bits, Open, ReadFile or ReadDir should trigger or not an fs.ErrPermission.

Currently any error (including ErrPermission) on ReadDir is always considered an error. However returning fs.ErrPermission is correct behaviour if the filesystem enforces fs.FileMode and the directory has read permissions bits off.

Proposal

I propose that TestFS to ignore ErrPermission on ReadDir if at least one read permission bit is not set: ignore ErrPermission (and silently skip other ReadDir checks) if mode & 0444 != 0444.

Impact

This change will only drop some returned errors and will never raise more errors, so backward compatibility is preserved.

@dolmen
Copy link
Contributor Author

dolmen commented Oct 24, 2023

Cc: @bcmills

dolmen added a commit to dolmen-go/sqlar that referenced this issue Oct 24, 2023
Add testdata/perms.sqlar to check the permissions system.

This allowed to discover two issues in testing/fstest.TestFS:
- golang/go#63675 errors must be unwrappable
- golang/go#63707 relax check on ReadDir if
  mode & 0444 != 0444
dolmen added a commit to dolmen-go/sqlar that referenced this issue Oct 24, 2023
Add testdata/perms.sqlar to check the permissions system.

This allowed to discover two issues in testing/fstest.TestFS:
- golang/go#63675 errors must be unwrappable
- golang/go#63707 relax check on ReadDir if
  mode & 0444 != 0444
@dolmen dolmen changed the title testing/fstest: TestFS: do not report ErrPermission as error for ReadDir based on mode testing/fstest: TestFS: relax check ReadDir based on perms Oct 24, 2023
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 24, 2023
@neild
Copy link
Contributor

neild commented Oct 25, 2023

Permission bits aren't universally supported; if TestFS should ignore a permission error opening a file with no Unix read bits, shouldn't it ignore a permission error opening a Windows file with an ACL forbidding access?

@dolmen
Copy link
Contributor Author

dolmen commented Apr 2, 2024

@josharian May I ask your opinion on this (as you were the author of #46776 as well as of various io/fs.FS implementations)?

@dolmen
Copy link
Contributor Author

dolmen commented Apr 2, 2024

@neild The documentation for fs.FileMode mentions:

The nine least-significant bits are the standard Unix rwxrwxrwx permissions. The values of these bits should be considered part of the public API and may be used in wire protocols or disk representations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants