This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1009 from GabyCT/topic/security
test: Add K8s test using a security context
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
integration/kubernetes/runtimeclass_workloads/pod-security-context.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
19 changes: 19 additions & 0 deletions
19
integration/kubernetes/untrusted_workloads/pod-security-context.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |