Skip to content

respect umask for files / dirs (1.2) #6403

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

Merged

Conversation

ThomasWaldmann
Copy link
Member

No description provided.

@ThomasWaldmann
Copy link
Member Author

ThomasWaldmann commented Mar 4, 2022

this feels a bit dirty considering that it undoes some efforts of tempfile.mkstemp, but I don't see a better way.

chmod'ing it while it has the temp name at least avoids concurrent (and potentially even different) chmods onto the same filename.

@ThomasWaldmann ThomasWaldmann changed the title SaveFile: respect umask for final file mode, fixes #6400 respect umask for files / dirs (1.2) Mar 4, 2022
…up#6400

we tried to be very private / secure here, but that created the issue
that a less secure umask (like e.g. 0o007) just did not work.

to make the umask work, we must start from 0o777 mode and let the
umask do its work, like e.g. 0o777 & ~0o007 --> 0o770.

with borg's default umask of 0o077, it usually ends up being 0o700,
so only permissions for the user (not group, not others).
@ThomasWaldmann ThomasWaldmann force-pushed the fix-savefile-mode-1.2 branch from 7a9ae85 to f5a47d8 Compare March 4, 2022 20:24
@ThomasWaldmann
Copy link
Member Author

^^^ @enkore @textshell please review.

@ThomasWaldmann ThomasWaldmann marked this pull request as draft March 4, 2022 20:29
@ThomasWaldmann ThomasWaldmann marked this pull request as ready for review March 5, 2022 13:29
def ensure_dir(path, mode=stat.S_IRWXU, pretty_deadly=True):
def ensure_dir(path, mode=stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO, pretty_deadly=True):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, borg never calls this with the mode parameter, so the default value is always used.

permissions to the leaf directory
permissions to the leaf directory. The current umask value is masked out first.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^^ from the os.makedirs docs.

not giving a non-default mode to ensure_dir makes the leaf directory creation consistent with the potential parent directory creation: it just uses 0o777 & ~ umask everywhere (as usual).

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

Successfully merging this pull request may close these issues.

1 participant