@@ -11,7 +11,7 @@ describe "Platform" do
11
11
it " 'control_plane_hardening' should pass if the control plane has been hardened" , tags: [" platform:security" ] do
12
12
response_s = ` ./cnf-testsuite platform:control_plane_hardening`
13
13
Log .info { response_s }
14
- (/(PASSED: Insecure port of Kubernetes API server is not enabled) / =~ response_s).should_not be_nil
14
+ (/(PASSED) .* ( Insecure port of Kubernetes API server is not enabled) / =~ response_s).should_not be_nil
15
15
end
16
16
17
17
it " 'cluster_admin' should fail on a cnf that uses a cluster admin binding" , tags: [" platform:security" ] do
@@ -21,18 +21,57 @@ describe "Platform" do
21
21
response_s = ` ./cnf-testsuite platform:cluster_admin`
22
22
LOGGING .info response_s
23
23
$? .success?.should be_true
24
- (/FAILED: Users with cluster-admin RBAC permissions found/ =~ response_s).should_not be_nil
24
+ (/( FAILED) .* ( Users with cluster-admin RBAC permissions found) / =~ response_s).should_not be_nil
25
25
# ensure
26
26
# `./cnf-testsuite cnf_cleanup cnf-config=./sample-cnfs/sample-privilege-escalation/cnf-testsuite.yml`
27
27
end
28
28
end
29
29
30
+ it " 'exposed_dashboard' should fail when the Kubernetes dashboard is exposed" , tags: [" platform:security" ] do
31
+ dashboard_install_url = " https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml"
32
+ begin
33
+ # Run the exposed_dashboard test to confirm no vulnerability before dashboard is installed
34
+ response_s = ` ./cnf-testsuite platform:exposed_dashboard`
35
+ (/(PASSED) .*(No exposed dashboard found in the cluster) / =~ response_s).should_not be_nil
36
+
37
+ # Install the dashboard version 2.0.0.
38
+ # According to the kubescape rule, anything less than v2.0.1 would fail.
39
+ KubectlClient ::Apply .file(dashboard_install_url)
40
+
41
+ # Construct patch spec to expose Kubernetes Dashboard on a Node Port
42
+ patch_spec = {
43
+ spec: {
44
+ type: " NodePort" ,
45
+ ports: [
46
+ {
47
+ nodePort: 30500 ,
48
+ port: 443 ,
49
+ protocol: " TCP" ,
50
+ targetPort: 8443
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ # Apply the patch to expose the dashboard on the NodePort
56
+ result = KubectlClient ::Patch .spec(" service" , " kubernetes-dashboard" , patch_spec.to_json, " kubernetes-dashboard" )
57
+
58
+ # Run the test again to confirm vulnerability with an exposed dashboard
59
+ response_s = ` ./cnf-testsuite platform:exposed_dashboard`
60
+ Log .info { response_s }
61
+ $? .success?.should be_true
62
+ (/(FAILED) .*(Found exposed dashboard in the cluster) / =~ response_s).should_not be_nil
63
+ ensure
64
+ # Ensure to remove the Kubectl dashboard after the test
65
+ KubectlClient ::Delete .file(dashboard_install_url)
66
+ end
67
+ end
68
+
30
69
it " 'helm_tiller' should fail if Helm Tiller is running in the cluster" , tags: [" platform:security" ] do
31
70
ShellCmd .run(" kubectl run tiller --image=rancher/tiller:v2.11.0" , " create_tiller" )
32
71
KubectlClient ::Get .resource_wait_for_install(" pod" , " tiller" )
33
72
response_s = ` ./cnf-testsuite platform:helm_tiller`
34
73
$? .success?.should be_true
35
- (/FAILED: Containers with the Helm Tiller image are running/ =~ response_s).should_not be_nil
74
+ (/( FAILED) .* ( Containers with the Helm Tiller image are running) / =~ response_s).should_not be_nil
36
75
ensure
37
76
KubectlClient ::Delete .command(" pod/tiller" )
38
77
KubectlClient ::Get .resource_wait_for_uninstall(" pod" , " tiller" )
@@ -42,6 +81,6 @@ describe "Platform" do
42
81
# By default we have nothing to setup for this task to pass since Helm v3 does not use Tiller.
43
82
response_s = ` ./cnf-testsuite platform:helm_tiller`
44
83
$? .success?.should be_true
45
- (/PASSED: No Helm Tiller containers are running/ =~ response_s).should_not be_nil
84
+ (/( PASSED) .* ( No Helm Tiller containers are running) / =~ response_s).should_not be_nil
46
85
end
47
86
end
0 commit comments