Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to make Github runner take an action if a vulnerability is found? #428

Open
jasonculligan opened this issue Nov 2, 2024 · 0 comments

Comments

@jasonculligan
Copy link

I thought this would be easy but I was wrong. Consider the following Github action:

name: Daily Pull and Vulnerability Scan

on:
  schedule:
    - cron: "0 0 * * *"  # Runs daily at midnight UTC
  workflow_dispatch:  # Allows manual trigger

jobs:
  pull-and-scan:
    runs-on: ubuntu-latest

    steps:
    - name: Log in to Docker Hub
      uses: docker/login-action@v2
      with:
        username: ${{ secrets.DOCKER_USER }}
        password: ${{ secrets.DOCKER_PASS }}

    - name: Pull Docker image
      run: |
        IMAGE_NAME="example-image-name:latest"
        docker pull $IMAGE_NAME
      env:
        IMAGE_NAME: example-image-name:latest

    - name: Scan Docker image with Trivy
      id: scan_image
      uses: aquasecurity/trivy-action@master
      with:
        image-ref: example-image-name:latest
        ignore-unfixed: true  # Optional: set to false to capture all vulnerabilities
        format: "table"  # Output format
        exit-code: '123'

    - name: Check if vulnerabilities are found
      id: check_scan
      run: |
        # Fail the job if vulnerabilities were found
        if [[ "${{ steps.scan_image.outputs.results }}" != "" ]]; then
          echo "Vulnerabilities found!"
          echo "needs_rebuild=true" >> $GITHUB_ENV
        else
          echo "No vulnerabilities found."
          echo "needs_rebuild=false" >> $GITHUB_ENV
        fi

    - name: Build and push Docker image
      if: env.needs_rebuild == 'true'
      id: push
      uses: docker/build-push-action@v6
      with:
        context: .
        file: ./Dockerfile
        push: true
        tags: example-image-name:latest

It never reaches the portion to decide what to do if vulnerabilities are found:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant