Skip to main content

Command Palette

Search for a command to run...

โ™พSecuring the Future: A DevSecOps Project

We are going to variety of tools that are essential in the world of DevOps.

Updated
โ€ข4 min read
โ™พSecuring the Future: A DevSecOps Project
P

Hey there! ๐Ÿ‘‹

I'm Pratik R. Mandge, a DevOps Engineer passionate about all things AWS DevOps Technology. Currently on a learning adventure, I'm here to share my journey and Blog's in the world of cloud and DevOps.

๐Ÿ› ๏ธ My focus? Making sense of AWS services, improving CI/CD, and diving into infrastructure as code. Whether you're fellow interns or curious enthusiasts, let's grow together in the vibrant DevOps space.

๐ŸŒ Connect with me for friendly chats, shared experiences, and learning moments. Here's to embracing the learning curve and thriving in the exciting world of AWS DevOps Technology!

Follow me on LinkedIn: https://www.linkedin.com/in/pratik-mandge363

๐Ÿ”นFlow of DevSecOps Project

๐Ÿ”นPrerequisite Tools:

AWS Ubuntu: "AWS Ubuntu refers to the Ubuntu operating system instances that are hosted on the Amazon Web Services cloud platform."

GitHub: "GitHub is a web-based platform for version control using Git, commonly used for hosting and sharing code repositories."

Docker: "Docker is a platform for developing, shipping, and running applications using containerization."

Docker-compose: "Docker Compose is a tool for defining and running multi-container Docker applications."

Jenkins CI/CD: "Jenkins CI/CD is an automation server used for continuous integration and continuous deployment pipelines."

SonarQube: "SonarQube is an open-source platform for continuous inspection of code quality."

OWASP: "OWASP (Open Web Application Security Project) is a non-profit organization dedicated to improving software security."

Trivy: "Trivy is a vulnerability scanner for containers and other artifacts, focusing on simplicity and ease of use."

These tools will help us streamline our development processes while ensuring security throughout.

๐Ÿ”นNow Let's start the Project

โ—ผ๏ธSet EC2 Instance:

Instance Type - minimum t2.large & minimum Volume 10 GB.

โ—ผ๏ธInstall Openjdk 17-jre:

To run Jenkins, you need to have Java installed on your machine.

sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version

โ—ผ๏ธInstall Jenkins:

Long Term Support Release

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

โ—ผ๏ธNow enable, start and verify the Jenkins service with below command:

sudo systemctl enable jenkins   
sudo systemctl start jenkins
sudo systemctl status jenkins

โ—ผ๏ธInstall Docker and docker-compose:

sudo apt-get install docker.io docker-compose -y

โ—ผ๏ธAdd Current User & jenkins into docker group:

sudo usermod -aG docker $USER
sudo usermod -aG docker jenkins

โ—ผ๏ธOnce reboot your instance:

sudo reboot

โ—ผ๏ธCheck current user & jenkins added in docker group:

sudo cat /etc/group     # To check the users added in docker group

โ—ผ๏ธInstall SonarQube:

To start a Docker container running SonarQube Community Edition in the LTS (Long Term Support) version.

docker run -itd --name sonarqube-server -p 9000:9000 sonarqube:lts-community

โ—ผ๏ธInstall Trivy:

sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy

โ—ผ๏ธNow add the Ports shown below:

Go to Instance Security-> Security Groups-> Edit Inbound Rules-> Add Rules

For Jenkins: 8080, For SonarQube: 9000, For Docker: 8000

โ—ผ๏ธAccess Jenkins Server: With url as http://<publicIP>:8080

After acess jenkins-> Select suggested plugins.

After Installation you'll get path: /var/lib/jenkins/secrets/initialAdminPassword

Just copy that directory path and paste it in EC2 terminal using cat:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

โ—ผ๏ธCopy the password and paste to jenkins. & Create your Jenkins account.

โ—ผ๏ธInstall SonarQube, OWASP, Docker plugins in Jenkins below:

Plugins - SonarQube Scanner, Sonar Quality Gates, OWASP Dependency-Check, Docker.

โ—ผ๏ธAccess SonarQube Server: To access server just use http://<publicIP>:9000

Initially username and password will be โ€˜ adminโ€™ , โ€™ adminโ€™. Just change with a new password.

โ—ผ๏ธCreate users token in SonarQube: Generate a token for authentication purposes. Click on Administration tab-> Security-> Users-> create Token name as jenkins.

Whatever token generated, just copy and paste to somewhere else. Once window is closed, you wont be able to see that again.

โ—ผ๏ธCreate a webhook in SonarQube: Administration-> Configuration-> Webhook-> Create

โ—ผ๏ธNow Add SonarQube Credentials to Jenkins:

