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

Don't call umask in subscriptions #1421

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Apr 17, 2023

This call will be done in parallel which messes up the umask on CRI-O on container creation. This call will be done in parallel which messes up the umask on CRI-O on container creation. We now call chmod after directory and file creation to enforce the right permissions.

@rhatdan
Copy link
Member

rhatdan commented Apr 17, 2023

This is some ancient code that came from early days of Docker. Are you 100% sure this will not break some user of Podman or Buildah. Rootfull of rootless? Also what about using in podman-remote, where the service umask gets involved?

@rhatdan
Copy link
Member

rhatdan commented Apr 17, 2023

@giuseppe @mtrmac @nalind @vrothberg WDYT?

@saschagrunert
Copy link
Member Author

saschagrunert commented Apr 17, 2023

Are you 100% sure this will not break some user of Podman or Buildah. Rootfull of rootless? Also what about using in podman-remote, where the service umask gets involved?

I can't be sure that it won't break anything, but manually checking the code paths actually involved creating files/dirs with the correct mode. For what would we need the umask then?

I vendored the change into CRI-O to see if it fixes the umask issue: cri-o/cri-o#6785
Refers to bug: https://issues.redhat.com/browse/OCPBUGS-10704
Referencing discussion point: opencontainers/runc#3563 (review)

@rhatdan
Copy link
Member

rhatdan commented Apr 17, 2023

Lets wait for others to comment. This code was added by me, but not written by me, or at least I don't recall.

@mheon @baude Thoughts?

@Luap99
Copy link
Member

Luap99 commented Apr 17, 2023

As I read the code the goal is to keep the same permission as they are on the host. So if your umask is 077 as an example and on the host the dir has 755 as permission then calling mkdir with 755 will result in a directory with 700 permissions because the umask was applied.
Setting the umask to 0 fixes this but is obviously not thread safe, the other fix is to do an explicit chmod on the created directory/file afterwards because chmod ignores the umask.

@mtrmac
Copy link
Contributor

mtrmac commented Apr 17, 2023

Yes, AFAICS this must use an explicit chmod.

And if it is confusing or risky, it should ideally have unit tests that verify the expected behavior, before&after the refactoring.


(It would, also, uh, be useful for the subpackage to document what it does, and to have some discussion for why a single piece of code deals with RHEL subscription and with FIPS state.)

@saschagrunert
Copy link
Member Author

saschagrunert commented Apr 17, 2023

Hm, we need a somewhat urgent workaround for CRI-O, so I’ll see if I can restore the umask after the parallel calls to this method.

Let’s leave this PR open to aim for a cleaner mid-term solution which probably does also not require a backport.

@mtrmac
Copy link
Contributor

mtrmac commented Apr 17, 2023

A fix adding the Chowns, is IMHO, not that much work.

I worry that adding more Umask calls to a multi-threaded server is very likely to make the problem worse, even short-term, even if it fixes a specific reproducer right now.

@saschagrunert
Copy link
Member Author

A fix adding the Chowns, is IMHO, not that much work.

chmod, correct?

It depends, I’ll have to double check that when I’m back from kubecon how many backports we need for CRI-O.

@mtrmac
Copy link
Contributor

mtrmac commented Apr 17, 2023

Yes, Chmod. My mistake, I keep confusing the two for some reason.

@saschagrunert
Copy link
Member Author

Gave it a push from the airport, will come up with testing at some later point in time.

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 18, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhatdan
Copy link
Member

rhatdan commented Apr 19, 2023

LGTM

@mheon
Copy link
Member

mheon commented Apr 20, 2023

LGTM, but it would be nice to have a test before merge

@saschagrunert saschagrunert force-pushed the umask branch 3 times, most recently from ed02a6d to a5b8b7f Compare April 24, 2023 08:42
@saschagrunert
Copy link
Member Author

Updated the code as well as added tests.

Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

The …IgnoreUmask functions are a nice idea.

pkg/subscriptions/subscriptions_test.go Outdated Show resolved Hide resolved
pkg/subscriptions/subscriptions.go Outdated Show resolved Hide resolved
pkg/subscriptions/subscriptions.go Outdated Show resolved Hide resolved
@saschagrunert saschagrunert force-pushed the umask branch 3 times, most recently from d9effc7 to 0fc225e Compare April 25, 2023 07:37
@saschagrunert
Copy link
Member Author

I moved the functions to the umask package. We can re-use them in podman later on to fix: https://github.com/containers/podman/blob/3ecb174eeeda7aa218ecce8f20df2af301469d3e/libpod/container_internal_common.go#L2748-L2749

This call will be done in parallel which messes up the umask on CRI-O on
container creation. We now call `chmod` after directory and file
creation to enforce the right permissions.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

We can re-use them in podman later on to fix …

Good thinking.

LGTM. Thanks!

@mheon
Copy link
Member

mheon commented Apr 25, 2023

/lgtm

Really like the new umask package, that will definitely be useful.

@openshift-ci openshift-ci bot added the lgtm label Apr 25, 2023
@openshift-merge-robot openshift-merge-robot merged commit a670892 into containers:main Apr 25, 2023
@saschagrunert saschagrunert deleted the umask branch April 26, 2023 06:18
saschagrunert added a commit to saschagrunert/cri-o that referenced this pull request Apr 27, 2023
This fixes the umask `0` bug because it contains:
containers/common#1421

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/cri-o that referenced this pull request Apr 28, 2023
This fixes the umask `0` bug because it contains:
containers/common#1421

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants