Commit Graph

149 Commits

Author SHA1 Message Date
Giuseppe Scrivano b0885dfba9
store: drop rootless from arguments
drop the rootless argument from DefaultStoreOptions and
UpdateStoreOptions since this can be retrieved internally through the
unshare package.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-16 21:13:28 +01:00
Giuseppe Scrivano c72a594c83
types: use functionalities from pkg/homedir
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-16 08:36:21 +01:00
Nalin Dahyabhai b0c1c886c3 "pull up" images when creating them, too
We previously started "pulling up" images when we changed their names,
and started denying the presence of images in read-only stores which
shared their ID with an image in the read-write store, so that it would
be possible to "remove" names from an image in read-only storage.  We
forgot about the Flags field, so start pulling that up, too.

Do all of the above when we're asked to create an image, since denying
the presence of images with the same ID in read-only stores would
prevent us from finding the image by any of the names that it "had" just
a moment before we created the new record.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-06 18:21:11 -04:00
Nalin Dahyabhai f3808272d8 Drop nameLooksLikeID()
Replace the newer nameLooksLikeID() function with calls to
stringid.Validate(), which does the same thing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-03 10:21:35 -04:00
Alexander Larsson ddf18d41da Add Store.GarbageCollect() method
This looks in the container store for existing data dirs with ids not in
the container files and removes them. It also adds an (optional) driver
method to list available layers, then uses this and compares it to the
layers json file and removes layers that are not references.

Losing track of containers and layers can potentially happen in the
case of some kind of unclean shutdown, but mainly it happens at reboot
when using transient storage mode. Such users are recommended to run
a garbage collect at boot.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-11-14 16:36:30 +01:00
Nalin Dahyabhai 449ffb0f8d Use defined constants for flag names
Use constants for the names of flags that we set in Flags maps that we
store in layer/image/container records, to make it easier to avoid
possible breakages due to typos in the future.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-09-14 10:54:54 -04:00
Miloslav Trmač fdd89d3dd8 Fix an unused line in applyNameOperation
... by actually using it, removing some duplication, and
perhaps micro-optimizing some memory allocations.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 18:56:24 +02:00
Aditya R 4c37491c64
store: add independent AddNames and RemoveNames for images,layers,containers
Adds AddNames and RemoveNames so operations which are invoked in parallel
manner can use it without destroying names from storage.

For instance

We are deleting names which were already written in store.
This creates faulty behavior when builds are invoked in parallel manner, as
this removes names for other builds.

To fix this behavior we must append to already written names and
override if needed. But this should be optional and not break public API

Following patch will be used by parallel operations at podman or buildah end, directly or indirectly.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-01 01:33:35 +05:30
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
Nalin Dahyabhai 82599ce3d6 Fix TestDefaultStoreOpts()
Use the variable name that matches the one used in the config file, and
add environment expansion for the rootless storage location.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-02-24 16:44:51 -05:00
Nalin Dahyabhai bc6102ea53 getRootlessRuntimeDirIsolated(): don't use an empty tmpPerUserDir
If the tmpPerUserDir value is the empty string, don't try to use it as a
directory path.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-02-24 16:44:51 -05:00
Daniel J Walsh c935869b9f
Use STORAGE_DRIVER environment variable in rootless mode
Currently we ignore STORAGE_DRIVER enviroment variable in
rootless mode, always forcing it to be Overlay if fuse-overlay
is installed of vfs.

This patch will respect both the STORAGE_DRIVER and STORAGE_OPT
environment variable if set in rootless mode.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-08 06:18:43 -05:00
Daniel J Walsh 09645065ae
Revert returning storageOpts
Revert 8bdc527f24

