Application Security in Continuous Delivery
Total Page:16
File Type:pdf, Size:1020Kb
Application Security in Continuous Delivery Fábio Freitas Master’s Degree in Information Security Departament of Computer Science 2020 Orientador Prof. Dr. Eduardo R. B. Marques, Faculty of Sciences of University of Porto Coorientador Eng. Pedro Borges, LOQR S.A. Todas as correções determinadas pelo júri, e só essas, foram efetuadas. O Presidente do Júri, Porto, / / UNIVERSIDADE DO PORTO MASTERS THESIS Application Security in Continuous Delivery Author: Supervisor: Fábio FREITAS Eduardo R. B. MARQUES Co-supervisor: Pedro BORGES A thesis submitted in fulfilment of the requirements for the degree of MSc. Information Security at the Faculdade de Ciências da Universidade do Porto November 25, 2020 Acknowledgements Firstly, I would like to thank my thesis supervisors Prof. Dr. Eduardo R. B. Marques and Eng. Pedro Borges, whose expertise and guidance throughout the entire project proved itself invaluable. Secondly, I would like to thank my co-workers at Euronext, in special to my two mentors and good friends Duarte Monteiro and Ricardo Gonçalves, both alumni of this department and experts in this subject. I’m lucky to have worked alongside you two and to have learned so much from both of you. Then to all my friends, specially to my colleagues at the Information Security Master’s Degree André Cirne and Nuno Lopes, who taught me a lot in the past two years, and helped me grow as both a student and more recently, as a professional of the Information Security field. And lastly, and most importantly, to my family - most of all to my parents and siblings - who have been there for me for all of my academic journey and allowed me this opportunity to pursue and now work in a field that I’m passionate about. iii Abstract In the last few years, software development has seen a shift regarding the gap between the development and operation activities, with more and more focus with automating the building, testing and deployment of the application in what is usually called the Continuous Integration/Continuous Delivery process. However, this process has still few concerns with security in the real world. This thesis studies and implements security checks on top of a standard software delivery pipeline using a modular approach and considering a wide range of security checks of both Static and Dynamic nature. This framework is then instantiated for two different applications written in two different programming languages and the results are analyzed. Keywords: Application Security, Software Delivery Automation, Security Automation, De- vOps, DevSecOps v Resumo Nos últimos anos, o desenvolvimento de software tem sofrido mudanças no que toca à distância entre as desenvolvimento e as atividades das operações, com cada vez mais foco na automação do building, dos testes e do deployment das aplicações, no processo que é chamado Integração Contínua / Entrega Contínua (CI/CD). No entanto, no mundo real, este processo ainda considera muito poucas preocupações com a segurança das aplicações. Nesta tese será feito o estudo e implementação de validações de segurança assentes em cima de uma software delivery pipeline padrão utilizando uma abordagem modular com um leque vasto de validações de segurança distintas, de natureza estática e dinâmica. Esta framework é depois instanciada em duas aplicações escritas em duas linguagens diferentes, e os respetivos resultados analisados. Palavras-chave: Segurança Aplicacional, Automação de Segurança, Integração Contínua, DevOps, DevSecOps vii Contents Acknowledgements iii Abstract v Resumo vii Contents vii List of Figures xi List of Tables xiii 1 Introduction 1 1.1 Problem statement....................................1 1.2 Contributions.......................................2 1.3 Thesis structure......................................2 2 State of the Art3 2.1 DevOps...........................................4 2.1.1 Software Version Control............................5 2.1.2 GitLab.......................................6 2.1.3 Continuous Integration.............................6 2.1.4 Continuous Delivery...............................6 2.2 Containers.........................................7 2.2.1 Docker.......................................8 2.2.2 Container Security................................9 2.3 Application Security................................... 10 2.3.1 OWASP...................................... 10 2.3.2 Static Application Security Testing (SAST).................. 11 2.3.3 Source-Code Analysis.............................. 11 2.3.4 Secrets Scanning................................. 12 2.3.5 Dependency Scanning.............................. 13 2.3.6 Dynamic Application Security Testing (DAST)................ 13 2.4 Vulnerability Management................................ 14 2.4.1 DefectDojo..................................... 15 2.5 Integrating Security Checks in a CI/CD Pipeline................... 15 3 Implementation 17 ix x APPLICATION SECURITY IN CONTINUOUS DELIVERY 3.1 Architecture........................................ 17 3.2 Setting up the environment............................... 20 3.2.1 Software Versioning Control System - GitLab ................ 21 3.2.2 Automation Server - Gitlab CI/CD + Runner ................ 21 3.3 Implementing the Secure Pipeline........................... 24 3.3.1 Baseline...................................... 24 3.3.2 Integrating Source-Code Analysis - Sonarqube ............... 28 3.3.3 Integrating DAST - Zed Attack Proxy ..................... 32 3.3.4 Integrating Container Scanning - Clair .................... 36 3.3.5 Integrating Secrets Scanning - Gitleaks .................... 38 3.3.6 Integrating Dependency Checks - OWASP Dependency Checker ..... 41 3.3.7 Integrating a results aggregator (custom script) - build_risk_calc.py ... 44 3.3.8 Integrating a Vulnerability Tracker - DefectDojo ............... 47 4 Results 55 4.1 Instantiation 1 - Java Vulnerable Lab - Java...................... 55 4.1.1 Vulnerabilities................................... 56 4.1.2 Performance.................................... 56 4.2 Instantiation 2 - OWASP Juice Shop - JavaScript/NodeJS.............. 57 4.2.1 Vulnerabilities................................... 58 4.2.2 Performance.................................... 58 5 Conclusion 61 5.1 Concluding Remarks................................... 61 5.2 Future Work........................................ 61 Bibliography 63 List of Figures 2.1 DevOps Process Overview - as described by AWS..................4 2.2 Google Trends Query - "DevOps" - January 2010 to January 2020..........5 2.3 Continuous Delivery Pipeline..............................7 2.4 Architecture - Containers vs Virtual Machines....................8 2.5 Docker Architecture...................................9 3.1 Complete Pipeline..................................... 19 3.2 Prototype - System Architecture............................. 20 3.3 GitLab Runner Token................................... 23 3.4 GitLab Runner Test 1................................... 24 3.5 Baseline for Software Delivery Pipeline........................ 25 3.6 SAST Check in the Pipeline - Flow........................... 28 3.7 Secure Pipeline with SAST................................ 31 3.8 DAST Check in the Pipeline - Flow........................... 33 3.9 Secure Pipeline with DAST............................... 35 3.10 Container Scanning in the Pipeline - Flow....................... 37 3.11 Secrets Scanning in the Pipeline - Flow......................... 40 3.12 Dependency Check in the Pipeline - Flow....................... 42 3.13 Results aggregator in the Pipeline - Flow........................ 45 3.14 build_risk_calc.py - HTML Dashboard......................... 46 3.15 Pipeline results submitted to DefectDojo Vulnerability Tracker - Flow....... 48 3.16 Deduplication of issues at the Product Level..................... 49 3.17 DefectDojo - Main Product Dashboard......................... 52 3.18 DefectDojo - Engagement View............................. 52 3.19 DefectDojo - Issues View................................. 53 xi List of Tables 4.1 Issues Table - By Severity and Security Check..................... 56 4.2 Pipeline Performance - Times over 5 Executions................... 57 4.3 Issues Table - By Severity and Security Check..................... 58 4.4 Pipeline Performance - Times over 5 Executions................... 59 xiii Listings 2.1 Gitleaks Rules TOML file example........................... 12 3.1 Gitlab CI/CD Runner Installation Commands.................... 22 3.2 Gitlab CI/CD Runner Installation Check........................ 22 3.3 Gitlab Runner Registration................................ 23 3.4 Test .gitlab-ci.yml file................................... 23 3.5 .gitlab.yml - Baseline definition for Java Project.................... 25 3.6 .gitlab.yml - Baseline definition for NodeJS Project.................. 26 3.7 SonarQube.service file in /etc/system/systemd/.................. 29 3.8 sonar-project.properties................................. 30 3.9 code-analysis.yml..................................... 30 3.10 SonarQube output result - report_sast.json...................... 32 3.11 connection_check.sh................................... 33 3.12 dynamic-analysis.yml.................................. 34 3.13 ZAP output result - report_dast.json.......................... 35 3.14 container-scan.yml.................................... 37 3.15 Clair output result - report_container-scan.json.................... 38 3.16 Hardwired E-mails Regex Rule - .gitleaks.toml.................... 39 3.17 secrets-scan.yml.....................................