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

Add --umask flag for create, run #7006

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

ashley-cui
Copy link
Member

@ashley-cui ashley-cui commented Jul 17, 2020

--umask sets the umask inside the container
Defaults to 0022

Replaces #6946

Co-authored-by: Daniel J Walsh [email protected]
Signed-off-by: Ashley Cui [email protected]

@ashley-cui ashley-cui force-pushed the umask branch 2 times, most recently from 49ebbe8 to 0c29264 Compare July 17, 2020 13:20
session = podmanTest.Podman([]string{"create", "--umask", "9999", "--name", "bad", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Not(Equal(0)))
})
Copy link
Member

Choose a reason for hiding this comment

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

You're testing both create and confirming with inspect in here which is good. It might make sense to also add a part of this to the inspect test too, even though it would be redundant. I'll let @mheon make the call there.

@TomSweeneyRedHat
Copy link
Member

All kinds of test unhappiness @ashley-cui

@ashley-cui ashley-cui force-pushed the umask branch 2 times, most recently from 6dbb789 to 42bef7c Compare July 17, 2020 17:35
@rhatdan
Copy link
Member

rhatdan commented Jul 17, 2020

The random tests are blowing up with
time="2020-07-17T16:18:53-04:00" level=error msg="error starting some container dependencies"
time="2020-07-17T16:18:53-04:00" level=error msg=""Invalid Umask Value: strconv.ParseUint: parsing \"\": invalid syntax""

@rhatdan
Copy link
Member

rhatdan commented Jul 17, 2020

This looks like there is something wrong with the runtime-tools vendor, that is causing this issue.

# ./bin/podman pod create -p 8080:80 --name test1
d164202b886bb247f5b32b36ba0d6aa92aa14ab050a09eadc2fde0875cf1d13d
# ./bin/podman run --pod test1 fedora echo top
Error: open `/proc/1513113/ns/net`: No such file or directory: OCI runtime command not found error

@giuseppe @mheon PTAL

@rhatdan
Copy link
Member

rhatdan commented Jul 17, 2020

@ashley-cui I think you might want

diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 53b7f31c4..ed0a0f2da 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -341,12 +341,13 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
                g.SetProcessGID(uint32(execUser.Gid))
        }
 
-       decVal, err := strconv.ParseUint(c.config.Umask, 8, 32)
-       if err != nil {
-               return nil, errors.Wrapf(err, "Invalid Umask Value")
+       if c.config.Umask != "" {
+               decVal, err := strconv.ParseUint(c.config.Umask, 8, 32)
+               if err != nil {
+                       return nil, errors.Wrapf(err, "Invalid Umask Value: %q", c.config.Umask)
+               }
+               g.SetProcessUmask(uint32(decVal))
        }
-       g.SetProcessUmask(uint32(decVal))
-
        // Add addition groups if c.config.GroupAdd is not empty
        if len(c.config.Groups) > 0 {
                gids, err := lookup.GetContainerGroups(c.config.Groups, c.state.Mountpoint, overrides)

@ashley-cui
Copy link
Member Author

@rhatdan already updated :) the runtime-tools i vendored in myself, so it might be a vendoring error caused by me..

@@ -435,6 +435,9 @@ type ContainerConfig struct {
// Timezone is the timezone inside the container.
// Local means it has the same timezone as the host machine
Timezone string `json:"timezone,omitempty"`

// Umask is the umask inside the container.
Umask string `json:"umask,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Why are we storing this as a string? We should use whatever type the OCI spec uses - probably an int? Parsing should be done when we set the umask.

Copy link
Member

Choose a reason for hiding this comment

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

The value is actually an octal. Storing it as an int, may make it hard to convert and hard to view in inspect.

Copy link
Member Author

@ashley-cui ashley-cui Jul 19, 2020

Choose a reason for hiding this comment

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

yep, it's a octal representing a bitmap. setting umask to 0022 would actually show up as 18 if stored as an int. i got stuck on this for a good hour or two when implementing LOL

inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data[0].Config.Umask).To(Equal("0022"))
Copy link
Member

Choose a reason for hiding this comment

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

Coud you add a test for

podman run --umask 0077 fedora umask
And make sure it outputs 0077

@ashley-cui ashley-cui force-pushed the umask branch 3 times, most recently from ac042a1 to 6caa6c1 Compare July 19, 2020 01:18
@ashley-cui
Copy link
Member Author

I'm unable to reproduce locally the system tests that are failing but I confirmed that umask doesn't work on ubuntu at all. Any pointers on how to proceed? @rhatdan

@edsantiago
Copy link
Member

The system-test failures look suspiciously like something I may have introduced in #6958 - probably a bad interaction with a missing-cleanup bug in one of the integration tests. PR in progress.

The umask-on-ubuntu issue looks real though. FW(little)IW my guess is it's runc vs crun.

@ashley-cui
Copy link
Member Author

@edsantiago thanks! any idea who i should talk to about the ubuntu stuff?

@edsantiago
Copy link
Member

#7026 should fix the system-test flake. I'm sorry, I have no experience with Ubuntu and no idea how to investigate there. If you want to look into crun vs runc, you can reboot a Fedora system into cgroups v1 mode by booting with systemd.unified_cgroup_hierarchy=0

@ashley-cui ashley-cui force-pushed the umask branch 2 times, most recently from ce51a2e to c6bb490 Compare July 21, 2020 17:26

session = podmanTest.Podman([]string{"run", "--umask", "9999", "--rm", ALPINE, "sh", "-c", "umask"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Not(Equal(0)))
Copy link
Member

Choose a reason for hiding this comment

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

Ed's standard rant: it's important to check error messages, not just error codes:

    Expect(session.ErrorToString()).To(ContainSubstring("Invalid umask"))

Without that, the test could be failing for infinite unrelated reasons: too often a misspelled option or command name yields the expected nonzero exit status, but the test isn't actually testing anything.

Aside from that, lgtm. Nice set of tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, will keep in mind for future tests too :)

--umask sets the umask inside the container
Defaults to 0022

Co-authored-by: Daniel J Walsh <[email protected]>
Signed-off-by: Ashley Cui <[email protected]>
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-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashley-cui, giuseppe

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 22, 2020
@rhatdan
Copy link
Member

rhatdan commented Jul 22, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 22, 2020
@openshift-merge-robot openshift-merge-robot merged commit 59bad8b into containers:master Jul 22, 2020
@ashley-cui ashley-cui deleted the umask branch October 12, 2020 13:59
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants