Commit Graph

163 Commits

Author SHA1 Message Date
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 df36bb835a commit: exclude 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 filter them
out when generating a layer diff or --output data.

The exceptions will be directories that the conformance tests confirm
that BuildKit also leaves behind, though for compatibility with the
classic builder, we have to make that conditional.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-20 11:19:27 -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
Nalin Dahyabhai 9e00b6b399 Run(): always clean up options.ExternalImageMounts
Make sure that we consistently unmount the list of images that we're
told to, even in cases where we return an error before arranging to do
so in Run().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-23 11:29:28 -05: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
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
Nalin Dahyabhai a7098c776a imagebuildah: make traditional volume handling not the default
Make the traditional handling of volumes (where they're "frozen" and can
only be modified by ADD or COPY, which requires that we cache their
contents and save/restore them before/after RUN instructions) an option
that is not enabled by default.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-15 09:38:28 -04:00
Nalin Dahyabhai 5198af7d7c Add support for passing CDI specs to --device
Add support for using CDI to resolve `--device` devices for RUN
instructions during `buildah build`, `buildah from`, and `buildah run`,
as `podman run` does.

This generally requires that we stop resolving device specifications
(arguments passed to --device) earlier and deferring that until it's
time to run a process, because CDI wants to pick over those values,
modify a runtime spec to set up the ones that it knows about, and then
hand back the list of values that it doesn't know about.

We don't want to do a dry run of this during CLI processing because that
would create a window where the underlying hardware state could change,
and that could produce some hard-to-diagnose errors.

