Commit Graph

5707 Commits

Author SHA1 Message Date
Mrunal Patel fac268b4ff Merge pull request #3252 from AkihiroSuda/fix-libcontainer-integration-compilation-failure
fix `libcontainer/integration/exec_test.go:1859:8: undefined: ioutil`
2021-10-29 09:45:34 -07:00
Akihiro Suda 95f8ecdd53 fix libcontainer/integration/exec_test.go:1859:8: undefined: ioutil
Fix 4d17654479

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-10-28 14:56:03 +09:00
Akihiro Suda 4d17654479 Merge pull request #2576 from kinvolk/alban/userns-2484-take2
Open bind mount sources from the host userns
2021-10-28 14:50:33 +09:00
Mrunal Patel af16f56a17 Merge pull request #3242 from opencontainers/dependabot/go_modules/github.com/cilium/ebpf-0.7.0
build(deps): bump github.com/cilium/ebpf from 0.6.2 to 0.7.0
2021-10-18 13:56:44 -07:00
Mrunal Patel 0bbd7bd7e4 Merge pull request #3231 from najohnsn/no-linux-section
fix createDevices when no Linux section
2021-10-18 13:53:35 -07:00
Mrunal Patel d5c9905be8 Merge pull request #3235 from kolyshkin/rm-exc-lock
libct: Init: remove LockOSThread
2021-10-18 13:52:26 -07:00
dependabot[bot] dc473cad80 build(deps): bump github.com/cilium/ebpf from 0.6.2 to 0.7.0
Bumps [github.com/cilium/ebpf](https://github.com/cilium/ebpf) from 0.6.2 to 0.7.0.
- [Release notes](https://github.com/cilium/ebpf/releases)
- [Commits](https://github.com/cilium/ebpf/compare/v0.6.2...v0.7.0)

---
updated-dependencies:
- dependency-name: github.com/cilium/ebpf
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-18 17:50:42 +00:00
Sebastiaan van Stijn 6d35069b5e Merge pull request #3245 from kolyshkin/go116
Drop Go 1.15 support
2021-10-17 21:14:33 +02:00
Mauricio Vásquez 8542322dfe libcontainer: Add unit tests with userns and mounts
Add a unit test to check that bind mounts that have a part of its
path non accessible by others still work when using user namespaces.

To do this, we also modify newRoot() to return rootfs directories that
can be traverse by others, so the rootfs created works for all test
(either running in a userns or not).

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
Co-authored-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-10-16 17:29:33 +02:00
Akihiro Suda d8a3446acd Merge pull request #3002 from iholder-redhat/feature/TestingSkipFinalCheckPublic
Make DevicesGroup's "TestingSkipFinalCheck" attribute public
2021-10-16 16:15:32 +09:00
Kir Kolyshkin 5516294172 Remove io/ioutil use
See https://golang.org/doc/go1.16#ioutil

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-14 13:46:02 -07:00
Kir Kolyshkin 6a4f4a6a37 libcontainer/ignoreTerminateErrors: simplify for Go 1.16+
One less TODO in the code, yay!

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-14 13:46:02 -07:00
Kir Kolyshkin 12e99a0f8d Require Go >= 1.16
Go 1.15 is not supported since Go 1.17 release (16 Aug 2021), and some
packages that we use already require Go 1.16+ (notably,
github.com/cilium/ebpf v0.7.0).

Let's require Go 1.16+.

Remove Go version requirement from README when describing dependencies,
since it is no longer needed:

	$ GO=go1.15.15 make vendor
	go1.15.15 mod tidy
	go mod tidy: go.mod file indicates go 1.16, but maximum supported version is 1.15
	make: *** [Makefile:141: vendor] Error 1

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-14 13:46:02 -07:00
Kir Kolyshkin 3d98676626 ci/gha: install latest stable Go version
Jobs verify/compile-buildtags and verify/deps relied on whatever Go
version is available from the Ubuntu-20.04 image, which seems to be
1.15.x).

Job test/cross-i386 was installing whatever Go version is considered to
be the default one by actions/setup-go@v2, which seems to be go 1.15.15
at the moment.

Fix all three jobs to install Go 1.x (which should translate to latest
stable Go version, i.e. 1.17.2 as of now).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-14 13:46:02 -07:00
Akihiro Suda 97875b0abf Merge pull request #3246 from kolyshkin/fix-ci
ci: temporarily disable criu repo gpg check
2021-10-15 05:14:05 +09:00
Kir Kolyshkin c5ca778fa8 ci: temporarily disable criu repo gpg check
This unblocks our CI, which is broken by the repo's expired signing key.

Stolen-from: https://github.com/moby/moby/pull/42935
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-14 12:50:17 -07:00
Rodrigo Campos 81fdc8ce1c New integration tests for user namespaces bind sources
The previous commit fixed an issue opening bind mount sources. This
commit just adds integration tests to make sure we don't regress on this
in the future.

Signed-off-by: Alban Crequy <alban@kinvolk.io>
Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
Co-authored-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-10-12 15:13:45 +02:00
Alban Crequy 9c444070ec Open bind mount sources from the host userns
The source of the bind mount might not be accessible in a different user
namespace because a component of the source path might not be traversed
under the users and groups mapped inside the user namespace. This caused
errors such as the following:

  # time="2020-06-22T13:48:26Z" level=error msg="container_linux.go:367:
  starting container process caused: process_linux.go:459:
  container init caused: rootfs_linux.go:58:
  mounting \"/tmp/busyboxtest/source-inaccessible/dir\"
  to rootfs at \"/tmp/inaccessible\" caused:
  stat /tmp/busyboxtest/source-inaccessible/dir: permission denied"

To solve this problem, this patch performs the following:

1. in nsexec.c, it opens the source path in the host userns (so we have
   the right permissions to open it) but in the container mntns (so the
   kernel cross mntns mount check let us mount it later:
   https://github.com/torvalds/linux/blob/v5.8/fs/namespace.c#L2312).

2. in nsexec.c, it passes the file descriptors of the source to the
   child process with SCM_RIGHTS.

3. In runc-init in Golang, it finishes the mounts while inside the
   userns even without access to the some components of the source
   paths.

Passing the fds with SCM_RIGHTS is necessary because once the child
process is in the container mntns, it is already in the container userns
so it cannot temporarily join the host mntns.

This patch uses the existing mechanism with _LIBCONTAINER_* environment
variables to pass the file descriptors from runc to runc init.

This patch uses the existing mechanism with the Netlink-style bootstrap
to pass information about the list of source mounts to nsexec.c.

Rootless containers don't use this bind mount sources fdpassing
mechanism because we can't setns() to the target mntns in a rootless
container (we don't have the privileges when we are in the host userns).

This patch takes care of using O_CLOEXEC on mount fds, and close them
early.

Fixes: #2484.

Signed-off-by: Alban Crequy <alban@kinvolk.io>
Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
Co-authored-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-10-12 15:13:45 +02:00
Akihiro Suda 2357eab8ca Merge pull request #3233 from kolyshkin/hugepage-fix
libct/cg/fs2: fix GetStats for unsupported hugetlb
2021-10-12 12:20:51 +09:00
Akihiro Suda a5a45c731d Merge pull request #3239 from kolyshkin/rdt-path
libct/intelrdt: add Root()
2021-10-11 13:08:06 +09:00
Sebastiaan van Stijn b098f33caf Merge pull request #3238 from kolyshkin/wrap-exec-err
libct/system: Exec: wrap the error
2021-10-08 21:18:39 +02:00
Kir Kolyshkin a80e1217d2 libct/intelrdt: add Root()
Export getIntelRdtRoot function as Root.

This is needed by google/cadvisor, which is (ab)using GetIntelRdtPath,
removed by commit 7296dc1712.

While at it, do some minimal refactoring to always use Root()
internally, not relying on variable value. Other than that it's just
some renaming.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-07 20:23:21 -07:00
Kir Kolyshkin 794cd66df8 libct/system: Exec: wrap the error
If the container binary to be run is removed in between runc create
and runc start, the latter spits the following error:

> can't exec user process: no such file or directory

This is a bit confusing since we don't see what file is missing.

Wrap the unix.Exec error into os.PathError, like in many other cases,
to provide some context. Remove the error wrapping from
(*linuxStandardInit).Init as it is now redundant.

With this patch, the error is now:

> exec /bin/false: no such file or directory

Reported-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-07 11:09:08 -07:00
Aleksa Sarai 3a5223d010 merge branch 'pr-3236'
dependabot[bot] (1):
  build(deps): bump github.com/opencontainers/selinux from 1.8.5 to 1.9.1

LGTMs: AkihiroSuda cyphar
2021-10-07 17:37:33 +11:00
dependabot[bot] 6eba68deae build(deps): bump github.com/opencontainers/selinux from 1.8.5 to 1.9.1
Bumps [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) from 1.8.5 to 1.9.1.
- [Release notes](https://github.com/opencontainers/selinux/releases)
- [Commits](https://github.com/opencontainers/selinux/compare/v1.8.5...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/opencontainers/selinux
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-07 04:21:41 +00:00
Kir Kolyshkin f594edee21 Merge pull request #3059 from kolyshkin/cgroup-clean
runc exec --cgroup
2021-10-06 18:02:46 -07:00
Kir Kolyshkin e395d2dc50 libct: Init: remove LockOSThread
This call is already made in init.go, no need for a duplicate.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-05 19:19:40 -07:00
Kir Kolyshkin 916c6a1539 libct/cg/fs2: fix GetStats for unsupported hugetlb
In case hugetlb is not supported, GetStats() should not error out,
and yet it does.

Assume that if GetHugePageSize return an error, hugetlb is
not supported (this is what cgroup v1 manager do).

Fixes: 89a87adb
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-05 16:48:15 -07:00
Kir Kolyshkin c670691ee8 Merge pull request #3226 from chenk008/fix_delete_cgroupv2
Remove sub cgroup when container exits
2021-10-05 14:06:25 -07:00
Itamar Holder f9667e633b Make DevicesGroup's "TestingSkipFinalCheck" attribute public
Users would like to have the possibility to skip checks for their
tests the same way they are skipped within the tests in runc.

Not exposing this variable makes it very hard to test components
that use this library. To avoid copying-and-pasting the code
into outside projects this variable sould be exposed to the users.

Signed-off-by: Itamar Holder <iholder@redhat.com>
2021-10-05 17:36:39 +03:00
Sebastiaan van Stijn 8e7ab26104 Merge pull request #3230 from kolyshkin/release-arch-followup
Dockerfile: fix for seccomp
2021-10-05 10:06:24 +02:00
Neil Johnson 2e0ceaa935 fix createDevices when no Linux section
Signed-off-by: Neil Johnson <najohnsn@us.ibm.com>
2021-10-04 17:37:19 -04:00
Kir Kolyshkin fae5d8b568 release: add s390x
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-01 10:25:30 -07:00
Kir Kolyshkin f95063ede4 Dockerfile: fix for seccomp
Commit f30244ee1b broke the scenario of using Dockefile for
anything but making a release. This happened because it installed
native libseccomp build to a temporary directory, and so linking against
libseccomp required setting a few environment variables.

Let's fix this, and simplify libseccomp installation. Instead of using
temporary directories, let's install native libseccomp to a specified
directory, all the cross-builds to its subdirectories, and set
PKG_CONFIG_PATH and LD_LIBRARY_PATH in Dockerfile so that the built
library will found by pkg-config and the dynamic linker (without setting
LD_LIBRARY_PATH, ld picks up distro-provided libseccomp.so).

While at it, fix some bugs introduced by the abovementioned commit.

This fixes building runc in  make targets like shell, dbuild,
integration, unittest -- i.e. those that depend on runcimage.

Fixes: f30244ee1b
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-01 10:20:56 -07:00
Kang Chen 7758d3fb02 libct/cg/sd/v2: Destroy: remove cgroups recursively
Currently, we can create subcgroup in a rootless container with systemd cgroupv2 on centos8.
But after the container exited, the container cgroup and its subcgroup will not be removed.

Fix this by removing all directories recursively.

Fixes: https://github.com/opencontainers/runc/issues/3225

Signed-off-by: Kang Chen <kongchen28@gmail.com>
2021-10-01 22:07:02 +08:00
Aleksa Sarai d1c9b43e94 merge branch 'pr-3228'
Kir Kolyshkin (1):
  contrib: rm init from bash completion

LGTMs: AkihiroSuda cyphar
Closes #3228
2021-09-28 15:06:33 +10:00
Kir Kolyshkin 580e43ec25 contrib: rm init from bash completion
Commit 7a0302f0d7 already removed "runc init" from runc help output,
as this is an internal option not supposed to be used by the end user.

Let's remove runc init completion, too.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-27 16:54:38 -07:00
Kir Kolyshkin 0202c398ff runc exec: implement --cgroup
In some setups, multiple cgroups are used inside a container,
and sometime there is a need to execute a process in a particular
sub-cgroup (in case of cgroup v1, for a particular controller).
This is what this commit implements.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-27 10:25:42 -07:00
Mauricio Vásquez cc15b887a0 tests: add integration test for cgroups hybrid
Check that runc run and runc exec put the process on the same cgroups v2
when using hybrid mode.

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-27 10:25:12 -07:00
Mauricio Vásquez a8435007d9 cgroups: join cgroup v2 when using hybrid mode
Currently the parent process of the container is moved to the right
cgroup v2 tree when systemd is using a hybrid model (last line with 0::):

$ runc --systemd-cgroup run myid
/ # cat /proc/self/cgroup
12:cpuset:/system.slice/runc-myid.scope
11:blkio:/system.slice/runc-myid.scope
10:devices:/system.slice/runc-myid.scope
9:hugetlb:/system.slice/runc-myid.scope
8:memory:/system.slice/runc-myid.scope
7:rdma:/
6:perf_event:/system.slice/runc-myid.scope
5:net_cls,net_prio:/system.slice/runc-myid.scope
4:freezer:/system.slice/runc-myid.scope
3:pids:/system.slice/runc-myid.scope
2:cpu,cpuacct:/system.slice/runc-myid.scope
1:name=systemd:/system.slice/runc-myid.scope
0::/system.slice/runc-myid.scope

However, if a second process is executed in the same container, it is
not moved to the right cgroup v2 tree:

$ runc exec myid /bin/sh -c 'cat /proc/self/cgroup'
12:cpuset:/system.slice/runc-myid.scope
11:blkio:/system.slice/runc-myid.scope
10:devices:/system.slice/runc-myid.scope
9:hugetlb:/system.slice/runc-myid.scope
8:memory:/system.slice/runc-myid.scope
7:rdma:/
6:perf_event:/system.slice/runc-myid.scope
5:net_cls,net_prio:/system.slice/runc-myid.scope
4:freezer:/system.slice/runc-myid.scope
3:pids:/system.slice/runc-myid.scope
2:cpu,cpuacct:/system.slice/runc-myid.scope
1:name=systemd:/system.slice/runc-myid.scope
0::/user.slice/user-1000.slice/session-8.scope

This commit makes that processes executed with exec are placed into the
right cgroup v2 tree. The implementation checks if systemd is using a
hybrid mode (by checking if cgroups v2 is mounted in
/sys/fs/cgroup/unified), if yes, the path of the cgroup v2 slice for
this container is saved into the cgroup path list.

The fs group driver has a similar issue, in this case none of the runc
run or runc exec commands put the process in the right cgroups v2. This
commit also fixes that.

Having the processes of the container in its own cgroup v2 is useful
for any BPF programs that rely on bpf_get_current_cgroup_id(), like
https://github.com/kinvolk/inspektor-gadget/ for instance.

[@kolyshkin: rebased]

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 19:29:11 -07:00
Kir Kolyshkin 39914db679 runc exec: don't skip non-existing cgroups
The function used here, cgroups.EnterPid, silently skips non-existing
paths, and it does not look like a good idea to do so for an existing
container with already configured cgroups.

Switch to cgroups.WriteCgroupProc which does not do that, so in case
a cgroup does not exist, we'll get an error.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 19:26:57 -07:00
Kir Kolyshkin 7d446c63d0 libct/cg.WriteCgroupProcs: improve errors
No need to add a file name to the error messages, as errors from
OpenFile and (*os.File).Write both contain the file name already.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 19:26:57 -07:00
Kir Kolyshkin cc1d746643 exec.go: nit
No need to have an intermediate variable here.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 19:26:57 -07:00
Aleksa Sarai e999e29a28 merge branch 'pr-3222'
Kir Kolyshkin (5):
  ci/gha: test criu-dev with latest go
  ci/gha: remove debug info
  CI/GHA: switch to OBS criu repo
  Dockerfile: fix apt-key warning
  Dockerfile: use Debian_11 repo for criu

LGTMs: mrunalp cyphar
2021-09-24 11:05:57 +10:00
Mrunal Patel b1b0e7f8d9 Merge pull request #3216 from kolyshkin/manager-new
cgroup: make paths available, simplify getting manager
2021-09-23 14:44:13 -07:00
Kir Kolyshkin 0d297b7190 ci/gha: test criu-dev with latest go
As commits 120f74060 and a58718013 were added independently,
criu-dev go version was left at 1.16.x. Fix this.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 12:58:26 -07:00
Kir Kolyshkin 16aedc3130 ci/gha: remove debug info
This was supposed to be added temporarily, but slipped into the final
commit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 12:58:26 -07:00
Kir Kolyshkin 3fd1851ce9 CI/GHA: switch to OBS criu repo
This will bring criu 3.16, which is available from OBS but not (yet?) PPA.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 12:58:21 -07:00
Kir Kolyshkin 81dc559993 Dockerfile: fix apt-key warning
This fixes

> Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

Apparently, "the internets" disagree with the above, instead suggesting
using /usr/share/keyrings and a signed-by= declaration in sources.list.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 12:20:11 -07:00
Kir Kolyshkin 2bf560fbd7 Dockerfile: use Debian_11 repo for criu
The Debian_11 was not available in this repo at the time when commit 24d318b8b
was made, so we had to use Debian_10 URL for Debian 11 (apparently without any
consequences).

Now Debian_11 is available, so let's switch to it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 11:23:18 -07:00