Commit Graph

168 Commits

Author SHA1 Message Date
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
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 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 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 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
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
Aditya R 5686018e79
build: support OCI hooks for ephemeral build containers
Following PR adds support for OCI hooks attached to each of ephemeral
build contains which are created by `RUN` step invoked during `buildah
build` command.

Following PR also adds `--hooks-dir` flag to `buildah build` option
which allows end-users to specify one or more configuration directories
for OCI-hooks.

Note: Following PR migrates `pkg/hooks` from `podman` to `buildah` so
buildah could implement this feature and once merged `podman` can start
using `buildah/pkg/hooks`.

For usage see man-page and example test-case.

See: https://github.com/opencontainers/runtime-spec/blob/main/config.md#posix-platform-hooks

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-06-28 11:21:28 +05:30
Paul Holzinger ed4412b968
use resolvconf package from c/common/libnetwork
Podman and Buildah should use the same code the generate the resolv.conf
file. This mostly moved the podman code into c/common and created a
better API for it so buildah can use it as well.

[NO NEW TESTS NEEDED] All existing tests should continue to pass.

Fixes #3806

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-08 13:30:42 +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
OpenShift Merge Robot 67c2219bf1
Merge pull request #4015 from rhatdan/codespell
Fix codespell errors
2022-05-25 10:32:48 -04: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
Aditya R b3fbb59827
buildah: add support for renaming a device in rootless setups
Buildah now supports renaming devices while performing a build using
`--device <some-name>:<new-name>`. Implementation is similar to `podman`
where we prefer using `bind-mount` for devices instead of `mknod` in
`rootless` setups.

Usage
```console
buildah build -t test --device /dev/null:/test/dev/null .
```

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-05-25 13:53:37 +05:30
Aditya R 45bd47b4e3
run: allow resuing secret twice in different RUN steps
If a secret is used in a RUN step it is created on host but we had a
check which expects a secret to not exist on the host however same
secret can be remounted on another step so it can already exists on host
so remove the check since a secret can be mounted again from host in
another RUN step.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-05-17 14:53:07 +05:30
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
Paul Holzinger 8e299da770
oci spec: change special mount points for namespaces
The current logic in setupRootlessSpecChanges has quite a few problems.
First of this logic is a noop for rootful and when we have a netns.
However pid and ipc could still need special mounts.

In Podman we have already working code for this so this reuses the same
logic and adapts it to buildah.
4ba71f955a/pkg/specgen/generate/oci.go (L178)

Since there is already logic to handle these mounts in buildah we will
add it there and also handle the special rootless case there.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-08 10:50:01 +02:00
Paul Holzinger 216117c2d8
buildah: actually use containers.conf settings
Buildah ignores the container.conf settings. Commit 05d5d22dc6 tried
to fix this but I cannot see how this would have worked, there were also
no test added related to containers.conf.

The code below were we read the default just overwrites everything we
already set so the config settings are ignored.

Also there are many weird places were settings are just overwritten for
no particular reason. The namespaces code path looks like mess to me.
Namespaces are added/changed/removed in many different places and there
is no explanation why. Maybe I am just not familar enough with this code
base but I cannot really understand this. Hopefully a maintainer can
take a closer look to see if my changes are indeed correct.

