Commit Graph

129 Commits

Author SHA1 Message Date
Nalin Dahyabhai 27c40b3dbe Reap stray processes
run: after we've picked up the exit status of the "main" process that
we're running, reap anything that was reparented to us before returning.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-08-01 13:30:47 -04:00
Nalin Dahyabhai a3bea818b8 run: clean up parents of mount targets, too
When RUN requires us to create the target for a mountpoint, make note of
it and any parent directories that needed to be created, and clear them
all out if they look basically the same after the command finishes.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-20 11:19:27 -04:00
openshift-merge-bot[bot] 3ffed0fd6b
Merge pull request #6228 from nalind/ci-rootless-supplemental-groups
CI: ensure rootless groups aren't duplicates
2025-06-18 01:15:20 +00:00
Nalin Dahyabhai 3e11fea02e "root fs only mounted once" test: accept root with only the rw option
When checking /proc/self/mountinfo for a root filesystem, also match "/"
mounted with "rw" as its only mount option, as an alternative to being
mounted with "rw" and other options at the same time.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-17 12:55:55 -04:00
Nalin Dahyabhai b97fd7d686 CI: ensure rootless groups aren't duplicates
When adding an unprivileged user to run tests as, ensure that the
primary and supplemental groups are not repeated, and that at least one
supplemental group is outside of the user's subgid range.  When skipping
a test because the invoking user doesn't have any supplemental groups,
log the user's IDs.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-17 09:18:47 -04:00
Ricardo Branco ab8fc6deeb
bud,run: runc does not support keep-groups
Signed-off-by: Ricardo Branco <rbranco@suse.de>
2025-06-12 15:19:57 +02:00
Nalin Dahyabhai d53d837e0e run: handle relabeling bind mounts ourselves
Handle requested relabeling of bind mounts (i.e., the "z" and "Z" flags)
directly, instead of letting the runtime handle the relabeling.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-05-29 09:27:09 -04:00
Nalin Dahyabhai 699c84d40b chroot createPlatformContainer: use MS_REMOUNT
When setting mount propagation on the root mount before unmounting it,
use MS_REBIND, since we know it's already a bind mount, and we actually
want to affect the extant bind mount instead of creating another right
over it. Otherwise, we might as well have not bothered.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-02-19 13:29:20 -05:00
Nalin Dahyabhai 72e2bf4c69 Support the containers.conf container_name_as_hostname option
When containers.conf has the "container_name_as_hostname" option set,
use that value, with values that don't fit `[A-Za-z0-9][A-Za-z0-9.-]+`
stripped out.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-02-18 17:43:07 -05:00
Paul Holzinger 2119c8da3c
tests: remove masked /sys/dev/block check
The c/common defaults were changed to no longer mask this path[1]. As
such we need to remove it from this test.

[1] https://github.com/containers/common/pull/2278

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-24 11:45:28 +01:00
Nalin Dahyabhai 6e62bd0835 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>
2025-01-17 09:59:55 -05:00
Nalin Dahyabhai 25a3b385af 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>
2025-01-17 09:59:55 -05:00
Ed Santiago e3950407f2 tests: skip two ulimit tests
They compare buildah-bud against podman-run, which breaks if
/usr/bin/podman changes its ulimits, as happened recently
in podman PR 24335.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-11-07 08:24:26 -07:00
Paul Holzinger 5184bf1612
Add support for the new c/common pasta options
We always map 169.254.1.2 with pasta to the host now so ensure the
host.containers.internal entry is set correctly.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-06 17:05:52 +02:00
Ed Santiago 3ad0fd1ed1 CI: use local registry, part 2 of 2
Make tests pass when using a local cache registry (as triggered
by $CI_USE_REGISTRY_CACHE being non-empty).

Mostly just change images: consolidate to a smaller set, like,
replace the few instances of debian with ubuntu, use $SAFEIMAGE
where we can.

The most significant change was with some s1 (schema 1?) images.
Those exist on quay, but cannot be mirrored locally: the local
registry forbids schema 1 images. I choose to skip these tests
when running against a local registry.

Second most significant change is running containerized tests
with --net=host. We need this to access the registry running
on a localhost port. (One alternative would be to bind the
registry on all interfaces, cringe, then perform sed magic
on the registries-cache.conf file changing 127.0.0.1 to
host.containers.internal, more cringe).

Also, some cleanup.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-07-17 12:26:49 -06:00
Ed Santiago 7602e9e1d6 CI VMs: bump, to debian with cgroups v2
Per consent in 2024-03-20 Planning, remove support for cgroups v1.
And, per discovery on 2024-05-28, systemd 256 no longer even
boots on a cgroups v1 system.

This commit switches to VMs built in:

  https://github.com/containers/automation_images/pull/338

