Commit Graph

6503 Commits

Author SHA1 Message Date
Kir Kolyshkin 883aef789b libct/init: unify init, fix its error logic
This commit does two things:

1. Consolidate StartInitialization calling logic into Init().
2. Fix init error handling logic.

The main issues at hand are:
- the "unable to convert _LIBCONTAINER_INITPIPE" error from
  StartInitialization is never shown;
- errors from WriteSync and WriteJSON are never shown;
- the StartInit calling code is triplicated;
- using panic is questionable.

Generally, our goals are:
 - if there's any error, do our best to show it;
 - but only show each error once;
 - simplify the code, unify init implementations.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-08-04 13:00:35 -07:00
Kir Kolyshkin 789a73db22 init.go: move logger setup to StartInitialization
Currently, logrus is used from the Go part of runc init, mostly for a
few debug messages (see setns_init_linux.go and standard_init_linux.go),
and a single warning (see rootfs_linux.go).

This means logrus is part of init implementation, and thus, its setup
belongs to StartInitialization().

Move the code there. As a nice side effect, now we don't have to convert
_LIBCONTAINER_LOGPIPE twice.

Note that since this initialization is now also called from libct/int
tests, which do not set _LIBCONTAINER_LOGLEVEL, let's make
_LIBCONTAINER_LOGLEVEL optional.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-08-04 13:00:34 -07:00
Akihiro Suda 23e41ef04d Merge pull request #3960 from kolyshkin/local-ci-v2
Fix running tests under Docker/Podman and cgroup v2
2023-08-03 16:02:46 +09:00
Kir Kolyshkin f88a765460 ci: fix flaky test "update memory vs CheckBeforeUpdate"
This test fails in CI sometimes with the following error:

