diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/commands.go | 1 | ||||
-rw-r--r-- | cmd/podman/events.go | 2 | ||||
-rw-r--r-- | cmd/podman/unshare.go | 54 | ||||
-rw-r--r-- | cmd/podman/varlink.go | 4 | ||||
-rw-r--r-- | cmd/podman/version.go | 2 |
5 files changed, 59 insertions, 4 deletions
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go index 3a409f503..2ac465b9d 100644 --- a/cmd/podman/commands.go +++ b/cmd/podman/commands.go @@ -20,6 +20,7 @@ func getMainCommands() []*cobra.Command { _refreshCommand, _searchCommand, _statsCommand, + _unshareCommand, } if len(_varlinkCommand.Use) > 0 { diff --git a/cmd/podman/events.go b/cmd/podman/events.go index 15f5e9571..88c1010e3 100644 --- a/cmd/podman/events.go +++ b/cmd/podman/events.go @@ -13,7 +13,7 @@ var ( _eventsCommand = &cobra.Command{ Use: "events", Args: noSubArgs, - Short: "show podman events", + Short: "Show podman events", Long: eventsDescription, RunE: func(cmd *cobra.Command, args []string) error { eventsCommand.InputArgs = args diff --git a/cmd/podman/unshare.go b/cmd/podman/unshare.go new file mode 100644 index 000000000..1db647dba --- /dev/null +++ b/cmd/podman/unshare.go @@ -0,0 +1,54 @@ +// +build linux + +package main + +import ( + "os" + "os/exec" + + "github.com/containers/buildah/pkg/unshare" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +var ( + unshareDescription = "Runs a command in a modified user namespace." + _unshareCommand = &cobra.Command{ + Use: "unshare [flags] [COMMAND [ARG]]", + Short: "Run a command in a modified user namespace", + Long: unshareDescription, + RunE: unshareCmd, + Example: `podman unshare id + podman unshare cat /proc/self/uid_map, + podman unshare podman-script.sh`, + } +) + +func init() { + _unshareCommand.SetUsageTemplate(UsageTemplate()) + flags := _unshareCommand.Flags() + flags.SetInterspersed(false) +} + +// unshareCmd execs whatever using the ID mappings that we want to use for ourselves +func unshareCmd(c *cobra.Command, args []string) error { + if isRootless := unshare.IsRootless(); !isRootless { + return errors.Errorf("please use unshare with rootless") + } + // exec the specified command, if there is one + if len(args) < 1 { + // try to exec the shell, if one's set + shell, shellSet := os.LookupEnv("SHELL") + if !shellSet { + return errors.Errorf("no command specified and no $SHELL specified") + } + args = []string{shell} + } + cmd := exec.Command(args[0], args[1:]...) + cmd.Env = unshare.RootlessEnv() + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + unshare.ExecRunnable(cmd) + return nil +} diff --git a/cmd/podman/varlink.go b/cmd/podman/varlink.go index 215542d2c..698a30d84 100644 --- a/cmd/podman/varlink.go +++ b/cmd/podman/varlink.go @@ -29,7 +29,7 @@ var ( Tools speaking varlink protocol can remotely manage pods, containers and images. ` _varlinkCommand = &cobra.Command{ - Use: "varlink [flags] URI", + Use: "varlink [flags] [URI]", Short: "Run varlink interface", Long: varlinkDescription, RunE: func(cmd *cobra.Command, args []string) error { @@ -68,7 +68,7 @@ func varlinkCmd(c *cliconfig.VarlinkValues) error { args := c.InputArgs if len(args) > 1 { - return errors.Errorf("too many arguments. you may optionally provide 1") + return errors.Errorf("too many arguments. You may optionally provide 1") } if len(args) > 0 { diff --git a/cmd/podman/version.go b/cmd/podman/version.go index 439a1cca6..52a518db8 100644 --- a/cmd/podman/version.go +++ b/cmd/podman/version.go @@ -70,7 +70,7 @@ func versionCmd(c *cliconfig.VersionValues) error { if remote { fmt.Fprintf(w, "\nService:\n") - runtime, err := adapter.GetRuntime(getContext(), nil) + runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } |