rootless: support podman network create (CNI-in-slirp4netns)

Usage:
```
$ podman network create foo
$ podman run -d --name web --hostname web --network foo nginx:alpine
$ podman run --rm --network foo alpine wget -O - http://web.dns.podman
Connecting to web.dns.podman (10.88.4.6:80)
...
<h1>Welcome to nginx!</h1>
...
```

See contrib/rootless-cni-infra for the design.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2020-08-26 18:07:51 +09:00
parent d34868a136
commit f82abc774a
18 changed files with 401 additions and 48 deletions

View File

@ -21,9 +21,6 @@ var (
RunE: networkCreate, RunE: networkCreate,
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Example: `podman network create podman1`, Example: `podman network create podman1`,
Annotations: map[string]string{
registry.ParentNSRequired: "",
},
} }
) )

View File

@ -22,9 +22,6 @@ var (
RunE: networkInspect, RunE: networkInspect,
Example: `podman network inspect podman`, Example: `podman network inspect podman`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
Annotations: map[string]string{
registry.ParentNSRequired: "",
},
} }
) )

View File

@ -25,9 +25,6 @@ var (
Long: networklistDescription, Long: networklistDescription,
RunE: networkList, RunE: networkList,
Example: `podman network list`, Example: `podman network list`,
Annotations: map[string]string{
registry.ParentNSRequired: "",
},
} }
) )

View File

@ -19,9 +19,6 @@ var (
RunE: networkRm, RunE: networkRm,
Example: `podman network rm podman`, Example: `podman network rm podman`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
Annotations: map[string]string{
registry.ParentNSRequired: "",
},
} }
) )

View File

