Commit Graph

38 Commits

Author SHA1 Message Date
Nalin Dahyabhai 11d651588c overlay: only chown the upper directory if we created it
The limited documentation on how "overlay" works in podman-run suggests
that the calling user does all of the management of the upper directory
themselves, and we don't want to break whatever use case that is.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-11-03 18:07:34 -05:00
Jan Kaluza a0a9ac6380 Switch common, storage and image to monorepo.
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-08-29 15:04:28 +02:00
Nalin Dahyabhai 670a7bec6e pkg/overlay: cleanups
Change generateOverlayStructure() to not return its first argument
unchanged, since both of its callers already have that value, and adjust
a few error messages.

In the Linux MountWithOptions(), ensure that, if UpperDirOptionFragment
and WorkDirOptionFragment values were specified, they are absolute
paths, otherwise place them under the top-level parent of the various
directories we have for this mount.

Update a number of comments.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-24 15:54:08 -05:00
Nalin Dahyabhai 0f5c6fc504 pkg/overlay: add a MountLabel flag to Options
Add a way to pass a "set the SELinux contexts" labels to
MountWithOptions.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-17 09:59:55 -05:00
Nalin Dahyabhai c0efbe8210 pkg/overlay: add a ForceMount flag to Options
Add a ForceMount flag to pkg/overlay.Options that forces mounting the
overlay filesystem and returning a bind mount to it instead of trying to
leave that for later in cases where we're able to have the kernel do it.

This is mainly for the sake of callers that want to do more things with
the mounted overlay filesystem before passing them to the (presumably)
OCI runtime.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-17 09:59:55 -05:00
Nalin Dahyabhai 8ae99121c1 CI: enable the gofumpt linter
Turn on the gofumpt linter.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-15 13:17:44 -04:00
Philip Dubé a42bfd0191 Replace map[K]bool with map[K]struct{} where it makes sense
Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-05 15:58:43 +00:00
Nalin Dahyabhai 81435aadcb mkcw: populate the rootfs using an overlay
When using the working container's rootfs to populate a plaintext disk
image with mkfs, instead of writing .krun_config.json to the rootfs and
then removing it afterward (since we don't want it to show up if the
same working container is later committed to non confidential-workload
image), mount an overlay filesystem using a temporary directory as the
upper and the rootfs as the lower, create the .krun_config.json file in
the overlay filesystem, and use the overlay filesystem as the source
directory for mkfs.

Add the necessary stubs to allow pkg/overlay to at least compile on
non-Linux systems.  Change the naming scheme for a test so that the path
names it uses for temporary directories don't include "," or "=", which
can confuse the kernel.

Creating confidential workload images will now only be possible on Linux
systems, but we exec'd out to sevctl to read platform certificates, and
that requires kernel support with vendor firmware, so I don't know that
anyone will actually be impacted by the change.

Teach pkg/overlay.MountWithOptions() to accept `nil` as a pointer to a
struct parameter that is otherwise optional.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-12-13 14:06:59 -05:00
Doug Rabson 4c72c25a21 pkg/overlay: add limited support for FreeBSD
Note: in theory, we could support read/write overlays on FreeBSD using a
combination of unionfs and nullfs but this would take two mounts and the
API only lets us return a single mount from MountWithOptions. Read only
mounts can be done with just nullfs and this is enough to support read
only image mounts in podman.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2023-06-29 14:54:31 +01:00
Chris Evich 46eea31588
Replace io/ioutil calls with os calls
In golang 1.19, `io/ioutil` is fully deprecated preventing Buildah from
compiling.  Replace all calls with equivalent calls from the `os`
package.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-12-06 14:29:32 -05:00
Nalin Dahyabhai bb149ea686 Use errors.Is() instead of os.Is{Not,}Exist
If errors for which os.IsExist() or os.IsNotExist() would have returned
true have been wrapped using fmt.Errorf()'s "%w" verb, os.IsExist() and
os.IsNotExist(), not having been retrofitted to use errors.Is(), will
return false.

