-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
feat: improve permissions support #1059
Conversation
While files are not a permitted place to create subdirectories in, the proper error should be ENOTDIR, not EACCES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is looking good to me - would you mind just running prettier
over the files? (don't worry about commitlint, as everything will get squashed when we merge 🙂)
I found a bug in |
# [4.12.0](v4.11.2...v4.12.0) (2024-09-19) ### Features * improve permissions support ([#1059](#1059)) ([575a76b](575a76b))
🎉 This PR is included in version 4.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [4.12.0](streamich/memfs@v4.11.2...v4.12.0) (2024-09-19) ### Features * improve permissions support ([streamich#1059](streamich#1059)) ([575a76b](streamich@575a76b))
Pursuant to our discussion in #1009, this PR adds basic permission support to memfs. It supports the POSIX-compliant r, w and x permissions for user, group and world. It does not support the more eclectic permissions such as SUID, GUID, or the sticky bit.
Some remarks on design considerations/implementation details:
All permissions checking is done within
Volume
.Node
andLink
remain permission agnostic, to stay in keeping with how existence checking was done. To make this possible, tree walking had to be moved fromLink
to a private method on the volume, though. The overhead, as per your requirement, is pretty small.Extensive tests are under
src/__tests__/volume/*
. I could not quite figure out by what logic tests go intosrc/__tests__/volume.test.ts
as opposed to a dedicated file undersrc/__tests__/volume/
. In the end, I decided the latter was probably sort of avolume.test.d
directory.I did not implement permissions checking for
chmod
andchown
, because their security model largely depends on whether the user is root or not. (More specifically, on whether the executing process has certain capability flags set, which I'm not sure there is a way to check from within Node.js anyways.) (NB: Forchmod
, it also depends on whether the current user is the owner of the file to be changed.) For the most part, I left this out to prevent creating situations where the user locks themselves out from accessing a file, which is then irrevocable due to the lack of a concept of elevating privileges.I think in the
open*
code path, there is duplicate symlink resolution: first by openFile, then again by openLink. I commented the second one out for a try, and all tests still passed. But since was already the case before I changed things around, I do not feel quite confident enough to delete it. In this PR, it is active code, but maybe you can take a look at it yourself.Resolves #1009