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

Commit

Permalink
Merge pull request #1009 from GabyCT/topic/security
Browse files Browse the repository at this point in the history
test: Add K8s test using a security context
  • Loading branch information
jodh-intel authored Dec 19, 2018
2 parents 994321e + aba5947 commit 36ed3d8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
36 changes: 36 additions & 0 deletions integration/kubernetes/k8s-security-context.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bats
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh"

setup() {
export KUBECONFIG=/etc/kubernetes/admin.conf
if sudo -E kubectl get runtimeclass | grep kata; then
pod_config_dir="${BATS_TEST_DIRNAME}/runtimeclass_workloads"
else
pod_config_dir="${BATS_TEST_DIRNAME}/untrusted_workloads"
fi
}

@test "Security context" {
pod_name="security-context-test"

# Create pod
sudo -E kubectl create -f "${pod_config_dir}/pod-security-context.yaml"

# Check pod creation
sudo -E kubectl wait --for=condition=Ready pod "$pod_name"

# Check user
cmd="ps --user 1000 -f"
process="tail -f /dev/null"
sudo -E kubectl exec $pod_name -- sh -c $cmd | grep "$process"
}

teardown() {
sudo -E kubectl delete pod "$pod_name"
}
1 change: 1 addition & 0 deletions integration/kubernetes/run_kubernetes_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bats k8s-credentials-secrets.bats
bats k8s-pid-ns.bats
bats k8s-cpu-ns.bats
bats k8s-parallel.bats
bats k8s-security-context.bats
bats k8s-memory.bats
bats k8s-liveness-probes.bats
bats k8s-attach-handlers.bats
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v1
kind: Pod
metadata:
name: security-context-test
spec:
runtimeClassName: kata
securityContext:
runAsUser: 1000
containers:
- name: sec-text
image: busybox
command: ["tail", "-f", "/dev/null"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v1
kind: Pod
metadata:
name: security-context-test
annotations:
io.kubernetes.cri-o.TrustedSandbox: "false"
io.kubernetes.cri.untrusted-workload: "true"
spec:
securityContext:
runAsUser: 1000
containers:
- name: sec-text
image: busybox
command: ["tail", "-f", "/dev/null"]

0 comments on commit 36ed3d8

Please sign in to comment.