Use errors.Is() to check if an error is an os.ErrExist or os.ErrNotExist
error instead of calling os.IsExist() or os.IsNotExist().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-26 15:36:58 -04:00
Sascha Grunert ce384684c0
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 11:41:47 +02:00
Daniel J Walsh 0986de4036
Fix codespell errors
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-05-25 05:51:47 -04:00
Giuseppe Scrivano 4d0eb18796
overlay: always honor mountProgram
if a mountProgram is specified, use it also in rootfull mode.

Closes: https://github.com/containers/buildah/issues/3281

[NO NEW TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-27 12:14:42 +01:00
Giuseppe Scrivano 5a25fc6f83
overlay: move mount program invocation to separate function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-27 11:01:55 +01:00
Giuseppe Scrivano a0d3ce33eb
overlay: move mount program lookup to separate function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-27 11:00:55 +01:00
Aditya R 316e34d268
mount: add support for custom upper and workdir with overlay mounts
Allow users to specify non-volatile `upper` and `workdir` with overlay
mounts.

Usage

```console
buildah from alpine
buildah run -v /something/lower:/test:z,O,upperdir=/somewhere/upperdir,workdir=/somwhere/workdir alpine-working-container cat /test/hello
```

Signed-off-by: Aditya R <arajan@redhat.com>
2022-01-20 21:35:34 +05:30
Aditya Rajan db6943a170
overlay: add MountWithOptions to API which extends support for advanced overlay
Expose `MountWithOptions` for overlay which allows users to pass more
verbose configuration for overlay mounts.

For instance `upperdir, workerdir` and in future `volatile`.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-01-20 14:54:02 +05:30
chenk008 03186a3307 Support overlayfs path contains colon
In linux, directory can contains colon.
Add support to mount path contains colon.

buildah run --volume /root/a\\🅱️/root/test:O

Signed-off-by: chenk008 <kongchen28@gmail.com>
2021-10-20 14:40:38 +08:00
Daniel J Walsh 4dc36e85b4
Add support for rootless overlay mounts
This patch sets the userxattr field when run in rootless mode.

Fixes: https://github.com/containers/buildah/issues/3503

Patch came from @flouthoc  Aditya Rajan <arajan@redhat.com>

[NO TESTS NEEDED] Since this can not be tested in CI/CD system yet.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-09 13:27:46 -04:00
Nalin Dahyabhai 32c68951a4 imagebuildah: handle --manifest directly
When we're told to add built images to a manifest list, manipulate the
list ourselves, so that if we're creating a list, we won't have a
partially-populated list if some of the builds fail.

This also lets us include all of the platform information (including
variant info, which we can't sniff out after the fact) that we were
given when we started building the images.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-08-17 11:05:28 -04:00
flouthoc e62df2b67a Adds GenerateStructure helper function to support rootfs-overlay.
Following function generates a permanent overlayfs struct as compared to tempdir.

[NO NEW TESTS NEEDED]

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2021-08-12 00:48:36 +05:30
Daniel J Walsh 2e1b71c3ef
Preserve ownership of lower directory when doing an overlay mount
Overlay mounts should work like volume bind mounts and preserve the
underlyng source directories permissions.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-07 07:19:18 -04:00
Daniel J Walsh 08201577e5
Remove some stuttering on returns errors
Golangs os.* functions return the name of the file/directory they
fail to use.  We should not wrap these errors with the file/directory
to use names, causes stuttering when the user sees the errors, and looks
bad having huge error messages.

Since this is just code cleanup, existing tests should handle the
changes.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-04-03 06:03:13 -04:00
Daniel J Walsh b7197a1e10
Set upperdir permissions based on source
We are setting the permissions based on the dest dir rather
then the source dir.  Since we want this to work identical to a bind
mount, we need to have the permissions align.

There is also an issue where overlays on existing mounts is blowing up.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-03 16:20:30 -05:00
Daniel J Walsh 0fcc8ff8f5
If destination does not exists, do not throw error
When using volume mounts, the destination directory will get
created if it does not exists. The current code blows up when
the destination directory did not exists.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-14 21:42:32 -05:00
Daniel J Walsh 84a261dd10
Upper directory should match mode of destination directory
When we mount over a destination directory inside of the container
we need to preserve the mode of the destination.

Needed to fix: https://github.com/containers/podman/issues/8801

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-06 14:44:38 -05:00
Valentin Rothberg efb3d21596 overlay.MountReadOnly: support RO overlay mounts
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-10-28 16:49:34 +01:00
Giuseppe Scrivano 777256bd51
overlay: use fusermount for rootless umounts
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-10-28 09:06:20 +01:00
Giuseppe Scrivano 2eb5b6f5e6
overlay: fix umount
there can be multiple overlay mounts for a container.  Each mount is
performed in a ../userdata/overlay subdirectory.

Iterate the subdirectories and attempt to unmount them.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-10-28 09:06:20 +01:00
Daniel J Walsh b2e7110255
vendor in latest containers/storage 1.18.0 and containers/common v0.7.0
This vendor moves containers/common/pkg/unshare to containers/storage/pkg/unshare

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-31 09:56:18 -04:00
Daniel J Walsh af05f5aa3c
Add codespell support
Check codespell on each PR in make validate.

Add fixes for issues found with codespell.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-01-10 12:12:30 -05:00
Daniel J Walsh 41b7852611 Rework overlay pkg for use with libpod
Podman uses the overlay mounts differently then in buildah.  Specifically the
overlay mount points can be used over and over again when starting and stopping
the container.  Since the paths are backed into the contianer config, we have
to be able to cleanout just the Upper and Merged directory rather then destroying
and recreating the overlay directories on each container start.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1822
Approved by: vrothberg
2019-12-22 12:04:13 +00:00
Daniel J Walsh 8fc5b0116f Start using containers/common
We have moved share code from buildah, podman and others into containers/common.

Specifically for this PR we are moving to use containers/common/pkg/unshare and
containers/common/pkg/cgroups.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #2010
Approved by: QiWang19
2019-12-06 14:37:27 +00:00
Giuseppe Scrivano 1ac63a264d rootless, overlay: use fuse-overlayfs
when running in rootless mode, use fuse-overlayfs for mounting the
overlay file system on the host.  Then create a bind mount inside the
container.

Closes: https://github.com/containers/buildah/issues/1741

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1743
Approved by: rhatdan
2019-07-29 23:46:00 +00:00
Sascha Grunert 6b214d2921 Add golint linter and apply fixes
This commit enabled to golint linter in golangci-lint and applies all
necessary fixes.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>

Closes: #1740
Approved by: rhatdan
2019-07-27 09:45:49 +00:00
Daniel J Walsh fa67ecb27a Cleanup Overlay Mounts content
There is a chance that buildah crashed and left overlay
content.  This patch will remove any left over content
before creating the overlay mounts.

Also the previous patch would not be able to handle multiple
overlay volume mounts.  This patch fixes this issue as well.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1625
Approved by: TomSweeneyRedHat
2019-06-05 13:47:29 +00:00
Daniel J Walsh bcc5e51a94 Add support for Overlay volumes into the container.
Overlay mounts allow buildah bud and buildah from to
specify a directory on the disk that will be mounted
as an overlay into the container, where the overlay can be written to
but when the RUN or buildah run exits, the modified files will dissapear.

The basic idea is to be able to mount cache from the disk for things like yum/dnf/apt
to be able to be used and modified in the contianer on a run command, but to be
kept fresh for each RUN.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1560
Approved by: giuseppe
2019-05-20 12:54:10 +00:00