Commit Graph

245 Commits

Author SHA1 Message Date
Paul Holzinger 8f0f7109e5 pkg/config: read user local config also as root
There is really no need to limit reading the config under
$XDG_CONFIG_HOME or $HOME to rootless users only. This poses two
problems, first on a multi user system any config that should be only
applied to root in /etc will also be read by all other users which makes
this impossible to use without having all user overwrite that option
with their local containers.conf. If we read the config from $HOME as
root as well then such changes are easy.
Second, because connections/farms are currently written by the cli it
means as root is tries to write under /etc which is not good as in some
envs /etc is mounted read only.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 16:28:07 +01:00
Paul Holzinger 029ea2b917 pkg/config: remove unused Path() function
It is not called by podman or buildah, it also makes no sense to return
a path string with $HOME in it. Just delete it.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 16:28:07 +01:00
Paul Holzinger 21d3f3431f pkg/config: remove unnecessary stat on default paths
The current code has a small race it first stats the file and if it
exists it tries to read the file. Between this it is possible that the
file was removed and thus cause a fatal error when reading the config.
The better way is to simply read the file and ignore the ENOENT error
instead where we want this behavior. This avoids the need for the extra
stat syscalls. For CONTAINERS_CONF and modules we still need the hard
error if the file does not exists so we have to keep it there.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 16:28:06 +01:00
Paul Holzinger 745268b117 pkg/config: use containersConfEnv constant everywhere
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 16:28:06 +01:00
Vikas Goel 9b0147a1ae New global option interface_name in containers.conf
Add a new containers.conf attribute to define how to set interface name inside containers.

Relates to: containers/podman#21313

Signed-off-by: Vikas Goel <vikas.goel@gmail.com>
2024-01-25 07:11:33 -08:00
Oleksandr Redko 4dbd58b735 Refactor: replace raw loops with funcs from slices and maps
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-05 00:11:15 +02:00
Oleksandr Redko 3cc2a76ae9 Fix typos across repo; extend codespell config
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 23:38:47 +02:00
Chetan Giradkar 41f0492c7f Add configurability to Netavark firewall driver
closes #1338

Signed-off-by: Chetan Giradkar <cgiradka@redhat.com>
2023-11-28 12:51:21 +00:00
Valentin Rothberg cd2797eb34 pkg/config: use NewSlice, Get and Set where possible
To improve the code and reduce memory allocations.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 10:04:20 +02:00
Valentin Rothberg e212082542 pkg/config: turn machine Volumes into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg f4afa37c23 pkg/config: turn PastaOptions into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 5fb9ed7f84 pkg/config: turn NetavarkPluginDirs into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 67a73c7cc6 pkg/config: turn CNIPluginDirs into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 318bae8a6a pkg/config: turn RuntimeSupportsKVM into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 6e28b11cdd pkg/config: turn RuntimeSupportsNoCgroups into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 7b367af14c pkg/config: turn RuntimeSupportsJSON into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg a75c1ca09a pkg/config: turn RuntimePath into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 89b8572671 pkg/config: turn AddCompression into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg cad0135389 pkg/config: turn NetworkCmdOptions into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 67bf05db37 pkg/config: turn DefaultHooksDir into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 8a06b6cb94 pkg/config: turn HelperBinariesDir into attributedstring.Slice
Also tag it as omitempty to fix the test.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg ddf52636dd pkg/config: turn engine Env into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 499d0a683e pkg/config: turn ComposeProviders into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg f09869b142 pkg/config: turn ConmonRsPath into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg fbafbc0cb6 pkg/config: turn ConmonPath into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 02c8cd8521 pkg/config: turn ConmonEnvVars into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg b4f49e7b28 pkg/config: turn DNSSearches into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 45cb2feed0 pkg/config: turn DNSOptions into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 26143a5a0f pkg/config: turn DNSServers into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg a86cc6fc42 pkg/config: turn Ulimites into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 051dddac85 pkg/config: turn DefaultSysctls into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 12bde4bc00 pkg/config: turn Capabilities into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg bde9e751dc pkg/config: turn CgroupConf into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 04569d2f52 pkg/config: turn Annotations into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg b8c3014c2a pkg/config: turn devices into attributedstring.Slice
The tests are messy and should be turned into table-driven tests but I
do not have time at the moment.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg b103cb9e93 containers.conf: appendable string arrays, Part 1
Commit 395ba05c44 implemented a POC to allow for changing the behavior
when loading multiple container.conf files in sequence.  By default, the
TOML encoder will override existing data/fields with the one specified
in the loaded file.  The POC has demonstrated how this behavior can be
changed to append string slices instead of overriding/replacing them
entirely.

This change is the first step of integrating these appendable string
arrays into containers.conf and starts with enabling the `Env`,
`Mounts`, and `Volumes` fields in the `[Containers]` table.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-24 11:47:46 +02:00
Paul Holzinger 27b072610b pkg/config: lookup InitPath in HelperBinariesDir
Forcing a single upstream default for the init path is bad as some
distro use different install locations for various reasons.

