|
| 1 | +# Trivy IaC scan: Helm charts (Kubernetes misconfig). |
| 2 | +# Whole-repo scan of charts/ and config files. |
| 3 | +# |
| 4 | +# ADVANCED_SECURITY (env below): |
| 5 | +# "true" – SARIF → Security tab + artifacts (public / GHAS). |
| 6 | +# "false" – Table → job summary only (private, no GHAS). Default. |
| 7 | +# |
| 8 | +name: Trivy IaC (Kubernetes / Helm) |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + security-events: write |
| 13 | + actions: read |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + branches: [main] |
| 18 | + paths: |
| 19 | + - "**/*.yaml" |
| 20 | + - "**/*.yml" |
| 21 | + - "**/*.tpl" |
| 22 | + - "**/Chart.yaml" |
| 23 | + - "**/Dockerfile" |
| 24 | + - ".github/workflows/trivy.yml" |
| 25 | + pull_request: |
| 26 | + branches: [main] |
| 27 | + paths: |
| 28 | + - "**/*.yaml" |
| 29 | + - "**/*.yml" |
| 30 | + - "**/*.tpl" |
| 31 | + - "**/Chart.yaml" |
| 32 | + - "**/Dockerfile" |
| 33 | + - ".github/workflows/trivy.yml" |
| 34 | + |
| 35 | +concurrency: |
| 36 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 37 | + cancel-in-progress: true |
| 38 | + |
| 39 | +env: |
| 40 | + ADVANCED_SECURITY: "false" |
| 41 | + TRIVY_SKIP_DIRS: "**/.git,**/node_modules" |
| 42 | + |
| 43 | +jobs: |
| 44 | + trivy-config: |
| 45 | + name: trivy-iac |
| 46 | + runs-on: ubuntu-latest |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v6 |
| 49 | + |
| 50 | + - name: Trivy config scan (SARIF) |
| 51 | + if: env.ADVANCED_SECURITY == 'true' |
| 52 | + uses: aquasecurity/trivy-action@0.34.0 |
| 53 | + with: |
| 54 | + scan-type: "config" |
| 55 | + scan-ref: "." |
| 56 | + skip-dirs: ${{ env.TRIVY_SKIP_DIRS }} |
| 57 | + format: "sarif" |
| 58 | + output: "trivy-config.sarif" |
| 59 | + severity: "CRITICAL,HIGH" |
| 60 | + exit-code: "0" |
| 61 | + hide-progress: "true" |
| 62 | + |
| 63 | + - name: Trivy config scan (table) |
| 64 | + if: env.ADVANCED_SECURITY != 'true' |
| 65 | + uses: aquasecurity/trivy-action@0.34.0 |
| 66 | + with: |
| 67 | + scan-type: "config" |
| 68 | + scan-ref: "." |
| 69 | + skip-dirs: ${{ env.TRIVY_SKIP_DIRS }} |
| 70 | + format: "table" |
| 71 | + output: "trivy-config.txt" |
| 72 | + severity: "CRITICAL,HIGH" |
| 73 | + exit-code: "0" |
| 74 | + hide-progress: "true" |
| 75 | + |
| 76 | + - name: Post Trivy config to job summary |
| 77 | + if: env.ADVANCED_SECURITY != 'true' |
| 78 | + run: | |
| 79 | + { |
| 80 | + echo "### Trivy IaC (Kubernetes / Helm)" |
| 81 | + echo "" |
| 82 | + if [[ -s trivy-config.txt ]]; then |
| 83 | + echo "<details><summary>Click to expand</summary>" |
| 84 | + echo "" |
| 85 | + echo '```' |
| 86 | + cat trivy-config.txt |
| 87 | + echo '```' |
| 88 | + echo "" |
| 89 | + echo "</details>" |
| 90 | + else |
| 91 | + echo "No CRITICAL/HIGH findings." |
| 92 | + fi |
| 93 | + echo "" |
| 94 | + } >> $GITHUB_STEP_SUMMARY |
| 95 | +
|
| 96 | + - name: Upload Trivy config SARIF |
| 97 | + if: env.ADVANCED_SECURITY == 'true' |
| 98 | + uses: github/codeql-action/upload-sarif@v3 |
| 99 | + continue-on-error: true |
| 100 | + with: |
| 101 | + sarif_file: "trivy-config.sarif" |
| 102 | + category: "trivy-iac-k8s-helm" |
| 103 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + |
| 105 | + - name: Upload Trivy SARIF as artifacts |
| 106 | + if: env.ADVANCED_SECURITY == 'true' |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: trivy-iac-sarif |
| 110 | + path: trivy-config.sarif |
0 commit comments