summaryrefslogtreecommitdiff
path: root/cmd
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-07-27 16:53:02 -0400
commit8f7ed50cb20c04bbbb7c4907a183c07912d4bffb (patch)
tree14001f06bc0a278d0e34c6e7312ffd08c3afe526 /cmd
parent2b7bc9b101887a789a9fc0282d448efad824404f (diff)
downloadpodman-8f7ed50cb20c04bbbb7c4907a183c07912d4bffb.tar.gz
podman-8f7ed50cb20c04bbbb7c4907a183c07912d4bffb.tar.bz2
podman-8f7ed50cb20c04bbbb7c4907a183c07912d4bffb.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')
-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 186c4df16..b578daa49 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 f46f74547..d0e89c2f5 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -40,13 +40,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 f5a231172..a62a41c12 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 (