Commit Graph

133 Commits

Author SHA1 Message Date
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
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
Daniel J Walsh 1c67aad88f
Use config.ProxyEnv from containers/common
This table is being used in multiple different places, so consolidating
it in containers/common

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-07 14:31:16 -05:00
Paul Holzinger f9cff07b81
use libnetwork from c/common for networking
Podman uses the new netavark network stack. Buildah should be able to do
the same. Both projects should use the same networking code which was
move to c/common/libnetwork. The new network interface can use either
CNI or netvavark. Using the same code for podman and buildah is
important to ensure that both use the same backend. Mixing CNI and
netavark is not supported.

This also fixes some outstanding CNI issues, e.g. buildah trying to
connect all cni networks.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-07 18:10:26 +01:00
Paul Holzinger 5e11770c19
setup the netns in the buildah parent process
Do not configure the netns in the runtime child process, this removes
the need to send the network options to the child. This will be needed
for the new libnetwork network interface which cannot be transfered as
json.

To synchronize this between the child and parent we use two pipe pairs.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-07 15:05:08 +01:00
Daniel J Walsh 300d9d1de1
Allow rootless buildah to set resource limits on cgroup V2
First move podman/pkg/cgroups into Buildah.
Only set resources to nil on non cgroupsv2 systems in rootless mode.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-12-14 12:36:03 -05:00
Daniel J Walsh 05d5d22dc6
Grab all of the containers.conf settings for namespaces.
Buildah is mainly building with Host Namespaces, this changes most
namespaces to be private matching Podman and using containers.conf

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-30 10:24:00 -05:00
Daniel J Walsh 1d74137908
Make LocalIP public function so Podman can use it
[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-22 10:00:50 -05:00
Nalin Dahyabhai 9b6a02f3af run: ensure that stdio pipes are labeled correctly
Label stdio pipes to ensure that processes we run can read through
/dev/stdin and write through the /dev/stdout and /dev/stderr links.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-11-19 10:55:50 -05:00
Giuseppe Scrivano b798e6a21a
rootless: do not bind mount /sys if not needed
if the container is using a private network namespace, we can mount a
fresh /sys.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-04 14:34:21 +01:00
OpenShift Merge Robot ecd74746cc
Merge pull request #3598 from ashley-cui/envs
Add support for env var secret sources
2021-10-31 09:58:44 +00:00
Aditya Rajan 37377e6827
run: honor --network=none from builder if nothing specified
This commit makes sure we honor NetworkDisabled in `runs` if
`--network=none` was specified while building the container and no
configuration was specified in while running the container.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-27 14:50:11 +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
OpenShift Merge Robot d6b04349fe
Merge pull request #3593 from rhatdan/group
Rootless containers users should use additional groups
2021-10-21 17:45:42 +00:00
Daniel J Walsh 08b55f91cc
Rootless containers users should use additional groups
Fixes https://github.com/containers/buildah/issues/3592

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-20 14:22:42 -04:00
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
OpenShift Merge Robot e4a4f2c0d4
Merge pull request #3586 from rhatdan/docs
Add support for host.containers.internal in the /etc/hosts
2021-10-15 01:08:56 +02:00
Daniel J Walsh f8c152694c
Add support for host.containers.internal in the /etc/hosts
Also switch default hostname from truncated ContainerID to Container
name.

It makes more sense that a user would know the name of the container
versus the generated id, so we should use this as a default.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-14 13:21:25 -04:00
Aditya Rajan fc69aa68c2
buildkit: add support for mount=type=cache
Following PR inroduces a new mount type=cache in parity to buildkit
which allows users to share persistant cache between different builds.

Allowing users to cache content generated by bussiness logic or enhance
build performance by caching components across builds.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-14 16:07:11 +05:30
Ashley Cui b9b3184632 Default secret mode to 400
Fixed a bug where buildah bud mounted secrets permissions were incorrect due to a decimal/octal conversion error. buildah bud mounted secrets now have a default permission of 400. Fixes #3557

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-10-12 16:00:23 -04:00
Aditya Rajan e96df7060c
buildkit: Add support for --mount=type=tmpfs
Following PR adds supports for buildkit like `--mount=type=tmpfs` which
allows end users to mount a chunk of volatile memory instead of a persistent storage device.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-08 13:29:57 +05:30
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
OpenShift Merge Robot bc718ca758
Merge pull request #3540 from rhatdan/log-level
Plumb the remote logger throughut Buildah
2021-09-30 03:52:31 -04:00
OpenShift Merge Robot 455f2f11d9
Merge pull request #3525 from flouthoc/cleanup-run-directory-after-step
build: Cleanup transient mount destinations with every RUN step
2021-09-28 17:18:26 -04:00
Daniel J Walsh 00ba17b37a
Plumb the remote logger throughut Buildah
Users are not seeing Warnings when doing podman --remote build.
We need to wire the logrus messages all the way through the system.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-28 14:48:16 -04:00
Nalin Dahyabhai c6e2a5e87d Replace fmt.Sprintf("%d", x) with strconv.Itoa(x)
Replace calls to fmt.Sprintf("%d", x) with strconv.Itoa(x), which is
slightly faster.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-09-27 18:27:22 -04:00
Aditya Rajan 4cb43961b8
Run: Cleanup run directory after every RUN step
Following commit ensures that we cleanup dangling `/run` after every RUN
command and make sure that it does not persists on physical image. Ensure
parity with how docker behaves with `.dockerenv`.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-09-27 19:59:20 +05:30
Nalin Dahyabhai a314d2a6ca Makefile: turn on race detection whenever it's available
Check if `go test` supports the -race flag on the build platform, and if
so, use it for unit tests instead of just assuming that it's always
available.

Use sync/atomic to safely use a uint32 instead of a bool to keep track
of whether or not the process we started for RUN has stopped.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-09-16 14:19:19 -04:00
Nalin Dahyabhai 1ec4983d50 Replace golang.org/x/crypto/ssh/terminal with golang.org/x/term
The golang.org/x/crypto/ssh/terminal package has been deprecated and
replaced upstream by golang.org/x/term, so switch to that.  It's a
simple 1:1 replacement.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-08-24 15:35:12 -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
openshift-ci[bot] c6908de514
Merge pull request #3424 from Luap99/resolv
Fix resolv.conf content with run --net=private
2021-08-10 17:29:29 +00:00
openshift-ci[bot] 88f55c8f15
Merge pull request #3409 from ashley-cui/sshagent
Implement SSH RUN mount
2021-08-06 22:35:40 +00:00
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
Paul Holzinger f90481d03a
Fix resolv.conf content with run --net=private
Make sure to use the correct resolv.conf in case of systemd-resolved.
Also filter out 127... nameserver when run in private netns.

Fixes #2780

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-08-06 12:32:43 +02:00
Valentin Rothberg 078efc2197 run: fix nil deref using the option's logger
[NO TESTS NEEDED] since I've no idea how to force it.

Reported-in: containers/podman/issues/11148
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-06 11:13:01 +02:00
Daniel J Walsh bb738d4406
Allow dst and destination for target in secret mounts
Fixes: https://github.com/containers/buildah/issues/3396

Patch from @mixedCase

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-07-22 14:47:22 -04:00