Skip to content

Commit

Permalink
Merge pull request #221 from giuseppe/permit-rootless-cni
Browse files Browse the repository at this point in the history
rootless: permit custom configuration for cni
  • Loading branch information
vrothberg authored Jul 21, 2020
2 parents 6b9e533 + c770265 commit fce2cad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,17 @@ func (c *ContainersConfig) Validate() error {
// execution checks. It returns an `error` on validation failure, otherwise
// `nil`.
func (c *NetworkConfig) Validate() error {
if c.NetworkConfigDir != _cniConfigDir {
err := isDirectory(c.NetworkConfigDir)
expectedConfigDir := _cniConfigDir
if unshare.IsRootless() {
home, err := unshare.HomeDir()
if err != nil {
return err
}
expectedConfigDir = filepath.Join(home, _cniConfigDirRootless)
}
if c.NetworkConfigDir != expectedConfigDir {
err := isDirectory(c.NetworkConfigDir)
if err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "invalid network_config_dir: %s", c.NetworkConfigDir)
}
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ const (
// InstallPrefix is the prefix where podman will be installed.
// It can be overridden at build time.
_installPrefix = "/usr"
// _cniConfigDir is the directory where cni plugins are found
// _cniConfigDir is the directory where cni configuration is found
_cniConfigDir = "/etc/cni/net.d/"
// _cniConfigDirRootless is the directory where cni plugins are found
_cniConfigDirRootless = ".config/cni/net.d/"
// CgroupfsCgroupsManager represents cgroupfs native cgroup manager
CgroupfsCgroupsManager = "cgroupfs"
// DefaultApparmorProfile specifies the default apparmor profile for the container.
Expand Down Expand Up @@ -138,6 +140,8 @@ func DefaultConfig() (*Config, error) {

netns := "bridge"

cniConfig := _cniConfigDir

defaultEngineConfig.SignaturePolicyPath = DefaultSignaturePolicyPath
if unshare.IsRootless() {
home, err := unshare.HomeDir()
Expand All @@ -152,6 +156,7 @@ func DefaultConfig() (*Config, error) {
}
}
netns = "slirp4netns"
cniConfig = filepath.Join(home, _cniConfigDirRootless)
}

cgroupNS := "host"
Expand Down Expand Up @@ -198,7 +203,7 @@ func DefaultConfig() (*Config, error) {
},
Network: NetworkConfig{
DefaultNetwork: "podman",
NetworkConfigDir: _cniConfigDir,
NetworkConfigDir: cniConfig,
CNIPluginDirs: cniBinDir,
},
Engine: *defaultEngineConfig,
Expand Down

0 comments on commit fce2cad

Please sign in to comment.