Building CI Pipeline
Using OWASP Juiceshop and GitLab to build CI Pipeline.
Building a CI Pipeline to Learn DevSecOps Using OWASP Juice Shop
Introduction
In today's fast-paced software development world, integrating security into the DevOps process (DevSecOps) is crucial. This blog will guide you through setting up a CI/CD pipeline using GitLab to learn DevSecOps concepts. We'll use OWASP Juice Shop, a vulnerable web application, as our target application. Our pipeline will include tools for static application security testing (SAST), software composition analysis (SCA), dynamic application security testing (DAST), and secret management.
Prerequisites
Before we start, ensure you have the following:
A GitLab account
Basic understanding of Git
Basic understanding of CI/CD pipelines
Step 1: Fork and Clone OWASP Juice Shop
First, fork the OWASP Juice Shop repository from GitHub to your account. Then, clone the forked repository to your local machine.
Step 2: Push the Repository to GitLab
Create a new project in GitLab and push the cloned repository to it.
Step 3: Setting Up the GitLab CI/CD Pipeline
Create .gitlab-ci.yml
File
.gitlab-ci.yml
FileCreate a .gitlab-ci.yml
file in the root directory of your repository. This file will define the stages and jobs in your pipeline.
Explanation of Each Stage
Build Stage:
Installs dependencies and builds the Juice Shop application.
SAST Stage:
Uses SonarQube to perform static code analysis.
SCA Stage:
Uses OWASP Dependency-Check to identify vulnerabilities in third-party dependencies.
DAST Stage:
Uses OWASP ZAP to perform dynamic security testing against the running application.
Secret Management:
Uses Gitleaks to detect any hardcoded secrets in the codebase.
Configuring SonarQube
If you haven't already, configure SonarQube by following these steps:
Create a new project in SonarQube
Generate a token for the project
Add the token to your GitLab project settings under CI/CD > Variables as
SONAR_TOKEN
.
Step 4: Running the Pipeline
After setting up the .gitlab-ci.yml
file and pushing it to your GitLab repository, navigate to CI/CD > Pipelines in your GitLab project. You should see a new pipeline running. Each job will execute in sequence according to the stages defined.
Monitoring the Pipeline
Pipeline List:
Navigate to CI/CD > Pipelines to see the list of pipelines.
Click on the pipeline to view details.
Job Logs:
Click on individual jobs to view their logs and results.
Logs provide insights into the execution of each stage.
Artifacts:
Download and view artifacts (e.g., reports) generated by each job.
Step 5: Reviewing the Results
SonarQube
Access the SonarQube dashboard to view detailed static analysis reports.
Dependency-Check
Open the generated dependency-check report to review vulnerabilities in third-party dependencies.
OWASP ZAP
Open the ZAP report (
zap-report.html
) to see the results of dynamic security testing.
Gitleaks
Review the
gitleaks-report.json
file for any detected secrets.
Conclusion
By following these steps, you've successfully set up a CI/CD pipeline in GitLab that integrates essential DevSecOps practices using OWASP Juice Shop. This setup helps you understand how to automate security testing at different stages of the software development lifecycle, ensuring that security is an integral part of the process.
This guide provides a comprehensive walkthrough, ensuring that even beginners can follow along and learn the essentials of integrating security into their CI/CD pipelines using GitLab and OWASP Juice Shop.
Last updated