Commit Graph

5630 Commits

Author SHA1 Message Date
Kir Kolyshkin d2b6899ea9 Makefile: fixes for seccompagent
1. The seccompagent target it built in the same way as others in contrib,
   so there is no need to have a separate rule.

2. Mark seccompagent as phony, because it is (it rarely happens, but I
   actually just had an issue because this was absent).

3. Add seccompagent binary to clean target.

Fixes: e21a9ee81

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-20 09:35:33 -07:00
Akihiro Suda d362b7acf5 Merge pull request #3219 from zhsj/simple-bits
libct/cg: replace bitset with std math/big library
2021-09-20 15:05:21 +09:00
Shengjing Zhu 163e2523d7 libct/cg: replace bitset with std math/big library
Cut down third party dependency.

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2021-09-19 23:38:15 +08:00
Aleksa Sarai dbc294fc1e merge branch 'pr-3214'
Kir Kolyshkin (3):
  create, run: amend final errors
  startContainer: minor refactor
  delete, start: remove newline from errors

LGTMs: AkihiroSuda cyphar
2021-09-15 15:16:11 +10:00
Kir Kolyshkin d974b22ac4 create, run: amend final errors
As the error may contain anything, it may not be clear to a user that
the whole (create or run) operation failed. Amend the errors.

Also, change the code flow in create to match that of run, so we don't
have to add the fake "return nil" at the end.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-14 10:53:11 -07:00
Kir Kolyshkin 9ba2f65d6b startContainer: minor refactor
All three callers* of startContainer call revisePidFile and createSpec
before calling it, so it makes sense to move those calls to inside of
the startContainer, and drop the spec argument.

* -- in fact restore does not call revisePidFile, but it should.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-14 10:53:11 -07:00
Kir Kolyshkin 1545ea69b7 delete, start: remove newline from errors
Error messages should not usually contain newlines.

Testing shows that the error runc delete prints is the same before and
after this commit:

	[kir@kir-rhat runc-tst]$ sudo ../runc/runc delete xx3
	ERRO[0000] cannot delete container xx3 that is not stopped: running
	[kir@kir-rhat runc-tst]$

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-14 10:52:03 -07:00
Kir Kolyshkin bcadc5bf3e Merge pull request #3206 from kinvolk/rata/notify
Add tests for seccomp agent example
2021-09-13 16:10:36 -07:00
Kir Kolyshkin cd7df39ac5 Merge pull request #3201 from kolyshkin/nsexec-less-logs
nsexec.c: don't write logs that are to be discarded
2021-09-13 13:40:15 -07:00
Sebastiaan van Stijn 2eaeea77c2 Merge pull request #3207 from kolyshkin/update-shfmt
ci/gha: bump shfmt to 3.3.1
2021-09-10 23:36:56 +02:00
Rodrigo Campos af641cd587 seccomp: Add test using the seccomp agent example
This commit adds the config.json as generated by the script. Note that
the diff is minimal if you see this commit with "git show -w". The
differences are mostly whitespaces and some ordering.

We add a simple test that runs this and expects sucess.

Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-09-10 12:44:43 +02:00
Aleksa Sarai 5906c67371 merge branch 'pr-3208'
Kir Kolyshkin (2):
  ci/gha: update golangci-lint to 1.42.1
  contrib/cmd/seccompagent: fix build tags