To fix this use the existing helper_binaries_dir field to lookup in all
directories. To keep backwards compatibility we keep using the old
default and both Containers.InitPath and Engine.InitPath. Yes that is
right, somehow we ended up with the same config field under the
containers and engine section and they are both used in podman!
Thus we need to keep supporting both, only the field under the container
section was documented and now recommends the use of helper_binaries_dir.

To make the docs more clear also document what binaries are currently
looked up in helper_binaries_dir.

Note this needs further integration in podman.

Fixes #1110

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-18 12:55:29 +02:00
Paul Holzinger 6a79383d51 pkg/config: use empty default for db_backend
Podman should default to sqlite for new installs, however to not break
upgrades we should detect if a boltdb database exists and use that in
such case. Now in order to distinguish between an explicitly set
"sqlite" and "boltdb" and nothing set we use an empty default.

With that podman can know if we really should use the default or if it
was configured for a db explicitly. The actual detection logic must be
implemented in podman as we only know the file locations there.

This commit also drops the unused StateType as this was not used at all.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-10 15:57:52 +02:00
Valentin Rothberg ac851d5930 containers.conf: add `privileged` field to containers table
As requested in containers/podman/issues/20000, add a `privileged` field
to the containers table in containers.conf.  I was hesitant to add such
a field at first (for security reasons) but I understand that such a
field can come in handy when using modules - certain workloads require a
privileged container.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-05 13:22:35 +02:00
Valentin Rothberg 6923f768c2 URGENT: heal CI: fix codespell
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-03 11:15:37 +02:00
Valentin Rothberg ab4a3cc433 pkg/config: remove *DirSet fields
They are not correctly and inconcistently being used by Podman making it
super hard to know what's going on.  Just remove them for now and deal
with the remaining chaos in subsequent changes in common and Podman.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-21 11:27:13 +02:00
Chetan Giradkar 819434a2ea Remove ActiveDestination method to move into podman
The method ActiveDestination was being used only by Podman and there seemed to code complications as the code is split in multiple parts. Hence, moved the code to Podman to make it more readable and efficient.

Signed-off-by: Chetan Giradkar <cgiradka@redhat.com>
2023-09-20 13:29:52 +01:00
Valentin Rothberg de32d5a9f7 linters: enable dupword
Mostly monkey work to fix comments but there was also an error message.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-01 11:51:25 +02:00
Valentin Rothberg 9ca6b06f1a linters: enable predeclared
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-01 11:08:17 +02:00
Aditya R 359ff162d0 containers.conf: add field for AddCompression to Engine table
Allows users to set default value of `AddCompression` to Engine table so
users can use https://github.com/containers/buildah/pull/4912 by
default.

Closes: https://github.com/containers/buildah/pull/4912#issuecomment-1661105029

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-24 17:10:06 +05:30
Valentin Rothberg 163f808bdb pkg/config: add (*Config).LoadedModules()
To return absolute paths to modules a config was loaded with.
Knowing the modules is required for conmon's callback to
Podman's cleanup.  Returning them as absolute paths makes
loading the modules a bit faster as it avoids the lookup.

Also drop the attempted performance tune in `Default()` to
accommodate for go's memory model.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-14 09:54:50 +02:00
Valentin Rothberg 6847ea48a2 containers.conf: implement modules
Add a new concept to containers.conf called "modules".  A "module" is
a containers.conf file located at a specific directory.  More than one
module can be loaded in the specified order, following existing
override semantics.

There are three directories to load modules from:
 - $CONFIG_HOME/containers/containers.conf.modules
 - /etc/containers/containers.conf.modules
 - /usr/share/containers/containers.conf.modules

With CONFIG_HOME pointing to $HOME/.config or, if set, $XDG_CONFIG_HOME.
Absolute paths will be loaded as is, relative paths will be resolved
relative to the three directories above allowing for admin configs
(/etc/) to override system configs (/usr/share/) and user configs
($CONFIG_HOME) to override admin configs.

Also move some functions from config.go for locality.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-14 09:40:27 +02:00
Valentin Rothberg 9e659206ec pkg/config: add a new API to create a Config
Add `New()` function to create a Config and deprecate `NewConfig` which is
a) not extensible and b) broken in the sense that no external caller was
actually using the argument.

Many call sites use `Default()` which now has improved documentation and
allows for interacting with `New().  Most call sites just need to access
a pro-loaded config (via `Default()`).  This config can overridden by
`New()` if the caller sets the specific option - a requirement for an
upcoming feature for Podman allowing to load user-specified configs via
CLI flags.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-14 09:40:27 +02:00
Valentin Rothberg e00d7e3560 pkg/config: unexport DefaultConfig
It has no external user and should not be exported to avoid any API
misuse; built-in defaults are an implementation detail.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-14 09:40:27 +02:00
OpenShift Merge Robot 8694484524 Merge pull request #1586 from umohnani8/farms
Add Farms to config
2023-08-05 04:34:23 +02:00