Commit Graph

39 Commits

Author SHA1 Message Date
Kir Kolyshkin dd696235a4 runc exec: reject paused container unless --ignore-paused
Currently, if a container is paused (i.e. its cgroup is frozen), runc exec
just hangs, and it is not obvious why.

Refuse to exec in a paused container. Add a test case.

In case runc exec in a paused container is a legit use case,
add --ignore-paused option to override the check. Document it,
add a test case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-11-03 20:36:27 -07:00
Kir Kolyshkin 5516294172 Remove io/ioutil use
See https://golang.org/doc/go1.16#ioutil

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-10-14 13:46:02 -07:00
Kir Kolyshkin 580e43ec25 contrib: rm init from bash completion
Commit 7a0302f0d7 already removed "runc init" from runc help output,
as this is an internal option not supposed to be used by the end user.

Let's remove runc init completion, too.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-27 16:54:38 -07:00
Kir Kolyshkin 097c6d7425 libct/cg: simplify getting cgroup manager
1. Make Rootless and Systemd flags part of config.Cgroups.

2. Make all cgroup managers (not just fs2) return error (so it can do
   more initialization -- added by the following commits).

3. Replace complicated cgroup manager instantiation in factory_linux
   by a single (and simple) libcontainer/cgroups/manager.New() function.

4. getUnifiedPath is simplified to check that only a single path is
   supplied (rather than checking that other paths, if supplied,
   are the same).

