Commit Graph

41 Commits

Author SHA1 Message Date
Nalin Dahyabhai d10c03bc3d Extend driver.ListLayers()
Implement ListLayers() for the aufs, btrfs, and devicemapper drivers,
along with a unit test for them.
Stop filtering out directories with names that aren't 64-hex chars in
vfs and overlay ListLayers() implementations, which is more a convention
than a hard rule.
Have layerStore.Wipe() try to remove remaining listed layers after it
removes the layers that the layerStore knew of.
Close() a dangling ReadCloser in NaiveCreateFromTemplate.
Switch from using plain defer to using t.Cleanup() to handle deleting
layers that tests create, have the addManyLayers() test function do so
as well.
Remove vfs.CopyDir, which near as I can tell isn't referenced anywhere.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-12 16:05:09 -04:00
Giuseppe Scrivano 7113c3d0ae
drivers: chown root mount to root in the userns
chown the root mount to root in the userns so that it can be used by
the container.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-04-11 12:56:23 +02: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
Miloslav Trmač 5e410ef763 Misc individual warning fixes
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:53 +02:00
Miloslav Trmač f42467020f Misc. warning cleanups
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-01 02:53:06 +02:00
Miloslav Trmač f1e256e70d Introduce, and use, graphdriver.MustRegister
... instead of silently failing.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-01 02:46:52 +02:00
Sergio Lopez 7617ae34d8 Limited support for operating on images on macOS
Supporting macOS presents a number of challenges since the lack of
user namespaces means that operations that alter the ownership or
permissions on a file face harsh limitations, since are requested by
an unprivileged user that may need to potentially operate on arbitrary
uids/gids.

To overcome this challenges, we rely on the existing "forceMask"
feature to store the actual ownership and permission bits as an
extended attribute entry on each file.

In addition to automatically enabling "forceMask" when running on
macOS, we also need some minor changes to ensure the compatibility
with this OS. The most significant is the fact that, on macOS
SafeLchmod and SafeChmod also operate on the extended attributes, to
allow us to properly create the directories supporting the image.

With this changes in place, buildah is able to perform basic
operations on OCI images, such as downloading the image, creating a
working container, and removing them.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2022-06-06 08:01:54 +02:00
Nalin Dahyabhai c434673f89 drivers/vfs: inherit permissions on "/" from parent layers
When creating a new vfs base layer, default its permissions to 0555
instead of 0755, bringing it in line with overlay.  When creating a vfs
layer based on another layer, use the permissions of the parent layer's
root directory as the permissions of the root directory of the new
layer.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-02-24 16:44:51 -05:00
Peter Hunt 01776faaa6 drivers: add ReadWriteDiskUsage endpoint
all endpoints currently walk the directory to find the size

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2021-01-28 11:57:53 -05:00
Giuseppe Scrivano c2633cba0b
vfs: implement DiffGetter
if the DiffGetter interface is provided, the layer store doesn't need
to mount the layer to access the files for tar-split.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-05-19 12:49:14 +02:00
Sascha Grunert d88ef6dc08
Enable goimports linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Giuseppe Scrivano 7a0d58dab5
storage: drop ostree deduplication
it was an attempt to use OSTree to deduplicate files, at the time we
already had a dependency on OSTree for system containers in
containers/image.  Since the feature never really took off, let's just
drop it.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-05 20:27:45 +02:00
Daniel J Walsh e96cd8656f
Naive diff should pass in the ro option on parent directory
If we are just mounting the parent directory, we should do it read
only.  We should not use the upper and work directory.

If there is only one lower directory we should return that path.  No
reason to mount the lower directory at all.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-08-06 08:37:29 -04:00
Kevin Pelzel a2f32f9dbf Removing need to specify storage driver when using ignore_chown_errors option
Signed-off-by: Kevin Pelzel <kevinpelzel22@gmail.com>
2019-08-05 09:52:50 -06:00
Daniel J Walsh fa580f0747
Add support for ignoreChownErrors to vfs
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-07-29 14:30:17 -04:00
Daniel J Walsh 976fe22092
Add storage options to IgnoreChownErrors
Modified patch of Kevin Pelzel.

