diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 02fe620a..071248ac 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -20,6 +20,7 @@ jobs: permissions: contents: read packages: write + security-events: write steps: # Step 1: Download the code @@ -72,6 +73,7 @@ jobs: # Step 7: Build and push Docker image - name: 🐳 Build and push Docker image uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5 + id: build with: context: . file: ./Dockerfile @@ -82,7 +84,30 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - # Step 8: Create a summary + # Step 8: Run Trivy security scan + - name: 🔍 Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }} + format: 'sarif' + output: 'trivy-results.sarif' + + # Step 9: Upload Trivy results to GitHub Security tab + - name: 📤 Upload Trivy results to GitHub Security + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: 'trivy-results.sarif' + + # Step 10: Run Trivy with table output for workflow logs + - name: 📋 Run Trivy scan (table output) + uses: aquasecurity/trivy-action@master + with: + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }} + format: 'table' + severity: 'CRITICAL,HIGH' + + # Step 11: Create a summary - name: 📋 Create summary run: | echo "## 🎉 Docker Image Built Successfully!" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 91390e43..05552e3d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -23,6 +23,7 @@ jobs: permissions: contents: read packages: write + security-events: write steps: - name: Checkout repository @@ -74,3 +75,26 @@ jobs: - name: Image digest run: echo ${{ steps.build-and-push.outputs.digest }} + + - name: Run Trivy vulnerability scanner + if: github.event_name != 'pull_request' + uses: aquasecurity/trivy-action@master + with: + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }} + format: 'sarif' + output: 'trivy-results.sarif' + + - name: Upload Trivy results to GitHub Security + if: github.event_name != 'pull_request' + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: 'trivy-results.sarif' + + - name: Run Trivy scan (table output) + if: github.event_name != 'pull_request' + uses: aquasecurity/trivy-action@master + with: + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }} + format: 'table' + severity: 'CRITICAL,HIGH' +