1 ##############################################################################
2 # Copyright (c) 2020 AT&T Intellectual Property. #
3 # Copyright (c) 2020 Nokia. #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you maynot use this file except in compliance with the License. #
8 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ##############################################################################
21 Library OperatingSystem
28 ${REPORTDIR} ${LOG_PATH}/${SUITE_NAME.replace(' ','_')}
29 &{KUBE_HUNTER} path=akraino
30 ... name=validation:kube-hunter-latest
34 Open Connection And Log In
35 Open Connection ${HOST}
36 Run Keyword IF '${SSH_KEYFILE}' != 'None' Login With Public Key ${USERNAME} ${SSH_KEYFILE} ELSE IF '${PASSWORD}' != 'None' Login ${USERNAME} ${PASSWORD} ELSE FAIL
39 ${result}= Run Process kubectl config view --minify
40 ... -o jsonpath\={.clusters[0].cluster.server}
41 Should Be Equal As Integers ${result.rc} 0
42 ${addr}= Fetch From Right ${result.stdout} ://
43 ${addr}= Fetch From Left ${addr} :
44 Should Not Be Empty ${addr}
48 ${result}= Run Process kubectl get nodes
49 ... -o jsonpath\={.items[*].status.addresses[?(@.type\=\="ExternalIP")].address}
50 Should Be Equal As Integers ${result.rc} 0
51 Pass Execution If '${result.stdout}' == '${EMPTY}' No external node IPs exposed
52 @{addrs}= Split String ${result.stdout}
55 Upload To Internal Registry
56 [Arguments] ${path} ${name}
57 ${rc}= Execute Command
58 ... docker pull ${path}/${name}
59 ... return_stdout=False return_rc=True
60 Should Be Equal As Integers ${rc} 0
61 ${rc}= Execute Command
62 ... docker tag ${path}/${name} ${INT_REG}/bluval/${name}
63 ... return_stdout=False return_rc=True
64 Should Be Equal As Integers ${rc} 0
65 ${rc}= Execute Command
66 ... docker push ${INT_REG}/bluval/${name}
67 ... return_stdout=False return_rc=True
68 Should Be Equal As Integers ${rc} 0
71 ${INT_REG}= Get Variable Value ${INTERNAL_REGISTRY} ${EMPTY}
72 Set Test Variable ${INT_REG}
73 Return From Keyword If $INT_REG == '${EMPTY}'
74 Open Connection And Log In
75 Upload To Internal Registry ${KUBE_HUNTER['path']} ${KUBE_HUNTER['name']}
76 Set To Dictionary ${KUBE_HUNTER} path=${INT_REG}/bluval
79 Run Process sed -i s|{{ image }}|${KUBE_HUNTER['path']}/${KUBE_HUNTER['name']}|g
80 ... ${CURDIR}/job.yaml
84 ${STATUS}= Evaluate "No vulnerabilities were found" in """${log}"""
85 Set Test Variable ${STATUS}
88 ${result}= Run Process kubectl delete job kube-hunter
89 Should Be Equal As Integers ${result.rc} 0
91 Should Discover No Vulnerabilities
92 Return From Keyword If ${STATUS}
93 Fail Vulnerabilities discovered
97 ${result}= Run Process kubectl apply -f ${CURDIR}/job.yaml
98 Should Be Equal As Integers ${result.rc} 0
99 ${result}= Run Process kubectl wait --for\=condition\=complete
100 ... --timeout\=15m job/kube-hunter
101 Should Be Equal As Integers ${result.rc} 0
102 ${result}= Run Process kubectl get pods --selector\=job-name\=kube-hunter
103 ... -o jsonpath\={.items[*].metadata.name}
104 Should Be Equal As Integers ${result.rc} 0
105 ${result}= Run Process kubectl logs ${result.stdout}
107 Copy File pod.log ${REPORTDIR}/
108 Should Be Equal As Integers ${result.rc} 0
109 Set Scan Status ${result.stdout}
112 ${addrs}= Get Remote Addresses
113 ${result}= Run Process kube-hunter --remote @{addrs}
115 Copy File node.log ${REPORTDIR}/
116 Should Be Equal As Integers ${result.rc} 0
117 Set Scan Status ${result.stdout}
120 ${addr}= Get Cluster Address
121 ${result}= Run Process kube-hunter --remote ${addr}
122 ... stdout=cluster.log
123 Copy File cluster.log ${REPORTDIR}/
124 Should Be Equal As Integers ${result.rc} 0
125 Set Scan Status ${result.stdout}