Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 36ed3d8

Browse files
authored
Merge pull request #1009 from GabyCT/topic/security
test: Add K8s test using a security context
2 parents 994321e + aba5947 commit 36ed3d8

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright (c) 2018 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh"
9+
10+
setup() {
11+
export KUBECONFIG=/etc/kubernetes/admin.conf
12+
if sudo -E kubectl get runtimeclass | grep kata; then
13+
pod_config_dir="${BATS_TEST_DIRNAME}/runtimeclass_workloads"
14+
else
15+
pod_config_dir="${BATS_TEST_DIRNAME}/untrusted_workloads"
16+
fi
17+
}
18+
19+
@test "Security context" {
20+
pod_name="security-context-test"
21+
22+
# Create pod
23+
sudo -E kubectl create -f "${pod_config_dir}/pod-security-context.yaml"
24+
25+
# Check pod creation
26+
sudo -E kubectl wait --for=condition=Ready pod "$pod_name"
27+
28+
# Check user
29+
cmd="ps --user 1000 -f"
30+
process="tail -f /dev/null"
31+
sudo -E kubectl exec $pod_name -- sh -c $cmd | grep "$process"
32+
}
33+
34+
teardown() {
35+
sudo -E kubectl delete pod "$pod_name"
36+
}

integration/kubernetes/run_kubernetes_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bats k8s-credentials-secrets.bats
3131
bats k8s-pid-ns.bats
3232
bats k8s-cpu-ns.bats
3333
bats k8s-parallel.bats
34+
bats k8s-security-context.bats
3435
bats k8s-memory.bats
3536
bats k8s-liveness-probes.bats
3637
bats k8s-attach-handlers.bats
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (c) 2018 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
apiVersion: v1
7+
kind: Pod
8+
metadata:
9+
name: security-context-test
10+
spec:
11+
runtimeClassName: kata
12+
securityContext:
13+
runAsUser: 1000
14+
containers:
15+
- name: sec-text
16+
image: busybox
17+
command: ["tail", "-f", "/dev/null"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2018 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
apiVersion: v1
7+
kind: Pod
8+
metadata:
9+
name: security-context-test
10+
annotations:
11+
io.kubernetes.cri-o.TrustedSandbox: "false"
12+
io.kubernetes.cri.untrusted-workload: "true"
13+
spec:
14+
securityContext:
15+
runAsUser: 1000
16+
containers:
17+
- name: sec-text
18+
image: busybox
19+
command: ["tail", "-f", "/dev/null"]

0 commit comments

Comments
 (0)