...in which Debian is now cgroups v2 with crun.

Requires disabling two conformance tests which fail when run
against docker 26.1; see #5526 for context on those.

Also requires disabling two bats tests on debian because
something changed there in ulimits. I'll look into them
later but right now this gives us breathing space.

And, latest git on f40 refuses to serve non-root files when
run as root ("dubious ownership"); so, in start_git_daemon(),
chown the extracted files.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-05-29 10:04:49 -06:00
Nalin Dahyabhai c7f0881422 Integration tests: use cached images more
Attempt to make more thorough use of cached copies of images during
integration tests, except in tests which need to pull a new image while
they're running, either because they test pulling directly, or because
they expect to pull a given image for a non-default platform or for
multiple platforms.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-18 11:27:02 -04:00
Paul Holzinger 516f9e9a24
correctly configure /etc/hosts and resolv.conf when using network
Previously buildah may have created a incorrect hosts/resolv.conf file,
when netavark, slirp4netns or pasta are used we have to actually
consider their special setup and use the correct nameservers.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-18 14:38:01 +01:00
Paul Holzinger d50122aeb2
tests: enable pasta tests
This should have been done a long time ago and this would have made
clear that it did not work properly. However now that pasta is the
default and we fixed all the remaining problems we can easily enable
them.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-12 11:53:06 +01:00
Daniel J Walsh 63975b5418
Properly handle build --pull=false
buildah build --pull=false is documented to never pull the image, but it
is currently ignored.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-26 16:42:14 -05:00
openshift-merge-bot[bot] 20ae380912
Merge pull request #5275 from rhatdan/ulimit
Make buildah match podman for handling of ulimits
2024-02-05 09:08:37 +00:00
Giuseppe Scrivano 9d516e22e3
imagebuildah: fix crash with empty RUN
fix a crash when RUN is executed without any argument.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-01 17:14:33 +01:00
Daniel J Walsh 79fb3c2135
Make buildah match podman for handling of ulimits
Podman currently sets the ulimits of nofile and nproc
to max in rootless mode, if the user does not override.

Buildah on the other hand just passes in the current defaults.

Podman build should match podman run, and this will fix that problem.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-01-31 15:28:51 -05:00
Nalin Dahyabhai 1f9103562b run.bats: use --quiet --pull=false when using a prefetched image
When creating a container using a prefetched image, use --quiet and
--pull=false for the pair of tests which didn't, bringing them in line
with the rest of the tests in the file.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-28 16:43:44 -05:00
Daniel J Walsh 3b96b1cafb
Use mask definitions from containers/common
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-10-27 13:10:18 -04:00
Daniel J Walsh 48a9c43718
Add --no-hostname option to buildah containers
Fixes: https://github.com/containers/buildah/issues/5093

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-10-24 19:43:56 -04:00
Paul Holzinger a8f350fc51
rootless: use default_rootless_network_cmd config
Use the `default_rootless_network_cmd` containers.conf options to know
which rootless network program to use as default. This setting is
important so distros and user can actually set a different default if
they wish.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-28 15:20:39 +02:00
Paul Holzinger 74b885b9e2
buildah: add pasta(1) support
Like podman allow buildah and therefore podman build to use the network
mode pasta. The pasta integration is very simple and we do not even
need a teardown handler for that as pasta will exit on its own when the
netns path is removed.

However right now this is broken, pasta will fail to open
/proc/$pid/ns/net. I send a patch[1] to fix this upstream in pasta.
I assume this will land quickly so I like to get this in now just so we
have this included in podman v4.6. Thus the test is skipped for now.

[1] https://archives.passt.top/passt-dev/20230623082531.25947-2-pholzing@redhat.com/

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-23 13:58:34 +02:00
Paul Holzinger 11ba328e2b
use slirp4netns package from c/common
This uses the same code as podman for slirp4netns, this means
- ipv6 is enabled by default
- slirp4netns options are read from contianers.conf
- slirp4netns options can now be set on the cli. This required some
small rework on where we parse the network string.

Lastly I updated the --network docs, to document the new slirp4netns
mode. That included fixing up buildah-from and buildah-run pages which
were incomplete in that regard. Now we show the same for all options.

Fixes #3968

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-23 13:57:30 +02:00
Paul Holzinger 14cd28c262
add hostname to /etc/hosts when running with host network
Some tools depend on the hostname being present in /etc/hosts. I would
argue they are broken but its not like we can do anything about that.

This adds the hostname with the local host ip when the host network is
used. For private networking we already add the hostname.

We also now correctly force host networking in chroot mode, it was
silently ignored before thus causing extra confusion here.

