Commit Graph

4571 Commits

Author SHA1 Message Date
root ede8a86ec1 Convert root path to absolute path on create command
Signed-off-by: Amim Knabben <amim.knabben@gmail.com>
2020-10-03 07:56:27 -04:00
Michael Crosby 09ddc63afd Merge pull request #2535 from kolyshkin/no-term-on-stdin
Fix run/exec with terminal: true in case stdin is not a terminal
2020-08-24 21:18:38 -04:00
Akihiro Suda e5f2eae5a5 Merge pull request #2558 from rhatdan/windows
Since no kernels support direct labeling of /dev/mqueue remove label
2020-08-22 04:43:36 +09:00
Akihiro Suda 19b63de7f7 Merge pull request #2554 from saschagrunert/apparmor-parser
Remove check for apparmor_parser in apparmor.IsEnabled()
2020-08-22 04:15:17 +09:00
Kir Kolyshkin f844a2f56c Merge pull request #2527 from ashley-cui/master
Add support for umask
2020-08-20 11:28:03 -07:00
Kir Kolyshkin 8898ad31e6 Merge pull request #2488 from ManaSugi/modify-space-to-tab
Modify spaces to tabs for indentation
2020-08-20 11:24:23 -07:00
Daniel J Walsh 0445fd60a4 Since no kernels support direct labeling of /dev/mqueue remove label
This looks like this is just filling logs for years, since the kernel never
added the support for automatically labeling /dev/mqueue.

Removes these dmesg lines

