summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-07-09 14:53:46 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-08-20 13:35:11 -0400
commit4e31c8136dffd2272e49715b83fba092621ffd2a (patch)
tree52070eed2d7619f1a33c40ff826c681fb6dc6e7f /cmd/podman
parent386de7a1fbfef0c266e04f6471f9382a5d39a02f (diff)
downloadpodman-4e31c8136dffd2272e49715b83fba092621ffd2a.tar.gz
podman-4e31c8136dffd2272e49715b83fba092621ffd2a.tar.bz2
podman-4e31c8136dffd2272e49715b83fba092621ffd2a.zip
Cleanup handling of podman mount/unmount
We should default to the user name unmount rather then the internal name of umount. Also User namespace was not being handled correctly. We want to inform the user that if they do a mount when in rootless mode that they have to be first in the podman unshare state. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/mount.go17
-rw-r--r--cmd/podman/containers/unmount.go41
-rw-r--r--cmd/podman/main.go18
-rw-r--r--cmd/podman/registry/config.go3
4 files changed, 49 insertions, 30 deletions
diff --git a/cmd/podman/containers/mount.go b/cmd/podman/containers/mount.go
index 37ee92177..e2603a55c 100644
--- a/cmd/podman/containers/mount.go
+++ b/cmd/podman/containers/mount.go
@@ -10,6 +10,7 @@ import (
"github.com/containers/libpod/v2/cmd/podman/utils"
"github.com/containers/libpod/v2/cmd/podman/validate"
"github.com/containers/libpod/v2/pkg/domain/entities"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@@ -31,7 +32,8 @@ var (
return validate.CheckAllLatestAndCIDFile(cmd, args, true, false)
},
Annotations: map[string]string{
- registry.ParentNSRequired: "",
+ registry.UnshareNSRequired: "",
+ registry.ParentNSRequired: "",
},
}
@@ -51,7 +53,7 @@ var (
func mountFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&mountOpts.All, "all", "a", false, "Mount all containers")
- flags.StringVar(&mountOpts.Format, "format", "", "Change the output format to Go template")
+ flags.StringVar(&mountOpts.Format, "format", "", "Print the mounted containers in specified format (json)")
flags.BoolVar(&mountOpts.NoTruncate, "notruncate", false, "Do not truncate output")
}
@@ -90,14 +92,21 @@ func mount(_ *cobra.Command, args []string) error {
}
return errs.PrintErrors()
}
- if mountOpts.Format == "json" {
+
+ switch mountOpts.Format {
+ case "json":
return printJSON(reports)
+ case "":
+ // do nothing
+ default:
+ return errors.Errorf("unknown --format argument: %s", mountOpts.Format)
}
+
mrs := make([]mountReporter, 0, len(reports))
for _, r := range reports {
mrs = append(mrs, mountReporter{r})
}
- row := "{{.ID}} {{.Path}}"
+ row := "{{.ID}} {{.Path}}\n"
format := "{{range . }}" + row + "{{end}}"
tmpl, err := template.New("mounts").Parse(format)
if err != nil {
diff --git a/cmd/podman/containers/unmount.go b/cmd/podman/containers/unmount.go
index c40c2be7e..6556a6510 100644
--- a/cmd/podman/containers/unmount.go
+++ b/cmd/podman/containers/unmount.go
@@ -18,31 +18,32 @@ var (
An unmount can be forced with the --force flag.
`
- umountCommand = &cobra.Command{
- Use: "umount [flags] CONTAINER [CONTAINER...]",
- Aliases: []string{"unmount"},
+ unmountCommand = &cobra.Command{
+ Use: "unmount [flags] CONTAINER [CONTAINER...]",
+ Aliases: []string{"umount"},
Short: "Unmounts working container's root filesystem",
Long: description,
RunE: unmount,
Args: func(cmd *cobra.Command, args []string) error {
return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
},
- Example: `podman umount ctrID
- podman umount ctrID1 ctrID2 ctrID3
- podman umount --all`,
+ Example: `podman unmount ctrID
+ podman unmount ctrID1 ctrID2 ctrID3
+ podman unmount --all`,
}
containerUnmountCommand = &cobra.Command{
- Use: umountCommand.Use,
- Short: umountCommand.Short,
- Long: umountCommand.Long,
- RunE: umountCommand.RunE,
+ Use: unmountCommand.Use,
+ Short: unmountCommand.Short,
+ Aliases: unmountCommand.Aliases,
+ Long: unmountCommand.Long,
+ RunE: unmountCommand.RunE,
Args: func(cmd *cobra.Command, args []string) error {
return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
},
- Example: `podman container umount ctrID
- podman container umount ctrID1 ctrID2 ctrID3
- podman container umount --all`,
+ Example: `podman container unmount ctrID
+ podman container unmount ctrID1 ctrID2 ctrID3
+ podman container unmount --all`,
}
)
@@ -50,25 +51,25 @@ var (
unmountOpts entities.ContainerUnmountOptions
)
-func umountFlags(flags *pflag.FlagSet) {
- flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Umount all of the currently mounted containers")
- flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete umount all of the currently mounted containers")
+func unmountFlags(flags *pflag.FlagSet) {
+ flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Unmount all of the currently mounted containers")
+ flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete unmount of the specified mounted containers")
}
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
- Command: umountCommand,
+ Command: unmountCommand,
})
- umountFlags(umountCommand.Flags())
- validate.AddLatestFlag(umountCommand, &unmountOpts.Latest)
+ unmountFlags(unmountCommand.Flags())
+ validate.AddLatestFlag(unmountCommand, &unmountOpts.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Command: containerUnmountCommand,
Parent: containerCmd,
})
- umountFlags(containerUnmountCommand.Flags())
+ unmountFlags(containerUnmountCommand.Flags())
validate.AddLatestFlag(containerUnmountCommand, &unmountOpts.Latest)
}
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index 5f740a006..4bdb020af 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -39,13 +39,21 @@ func main() {
for _, m := range c.Mode {
if cfg.EngineMode == m {
// Command cannot be run rootless
- _, found := c.Command.Annotations[registry.ParentNSRequired]
- if rootless.IsRootless() && found {
- c.Command.RunE = func(cmd *cobra.Command, args []string) error {
- return fmt.Errorf("cannot run command %q in rootless mode", cmd.CommandPath())
+ _, found := c.Command.Annotations[registry.UnshareNSRequired]
+ if found {
+ if rootless.IsRootless() && found && os.Getuid() != 0 {
+ c.Command.RunE = func(cmd *cobra.Command, args []string) error {
+ return fmt.Errorf("cannot run command %q in rootless mode, must execute `podman unshare` first", cmd.CommandPath())
+ }
+ }
+ } else {
+ _, found = c.Command.Annotations[registry.ParentNSRequired]
+ if rootless.IsRootless() && found {
+ c.Command.RunE = func(cmd *cobra.Command, args []string) error {
+ return fmt.Errorf("cannot run command %q in rootless mode", cmd.CommandPath())
+ }
}
}
-
parent := rootCmd
if c.Parent != nil {
parent = c.Parent
diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go
index 24e728bad..ea33e3a4e 100644
--- a/cmd/podman/registry/config.go
+++ b/cmd/podman/registry/config.go
@@ -15,7 +15,8 @@ import (
)
const (
- ParentNSRequired = "ParentNSRequired"
+ ParentNSRequired = "ParentNSRequired"
+ UnshareNSRequired = "UnshareNSRequired"
)
var (