Also changed ApplyDiff to take new ApplyDiffOpts Struct.

Signed-off-by: Kevin Pelzel <kevinpelzel22@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-07-26 06:05:27 -04:00
Danila Kiver fe0e9e0b58 Remove unfinished VFS layer if its creation fails.
Current implementation of VFS driver performs the copy of the parent
layer during the creation of new (child) layer, but does not clean
the destination if the copy process fails.

From the consuming application perspective, this make storage leaks
possible, e.g. an attempt to create new container with podman,
if failed in the middle of the copy due to disk overflow, leaves
unfinished container layer stray.

To avoid obliging the application (or the end user) to take care of
such possible leaks, cleanup is added.

Signed-off-by: Danila Kiver <danila.kiver@mail.ru>
2019-06-29 14:33:39 +03:00
Nalin Dahyabhai 026db3c2bd drivers: make Init() take a graphdriver.Config
Instead of passing the driver-specific directory and assorted fields
from a Config struct to lower-level drivers when we initialize them,
pass them the directory and the Config struct.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-06-20 11:38:33 -04:00
Daniel J Walsh ef42340c2e
Revert "Add MountTempFromSource and RemoveTemp interfaces"
This reverts commit e9695564db.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-05-02 11:54:55 -04:00
Daniel J Walsh 91cf837e44
Merge branch 'master' of github.com:containers/storage 2019-05-02 10:36:36 -04:00
Nalin Dahyabhai 8d7b848bcb Compilation fixes
Add a couple of quick compilation fixes.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-05-01 23:37:07 -04:00
Giuseppe Scrivano 7c6d502e9b
vfs: prefer layer custom idmappings
Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-05-01 18:46:06 +02:00
Daniel J Walsh e9695564db
Add MountTempFromSource and RemoveTemp interfaces
These interfaces can be used to setup a graphdriver mountpoint
of the source directory for use within a container.
The RemoveTemp interface umounts the mountpoint and then removes
all of the modified data in the graphdriver for this source directory.

The primary use case of these interfaces is for container engines that
want to mount a directory from the host system into the container. The
source dirctory then can be modified without actually changing the
directory on the host.

Containers will use these interfaces for sharing packaing cache directories
like /var/cache/dnf, to help speed up container builds.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-04-29 14:46:40 -04:00
Nalin Dahyabhai c073b43547 Add a CreateFromTemplate() method to drivers, and use it for mapped layers
Add a CreateFromTemplate() method to graph drivers, and use it instead
of a driver-oblivious diff/put method when we want to create a copy of
an image's top layer that has the same parent and which differs from the
original only in its ID maps.

This lets drivers that can quickly make an independent layer based on
another layer do something smarter than we were doing with the
driver-oblivious method.  For some drivers, a native method is
dramatically faster.

Note that the driver needs to be able to do this while still exposing
just one notional layer (i.e., one link in the chain of layers for a
given container) to the higher levels of the APIs, so if the new layer
is actually a child of the template layer, that needs to remain a detail
that's private to the driver.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-01-17 14:28:40 -05:00
Daniel J Walsh 6c86fe70d3
Rebase vfs code to use Moby definition of copy driver
This new version of copy will attempt to use reflinks
if the underlying file system supports reflink, which
should optimize the vfs storage driver for rootless
podman and buildah.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-12-05 10:16:19 -05:00
Daniel J Walsh ab6be50561
Allow the passing in and retrieval of mount options
We want to allow tools like podman/buildah to override default storage
container mount options on a container by container basis.

For example if the default mount options for containers/storage include
nodev or nosuid, we want to allow podman to turn these off if the user
specifies --privileged.

