Skip to content

Commit

Permalink
cicd(trivy): build local images for scheduled trivy checks
Browse files Browse the repository at this point in the history
- update trivy to 0.29.0 to avoid rate limit issues
  • Loading branch information
nicoprow committed Nov 22, 2024
1 parent 87d8c9c commit 1b22a97
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 154 deletions.
40 changes: 24 additions & 16 deletions .github/workflows/app-test-trivy-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,30 @@ on:
- main
- 'release/**'
jobs:
scan-pool:
uses: ./.github/workflows/app-test-trivy.yaml
with:
app: pool
scan-image:
runs-on: ubuntu-latest
strategy:
matrix:
app: [pool, gate, orchestrator, cleaning-service-dummy]
steps:
- name: Checkout repository
uses: actions/checkout@v4

scan-gate:
uses: ./.github/workflows/app-test-trivy.yaml
with:
app: gate
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

scan-orchestrator:
uses: ./.github/workflows/app-test-trivy.yaml
with:
app: orchestrator
- name: Build App Image
uses: docker/build-push-action@v6
with:
context: .
file: docker/${{ matrix.app }}/Dockerfile
tags: bpdm-${{ matrix.app }}:test
load: true

scan-cleaning-service-dummy:
uses: ./.github/workflows/app-test-trivy.yaml
with:
app: cleaning-service-dummy
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: "bpdm-${{ matrix.app }}:test"
exit-code: "1"
severity: "CRITICAL,HIGH"
timeout: 15m
158 changes: 20 additions & 138 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,169 +26,51 @@ on:
push:
branches:
- main
- 'release/**'
schedule:
# Once a day
- cron: "0 0 * * *"
# Trigger manually
workflow_dispatch:

jobs:
analyze-config:
scan-app:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
matrix:
app: [pool, gate, orchestrator, cleaning-service-dummy]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/[email protected]
with:
scan-type: "config"
# ignore-unfixed: true
exit-code: "0"
hide-progress: false
format: "sarif"
output: "trivy-results1.sarif"
severity: "CRITICAL,HIGH"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
- name: Build App Image
uses: docker/build-push-action@v6
with:
sarif_file: "trivy-results1.sarif"

analyze-product-bpdm-pool:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
packages: read

steps:
- name: Checkout repository
uses: actions/checkout@v4
context: .
file: docker/${{ matrix.app }}/Dockerfile
tags: bpdm-${{ matrix.app }}:test
load: true

- name: Run Trivy vulnerability scanner
if: always()
uses: aquasecurity/trivy-action@master
uses: aquasecurity/[email protected]
with:
# Path to Docker image
image-ref: "docker.io/tractusx/bpdm-pool:latest"
image-ref: "bpdm-${{ matrix.app }}:test"
format: "sarif"
output: "trivy-results2.sarif"
exit-code: "0"
output: "trivy-${{ matrix.app }}-results.sarif"
severity: "CRITICAL,HIGH"
timeout: 15m
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results2.sarif"

analyze-product-bpdm-gate:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
packages: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
if: always()
uses: aquasecurity/[email protected]
with:
# Path to Docker image
image-ref: "docker.io/tractusx/bpdm-gate:latest"
format: "sarif"
output: "trivy-results3.sarif"
exit-code: "0"
severity: "CRITICAL,HIGH"
timeout: 15m
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results3.sarif"

analyze-product-bpdm-cleaning-service-dummy:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
packages: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
if: always()
uses: aquasecurity/[email protected]
with:
# Path to Docker image
image-ref: "docker.io/tractusx/bpdm-cleaning-service-dummy:latest"
format: "sarif"
output: "trivy-results4.sarif"
exit-code: "0"
severity: "CRITICAL,HIGH"
timeout: 15m
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results4.sarif"

analyze-product-bpdm-orchestrator:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
packages: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
if: always()
uses: aquasecurity/[email protected]
with:
# Path to Docker image
image-ref: "docker.io/tractusx/bpdm-orchestrator:latest"
format: "sarif"
output: "trivy-results4.sarif"
exit-code: "0"
severity: "CRITICAL,HIGH"
timeout: 15m
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
hide-progress: false
exit-code: "1"
limit-severities-for-sarif: true

- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results4.sarif"
sarif_file: "trivy-${{ matrix.app }}-results.sarif"

0 comments on commit 1b22a97

Please sign in to comment.