> `testcontainer test_update stopped' failed

Give OOM killer some time to do its job.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-08-02 23:00:46 -07:00
Kir Kolyshkin 5c6b334c88 ci: fix TestOpenat2 when no systemd is used
A few cases relied on the fact that systemd is used, and thus
/sys/fs/cgroup/user.slice is available.

Guess what, in case of "make unittest" it might not be.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-08-02 23:00:46 -07:00
Kir Kolyshkin 962019d64e ci: fix TestNilResources when systemd not available
Split the test into two -- for fs and systemd cgroup managers, and only
run the second one if systemd is available.

Prevents the following failure during `make unittest`:

> === RUN   TestNilResources
>     manager_test.go:27: systemd not running on this host, cannot use systemd cgroups manager
> --- FAIL: TestNilResources (0.22s)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-08-02 23:00:46 -07:00
Kir Kolyshkin cfc801b7ed Fix running tests under Docker/Podman and cgroup v2
For "make integration", the tests are run inside a Docker/Podman
container. Problem is, if cgroup v2 is used, the in-container
/sys/fs/cgroup/cgroup.subtree_control is empty.

The added script, used as Docker entrypoint, moves the current process
into a sub-cgroup, and then adds all controllers in top-level
cgroup.subtree_control.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-08-02 23:00:46 -07:00
Akihiro Suda f0a5e6b96f Merge pull request #3930 from cyphar/close_range
utils: use close_range(2) to close leftover file descriptors
2023-08-03 14:58:15 +09:00
Kir Kolyshkin 2da710ca2f Merge pull request #3933 from alexeldeib/ace/v2root
libct/cg/fs2: use file + anon + swap for usage
2023-08-02 22:30:13 -07:00
Kir Kolyshkin cbf8c67a5e Merge pull request #3954 from kinvolk/rata/idmap-tests
contrib/fs-idmap: Minor cleanups
2023-08-02 19:55:38 -07:00
Kir Kolyshkin 534fa8e114 Merge pull request #3956 from lifubang/fix-ModeSticky
Fix some file mode bits missing when doing mount syscall
2023-08-02 19:51:10 -07:00
lifubang 83137c6884 add a test case about missing stricky bit
Signed-off-by: lifubang <lifubang@acmcoder.com>
2023-08-03 09:04:27 +08:00
lifubang 6092a4b42d fix some file mode bits missing when doing mount syscall
Signed-off-by: lifubang <lifubang@acmcoder.com>
2023-08-03 08:44:00 +08:00
lfbzhm a73602846b Merge pull request #3957 from opencontainers/dependabot/go_modules/golang.org/x/net-0.13.0
build(deps): bump golang.org/x/net from 0.12.0 to 0.13.0
2023-08-03 08:32:00 +08:00
Rodrigo Campos 0688288876 contrib/fs-idmap: Move logic to a new function
We can't call log.Fatalf() and defer functions, as the former doesn't
call any defers. Let's just move the code to a new function and call
os.Exit() only in main, when all defer executed.

Now that all the code is one function, we only print twice to stderr. It
is simpler to just print to stderr instead of logging and having also
the timestamp we don't really want.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-08-02 15:36:01 +02:00
Rodrigo Campos 855c5a0e8b contrib/fs-idmap: Don't hardcode sleep path
Let's just rely on the lookup performed to find the sleep binary.

This didn't cause any issues as far as I know, I just saw this while
doing other cleanups.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-08-02 15:36:01 +02:00
Rodrigo Campos 882e5fe3ba contrib/fs-idmap: Check exactly 2 args are received
If more args are passed, let's just throw an error.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-08-02 15:36:01 +02:00
Rodrigo Campos 821d0018f5 contrib/fs-idmap: Remove not needed flags
We don't really need to check if AT_RECURSIVE is possible here. We just
want to check if we can idmap the src, it doesn't matter other nested
mounts.

While we are there, allow relative paths too.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-08-02 15:35:43 +02:00
Alexander Eldeib 7d2becdf2c libct/cg/fs2: use file + anon + swap for usage
This aligns v2 usage calculations more closely with v1.
Current node-level reporting for v1 vs v2 on the same
machine under similar load may differ by ~250-750Mi.

Also return usage as combined swap + memory usage, aligned
with v1 and non-root v2 cgroups.

`mem_cgroup_usage` in the kernel counts NR_FILE_PAGES
+ NR_ANON_MAPPED + `nr_swap_pages` (if swap enabled) [^0].

Using total - free results in higher "usage" numbers.
This is likely due to various types of reclaimable
memory technically counted as in use (e.g. inactive anon).

See also https://github.com/kubernetes/kubernetes/issues/118916 for more context

[^0]: https://github.com/torvalds/linux/blob/06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5/mm/memcontrol.c#L3673-L3680

Signed-off-by: Alexander Eldeib <alexeldeib@gmail.com>
2023-08-02 15:18:22 +02:00
Rodrigo Campos 99340bb0bd contrib/fs-idmap: Reap childs
This is what we should do, although in practice this probably won't be a
big issue as the parent also exits.

While we are there, instead of waiting for the child to finish, kill it
if we did everything we wanted to do.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-08-02 11:52:16 +02:00
dependabot[bot] c537cb3d59 build(deps): bump golang.org/x/net from 0.12.0 to 0.13.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.12.0 to 0.13.0.
- [Commits](https://github.com/golang/net/compare/v0.12.0...v0.13.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-08-02 04:55:22 +00:00
Aleksa Sarai 70f4e46e68 utils: use close_range(2) to close leftover file descriptors
close_range(2) is far more efficient than a readdir of /proc/self/fd and
then doing a syscall for each file descriptor.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2023-08-01 15:37:58 +10:00
Kir Kolyshkin dbe8434359 Merge pull request #3949 from kinvolk/rata/idmap-improve-errors
libct/nsenter: Show better errors for idmap mounts
2023-07-31 17:27:35 -07:00
Rodrigo Campos 57f31c68dc libct/nsenter: Show better errors for idmap mounts
While testing this with old kernel versions and kernels that don't
support idmap mounts for some of the filesystems used by a container, I
realized we can throw a more clear errors.

Let's make it clear which syscall we are using, when it is not supported
and when if the fs doesn't support idmap mounts, which path it is.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2023-07-31 13:44:37 +02:00
lfbzhm 14c7ab7f4d Merge pull request #3843 from kolyshkin/skip-proc-devices
libct/cg/sd: use systemd v240+ new MAJOR:* syntax
2023-07-30 15:46:18 +08:00
Kir Kolyshkin 701dff798d libct/cg/sd: use systemd v240+ new MAJOR:* syntax
Since systemd v240 (commit 8e8b5d2e6d91180a), one can use
/dev/{char,block}-MAJOR syntax to specify that all MAJOR:*
devices are allowed.

Use it, if available, since it's more straightforward, plus
we can skip somewhat expensive parsing of /proc/devices.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-07-29 22:41:05 +08:00
Kir Kolyshkin b15a6a3da7 Merge pull request #3805 from rpluem-vf/nodev_noexec_nosuid
Allow bind mounts of nodev,nosuid,noexec filesystems
2023-07-29 04:12:02 -07:00
Ruediger Pluem da780e4d27 Fix bind mounts of filesystems with certain options set
Currently bind mounts of filesystems with nodev, nosuid, noexec,
noatime, relatime, strictatime, nodiratime options set fail in rootless
mode if the same options are not set for the bind mount.
For ro filesystems this was resolved by #2570 by remounting again
with ro set.

Follow the same approach for nodev, nosuid, noexec, noatime, relatime,
strictatime, nodiratime but allow to revert back to the old behaviour
via the new `--no-mount-fallback` command line option.

Add a testcase to verify that bind mounts of filesystems with nodev,
nosuid, noexec, noatime options set work in rootless mode.
Add a testcase that mounts a nodev, nosuid, noexec, noatime filesystem
with a ro flag.
Add two further testcases that ensure that the above testcases would
fail if the `--no-mount-fallback` command line option is set.

* contrib/completions/bash/runc:
      Add `--no-mount-fallback` command line option for bash completion.

* create.go:
      Add `--no-mount-fallback` command line option.

* restore.go:
      Add `--no-mount-fallback` command line option.

* run.go:
      Add `--no-mount-fallback` command line option.

* libcontainer/configs/config.go:
      Add `NoMountFallback` field to the `Config` struct to store
      the command line option value.

* libcontainer/specconv/spec_linux.go:
      Add `NoMountFallback` field to the `CreateOpts` struct to store
      the command line option value and store it in the libcontainer
      config.

* utils_linux.go:
      Store the command line option value in the `CreateOpts` struct.

* libcontainer/rootfs_linux.go:
      In case that `--no-mount-fallback` is not set try to remount the
      bind filesystem again with the options nodev, nosuid, noexec,
      noatime, relatime, strictatime or nodiratime if they are set on
      the source filesystem.

* tests/integration/mounts_sshfs.bats:
      Add testcases and rework sshfs setup to allow specifying
      different mount options depending on the test case.

Signed-off-by: Ruediger Pluem <ruediger.pluem@vodafone.com>
2023-07-28 16:32:02 -07:00
Kir Kolyshkin 465cb34a4b Merge pull request #3945 from opencontainers/dependabot/go_modules/github.com/opencontainers/runtime-spec-1.1.0
build(deps): bump github.com/opencontainers/runtime-spec from 1.1.0-rc.3 to 1.1.0
2023-07-28 15:41:35 -07:00
Kir Kolyshkin cd5caa02ae Merge pull request #3946 from lifubang/forword-port-changelog-after-1.1.5
[CHANGELOG] Forword port changelog after release 1.1.5
2023-07-28 15:41:11 -07:00
lifubang 237acdd813 add some important announcements in unreleased section
Signed-off-by: lifubang <lifubang@acmcoder.com>
2023-07-23 18:48:31 +08:00
Sebastiaan van Stijn a5777e8716 Merge pull request #3947 from lifubang/followup-3939
use the length of UIDMappings/GIDMappings to check whether empty or not
2023-07-23 09:02:23 +02:00
lifubang c875ea8529 use the length of UIDMappings/GIDMappings to check whether empty or not
Signed-off-by: lifubang <lifubang@acmcoder.com>
2023-07-23 11:59:18 +08:00
lifubang d9494fc6b4 CHANGELOG: forward-port 1.1.6-1.1.8 changes
Signed-off-by: lifubang <lifubang@acmcoder.com>
2023-07-23 10:31:34 +08:00
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
dependabot[bot] 11b6c9b638 build(deps): bump github.com/opencontainers/runtime-spec
Bumps [github.com/opencontainers/runtime-spec](https://github.com/opencontainers/runtime-spec) from 1.1.0-rc.3 to 1.1.0.
- [Release notes](https://github.com/opencontainers/runtime-spec/releases)
- [Changelog](https://github.com/opencontainers/runtime-spec/blob/main/ChangeLog)
- [Commits](https://github.com/opencontainers/runtime-spec/compare/v1.1.0-rc.3...v1.1.0)

---
updated-dependencies:
- dependency-name: github.com/opencontainers/runtime-spec
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-07-22 13:03:35 +09: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