@ -957,8 +957,10 @@ func (c *Container) completeNetworkSetup() error {
if err := c.syncContainer(); err != nil { if err := c.syncContainer(); err != nil {
return err return err
} }
if c.config.NetMode.IsSlirp4netns() { if rootless.IsRootless() {
return c.runtime.setupRootlessNetNS(c) return c.runtime.setupRootlessNetNS(c)
} else if c.config.NetMode.IsSlirp4netns() {
return c.runtime.setupSlirp4netns(c)
} }
if err := c.runtime.setupNetNS(c); err != nil { if err := c.runtime.setupNetNS(c); err != nil {
return err return err

View File

@ -84,7 +84,11 @@ func (c *Container) prepare() error {
// Set up network namespace if not already set up // Set up network namespace if not already set up
noNetNS := c.state.NetNS == nil noNetNS := c.state.NetNS == nil
if c.config.CreateNetNS && noNetNS && !c.config.PostConfigureNetNS { if c.config.CreateNetNS && noNetNS && !c.config.PostConfigureNetNS {
netNS, networkStatus, createNetNSErr = c.runtime.createNetNS(c) if rootless.IsRootless() && len(c.config.Networks) > 0 {
netNS, networkStatus, createNetNSErr = AllocRootlessCNI(context.Background(), c)
} else {
netNS, networkStatus, createNetNSErr = c.runtime.createNetNS(c)
}
if createNetNSErr != nil { if createNetNSErr != nil {
return return
} }
@ -98,8 +102,12 @@ func (c *Container) prepare() error {
} }
// handle rootless network namespace setup // handle rootless network namespace setup
if noNetNS && c.config.NetMode.IsSlirp4netns() && !c.config.PostConfigureNetNS { if noNetNS && !c.config.PostConfigureNetNS {
createNetNSErr = c.runtime.setupRootlessNetNS(c) if rootless.IsRootless() {
createNetNSErr = c.runtime.setupRootlessNetNS(c)
} else if c.config.NetMode.IsSlirp4netns() {
createNetNSErr = c.runtime.setupSlirp4netns(c)
}
} }
}() }()
// Mount storage if not mounted // Mount storage if not mounted

View File

@ -2,7 +2,6 @@ package libpod
import ( import (
"github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/rootless"
spec "github.com/opencontainers/runtime-spec/specs-go" spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -68,16 +67,6 @@ func (c *Container) validate() error {
} }
} }
// Rootless has some requirements, compared to networks.
if rootless.IsRootless() {
if len(c.config.Networks) > 0 {
return errors.Wrapf(define.ErrInvalidArg, "cannot join CNI networks if running rootless")
}
// TODO: Should we make sure network mode is set to Slirp if set
// at all?
}
// Can only set static IP or MAC is creating a network namespace. // Can only set static IP or MAC is creating a network namespace.
if !c.config.CreateNetNS && (c.config.StaticIP != nil || c.config.StaticMAC != nil) { if !c.config.CreateNetNS && (c.config.StaticIP != nil || c.config.StaticMAC != nil) {
return errors.Wrapf(define.ErrInvalidArg, "cannot set static IP or MAC address if not creating a network namespace") return errors.Wrapf(define.ErrInvalidArg, "cannot set static IP or MAC address if not creating a network namespace")

View File

@ -4,6 +4,7 @@ package libpod
import ( import (
"bytes" "bytes"
"context"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io" "io"
@ -208,6 +209,20 @@ func checkSlirpFlags(path string) (*slirpFeatures, error) {
// Configure the network namespace for a rootless container // Configure the network namespace for a rootless container
func (r *Runtime) setupRootlessNetNS(ctr *Container) error { func (r *Runtime) setupRootlessNetNS(ctr *Container) error {
if ctr.config.NetMode.IsSlirp4netns() {
return r.setupSlirp4netns(ctr)
}
if len(ctr.config.Networks) > 0 {
// set up port forwarder for CNI-in-slirp4netns
netnsPath := ctr.state.NetNS.Path()
// TODO: support slirp4netns port forwarder as well
return r.setupRootlessPortMappingViaRLK(ctr, netnsPath)
}
return nil
}
// setupSlirp4netns can be called in rootful as well as in rootless
func (r *Runtime) setupSlirp4netns(ctr *Container) error {
path := r.config.Engine.NetworkCmdPath path := r.config.Engine.NetworkCmdPath
if path == "" { if path == "" {
@ -711,7 +726,7 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {
logrus.Debugf("Tearing down network namespace at %s for container %s", ctr.state.NetNS.Path(), ctr.ID()) logrus.Debugf("Tearing down network namespace at %s for container %s", ctr.state.NetNS.Path(), ctr.ID())
// rootless containers do not use the CNI plugin // rootless containers do not use the CNI plugin directly
if !rootless.IsRootless() && !ctr.config.NetMode.IsSlirp4netns() { if !rootless.IsRootless() && !ctr.config.NetMode.IsSlirp4netns() {
var requestedIP net.IP var requestedIP net.IP
if ctr.requestedIP != nil { if ctr.requestedIP != nil {
@ -738,6 +753,13 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {
} }
} }
// CNI-in-slirp4netns
if rootless.IsRootless() && len(ctr.config.Networks) != 0 {
if err := DeallocRootlessCNI(context.Background(), ctr); err != nil {
return errors.Wrapf(err, "error tearing down CNI-in-slirp4netns for container %s", ctr.ID())
}
}
// First unmount the namespace // First unmount the namespace
if err := netns.UnmountNS(ctr.state.NetNS); err != nil { if err := netns.UnmountNS(ctr.state.NetNS); err != nil {
return errors.Wrapf(err, "error unmounting network namespace for container %s", ctr.ID()) return errors.Wrapf(err, "error unmounting network namespace for container %s", ctr.ID())

View File

@ -8,6 +8,10 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) error {
return define.ErrNotImplemented return define.ErrNotImplemented
} }
func (r *Runtime) setupSlirp4netns(ctr *Container) error {
return define.ErrNotImplemented
}
func (r *Runtime) setupNetNS(ctr *Container) error { func (r *Runtime) setupNetNS(ctr *Container) error {
return define.ErrNotImplemented return define.ErrNotImplemented
} }

View File

@ -1086,7 +1086,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
cmd.ExtraFiles = append(cmd.ExtraFiles, childSyncPipe, childStartPipe) cmd.ExtraFiles = append(cmd.ExtraFiles, childSyncPipe, childStartPipe)
cmd.ExtraFiles = append(cmd.ExtraFiles, envFiles...) cmd.ExtraFiles = append(cmd.ExtraFiles, envFiles...)
if r.reservePorts && !ctr.config.NetMode.IsSlirp4netns() { if r.reservePorts && !rootless.IsRootless() && !ctr.config.NetMode.IsSlirp4netns() {
ports, err := bindPorts(ctr.config.PortMappings) ports, err := bindPorts(ctr.config.PortMappings)
if err != nil { if err != nil {
return err return err
@ -1098,7 +1098,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
cmd.ExtraFiles = append(cmd.ExtraFiles, ports...) cmd.ExtraFiles = append(cmd.ExtraFiles, ports...)
} }
if ctr.config.NetMode.IsSlirp4netns() { if ctr.config.NetMode.IsSlirp4netns() || rootless.IsRootless() {
if ctr.config.PostConfigureNetNS { if ctr.config.PostConfigureNetNS {
havePortMapping := len(ctr.Config().PortMappings) > 0 havePortMapping := len(ctr.Config().PortMappings) > 0
if havePortMapping { if havePortMapping {

View File

@ -0,0 +1,320 @@
// +build linux
package libpod
import (
"bytes"
"context"
"io"
"path/filepath"
"runtime"
cnitypes "github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/pkg/util"
"github.com/containers/storage/pkg/lockfile"
"github.com/hashicorp/go-multierror"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
var rootlessCNIInfraImage = map[string]string{
// Built from ../contrib/rootless-cni-infra
// TODO: move to Podman's official quay
"amd64": "ghcr.io/akihirosuda/podman-rootless-cni-infra:gd34868a13-amd64",
}
const (
rootlessCNIInfraContainerNamespace = "podman-system"
rootlessCNIInfraContainerName = "rootless-cni-infra"
)
// AllocRootlessCNI allocates a CNI netns inside the rootless CNI infra container.
// Locks "rootless-cni-infra.lck".
//
// When the infra container is not running, it is created.
//
// AllocRootlessCNI does not lock c. c should be already locked.
func AllocRootlessCNI(ctx context.Context, c *Container) (ns.NetNS, []*cnitypes.Result, error) {
if len(c.config.Networks) == 0 {
return nil, nil, errors.New("allocRootlessCNI shall not be called when len(c.config.Networks) == 0")
}
l, err := getRootlessCNIInfraLock(c.runtime)
if err != nil {
return nil, nil, err
}
l.Lock()
defer l.Unlock()
infra, err := ensureRootlessCNIInfraContainerRunning(ctx, c.runtime)
if err != nil {
return nil, nil, err
}
k8sPodName := getPodOrContainerName(c) // passed to CNI as K8S_POD_NAME
cniResults := make([]*cnitypes.Result, len(c.config.Networks))
for i, nw := range c.config.Networks {
cniRes, err := rootlessCNIInfraCallAlloc(infra, c.ID(), nw, k8sPodName)
if err != nil {
return nil, nil, err
}
cniResults[i] = cniRes
}
nsObj, err := rootlessCNIInfraGetNS(infra, c.ID())
if err != nil {
return nil, nil, err
}
logrus.Debugf("rootless CNI: container %q will join %q", c.ID(), nsObj.Path())
return nsObj, cniResults, nil
}
// DeallocRootlessCNI deallocates a CNI netns inside the rootless CNI infra container.
// Locks "rootless-cni-infra.lck".
//
// When the infra container is no longer needed, it is removed.
//
// DeallocRootlessCNI does not lock c. c should be already locked.
func DeallocRootlessCNI(ctx context.Context, c *Container) error {
if len(c.config.Networks) == 0 {
return errors.New("deallocRootlessCNI shall not be called when len(c.config.Networks) == 0")
}
l, err := getRootlessCNIInfraLock(c.runtime)
if err != nil {
return err
}
l.Lock()
defer l.Unlock()
infra, _ := getRootlessCNIInfraContainer(c.runtime)
if infra == nil {
return nil
}
var errs *multierror.Error
for _, nw := range c.config.Networks {
err := rootlessCNIInfraCallDelloc(infra, c.ID(), nw)
if err != nil {
errs = multierror.Append(errs, err)
}
}
if isIdle, err := rootlessCNIInfraIsIdle(infra); isIdle || err != nil {
if err != nil {
logrus.Warn(err)
}
logrus.Debugf("rootless CNI: removing infra container %q", infra.ID())
if err := c.runtime.removeContainer(ctx, infra, true, false, true); err != nil {
return err
}
logrus.Debugf("rootless CNI: removed infra container %q", infra.ID())
}
return errs.ErrorOrNil()
}
func getRootlessCNIInfraLock(r *Runtime) (lockfile.Locker, error) {
fname := filepath.Join(r.config.Engine.TmpDir, "rootless-cni-infra.lck")
return lockfile.GetLockfile(fname)
}
func getPodOrContainerName(c *Container) string {
pod, err := c.runtime.GetPod(c.PodID())
if err != nil || pod.config.Name == "" {
return c.Name()
}
return pod.config.Name
}
func rootlessCNIInfraCallAlloc(infra *Container, id, nw, k8sPodName string) (*cnitypes.Result, error) {
logrus.Debugf("rootless CNI: alloc %q, %q, %q", id, nw, k8sPodName)
var err error
_, err = rootlessCNIInfraExec(infra, "alloc", id, nw, k8sPodName)
if err != nil {
return nil, err
}
cniResStr, err := rootlessCNIInfraExec(infra, "print-cni-result", id, nw)
if err != nil {
return nil, err
}
var cniRes cnitypes.Result
if err := json.Unmarshal([]byte(cniResStr), &cniRes); err != nil {
return nil, errors.Wrapf(err, "unmarshaling as cnitypes.Result: %q", cniResStr)
}
return &cniRes, nil
}
func rootlessCNIInfraCallDelloc(infra *Container, id, nw string) error {
logrus.Debugf("rootless CNI: dealloc %q, %q", id, nw)
_, err := rootlessCNIInfraExec(infra, "dealloc", id, nw)
return err
}
func rootlessCNIInfraIsIdle(infra *Container) (bool, error) {
type isIdle struct {
Idle bool `json:"idle"`
}
resStr, err := rootlessCNIInfraExec(infra, "is-idle")
if err != nil {
return false, err
}
var res isIdle
if err := json.Unmarshal([]byte(resStr), &res); err != nil {
return false, errors.Wrapf(err, "unmarshaling as isIdle: %q", resStr)
}
return res.Idle, nil
}
func rootlessCNIInfraGetNS(infra *Container, id string) (ns.NetNS, error) {
type printNetnsPath struct {
Path string `json:"path"`
}
resStr, err := rootlessCNIInfraExec(infra, "print-netns-path", id)
if err != nil {
return nil, err
}
var res printNetnsPath
if err := json.Unmarshal([]byte(resStr), &res); err != nil {
return nil, errors.Wrapf(err, "unmarshaling as printNetnsPath: %q", resStr)
}
nsObj, err := ns.GetNS(res.Path)
if err != nil {
return nil, err
}
return nsObj, nil
}
func getRootlessCNIInfraContainer(r *Runtime) (*Container, error) {
containers, err := r.GetContainersWithoutLock(func(c *Container) bool {
return c.Namespace() == rootlessCNIInfraContainerNamespace &&
c.Name() == rootlessCNIInfraContainerName
})
if err != nil {
return nil, err
}
if len(containers) == 0 {
return nil, nil
}
return containers[0], nil
}
func ensureRootlessCNIInfraContainerRunning(ctx context.Context, r *Runtime) (*Container, error) {
c, err := getRootlessCNIInfraContainer(r)
if err != nil {
return nil, err
}
if c == nil {
return startRootlessCNIInfraContainer(ctx, r)
}
st, err := c.ContainerState()
if err != nil {
return nil, err
}
if st.State == define.ContainerStateRunning {
logrus.Debugf("rootless CNI: infra container %q is already running", c.ID())
return c, nil
}
logrus.Debugf("rootless CNI: infra container %q is %q, being started", c.ID(), st.State)
if err := c.initAndStart(ctx); err != nil {
return nil, err
}
logrus.Debugf("rootless CNI: infra container %q is running", c.ID())
return c, nil
}
func startRootlessCNIInfraContainer(ctx context.Context, r *Runtime) (*Container, error) {
imageName, ok := rootlessCNIInfraImage[runtime.GOARCH]
if !ok {
return nil, errors.Errorf("cannot find rootless-podman-network-sandbox image for %s", runtime.GOARCH)
}
logrus.Debugf("rootless CNI: ensuring image %q to exist", imageName)
newImage, err := r.ImageRuntime().New(ctx, imageName, "", "", nil, nil,
image.SigningOptions{}, nil, util.PullImageMissing)
if err != nil {
return nil, err
}
logrus.Debugf("rootless CNI: image %q is ready", imageName)
g, err := generate.New("linux")
if err != nil {
return nil, err
}
g.SetupPrivileged(true)
// Set --pid=host for ease of propagating "/proc/PID/ns/net" string
if err := g.RemoveLinuxNamespace(string(spec.PIDNamespace)); err != nil {
return nil, err
}
g.RemoveMount("/proc")
procMount := spec.Mount{
Destination: "/proc",
Type: "bind",
Source: "/proc",
Options: []string{"rbind", "nosuid", "noexec", "nodev"},
}
g.AddMount(procMount)
// Mount CNI networks
etcCNINetD := spec.Mount{
Destination: "/etc/cni/net.d",
Type: "bind",
Source: r.config.Network.NetworkConfigDir,
Options: []string{"ro"},
}
g.AddMount(etcCNINetD)
// FIXME: how to propagate ProcessArgs and Envs from Dockerfile?
g.SetProcessArgs([]string{"sleep", "infinity"})
g.AddProcessEnv("CNI_PATH", "/opt/cni/bin")
var options []CtrCreateOption
options = append(options, WithRootFSFromImage(newImage.ID(), imageName, imageName))
options = append(options, WithCtrNamespace(rootlessCNIInfraContainerNamespace))
options = append(options, WithName(rootlessCNIInfraContainerName))
options = append(options, WithPrivileged(true))
options = append(options, WithSecLabels([]string{"disable"}))
options = append(options, WithRestartPolicy("always"))
options = append(options, WithNetNS(nil, false, "slirp4netns", nil))
c, err := r.NewContainer(ctx, g.Config, options...)
if err != nil {
return nil, err
}
logrus.Debugf("rootless CNI infra container %q is created, now being started", c.ID())
if err := c.initAndStart(ctx); err != nil {
return nil, err
}
logrus.Debugf("rootless CNI: infra container %q is running", c.ID())
return c, nil
}
func rootlessCNIInfraExec(c *Container, args ...string) (string, error) {
cmd := "rootless-cni-infra"
var (
outB bytes.Buffer
errB bytes.Buffer
streams define.AttachStreams
config ExecConfig
)
streams.OutputStream = &nopWriteCloser{Writer: &outB}
streams.ErrorStream = &nopWriteCloser{Writer: &errB}
streams.AttachOutput = true
streams.AttachError = true
config.Command = append([]string{cmd}, args...)
config.Privileged = true
logrus.Debugf("rootlessCNIInfraExec: c.ID()=%s, config=%+v, streams=%v, begin",
c.ID(), config, streams)
code, err := c.Exec(&config, &streams, nil)
logrus.Debugf("rootlessCNIInfraExec: c.ID()=%s, config=%+v, streams=%v, end (code=%d, err=%v)",
c.ID(), config, streams, code, err)
if err != nil {
return "", err
}
if code != 0 {
return "", errors.Errorf("command %s %v in container %s failed with status %d, stdout=%q, stderr=%q",
cmd, args, c.ID(), code, outB.String(), errB.String())
}
return outB.String(), nil
}
type nopWriteCloser struct {
io.Writer
}
func (nwc *nopWriteCloser) Close() error {
return nil
}

View File

@ -770,7 +770,11 @@ func (r *Runtime) LookupContainer(idOrName string) (*Container, error) {
func (r *Runtime) GetContainers(filters ...ContainerFilter) ([]*Container, error) { func (r *Runtime) GetContainers(filters ...ContainerFilter) ([]*Container, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
return r.GetContainersWithoutLock(filters...)
}
// GetContainersWithoutLock is same as GetContainers but without lock
func (r *Runtime) GetContainersWithoutLock(filters ...ContainerFilter) ([]*Container, error) {
if !r.valid { if !r.valid {
return nil, define.ErrRuntimeStopped return nil, define.ErrRuntimeStopped
} }

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -216,6 +217,9 @@ func createBridge(r *libpod.Runtime, name string, options entities.NetworkCreate
if err != nil { if err != nil {
return "", err return "", err
} }
if err := os.MkdirAll(network.GetCNIConfDir(runtimeConfig), 0755); err != nil {
return "", err
}
cniPathName := filepath.Join(network.GetCNIConfDir(runtimeConfig), fmt.Sprintf("%s.conflist", name)) cniPathName := filepath.Join(network.GetCNIConfDir(runtimeConfig), fmt.Sprintf("%s.conflist", name))
err = ioutil.WriteFile(cniPathName, b, 0644) err = ioutil.WriteFile(cniPathName, b, 0644)
return cniPathName, err return cniPathName, err

View File

@ -14,11 +14,16 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func GetCNIConfDir(config *config.Config) string { func GetCNIConfDir(configArg *config.Config) string {
if len(config.Network.NetworkConfigDir) < 1 { if len(configArg.Network.NetworkConfigDir) < 1 {
return CNIConfigDir dc, err := config.DefaultConfig()
if err != nil {
// Fallback to hard-coded dir
return CNIConfigDir
}
return dc.Network.NetworkConfigDir
} }
return config.Network.NetworkConfigDir return configArg.Network.NetworkConfigDir
} }
// LoadCNIConfsFromDir loads all the CNI configurations from a dir // LoadCNIConfsFromDir loads all the CNI configurations from a dir

View File

@ -28,9 +28,6 @@ can easily fail
* Can not use overlayfs driver, but does support fuse-overlayfs * Can not use overlayfs driver, but does support fuse-overlayfs
* Ubuntu supports non root overlay, but no other Linux distros do. * Ubuntu supports non root overlay, but no other Linux distros do.
* Only other supported driver is VFS. * Only other supported driver is VFS.
* No CNI Support
* CNI wants to modify IPTables, plus other network manipulation that requires CAP_SYS_ADMIN.
* There is potential we could probably do some sort of denylisting of the relevant plugins, and add a new plugin for rootless networking - slirp4netns as one example and there may be others
* Cannot use ping out of the box. * Cannot use ping out of the box.
* [(Can be fixed by setting sysctl on host)](https://github.com/containers/podman/blob/master/troubleshooting.md#6-rootless-containers-cannot-ping-hosts) * [(Can be fixed by setting sysctl on host)](https://github.com/containers/podman/blob/master/troubleshooting.md#6-rootless-containers-cannot-ping-hosts)
* Requires new shadow-utils (not found in older (RHEL7/Centos7 distros) Should be fixed in RHEL7.7 release) * Requires new shadow-utils (not found in older (RHEL7/Centos7 distros) Should be fixed in RHEL7.7 release)

View File

@ -245,6 +245,12 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
} }
os.Setenv("DISABLE_HC_SYSTEMD", "true") os.Setenv("DISABLE_HC_SYSTEMD", "true")
CNIConfigDir := "/etc/cni/net.d" CNIConfigDir := "/etc/cni/net.d"
if rootless.IsRootless() {
CNIConfigDir = filepath.Join(os.Getenv("HOME"), ".config/cni/net.d")
}
if err := os.MkdirAll(CNIConfigDir, 0755); err != nil {
panic(err)
}
storageFs := STORAGE_FS storageFs := STORAGE_FS
if rootless.IsRootless() { if rootless.IsRootless() {

View File

@ -74,7 +74,6 @@ var _ = Describe("Podman network create", func() {
) )
BeforeEach(func() { BeforeEach(func() {
SkipIfRootless()
tempdir, err = CreateTempDirInTempDir() tempdir, err = CreateTempDirInTempDir()
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)
@ -180,6 +179,7 @@ var _ = Describe("Podman network create", func() {
It("podman network create with name and IPv6 subnet", func() { It("podman network create with name and IPv6 subnet", func() {
SkipIfRemote() SkipIfRemote()
SkipIfRootless()
var ( var (
results []network.NcList results []network.NcList
) )

View File

@ -9,6 +9,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/containers/podman/v2/pkg/rootless"
. "github.com/containers/podman/v2/test/utils" . "github.com/containers/podman/v2/test/utils"
"github.com/containers/storage/pkg/stringid" "github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
@ -34,7 +35,6 @@ var _ = Describe("Podman network", func() {
) )
BeforeEach(func() { BeforeEach(func() {
SkipIfRootless()
tempdir, err = CreateTempDirInTempDir() tempdir, err = CreateTempDirInTempDir()
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)
@ -76,13 +76,12 @@ var _ = Describe("Podman network", func() {
} }
] ]
}` }`
cniPath = "/etc/cni/net.d"
) )
It("podman network list", func() { It("podman network list", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)
@ -95,7 +94,7 @@ var _ = Describe("Podman network", func() {
It("podman network list -q", func() { It("podman network list -q", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)
@ -108,7 +107,7 @@ var _ = Describe("Podman network", func() {
It("podman network list --filter success", func() { It("podman network list --filter success", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)
@ -121,7 +120,7 @@ var _ = Describe("Podman network", func() {
It("podman network list --filter failure", func() { It("podman network list --filter failure", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)
@ -140,7 +139,7 @@ var _ = Describe("Podman network", func() {
It("podman network rm", func() { It("podman network rm", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)
@ -168,11 +167,16 @@ var _ = Describe("Podman network", func() {
It("podman network inspect", func() { It("podman network inspect", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)
session := podmanTest.Podman([]string{"network", "inspect", "podman-integrationtest", "podman"}) expectedNetworks := []string{"podman-integrationtest"}
if !rootless.IsRootless() {
// rootful image contains "podman/cni/87-podman-bridge.conflist" for "podman" network
expectedNetworks = append(expectedNetworks, "podman")
}
session := podmanTest.Podman(append([]string{"network", "inspect"}, expectedNetworks...))
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0)) Expect(session.ExitCode()).To(Equal(0))
Expect(session.IsJSONOutputValid()).To(BeTrue()) Expect(session.IsJSONOutputValid()).To(BeTrue())
@ -181,7 +185,7 @@ var _ = Describe("Podman network", func() {
It("podman network inspect", func() { It("podman network inspect", func() {
// Setup, use uuid to prevent conflict with other tests // Setup, use uuid to prevent conflict with other tests
uuid := stringid.GenerateNonCryptoID() uuid := stringid.GenerateNonCryptoID()
secondPath := filepath.Join(cniPath, fmt.Sprintf("%s.conflist", uuid)) secondPath := filepath.Join(podmanTest.CNIConfigDir, fmt.Sprintf("%s.conflist", uuid))
writeConf([]byte(secondConf), secondPath) writeConf([]byte(secondConf), secondPath)
defer removeConf(secondPath) defer removeConf(secondPath)