Commit Graph

6385 Commits

Author SHA1 Message Date
Kir Kolyshkin f8ad20f500 runc kill: drop -a option
As of previous commit, this is implied in a particular scenario. In
fact, this is the one and only scenario that justifies the use of -a.

Drop the option from the documentation. For backward compatibility, do
recognize it, and retain the feature of ignoring the "container is
stopped" error when set.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-08 09:30:40 -07:00
Kir Kolyshkin 9583b3d1c2 libct: move killing logic to container.Signal
By default, the container has its own PID namespace, and killing (with
SIGKILL) its init process from the parent PID namespace also kills all
the other processes.

Obviously, it does not work that way when the container is sharing its
PID namespace with the host or another container, since init is no
longer special (it's not PID 1). In this case, killing container's init
will result in a bunch of other processes left running (and thus the
inability to remove the cgroup).

The solution to the above problem is killing all the container
processes, not just init.

The problem with the current implementation is, the killing logic is
implemented in libcontainer's initProcess.wait, and thus only available
to libcontainer users, but not the runc kill command (which uses
nonChildProcess.kill and does not use wait at all). So, some workarounds
exist:
 - func destroy(c *Container) calls signalAllProcesses;
 - runc kill implements -a flag.

This code became very tangled over time. Let's simplify things by moving
the killing all processes from initProcess.wait to container.Signal,
and documents the new behavior.

In essence, this also makes `runc kill` to automatically kill all container
processes when the container does not have its own PID namespace.
Document that as well.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-08 09:29:25 -07:00
Kir Kolyshkin 2a7dcbbb40 libct: fix shared pidns detection
When someone is using libcontainer to start and kill containers from a
long lived process (i.e. the same process creates and removes the
container), initProcess.wait method is used, which has a kludge to work
around killing containers that do not have their own PID namespace.

The code that checks for own PID namespace is not entirely correct.
To be exact, it does not set sharePidns flag when the host/caller PID
namespace is implicitly used. As a result, the above mentioned kludge
does not work.

Fix the issue, add a test case (which fails without the fix).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-08 09:23:29 -07:00
Kir Kolyshkin 5b8f8712a4 libct: signalAllProcesses: remove child reaping
There are two very distinct usage scenarios for signalAllProcesses:

* when used from the runc binary ("runc kill" command), the processes
  that it kills are not the children of "runc kill", and so calling
  wait(2) on each process is totally useless, as it will return ECHLD;

* when used from a program that have created the container (such as
  libcontainer/integration test suite), that program can and should call
  wait(2), not the signalling code.

So, the child reaping code is totally useless in the first case, and
should be implemented by the program using libcontainer in the second
case. I was not able to track down how this code was added, my best
guess is it happened when this code was part of dockerd, which did not
have a proper child reaper implemented at that time.

Remove it, and add a proper documentation piece.

Change the integration test accordingly.

PS the first attempt to disable the child reaping code in
signalAllProcesses was made in commit bb912eb00c, which used a
questionable heuristic to figure out whether wait(2) should be called.
This heuristic worked for a particular use case, but is not correct in
general.

While at it:
 - simplify signalAllProcesses to use unix.Kill;
 - document (container).Signal.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-08 09:23:29 -07:00
Kir Kolyshkin e0e8d9c886 tests/int/kill: add kill -a with host pidns test
This is roughly the same as TestPIDHostInitProcessWait in libct/int,
except that here we use separate processes to create and to kill a
container, so the processes inside a container are not children of "runc kill", and
also we hit different codepaths (nonChildProcess.signal rather than
initProcess.signal).

One other thing is, rootless is also tested.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-08 09:23:29 -07:00
Kir Kolyshkin 67bc4bc240 tests/rootless.sh: drop set -x
It seems that set -x was temporarily added as a debug measure, but
slipped into the final commit.

Remove it, for the sake of test logs brevity.

Fixes: 9f656dbb11
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-08 09:23:29 -07:00
Kir Kolyshkin f075e26bdb Merge pull request #3874 from kolyshkin/fix-cs9-oom
tests/int: increase num retries for oom tests
2023-06-07 17:20:45 -07:00
Kir Kolyshkin 9c6b9131e6 Merge pull request #3887 from kolyshkin/manman
man/runc: fixes
2023-06-07 14:39:16 -07:00
Kir Kolyshkin fed0b12436 tests/int: increase num retries for oom tests
This test is occasionally failing on CS9.

The test case always takes about 7 seconds on my laptop (decreasing
memory, using a different memory eater in shell etc. doesn't help).

Increase the number of iterations from 10 to 30 to make sure we don't
see any flakes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-07 11:30:07 -07:00
Kir Kolyshkin 511c76143b man/runc: fixes
1. Fix some missing punctuation, use proper case.

2. Remove "runc init" (previously removed from "runc --help" by commit
   7a0302f0d7).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-07 11:23:59 -07:00
Kir Kolyshkin df57f74f87 Merge pull request #3880 from kolyshkin/fix-vagrant-cache
Fix Vagrant caching
2023-06-06 14:32:27 -07:00
Kir Kolyshkin bb4dbbc4f5 ci/cirrus: limit numcpu
... so we can run all four jobs in parallel.

While at it, fix the comment in the file.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-05 17:24:59 -07:00
Kir Kolyshkin 650efb2c22 Fix Vagrant caching
As of today, vagrant stopped working, my best guess is due to bad
caching. Here's an excerpt from logs:

...
vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Building native extensions. This could take a while...
Installed the plugin 'vagrant-libvirt (0.12.1)'!
...
uname -s ; cat Vagrantfile.$DISTRO
Linux
...

Downloaded 481Mb in 4.096201s.
Cache hit for vagrant-8be35383dc00f23d080ff00b2a724c938d650254861f26b67624c28e3fe5e6ae!
...
Vagrant failed to initialize at a very early stage:
The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory.
...
Error message given during initialization: Unable to resolve dependency:
user requested 'vagrant-libvirt (= 0.12.0)'
...

The problem is, vagrant cache overwrites newer plugin with an older one.

Let's only cache the downloaded image.

Also, change the cache fingerprint script (remove "Linux").

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-23 11:21:54 -07:00
Kir Kolyshkin ba58ee9c3b Merge pull request #3873 from opencontainers/dependabot/go_modules/github.com/sirupsen/logrus-1.9.2
build(deps): bump github.com/sirupsen/logrus from 1.9.0 to 1.9.2
2023-05-18 12:03:08 -07:00
dependabot[bot] b9d2d8d8a6 build(deps): bump github.com/sirupsen/logrus from 1.9.0 to 1.9.2
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.9.0 to 1.9.2.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.9.0...v1.9.2)

---
updated-dependencies:
- dependency-name: github.com/sirupsen/logrus
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-18 05:00:24 +00:00
Mrunal Patel a2b60cf268 Merge pull request #3854 from kolyshkin/refff
Some init code refactoring
2023-05-17 14:50:00 -07:00
Kir Kolyshkin 7e481ee2eb libct/int: remove logger from init
Currently, TestInit sets up logrus, and init uses it to log an error
from StartInitialization(). This is solely used by TestExecInError
to check that error returned from StartInitialization is the one it
expects.

Note that the very same error is communicated to the runc init parent
and is ultimately returned by container.Run(), so checking what
StartInitialization returned is redundant.

Remove logrus setup and use from TestMain/init.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-17 12:46:27 -07:00
Kir Kolyshkin eba31a7c6c libct/StartInitialization: rename returned error
This is a cosmetic change to improve code readability, making it easier
to distinguish between a local error and the error being returned.

While at it, rename e to err (it was originally called e to not clash
with returned error named err) and ee to err2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-17 12:46:27 -07:00
Kir Kolyshkin 4f0a7e78c3 libct/init: call Init from containerInit
Instead of having newContainerInit return an interface, and let its
caller call Init(), it is easier to call Init directly.

Do that, and rename newContainerInit to containerInit.

I think it makes the code more readable and straightforward.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-17 12:46:27 -07:00
Kir Kolyshkin 72657eac2e libct: move StartInitialization
No code change, just moving a function from factory_linux.go to
init_linux.go.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-17 12:46:27 -07:00
Kir Kolyshkin 8cbf64055a Merge pull request #3871 from opencontainers/dependabot/github_actions/tim-actions/get-pr-commits-1.3.0
build(deps): bump tim-actions/get-pr-commits from 1.2.0 to 1.3.0
2023-05-17 12:44:52 -07:00
dependabot[bot] 2a3470456e build(deps): bump tim-actions/get-pr-commits from 1.2.0 to 1.3.0
Bumps [tim-actions/get-pr-commits](https://github.com/tim-actions/get-pr-commits) from 1.2.0 to 1.3.0.
- [Release notes](https://github.com/tim-actions/get-pr-commits/releases)
- [Commits](https://github.com/tim-actions/get-pr-commits/compare/v1.2.0...v1.3.0)

---
updated-dependencies:
- dependency-name: tim-actions/get-pr-commits
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-17 05:00:09 +00:00
Kir Kolyshkin b492357d8b Merge pull request #3822 from kolyshkin/gha-rm-cache
ci/gha: disable double caching
2023-05-16 12:27:04 -07:00
Kir Kolyshkin 62cc13ea1a gha: disable setup-go cache for golangci job
Since commit e3cf217cf1 actions/setup-go@v4 uses caching
implicitly, and olangci/golangci-lint-action also uses caching.

These two caches clash, resulting in multiple warnings in CI logs.

The official golangci-lint-action solution is to disable caching
for setup-go job (see [1]). Do the same.

[1] https://github.com/golangci/golangci-lint-action/pull/704

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-16 11:22:31 -07:00
Kir Kolyshkin 083e9789b8 ci/gha: rm actions/cache from validate/deps job
Since commit e3cf217cf1 actions/setup-go@v4 uses caching
implicitly, so it is no longer required.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-16 11:22:31 -07:00
Mrunal Patel 57952fe231 Merge pull request #3870 from kolyshkin/ci-386
ci/gha: cross-i386: fix build, rm kludges
2023-05-16 11:17:12 -07:00
Kir Kolyshkin da5cdfed7c ci/gha: fix cross-i386
As of today, installing fails with

> libc6:i386 : Depends: libgcc-s1:i386 but it is not going to be installed

Add the package explicitly to work around that.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-15 16:19:39 -07:00
Kir Kolyshkin b32655d2bc ci/gha: rm kludges for cross-i386 job
The first kludge is not needed since the switch to Ubuntu 22.04 in
commit 953e1cc48.

The second one is not needed since Go 1.20.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-15 15:13:25 -07:00
Kir Kolyshkin 268511680f Merge pull request #3858 from opencontainers/dependabot/go_modules/golang.org/x/net-0.10.0
build(deps): bump golang.org/x/net from 0.9.0 to 0.10.0
2023-05-10 15:51:10 -07:00
Sebastiaan van Stijn d782db4536 Merge pull request #3830 from AkihiroSuda/spec-v1.1.0-rc.2
go.mod: runtime-spec v1.1.0-rc.2
2023-05-10 18:06:13 +02:00
Akihiro Suda 6beb3c6a3e go.mod: runtime-spec v1.1.0-rc.2
See https://github.com/opencontainers/runtime-spec/releases/tag/v1.1.0-rc.2
for the spec changes.

The `runc features` json is now defined in
https://github.com/opencontainers/runtime-spec/blob/v1.1.0-rc.2/specs-go/features/features.go

Replaces PR 3829

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-05-10 22:23:29 +09:00
Kir Kolyshkin 8eb801dff5 Merge pull request #3512 from kolyshkin/fix-mntns-userns-II
Refactor mountFd code
2023-05-09 01:37:25 -07:00
dependabot[bot] 882a2cc887 build(deps): bump golang.org/x/net from 0.9.0 to 0.10.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.9.0 to 0.10.0.
- [Commits](https://github.com/golang/net/compare/v0.9.0...v0.10.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-05-09 08:36:13 +00:00
Akihiro Suda 712a781fe5 Merge pull request #3856 from opencontainers/dependabot/go_modules/golang.org/x/sys-0.8.0
build(deps): bump golang.org/x/sys from 0.7.0 to 0.8.0
2023-05-09 17:35:38 +09:00
dependabot[bot] 02afa9f142 build(deps): bump golang.org/x/sys from 0.7.0 to 0.8.0
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.7.0 to 0.8.0.
- [Commits](https://github.com/golang/sys/compare/v0.7.0...v0.8.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-05-05 04:58:43 +00:00
Kir Kolyshkin a60933bb24 libct/rootfs: introduce and use mountEntry
Adding fd field to mountConfig was not a good thing since mountConfig
contains data that is not specific to a particular mount, while fd is
a mount entry attribute.

Introduce mountEntry structure, which embeds configs.Mount and adds
srcFd to replace the removed mountConfig.fd.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-02 18:54:38 -07:00
Kir Kolyshkin 976748e8d6 libct: add mountViaFDs, simplify mount
1. Simplify mount call by removing the procfd argument, and use the new
   mount() where procfd is not used. Now, the mount() arguments are the
   same as for unix.Mount.

2. Introduce a new mountViaFDs function, which is similar to the old
   mount(), except it can take procfd for both source and target.
   The new arguments are called srcFD and dstFD.

3. Modify the mount error to show both srcFD and dstFD so it's clear
   which one is used for which purpose. This fixes the issue of having
   a somewhat cryptic errors like this:

> mount /proc/self/fd/11:/sys/fs/cgroup/systemd (via /proc/self/fd/12), flags: 0x20502f: operation not permitted

  (in which fd 11 is actually the source, and fd 12 is the target).

   After this change, it looks like

> mount src=/proc/self/fd/11, dst=/sys/fs/cgroup/systemd, dstFD=/proc/self/fd/12, flags=0x20502f: operation not permitted

   so it's clear that 12 is a destination fd.

4. Fix the mountViaFDs callers to use dstFD (rather than procfd) for the
   variable name.

5. Use srcFD where mountFd is set.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-02 18:41:09 -07:00
Sebastiaan van Stijn 5a9266b068 Merge pull request #3851 from kolyshkin/bump-urfave
deps: bump urfave/cli
2023-05-01 02:06:29 +02:00
Akihiro Suda 253707d8fc Merge pull request #3850 from cyphar/env-nul-byte
init: do not print environment variable value
2023-04-29 14:45:27 +09:00
Kir Kolyshkin 5a17746302 deps: bump urfave/cli
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-04-28 12:43:08 -07:00
Aleksa Sarai 20e38fb2b1 init: do not print environment variable value
When given an environment variable that is invalid, it's not a good idea
to output the contents in case they are supposed to be private (though
such a container wouldn't start anyway so it seems unlikely there's a
real way to use this to exfiltrate environment variables you didn't
already know).

Reported-by: Carl Henrik Lunde <chlunde@ifi.uio.no>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2023-04-28 16:32:15 +10:00
Sebastiaan van Stijn 8af2f48d9f Merge pull request #3357 from kolyshkin/more-bytes-less-strings
libct/cg/sd: optimize and test findDeviceGroup
2023-04-27 18:36:47 +02:00
Kir Kolyshkin defb1cc718 libct/cg/dev: optimize and test findDeviceGroup
1. Use strings.TrimPrefix instead of fmt.Sscanf and simplify the code.

2. Add a test case and a benchmark.

The benchmark shows some improvement, compared to the old
implementation:

name               old time/op    new time/op    delta
FindDeviceGroup-4    39.7µs ± 2%    26.8µs ± 2%  -32.63%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
FindDeviceGroup-4    6.08kB ± 0%    4.23kB ± 0%  -30.39%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
FindDeviceGroup-4       117 ± 0%         6 ± 0%  -94.87%  (p=0.008 n=5+5)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-04-27 09:12:08 -07:00
Sebastiaan van Stijn 39fe1c39fc Merge pull request #3848 from kolyshkin/bump-vagrant
ci/cirrus: use vagrant from hashicorp repo, bump Fedora to 38, bump bats
2023-04-27 12:22:16 +02:00
Kir Kolyshkin 13091eeefa ci: bump bats 1.8.2 -> 1.9.0
As Fedora 38 uses bats 1.9.0, let's switch to this version in other
places.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-04-26 18:56:37 -07:00
Kir Kolyshkin a19200096e Vagrantfile.fedora: bump to 38
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-04-26 18:56:37 -07:00
Kir Kolyshkin 33b6ec2925 ci/cirrus: use vagrant from hashicorp repo
A version of vagrant available from the stock repos (2.2.19) is too old
and contains a bug that prevents downloading Fedora 38 image (see [1]).

Use packages from hashicorp repo, which currently has vagrant 2.3.4.
This resolves the problem of downloading the latest Fedora image.

Also, vagrant-libvirt plugin from Ubuntu repos is not working with
vagrant from hashicorp, so switch to using "vagrant plugin install".
The downside it, this takes extra 4 minutes or so in our CI, and I
am not sure how to cache it or speed it up.

[1] https://github.com/opencontainers/runc/pull/3835#issuecomment-1519321619

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-04-26 18:56:30 -07:00
Aleksa Sarai 30f9f8086d merge #3844 into main
Akihiro Suda (1):
  runc.keyring: add Akihiro Suda

LGTMs: kolyshkin cyphar
Closes #3844
2023-04-26 08:00:02 +10:00
Mrunal Patel bf6a78c140 Merge pull request #3842 from kolyshkin/rm-warning
libct/cg/sd: use systemd version when generating device properties
2023-04-25 09:22:02 -07:00
Akihiro Suda 14d6c7dfcb runc.keyring: add Akihiro Suda
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-04-25 10:33:12 +09:00