From 04a59d49996aebc67fcf6b52c1aec3a5c304ae89 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 8 Sep 2021 12:06:28 +0200 Subject: [PATCH] Add HelperBinariesDir field to engine config This field contains a list of directories which should be used to store some helper binaries, e.g. gvproxy. Also add a FindHelperBinary method to the config struct to get the full path to a helper binary. Signed-off-by: Paul Holzinger --- docs/containers.conf.5.md | 23 +++++++++++++++++++++ pkg/config/config.go | 22 ++++++++++++++++++++ pkg/config/config_darwin.go | 13 ++++++++++++ pkg/config/config_linux.go | 7 +++++++ pkg/config/config_test.go | 5 +++++ pkg/config/config_windows.go | 4 ++++ pkg/config/containers.conf | 9 ++++++++ pkg/config/default.go | 1 + pkg/config/testdata/containers_default.conf | 7 +++++++ 9 files changed, 91 insertions(+) diff --git a/docs/containers.conf.5.md b/docs/containers.conf.5.md index 84615f306..1cdc6403c 100644 --- a/docs/containers.conf.5.md +++ b/docs/containers.conf.5.md @@ -378,6 +378,29 @@ if you want to set environment variables for the container. Default method to use when logging events. Valid values: `file`, `journald`, and `none`. +**helper_binaries_dir**=["/usr/libexec/podman", ...] + +A is a list of directories which are used to search for helper binaries. + +The default paths on Linux are: +- `/usr/local/libexec/podman` +- `/usr/local/lib/podman` +- `/usr/libexec/podman` +- `/usr/lib/podman` + +The default paths on macOS are: +- `/usr/local/opt/podman/libexec` +- `/opt/homebrew/bin` +- `/opt/homebrew/opt/podman/libexec` +- `/usr/local/bin` +- `/usr/local/libexec/podman` +- `/usr/local/lib/podman` +- `/usr/libexec/podman` +- `/usr/lib/podman` + +The default path on Windows is: +- `C:\Program Files\RedHat\Podman` + **hooks_dir**=["/etc/containers/oci/hooks.d", ...] Path to the OCI hooks directories for automatically executed hooks. diff --git a/pkg/config/config.go b/pkg/config/config.go index 94f1b4695..3a6ce8780 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -234,6 +234,10 @@ type EngineConfig struct { // EventsLogger determines where events should be logged. EventsLogger string `toml:"events_logger,omitempty"` + // HelperBinariesDir is a list of directories which are used to search for + // helper binaries. + HelperBinariesDir []string `toml:"helper_binaries_dir"` + // configuration files. When the same filename is present in in // multiple directories, the file in the directory listed last in // this slice takes precedence. @@ -1126,3 +1130,21 @@ func (c *Config) ActiveDestination() (uri, identity string, err error) { } return "", "", errors.New("no service destination configured") } + +// FindHelperBinary will search the given binary name in the configured directories. +// If searchPATH is set to true it will also search in $PATH. +func (c *Config) FindHelperBinary(name string, searchPATH bool) (string, error) { + for _, path := range c.Engine.HelperBinariesDir { + fullpath := filepath.Join(path, name) + if fi, err := os.Stat(fullpath); err == nil && fi.Mode().IsRegular() { + return fullpath, nil + } + } + if searchPATH { + return exec.LookPath(name) + } + if len(c.Engine.HelperBinariesDir) == 0 { + return "", errors.Errorf("could not find %q because there are no helper binary directories configured", name) + } + return "", errors.Errorf("could not find %q in one of %v", name, c.Engine.HelperBinariesDir) +} diff --git a/pkg/config/config_darwin.go b/pkg/config/config_darwin.go index c0722ec7f..5abb51f30 100644 --- a/pkg/config/config_darwin.go +++ b/pkg/config/config_darwin.go @@ -15,3 +15,16 @@ func customConfigFile() (string, error) { func ifRootlessConfigPath() (string, error) { return rootlessConfigPath() } + +var defaultHelperBinariesDir = []string{ + // Homebrew install paths + "/usr/local/opt/podman/libexec", + "/opt/homebrew/bin", + "/opt/homebrew/opt/podman/libexec", + "/usr/local/bin", + // default paths + "/usr/local/libexec/podman", + "/usr/local/lib/podman", + "/usr/libexec/podman", + "/usr/lib/podman", +} diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go index fac9e2283..da0ae871a 100644 --- a/pkg/config/config_linux.go +++ b/pkg/config/config_linux.go @@ -35,3 +35,10 @@ func ifRootlessConfigPath() (string, error) { } return "", nil } + +var defaultHelperBinariesDir = []string{ + "/usr/local/libexec/podman", + "/usr/local/lib/podman", + "/usr/libexec/podman", + "/usr/lib/podman", +} diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 51b37fde4..481f5d190 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -163,6 +163,10 @@ var _ = Describe("Config", func() { "TERM=xterm", } + helperDirs := []string{ + "/somepath", + } + // Then gomega.Expect(err).To(gomega.BeNil()) gomega.Expect(defaultConfig.Engine.CgroupManager).To(gomega.Equal("systemd")) @@ -172,6 +176,7 @@ var _ = Describe("Config", func() { gomega.Expect(defaultConfig.Engine.NumLocks).To(gomega.BeEquivalentTo(2048)) gomega.Expect(defaultConfig.Engine.OCIRuntimes).To(gomega.Equal(OCIRuntimeMap)) gomega.Expect(defaultConfig.Containers.HTTPProxy).To(gomega.Equal(false)) + gomega.Expect(defaultConfig.Engine.HelperBinariesDir).To(gomega.Equal(helperDirs)) }) It("test GetDefaultEnvEx", func() { diff --git a/pkg/config/config_windows.go b/pkg/config/config_windows.go index 28e8471f2..dbe7ba00d 100644 --- a/pkg/config/config_windows.go +++ b/pkg/config/config_windows.go @@ -13,3 +13,7 @@ func customConfigFile() (string, error) { func ifRootlessConfigPath() (string, error) { return os.Getenv("APPDATA") + "\\containers\\containers.conf", nil } + +var defaultHelperBinariesDir = []string{ + "C:\\Program Files\\RedHat\\Podman", +} diff --git a/pkg/config/containers.conf b/pkg/config/containers.conf index 481405a1a..fc61ed709 100644 --- a/pkg/config/containers.conf +++ b/pkg/config/containers.conf @@ -341,6 +341,15 @@ default_sysctls = [ # #events_logger = "journald" +# A is a list of directories which are used to search for helper binaries. +# +#helper_binaries_dir = [ +# "/usr/local/libexec/podman", +# "/usr/local/lib/podman", +# "/usr/libexec/podman", +# "/usr/lib/podman", +#] + # Path to OCI hooks directories for automatically executed hooks. # #hooks_dir = [ diff --git a/pkg/config/default.go b/pkg/config/default.go index 89193be64..db5ba6936 100644 --- a/pkg/config/default.go +++ b/pkg/config/default.go @@ -247,6 +247,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) { c.StaticDir = filepath.Join(storeOpts.GraphRoot, "libpod") c.VolumePath = filepath.Join(storeOpts.GraphRoot, "volumes") + c.HelperBinariesDir = defaultHelperBinariesDir c.HooksDir = DefaultHooksDirs c.ImageDefaultTransport = _defaultTransport c.StateType = BoltDBStateStore diff --git a/pkg/config/testdata/containers_default.conf b/pkg/config/testdata/containers_default.conf index 02dafb9eb..41d2c6f9e 100644 --- a/pkg/config/testdata/containers_default.conf +++ b/pkg/config/testdata/containers_default.conf @@ -164,6 +164,13 @@ no_pivot_root = false # namespace is set, all containers and pods are visible. #namespace = "" +# A is a list of directories which are used to search for helper binaries. +# +helper_binaries_dir = [ + "/somepath", +] + + # Path to OCI hooks directories for automatically executed hooks. hooks_dir = [ ]