Showing posts with label Trivy Scanner. Show all posts
Showing posts with label Trivy Scanner. Show all posts

Sunday, May 24, 2026

How to Setup AquaSec Trivy Vulnerability Scanner | How to install AquaSec Trivy Scanner on Linux OS | Jenkins Pipeline For Scanning MyWebApp | DevSecOps Tutorials

 What is Trivy?

  • open-source security scanner tool developed by Aqua Security. 
  • Used for vulnerability scanning in such as 
    • container images 
    • file systems/folders 
    • Git repositories
    • Kubernetes clusters
    • misconfiguration in files such as Terraform, K8S manifest files
  • Trivy helps identify security issues and misconfigurations early in the software development lifecycle.

Pre-requisites:

  • Any Linux instance is up and running, in our case we will use Jenkins Ubuntu machine

How to Install Trivy scanner on Jenkins Ubuntu EC2 instance?

Trivy scanner can be installed so many ways. Check here for more information. But we will be using APT package manager to install on Ubuntu EC2.

sudo apt-get install wget gnupg -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null 
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee -a /etc/apt/sources.list.d/trivy.list 
sudo apt-get update 
sudo apt-get install trivy -y

Check Trivy got installed
trivy --version


This confirm that Trivy got installed successfully.

Jenkins Pipeline 

pipeline {
    agent any

    tools {
        maven 'Maven3'
    }
    stages {
        stage('Checkout') {
            steps {
                git branch: 'main', credentialsId: '', url: 'https://github.com/akannan1087/myApr2026WeekendRepo'
            }
        }
        
        stage ("build") {
            steps {
                echo "doing my build.."
                sh "mvn clean install -f MyWebApp/pom.xml"
            }
        }

    stage ("code coverage") {
        steps {
         jacoco()
        }
    }
    
    stage ("code scan") {
        steps {
        withSonarQubeEnv('SonarQube') {
            sh "mvn sonar:sonar -f MyWebApp/pom.xml"
        }
     }
    }
    
    stage ("security scan") {
        steps {
         sh "trivy fs ."
        }
    }
 }
}


Watch video in my YouTube channel:

Tuesday, January 21, 2025

How to Setup AquaSec Trivy Vulnerability Scanner | How to install AquaSec Trivy Scanner on Linux OS | Security Scanning Tool | DevSecOps Tutorials

What is Trivy?

  • open-source security scanner tool developed by Aqua Security. 
  • Used for vulnerability scanning in such as 
    • container images 
    • file systems/folders 
    • Git repositories
    • Kubernetes clusters
    • misconfiguration in files such as Terraform, K8S manifest files
  • Trivy helps identify security issues and misconfigurations early in the software development lifecycle.

Pre-requisites:

  • Any Linux instance is up and running, in our case we will use a Ubuntu machine

How to Install Trivy scanner on Linux OS?

Trivy scanner can be installed so many ways. Check here for more information. But we will be using APT package manager to install on Ubuntu EC2.

sudo apt-get install wget gnupg -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null 
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee -a /etc/apt/sources.list.d/trivy.list 
sudo apt-get update 
sudo apt-get install trivy -y

Check Trivy got installed
trivy --version


This confirm that Trivy got installed successfully.

Perform Docker image scan locally
trivy image nginx:latest

where nginx is name of the docker image

You can also pass arguments to filter based on severity
trivy image --severity HIGH,CRITICAL,MEDIUM nginx:latest

Perform scanning a Git Repo

where repo_url is the public git repo that you want to scan

Perform scanning a file system locally
trivy fs your_folder

where your_folder is directory on your machine where you have installed Trivy.

Additional links:
If you want to integrate Trivy with Jenkins CICD pipeline for automating docker image scanning, please click here.
If you want to integrate Trivy with Azure DevOps CICD pipeline for automating docker image scanning, please click here.

Watch video in my YouTube channel:

Friday, January 10, 2025

Perform Security Scan for SpringBoot Microservice Docker image using Trivy Scanner and Azure YAML Pipeline | How to Scan Spring Boot Docker Image in Azure DevOps using Trivy Scanner

Perform vulnerability scan using Trivy scanner on Azure DevOps Pipeline


What is Trivy?
Trivy is an open-source security scanner tool developed by Aqua Security. It can scan:
    • container images 
    • file systems/folders 
    • Git repositories
    • Kubernetes clusters
    • misconfiguration in files such as Terraform, K8S manifest files

Pre-requisites:

ADO Yaml Pipeline for scanning docker image using Trivy scanner in Azure Hosted Build Agent:
# Perform Trivy scan for Docker image and upload docker image into ACR

trigger:
- master

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '723477ce-4e05-4e6e-a3c1-13bdf919a5cd'
imageRepository: 'dockerspringbootapp'
containerRegistry: 'myacrrepo131.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Maven@4
inputs:
mavenPomFile: 'pom.xml'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: Docker@2
displayName: Build a Docker image
inputs:
command: build
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- task: Bash@3
displayName: "Install Trivy"
inputs:
targetType: inline
script: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh
# Run Trivy Scan
- task: Bash@3
displayName: "Run Trivy Scan"
inputs:
targetType: inline
script: |
./bin/trivy image --severity HIGH,CRITICAL,MEDIUM --ignore-unfixed $(containerRegistry)/$(imageRepository):$(tag)
- task: Docker@2
displayName: push the image to container registry
inputs:
command: Push
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)

Scan report can be viewed in Build output of Azure Pipelines



Watch Steps in YouTube channel:

Thursday, January 9, 2025

Setup AquaSec Trivy for Vulnerability scanning | How to Set Up Trivy Scanner in Azure DevOps | How to scan Docker image using Trivy Scanner | Create Azure YAML Pipeline for scanning Docker image

How to perform vulnerability scan using Trivy scanner on Azure DevOps Pipeline?


Pre-requisites:

ADO Yaml Pipeline for scanning docker image using Trivy scanner:
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'd676875f-d1fb-485a-8da4-88d6bfb04604'
imageRepository: 'mypythondockerrepo'
containerRegistry: 'myacrrep31.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'

vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
# build docker image
- task: Docker@2
displayName: Build Docker image
inputs:
command: build
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
# Install Trivy Scanner on Agent
- task: Bash@3
displayName: "Install Trivy"
inputs:
targetType: inline
script: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh
# Run Trivy Scan
- task: Bash@3
displayName: "Run Trivy Scan"
inputs:
targetType: inline
script: |
./bin/trivy image --severity HIGH,CRITICAL,MEDIUM --ignore-unfixed $(containerRegistry)/$(imageRepository):$(tag)
# Push docker image
- task: Docker@2
displayName: push Docker image to container registry
inputs:
command: push
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)

Scan report can be viewed in Build output of Azure Pipelines


Complete AI-Enabled DevOps Learning Roadmap for 2026 | Skills Required to Become a Modern DevSecOps Engineer

🚀  AI-Enabled DevOps Engineer Roadmap for 2026 The future belongs to AI-Enabled DevOps Engineers, not AI-only Engineers. Strong DevOps fund...