Commit Graph

5526 Commits

Author SHA1 Message Date
Kir Kolyshkin f77fb7a3ee init.go, main.go: don't use logs.ConfigureLogging
This function is somewhat strange and I always wanted to remove it,
as it tries to satisfy both init.go and main.go, which have somewhat
different needs.

It is more straightforward and readable to configure logrus directly.

While at it, simplify errors on panic (errors from logrus.ParseLevel
and strconv.Atoi already contain value which they fail to parse, and
panic already contains enough context to figure out what's wrong).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-20 10:59:46 -07:00
Kir Kolyshkin 3023e6c625 Merge pull request #3166 from kolyshkin/fix-freeze-before-set-alt-2
libct/cg/sd/v1: fix freezeBeforeSet (alt 2)
2021-08-19 11:40:06 -07:00
Sebastiaan van Stijn 926a9a088f Merge pull request #3171 from kolyshkin/try-bullseye
Dockerfile: switch to bullseye
2021-08-19 18:16:11 +02:00
Sebastiaan van Stijn 8e6871a3b1 Merge pull request #3116 from kolyshkin/ci-add-criu-dev
ci/gha: add latest criu-dev test run
2021-08-19 09:46:52 +02:00
Kir Kolyshkin 24d318b8bb Dockerfile: switch to bullseye
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-18 15:59:22 -07:00
Mrunal Patel 9835e9c6b2 Merge pull request #3021 from kolyshkin/go-1.17beta1
ci: add go1.17
2021-08-18 13:32:05 -07:00
Kir Kolyshkin 9a095e44db libct/cg/sd/v1: add SkipFreezeOnSet knob
This is helpful to kubernetes in cases it knows for sure that the freeze
is not required (since it created the systemd unit with no device
restrictions).

As the code is trivial, no tests are required.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-18 12:43:55 -07:00
Kir Kolyshkin fec49f2a6c libct/cg/sd/v1: add freezeBeforeSet unit test
Add a test for freezeBeforeSet, checking various scenarios including
those that were failing before the fix in the previous commit.

[v2: add more cases, add a check before creating a unit.]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-18 12:43:55 -07:00
Odin Ugedal 41043673b7 libct/cg/sd/v1: Fix unnecessary freeze/thaw
This fixes the behavior intended to avoid freezing containers/control
groups without it being necessary. This is important for end users of
libcontainer who rely on the behavior of no freeze.

The previous implementation would always get error trying to get
DevicePolicy from the Unit via dbus, since the Unit interface doesn't
contain DevicePolicy.

Signed-off-by: Odin Ugedal <odin@uged.al>
2021-08-18 12:43:36 -07:00
Akihiro Suda 4d26c4a0a1 Merge pull request #3144 from kolyshkin/codespell
Fix codespell warnings, add codespell to ci
2021-08-18 11:42:36 +09:00
Akihiro Suda ba7a87730d Merge pull request #3168 from kolyshkin/fix-cc-warn
libct/nsenter: fix unused-result warning
2021-08-18 11:37:59 +09:00
Kir Kolyshkin a587180136 ci: add go1.17
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-17 17:49:44 -07:00
Kir Kolyshkin 75761bccf7 Fix codespell warnings, add codespell to ci
The two exceptions I had to add to codespellrc are:
 - CLOS (used by intelrtd);
 - creat (syscall name used in tests/integration/testdata/seccomp_*.json).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-17 16:12:35 -07:00
Kir Kolyshkin db8330c9e5 libct/nsenter: fix unused-result warning
Commit 2bab4a5 resulted in a warning from gcc:

	nsexec.c: In function ‘write_log’:
	nsexec.c:171:2: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
	  171 |  write(logfd, json, ret);
	      |  ^~~~~~~~~~~~~~~~~~~~~~~

As there's nothing we can or want to do in case write fails,
let's just tell the compiler we're not going to use it.

Fixes: 2bab4a5
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-17 15:19:31 -07:00
Sebastiaan van Stijn e53e97a875 Merge pull request #3164 from kinvolk/rata/make-no-buildtags
CI: Validate compilation without buildtags
2021-08-17 23:04:50 +02:00
Akihiro Suda dff416868e Merge pull request #3160 from kailun-qin/fix-check
libct/nsenter: no need to check size_t less than 0
2021-08-18 02:34:33 +09:00
Sebastiaan van Stijn ca4433f613 Merge pull request #3153 from kolyshkin/cirrus-robust
.cirrus.yml: simplify for centos, retry yum
2021-08-17 15:34:39 +02:00
Kir Kolyshkin 10f179c8c2 Merge pull request #3162 from kailun-qin/null-on-error
libct/nsenter: nullify pointer on asprintf error
2021-08-16 16:18:52 -07:00
Rodrigo Campos 844d6774e0 CI: Validate compilation without buildtags
Today we support the seccomp build tag only that is used by default.
However, we are not testing that compiling without any build tag works.

I found the CI didn't catch this when working on #2682, that the CI was
green but compilation without build tags was broken.

We test compilation without build tags only, compilation with the only
build tag supported is done extensively in other actions.

Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-08-16 17:44:54 +02:00
Akihiro Suda 55e93b89f1 Merge pull request #3150 from kolyshkin/maintainers
MAINTAINERS: add Sebastiaan van Stijn
2021-08-16 22:51:53 +09:00
Kailun Qin 515082102e libct/nsenter: nullify pointer on asprintf error
The contents of the pointer returned on asprintf() error are undefined
i.e., it can be anything there. We set it to NULL on error so that
free() afterwards won't get a garbage pointer.

This patch applies the above to message and stage as well to be
consistent with what we do for json.

Signed-off-by: Kailun Qin <kailun.qin@intel.com>
2021-08-14 04:15:45 -04:00
Kailun Qin 2ab6484ff6 libct/nsenter: no need to check size_t less than 0
According to C standards, `size_t` is always an unsigned integer type.
Thus, checking unsigned expressions to be less than zero is not needed.

Signed-off-by: Kailun Qin <kailun.qin@intel.com>
2021-08-13 09:26:07 -04:00
Kir Kolyshkin f0dbefac61 .cirrus.yum: retry yum if failed
Add a sleep + retry loop in case yum install has failed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-12 20:19:25 -07:00
Kir Kolyshkin 74b5c34e6e .cirrus.yml: simplify
GCP images description at [1] claims that:

 - For CentOS 8 and CentOS Stream 8, the PowerTools repository is
   enabled.
 - For CentOS 7, EPEL is enabled.

Apparently,
 - we do not need epel for centos-stream-8;
 - powertools is not enabled on centos-stream-8 despite [1].

Anyway, the less yum commands the better, as we have seen those fail
sometimes due to occasional networking problems etc.

[1] https://cloud.google.com/compute/docs/images/os-details#centos
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-12 00:10:14 -07:00
Akihiro Suda bb34048f93 Merge pull request #3152 from opencontainers/dependabot/go_modules/github.com/containerd/console-1.0.3
build(deps): bump github.com/containerd/console from 1.0.2 to 1.0.3
2021-08-12 15:20:35 +09:00
dependabot[bot] 77fb9aff56 build(deps): bump github.com/containerd/console from 1.0.2 to 1.0.3
Bumps [github.com/containerd/console](https://github.com/containerd/console) from 1.0.2 to 1.0.3.
- [Release notes](https://github.com/containerd/console/releases)
- [Commits](https://github.com/containerd/console/compare/v1.0.2...v1.0.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-12 04:15:47 +00:00
Mrunal Patel b114862c53 Merge pull request #3120 from kolyshkin/nsexec-log-race
libct/nsenter: fix logging race in nsexec (regression in rc94)
2021-08-11 16:21:11 -07:00
Kir Kolyshkin ab577f6fc4 MAINTAINERS: add Sebastiaan van Stijn
Sebastiaan is one of the most active contributors recently:
https://github.com/opencontainers/runc/graphs/contributors?from=2019-08-11&to=2021-08-11&type=c

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-11 16:10:57 -07:00
Kir Kolyshkin 2bab4a56f1 libct/nsenter: fix logging race in nsexec
As reported in issue 3119, there is a race in nsexec logging
that can lead to garbled json received by log forwarder, which
complains about it with a "failed to decode" error.

This happens because dprintf (used since the very beginning of nsexec
logging introduced in commit ba3cabf932) relies on multiple write(2)
calls, and with additional logging added by 64bb59f592 a race is
possible between runc init parent and its children.

The fix is to prepare a string and write it using a single call to
write(2).

[v2: NULLify json on error from asprintf]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-11 10:01:00 -07:00
Kir Kolyshkin 16027b814d Merge pull request #3140 from opencontainers/dependabot/go_modules/github.com/opencontainers/selinux-1.8.4
build(deps): bump github.com/opencontainers/selinux from 1.8.3 to 1.8.4
2021-08-10 10:19:47 -07:00
dependabot[bot] bda1bd7a2f build(deps): bump github.com/opencontainers/selinux from 1.8.3 to 1.8.4
Bumps [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/opencontainers/selinux/releases)
- [Commits](https://github.com/opencontainers/selinux/compare/v1.8.3...v1.8.4)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-10 04:22:14 +00:00
Aleksa Sarai 7d4bac6810 merge branch 'pr-3133'
Kir Kolyshkin (3):
  libct/cg: GetAllPids: optimize for go 1.16+
  libct/cg: improve GetAllPids and readProcsFile
  libct/cg: move GetAllPids out of utils.go

LGTMs: AkihiroSuda cyphar
Closes #3133
2021-08-10 14:16:59 +10:00
Kir Kolyshkin d0c3bc44e7 libct/cg: GetAllPids: optimize for go 1.16+
filepath.WalkDir function, introduced in Go 1.16, doesn't do stat(2)
on every entry, and is therefore somewhat faster (see below).

Since we have to support Go 1.15, keep the old version for backward
compatibility.

Add a quick benchmark, which shows approximately 3x improvement:

        $ go1.15.15 test -bench AllPid -run xxx .
	BenchmarkGetAllPids-4   	      48	  23528839 ns/op

        $ go version
        go version go1.16.6 linux/amd64
        $ go test -bench AllPid -run xxx .
	BenchmarkGetAllPids-4   	     147	   7700170 ns/op

(Unrelated but worth noting -- go 1.17rc2 is pushing it even further)

        $ go1.17rc2 test -bench AllPid -run xxx .
	BenchmarkGetAllPids-4   	     164	   6820994 ns/op

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-05 16:22:18 -07:00
Kir Kolyshkin 363468d0e4 libct/cg: improve GetAllPids and readProcsFile
Since every cgroup directory is guaranteed to have cgroup.procs file,
we don't have to do filename comparison in GetAllPids() and just read
cgroup.procs in every directory.

While at it, switch readProcsFile to use our own OpenFile.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-05 16:22:11 -07:00
Kir Kolyshkin 504271a374 libct/cg: move GetAllPids out of utils.go
This is just moving the code around to ease the code review, no other
changes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-05 16:00:03 -07:00
Mrunal Patel 8772c4dd2f Merge pull request #3109 from kolyshkin/seccomp
seccomp: skip redundant rules
2021-08-03 23:09:00 -04:00
Mrunal Patel 64b3fe91bd Merge pull request #3117 from kolyshkin/cirrus-nit
ci/cirrus: remove unused code
2021-08-03 23:06:20 -04:00
Mrunal Patel c9b8b4f35e Merge pull request #3073 from kolyshkin/runc-exec-255
runc exec: fail with exit code of 255
2021-08-03 23:05:57 -04:00
Kir Kolyshkin 907c8defe0 Merge pull request #3125 from opencontainers/dependabot/go_modules/github.com/opencontainers/selinux-1.8.3
build(deps): bump github.com/opencontainers/selinux from 1.8.2 to 1.8.3
2021-08-03 16:40:07 -07:00
dependabot[bot] fc99ab7e65 build(deps): bump github.com/opencontainers/selinux from 1.8.2 to 1.8.3
Bumps [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/opencontainers/selinux/releases)
- [Commits](https://github.com/opencontainers/selinux/compare/v1.8.2...v1.8.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-03 04:21:49 +00:00
Kir Kolyshkin 2aabb29741 Merge pull request #3113 from kolyshkin/init-rm-code
runc init: remove some code
2021-07-29 16:54:47 -07:00
Aleksa Sarai d962bb0cb0 merge branch 'pr-3099'
Kir Kolyshkin (1):
  script/release.sh: make builds reproducible

Kailun Qin (1):
  makefile: update ldflags and add strip for static builds

LGTMs: AkihiroSuda cyphar
Closes #3099
2021-07-29 18:03:56 +10:00
Kir Kolyshkin e06465acd4 ci/cirrus: remove unused code
Since commit 9f656dbb11 these conditions are not needed.

Fixes: 9f656dbb11
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-28 17:28:23 -07:00
Kir Kolyshkin 120f740601 ci/gha: add latest criu-dev test run
Add testing against criu-dev branch instead of a released version
(happens to be criu v3.15 at the moment), to check how it works.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-28 17:00:58 -07:00
Kir Kolyshkin 60e02b4b25 runc exec: fail with exit code of 255
Currently there's no way to distinguish between the two cases:
 - runc exec failed;
 - the command executed returned 1.

This was possible before commit 8477638aab, as runc exec exited with
the code of 255 if exec itself has failed. The code of 255 is the same
convention as used by e.g. ssh.

Re-introduce the feature, document it, and add some tests so it won't be
broken again.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-28 13:46:13 -07:00
Kir Kolyshkin 18f434e10a script/release.sh: make builds reproducible
What it takes is add an empty buildid, which, together with previously
added strip invocation, results in reproducible build!

NB: earlier versions of this patch also added the following:

1. non-random libseccomp install $prefix;

2. "objcopy --enable-deterministic-archives $prefix/lib/libseccomp.a"
   to strip ar dates and UIDs/GIDs;

3. "-B=0x00" to EXTRA_LDFLAGS to have non-variable NT_GNU_BUILD_ID.

Apparently, all this is not needed with strip.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-27 13:58:29 -07:00
Kailun Qin 61e201abb2 makefile: update ldflags and add strip for static builds
This patch
* drops the default `-w` flag for `make static`, which helps with
  debugging the static runc binary;
* adds `EXTRA_LDFLAGS="-w -s"` to `script/release.sh` to disable DWARF
  generation and symbol table for the release runc binary;
* adds strip in `script/release.sh` for a further size-optimized release
  runc binary.

Signed-off-by: Kailun Qin <kailun.qin@intel.com>
2021-07-27 13:58:22 -07:00
Kir Kolyshkin 1f5f237b37 Merge pull request #3100 from kolyshkin/drop-go-1.13
Drop Go 1.13 support, require go 1.15+
2021-07-27 13:19:10 -07:00
Kir Kolyshkin 5110bd2fc0 nsenter: remove cgroupns sync mechanism
As pointed out in TODO item added by commit 64bb59f59, it is not
necessary to have a special sync mechanism for cgroupns, as the parent
adds runc init to cgroup way earlier (before sending nl bootstrap data.

This sync was added by commit df3fa115f9, which was also added a
second cgroup manager.Apply() call, later removed in commit
d1ba8e39f8. It seems the original author had the idea to wait for
that second Apply().

Fixes: df3fa115f9
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-27 12:17:47 -07:00
Kir Kolyshkin 7a0302f0d7 runc init: simplify
runc init is special. For one thing, it needs to do a few things before
main(), so we have func init() that checks if we're init and does that.

What happens next is main() is called, which does some options parsing,
figures out it needs to call initCommand.Action and so it does.

Now, main() is entirely unnecessary -- we can do everything right from
init().

Hopefully the change makes things slightly less complicated.

From a user's perspective, the only change is runc help no longer
lists 'runc init` (which I think it also good).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-27 12:16:09 -07:00