Skip to content

Commit

Permalink
feat: add trivy vulnerability check
Browse files Browse the repository at this point in the history
Trivy vulnerability check is added the GitHub Actions workflows.

ING-4183
  • Loading branch information
emanuelaepure10 committed Apr 26, 2024
1 parent 2a6b7cd commit 295058e
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: trivy

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
schedule:
- cron: '39 17 * * 3'

permissions:
contents: read

jobs:
build:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

#- name: Build an image from Dockerfile
# run: |
# docker build -t docker.io/my-organization/my-app:${{ github.sha }} .

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@7b7aa264d83dc58691451798b4d117d53d21edfe
with:
# image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
scan-type: 'fs'
scan-ref: '.'
template: '/sarif.tpl'
output: 'trivy-scan-results.sarif'
severity: 'CRITICAL,HIGH'

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
name: trivy-results
path: trivy-scan-results.sarif
sarif_file: 'trivy-scan-results.sarif'
58 changes: 58 additions & 0 deletions sarif.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Trivy",
"version": "0.12.0"
}
},
"results": [
{
"ruleId": "Vulnerability",
"level": "error",
"message": {
"text": "Critical vulnerability found in the Docker image."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "https://example.com/repo/docker-image.tar.gz"
}
}
}
],
"properties": {
"severity": "Critical",
"vulnerabilityId": "CVE-2021-12345",
"description": "Description of the vulnerability."
}
},
{
"ruleId": "Vulnerability",
"level": "warning",
"message": {
"text": "Medium severity vulnerability found in the Docker image."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "https://example.com/repo/docker-image.tar.gz"
}
}
}
],
"properties": {
"severity": "Medium",
"vulnerabilityId": "CVE-2021-67890",
"description": "Description of the vulnerability."
}
}
]
}
]
}
73 changes: 73 additions & 0 deletions trivy-scan-results-sarif
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Trivy",
"version": "0.12.0",
"informationUri": "https://github.com/aquasecurity/trivy",
"rules": [
{
"id": "TRIVY_SCAN_RESULT",
"name": "Trivy Vulnerability Scan Result",
"shortDescription": {
"text": "Trivy scan result for vulnerabilities"
},
"fullDescription": {
"text": "Trivy scan result for vulnerabilities found in the scanned image."
}
}
]
}
},
"results": [
{
"ruleId": "TRIVY_SCAN_RESULT",
"level": "error",
"message": {
"text": "High severity vulnerability found in package XYZ"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///path/to/scanned/image"
}
}
}
],
"properties": {
"CVE": "CVE-2021-1234",
"package": "XYZ",
"version": "1.2.3",
"severity": "High"
}
},
{
"ruleId": "TRIVY_SCAN_RESULT",
"level": "warning",
"message": {
"text": "Medium severity vulnerability found in package ABC"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///path/to/scanned/image"
}
}
}
],
"properties": {
"CVE": "CVE-2021-5678",
"package": "ABC",
"version": "4.5.6",
"severity": "Medium"
}
}
]
}
]
}

0 comments on commit 295058e

Please sign in to comment.