Manage Jenkins-> Credentials-> Add SonarQube Credential

Kind -Secret Text

Scope- Global (Jenkins nodes..)

Secret- Token generated from sonarqube.

ID- Sonar

Description- Sonar

โ—ผ๏ธAlso Add DockerHub Credentials:

Kind- โ€˜Username with Passwordโ€˜

Scope- Global (Jenkins nodes..)

Username- your DockerHub Username

Password- your DockerHub Password

ID- dockerHub

Description- DockerHub Credentials.

โ—ผ๏ธAdd SonarQube in Jenkins:

Manage Jenkins-> System-> SonarQube Servers-> SonarQube Installations

Server URL:http://ipaddress:9000

Server authentication token: Sonar

โ—ผ๏ธAdd SonarQube Scanner from tools:

Manage Jenkins-> Tools-> SonarQube Scanner

โ—ผ๏ธAdd OWASP from tools:

Manage Jenkins-> Tools-> Dependency-Check installations

Select Install from Github.com and it will take version

โ—ผ๏ธBuild Pipeline:

New Item-> (Enter Project Name)-> Select Pipeline-> OK

Configuration-> GitHub Project(Github url)-> Build Trigger(Github hook trigger)

Select Pipeline script-> Paste Pipeline Syntax.

pipeline {

    agent any
     environment{
        SONAR_HOME = tool "Sonar"
    }
    stages {

        stage("Code"){
            steps{
                git url: "https://github.com/mandgepratik/node-todo-cicd.git" , branch: "master"
                echo "Code Cloned Successfully"
            }
        }
        stage("SonarQube Analysis"){
            steps{
               withSonarQubeEnv("Sonar"){
                   sh "$SONAR_HOME/bin/sonar-scanner -Dsonar.projectName=nodetodo -Dsonar.projectKey=nodetodo -X"
               }
            }
        }
        stage("SonarQube Quality Gates"){
            steps{
               timeout(time: 1, unit: "MINUTES"){
                   waitForQualityGate abortPipeline: false
               }
            }
        }
        stage("Build & Test"){
            steps{
                sh 'docker build -t node-app:latest .'
                echo "Code Built & Test Successfully"
            }
        }
        stage("OWASP"){
            steps{
                dependencyCheck additionalArguments: '--scan ./', odcInstallation: 'OWASP'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage("Trivy"){
            steps{
                sh "trivy image node-app"
                echo "Image Scanned Successfully"
            }
        }
       stage("Push to Private Docker Hub Repo"){
            steps{
                withCredentials([usernamePassword(credentialsId:"dockerHub",passwordVariable:"dockerPass",usernameVariable:"dockerUser")]){
                sh "docker login -u ${env.dockerUser} -p ${env.dockerPass}"
                sh "docker tag node-app:latest ${env.dockerUser}/node-app:latest"
                sh "docker push ${env.dockerUser}/node-app:latest"
                }

            }
        }
        stage("Deploy"){
            steps{
                sh "docker-compose down && docker-compose up -d"
                echo "App Deployed Successfully"
            }
        }
    }
}

โ—ผ๏ธSave & Build Now

The Stages Box sequence will show as per your code.

โ—ผ๏ธTo access App:PublicIP:8000

๐ŸŽŠCongratulations!!! You have done it...

๐Ÿ“ŒIf you find any issue during the execution of this project, let me know on LinkedIn.

Happy Learning๐Ÿ˜Š

More from this blog

๐Ÿš€ ๐——๐—ฎ๐˜† ๐Ÿญ ๐—ผ๐—ณ ๐— ๐˜† ๐Ÿณ-๐——๐—ฎ๐˜† ๐—”๐—ช๐—ฆ ๐—–๐—ต๐—ฎ๐—น๐—น๐—ฒ๐—ป๐—ด๐—ฒ ๐ŸŒŸ

Today, I kicked off my AWS Challenge with a deep dive into several fundamental concepts. Hereโ€™s what I covered: ๐Ÿท๏ธ ๐˜ผ๐™’๐™Ž ๐™‹๐™ง๐™ž๐™˜๐™ž๐™ฃ๐™œ ๐™ˆ๐™ค๐™™๐™š๐™ก๐™จ:AWS offers various pricing models to cater to different business needs: ๐Ÿญ) ๐—ข๐—ป-๐——๐—ฒ๐—บ๐—ฎ๐—ป๐—ฑ ๐—œ๐—ป...

May 22, 20242 min read
๐Ÿš€ ๐——๐—ฎ๐˜† ๐Ÿญ ๐—ผ๐—ณ ๐— ๐˜† ๐Ÿณ-๐——๐—ฎ๐˜† ๐—”๐—ช๐—ฆ ๐—–๐—ต๐—ฎ๐—น๐—น๐—ฒ๐—ป๐—ด๐—ฒ ๐ŸŒŸ

๐ŸŒŸ ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐—ž๐—ฒ๐˜† ๐—–๐—ผ๐—บ๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐˜€ ๐—ผ๐—ณ ๐—ž๐˜‚๐—ฏ๐—ฒ๐—ฟ๐—ป๐—ฒ๐˜๐—ฒ๐˜€ ! ๐ŸŒŸ

Kubernetes is designed to automate the deployment, scaling, and operation of application containers. The architecture is divided into two main components: ๐™ˆ๐™–๐™จ๐™ฉ๐™š๐™ง and ๐™’๐™ค๐™ง๐™ ๐™š๐™ง. Hereโ€™s a detailed breakdown: ๐Ÿ”ถ๐™ˆ๐™–๐™จ๐™ฉ๐™š๐™ง ๐™‰๐™ค๐™™๐™š ๐˜พ๐™ค๐™ข๐™ฅ๐™ค๏ฟฝ...

May 19, 20242 min read
๐ŸŒŸ ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐—ž๐—ฒ๐˜† ๐—–๐—ผ๐—บ๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐˜€ ๐—ผ๐—ณ ๐—ž๐˜‚๐—ฏ๐—ฒ๐—ฟ๐—ป๐—ฒ๐˜๐—ฒ๐˜€ ! ๐ŸŒŸ

โ›…๏ธImportant AWS Services: Part - 3

๐Ÿš€๐™€๐™ญ๐™˜๐™ž๐™ฉ๐™š๐™™ ๐™ฉ๐™ค ๐™จ๐™๐™–๐™ง๐™š ๐™ข๐™ฎ ๐™š๐™ญ๐™ฅ๐™š๐™ง๐™ฉ๐™ž๐™จ๐™š ๐™ž๐™ฃ ๐˜ผ๐™’๐™Ž ๐™ฌ๐™ž๐™ฉ๐™ ๐™– ๐™›๐™ค๐™˜๐™ช๐™จ ๐™ค๐™ฃ ๐™˜๐™ค๐™ฃ๐™ฉ๐™–๐™ž๐™ฃ๐™š๐™ง๐™ž๐™ฏ๐™–๐™ฉ๐™ž๐™ค๐™ฃ ๐™–๐™ฃ๐™™ ๐™™๐™š๐™ฅ๐™ก๐™ค๐™ฎ โ–ถ๏ธ๐—”๐—บ๐—ฎ๐˜‡๐—ผ๐—ป ๐—˜๐—น๐—ฎ๐˜€๐˜๐—ถ๐—ฐ ๐—ž๐˜‚๐—ฏ๐—ฒ๐—ฟ๐—ป๐—ฒ๐˜๐—ฒ๐˜€ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ (๐—˜๐—ž๐—ฆ): โ–ช๏ธFully managed Kuberne...

May 12, 20242 min read
โ›…๏ธImportant AWS Services: Part - 3

โ›…๏ธImportant AWS Services: Part - 2

โšœ๏ธ๐™„๐™ข๐™ฅ๐™ค๐™ง๐™ฉ๐™–๐™ฃ๐™ฉ ๐™ฌ๐™ž๐™™๐™š ๐™ง๐™–๐™ฃ๐™œ๐™š ๐™ค๐™› ๐˜ผ๐™’๐™Ž ๐™จ๐™š๐™ง๐™ซ๐™ž๐™˜๐™š๐™จ ๐™ฉ๐™๐™–๐™ฉ ๐™˜๐™–๐™ฃ ๐™š๐™ฃ๐™–๐™—๐™ก๐™š ๐™ฉ๐™ค ๐™–๐™ง๐™˜๐™๐™ž๐™ฉ๐™š๐™˜๐™ฉ ๐™จ๐™˜๐™–๐™ก๐™–๐™—๐™ก๐™š, ๐™จ๐™š๐™˜๐™ช๐™ง๐™š, ๐™–๐™ฃ๐™™ ๐™š๐™›๐™›๐™ž๐™˜๐™ž๐™š๐™ฃ๐™ฉ ๐™˜๐™ก๐™ค๐™ช๐™™ ๐™จ๐™ค๐™ก๐™ช๐™ฉ๐™ž๐™ค๐™ฃ๐™จ. ๐™ƒ๐™š๐™ง๐™š ๐™–๐™ง๐™š ๐™จ๐™ค๐™ข๐™š ๐™ ๐™š๐™ฎ ๐™จ๐™š๐™ง...

May 10, 20243 min read
โ›…๏ธImportant AWS Services: Part - 2

PratikM's Blog

49 posts