Merge pull request #248 from davidscherer/davidscherer-xdg-config-home

Respect XDG_CONFIG_HOME for policy.json and cni
This commit is contained in:
Daniel J Walsh 2020-08-10 08:50:26 -04:00 committed by GitHub
commit ed9aec43d0
1 changed files with 9 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/containers/common/pkg/apparmor" "github.com/containers/common/pkg/apparmor"
"github.com/containers/common/pkg/cgroupv2" "github.com/containers/common/pkg/cgroupv2"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/containers/storage/pkg/homedir"
"github.com/containers/storage/pkg/unshare" "github.com/containers/storage/pkg/unshare"
"github.com/opencontainers/selinux/go-selinux" "github.com/opencontainers/selinux/go-selinux"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -94,8 +95,8 @@ const (
_installPrefix = "/usr" _installPrefix = "/usr"
// _cniConfigDir is the directory where cni configuration is found // _cniConfigDir is the directory where cni configuration is found
_cniConfigDir = "/etc/cni/net.d/" _cniConfigDir = "/etc/cni/net.d/"
// _cniConfigDirRootless is the directory where cni plugins are found // _cniConfigDirRootless is the directory in XDG_CONFIG_HOME for cni plugins
_cniConfigDirRootless = ".config/cni/net.d/" _cniConfigDirRootless = "cni/net.d/"
// CgroupfsCgroupsManager represents cgroupfs native cgroup manager // CgroupfsCgroupsManager represents cgroupfs native cgroup manager
CgroupfsCgroupsManager = "cgroupfs" CgroupfsCgroupsManager = "cgroupfs"
// DefaultApparmorProfile specifies the default apparmor profile for the container. // DefaultApparmorProfile specifies the default apparmor profile for the container.
@ -115,9 +116,9 @@ const (
// DefaultSignaturePolicyPath is the default value for the // DefaultSignaturePolicyPath is the default value for the
// policy.json file. // policy.json file.
DefaultSignaturePolicyPath = "/etc/containers/policy.json" DefaultSignaturePolicyPath = "/etc/containers/policy.json"
// DefaultRootlessSignaturePolicyPath is the default value for the // DefaultRootlessSignaturePolicyPath is the location within
// rootless policy.json file. // XDG_CONFIG_HOME of the rootless policy.json file.
DefaultRootlessSignaturePolicyPath = ".config/containers/policy.json" DefaultRootlessSignaturePolicyPath = "containers/policy.json"
// DefaultShmSize default value // DefaultShmSize default value
DefaultShmSize = "65536k" DefaultShmSize = "65536k"
// DefaultUserNSSize default value // DefaultUserNSSize default value
@ -144,11 +145,11 @@ func DefaultConfig() (*Config, error) {
defaultEngineConfig.SignaturePolicyPath = DefaultSignaturePolicyPath defaultEngineConfig.SignaturePolicyPath = DefaultSignaturePolicyPath
if unshare.IsRootless() { if unshare.IsRootless() {
home, err := unshare.HomeDir() configHome, err := homedir.GetConfigHome()
if err != nil { if err != nil {
return nil, err return nil, err
} }
sigPath := filepath.Join(home, DefaultRootlessSignaturePolicyPath) sigPath := filepath.Join(configHome, DefaultRootlessSignaturePolicyPath)
defaultEngineConfig.SignaturePolicyPath = sigPath defaultEngineConfig.SignaturePolicyPath = sigPath
if _, err := os.Stat(sigPath); err != nil { if _, err := os.Stat(sigPath); err != nil {
if _, err := os.Stat(DefaultSignaturePolicyPath); err == nil { if _, err := os.Stat(DefaultSignaturePolicyPath); err == nil {
@ -156,7 +157,7 @@ func DefaultConfig() (*Config, error) {
} }
} }
netns = "slirp4netns" netns = "slirp4netns"
cniConfig = filepath.Join(home, _cniConfigDirRootless) cniConfig = filepath.Join(configHome, _cniConfigDirRootless)
} }
cgroupNS := "host" cgroupNS := "host"