Skip to content

Commit 60f5203

Browse files
committed
tests/int: add selinux test case
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9350f90 commit 60f5203

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

.cirrus.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ task:
5757
mkdir -p -m 0700 /root/.ssh
5858
vagrant ssh-config >> /root/.ssh/config
5959
guest_info_script: |
60-
ssh default 'sh -exc "uname -a && systemctl --version && df -T && cat /etc/os-release && go version"'
60+
ssh default 'sh -exc "uname -a && systemctl --version && df -T && cat /etc/os-release && go version; sestatus; ls -lZ /"'
6161
check_config_script: |
6262
ssh default /vagrant/script/check-config.sh
6363
unit_tests_script: |
@@ -79,7 +79,7 @@ task:
7979
CIRRUS_WORKING_DIR: /home/runc
8080
GO_VERSION: "1.20"
8181
BATS_VERSION: "v1.9.0"
82-
RPMS: gcc git iptables jq glibc-static libseccomp-devel make criu fuse-sshfs
82+
RPMS: gcc git iptables jq glibc-static libseccomp-devel make criu fuse-sshfs container-selinux
8383
# yamllint disable rule:key-duplicates
8484
matrix:
8585
DISTRO: centos-7
@@ -170,6 +170,10 @@ task:
170170
# -----
171171
df -T
172172
# -----
173+
sestatus
174+
# -----
175+
ls -lZ /
176+
# -----
173177
cat /proc/cpuinfo
174178
check_config_script: |
175179
/home/runc/script/check-config.sh

Vagrantfile.fedora

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Vagrant.configure("2") do |config|
2323
cat << EOF | dnf -y --exclude=kernel,kernel-core shell && break
2424
config install_weak_deps false
2525
update
26-
install iptables gcc golang-go make glibc-static libseccomp-devel bats jq git-core criu fuse-sshfs
26+
install iptables gcc golang-go make glibc-static libseccomp-devel bats jq git-core criu fuse-sshfs container-selinux
2727
ts run
2828
EOF
2929
done

tests/integration/selinux.bats

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
requires root # for chcon
7+
if ! selinuxenabled; then
8+
skip "requires SELinux enabled and in enforcing mode"
9+
fi
10+
11+
# FIXME this should be done elsewhere!
12+
chcon -u system_u -r object_r -t container_runtime_exec_t "$(readlink -f "${INTEGRATION_ROOT}/../../runc")"
13+
14+
setup_busybox
15+
if ! chcon -u system_u -r object_r -t container_file_t -R rootfs; then
16+
skip "chcon failed"
17+
fi
18+
}
19+
20+
function teardown() {
21+
teardown_bundle
22+
grep denied /var/log/audit/audit.log | tail
23+
}
24+
25+
@test "runc run (no selinux label)" {
26+
update_config ' .process.args = ["/bin/true"]'
27+
runc run tst
28+
[ "$status" -eq 0 ]
29+
}
30+
31+
@test "runc run (custom selinux label)" {
32+
update_config ' .process.selinuxLabel |= "system_u:system_r:container_t:s0:c4,c5"
33+
| .process.args = ["/bin/true"]'
34+
runc run tst
35+
[ "$status" -eq 0 ]
36+
}
37+
38+
@test "runc run (custom selinux label, RUNC_DMZ=legacy)" {
39+
export RUNC_DMZ=legacy
40+
update_config ' .process.selinuxLabel |= "system_u:system_r:container_t:s0:c4,c5"
41+
| .process.args = ["/bin/true"]'
42+
runc run tst
43+
[ "$status" -eq 0 ]
44+
}

0 commit comments

Comments
 (0)