-
-
Notifications
You must be signed in to change notification settings - Fork 329
Set file permissions accoding to umask #325
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
Comments
Thanks @funkey. Do you know if there a reliable way to determine what the current user's umask is? I found something like this, but don't know if it's the best way, and involves temporarily obliterating the umask just to find out what it is, which seems a little awkward: import os
umask = os.umask(0)
os.umask(umask) Is this something that can be done once and cached somewhere, or would we need to query the umask before every time you want to change a file's permissions? Also wondering if file permissions should be surfaced as an argument to the |
I think this is the only way to get the umask, this seems to go back to the POSIX standard (see Caching should be fine, I don't think the umask of a process can be changed from the outside. Having file permissions as an optional argument to |
Cool. How about adding in a |
That sounds very reasonable to me! |
Great, thanks @funkey. A PR would be welcome if you have the time, otherwise we can label this as "help wanted". |
What if we just used a normal file (instead of a temp file)? Would that solve this issue? |
Actually, yes. That might be the easiest solution. |
How would you generate a name for that file?
…On Thu, 8 Nov 2018, 18:28 Jan Funke ***@***.*** wrote:
Actually, yes. That might be the easiest solution.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#325 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAq8QrfNwj4V3MrzCWjF6m6AcA110zVNks5utHfngaJpZM4YTd8Z>
.
|
Meaning the randomized part? We could use a UUID. |
So the benefit of using a normal file is (1) no need to query current umask, and (2) no need to chmod? I.e., in the default case (file should be created according to current umask) would you generate a temporary file name using UUID, then use the built-in open() function to open it? (Then use In the case where you want to allow the user to provide an explicit file mode, would you open the file with the lower-level os.open() function? Or open with built-in |
Thinking about this has actually reminded me that we might want to reconsider the strategy of using a different randomly-named temporary file for each atomic write. I've tried to write up the issue in #328. It's somewhat orthogonal to the issue here of file permissions, however if we are considering changes to the way files are created then #328 is also relevant. |
That's right.
Sounds like a good plan to me.
Wouldn't worry about this yet. This basically hasn't come up AFAICT. Except of course because temp files are a little unusual. Moving away from temp files should eliminate the need to think about this. |
This is bothering me a lot, since the directory storage created by Zarr cannot be shared between members of the group. See my quick fix in the PR, does that seem reasonable? |
+1 can this be included this in the next release? |
+1 In my opinion, this is absolutely necessary in UNIX enviroments, should be released ASAP ... |
Just in case someone needs it: I've solved this in a dirty way ... The problem comes with tempfile__mkstemp_inner, that creates the temp file with 0600 permissions. I've set up this to use current mask (mine takes into account group is 0007):
|
+1 A fix to this would be greatly appreciated. |
+1 We also ran into this limitation just recently. A fix seems necessary to be able share data as expected @raphaeldussin |
* Set file permissions in DirectoryStorage according to umask Fixes #325 * Use built-in open function * Adds link to GH issue * Adds release notes entry
### Description The `download_url_to_file` function in torch.hub uses a temporary file to prevent overriding a local working checkpoint with a broken download.This temporary file is created using `NamedTemporaryFile`. However, since `NamedTemporaryFile` creates files with overly restrictive permissions (0600), the resulting download will not have default permissions and will not respect umask on Linux (since moving the file will retain the restrictive permissions of the temporary file). This is especially problematic when trying to share model checkpoints between multiple users as other users will not even have read access to the file. The change in this PR fixes the issue by using custom code to create the temporary file without changing the permissions to 0600 (unfortunately there is no way to override the permissions behaviour of existing Python standard library code). This ensures that the downloaded checkpoint file correctly have the default permissions applied. If a user wants to apply more restrictive permissions, they can do so via usual means (i.e. by setting umask). See these similar issues in other projects for even more context: * borgbackup/borg#6400 * borgbackup/borg#6933 * zarr-developers/zarr-python#325 ### Issue #81297 ### Testing Extended the unit test `test_download_url_to_file` to also check permissions. Pull Request resolved: #82869 Approved by: https://github.com/vmoens
Zarr uses temporary files that are moved in place to write meta-files and chunks. As a side effect, the created containers are only readable by the user who created them (as is default for temporary files). A better approach might be to set the file permissions after the move according to the users
umask
.The text was updated successfully, but these errors were encountered: