Skip to content

Scan

Scan #10

Workflow file for this run

name: Scan
on:
schedule:
- cron: "0 7 * * *"
# Allow to run this workflow manually
workflow_dispatch:
env:
CONTAINER_REGISTRY: ghcr.io
CONTAINER_IMAGE_NAME: ${{ github.repository }}
CONTAINER_IMAGE_VERSION: latest
jobs:
reset-trivy-cache:
runs-on: ubuntu-latest
steps:
- name: Remove all caches and database of the trivy scanner
uses: aquasecurity/trivy-action@84384bd6e777ef152729993b8145ea352e9dd3ef
env:
TRIVY_RESET: true
TRIVY_DEBUG: true
with:
scan-type: "image"
- name: Download trivy vulnerabilities DB
uses: aquasecurity/trivy-action@84384bd6e777ef152729993b8145ea352e9dd3ef
env:
TRIVY_DEBUG: true
TRIVY_DOWNLOAD_DB_ONLY: true
with:
scan-type: "image"
vulnerability-scan-backend:
runs-on: ubuntu-latest
needs: reset-trivy-cache
permissions:
contents: read
id-token: write # for cosign w/ keyless signing
packages: write # for updating cosign attestation
security-events: write
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: aquasecurity/trivy-action@84384bd6e777ef152729993b8145ea352e9dd3ef
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
image-ref: ${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_IMAGE_NAME }}:${{ env.CONTAINER_IMAGE_VERSION }}
format: "sarif"
output: "trivy-results.sarif"
- name: Check trivy results
run: |
if grep -qE 'HIGH|CRITICAL' trivy-results.sarif; then
echo "Vulnerabilities found"
exit 1
else
echo "No significant vulnerabilities found"
exit 0
fi
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: ${{ always() && github.ref == 'refs/heads/main' }} # Bypass non-zero exit code..
with:
sarif_file: "trivy-results.sarif"
- name: Generate cosign vulnerability scan record
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: aquasecurity/trivy-action@84384bd6e777ef152729993b8145ea352e9dd3ef
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
image-ref: ${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_IMAGE_NAME }}:${{ env.CONTAINER_IMAGE_VERSION }}
format: "cosign-vuln"
output: "vulnerabilities.json"
- name: Install cosign
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4
with:
cosign-release: "v1.13.1"
- name: Log into container registry
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull latest docker image
run: docker pull ghcr.io/digitalservicebund/a2j-rechtsantragstelle:latest
- name: Get Docker image digest
id: get_docker_digest
run: |
digest=$(docker inspect --format='{{ index .RepoDigests 0 }}' ghcr.io/digitalservicebund/a2j-rechtsantragstelle:latest)
echo "::set-output name=digest::$digest"
- name: Print Docker image digest
run: echo "Image latest digest is ${{ steps.get_docker_digest.outputs.digest }}\n"
- name: Set up environment
run: echo "IMAGE_DIGEST=${{ steps.get_docker_digest.outputs.digest }}" >> $GITHUB_ENV
- name: Attest vulnerability scan
run: cosign attest --yes --replace --predicate vulnerabilities.json --type vuln $IMAGE_DIGEST
env:
COSIGN_EXPERIMENTAL: "true"