Commit Graph

46 Commits

Author SHA1 Message Date
Daniel J Walsh f75d738e63
Use system defaults if storage.conf does not exist in XDG_CONFIG_HOME
Follow up to https://github.com/containers/storage/pull/1357

Podman tests suggest that do not need to use XDG_CONFIG_HOME if
storage.conf does not exists.  In that case we fall back to
/etc/containers/storage.conf and /usr/share/containers/storage.conf

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-27 14:21:54 -04:00
Daniel J Walsh 9415b88c35
If XDG_CONFIG_HOME env is set we should use it and ignore defaults
HPC Customers noticed that storage was attempting to read files in /usr
and /etc, even though they set XDG_CONFIG_HOME, they expect to only read
config files in this directory.

Fixes: https://github.com/containers/podman/issues/15680

(Actually partial fixes), need to look at other config files.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-23 15:40:13 -04:00
Miloslav Trmač a1ccc9d862 Use os.WriteFile instead of ioutil.WriteFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:34 +02:00
Miloslav Trmač 4b28197720 Use os.ReadFile instead of ioutil.ReadFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:30:43 +02:00
Eng Zer Jun 6ea3603b6b
test: use `T.TempDir` to create temporary test directory
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-30 01:21:37 +08:00
Sascha Grunert a10dcf45f5
Do not error if no storage.conf exists
This allows consumers of this library to rely on the in-memory default
rather than requiring a storage.conf.

Refers to https://github.com/containers/storage/pull/1279 and
1f647d954f

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-14 10:37:00 +02:00
Sascha Grunert 3455d12729
Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the
deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 13:22:46 +02:00
Giuseppe Scrivano cbb1446d16
options: copy all options on explicit config file
when the configuration file was explicitly specified, all the graph
drivers options are copied, not only the ones allowed for rootless.

Closes: https://github.com/containers/storage/issues/1278

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 63f6bba7bb
options: store a copy for prevReloadConfig
otherwise changes applied later to the object are propagated to the
copy in prevReloadConfig.storeOptions.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 880f7a7b34
options: treat missing $CONTAINERS_STORAGE_CONF as error
if the CONTAINERS_STORAGE_CONF environment variable is set and the
specified file doesn't exist, then return an error.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 1f647d954f
types: propagate configuration load errors
if any error happens when loading the default configuration file,
report it to the caller.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 8e9ae4fd4b
options: fix function name
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-01 22:50:31 +02:00
Paul Holzinger 43bc333374
types: do not load storage.conf at init time
Using init in libs is bad. init() has to be run every time the
application which imports this package starts. This slows down startup
time even if the application will never use this code path.

Instead use a sync.Once to only the config when it is required.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-01 16:26:49 +02:00
Paul Holzinger 07530efd08
storage.conf: respect CONTAINERS_STORAGE_CONF env
CONTAINERS_STORAGE_CONF env var should overwrite the default path even
for the first config load at init time.

Fixes containers/podman#14267

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-01 16:23:55 +02:00
Valentin Rothberg b6be89d47f types: logrus: remove trailing dots
Not needed by the log convention in the rest of the code.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-17 13:56:38 +02:00
Valentin Rothberg e1ebdadf52 types: fix typo in warning
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-17 13:56:38 +02:00
Daniel J Walsh b05b3b44e2
PullOptions should work for rootless users also
Also add interfaces to allow callers to see the pull options.

While experimenting with pushing and pulling with zstd, I found
that storage pulloptions were not being used in rootless mode.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-05-16 16:05:15 -04:00
Doug Rabson ae67ca335b Change default location for storage.conf to...
... /usr/local/etc/containers on FreeBSD

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-05-03 16:39:32 +01:00
Dan Čermák 39de90b9d7
Move the mount_program autodetection into the graphdriver Init()
This prevents issues inside podman where the mount_program is detected and
subsequently erased, e.g. via the usage of the --root option.
This fixes https://github.com/containers/podman/issues/13459
This fixes https://github.com/containers/podman/issues/13458

Signed-off-by: Dan Čermák <dcermak@suse.com>
2022-03-18 12:07:49 +01:00
cdoern f260c4ec1e fix Save()
switched os.Open to os.Create because os.Open() creates a file in read only mode

Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
2022-02-10 22:34:00 -05:00
Giuseppe Scrivano 7e610596cf
containers: detect overlapping mappings
when the container specifies some mappings to be applied, verify that
they are not overlapping and give a clearer error message.

Closes: https://github.com/containers/storage/issues/1127

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-02-08 09:57:34 +01:00
Daniel J Walsh 86dd22e482
Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-21 07:42:51 -05:00
cdoern 454ba682f6 GetStore modifications, Create StorageConfig and Save
If passing either just a runroot or both a runroot and a graphroot
GetStore() was returning when finding a match for JUST the graph root,
overriding the runroot and using a different location than specified

Also create two new helper functions which add the ability to retrieve and overwrite
the toml config in the user's storage.conf file

Signed-off-by: cdoern <cdoern@redhat.com>
2022-01-10 21:40:29 -05:00
Daniel J Walsh cadf8d9017
Merge branch 'main' into default 2021-12-13 15:21:36 -05:00
Aditya Rajan 0bc7e4dd52
options: use global const for run and graph root
Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-12-02 21:28:56 +05:30
Aditya Rajan cf1b8c2ab3
options: fall back to default graph and run root for empty case
While reloading from config files `graph` and `run` root could be set to
empty. We should fall back to default if they are empty.

See: https://github.com/containers/podman/issues/12467

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-12-02 17:07:06 +05:30
Daniel J Walsh 0baf764c4a
Reset defaultConfigFile if defaultOverrideConfigFile exits.
Currently DefaultConfigFile does not report back the storage.conf file
that is actually used if /etc/containers/storage.conf exists it should
be reported back to the user. This issue was seen with Podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-30 06:34:40 -05:00
Daniel J Walsh d963622899
User are reporting potential issues with using overlay2
We should just switch to overlay right away rather then
handling the driver code lower in the stack.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-15 08:48:58 -05:00
Daniel J Walsh 5c5bf639ed
Support /usr/share/containers/storage.conf
Man page says we support storage.conf in this directory, so if
system does not have /etc/containers/storage.conf we should use it.

Fixes: https://github.com/containers/storage/issues/1015

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-14 09:09:21 -04:00
Daniel J Walsh 534b0b3281
Standardize on capatalized logrus messages, and remove stutters
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-23 14:43:35 -04:00
Giuseppe Scrivano 2c2968534e
types: on error fallback to filepath.Clean()
Now expandEnvPath always fallbacks to filepath.Clean() when
filepath.EvalSymlinks() fails.

commit b4477c7a8b introduced the
regression.

This is useful in a user namespace when the permissions for the
storage path are not yet tweaked to allow access for all users.

Reported by: https://github.com/containers/buildah/pull/3450

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-16 13:28:16 +02:00
Daniel J Walsh b4477c7a8b
Follow symlinks if they exists
Fixes: https://github.com/containers/podman/issues/10187

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-08-04 07:13:58 -04:00
Daniel J Walsh 728a92897f
Revert #952, we don't want to use /run/user on non systemd systems
This feature was originally added for  #568, and I mistakenly removed
it.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-07-12 14:00:58 -04:00
Daniel J Walsh c2bc7b1643
Add test for bad entries in storage.conf
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-07-01 04:50:58 -04:00
Daniel J Walsh 5bd2e7b703
Report bad entries in storage.conf to the user
Currently if a user puts a typo into a storage.conf
or puts the keys in the wrong section, then tools using
container/storage ignore them. This patch will print them
as warnings, so that the user has some idea what is going on.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-30 10:23:21 -04:00
Daniel J Walsh 06e2dce12b
Use /run/user/UID in rootless mode if writable
Other parts of the code are using this directory, so we end up
with us creating an empty directory.

I don't see a reason why we would just use this directory only if
the init program is systemd?

Fixes: https://github.com/containers/podman/issues/10782

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-25 08:53:40 -04:00
mla 74a61676d2 Added support for CONTAINERS_STORAGE_CONF override
Signed-off-by: Morten Larsen <mortenlarsens@gmail.com>
2021-06-09 10:17:09 +02:00
Giuseppe Scrivano 7e665ab835
store: add option to disable volatile
add an option to storage.options to inhibit usage of the
volatile storage flag.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-17 09:51:52 +02:00
Giuseppe Scrivano 7400647378
types: add map PullOptions to the conf file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-07 11:29:27 +02:00
Giuseppe Scrivano c2a5fd1bb7
drivers: add interface to directly write diff
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-07 11:29:25 +02:00
Daniel J Walsh 98384ff1ca
Expand Variables on rootlessStoragePath
The current code was hanging for me, this makes sure the path is
expanded properly when it is read.

Fixes: https://github.com/containers/podman/issues/10181

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-05 13:49:51 -04:00
Daniel J Walsh c12c9e28f4
ReloadConfigurationFile should Reset storage options
Currently in Podman if we reset the CONTAINERS_STORAGE_CONF path, we get
the graph driver options from the original config file as well as the
options from the override path. This PR resets the storageconf to the
initial state when called multiple times.

Also if user sets STORAGE_OPTS="" then we should use it to override all
other storage options.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-04-12 06:13:44 -04:00
ktock 64f018103e Support additional layer store
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2021-04-07 17:53:36 +09:00
Giuseppe Scrivano f5f3c45d14
types: check for native overlay support
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-03-05 09:27:23 +01:00
Jordan Williams 33418be0fc
Inherit system storage driver in rootless configurations
The storage driver set in `/etc/containers/storage.conf` was ignored for rootless configurations.
Rootless configurations would use overlay or vfs by default.
If the STORAGE_DRIVER environment was variable set, this value would be used instead.

This commit changes this behavior to inherit the driver set in `/etc/containers/storage.conf`.
To inherit the driver in rootless configurations, the driver must be valid in a rootless context.
The valid rootless drivers are btrfs, overlay, and vfs at this time.
To remain consistent with previous behavior, the STORAGE_DRIVER environment variable supersedes any driver set in `/etc/containers/storage.conf` and does not need to be a valid rootless driver.

buildah's documentation for the `--storage-driver` command will need to be updated to reflect these changes.
2021-03-02 10:28:53 -06:00
Daniel J Walsh 120cc997d2
Move storageOpts structures into types subdir to shrink bindings.
Currently when we build podman bindings we are pulling in the entire
storage libraries, even though we only need a few structures and
functions.

Testing with the following program

```
package main

import (
	"fmt"
	"github.com/containers/storage/types"
)

func main() {
	fmt.Println(types.GetRootlessRuntimeDir(0))
}
```

Removing types above gives me compile size of the the program

du -s t.old t.new
9640	t.before
3232	t.after

Currently these functions are being vendored into
containers/common/pkg/config, which leads to large size in podman-remote
and podman bindings.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-26 05:34:09 -05:00