Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,18 @@ function ping_pod_from_pod() {
# in such an environment without giving all containers NET_RAW capability
# rather than reducing the security of the tests for all cases, skip this check
# instead
if grep -i 'Red Hat\|CentOS' /etc/redhat-release | grep -q " 7"; then
if is_rhel_7; then
return
fi

ip=$(pod_ip -6 "$1")
crictl exec --sync "$2" ping6 -W 1 -c 2 "$ip"
}

function is_rhel_7() {
grep -i 'Red Hat\|CentOS' /etc/redhat-release | grep -q " 7"
}

function cleanup_network_conf() {
rm -rf "$CRIO_CNI_CONFIG"
}
Expand Down
24 changes: 16 additions & 8 deletions test/selinux.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ function teardown() {
if [[ $(getenforce) != "Enforcing" ]]; then
skip "not enforcing"
fi

# RHEL/CentOS 7's container-selinux package replaces container_file_t with svirt_sandbox_file_t
# under the hood. This causes the annotation to not work correctly.
if is_rhel_7; then
skip "fails on RHEL 7 or earlier"
fi

VOLUME="$TESTDIR"/dir
FILE="$VOLUME"/file
mkdir "$VOLUME"
touch "$VOLUME"/file
touch "$FILE"

create_runtime_with_allowed_annotation "selinux" "io.kubernetes.cri-o.TrySkipVolumeSELinuxLabel"
start_crio
Expand All @@ -49,19 +57,19 @@ function teardown() {

crictl rm "$ctr_id"

# shellcheck disable=SC2012
oldlabel=$(ls -Z "$VOLUME" | awk '{ printf $1 }')
# shellcheck disable=SC2010
oldlabel=$(ls -Z "$FILE" | grep -o '[a-z,_]*_u:[a-z,_]*_r:[a-z,_]*_t:[c,s,0-9,:,\,]* ')

# Label file, but not top dir. This will show us the directory was not relabeled (as expected)
chcon --reference "$TESTDIR"/container.json "$VOLUME"/file # || \
chcon --reference "$TESTDIR"/container.json "$FILE" # || \

# shellcheck disable=SC2012
label=$(ls -Z "$VOLUME" | awk '{ printf $1 }')
# shellcheck disable=SC2010
label=$(ls -Z "$FILE" | grep -o '[a-z,_]*_u:[a-z,_]*_r:[a-z,_]*_t:[c,s,0-9,:,\,]* ')
[[ "$oldlabel" != "$label" ]]

# Recreate. Since top level is already labeled right, there won't be a relabel.
ctr_id=$(crictl create "$pod_id" "$TESTDIR"/container.json "$TESTDIR"/sandbox.json)
# shellcheck disable=SC2012
newlabel=$(ls -Z "$VOLUME" | awk '{ printf $1 }')
# shellcheck disable=SC2010
newlabel=$(ls -Z "$FILE" | grep -o '[a-z,_]*_u:[a-z,_]*_r:[a-z,_]*_t:[c,s,0-9,:,\,]* ')
[[ "$label" == "$newlabel" ]]
}