mirror of
https://github.com/containers/podman.git
synced 2025-08-06 11:32:07 +08:00
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:
@ -58,9 +58,6 @@ func cpCmd(c *cliconfig.CpValues) error {
|
||||
if len(args) != 2 {
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -2,12 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/containers/libpod/cmd/podman/shared"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@ -54,10 +52,6 @@ func createCmd(c *cliconfig.CreateValues) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
|
@ -67,7 +67,6 @@ func execCmd(c *cliconfig.ExecValues) error {
|
||||
if c.Latest {
|
||||
argStart = 0
|
||||
}
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
cmd := args[argStart:]
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/cmd/podman/shared/parse"
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@ -41,10 +40,6 @@ func init() {
|
||||
|
||||
// exportCmd saves a container to a tarball on disk
|
||||
func exportCmd(c *cliconfig.ExportValues) error {
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -4,12 +4,10 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
|
||||
"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/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -63,7 +61,6 @@ func killCmd(c *cliconfig.KillValues) error {
|
||||
return err
|
||||
}
|
||||
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -60,10 +60,6 @@ type jsonMountPoint struct {
|
||||
}
|
||||
|
||||
func mountCmd(c *cliconfig.MountValues) error {
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -49,7 +48,6 @@ func init() {
|
||||
|
||||
// podKillCmd kills one or more pods with a signal
|
||||
func podKillCmd(c *cliconfig.PodKillValues) error {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
@ -48,9 +47,6 @@ func init() {
|
||||
|
||||
func podRestartCmd(c *cliconfig.PodRestartValues) error {
|
||||
var lastError error
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
@ -48,9 +47,6 @@ func init() {
|
||||
|
||||
// podRmCmd deletes pods
|
||||
func podRmCmd(c *cliconfig.PodRmValues) error {
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
@ -48,10 +47,6 @@ func init() {
|
||||
}
|
||||
|
||||
func podStopCmd(c *cliconfig.PodStopValues) error {
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -54,10 +53,6 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
|
||||
)
|
||||
args := c.InputArgs
|
||||
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
if c.ListDescriptors {
|
||||
descriptors, err := libpod.GetContainerPidInformationDescriptors()
|
||||
if err != nil {
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/containers/libpod/cmd/podman/shared"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
||||
"github.com/docker/go-units"
|
||||
@ -202,9 +201,6 @@ func init() {
|
||||
}
|
||||
|
||||
func psCmd(c *cliconfig.PsValues) error {
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
if c.Bool("trace") {
|
||||
span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd")
|
||||
defer span.Finish()
|
||||
|
@ -57,9 +57,6 @@ func restartCmd(c *cliconfig.RestartValues) error {
|
||||
restartContainers []*libpod.Container
|
||||
)
|
||||
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
if rootless.IsRootless() {
|
||||
// If we are in the re-execed rootless environment,
|
||||
// override the arg to deal only with one container.
|
||||
|
@ -82,9 +82,6 @@ func rmCmd(c *cliconfig.RmValues) error {
|
||||
var (
|
||||
deleteFuncs []shared.ParallelWorkerInput
|
||||
)
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
ctx := getContext()
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||
"github.com/containers/libpod/cmd/podman/shared"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -57,9 +56,6 @@ func runCmd(c *cliconfig.RunValues) error {
|
||||
if err := createInit(&c.PodmanCommand); err != nil {
|
||||
return err
|
||||
}
|
||||
if os.Geteuid() != 0 {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
|
@ -75,7 +75,8 @@ func CreateContainer(ctx context.Context, c *cliconfig.PodmanCommand, runtime *l
|
||||
imageName := ""
|
||||
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
|
||||
if !c.Bool("quiet") {
|
||||
writer = os.Stderr
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/adapter"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@ -59,7 +58,6 @@ func stopCmd(c *cliconfig.StopValues) error {
|
||||
defer span.Finish()
|
||||
}
|
||||
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
@ -77,7 +77,6 @@ func topCmd(c *cliconfig.TopValues) error {
|
||||
return errors.Errorf("you must provide the name or id of a running container")
|
||||
}
|
||||
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
|
@ -742,7 +742,7 @@ func makeRuntime(runtime *Runtime) (err error) {
|
||||
|
||||
// Set up containers/storage
|
||||
var store storage.Store
|
||||
if rootless.SkipStorageSetup() {
|
||||
if os.Geteuid() != 0 {
|
||||
logrus.Debug("Not configuring container store")
|
||||
} else {
|
||||
store, err = storage.GetStore(runtime.config.StorageConfig)
|
||||
|
@ -46,20 +46,6 @@ func IsRootless() bool {
|
||||
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.
|
||||
func Argument() string {
|
||||
return os.Getenv("_CONTAINERS_ROOTLESS_ARG")
|
||||
|
@ -30,15 +30,6 @@ func GetRootlessUID() int {
|
||||
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
|
||||
// PID.
|
||||
func JoinNS(pid uint, preserveFDs int) (bool, int, error) {
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/containers/image/manifest"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/namespaces"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/containers/storage"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
"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 {
|
||||
var options string
|
||||
|
||||
if rootless.SkipStorageSetup() {
|
||||
if os.Geteuid() != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user