Skip to content

Commit

Permalink
rootless: not require userns for help/version
Browse files Browse the repository at this point in the history
these commands do not require to be root in an userns

Closes: #1263

Signed-off-by: Giuseppe Scrivano <[email protected]>

Closes: #1268
Approved by: vrothberg
  • Loading branch information
giuseppe authored and rh-atomic-bot committed Aug 14, 2018
1 parent 9563f31 commit a04ce68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@ var (
exitCode = 125
)

var cmdsNotRequiringRootless = map[string]bool{"help": true, "version": true}

func main() {
debug := false
cpuProfile := false

became, ret, err := rootless.BecomeRootInUserNS()
if err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
if became {
os.Exit(ret)
}

if reexec.Init() {
return
}
Expand Down Expand Up @@ -97,6 +90,19 @@ func main() {
}

app.Before = func(c *cli.Context) error {
args := c.Args()
if args.Present() {
if _, notRequireRootless := cmdsNotRequiringRootless[args.First()]; !notRequireRootless {
became, ret, err := rootless.BecomeRootInUserNS()
if err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
if became {
os.Exit(ret)
}
}
}
if c.GlobalBool("syslog") {
hook, err := lsyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
if err == nil {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/rootless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ var _ = Describe("Podman rootless", func() {
GinkgoWriter.Write([]byte(timedResult))
})

It("podman rootless help|version", func() {
commands := []string{"help", "version"}
for _, v := range commands {
env := os.Environ()
cmd := podmanTest.PodmanAsUser([]string{v}, 1000, 1000, env)
cmd.WaitWithDefaultTimeout()
Expect(cmd.ExitCode()).To(Equal(0))
}
})

It("podman rootless rootfs", func() {
// Check if we can create an user namespace
err := exec.Command("unshare", "-r", "echo", "hello").Run()
Expand Down

0 comments on commit a04ce68

Please sign in to comment.