From df77dbc9ddce9c3e0d9ba0c79b789cd6ee0417dd Mon Sep 17 00:00:00 2001 From: mrichomme Date: Fri, 18 Sep 2020 16:50:03 +0200 Subject: Add xfail list for test on pod limits Note: a waiver shall be created (and merged) in SECCOM repo before we can merge this patch Issue-ID: INT-1722 Signed-off-by: mrichomme Change-Id: I1d064275e9b90574e8b90c733d0dcc9b6f2bed74 Signed-off-by: mrichomme --- security/scripts/check_unlimitted_pods.sh | 62 ++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'security/scripts/check_unlimitted_pods.sh') diff --git a/security/scripts/check_unlimitted_pods.sh b/security/scripts/check_unlimitted_pods.sh index fdef6f3..1fc5e69 100644 --- a/security/scripts/check_unlimitted_pods.sh +++ b/security/scripts/check_unlimitted_pods.sh @@ -1,4 +1,40 @@ #!/bin/bash +usage() { + cat < [-l ] + -l: unlimitted pod xfail file +EOF + exit ${1:-0} +} + +if [ "$#" -lt 1 ]; then + usage + exit 1 +fi + +K8S_NAMESPACE=$1 +FILTERED_PODS_LIST=$(mktemp unlimitted_pods_XXXXXX) +WL_RAW_FILE_PATH=$(mktemp raw_filtered_unlimitted_XXXXXX) + +manage_list() { + # init filtered port list file + if [ ! -f $WL_FILE_PATH ];then + echo "File not found" + usage + fi + grep -o '^[^#]*' $WL_FILE_PATH > $WL_RAW_FILE_PATH +} + +### getopts +while : +do + case $2 in + -h|--help|help) usage;; + -l) WL_FILE_PATH=$3;manage_list;shift;; + -*) usage 1 ;; + *) break ;; + esac +done echo "------------------------------------------------------------------------" echo "-------------------- ONAP Security tests ----------------------------" @@ -8,19 +44,35 @@ echo "------------------------------------------------------------------------" code=0 # get the pod list -for pod in `kubectl get pod -n onap|grep -v "NAME"|grep "Running\|Completed" |grep -v functest |grep -v integration | awk '{print $1}'`;do +for pod in `kubectl get pod -n $K8S_NAMESPACE |grep -v "NAME"|grep "Running\|Completed" |grep -v functest |grep -v integration | awk '{print $1}'`;do kubectl describe pod $pod -n onap|grep "Limits"; if [ $? == 1 ] ; then echo $pod ; fi; -done | grep -v Limits > NoLimitContainer.txt +done | grep -v Limits > $FILTERED_PODS_LIST + +while IFS= read -r line; do + # for each line we test if it is in the white list with a regular expression + while IFS= read -r wl_line; do + wl_name=$(echo $wl_line | awk {'print $1'}) + if grep -e $K8S_NAMESPACE-$wl_name <<< "$line" > /dev/null ;then + # Found in white list, exclude it + sed -i "/$line/d" $FILTERED_PODS_LIST + fi + # tmp ugly workaround to exlude dep (temporary dcae dockers) + if grep -e dep-$wl_name <<< "$line" > /dev/null ;then + sed -i "/$line/d" $FILTERED_PODS_LIST + fi + done < $WL_RAW_FILE_PATH +done < $FILTERED_PODS_LIST + -if [ -s NoLimitContainer.txt ] +if [ -s $FILTERED_PODS_LIST ] then code=1 - nb_errors=`cat NoLimitContainer.txt | wc -l` + nb_errors=`cat $FILTERED_PODS_LIST | wc -l` echo "Test FAIL: $nb_errors pod(s) launched without limit" - cat NoLimitContainer.txt + cat $FILTERED_PODS_LIST else echo "Test PASS: No pod launched without limit" fi -- cgit 1.2.3-korg