Skip to content

feat: improve permissions support#1059

Merged
G-Rath merged 16 commits intostreamich:masterfrom
BadIdeaException:master
Sep 19, 2024
Merged

feat: improve permissions support#1059
G-Rath merged 16 commits intostreamich:masterfrom
BadIdeaException:master

Conversation

@BadIdeaException
Copy link
Copy Markdown
Contributor

@BadIdeaException BadIdeaException commented Sep 15, 2024

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:

  1. All permissions checking is done within Volume. Node and Link remain permission agnostic, to stay in keeping with how existence checking was done. To make this possible, tree walking had to be moved from Link to a private method on the volume, though. The overhead, as per your requirement, is pretty small.

  2. Extensive tests are under src/__tests__/volume/*. I could not quite figure out by what logic tests go into src/__tests__/volume.test.ts as opposed to a dedicated file under src/__tests__/volume/. In the end, I decided the latter was probably sort of a volume.test.d directory.

  3. I did not implement permissions checking for chmod and chown, 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: For chmod, 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.

  4. 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

@G-Rath G-Rath changed the title Permissions support feat: improve permissions support Sep 15, 2024
Copy link
Copy Markdown
Collaborator

@G-Rath G-Rath left a 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 🙂)

@BadIdeaException
Copy link
Copy Markdown
Contributor Author

I found a bug in utimes, which required permissions on the target when it shouldn't have. Fixed.

@G-Rath G-Rath merged commit 575a76b into streamich:master Sep 19, 2024
github-actions bot pushed a commit that referenced this pull request Sep 19, 2024
# [4.12.0](v4.11.2...v4.12.0) (2024-09-19)

### Features

* improve permissions support ([#1059](#1059)) ([575a76b](575a76b))
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

BadIdeaException pushed a commit to BadIdeaException/memfs that referenced this pull request Oct 2, 2024
# [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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permissions support

2 participants