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


2 comments:

  1. This is a highly practical article that explains how Aqua Security's Trivy can be configured for vulnerability scanning in modern development environments. The author clearly demonstrates the importance of identifying security weaknesses in containers, dependencies, and software artifacts before deployment. The step-by-step guidance makes the topic accessible while emphasizing the growing role of proactive security practices in software development and DevOps workflows.

    ReplyDelete
  2. The article highlights vulnerability assessment, security scanning, and threat detection techniques that help organizations identify and remediate risks before they impact production systems. These concepts are closely related to Cyber Security Projects for Final Year Students, where security monitoring, vulnerability management, and defensive security strategies are applied to protect modern applications and infrastructure.

    Implementing automated security checks using tools like Trivy strengthens the overall security posture of software delivery pipelines and cloud-native environments. These practices align well with Information Security Projects, which focus on safeguarding digital assets through risk assessment, secure system design, and comprehensive protection mechanisms.

    ReplyDelete

How to integrate SonarQube with GitLab CICD Pipeline | SonarQube Integration with GitLab CICD | Automate Code Scan using SonarQube In GitLab CICD

  Please find steps for integrating SonarQube with GitLab CICD Pre-requisites: Make sure SonarQube is up and running Make sure Java Project ...