We also might want to turn off certain user namespace flags that will cause
buildah and podman build to work slower when creating container images.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-11-19 19:14:21 -05:00
Daniel J Walsh b6ccc0acfa
Add MountOpts to stop adding fields to Get Interface
This patch adds a MountOpts field to the drivers so we can simplify
the interface to Get and allow additional options to be passed in the future.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-10-05 09:23:46 -04:00
Giuseppe Scrivano 1897396330
drivers: inform Mount of the mappings used by the container
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-26 06:12:42 +02:00
Daniel J Walsh 8b1a0f8d68
Add default mount options to pass to drivers
I believe we should be running container images mounted with nodev by default.
This would eliminate the disk of a device sneaking into the container without
being on the approved list.  This would give us the same or potentially additional
security over the device cgroup.

It would be nice if this could be passed in on an image by image basis.  So users
could also specify if they want nosuid images.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-07-18 10:20:27 -04:00
Giuseppe Scrivano 52a37816aa
vfs: add support for ostree deduplication
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-06-29 18:47:10 +02:00
Nalin Dahyabhai 97326e1d2f Support for per-container uid/gid mapping: lower
Expose reading and writing ID mapping in the archive and chrootarchive
packages, and in the driver interface.  Generally this means that
when computing or applying diffs, we need to have ID mappings passed in
that are specific to the layers we're using.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-04-03 10:34:32 -04:00
Nalin Dahyabhai b71d4c4197 Support for per-container uid/gid mapping: upper
Add support to the Store objects for per-container UID/GID mapping.
* UID and GID maps can be specified when creating layers and containers.
* If mapping options are specified when creating a container, those
  options are used for creating the layer which we create for the
  container and recorded with the container for convenience.
* A layer defaults to using the ID mapping configured for its parent, or
  to the default which was used to initialize the Store object if it has
  no parent.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-04-03 10:34:32 -04:00
Nalin Dahyabhai 2c38720f64 overlay, vfs: Accept options without the driver name prefix
In the overlay and vfs drivers, accept option names which we'd
recognize, if they had the driver name as a prefix, as aliases for their
proper names.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-11-08 15:13:24 -05:00
Nalin Dahyabhai 8c6a9fce16 Support additional image stores in "vfs"
Teach the vfs driver to use a list of search directories when looking
for a layer's directory, and have it interpret a "vfs.imagestore" option
to populate that list.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-10-03 12:46:49 -04:00
Daniel J Walsh 01a6d2bc42 Backport moby vfs changes to containers/storage
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-09-26 20:45:15 +00:00
Daniel J Walsh f39066fe1b Update packages to match latest code in moby/pkg
Had to vendor in a new version of golang.org/x/net to build
Also had to make some changes to drivers to handle
archive.Reader -> io.Reader
archive.Archive -> io.ReadCloser

Also update .gitingore to ignore emacs files, containers-storage.*
and generated man pages.

Also no longer test travis against golang 1.7, cri-o, moby have also
done this.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-09-12 18:00:29 +00:00
Dan Walsh 1624d9622b Fix container storage to support additional image stores
We want to support additional read/only image stores available on
file systems.  Usually these images stores would be on network shares.
Currently the only driver that will support additional images is the
overlay file system.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2017-05-20 12:18:51 -04:00
Dan Walsh 473f49f004 Remove Get prefix on method calls.
Go validate suggests that you should not use functions that begin with Get,
unless you have to.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2017-05-10 11:04:46 -04:00
Daniel J Walsh 79a5d04c2f Switch to using opencontainers/selinux
We have moved runc/libcontainers selinux support out of libcontainer
into opencontainers/selinux.  Switching containers/storage to use
new interfaces.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-03-22 14:12:48 -04:00
Nalin Dahyabhai 60ff079996 Rename: cow/cowman -> storage/oci-storage
Rename the library module and CLI wrapper.
Rename daemon/graphdriver to drivers.
Catch up vendoring to match modules we've pruned.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2016-07-18 17:35:50 -04:00