Commit Graph

44 Commits

Author SHA1 Message Date
Nalin Dahyabhai d580388018
Fix TOCTOU error when bind and cache mounts use "src" values
Fix a time-of-check/time-of-use error when mounting type=bind and
type=cache directories that use a "src" flag.  A hostile writer could
use a concurrently-running stage or build to replace that "src" location
between the point when we had resolved possible symbolic links and when
runc/crun/whatever actually went to create the bind mount
(CVE-2024-11218).

Stop ignoring the "src" option for cache mounts when there's no "from"
option.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: Vivek Naruka <vnaruka@redhat.com>
Signed-off-by: Chris Evich <cevich@redhat.com>
2025-02-06 09:55:38 -05:00
Nalin Dahyabhai 432cf3cf6b
internal/volume.GetBindMount(): discard writes in bind mounts
When handling RUN --mount=type=bind, where the mount is read-write,
instead of a simple bind mount, create an overlay mount with an upper
directory that will be discarded after the overlay mount is unmounted.
This brings us in line with the expected behavior, wherein writes to
bind mounts should be discarded.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: Vivek Naruka <vnaruka@redhat.com>
2025-02-06 09:52:24 -05:00
Aditya R 9fced965ee
build, secret: allow realtive mountpoints wrt to work dir
When working with `--mount=type=secret` allow `target`/`dst` to accept relative paths w.r.t to the configured work dir.

See detailed use-case here: https://github.com/containers/buildah/issues/4491

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

**Steps to reproduce the issue from #4491:**

1. Create Dockerfile and Makefile:

Dockerfile:
```
FROM docker.io/ubuntu:22.04

WORKDIR /somedir

RUN --mount=type=secret,id=secret-foo,dst=secret1.txt --mount=type=secret,id=secret-bar,dst=secret2.txt \
     printf "PWD=%s\n" "$(pwd)" && ls -la && ls -la / && stat secret1.txt && stat secret2.txt && \
     cp secret1.txt /root/secret-foo.txt && \
     cp secret2.txt /root/secret-bar.txt
```

Makefile:
```
DOCKER ?= docker

.PHONY: build-container

build-container:
	rm -rf build
	mkdir build
	echo "secret:foo" >build/secret1.txt
	echo "secret:bar" >build/secret2.txt
	buildah --no-cache --secret id=secret-foo,src=build/secret1.txt --secret id=secret-bar,src=build/secret2.txt -t defanator/example:tag1 .
	podman run --rm -t -i defanator/example:tag1 cat /root/secret-foo.txt
	podman run --rm -t -i defanator/example:tag1 cat /root/secret-bar.txt
	podman rmi defanator/example:tag1
```
```
make
```

Signed-off-by: Aditya R <arajan@redhat.com>
2023-01-09 23:34:55 +05:30
Daniel J Walsh f8eb73820a
Merge pull request #4452 from flouthoc/relative-mount
build, mount: allow realtive mountpoints wrt to work dir for `--mount=type=cache` and `--mount=type=bind`
2023-01-03 08:33:18 -05:00
Daniel J Walsh 60be7f2509
Add support for --group-add to buildah from
Allow containers running under buildah to use
--group-add keep-groups, so that they can inherit
access to the users groups.

Also allow users to add supplimental groups to the container.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-12-22 11:53:00 -05:00
Paul Holzinger 67c2e4de59
buildah: wrap network setup errors
User may get confusing error messages were it is not clear that they are
related to the network setup, wrap the error to make it more clear that
some network setup failed.

[NO NEW TESTS NEEDED]

Fixes containers/podman#16809

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-12-15 17:29:48 +01:00
Aditya R d9578d32cd
build, mount: allow realtive mountpoints wrt to work dir
When working with `--mount=type=bind` and `--mount=type=cache` allow
`target` to accept relative paths w.r.t to the configured work dir.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-12-15 16:30:34 +05:30
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
Miloslav Trmač a1698cde60 Update c/storage after https://github.com/containers/storage/pull/1436
... and update to remove the now-deprecated Locker interface.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-12-01 15:39:25 +01:00
Doug Rabson 646c282901 Use TypeBind consistently to name bind/nullfs mounts
This allows declaring run mounts using e.g. '-mount=type=nullfs,...' on
FreeBSD which makes more sense for FreeBSD users. It is also consistent
with 'podman run' which requires the nullfs mount type on FreeBSD.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-11-07 17:19:56 +00:00
Miloslav Trmač 8356687157 Ensure the cache volume locks are unlocked on all paths
... and use a more traditional error handling model,
where responsibility for the cleanup passes to the caller
_only_ if the called function succeeds.

