Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Taught util.misc.mkdir() to set umask to allow group-w for makedirs c… #4000

Merged
merged 1 commit into from Oct 8, 2020

Conversation

ggainey
Copy link
Collaborator

@ggainey ggainey commented Oct 5, 2020

…alls.

Hunted down a LOT of makedirs calls and replaced with call to misc.mkdir()

fixes #7445

ggainey added a commit to ggainey/pulp_rpm that referenced this pull request Oct 5, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7653
Required PR: pulp/pulp#4000
ggainey added a commit to ggainey/pulp_docker that referenced this pull request Oct 5, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7654
Required PR: pulp/pulp#4000
ggainey added a commit to ggainey/pulp_docker that referenced this pull request Oct 5, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7654
Required PR: pulp/pulp#4000
@@ -124,7 +124,7 @@ def _open_metadata_file_handle(self):
parent_dir = os.path.dirname(self.metadata_file_path)

if not os.path.exists(parent_dir):
Copy link
Member

Choose a reason for hiding this comment

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

you don't need to check for presence of the path here, remove the if condition

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The os.access() check in the elif is only needed if we're not creating the path in the mkdir() call. I tried a couple of iterations here, and decided that while this one is a little redundant around the mkdir(), it seemed more clear in terms of understanding the code. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

oooh right, i did not notice the elif statement, i am cool with leaving if

@@ -6,22 +6,7 @@
from hashlib import sha256

from pulp.server.config import config


def mkdir(path):
Copy link
Member

Choose a reason for hiding this comment

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

👍 let's say no to the code duplication!

except OSError as exc:
if exc.errno != errno.EEXIST:
raise
misc.mkdir(profile_directory, mode=0755)
Copy link
Member

Choose a reason for hiding this comment

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

0775

Copy link
Member

Choose a reason for hiding this comment

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

i think this is important and i understand correctly how umask works - if having mode 0755 the result will be:
usr grp others
-rwx r-x r-x is represented in octal as 0755
-000 000 010 umask of 002 removes any permission where there is a 1
-rwx r-x r-x is the result achieved requesting 0755 with umask of 002...and we are screwed :)

if having mode 0775 the result will be:
usr grp others
-rwx rwx r-x is represented in octal as 0775
-000 000 010 umask of 002 removes any permission where there is a 1
-rwx rwx r-x is the result achieved requesting 0775 with umask of 002

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I left a few things like certificate-directories and this profiling-directory alone - they're not 'content', and are more sensitive to permissions. Unless we're migrating profiling-information, this set of perms shouldn't affect migration, and I felt it better to leave the permissions as they had been specifically set.

(Your understanding of umask is correct - it turns off permission-bits where the umask has a 1. So 0755, with the mkdirs() umask of 0002, leaves 0755)

Copy link
Member

@ipanova ipanova left a comment

Choose a reason for hiding this comment

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

changes look good to me, i will try to test them tomorrow.

@ipanova
Copy link
Member

ipanova commented Oct 6, 2020

@rohanpm please take a look to be sure that you are not impacted by this change in an unexpected way


:param args: path[, mode] that goes to os.makedirs
:param kwargs: path
:return:
"""
try:
mask = os.umask(0002)
os.makedirs(*args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

The umask is apparently never restored if this raises an exception. Should the original os.umask be above the "try", and the umask reset in a new "finally" block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

...I am an idiot. I had exactly that at some point, and apparently lost it somewhere along the way. Thank you for the great catch, that would have been very embarrassing to allow out into the wild!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rohanpm @ipanova fixed mkdir() - more eyes please, when you have a moment free

@rohanpm
Copy link
Contributor

rohanpm commented Oct 6, 2020

@rohanpm please take a look to be sure that you are not impacted by this change in an unexpected way

Thanks Ina, I don't see any reason this would be harmful for RHSM Pulp, though I believe there is a bug where umask may not be restored when intended.

…alls.

Hunted down a LOT of makedirs calls and replaced with call to misc.mkdir()

fixes #7445
ggainey added a commit to pulp/pulp_rpm that referenced this pull request Oct 8, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7653
Required PR: pulp/pulp#4000
@ipanova ipanova merged commit e067d28 into pulp:2-master Oct 8, 2020
zjhuntin pushed a commit to zjhuntin/pulp_rpm that referenced this pull request Oct 14, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7653
Required PR: pulp/pulp#4000

(cherry picked from commit 234c399)
zjhuntin pushed a commit to zjhuntin/pulp_docker that referenced this pull request Oct 14, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7654
Required PR: pulp/pulp#4000

(cherry picked from commit 69dbf8d)
zjhuntin pushed a commit to pulp/pulp_rpm that referenced this pull request Oct 14, 2020
Tracked down a lot of makedirs() calls and replaced them with misc.mkdir()

Note: required-PR is needed to fix the permission problem, but the code
will build/work without it.

fixes #7653
Required PR: pulp/pulp#4000

(cherry picked from commit 234c399)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants