Commit Graph

59 Commits

Author SHA1 Message Date
Giuseppe Scrivano 9ebdbd9d9d
options: reject empty runroot or graphroot
make sure that the runroot and graphroot are not empty otherwise we will
end up using an empty directory as path prefix and create files in the
current directory.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-02-16 15:52:40 +01:00
Daniel J Walsh 0ee26255cd
Run codespell on codebase
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-02-09 12:27:59 -05:00
Giuseppe Scrivano f64e1bd14a
store: prefer /etc/containers/storage.conf
when running in rootful mode, if it is present, prefer the override path
/etc/containers/storage.conf instead of using the default storage.conf
provided by the package under the /usr/share/containers/ directory.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-01-17 11:02:23 +01:00
Dan Čermák df0cb3234e
Only override the graphdriver to vfs if the priority is unset
This is an amend to https://github.com/containers/storage/pull/1460

That PR was not addressing the case when the system wide config had the
driver_priority option configured and the user had no config file of their
own. Then `getRootlessStorageOpts` would be called and it would override the
graph driver to "vfs".

With this commit we only override the graph driver if driver priority is
empty. Otherwise we propagate the driver priority into the storage options, so
that the driver autodetection works as expected.

Signed-off-by: Dan Čermák <dcermak@suse.com>
2023-01-16 09:03:42 +01:00
Dan Čermák b2b2fefb3e
Only warn about 'driver' not being set if the priority list is unset
Currently we would display an error when the user does not specify a `driver` in
their config file. This has been present for historical reasons mostly to
prevent users from accidentally getting the vfs
driver (https://github.com/containers/storage/pull/1460#issuecomment-1370866271). Now
that most systems support the overlay driver natively, we can reduce this to a
warning and only warn about it if the driver_priority list is unset. If it is
provided, then clearly the user or the distribution wanted for c/storage to pick
a driver itself and the warning would be only confusing to users.

Signed-off-by: Dan Čermák <dcermak@suse.com>
2023-01-06 08:43:46 +01:00
Dan Čermák 881ac4864a
Make the priority for picking the storage driver configurable
This fixes https://github.com/containers/storage/issues/1457

Co-authored-by: Valentin Rothberg <vrothberg@redhat.com>
Signed-off-by: Dan Čermák <dcermak@suse.com>
2023-01-05 12:38:33 +01:00
Daniel J Walsh 22ea83a845
Define error type for ErrNoAvailableIDs
Want to allow Podman to print helpful error message when
users runs out of UIDs to use with podman run --userns=auto.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-01-03 14:24:35 -05:00
Alexander Larsson 522b67c944 Add new storage.conf option "transient_store"
This just adds the support for setting and handling this key, it
doesn't really do anything yet.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-11-14 16:36:30 +01:00
Daniel J Walsh 68a0b369a2
Expose System wide config file
Currently Podman warns when attempting to reset storage, if the
system wide storage.conf file
/usr/share/containers/storage.conf exists.

Since distros ship this, we need to allow Podman to check if the
default is the System default and therefore do not warn.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-10-26 12:10:09 -04:00
Daniel J Walsh 9e06c38dfe
Only read storage.conf once
Currently running a simple container runs and stats configuration
storage.conf files multiple times on a simple container run.

This PR cuts the opens and stats in half by caching the first read.
This speeds up start by about 10-20 microseconds.

If container engines want to react to storage files changing, added a
new function UpdateStoreOptions to allow engines to reload options.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-10-20 08:39:06 -04:00
Miloslav Trmač 4c96809f7e Use testing.T.Setenv
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-17 20:04:31 +02:00
Miloslav Trmač 2d90000b09 Add missing error checks in tests
... and remove one WriteFile that was always failing.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:54 +02:00
Miloslav Trmač f42467020f Misc. warning cleanups
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-01 02:53:06 +02:00
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