I merged a patch that was a mistake that returned
rootless storage opts early. User had a broken
storage.conf that caused me to get confused.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-04 16:04:18 -05:00
Daniel J Walsh 8bdc527f24
Fix reading of ~/.config/containers/storage.conf
Currently rootless users of storage.conf in the home
dir ignore the storage options.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-02 17:07:06 -05:00
Roberto Castagnola 782c28d025
Restore usage of rootless_storage_path in user storage.conf
Signed-off-by: Roberto Castagnola <roberto.castagnola@gmail.com>
2020-11-02 14:58:06 +01:00
Daniel J Walsh a1e6151b71
If caller Sets the DefaultConfigFilePath, we need to use it
Attempting to override the location of the storage.conf file, using
the SetDefaultConfigFilePath for testing is failing in Podman.

This patch will use the replace configuration file.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-23 16:19:11 -04:00
Giuseppe Scrivano e4bf5a799d
Merge pull request #733 from rcasta74/podman_issue_7876
Fix usage of rootless_storage_path from system storage.conf file
2020-10-16 14:50:03 +02:00
Daniel J Walsh 690c8cb767
Stop excessive wrapping
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-15 06:08:37 -04:00
Roberto Castagnola 38f98a8bdf Fix usage of rootless_storage_path from system storage.conf file 2020-10-05 15:41:20 +02:00
Daniel J Walsh 3c3285331d
Support the rootless storage path from the system file
Currently rootless containers are ignoring the rootless_storage_path entry
from the storage.conf file.

This will use the path is specified.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-09 15:25:39 -04:00
Daniel J Walsh de3d59a92d
For podman v2.0 we need to use use ignore_chown_errors field if set
It is too risky to add all system options.
This is supposed to work for HPC customers, so we can just
grab this setting if set in system wide settings.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-09 15:25:39 -04:00
Ashley Cui d974c2ba30 Allow any env variable for graphroot, runroot, storagepath
Previously only resticted to home, uid, and user

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-08-11 17:18:28 -04:00
Ashley Cui 69e1110322 Allow env variables in graphroot and runroot
Expand env variables in paths

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-08-06 11:59:28 -04:00
Daniel J Walsh 3fb27a360c
new interface for MountImage added
Interface added to mount image rootfs without any container.
image can be mounted only in ReadOnly mode.

Signed-off-by: Kunal Kushwaha <kunal.kushwaha@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-07 13:45:51 -04:00
Andrew Aladjev 68325d17cd use temp instead of run as fallback directory for rootless mode 2020-06-13 16:28:57 +03:00
Giuseppe Scrivano c7b3063903
store: memoize ReloadConfigurationFile
avoid reloading the same configuration multiple times if the file was
not modified.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-24 08:28:31 +01:00
Giuseppe Scrivano 54a9cb2f4a
utils: do not write default storage.conf
when running as rootless, do not write the default storage.conf file.

Follow the same pattern used for libpod.conf.

Closes: https://github.com/containers/libpod/issues/5500

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-16 13:10:25 +01:00
Qi Wang 3b4c1af2fd fix else case for rootless storage path and path match
move the assignment of rootless_storage_path out of `else` block to make the config work even the graphroot is empty.
fix the path match error

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-03-02 09:58:18 -05:00
Daniel J Walsh e4f65e72d4 Add `rootless_storage_path` directive to storage.conf
This allows rootless admins to setup alternative
paths to content in the homedir.

Rootless users on NFS homedirs will not be allowed to run
podman, if an admin wants to setup alternative directory say
in /var/tmp on local storage, they could configure the storage.conf
file and then all users would automatically get storage in /var/tmp.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-02-24 14:40:03 -05:00
Valentin Rothberg 76f71055fb use pkg/homedir
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-17 11:43:01 +01:00
Sascha Grunert fd72b45a3f
Enable golint linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Sascha Grunert ba51455527
Enable deadcode linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Daniel J Walsh b6f5c760ad
Move runroot containers storage into containers directory
Currently we are throwing lots of files/directories into the
top level of /run/user/UID/  And this makes it difficult to cleanup.
Switching to using /run/user/UID/containers, makes it easier and cleaner.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-11-22 12:49:57 -05:00
Giuseppe Scrivano c24f685d3f
utils: fix check for missing conf file
the previous error condition was causing an early failure when the
configuration file existed.  It prevented some additional checks and
to correctly set the RunRoot and GraphRoot to their default values
when they are not overriden in the configuration file.

