Commit Graph

6468 Commits

Author SHA1 Message Date
Aleksa Sarai b4f38918a4 merge #3861 into opencontainers/runc:main
Akihiro Suda (1):
  features: graduate from experimental

LGTMs: kolyshkin cyphar
Closes #3861
2023-07-22 19:38:45 +10:00
Kir Kolyshkin 74895d4552 Merge pull request #3939 from eiffel-fl/francis/caps-naming
Renaming *Mappings fields and use int* for mountEntry.fd
2023-07-21 09:13:41 -07:00
Francis Laniel a3785c88ec Remove idmapFD field for mountEntry
We cannot have both srcFD and idMapFD set at the same time.
So, we can simplify this struct to only have one field which is used a srcFD
most of the time and as idMapFD when we do an id map mount.

Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
2023-07-21 13:55:34 +02:00
Francis Laniel 46ada59ba2 Use an *int for srcFD
Previously to this commit, we used a string for srcFD as /proc/self/fd/NN.
This commit modified to this behavior, so srcFD is only an *int and the full path
is constructed in mountViaFDs() if srcFD is different than nil.

Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
2023-07-21 13:55:34 +02:00
Francis Laniel c47f58c4e9 Capitalize [UG]idMappings as [UG]IDMappings
Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
2023-07-21 13:55:34 +02:00
lfbzhm b338accc78 Merge pull request #3826 from kolyshkin/ps-rootless
tests/int/ps: enable for rootless
2023-07-17 23:39:32 +08:00
Kir Kolyshkin f92057aa1e tests/int: update set_cgroups_path doc
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-07-17 23:16:55 +08:00
Kir Kolyshkin 19f76b66c1 tests/int/ps: enable for rootless
runc ps requires cgroup, but all the tests but one required root. Let's
fix this.

1. Add rootless cgroup requirement to setup() to avoid repetition.

2. Add set_cgroups_path to setup() for rootless containers because
   there is no default cgroup path.

3. Modify output checks to use $output rather than $lines because in case
   of rootless the first line of output contains the following warning:

> runc ps may fail if you don't have the full access to cgroups