Fixes #4446

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-20 16:12:28 +02:00
Chris Bandy 2ad68d816f run: pass process environment variables by reference
See: https://github.com/containers/buildah/issues/4688
Signed-off-by: Chris Bandy <bandy.chris@gmail.com>
2023-04-02 18:19:37 -05:00
Giuseppe Scrivano 8e84bb7097
run_linux: Update heuristic for mounting /sys
change the heuristic to mount a fresh sysfs every time a new network
namespace is created.  This modification ensures the creation of the
sysfs when the network namespace is created, which is better than
sharing the one from the host.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2164524

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-03-23 23:21:39 +01:00
Giuseppe Scrivano c0f6c6b7ad
[Itests: change the runtime-flag test for crun
crun might not print any debugging message, so change the runtime-flag
test to use --log=log-file and test it was created.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-01-17 17:37:53 +01:00
Ed Santiago a75b263f75 system tests: remove unhelpful assertions
Regular primitive bats uses assertions like '[ $foo = something ]'.
These are worthless for debugging: when they fail, all you know
is that foo is not "something" but you don't know what foo _is_.

Find and replace those assertions with 'assert', which is
more informative. Instances found via:

   $ ack '^ *\[' tests/*.bats

There are many matches for 'test' (instead of '[') but those
mostly look like file-existence ones, which are less evil
than string-check tests. I'm leaving those be for now.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2023-01-05 08:20:25 -07: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
Aditya R 4c9fc47f0a
run,build: conflict --isolation=chroot and --network
Conflict --isolation=chroot and --network, since internally --chroot
will always configure network ns equivalent to host.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-21 12:27:44 +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
Nalin Dahyabhai 8bbeed70ff integration tests: quote "?" in shell scripts
When passing the value ? to a shell function as an argument, don't
forget to quote it, so that it doesn't get expanded as a filename
pattern by the shell.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-08-01 17:15:33 -04:00
Ed Santiago 552d09b272 Rename $TESTSDIR (the plural one), step 4 of 3
...rename $TESTDIR (the singular one) to $TEST_SCRATCH_DIR,
which is clearer but unfortunately longer

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-04-26 09:11:22 -06:00
Ed Santiago e347e88e02 Rename $TESTSDIR (the plural one), step 3 of 3
...rename all remaining instances to $TEST_SOURCES

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-04-26 09:11:19 -06:00
Ed Santiago f3e13380fb Rename $TESTSDIR (the plural one), step 2 of 3
...refactor $TESTSDIR/bud as $BUDFILES

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-04-26 09:11:14 -06:00
Ed Santiago 267f309911 Rename $TESTSDIR (the plural one), step 1 of 3
...refactor '--signature-policy .../policy.json' to $WITH_POLICY_JSON

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-04-26 09:11:05 -06:00
OpenShift Merge Robot d93a4eb313
Merge pull request #3917 from Luap99/hosts
use etchosts package from c/common
2022-04-21 15:01:12 -04:00
Paul Holzinger 5de32ade7c
use etchosts package from c/common
Use the new etchosts package to generate the hosts file.
This will ensure that we use the same logic in podman and buildah.

New features are:
- no duplicated entries
- adds entries for the network/slirp4netns ips
- configure the host.containers.internal entry in containers.conf
- configure the base hosts file in containers.conf

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-21 18:05:30 +02:00
Aditya R c147bb2b9a
run: set actual hostname in /etc/hostname to match docker parity
Following commit ensure the buildah run populates /etc/hostname with
actual hostname instead of `localhost`. This matches parity with docker.

See discussion here: https://github.com/containers/buildah/issues/3914
Closes: https://github.com/containers/buildah/issues/3914

Signed-off-by: Aditya R <arajan@redhat.com>
2022-04-21 19:13:52 +05:30
Giuseppe Scrivano a6f6a41a73
test: skip rootless on cgroupv2 in root env
the test needs to run as rootless, skip it when running in a root
environment.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-04-01 15:28:58 +02:00
Nalin Dahyabhai 90b3254c74 Add a test for CVE-2022-27651
Check that the inheritable capabilities are set to 0, even when we
explicitly try to add capabilities.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-03-24 16:34:43 -04:00
Daniel J Walsh deb9c69efe
Add --no-hosts flag to eliminate use of /etc/hosts within containers
Users want to turn off addition of /etc/hosts file while building
container images, this would allow them to customize the /etc/hosts
file within the image.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-03-10 08:52:28 -05:00
Aditya R 0b8c6ca49f
test: remove skips for rootless users
Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-09 21:36:04 +05:30
Aditya R d27b883709
tests: skip tests for rootless which need unshare
Instrument test so that they can be executed in rootless environment.

Certain tests perform mount directly and they need a seperate
usernamespace, these tests are marked to be skipped for `rootless
environment`

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-08 15:08:03 +05:30