We have not noticed it earlier as Podman would still use the
configuration from the DB in this case, so the issue is visible with
Podman only when the RunRoot is not specified in the configuration
file and in the libpod DB as well.

Closes: https://github.com/containers/libpod/issues/3274

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-06-23 23:28:48 +02:00
Daniel J Walsh 2bf9e95198
Return XDG_RUNTIME_DIR as RootlessRuntimeDir if set
We are currently ignoring XDG_RUNTIME_DIR if it is set, while
we should be using it.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-06-07 17:19:03 -04:00
Giuseppe Scrivano 8d53d451cc
utils: root in a userns uses global conf file
If the root user created a new user namespace, it still has to use the
system configuration and storage.

Previously if root created a user namespace when missing
CAP_SYS_ADMIN, we would use the configuration file under
/root/.config/containers instead of /etc/containers.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-23 14:12:03 +02:00
Daniel J Walsh aba92c81f9
Correctly check permissions on rootless directory
We have not been checking the permissions on the rootless directory
this causes issues in tools trying to access the login directory
if XDG_RUNTIME_DIR is not set correctly.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-04-17 10:22:48 -04:00
Giuseppe Scrivano 3dd479804f
storage: move the logic to detect rootless into utils.go
add a helper function that automatically detects the UID when running
in a user namespace..

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-05 15:11:57 +02:00
Daniel J Walsh e1ff94ad48
Fix cross compilation code for other platforms
When trying to vendor into containers/image we found issues
with cross platform compilation.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-03-20 08:36:26 -04:00
Daniel J Walsh 877c68cba0
Move pkg/util default storage functions from libpod to containers/storage
In an effort to remove cross vendoring, trying to fix buildah from importing
from libpod.  I beleive these libraries make more sense in containers/storage
then in libpod.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-03-19 08:33:42 -04:00
Victor Vieux d648708d02 remove utils.go
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
2014-03-10 21:06:27 +00:00
Michael Crosby 36c3614fdd Move runtime and container into sub pkg
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-03-09 23:03:40 -07:00
Alexander Larsson d8c888b3f8 Drop EofReader
This is not used any more

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
2014-02-14 13:46:21 +01:00
Solomon Hykes 6393c38339 Move the canonical run configuration objects to a sub-package
* Config is now runconfig.Config
    * HostConfig is now runconfig.HostConfig
    * MergeConfig is now runconfig.Merge
    * CompareConfig is now runconfig.Compare
    * ParseRun is now runconfig.Parse
    * ContainerConfigFromJob is now runconfig.ContainerConfigFromJob
    * ContainerHostConfigFromJob is now runconfig.ContainerHostConfigFromJob

This facilitates refactoring commands.go and shrinks the core.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
2014-02-11 20:18:46 -08:00
Solomon Hykes e6e320acc7 pkg/opts: a collection of custom value parsers implementing flag.Value
This facilitates the refactoring of commands.go.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
2014-02-11 19:59:52 -08:00
Solomon Hykes 3ecd8ff0c8 New package `nat`: utilities for manipulating the text description of network ports.
This facilitates the refactoring of commands.go

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
2014-02-11 16:51:01 -08:00
Alexander Larsson bcaf6c2359 Add Put() to graphdriver API and use it
This makes all users of Put() have a corresponding call
to Get() which means we will be able to track whether
any particular ID is in use and if not unmount it.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
2014-01-21 11:25:37 +01:00
Michael Crosby 1d8455e683 Move RootIsShared to lxc driver
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-01-17 17:42:22 -08:00
Tianon Gravi 8f3b8f3835 Run 'gofmt -s -w' 2014-01-06 22:14:35 -07:00
Solomon Hykes a009d4ae8d Move utility package 'namesgenerator' to pkg/namesgenerator 2013-12-23 23:45:18 +00:00