rootless: remove SkipStorageSetup()

in the few places where we care about skipping the storage
initialization, we can simply use the process effective UID, instead
of relying on a global boolean flag.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2019-03-19 10:59:43 +01:00
parent cd35e20772
commit ed326206f2
22 changed files with 6 additions and 88 deletions

View File

@ -58,9 +58,6 @@ func cpCmd(c *cliconfig.CpValues) error {
if len(args) != 2 { if len(args) != 2 {
return errors.Errorf("you must provide a source path and a destination path") return errors.Errorf("you must provide a source path and a destination path")
} }
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {

View File

@ -2,12 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/pkg/rootless"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -54,10 +52,6 @@ func createCmd(c *cliconfig.CreateValues) error {
return err return err
} }
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "error creating libpod runtime") return errors.Wrapf(err, "error creating libpod runtime")

View File

@ -67,7 +67,6 @@ func execCmd(c *cliconfig.ExecValues) error {
if c.Latest { if c.Latest {
argStart = 0 argStart = 0
} }
rootless.SetSkipStorageSetup(true)
cmd := args[argStart:] cmd := args[argStart:]
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {

View File

@ -6,7 +6,6 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/shared/parse" "github.com/containers/libpod/cmd/podman/shared/parse"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -41,10 +40,6 @@ func init() {
// exportCmd saves a container to a tarball on disk // exportCmd saves a container to a tarball on disk
func exportCmd(c *cliconfig.ExportValues) error { func exportCmd(c *cliconfig.ExportValues) error {
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -4,12 +4,10 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"github.com/containers/libpod/pkg/adapter"
"github.com/opentracing/opentracing-go"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/adapter"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -63,7 +61,6 @@ func killCmd(c *cliconfig.KillValues) error {
return err return err
} }
rootless.SetSkipStorageSetup(true)
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -60,10 +60,6 @@ type jsonMountPoint struct {
} }
func mountCmd(c *cliconfig.MountValues) error { func mountCmd(c *cliconfig.MountValues) error {
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -6,7 +6,6 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
"github.com/containers/libpod/pkg/rootless"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -49,7 +48,6 @@ func init() {
// podKillCmd kills one or more pods with a signal // podKillCmd kills one or more pods with a signal
func podKillCmd(c *cliconfig.PodKillValues) error { func podKillCmd(c *cliconfig.PodKillValues) error {
rootless.SetSkipStorageSetup(true)
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
@ -48,9 +47,6 @@ func init() {
func podRestartCmd(c *cliconfig.PodRestartValues) error { func podRestartCmd(c *cliconfig.PodRestartValues) error {
var lastError error var lastError error
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
@ -48,9 +47,6 @@ func init() {
// podRmCmd deletes pods // podRmCmd deletes pods
func podRmCmd(c *cliconfig.PodRmValues) error { func podRmCmd(c *cliconfig.PodRmValues) error {
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
@ -48,10 +47,6 @@ func init() {
} }
func podStopCmd(c *cliconfig.PodStopValues) error { func podStopCmd(c *cliconfig.PodStopValues) error {
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -9,7 +9,6 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -54,10 +53,6 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
) )
args := c.InputArgs args := c.InputArgs
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
if c.ListDescriptors { if c.ListDescriptors {
descriptors, err := libpod.GetContainerPidInformationDescriptors() descriptors, err := libpod.GetContainerPidInformationDescriptors()
if err != nil { if err != nil {

View File

@ -17,7 +17,6 @@ import (
"github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util" "github.com/containers/libpod/pkg/util"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/docker/go-units" "github.com/docker/go-units"
@ -202,9 +201,6 @@ func init() {
} }
func psCmd(c *cliconfig.PsValues) error { func psCmd(c *cliconfig.PsValues) error {
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
if c.Bool("trace") { if c.Bool("trace") {
span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd") span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd")
defer span.Finish() defer span.Finish()

View File

@ -57,9 +57,6 @@ func restartCmd(c *cliconfig.RestartValues) error {
restartContainers []*libpod.Container restartContainers []*libpod.Container
) )
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
if rootless.IsRootless() { if rootless.IsRootless() {
// If we are in the re-execed rootless environment, // If we are in the re-execed rootless environment,
// override the arg to deal only with one container. // override the arg to deal only with one container.

View File

@ -82,9 +82,6 @@ func rmCmd(c *cliconfig.RmValues) error {
var ( var (
deleteFuncs []shared.ParallelWorkerInput deleteFuncs []shared.ParallelWorkerInput
) )
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
ctx := getContext() ctx := getContext()
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)

View File

@ -12,7 +12,6 @@ import (
"github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -57,9 +56,6 @@ func runCmd(c *cliconfig.RunValues) error {
if err := createInit(&c.PodmanCommand); err != nil { if err := createInit(&c.PodmanCommand); err != nil {
return err return err
} }
if os.Geteuid() != 0 {
rootless.SetSkipStorageSetup(true)
}
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {

View File

@ -75,7 +75,8 @@ func CreateContainer(ctx context.Context, c *cliconfig.PodmanCommand, runtime *l
imageName := "" imageName := ""
var data *inspect.ImageData = nil var data *inspect.ImageData = nil
if rootfs == "" && !rootless.SkipStorageSetup() { // Set the storage if we are running as euid == 0 and there is no rootfs specified
if rootfs == "" && os.Geteuid() == 0 {
var writer io.Writer var writer io.Writer
if !c.Bool("quiet") { if !c.Bool("quiet") {
writer = os.Stderr writer = os.Stderr

View File

@ -7,7 +7,6 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
"github.com/containers/libpod/pkg/rootless"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -59,7 +58,6 @@ func stopCmd(c *cliconfig.StopValues) error {
defer span.Finish() defer span.Finish()
} }
rootless.SetSkipStorageSetup(true)
runtime, err := adapter.GetRuntime(&c.PodmanCommand) runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get runtime") return errors.Wrapf(err, "could not get runtime")

View File

@ -77,7 +77,6 @@ func topCmd(c *cliconfig.TopValues) error {
return errors.Errorf("you must provide the name or id of a running container") return errors.Errorf("you must provide the name or id of a running container")
} }
rootless.SetSkipStorageSetup(true)
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil { if err != nil {
return errors.Wrapf(err, "error creating libpod runtime") return errors.Wrapf(err, "error creating libpod runtime")

View File

@ -742,7 +742,7 @@ func makeRuntime(runtime *Runtime) (err error) {
// Set up containers/storage // Set up containers/storage
var store storage.Store var store storage.Store
if rootless.SkipStorageSetup() { if os.Geteuid() != 0 {
logrus.Debug("Not configuring container store") logrus.Debug("Not configuring container store")
} else { } else {
store, err = storage.GetStore(runtime.config.StorageConfig) store, err = storage.GetStore(runtime.config.StorageConfig)

View File

@ -46,20 +46,6 @@ func IsRootless() bool {
return isRootless return isRootless
} }
var (
skipStorageSetup = false
)
// SetSkipStorageSetup tells the runtime to not setup containers/storage
func SetSkipStorageSetup(v bool) {
skipStorageSetup = v
}
// SkipStorageSetup tells if we should skip the containers/storage setup
func SkipStorageSetup() bool {
return skipStorageSetup
}
// Argument returns the argument that was set for the rootless session. // Argument returns the argument that was set for the rootless session.
func Argument() string { func Argument() string {
return os.Getenv("_CONTAINERS_ROOTLESS_ARG") return os.Getenv("_CONTAINERS_ROOTLESS_ARG")

View File

@ -30,15 +30,6 @@ func GetRootlessUID() int {
return -1 return -1
} }
// SetSkipStorageSetup tells the runtime to not setup containers/storage
func SetSkipStorageSetup(bool) {
}
// SkipStorageSetup tells if we should skip the containers/storage setup
func SkipStorageSetup() bool {
return false
}
// JoinNS re-exec podman in a new userNS and join the user namespace of the specified // JoinNS re-exec podman in a new userNS and join the user namespace of the specified
// PID. // PID.
func JoinNS(pid uint, preserveFDs int) (bool, int, error) { func JoinNS(pid uint, preserveFDs int) (bool, int, error) {

View File

@ -12,7 +12,6 @@ import (
"github.com/containers/image/manifest" "github.com/containers/image/manifest"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/namespaces" "github.com/containers/libpod/pkg/namespaces"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/containers/storage/pkg/stringid" "github.com/containers/storage/pkg/stringid"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
@ -271,7 +270,7 @@ func (c *CreateConfig) GetVolumeMounts(specMounts []spec.Mount) ([]spec.Mount, e
func (c *CreateConfig) GetVolumesFrom() error { func (c *CreateConfig) GetVolumesFrom() error {
var options string var options string
if rootless.SkipStorageSetup() { if os.Geteuid() != 0 {
return nil return nil
} }