Merge pull request #1994 from giuseppe/rootless-mount-allow-only-from-vfs

mount: allow mount only when using vfs
This commit is contained in:
OpenShift Merge Robot 2018-12-13 13:46:38 -08:00 committed by GitHub
commit 93b5ccfe94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -34,6 +34,7 @@ var cmdsNotRequiringRootless = map[string]bool{
// If this change, please also update libpod.refreshRootless() // If this change, please also update libpod.refreshRootless()
"login": true, "login": true,
"logout": true, "logout": true,
"mount": true,
"kill": true, "kill": true,
"pause": true, "pause": true,
"restart": true, "restart": true,

View File

@ -3,9 +3,11 @@ package main
import ( import (
js "encoding/json" js "encoding/json"
"fmt" "fmt"
"os"
of "github.com/containers/libpod/cmd/podman/formats" of "github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -52,6 +54,9 @@ func mountCmd(c *cli.Context) error {
if err := validateFlags(c, mountFlags); err != nil { if err := validateFlags(c, mountFlags); err != nil {
return err return err
} }
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := libpodruntime.GetRuntime(c) runtime, err := libpodruntime.GetRuntime(c)
if err != nil { if err != nil {
@ -59,6 +64,22 @@ func mountCmd(c *cli.Context) error {
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
if os.Geteuid() != 0 {
if driver := runtime.GetConfig().StorageConfig.GraphDriverName; driver != "vfs" {
// Do not allow to mount a graphdriver that is not vfs if we are creating the userns as part
// of the mount command.
return fmt.Errorf("cannot mount using driver %s in rootless mode", driver)
}
became, ret, err := rootless.BecomeRootInUserNS()
if err != nil {
return err
}
if became {
os.Exit(ret)
}
}
formats := map[string]bool{ formats := map[string]bool{
"": true, "": true,
of.JSONString: true, of.JSONString: true,