To reinforce that, hard-code nil returns on error paths
instead of returning the locks.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-20 00:14:18 +02:00
Miloslav Trmač 60382209e3 Simplify the interface of GetCacheMount and getCacheMount
It can return at most one lock, so don't return an array.

Should not change behavior right now, but it will simplify
cleanup.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-19 23:23:34 +02:00
Miloslav Trmač bdd62ef870 Remove calls to Lockfile.Locked()
By construction it's now quite clear that the locks should
always be locked.

Don't even bother with AssertLockedForWriting(), that's
partially (checking for lock ownership, not for read-write ownership)
implied by Unlock() already.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-19 23:23:34 +02:00
Miloslav Trmač cfa10d16c9 Maintain cache mount locks as lock objects instead of paths
They exist in memory anyway, so this is more efficient:
we avoid the need to manually touch the filesystem again,
the associated costs - and the error paths go away.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-19 23:23:33 +02:00
Aditya R 6838cbc812
run: honor lockfiles for multiple --mount instruction
Single `RUN` can contain multiple `--mount` commands so lets append into
`lockedTargets` so we collect `lockfiles` from all the `--mount`
instructions.

Helps in: https://github.com/containers/buildah/issues/4342

Signed-off-by: Aditya R <arajan@redhat.com>
2022-10-19 14:27:07 +05:30
Daniel J Walsh 8d5d763213
Fix stutters
Podman adds an Error: to every error message. So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

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

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-19 07:11:44 -04:00
Aditya R ac30ed23d6
parse: make processing flags in --mount order agnostic
Flags processing in `--mount` must not be hardcode to expect first field to
be `type` instead it should be order agnostic.

Closes: https://github.com/containers/podman/issues/15748

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-14 12:37:09 +05:30
Aditya R 9934b17365
run: add container gid to additional groups
When container is created with specific uid and gid also add container
gid to supplementary/additional group.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-08-24 20:10:14 +05:30
openshift-ci[bot] a9fd30516c
Merge pull request #4169 from dfr/freebsd-stdio
Don't try to call runLabelStdioPipes if spec.Linux is not set
2022-08-08 05:49:46 +00:00
Doug Rabson fb6da9916a Don't try to call runLabelStdioPipes if spec.Linux is not set
On FreeBSD, the Linux section of the spec is not populated. FreeBSD does
have a similar labelling facility in its MAC framework but that would be
better managed via a future addition of a FreeBSD section to the runtime
spec rather than trying to make it look like Linux.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-08-05 09:35:59 +01: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
Nalin Dahyabhai 0ded0dca23 Fix a copy/paste error message
When we fail to create the pipe we're using to signal a start, don't
complain about failing to create the creation pipe.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-26 11:05:01 -04:00
Nalin Dahyabhai 62954c89c0 Set user namespace defaults correctly for the library
Set the default for user namespaces correctly for callers that don't use
our CLI, e.g. OpenShift or our own tutorials.  When we don't do that,
commands invoked through RUN instructions can see weird things, in this
case an empty /sys/fs/cgroup directory.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-22 09:38:56 -04:00
Doug Rabson ad389b1943 Rename footypes to fooTypes for naming consistency
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson cdac8e1ba9 Move cleanupTempVolumes and cleanupRunMounts to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson 4b7c61d5da Make the various run mounts work for FreeBSD
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson 57a73847e4 Move get{Bind,Tmpfs,Secret,SSH}Mount to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson 0832ea2f35 Move runSetupRunMounts to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson 9c808c76ac Move cleanableDestinationListFromMounts to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson c21f4bd2f4 Make setupMounts and runSetupBuiltinVolumes work on FreeBSD
This involves handling the fact that FreeBSD containers don't have a
Linux section in the spec and that mounting filesystem directories is
done with nullfs rather than bind.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson cf079d017a Move setupMounts and runSetupBuiltinVolumes to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:22 +01:00
Doug Rabson 95a18737a6 Move runAcceptTerminal to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson 1ab567151a Move stdio copying utilities to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson ba5ff64d1c Move runUsingRuntime and runCollectOutput to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson b290c86172 Move fileCloser, waitForSync and contains to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson bff1c193a3 Move checkAndOverrideIsolationOptions to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson 75ae804029 Move DefaultNamespaceOptions to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson acdf4777aa Move getNetworkInterface to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson 8e36f5fc9c Move configureEnvironment to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson f68f109234 Don't crash in configureUIDGID if Process.Capabilities is nil
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson 7ea97716d7 Move configureUIDGID to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson a405d62cb4 Move runLookupPath to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson 4d9a035e78 Move setupTerminal to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00
Doug Rabson 420107991b Move etc file generation utilities to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-12 09:14:21 +01:00