Fixes containers/podman#13294

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-08 10:50:00 +02:00
Nalin Dahyabhai 7b0718950f Remove a stray `\` from .containerenv
Start .containerenv with a blank line rather than a stray backslash.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-04-04 17:29:49 -04:00
Paul Holzinger f4ebdc160f
fix hang when oci runtime fails
When the run child process exits early the parent still tries to read
from the ready pipe. Reading from the pipe should end when all writers
are closed. The problem is that the parent kept the writer open as well.
To fix the hang we just need to close the writer before we try to read
and after we gave it to the child.

To prevent closing the fd twice with defer I added a new fileCloser type
to store if the file was already closed.

This problem was noticed in the podman CI:
https://storage.googleapis.com/cirrus-ci-6707778565701632-fcae48/artifacts/containers/podman/6624611893772288/html/sys-podman-fedora-35-root-host-netavark.log.html

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-31 13:51:21 +02:00
Nalin Dahyabhai 8b0f5be4b8 run: set parent-death signals and forward SIGHUP/SIGINT/SIGTERM
Restore setting of the parent-death signal when we're running
subprocesses in Run(), so that if we get killed, the child processes
will also get killed.

While a child process is running, if we receive SIGHUP, SIGINT, or
SIGTERM, forward the signal to our child process unless it's the command
we're executing, which we SIGKILL without mercy, and finish the current
routine, which will then notice that the child process has exited and
return an error to its caller.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-03-30 13:54:38 -04:00
Giuseppe Scrivano 08613ccd6b
buildah: create WORKDIR with USER permissions
Closes: https://github.com/containers/buildah/issues/3620

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-03-30 16:23:56 +02:00
Giuseppe Scrivano 6ad9ec3912
Merge pull request from GHSA-c3g4-w6cv-6v7h
do not set the inheritable capabilities
2022-03-24 17:00:48 +01:00
Paul Holzinger 33f61f667d
network setup: increase timeout to 4 minutes
Podman waits for 4 minutes to wait for conmon/oci runtime to create the
container[1]. Since this value seems to work we should use the same one
here.

[1] b4b8b8b537/libpod/define/runtime.go (L27)

[NO NEW TESTS NEEDED]

Fixes containers/podman#13327

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-23 11:31:15 +01:00
Giuseppe Scrivano e7e55c988c
do not set the inheritable capabilities
The kernel never sets the inheritable capabilities for a process, they
are only set by userspace.  Emulate the same behavior.

Closes: CVE-2022-27651

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-03-23 09:09:39 +01: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 3fb7522dc3
run_linux: use --systemd-cgroup
when the configured cgroup manager is set to "systemd", use the
--systemd-cgroup option to the OCI runtime.  It is understood both by
crun and runc.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-02-14 16:00:17 +01:00
Nalin Dahyabhai 38f60a3114 imagebuildah.BuildDockerfiles(): create the jobs semaphore
Make sure that, if we're given neither a concurrent jobs count nor a
semaphore to use, we create a semaphore.  Otherwise, each platform in a
multi-platform build will run with maximum concurrency, which isn't the
desired default.  Our CLI always passes in a Jobs count, so it hasn't
been affected by this problem.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-01-28 09:42:35 -05:00
Paul Holzinger 08d636a28b
buildah bud --network add support for custom networks
The backend logic already supports specifying custom network names. This
only adds the support for the frontend parsing.

Fixes containers/podman#12282

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-25 21:02:43 +01:00
OpenShift Merge Robot 2189882aeb
Merge pull request #3732 from rhatdan/codespell
Run codespell on code
2022-01-21 13:23:27 -05:00
OpenShift Merge Robot b6f6306231
Merge pull request #3715 from flouthoc/overlay-extend-api
overlay, mount: add support for non-volatile `upperdir`, `workdir` for overlay volumes
2022-01-21 07:37:26 -05:00
Daniel J Walsh 1267508918
Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-21 06:59:49 -05: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
Giuseppe Scrivano e02e273820
linux: fix lookup for runtime
lookup the full runtime path instead of using its name.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-20 10:53:36 +01:00
Daniel J Walsh e94e07e383
Fix permissions on secrets directory
The permission on this directory will prevent user namespaces from using
secrets.  Should be world searchable

[NO TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-11 14:18:57 -05:00
Paul Holzinger d7ccff3edb
Fix default CNI paths
We need to use the default from containers.conf and not hardcode them in
buildah. This fixes an issue with the cni network backend since it would
try to access /etc/cni/net.d/ even as rootless user. This regression was
introduced in commit f9cff07b81.

Also hide the cni flags as we do not expect users to change this. The
recommended way is to change them in containers.conf.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-10 15:49:43 +01:00