Being able to test this is going to require that we add the `--device`
flag to `buildah run` (`--security-opt` affects how we build the
container's layer, so it has to be done at `buildah from`).

The default configured devices list is pulled in by CLI flag processing
during `buildah from` and `buildah build`, so it doesn't also need to be
explicitly passed to `buildah run` or the internal Run() method.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-29 16:57:10 -04:00
Nalin Dahyabhai 14bf3db27a Update comments on some API objects
Avoid generically referring to "the container" where it can be ambiguous
that we're actually talking about the environment we set up for running
a command for a RUN instruction or Run() call.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-28 17:24:38 -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
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
guoguangwu d22a5293be chore: pkg imported more than once
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-06-27 13:35:36 +08: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
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
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
Ashley Cui 236c0bab10 Fix TODO: de-spaghettify run mounts
Code Cleanup: Buildkit run mount setup functions no longer have 13
arguments and are slightly more readable. Use structs instead.

[NO NEW TESTS NEEDED]

Signed-off-by: Ashley Cui <acui@redhat.com>
2022-06-06 17:22:39 -04:00
Aditya R a4c57068fa
buildkit: mount=type=cache support locking external cache store
A shared cache on host must support locking so other parallel/concurrent builds
will wait for current executing RUN statement to finish.

* Locks the cache store as soon as RUN is triggered.
* Locked target is added to cleanup list so it can be unlocked as soon
  as RUN step is completed.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-21 10:02:00 +05:30
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
Giuseppe Scrivano 5a999cfbd5
buildah: new global option --cgroup-manager
allow to override the cgroup manager with a global option
--cgroup-manager=MANAGER that has the same semantic as Podman.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-02-14 14:39:21 +01:00
Aditya Rajan 719b660462
buildkit: add from field to bind and cache mounts so images can be used as source
Following commit adds buildkit like support for `from` field to `--mount=type=bind`
and `--mount=type=cache` so images and stage can be used as mount source.

Usage looks like
```dockerfile
RUN --mount=type=bind,source=.,from=<your-image>,target=/path ls /path
```
and
```dockerfile
RUN --mount=type=cache,from=<your-image>,target=/path ls /path
```

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2022-01-08 16:58:38 +05:30
Ashley Cui 326edb312e Add support for env var secret sources
Run secrets can now be created from an environment variable. The
environment variable is read and is briefly stored as a file on /dev/shm
when it's being used, and the file is removed after the RUN command is
finished.

Fixes: #3524

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-10-26 13:18:00 -04:00
Aditya Rajan f0d3140e5a
build: Add support for buildkit like --mount=type=bind
Following commit adds support for using buildkit like
`--mount=type=bind` with `RUN` statements. Mounts created by `--mount`
are transient in nature and only scoped to current RUN statements.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-06 13:45:53 +05:30
Ashley Cui 3a5635f90b Implement SSH RUN mount
Allow ssh socket from host or certain ssh keys to be exposed to a
certain RUN instruction, but not any other instructions, as well as not
showing up in the final image.
This is done by spawining a new agent from buildah and mounting
the listening socket inside the run. SSH_AUTH_SOCK inside the container
will be set to the socket mountpoint. The defualt mountpoint is
/run/buildkit/ssh_agent.{i}

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-08-06 09:00:06 -04:00
Daniel J Walsh d7d078561c
Send logrus messages back to caller when building
We want Info, Warning and Debug logrus messages to be writen to the
buildah stderr. this way when podman-remote is using build, it will
get the messages back on the client side.

[NO TESTS NEEDED] Since this will be tested in Podman.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-15 03:55:05 -04:00
Ashley Cui c8002d9739 Add support for secret mounts
Add support for secrets. Secrets is a two-part flag that allows secret files to
be accessed for a certain RUN instruction, but not any other
instructions, as well as now showing up in the final image.

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-04-23 09:19:43 -04:00
Daniel J Walsh 4704e6cb3f
Eliminate the use of containers/building import in pkg subdirs
We want to shrink the size of the import when importing pkg from
buildah. This should help us shrink the size of the golang bindings
in podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-12 12:43:08 -05:00
Josh Soref c7963db369 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-21 16:47:18 -05:00
Nalin Dahyabhai bf41a3d707 Makefile: tweak the cross-compile target
What `go tool dist list` says the toolchain supports changes, so this
change removes these attempted cross-compile build targets.
* GOOS=darwin, GOARCH unspecified
* GOOS=darwin, GOARCH=386

Replace our use of slices of
github.com/opencontainers/runc/libcontainer/configs.Device structures
with a locally-defined type alias so that we can avoid importing the
package on non-Unixy systems.  The result is not going to be a very
useful binary on non-Linux systems, but it helps ensure that our
subpackages won't break compilation for other projects who consume us as
a library.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-24 12:09:48 -04:00
Daniel J Walsh 20a33e0791 Add --devices flag to bud and from
Some Dockerfiles (fuse-overlay) require additional devices to be in the
build environment.

This patch allows the user to specify additional devices.

Also I noticed that CapAdd and CapDrop was not working in buildah bud situations,
so this patch also fixes this.

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

Closes: #1820
Approved by: @TomSweeneyRedHat
2019-09-07 17:32:43 +00:00
baude 34e7eba408 allow podman to build a client for windows
the podman remote-client for windows pulls in some buildah code for
things like commit and build.  we need to perform some slight
refactoring of buildah code to accomodate that build.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #1551
Approved by: rhatdan
2019-04-26 19:16:11 +00:00
Daniel J Walsh 135542ecf0 Move Host IDMAppings code from util to unshare
This will make vendoring in pkg/unshare easier into other
packages like skopeo.

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

Closes: #1532
Approved by: TomSweeneyRedHat
2019-04-18 19:46:22 +00:00
James Cassell cd1b62a9ad auto pass http_proxy to container
- pass all proxy env vars
- --http-proxy option for bud and from
- bash_completion and docs

Signed-off-by: James Cassell <code@james.cassell.me>

Closes: #1525
Approved by: giuseppe
2019-04-17 14:33:46 +00:00
Qi Wang d43787be28 add --dns* flags to buildah bud
use --dns* flags to change /etc/resolv.conf in the container during the build.
Signed-off-by: Qi Wang <qiwan@redhat.com>

Closes: #1491
Approved by: rhatdan
2019-04-12 21:01:30 +00:00
Giuseppe Scrivano ac66d785d4 unshare: move to pkg/
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1475
Approved by: rhatdan
2019-04-05 03:04:46 +00:00
Daniel J Walsh 3d74031301 Move pkg/chrootuser from libpod to buildah.
We don't want to vendor anything from libpod into Buildah.
We want to switch this around.  Moving pkg content from libpod
to Buildah allows us to fix this.

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

Closes: #1400
Approved by: giuseppe
2019-03-26 15:45:33 +00:00
Valentin Rothberg d1c75eabb6 bump github.com/containernetworking/cni to v0.7.0-rc2
The {Add,Del}NetworkList APIs were extended with a context parameter,
which require adjustments in the code.

Fixes: #1433
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Closes: #1434
Approved by: rhatdan
2019-03-22 22:24:13 +00:00
Giuseppe Scrivano c6ae5c5a0c rootless: by default use the host network namespace
if --net is not specified, default to use the host network namespace.

It is still possible to use slirp4netns with --network container.

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

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

Closes: #1421
Approved by: rhatdan
2019-03-21 18:21:22 +00:00
Giuseppe Scrivano a986f34af5 slirp4netns: set mtu to 65520
it improves significantly the performance of the slirp4netns network:

777bdcccef (iperf3-netns---host)

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

Closes: #1404
Approved by: vrothberg
2019-03-15 08:56:49 +00:00
Giuseppe Scrivano 042a249e73
rootless: honor --net host
when running in rootless mode, do not use slirp4netns if --net host is
specified.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-12 13:48:02 +01:00
Daniel J Walsh 36605c29eb Prepend a comment to files setup in container
setup.rpm attempts to modify /etc/hosts, if it thinks
it has never been modified.  By adding a #comment to the
front of the file, it should prevent this from blowing up
the build.

Also add hostname to the /etc/hosts file linked to localhosts

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

Closes: #1313
Approved by: vrothberg
2019-03-09 14:24:50 +00:00
Daniel J Walsh e7e4122e1f Move secrets code from libpod into buildah
Starting to remove dependency on libpod from buildah.
secrets is used so that builds can access RHEL subscriptions
so this makes more sense to be in buildah then libpod.

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

Closes: #1366
Approved by: vrothberg
2019-02-26 13:34:18 +00:00
Miloslav Trmač c8727b4033 Fix a few issues found by tests/validate/gometalinter.sh
For some reason, the CI does not report any of these; on macOS
I see many more reports (including complaints about the standard
library), this only cleans up the trivial cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1365
Approved by: rhatdan
2019-02-25 10:27:46 +00:00
Nalin Dahyabhai fa8653314a run: ignore EIO when flushing at the end, avoid double log
When reading the last of the output from a child process, ignore an EIO,
since we already got the HUP indication.

Avoid double-logging errors in our I/O loop when using isolation other
than chroot (spotted by @afbjorklund).

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1273
Approved by: rhatdan
2019-01-12 12:04:54 +00:00
Anders F Björklund 5d22f3ced9 Make rootless work under no_pivot_root
Previously only done for root isolation

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>

Closes: #1261
Approved by: rhatdan
2019-01-10 13:15:42 +00:00
Daniel J Walsh 3cb835dfef Properly handle Hostname inside of RUN command
This will get buildah bud to follow docker build handling of
hostname environment variable and hostname command properly

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

Closes: #1242
Approved by: giuseppe
2018-12-19 12:24:57 +00:00
Giuseppe Scrivano 48cede4ed0 rootless: do not specify --rootless to the OCI runtime
runc has a good "auto detect" mode to find out when running in
rootless mode.  It also makes easier to plug another OCI runtime,
since --rootless is not part of the OCI specs.

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

Closes: #1145
Approved by: TomSweeneyRedHat
2018-11-08 15:57:52 +00:00
Giuseppe Scrivano 3cebe4f2c4 run: bind mount /etc/hosts and /etc/resolv.conf if not in a volume
change the logic for bind mounting /etc/hosts and /etc/resolv.conf in
the container.  Now they are not bind mounted when they are specified
as volumes, so it is still possible to have them writeable in the
container.

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

Closes: #1156
Approved by: rhatdan
2018-11-08 10:16:30 +00:00
Giuseppe Scrivano 68ee943fac rootless: use slirp4netns to setup the network namespace
If slirp4netns is available, use it to configure the network for the
rootless isolation mode.

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

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

Closes: #1156
Approved by: rhatdan
2018-11-08 10:16:30 +00:00
Nalin Dahyabhai ff57e92d44 rootless: only discard network configuration names
When changing settings for rootless containers, only discard the part of
the networking configuration that specifies which networks we want to
configure, and preserve whether or not we want to use the host's network
namespace.

If we were told to create an empty network namespace or to just attach
to another namespace, go ahead and try to do that.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1146
Approved by: rhatdan
2018-11-06 22:10:28 +00:00