4. While at it, move the common part of every test (creating the
   container and making sure it's running) to setup().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-07-17 23:16:55 +08:00
Akihiro Suda c99e6c6c5d Merge pull request #3750 from kinvolk/rata/idmap-merged
docs: Update spec conformance for idmap mounts
2023-07-17 23:49:20 +09:00
Rodrigo Campos 867ee90534 docs: Update spec conformance for idmap mounts
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-17 16:29:07 +02:00
lfbzhm f73b05dee6 Merge pull request #3717 from kinvolk/rata/idmap
Support idmap mounts for volumes
2023-07-17 21:55:50 +08:00
Rodrigo Campos b460dc39b7 tests/integration: Add tests for idmap mounts
Co-authored-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-17 13:30:12 +02:00
Rodrigo Campos fda12ab101 Support idmap mounts on volumes
This commit adds support for idmap mounts as specified in the runtime-spec.

We open the idmap source paths and call mount_setattr() in runc PARENT,
as we need privileges in the init userns for that, and then sends the
fds to the child process. For this fd passing we use the same mechanism
used in other parts of thecode, the _LIBCONTAINER_ env vars.

The mount is finished (unix.MoveMount) from go code, inside the userns,
so we reuse all the prepareBindMount() security checks and the remount
logic for some flags too.

This commit only supports idmap mounts when userns are used AND the mappings
are the same specified for the userns mapping. This limitation is to
simplify the initial implementation, as all our users so far only need
this, and we can avoid sending over netlink the mappings, creating a
userns with this custom mapping, etc. Future PRs will remove this
limitation.

Co-authored-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-17 13:30:12 +02:00
lfbzhm 4338e972fe Merge pull request #3919 from kolyshkin/golint153
ci: bump golangci-lint to v1.53, remove fixed exception
2023-07-16 18:26:26 +08:00
Kir Kolyshkin 98317c16ed ci: bump golangci-lint, remove fixed exception
The exception was fixed by https://github.com/polyfloyd/go-errorlint/pull/12
which eventually made its way into golangci-lint.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-07-16 15:02:26 +08:00
lfbzhm caa6e523f2 Merge pull request #3900 from kolyshkin/psi
libct/cg/stats: support PSI for cgroup v2
2023-07-14 09:06:31 +08:00
Rodrigo Campos fe4528b176 libcontainer: Just print the mountFds slice len on errors
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos 73b649705a libcontainer: Add mountFds struct
We will need to pass more slices of fds to these functions in future
patches. Let's add a struct that just contains them all, instead of
adding lot of parameters to these functions.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos 0172016a53 libcontainer: Add generic parseFdsFromEnv()
We will add code that uses this function in future patches. So let's
just split it to a new function now and reuse it later.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos f5814a1007 libcontainer: Add generic sendFdsSources()
Let's move the code to send mount sources to a generic function. Future
patches will use it for idmap sources too.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos 96bd487590 nsenter: Add idmap helpers
We add idmap.h with the needed includes and defines in case the system
headers don't have the definition for the idmap syscalls we need.

Future patches will use these helpers.

Co-authored-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos 5166164ded nsexec: Add generic receive_sources()
Future patches will use this with another env var.

Co-authored-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos 4b668a8224 Switch setupUserNamespace() to use the toConfigIDMap() helper
We just added this helper for other parts of the code, let's switch this
function to use the helper too.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Rodrigo Campos fbf183c6f8 Add uid and gid mappings to mounts
Co-authored-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-11 16:17:48 +02:00
Akihiro Suda 05669c8aba Merge pull request #3929 from opencontainers/dependabot/go_modules/github.com/cilium/ebpf-0.11.0
build(deps): bump github.com/cilium/ebpf from 0.10.0 to 0.11.0
2023-07-11 10:55:12 +08:00
dependabot[bot] 83418f8878 build(deps): bump github.com/cilium/ebpf from 0.10.0 to 0.11.0
Bumps [github.com/cilium/ebpf](https://github.com/cilium/ebpf) from 0.10.0 to 0.11.0.
- [Release notes](https://github.com/cilium/ebpf/releases)
- [Commits](https://github.com/cilium/ebpf/compare/v0.10.0...v0.11.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>
2023-07-11 01:40:04 +00:00
Akihiro Suda 3e2c42abe2 Merge pull request #3928 from opencontainers/dependabot/go_modules/golang.org/x/net-0.12.0
build(deps): bump golang.org/x/net from 0.11.0 to 0.12.0
2023-07-11 09:39:19 +08:00
dependabot[bot] 2c844977d4 build(deps): bump golang.org/x/net from 0.11.0 to 0.12.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.11.0 to 0.12.0.
- [Commits](https://github.com/golang/net/compare/v0.11.0...v0.12.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-08 23:14:46 +08:00
Rodrigo Campos 881e92a3fd libct/validator: Error out on non-abs paths
This was a warning already and it was requested to make this an error
while we will add validation of idmap mounts:
	https://github.com/opencontainers/runc/pull/3717#discussion_r1154705318

I've also tested a k8s cluster and the config.json generated by
containerd didn't use any relative paths. I tested one pod, so it was
definitely not an extensive test.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-07 12:00:33 +02:00
Aleksa Sarai 628256245e merge pr #3924 into opencontainers/runc:main
Kir Kolyshkin (1):
  MAINTAINERS: add Li Fu Bang

LGTMs: kolyshkin AkihiroSuda cyphar hqhq mrunalp crosbymichael
Vote: +6 -0 *2
Closes #3924
2023-07-07 10:18:55 +10:00
Akihiro Suda a1d47f0171 Merge pull request #3927 from opencontainers/dependabot/go_modules/golang.org/x/sys-0.10.0
build(deps): bump golang.org/x/sys from 0.9.0 to 0.10.0
2023-07-06 22:41:10 +08:00
Mrunal Patel 369ad5a503 Merge pull request #3888 from kolyshkin/reset-failed
runc delete: call systemd's reset-failed
2023-07-06 00:09:25 -04:00
dependabot[bot] 45c75ac7ed build(deps): bump golang.org/x/sys from 0.9.0 to 0.10.0
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.9.0 to 0.10.0.
- [Commits](https://github.com/golang/sys/compare/v0.9.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-05 04:35:31 +00:00
Aleksa Sarai 35eff7cdb2 merge pr #3599 into opencontainers/runc:main
Cory Snider (5):
  libct/nsenter: namespace the bindfd shuffle
  libct/nsenter: set FD_CLOEXEC on received fd
  libct/nsenter: refactor ipc funcs for reusability
  libct/nsenter: annotate write_log() prototype
  chore(libct/nsenter): extract utility code

LGTMs: AkihiroSuda kolyshkin cyphar
Closes #3599
2023-07-04 19:49:47 +10:00
Cory Snider 017d6996c0 libct/nsenter: namespace the bindfd shuffle
Processes can watch /proc/self/mounts or /mountinfo, and the kernel
will notify them whenever the namespace's mount table is modified. The
notified process still needs to read and parse the mountinfo to
determine what changed once notified. Many such processes, including
udisksd and SystemD < v248, make no attempt to rate-limit their
mountinfo notifications. This tends to not be a problem on many systems,
where mount tables are small and mounting and unmounting is uncommon.
Every runC exec which successfully uses the try_bindfd container-escape
mitigation performs two mount()s and one umount() in the host's mount
namespace, causing any mount-watching processes to wake up and parse the
mountinfo file three times in a row. Consequently, using 'exec' health
checks on containers has a larger-than-expected impact on system load
when such mount-watching daemons are running. Furthermore, the size of
the mount table in the host's mount namespace tends to be proportional
to the number of OCI containers as a unique mount is required for the
rootfs of each container. Therefore, on systems with mount-watching
processes, the system load increases *quadratically* with the number of
running containers which use health checks!

Prevent runC from incidentally modifying the host's mount namespace for
container-escape mitigations by setting up the mitigation in a temporary
mount namespace.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-07-04 17:56:25 +10:00
Cory Snider 3b191ff710 libct/nsenter: set FD_CLOEXEC on received fd
Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-07-04 17:56:25 +10:00
Cory Snider 8f67178139 libct/nsenter: refactor ipc funcs for reusability
Modify receive_fd() and send_fd() so they can be more readily reused in
cloned_binary.c. Change receive_fd() to have a single responsibility:
receiving and returning a single file descriptor over a UNIX domain
socket. Make send_fd() useable in precarious execution contexts such as
a clone(CLONE_VFORK|CLONE_VM) "thread" where allocating heap memory or
calling exit() would be dangerous.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-07-04 17:56:25 +10:00
Cory Snider 890dceeebf libct/nsenter: annotate write_log() prototype
...so the compiler can warn about mismatches between the format string
and varargs.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-07-04 17:56:25 +10:00
Cory Snider 35fddfd28f chore(libct/nsenter): extract utility code
...from nsexec.c so they can be used in cloned_binary.c.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-07-04 17:56:25 +10:00
Kir Kolyshkin 37732d1e7d MAINTAINERS: add Li Fu Bang
I am nominating @lifubang for the role of runc maintainer.

He provided a number of valuable contributions to runc, and demonstrated
both deep technical expertise and the long term commitment to the
project.

As noted in MAINTAINERS_GUIDE.md, we have a week to vote, and need to
get 66% of current maintainers' votes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-30 10:50:49 -07:00
Kir Kolyshkin 164e4bc5f6 Merge pull request #3915 from opencontainers/dependabot/go_modules/google.golang.org/protobuf-1.31.0
build(deps): bump google.golang.org/protobuf from 1.30.0 to 1.31.0
2023-06-28 09:54:16 -07:00
Kir Kolyshkin ad040b1caf tests/int/delete: make sure runc delete removes failed unit
The passing run (with the fix) looks like this:

----
delete.bats
 ✓ runc delete removes failed systemd unit [4556]
   runc spec (status=0):

   runc run -d --console-socket /tmp/bats-run-B08vu1/runc.lbQwU5/tty/sock test-failed-unit (status=0):

   Warning: The unit file, source configuration file or drop-ins of runc-cgroups-integration-test-12869.scope changed on disk. Run 'systemctl daemon-reload' to reload units.
   × runc-cgroups-integration-test-12869.scope - libcontainer container integration-test-12869
        Loaded: loaded (/run/systemd/transient/runc-cgroups-integration-test-12869.scope; transient)
     Transient: yes
       Drop-In: /run/systemd/transient/runc-cgroups-integration-test-12869.scope.d
                └─50-DevicePolicy.conf, 50-DeviceAllow.conf
        Active: failed (Result: timeout) since Tue 2023-06-13 14:41:38 PDT; 751ms ago
      Duration: 2.144s
           CPU: 8ms

   Jun 13 14:41:34 kir-rhat systemd[1]: Started runc-cgroups-integration-test-12869.scope - libcontainer container integration-test-12869.
   Jun 13 14:41:37 kir-rhat systemd[1]: runc-cgroups-integration-test-12869.scope: Scope reached runtime time limit. Stopping.
   Jun 13 14:41:38 kir-rhat systemd[1]: runc-cgroups-integration-test-12869.scope: Stopping timed out. Killing.
   Jun 13 14:41:38 kir-rhat systemd[1]: runc-cgroups-integration-test-12869.scope: Killing process 1107438 (sleep) with signal SIGKILL.
   Jun 13 14:41:38 kir-rhat systemd[1]: runc-cgroups-integration-test-12869.scope: Failed with result 'timeout'.
   runc delete test-failed-unit (status=0):

   Unit runc-cgroups-integration-test-12869.scope could not be found.
----

Before the fix, the test was failing like this:

----
delete.bats
 ✗ runc delete removes failed systemd unit
   (in test file tests/integration/delete.bats, line 194)
     `run -4 systemctl status "$SD_UNIT_NAME"' failed, expected exit code 4, got 3
  ....
----

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-28 09:28:35 -07:00
Kir Kolyshkin 58a811f6aa tests/int: add/use "requires systemd_vNNN"
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-28 09:28:35 -07:00
Kir Kolyshkin 43564a7b55 runc delete: call systemd's reset-failed
runc delete is supposed to remove all the container's artefacts.
In case systemd cgroup driver is used, and the systemd unit has failed
(e.g. oom-killed), systemd won't remove the unit (that is, unless the
"CollectMode: inactive-or-failed" property is set).

Call reset-failed from manager.Destroy so the failed unit will be
removed during "runc delete".

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-28 09:28:35 -07:00
Kir Kolyshkin 91b4cd25b7 libct/cg/sd: remove logging from resetFailedUnit
Sometimes we call resetFailedUnit as a cleanup measure, and we don't
care if it fails or not. So, move error reporting to its callers, and
ignore error in cases we don't really expect it to succeed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-28 09:28:35 -07:00
Kir Kolyshkin dacb3aaa0d tests/int/cgroups: remove useless/wrong setting
There is no such thing as linux.resources.memorySwap (the mem+swap is
set as linux.resources.memory.swap).

As it is not used in this test anyway, remove it.

Fixes: 4929c05ad1
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-28 09:28:35 -07:00
Sebastiaan van Stijn e42446f7c6 Merge pull request #3912 from cpuguy83/fix_tmpfs_mode
Fix tmpfs mode opts when dir already exists
2023-06-28 16:15:28 +02:00
Sebastiaan van Stijn f9bd4a5a2f Merge pull request #3827 from kolyshkin/no-panic
libct/cg: IsCgroup2UnifiedMode: don't panic
2023-06-28 15:29:46 +02:00
Sebastiaan van Stijn 17b335a2ee Merge pull request #3902 from kolyshkin/skip-less
ci/gha: don't skip rootless+systemd on ubuntu 22.04
2023-06-28 15:28:08 +02:00
Sebastiaan van Stijn 651c044a2b Merge pull request #3889 from kolyshkin/shellcheck-0.9
ci: bump shellcheck to 0.9.0, fix new SC2016 warnings
2023-06-28 15:26:43 +02:00