Trivy scanning #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and scan container for vulnerabilities | |
on: | |
pull_request: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: cloudflared-ssh-action | |
jobs: | |
build-and-push-image: | |
name: Build and push to ghcr.io | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ghcr.io/${{ github.repository }}:${{ github.sha }} | |
scan-image: | |
name: Run Trivy scanner | |
needs: build-and-push-image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Run scanner | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: 'ghcr.io/${{ github.repository }}:${{ github.sha }}' | |
exit-code: '1' | |
vuln-type: 'os,library' | |
severity: 'CRITICAL,HIGH' | |
limit-severities-for-sarif: true | |
format: 'sarif' | |
output: 'trivy-results.sarif' | |
env: | |
TRIVY_USERNAME: ${{ github.actor }} | |
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v3 | |
if: always() | |
with: | |
sarif_file: 'trivy-results.sarif' | |
clean-ghcr: | |
name: Delete old container images | |
needs: scan-image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete images | |
uses: actions/delete-package-versions@v5 | |
with: | |
package-name: ${{ env.IMAGE_NAME }} | |
package-type: 'container' | |
min-versions-to-keep: 2 | |
delete-only-pre-release-versions: "true" |