LGTMs: AkihiroSuda cyphar
2021-09-10 18:09:46 +10:00
Akihiro Suda 7e9fd9941a Merge pull request #3211 from opencontainers/dependabot/go_modules/github.com/bits-and-blooms/bitset-1.2.1
build(deps): bump github.com/bits-and-blooms/bitset from 1.2.0 to 1.2.1
2021-09-10 16:03:40 +09:00
Akihiro Suda eedf585a04 Merge pull request #3210 from opencontainers/dependabot/go_modules/github.com/opencontainers/selinux-1.8.5
build(deps): bump github.com/opencontainers/selinux from 1.8.4 to 1.8.5
2021-09-10 16:03:09 +09:00
dependabot[bot] 0865908023 build(deps): bump github.com/bits-and-blooms/bitset from 1.2.0 to 1.2.1
Bumps [github.com/bits-and-blooms/bitset](https://github.com/bits-and-blooms/bitset) from 1.2.0 to 1.2.1.
- [Release notes](https://github.com/bits-and-blooms/bitset/releases)
- [Commits](https://github.com/bits-and-blooms/bitset/compare/v1.2.0...v1.2.1)

---
updated-dependencies:
- dependency-name: github.com/bits-and-blooms/bitset
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-10 04:22:43 +00:00
dependabot[bot] 622acd24fb build(deps): bump github.com/opencontainers/selinux from 1.8.4 to 1.8.5
Bumps [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) from 1.8.4 to 1.8.5.
- [Release notes](https://github.com/opencontainers/selinux/releases)
- [Commits](https://github.com/opencontainers/selinux/compare/v1.8.4...v1.8.5)

---
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-09-10 04:22:23 +00:00
Kir Kolyshkin 47abdceef1 ci/gha: update golangci-lint to 1.42.1
v1.42.1 was released tagged a few days ago.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 17:06:48 -07:00
Kir Kolyshkin 704a1878ef contrib/cmd/seccompagent: fix build tags
* cgo tag is not required;
* add new style (go1.17+) build tags.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 17:06:48 -07:00
Kir Kolyshkin 49137c2aa0 ci/gha: bump shfmt to 3.3.1
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 16:37:00 -07:00
Kir Kolyshkin f1b703fc45 libct/nsenter/nsexec.c: honor _LIBCONTAINER_LOGLEVEL
Currently, if the log level is not set to e.g. "debug", runc init sends
some debug logs to the parent, which parses and discards it.

It is better to not send those in the first place.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 15:01:26 -07:00
Kir Kolyshkin d5ffe83f94 libct/nsenter/nsexec.c: factor out getenv_int
The code already parses an environment variable into an integer twice,
and we're about to add a third one.

Factor it out to getenv_int().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 14:57:20 -07:00
Kir Kolyshkin d2f49d4563 libct/nsenter/nsexec.c: improve bail
This makes it possible to use bail() even if logging is not set up
(yet), so we don't have to think whether it's OK to use it or not.
In addition, this might help some unit tests that do not set log
forwarding.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 14:57:20 -07:00
Kir Kolyshkin 6c4a3b13d1 runc init: pass _LIBCONTAINER_LOGLEVEL as int
Instead of passing _LIBCONTAINER_LOGLEVEL as a string
(like "debug" or "info"), use a numeric value.

Also, simplify the init log level passing code -- since we actually use
the same level as the runc binary, just get it from logrus.

This is a preparation for the next commit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 14:57:20 -07:00
Kir Kolyshkin 0a3577c680 utils_linux: simplify newProcess
newProcess do not need those extra arguments, they can be handled
in the caller.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-09 14:57:20 -07:00
Kir Kolyshkin 9e22bca54a Merge pull request #3204 from cyphar/seccomp-kill-thread-process
Add support for seccomp actions ActKillThread and ActKillProcess
2021-09-09 08:50:39 -07:00
Rodrigo Campos 51cd519e4c seccomp agent: Return non-zero on failures
This is useful for future patches, that will run the config in tests.

Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-09-09 17:05:28 +02:00
Rodrigo Campos 8b790e4f4f seccomp agent: Use arch SCMP_ARCH_X86_64
Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
2021-09-09 16:48:07 +02:00
Sascha Grunert 4a4d4f109b Add support for seccomp actions ActKillThread and ActKillProcess
Two new seccomp actions have been added to the libseccomp-golang
dependency, which can be now supported by runc, too.

ActKillThread kills the thread that violated the rule. It is the same as
ActKill. All other threads from the same thread group will continue to
execute.

ActKillProcess kills the process that violated the rule. All threads in
the thread group are also terminated. This action is only usable when
libseccomp API level 3 or higher is supported.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-09-09 17:47:00 +10:00
Aleksa Sarai 4a751b05a9 seccomp: drop unnecessary const SCMP_ACT_* defines
These are just boilerplate and are only really useful for the two
actions which require us to set a default errno/aux value (ActErrno and
ActTrace).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-09-09 17:46:34 +10:00
dependabot[bot] 41936bf8c1 Merge pull request #3203 from opencontainers/dependabot/go_modules/github.com/godbus/dbus/v5-5.0.5 2021-09-09 06:16:17 +00:00
Aleksa Sarai 76c1583413 merge branch 'pr-3186'
Akihiro Suda (1):
  improve error message when dbus-user-session is not installed

LGTMs: kolyshkin cyphar
2021-09-09 14:57:03 +10:00
Aleksa Sarai 3eccbe995e merge branch 'pr-3157'
Kir Kolyshkin (6):
  runc --debug: shorter caller info
  libct/logs: do not show caller in nsexec logs
  libct/logs: parse log level implicitly
  libct/logs: test: make more robust
  libct/logs: remove ConfigureLogging
  init.go, main.go: don't use logs.ConfigureLogging

LGTMs: thaJeztah cyphar
2021-09-09 14:54:53 +10:00
Aleksa Sarai 1e5fe26f4e merge branch 'pr-2696'
Kir Kolyshkin (3):
  libct/system: add I and P process states
  libct/system.Stat: fix/improve/speedup
  libct/system/proc_test: fix, improve, add benchmark

LGTMs: thaJeztah cyphar
2021-09-09 14:37:19 +10:00
Aleksa Sarai 8bf032602a merge branch 'pr-3047'
Liu Hua (1):
  checkpoint: resolve symlink for external bind mount(fix ci broken)

LGTMs: kolyshkin cyphar
2021-09-09 14:24:26 +10:00
dependabot[bot] 72b5c3ca18 build(deps): bump github.com/godbus/dbus/v5 from 5.0.4 to 5.0.5
Bumps [github.com/godbus/dbus/v5](https://github.com/godbus/dbus) from 5.0.4 to 5.0.5.
- [Release notes](https://github.com/godbus/dbus/releases)
- [Commits](https://github.com/godbus/dbus/compare/v5.0.4...v5.0.5)

---
updated-dependencies:
- dependency-name: github.com/godbus/dbus/v5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-09 04:21:44 +00:00
Aleksa Sarai 9a0419b920 merge branch 'pr-2682'
Alban Crequy (3):
  vendoring: Use libseccomp with notify support
  Implement Seccomp Notify
  contrib: add sample seccomp agent

Mauricio Vásquez (4):
  libcontainer/utils: introduce SendFds
  libcontainer/specconv: extend SetupSeccomp tests
  tests: add functional tests for seccomp
  tests: add functional tests for seccomp notify

Co-developed-by: Rodrigo Campos
LGTMs: kolyshkin cyphar
2021-09-08 14:31:43 +10:00
Akihiro Suda 110bdb02e6 Merge pull request #3200 from kolyshkin/release-fix-for-opensuse
script/release.sh: fix for opensuse
2021-09-07 20:17:27 +09:00
Mauricio Vásquez 00772caec7 tests: add functional tests for seccomp notify
Add functional test to check seccomp notify end-to-end. This test uses the
sample seccomp agent from the contrib/cmd folder.

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-09-07 13:04:24 +02:00
Mauricio Vásquez 5ae831d9b3 tests: add functional tests for seccomp
Test KILL and ERRNO actions.

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2021-09-07 13:04:24 +02:00
Alban Crequy e21a9ee813 contrib: add sample seccomp agent
Implement sample seccomp agent. It's also used in integration tests in
the following commit.

Instructions how to use it in contrib/cmd/seccompagent/README.md

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-09-07 13:04:24 +02:00
Mauricio Vásquez c64aaf0e0b libcontainer/specconv: extend SetupSeccomp tests
Extend the SetupSeccomp tests by adding the following cases:
- Test nil config
- Test empty config
- Test bad action and architecture
- Test all possible actions

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2021-09-07 13:04:24 +02:00
Alban Crequy 2b025c0173 Implement Seccomp Notify
This commit implements support for the SCMP_ACT_NOTIFY action. It
requires libseccomp-2.5.0 to work but runc still works with older
libseccomp if the seccomp policy does not use the SCMP_ACT_NOTIFY
action.

A new synchronization step between runc[INIT] and runc run is introduced
to pass the seccomp fd. runc run fetches the seccomp fd with pidfd_get
from the runc[INIT] process and sends it to the seccomp agent using
SCM_RIGHTS.

As suggested by @kolyshkin, we also make writeSync() a wrapper of
writeSyncWithFd() and wrap the error there. To avoid pointless errors,
we made some existing code paths just return the error instead of
re-wrapping it. If we don't do it, error will look like:

	writing syncT <act>: writing syncT: <err>

By adjusting the code path, now they just look like this
	writing syncT <act>: <err>

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-09-07 13:04:24 +02:00
Mauricio Vásquez 4e7aeff610 libcontainer/utils: introduce SendFds
SendFds is a helper function for sending a set of file descriptors and a message
over a unix domain socket.

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2021-09-07 12:38:12 +02:00
Alban Crequy c55530bedc vendoring: Use libseccomp with notify support
The notify support has been merged in libseccomp-golang in this PR:
	https://github.com/seccomp/libseccomp-golang/pull/59

Also, we update to new API of libseccomp-golang so code doesn't break.

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-09-07 12:38:12 +02:00
Akihiro Suda a244d57906 Merge pull request #3198 from Vanient/master
optimize log: move WriteJSON defer as early as possible
2021-09-07 15:19:16 +09:00
xiadanni 64358c4de9 optimize log: move WriteJSON defer as early as possible
if function returns error before WriteJSON defer, error will not be
printed out, so move this defer as early as possible and use logrus to
print out error if returns before it.

Signed-off-by: xiadanni <xiadanni1@huawei.com>
2021-09-07 07:00:57 +08:00
Kir Kolyshkin 39d0ee18e9 script/release.sh: fix for opensuse
openSUSE comes with site-config package, which makes configure select
${prefix}/lib64 as libdir on x86_64, unless explicitly specified.

Since release.sh relies on a particular libdir path (for pkgconfig), it
breaks things:

> + make -C /home/kir/git/runc PKG_CONFIG_PATH=/tmp/tmp.QgIJ1sR5c9/lib/pkgconfig COMMIT_NO= EXTRA_FLAGS=-a 'EXTRA_LDFLAGS=-w -s -buildid=' static
> make[1]: Entering directory '/home/kir/git/runc'
> CGO_ENABLED=1 go build -trimpath -a -tags "seccomp netgo osusergo" -ldflags "-extldflags -static -X main.gitCommit=v1.0.0-204-g963e0146 -X main.version=1.0.0+dev -w -s -buildid=" -o runc .
> Package libseccomp was not found in the pkg-config search path.
> Perhaps you should add the directory containing `libseccomp.pc'

To fix, we have to explicitly specify libdir.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-06 12:56:04 -07:00
Kir Kolyshkin a20c8b29d4 runc --debug: shorter caller info
Commit 9f3d7534ea enabled logrus to show information about log
caller, if --debug is set.

The problem is, the file name and in many cases the function name have a
long prefix of github.com/opencontainers/runc (this is with -trimpath,
and without it it's worse).

Add a function to trim the prefix.

Note all this happens only when --debug is given.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-04 11:47:31 -07:00
Kir Kolyshkin b55b308143 libct/logs: do not show caller in nsexec logs
Commit 9f3d7534ea enabled logrus to show information about log
caller, if --debug is set. It is helpful in many scenarios, but does
not work very well when we are debugging runc init, for example:

	# runc --debug run -d xx4557
	DEBU[0000]libcontainer/logs/logs.go:45 github.com/opencontainers/runc/libcontainer/logs.processEntry() nsexec[279687]: logging set up
	DEBU[0000]libcontainer/logs/logs.go:45 github.com/opencontainers/runc/libcontainer/logs.processEntry() nsexec[279687]: logging set up
	DEBU[0000]libcontainer/logs/logs.go:45 github.com/opencontainers/runc/libcontainer/logs.processEntry() nsexec[279687]: => nsexec container setup
	DEBU[0000]libcontainer/logs/logs.go:45 github.com/opencontainers/runc/libcontainer/logs.processEntry() nsexec[279687]: update /proc/self/oom_score_adj to '30'

As we're merely forwarding the logs here, printing out filename:line and
function is useless and clutters the logs a log.

To fix, create and use a copy of the standard logger with caller info
turned off.

With this in place, nsexec logs are sane again:

	# runc --debug --log-format=text run -d xe34
	DEBU[0000] nsexec[293595]: logging set up
	DEBU[0000] nsexec[293595]: logging set up
	DEBU[0000] nsexec[293595]: => nsexec container setup
	DEBU[0000] nsexec[293595]: update /proc/self/oom_score_adj to '30'

This patch also changes Logf to Log in processEntry, as this is what it
should be.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-04 11:47:31 -07:00
Kir Kolyshkin c3910e7331 libct/logs: parse log level implicitly
There's no need to call logrus.ParseLevel as logrus.Level already
implements encoding.TextUnmarshaler interface.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-04 11:47:31 -07:00