Building a Secure DevSecOps Pipeline: Ensuring Code Security at Every Stage “A Real Example”

Ranjan Singh CyberSecurity
3 min readMay 13, 2023

#github #gitsecret #SonarQube #dependencycheck #Anchore #Trivy #OWASPZAP #lynis #Bugzilla

Introduction:

In today’s rapidly evolving threat landscape, ensuring the security of software applications is of paramount importance. One way to achieve this is by implementing a robust DevSecOps pipeline that integrates security practices seamlessly into the software development lifecycle. In this article, we will explore how to integrate different security tools into each stage of the DevSecOps pipeline, ensuring code security from the very beginning.

  1. Checkout Project (e.g — Git):
stage('Checkout Project') {
steps {
// Add steps to clone the repository
// For example, using Git
git url: 'https://github.com/your/repository.git'
}
}

2. Git Secret Check (e.g — Git Secrets):

stage('Git Secret Check') {
steps {
// Install and run Git Secrets
sh 'git secrets --scan'
}
}

3. SAST (e.g — SonarQube):

stage('Static Code Analysis (SAST)') {
steps {
// Execute SonarQube analysis using the SonarQube Scanner
withSonarQubeEnv('SonarQube Server') {
sh 'sonar-scanner'
}
}
}

4. SCA (e.g — OWASP Dependency check):

stage('Software Composition Analysis (SCA)') {
steps {
// Execute an SCA tool, such as OWASP Dependency Check or Snyk
sh 'dependency-check --project your-project --scan .'
}
}

5. Container Audit (e.g — Trivy / Docker Security Scan):

stage('Container Audit') {
steps {
// Scan the container image for vulnerabilities
sh 'docker scan your-container-image'
}
}

6. DAST(e.g — OWASP ZAP):

stage('Dynamic Application Security Testing (DAST)') {
steps {
// Execute DAST tool against the application
sh 'zap-cli --start --spider your-application-url && zap-cli --scan --policy your-policy-file'
}
}

7. System Security Audit (e.g — lysis):

stage('System Security Audit') {
steps {
// Run system security audit tool
sh 'lynis audit system'
}
}

8. Vulnerability Tracking and Compliance (e.g -Bugzilla):

stage('Vulnerability Tracking and Compliance') {
steps {
// Create tickets or issues for identified vulnerabilities
sh 'jira-cli create-issue --project your-project --summary "Vulnerability found" --description "Details of the vulnerability"'
}
}

These are just examples, and you can customize them based on the specific tools and configurations you use in your environment. Remember to install the required tools and plugins in your Jenkins instance or CI/CD platform

GitHub DevSecOps Pipeline with GitSecret, SAST, SCA, Container Audit, DAST, and System Security Audit

Lets see the complete Yaml file for this DevSecOps Pipeline

name: DevSecOps Pipeline

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: GitSecret check
uses: gitsecret/action@v1
with:
secret-file: .gitsecret

- name: SAST for SonarQube
uses: sonarsource/sonarcloud-github-action@v1
with:
sonar-project-key: [your-sonar-project-key]
sonar-login: [your-sonar-login]

- name: SCA (Dependency Check)
uses: owasp/dependency-check-action@v1
with:
dependency-check-report: ./dependency-check-report.xml

- name: Container Audit (Trivy)
uses: aquasec/trivy-action@v1
with:
image: [your-image-name]

- name: DAST (WASP Zap)
uses: owasp/zap-action@v1
with:
zap-url: http://[your-zap-url]
zap-token: [your-zap-token]

- name: System Security Audit (Lynis)
uses: github/lyses-action@v1
with:
lyses-url: https://[your-lyses-url]
lyses-token: [your-lyses-token]

- name: Bugzilla for tracking
uses: bz-action/bugzilla-action@v1
with:
bugzilla-url: https://[your-bugzilla-url]
bugzilla-user: [your-bugzilla-user]
bugzilla-password: [your-bugzilla-password]

--

--

Ranjan Singh CyberSecurity

Application Security | DevSecOps | Cloud Security | Offensive Security | Cyber Defense | Security Operations | VAPT | WAF | DLP | Cyber Security | IITian