[v2: can't -> cannot]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-23 09:11:44 -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
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
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
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
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
Kir Kolyshkin 639445789d tests/int: add a "update cpu period with pod limit set" test
Add a test case for an issue fixed by the previous commit.

Unfortunately, this is somewhat complicated as there's no easy way to
create a transient unit, so a binary, sd-helper, had to be added. On top
of that, an ability to create a parent/pod cgroup is added to
helpers.bash, which might be useful for future integration tests.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-08-26 13:11:22 -07:00
Kir Kolyshkin 627a06ad92 Replace fmt.Errorf w/o %-style to errors.New
Using fmt.Errorf for errors that do not have %-style formatting
directives is an overkill. Switch to errors.New.

Found by

	git grep fmt.Errorf | grep -v ^vendor | grep -v '%'

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:42:07 -07:00
Kir Kolyshkin e6048715e4 Use gofumpt to format code
gofumpt (mvdan.cc/gofumpt) is a fork of gofmt with stricter rules.

Brought to you by

	git ls-files \*.go | grep -v ^vendor/ | xargs gofumpt -s -w

Looking at the diff, all these changes make sense.

Also, replace gofmt with gofumpt in golangci.yml.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-01 12:17:27 -07:00
Kir Kolyshkin 52390d6804 Ignore kernel memory settings
This is somewhat radical approach to deal with kernel memory.

Per-cgroup kernel memory limiting was always problematic. A few
examples:

 - older kernels had bugs and were even oopsing sometimes (best example
   is RHEL7 kernel);
 - kernel is unable to reclaim the kernel memory so once the limit is
   hit a cgroup is toasted;
 - some kernel memory allocations don't allow failing.

In addition to that,

 - users don't have a clue about how to set kernel memory limits
   (as the concept is much more complicated than e.g. [user] memory);
 - different kernels might have different kernel memory usage,
   which is sort of unexpected;
 - cgroup v2 do not have a [dedicated] kmem limit knob, and thus
   runc silently ignores kernel memory limits for v2;
 - kernel v5.4 made cgroup v1 kmem.limit obsoleted (see
   https://github.com/torvalds/linux/commit/0158115f702b).

In view of all this, and as the runtime-spec lists memory.kernel
and memory.kernelTCP as OPTIONAL, let's ignore kernel memory
limits (for cgroup v1, same as we're already doing for v2).

This should result in less bugs and better user experience.

The only bad side effect from it might be that stat can show kernel
memory usage as 0 (since the accounting is not enabled).

[v2: add a warning in specconv that limits are ignored]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-04-12 12:18:11 -07:00
Kir Kolyshkin dac0c1e34a console.ClearONLCR: move it back
This reverts most of commit 24c05b7, as otherwise it causes
a few regressions (docker cli, TestDockerSwarmSuite/TestServiceLogsTTY).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-19 09:39:54 -08:00
Kir Kolyshkin 24c05b71fa tty: fix ClearONLCR race
The TestExecInTTY test case is sometimes failing like this:

> execin_test.go:332: unexpected carriage-return in output "PID USER TIME COMMAND\r\n 1 root 0:00 cat\r\n 7 root 0:00 ps\r\n"

or this:

> execin_test.go:332: unexpected carriage-return in output "PID USER TIME COMMAND\r\n 1 root 0:00 cat\n 7 root 0:00 ps\n"

(this is easy to repro with `go test -run TestExecInTTY -count 1000`).

This is caused by a race between

 - an Init() (in this case it is is (*linuxSetnsInit.Init(), but
   (*linuxStandardInit).Init() is no different in this regard),
   which creates a pty pair, sends pty master to runc, and execs
   the container process,

and

 - a parent runc process, which receives the pty master fd and calls
   ClearONLCR() on it.

One way of fixing it would be to add a synchronization mechanism
between these two, so Init() won't exec the process until the parent
sets the flag. This seems excessive, though, as we can just move
the ClearONLCR() call to Init(), putting it right after console.NewPty().

Note that bug only happens in the TestExecInTTY test case, but
from looking at the code it seems like it can happen in runc run
or runc exec, too.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-01-07 13:33:00 -08:00
Kir Kolyshkin de80aae4bc recvtty: fix errcheck linter warnings
Fixes the following errcheck linter warnings

> contrib/cmd/recvtty/recvtty.go:115:10: Error return value of `io.Copy` is not checked (errcheck)
> 		io.Copy(os.Stdout, c)
> 		       ^
> contrib/cmd/recvtty/recvtty.go:120:11: Error return value of `io.Copy` is not checked (errcheck)
> 			io.Copy(c, os.Stdin)
> 			       ^
> contrib/cmd/recvtty/recvtty.go:175:11: Error return value of `io.Copy` is not checked (errcheck)
>			io.Copy(devnull, master)
>			       ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-30 19:30:13 -08:00
Kir Kolyshkin 6b41b463b1 recvtty: fix waiting for both goroutines
It looks like we need to wait for the both copy goroutines to finish,
not just the one that happen to finish first.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-30 19:30:13 -08:00
Kir Kolyshkin 4bbfd2e114 recvtty: use ioutil.Discard
Saves us a few lines of code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-11-30 19:30:13 -08:00
Kenta Tada 70538b39de Update bash completion to support systemd-cgroup
Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2020-10-21 21:15:30 +09:00
Kenta Tada 7613c718e6 Update bash completion to support new capabilities
This commit supports below capabilities.
* CAP_BPF
* CAP_CHECKPOINT_RESTORE
* CAP_PERFMON

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2020-10-15 08:32:57 +09:00
Amim Knabben 978fa6e906 Fixing some lint issues
Signed-off-by: Amim Knabben <amim.knabben@gmail.com>
2020-10-06 14:44:14 -04:00
Sebastiaan van Stijn 8bf216728c use string-concatenation instead of sprintf for simple cases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-30 10:51:59 +02:00
Aleksa Sarai a79fa7caa0 contrib: recvtty: add --no-stdin flag
This is mostly just useful for testing with the "single" mode, since it
allows you to run recvtty in the background without the console being
closed.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2020-05-13 17:38:45 +10:00
Kenta Tada 371d13c995 Update bash completion for v1.0.0 release
Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
2019-06-25 11:17:31 +09:00
Yan Zhu feb90346e0 doc: fix typo
Signed-off-by: Yan Zhu <yanzhu@alauda.io>
2018-09-07 11:58:59 +08:00
Michael Crosby f364c1a58c Set ClearONLCR in tests
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-09-25 13:35:22 -04:00
Daniel Dao 91eafcbc65 tty: move IO of master pty to be done with epoll
This moves all console code to use github.com/containerd/console library to
handle console I/O. Also move to use EpollConsole by default when user requests
a terminal so we can still cope when the other side temporarily goes away.

Signed-off-by: Daniel Dao <dqminh89@gmail.com>
2017-07-28 12:35:02 +01:00
W. Trevor King 830c0d70df libcontainer/console_linux.go: Make SaneTerminal public
And use it only in local tooling that is forwarding the pseudoterminal
master.  That way runC no longer has an opinion on the onlcr setting
for folks who are creating a terminal and detaching.  They'll use
--console-socket and can setup the pseudoterminal however they like
without runC having an opinion.  With this commit, the only cases
where runC still has applies SaneTerminal is when *it* is the process
consuming the master descriptor.

Signed-off-by: W. Trevor King <wking@tremily.us>
2017-06-07 21:32:41 -07:00
Christy Perez 9ed7e9b176 shfmt'ing files
Signed-off-by: Christy Perez <christy@linux.vnet.ibm.com>
2017-05-24 16:43:08 -05:00
Michael Crosby 957ef9cc73 Remove terminal info
This maybe a nice extra but it adds complication to the usecase.  The
contract is listen on the socket and you get an fd to the pty master and
that is that.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-03-16 10:23:59 -07:00
Aleksa Sarai 1543444ada contrib: add recvtty proof-of-concept
This is a proof-of-concept for the --console-socket API. It just acts as
a dumb input-output copy process (nowhere near as good as the internal
runC one since it doesn't handle console resizes or signals). It also
provides a test-friendly mode that will be used in the bats integration
tests.

This patch is part of the console rewrite patchset.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-12-01 15:49:36 +11:00
Daniel Martí cdb66f5421 Run shfmt on all shell files 2016-11-17 11:51:12 +00:00
Michael Crosby e58671e530 Add --all flag to kill
This allows a user to send a signal to all the processes in the
container within a single atomic action to avoid new processes being
forked off before the signal can be sent.

This is basically taking functionality that we already use being
`delete` and exposing it ok the `kill` command by adding a flag.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2016-11-08 09:35:02 -08:00
Zhang Wei 000431124b Add bash completions for new flags of update
Add bash completions for flags "--cpu-rt-period" and "--cpu-rt-runtime"
for `update` command.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
2016-11-07 17:49:31 +08:00
rajasec b2a194f226 Updating bash completion for ps command
Signed-off-by: rajasec <rajasec79@gmail.com>
2016-10-22 21:51:21 +05:30
rajasec 04f1a4cc98 Adding bash completion for create and run
Signed-off-by: rajasec <rajasec79@gmail.com>
2016-09-08 12:14:42 +05:30
rajasec e31a1ae0f1 bash completion step for update command
Signed-off-by: rajasec <rajasec79@gmail.com>
2016-05-28 13:22:28 +05:30
Dan Walsh 8b81b10397 Add bash completion support
I have taken the docker command completions code and reworked it for runc
support.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2016-05-25 15:18:43 -04:00