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

Permission checking does not match Posix behaviour for root #431

Closed
ttsalo opened this issue Sep 21, 2018 · 4 comments
Closed

Permission checking does not match Posix behaviour for root #431

ttsalo opened this issue Sep 21, 2018 · 4 comments

Comments

@ttsalo
Copy link

ttsalo commented Sep 21, 2018

I'm trying to simulate file operations performed by root but ran into the following problem:

Permission checking in various operations including mkdir does not match real os behaviour when running as root. Real os ignores filesystem permissions when uid=0 whereas pyfakefs raises permission denied exceptions.


import os
from pyfakefs import fake_filesystem
filesystem = fake_filesystem.FakeFilesystem()
fake_os = fake_filesystem.FakeOsModule(filesystem)

os.mkdir("/tmp/test")
os.chmod("/tmp/test", 0o444)
os.mkdir("/tmp/test/test2")

os.rmdir("/tmp/test/test2")
os.rmdir("/tmp/test")

fake_os.mkdir("/tmp")
fake_os.mkdir("/tmp/test")
fake_os.chmod("/tmp/test", 0o444)

# Raises EACCES
fake_os.mkdir("/tmp/test/test2")
@mrbean-bremen
Copy link
Member

Yes, this is correct - we currently do not support this. A non-root user is assumed for all operations.
Also, the uid and gid file attributes are currently ignored (you can see this in the FakeFile description) - they are both set to None, though they can be set using chown.
I don't think that we will add full support for these, but support for root should not be too difficult. We may add a function to set the user id (we would assume a non-root user by default, independent of the rights of the user running the test), and handle the root (e.g. 0) case by ignoring the access restrictions if it is set.
Would that be sufficient for you?

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 22, 2018
- can be used to test root user
- see pytest-dev#431
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 22, 2018
- can be used to test root user
- see pytest-dev#431
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Oct 17, 2018
- can be used to test root user
- see pytest-dev#431
jmcgeheeiv pushed a commit that referenced this issue Oct 18, 2018
- can be used to test root user
- see #431
@mrbean-bremen
Copy link
Member

@ttsalo - please have a look if this is what you need. This basically just allows to set the root user, for which some of the permissions are ignored.

@ttsalo
Copy link
Author

ttsalo commented Oct 24, 2018

Thanks, that looks good. Setting the current UID is pretty much what we would need.

@mrbean-bremen
Copy link
Member

Ok, closing the issue in this case. Please reopen if something does not work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants