diff --git a/defaults/main.yml b/defaults/main.yml index fcbbd797e3066ecc39c7e215d256b19458b64aa5..1b8463d9d55acca38b2f2597cb856dbfd2d28bc0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,6 @@ --- # defaults file for paas-ci paas_ci_orchestrator_url: https://paas.cloud.infn.it/orchestrator +paas_ci_iam_group: admins/cicd paas_ci_workdir: "{{ lookup('env','WORKSPACE') }}" -python3_script_path: 'python3 /home/gmp/.ansible/roles/paas-ci/utils/script.py' +paas_ci_scan_script_path: '/opt/scan.py' diff --git a/tasks/1-create-deployment.yml b/tasks/1-create-deployment.yml index 90830b79aaef3eedf018e2be0b3c1e74f6e71a2e..65a2ab411ea39347bc8a4ca30310cbbea277c0d2 100644 --- a/tasks/1-create-deployment.yml +++ b/tasks/1-create-deployment.yml @@ -1,3 +1,4 @@ +--- - name: Get template get_url: url: "{{ paas_ci_test.template_url }}" @@ -5,7 +6,7 @@ - name: Deployment command set_fact: - depcreate_cmd: "orchent depcreate --ojson template.yaml -g admins/beta-testers {{ paas_ci_test.inputs }}" + depcreate_cmd: "orchent depcreate --ojson template.yaml -g {{ paas_ci_iam_group }} {{ paas_ci_test.inputs }}" - name: Create the deployment command: "{{ depcreate_cmd }}" diff --git a/tasks/2-scan.yml b/tasks/2-scan.yml index 247dd2540bf63492794f5c650425fb21c0e1992b..eced4afcb9042205d73739bc4c1b41bf5a291d80 100644 --- a/tasks/2-scan.yml +++ b/tasks/2-scan.yml @@ -1,29 +1,13 @@ -- name: "Ping scans" - shell: - cmd: "ping -c1 -w 2 {{ pinging_host }}" - register: pingged_host - ignore_errors: yes - with_items: - - scans.cloud.infn.it - loop_control: - loop_var: pinging_host - -- name: "Result ping" - debug: - var: pingged_host - -- name: " ***Ip ping" - debug: - msg: "{{ pingged_host.results|map(attribute='rc')|list }}" +--- - name: Set SSH tunnel - command: ssh -f -N -L localhost:9390:192.168.187.162:9390 jenkins@scans.cloud.infn.it + command: ssh -o StrictHostKeyChecking=no -f -N -L localhost:9390:192.168.187.162:9390 jenkins@scans.cloud.infn.it - debug: - var: endpoints_to_scan + var: paas_ci_test.endpoints_to_scan - name: Run scan - command: "{{ python3_script_path }} {{ endpoints_to_scan }} {{ paas_ci_workdir + '/dep.json'}} {{ paas_ci_workdir }}" + command: "python3 {{ paas_ci_scan_script_path }} {{ paas_ci_test.endpoints_to_scan }} {{ paas_ci_workdir + '/dep.json'}} {{ paas_ci_workdir }}" register: scan_output - name: Find report files @@ -32,10 +16,10 @@ patterns: '*report.txt' register: report_files -- name: Show reports - debug: - msg: "{{lookup('file', item.path)}}" - with_items: "{{report_files.files}}" +# - name: Show reports +# debug: +# msg: "{{lookup('file', item.path)}}" +# with_items: "{{report_files.files}}" - name: get Severity file content shell: cat "{{ paas_ci_workdir + '/severity.json'}}" diff --git a/tasks/3-clean.yml b/tasks/3-clean.yml index f7160427501b3cce483b22f3f096c9eff386a421..3cc84ab4c03b817e67d93341bf42760c26104f28 100644 --- a/tasks/3-clean.yml +++ b/tasks/3-clean.yml @@ -1,3 +1,4 @@ +--- - set_fact: deployment: "{{ lookup('file', paas_ci_workdir + '/dep.json') }}" diff --git a/tasks/main.yml b/tasks/main.yml index 1e8fdd3b2490bf0d1dae11ec639c96e02b41fdcb..870726a391686607dc31dc2e1422c9b28f0157e9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,7 +11,7 @@ when: paas_ci_test_step == 'create_deployment' - include: 2-scan.yml - when: paas_ci_test_step == 'scan' + when: paas_ci_test_step == 'scan' and paas_ci_test.endpoints_to_scan is defined - include: 3-clean.yml when: paas_ci_test_step == 'clean' \ No newline at end of file diff --git a/tests/test-jupyter-vm.yml b/tests/test-jupyter-vm.yml index 7f93420e38fec8ea10e96e490c22f3e1187e004c..bb346a7ee3f8c56c1a9292353e99c6f7ef8451a6 100644 --- a/tests/test-jupyter-vm.yml +++ b/tests/test-jupyter-vm.yml @@ -13,6 +13,6 @@ paas_ci_test: template_url: https://baltig.infn.it/infn-cloud/tosca-templates/-/raw/master/jupyter/jupyter_vm.yaml inputs: | - '{ "users": [{"os_user_add_to_sudoers": true, "os_user_name": "scans", "os_user_ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCmQvE3sXtg4D/KYzhCdP6cICvy5foeSkHenKTisxdGJK8L0cDmV+4k7fIah1GIXrldjQBGWHSTbIj1qRTXG2OPWFxeDoXIN1FyKxwdOgwIfzIRtVq18VZEqt9eOiNUXN8jGoEAgcU7obqXuPqKAndk4tyOnSDuVnfnZWAiesVvWK16GEq0PAxBhJoX3eq501ilsNnJZDMEnvQEgtFuIbADEanrhRV3yaEca+9vFyOQRkyxDF8Gn6P/wZ4oe35bdgXxi/hg8JVKYbDCLlT+Fdi+OC3trRhwCcBSvDFD0ZQ8oLemzUk+732TqR+I8gVjPE9fiNF+/mrj5OX55SDr8Qgf scans"}]}' + '{ "enable_monitoring": "true", "users": [{"os_user_add_to_sudoers": true, "os_user_name": "scans", "os_user_ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCmQvE3sXtg4D/KYzhCdP6cICvy5foeSkHenKTisxdGJK8L0cDmV+4k7fIah1GIXrldjQBGWHSTbIj1qRTXG2OPWFxeDoXIN1FyKxwdOgwIfzIRtVq18VZEqt9eOiNUXN8jGoEAgcU7obqXuPqKAndk4tyOnSDuVnfnZWAiesVvWK16GEq0PAxBhJoX3eq501ilsNnJZDMEnvQEgtFuIbADEanrhRV3yaEca+9vFyOQRkyxDF8Gn6P/wZ4oe35bdgXxi/hg8JVKYbDCLlT+Fdi+OC3trRhwCcBSvDFD0ZQ8oLemzUk+732TqR+I8gVjPE9fiNF+/mrj5OX55SDr8Qgf scans"}]}' endpoints_to_scan: | - jupyter_notebook,grafana_endpoint \ No newline at end of file + jupyter_endpoint,grafana_endpoint \ No newline at end of file diff --git a/tests/test-simple-node.yml b/tests/test-simple-node.yml index 764c65f89c037f78aaf77ea99145f1d24588b8a9..908d5f1602b4191b103cf85ba3a4f3ffebff1b38 100644 --- a/tests/test-simple-node.yml +++ b/tests/test-simple-node.yml @@ -13,4 +13,4 @@ paas_ci_test: template_url: https://baltig.infn.it/infn-cloud/tosca-templates/-/raw/master/single-vm/single_vm.yaml inputs: | - '{ "users": [{"os_user_add_to_sudoers": true, "os_user_name": "antonacci", "os_user_ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE887DQ8WcX5f8d9/MakzMhG/QovKzjrgDzJ0CwjxKm3kUYildhPcUtj7k73WdcP06st6cWpxQ+7HmFseuX+1GASorENAqMHbOvoT0K6pkNlgwgyDOYdR5JSnXIEfR7gTE391SuYN8lbLEvFCscNHYP6814tYochO+sSlpa3XJ2nHvvVp4Ikt/X2Q+zidkKzuMUwFeGf4MZz93Nlwcbg3UM+ENEjjksb7Rqxx2WtYAv8Gn6Jr1X3PmvMoaO9HBgZaosp7NXh20LRHJW+aiEKcr+vzFlgUjTcd/h2CrkgS6+AhjKqpMNS1sS/QuOvPVMUNr1dSOkmAR5EwfHcXpY9RL marica@MacBook-Air-di-marica.local"}]}' + '{ "users": [{"os_user_add_to_sudoers": true, "os_user_name": "scans", "os_user_ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCmQvE3sXtg4D/KYzhCdP6cICvy5foeSkHenKTisxdGJK8L0cDmV+4k7fIah1GIXrldjQBGWHSTbIj1qRTXG2OPWFxeDoXIN1FyKxwdOgwIfzIRtVq18VZEqt9eOiNUXN8jGoEAgcU7obqXuPqKAndk4tyOnSDuVnfnZWAiesVvWK16GEq0PAxBhJoX3eq501ilsNnJZDMEnvQEgtFuIbADEanrhRV3yaEca+9vFyOQRkyxDF8Gn6P/wZ4oe35bdgXxi/hg8JVKYbDCLlT+Fdi+OC3trRhwCcBSvDFD0ZQ8oLemzUk+732TqR+I8gVjPE9fiNF+/mrj5OX55SDr8Qgf scans"}]}' \ No newline at end of file diff --git a/utils/Dockerfile b/utils/Dockerfile index e75e4ce1fd6eecb689674a6414f031db6522f295..5727b859a75bcd629efa8108a6172b924562e782 100644 --- a/utils/Dockerfile +++ b/utils/Dockerfile @@ -1,48 +1,13 @@ FROM jenkins/ssh-agent:4.1.0 ARG ORCHENT_VERSION=1.2.9 -ARG LIBQRENCODE_PATH=/tmp/libqrencode.deb RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - gnupg2 \ - apt-utils \ - software-properties-common \ - wget \ - git \ - ansible \ - python3-pip \ - iproute2 \ - net-tools \ - dialog \ - vim \ - openssh-client \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -RUN DEBIAN_FRONTEND=noninteractive \ - && wget -O ${LIBQRENCODE_PATH} http://archive.ubuntu.com/ubuntu/pool/universe/q/qrencode/libqrencode3_3.4.4-1build1_amd64.deb \ - && dpkg -i ${LIBQRENCODE_PATH} && rm -f ${LIBQRENCODE_PATH} \ - && apt-key adv --keyserver hkp://pgp.surfnet.nl --recv-keys ACDFB08FDC962044D87FF00B512839863D487A87 \ - && add-apt-repository "deb http://repo.data.kit.edu/ubuntu/bionic ./" - -RUN DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get install -y oidc-agent \ + && apt-get install -y wget git ansible python3-pip iproute2 iputils-ping \ && wget https://github.com/indigo-dc/orchent/releases/download/v${ORCHENT_VERSION}/orchent_${ORCHENT_VERSION}_amd64.deb \ && dpkg -i orchent_${ORCHENT_VERSION}_amd64.deb \ - && pip install gvm-tools jq yq \ && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN useradd -ms /bin/bash gmp \ - && mkdir /home/gmp/.ssh +RUN pip install gvm-tools jq yq -RUN chown -R gmp:gmp /home/gmp /tmp \ - && chown gmp:gmp /etc/environment \ - && export PATH=$PATH:~/.local/bin - -USER gmp - -RUN eval `oidc-agent-service start` - -WORKDIR /home/gmp - +COPY script.py /opt/scan.py \ No newline at end of file diff --git a/utils/Jenkinsfile b/utils/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..88f4f26b67f62e6f7ffe387fdacae2713432a255 --- /dev/null +++ b/utils/Jenkinsfile @@ -0,0 +1,51 @@ +pipeline { + agent { label 'docker-paas-agent' } + + options { + timestamps() + } + + environment { + ORCHENT_AGENT_ACCOUNT='infn-cloud' + ORCHENT_URL='https://my.cloud.infn.it/orchestrator' + } + + stages { + stage ('Create test deployment'){ + steps { + sh '''#!/bin/bash + wget -O site.yaml "${PLAYBOOK_URL}" + ansible-playbook site.yaml --extra-vars "paas_ci_test_step='create_deployment'" + + ''' + } + } + stage ('Scan endpoints'){ + steps { + withCredentials([ + sshUserPrivateKey(credentialsId: "ssh_scans", keyFileVariable: 'keyfile'), + usernamePassword(credentialsId: "jenkins_scans_creds", usernameVariable: 'GMP_USER', passwordVariable: 'GMP_PASSWORD') + ]) { + sh '''#!/bin/bash + cp ${keyfile} /home/jenkins/.ssh/id_rsa + ansible-playbook site.yaml --extra-vars "paas_ci_test_step='scan'" + + ''' + } + } + post { + failure { + archiveArtifacts artifacts: '*report.txt', allowEmptyArchive: true + emailext attachmentsPattern: '*report.txt', body: '$DEFAULT_CONTENT', subject: '$PROJECT_NAME - Build # $BUILD_NUMBER: Vulnerabilities detected!', to: '$DEFAULT_RECIPIENTS' + } + } + } + } + post { + always { + sh '''#!/bin/bash + ansible-playbook site.yaml --extra-vars "paas_ci_test_step='clean'" + ''' + } + } +} \ No newline at end of file diff --git a/utils/script.py b/utils/script.py index d181f83a85135def42607b80240d7b0146fca50c..253eee6ab39beaaf5322f8fb070803e506dc0076 100644 --- a/utils/script.py +++ b/utils/script.py @@ -399,7 +399,8 @@ auth_name = os.getenv('GMP_USER') auth_passwd = os.getenv('GMP_PASSWORD') print(auth_name, auth_passwd) logging.basicConfig(filename='debug.log', level=logging.DEBUG) -local_ip = socket.gethostbyname(socket.gethostname()) +#local_ip = socket.gethostbyname(socket.gethostname()) +local_ip = '127.0.0.1' connection = TLSConnection(hostname=local_ip) transform = EtreeTransform() config = {'id':"9866edc1-8869-4e80-acac-d15d5647b4d9"}