[ 1731.969847] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1736.985146] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1738.356796] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1738.479952] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1738.628935] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1763.433276] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1806.802133] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1806.982003] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1808.955390] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1815.951076] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1827.257757] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1828.947888] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1834.964451] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)
[ 1835.941465] SELinux: mount invalid.  Same superblock, different security settings for (dev mqueue, type mqueue)

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-20 13:56:19 -04:00
Sascha Grunert bfb4ea1b1b Remove check for apparmor_parser in apparmor.IsEnabled()
The `apparmor_parser` binary is not really required for a system to run
AppArmor from a runc perspective. How to apply the profile is more in
the responsibility of higher level runtimes like Podman and Docker,
which may do the binary check on their own.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-20 19:23:04 +02:00
Giuseppe Scrivano a63f99fcc5 Add support for umask
Signed-off-by: Ashley Cui <acui@redhat.com>
2020-08-20 11:39:43 -04:00
Kir Kolyshkin 42d9a6b43b tty.bats: add test cases when stdin is not a tty
Note that stdout/stderr are already redirected by bats'
`run` command, so the only way to get a controlling terminal
is to open /dev/tty (which fails if there isn't one).

Here's how I tested the failure to open /dev/tty:

> [root@kir-rhat ~]# ssh -T root@localhost cat ./runme
> cd /home/kir/go/src/github.com/opencontainers/runc
> ./runc run -b tst xxx-$$
> echo $?
>
> [root@kir-rhat ~]# ssh -T root@localhost ./runme
> time="2020-07-31T16:35:47-07:00" level=error msg="chdir tst: no such file or directory"
> 1

If anyone knows how to obtain an tty-less environment without using
ssh -T, please raise your hand.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-20 07:56:20 -07:00
Kir Kolyshkin b79cb04886 runc run/exec: fix terminal wrt stdin redirection
This fixes the following failure:

> sudo runc run -b bundle ctr </dev/null
> WARN[0000] exit status 2
> ERRO[0000] container_linux.go:367: starting container process caused: process_linux.go:459: container init caused:

The "exit status 2" with no error message is caused by SIGHUP
which is sent to init by the kernel when we are losing the
controlling terminal. If we choose to ignore that, we'll get
panic in console.Current(), which is addressed by [1].

Otherwise, the issue here is simple: the code assumes stdin
is opened to a terminal, and fails to work otherwise. Some
standard Linux tools (e.g. stty, top) do the same (modulo panic),
while some others (reset, tput) use the trick of trying
all the three std streams (starting with stderr as it is least likely
to be redirected), and if all three fails, open /dev/tty.

This commit does a similar thing (see initHostConsole).

It also replaces the call to console.Current(), which may panic
(see [1]), by reusing the t.hostConsole.

Finally, a simple test case is added.

Fixes: https://github.com/opencontainers/runc/issues/2485

[1] https://github.com/containerd/console/pull/37

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-20 07:56:20 -07:00
Akihiro Suda e949339cd6 Merge pull request #2561 from kolyshkin/shellcheck-followup
shellcheck CI files
2020-08-20 23:51:52 +09:00
Kir Kolyshkin b8efb02060 tests/int/delete.bats: fix shellcheck warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-19 18:00:08 -07:00
Kir Kolyshkin 28204ce7e8 tests/int/delete: rm useless code
Commit 335f0806c added a test case doing

```bash
for i in $(seq 1); do
   ...
done
```

and it does not make any sense to have it since we're only performing
a single iteration.

Remove the code.

I have not touched the indentation, for the sake of cleaner review,
also because already have different intentation in different tests;
this should be addressed separately.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-19 17:56:52 -07:00
Kir Kolyshkin 34b4b106c6 tests/int: alt fix for shellcheck SC2034
Instead of ignoring it, use a throwaway variable _
(yes, just like in Go).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-19 16:50:57 -07:00
Aleksa Sarai 2265daa55b merge branch 'pr-2522' into master
Cesar Talledo (2):
  Remove runc default devices that overlap with spec devices.
  Skip redundant setup for /dev/ptmx when specified explicitly in the OCI spec.

LGTMs: @AkihiroSuda @cyphar
Closes #2522
2020-08-19 16:58:23 +10:00
Mrunal Patel a5847db387 Merge pull request #2506 from kolyshkin/cgroup-fixes
cgroupv1 removal nits
2020-08-17 21:13:31 -07:00
Mrunal Patel 7930f0c150 Merge pull request #2549 from kolyshkin/bats-shellcheck
Add shellcheck to bats files
2020-08-17 17:22:44 -07:00
Mrunal Patel 49a7346333 Merge pull request #2547 from kolyshkin/moar-v2-tests
libct/integration: enable some tests for cgroupv2
2020-08-17 11:46:22 -07:00
Mrunal Patel 9ada2e6d4f Merge pull request #2539 from kolyshkin/ext-pidns-nits
external pidns c/r code nits
2020-08-17 11:41:46 -07:00
Mrunal Patel b70de388e4 Merge pull request #2540 from kolyshkin/unify-test-inval-cgroup
cgroups/fs tests: unify TestInvalid*Cgroup*
2020-08-17 11:40:44 -07:00
Mrunal Patel 0509b5ba3c Merge pull request #2553 from AkihiroSuda/support-kernel59-caps
support CAP_PERFMON, CAP_BPF, and CAP_CHECKPOINT_RESTORE
2020-08-17 11:39:08 -07:00
Akihiro Suda 6dfbe9b807 support CAP_PERFMON, CAP_BPF, and CAP_CHECKPOINT_RESTORE
CAP_PERFMON and CAP_BPF were introduced in kernel 5.8: https://kernelnewbies.org/Linux_5.8#Introduce_CAP_BPF_and_CAP_PERFMON_security_capabilities

CAP_CHECKPOINT_RESTORE was merged on the master recently and will be available in the next version of the kernel. https://github.com/torvalds/linux/commit/124ea650d3072b005457faed69909221c2905a1f

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-08-15 15:47:47 +09:00
Akihiro Suda 54c53b10d3 Merge pull request #2533 from XiaodongLoong/fix_cgMode_redundant
use criu cgroup mode const from go-criu
2020-08-13 12:13:24 +09:00
Mrunal Patel a2d1f85be0 Merge pull request #2542 from AkihiroSuda/go1.15
upgrade Go to 1.15
2020-08-12 09:08:15 -07:00
Akihiro Suda 4c71a68c6e upgrade Go to 1.15
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-08-12 15:37:25 +09:00
Kir Kolyshkin d34f1c819d CI: add shellcheck of bats files
Currently all the shellcheck warnings are fixed, and we'd like it to
stay thay way. So, add shellcheck call to validate target in Makefile,
which is run on Travis CI.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:42:48 -07:00
Kir Kolyshkin f36fb46bdf tests/int/*bats: ignore SC2016
Ignore the shellcheck warnings like this one:

> In tty.bats line 32:
> 	update_config '(.. | select(.[]? == "sh")) += ["-c", "stat -c %u:%g $(tty) | tr : \\\\n"]'
>                     ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

While at it, fix some minor whitespace issues in tty.bats.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 598d8b73a5 tests/int/checkpoint.bats: ignore SC2206
Ignore warnings like this:

> In checkpoint.bats line 169:
>   PIDS_TO_KILL=($cpt_pid)
>                 ^------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Since in all the cases we deal with either pids or fds, and they don't
have spaces.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 08766b9848 tests/int/*bats: fix/ignore shellcheck SC2046
Fix or ignore warnings like this one:

> In cgroups.bats line 107:
>             if [ $(id -u) = "0" ]; then
>                  ^------^ SC2046: Quote this to prevent word splitting.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 4ba4baea0e tests/int/*bats: fix shellcheck SC2086, SC2006
Those are pretty simple to allow shellcheck to fix these, so
this commit is courtesy of

> shellcheck -i SC2086 -i SC2006 -f diff *.bats > fix.diff
> patch -p1 < fix.diff

repeated 3 times ;)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin b02ca2dc9c tests/int: fix shellcheck warning SC2002
Fix all warnings like this one:

> In checkpoint.bats line 197:
>   cat ./work-dir/restore.log | grep -B 5 Error || true
>       ^--------------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 3b80850eaa tests/int/update.bats: fix a shellcheck warning
This fixes the following warning, and implements a suggestion:

> In update.bats line 426:
>     IFS='/' read -r -a dirs <<< $(echo ${CGROUP_CPU} | sed -e s@^${CGROUP_CPU_BASE_PATH}/@@)
>                                 ^-- SC2046: Quote this to prevent word splitting.
>                                   ^-- SC2001: See if you can use ${variable//search/replace} instead.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 612d079086 tests/int/update.bats: fix a shellcheck warning
Fixes the following warning:

> In update.bats line 422:
>     local root_period=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us")
>           ^---------^ SC2155: Declare and assign separately to avoid masking return values.
>
>
> In update.bats line 423:
>     local root_runtime=$(cat "${CGROUP_CPU_BASE_PATH}/cpu.rt_runtime_us")
>           ^----------^ SC2155: Declare and assign separately to avoid masking return values.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 82836d2429 tests/int/cgroups.bats: fix a shellcheck warning
Fixes the following warning:

> In cgroups.bats line 58:
>     if [ "$KERNEL_MAJOR" -lt 4 ] || [ "$KERNEL_MAJOR" -eq 4 -a "$KERNEL_MINOR" -le 5 ]; then
>                                                             ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 4b8ff6a17c tests/int/checkpoint.bats: ignore some shellcheck warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin ce50e1da7e test/int/spec.bats: simplify setup/teardown
1. cd is useless as all the paths are absolute
2. run is redundant, does not make sense to use it
3. use mkdir -p to save a line of code

This also eliminates shellcheck warnings like this one:

> In spec.bats line 8:
>   cd "$INTEGRATION_ROOT"
>   ^--------------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 699fdf8952 tests/int/mount.bats: fix a check
It's not a regex but a substring, so use a substring match.

Fixes the following warning by shellcheck:

> In mounts.bats line 20:
> 	[[ "${lines[0]}" =~ '/tmp/bind/config.json' ]]
>                           ^---------------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Kir Kolyshkin 85a3069878 test/int/hooks.bats: fix here-doc
The ending EOF should be
 - all by itself (i.e. no extra characters on the same line);
 - with no whitespace before it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-10 07:41:49 -07:00
Mrunal Patel dedadbf9ea Merge pull request #2545 from kolyshkin/go-mod-vendor
Makefile: fix go vet/fmt
2020-08-10 07:41:04 -07:00
Mrunal Patel 809dc64041 Merge pull request #2548 from kolyshkin/int-cr-fix
tests/int: fix error handling and logging
2020-08-10 07:39:29 -07:00
Xiaodong Liu 7f64fb4786 use criu cgroup mode const from go-criu
Signed-off-by: Xiaodong Liu <liuxiaodong@loongson.cn>
2020-08-10 10:25:53 +08:00
Kir Kolyshkin 5026bfab9c tests/int: fix error handling and logging
TL;DR: this allows to show logs from failed runc restore.

Bats scripts are run with `set -e`. This is well known and obvious,
and yet there are a few errors with respect to that, including a few
"gems" by yours truly.

1. bats scripts are run with `set -e`, meaning that `[ $? -eq 0 ]` is
   useless since the execution won't ever reach this line in case of
   non-zero exit code from a preceding command. So, remove all such
   checks, they are useless and misleading.

2. bats scripts are run with `set -e`, meaning that `ret=$?` is useless
   since the execution won't ever reach this line in case of non-zero
   exit code from a preceding command.

In particular, the code that calls runc restore needs to save the exit
code, show the errors in the log, and only when check the exit code and
fail if it's non-zero. It can not use `run` (or `runc` which uses `run`)
because of shell redirection that we need to set up.

The solution, implemented in this patch, is to use code like this:

```bash
ret=0
__runc ... || ret=$?
show_logs
[ $ret -eq 0 ]
```

In case __runc exits with non-zero exit code, `ret=$?` is executed, and
it always succeeds, so we won't fail just yet and have a chance to show
logs before checking the value of $ret.

In case __runc succeeds, `ret=$?` is never executed, so $ret will still
be zero (this is the reason why it needs to be set explicitly).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-08 20:33:04 -07:00
Kir Kolyshkin 2de0b5aaf3 libct/integration: enable some tests for cgroupv2
The only two tests that are still skipped on v2 are kmem
and invalid CpuShares test -- since v2 does not support either.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-08 19:19:31 -07:00
Cesar Talledo 9a699e1a9f Skip redundant setup for /dev/ptmx when specified explicitly in the OCI spec.
Per the OCI spec, /dev/ptmx is always a symlink to /dev/pts/ptmx. As such, if
the OCI spec has an explicit entry for /dev/ptmx, runc shall ignore it.

This change ensures this is the case. A integration test was also added
(in tests/integration/dev.bats).

Signed-off-by: Cesar Talledo <ctalledo@nestybox.com>
2020-08-07 16:46:26 -07:00
Cesar Talledo 0709202da7 Remove runc default devices that overlap with spec devices.
Runc has a set of default devices that it includes in Linux containers
(e.g., /dev/null, /dev/random, /dev/tty, etc.)

However if the container's OCI spec includes all or a subset of those same devices,
runc is currently not detecting the redundancy, causing it to create a lib
container config that has redundant device configurations.

This causes a failure in rootless mode, in particular when the /dev/tty device
has a redundant config:

container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:70: creating device nodes caused: open /tmp/busyboxtest/rootfs/dev/tty: no such device or address"

The reason this fails in rootless mode only is that in this case runc sets up
/dev/tty not by doing mknod (it's not allowed within a user-ns) but rather by
creating a regular file under /dev/tty and bind-mounting the host's /dev/tty to
the container's /dev/tty. When this operation is done redundantly, it fails the
second time.

This change fixes this problem by ensuring runc checks for redundant devices
between the OCI spec it receives and the default devices it configures. If
a redundant device is detected, the OCI spec takes priority.

The change adds both a unit test and an integration test to verify the
behavior. Without this fix, this new integration test fails as shown above.

Signed-off-by: Cesar Talledo <ctalledo@nestybox.com>
2020-08-07 16:46:15 -07:00
Kir Kolyshkin 985bd24f62 Makefile: fix go vet/fmt
I have noticed that `go vet` from golang 1.13 ignores the vendor/
subdir, downloading all the modules when invoked in Travis CI env.

As the other go commands, in 1.13 it needs explicit -mod=vendor
flag, so let's provide one.

PS once golang 1.13 is unsupported, we will drop it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-08-06 19:18:09 -07:00
Kir Kolyshkin a340fa9b56 Merge pull request #2543 from mrunalp/release_1.0.0-rc92
Release 1.0.0 rc92
2020-08-05 21:49:10 -07:00
Mrunal Patel 1ff1bf3452 VERSION: back to development
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2020-08-05 09:34:30 -07:00
Mrunal Patel ff819c7e91 VERSION: release 1.0.0-rc92
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
v1.0.0-rc92
2020-08-05 09:26:49 -07:00