forked from clouddrove/github-shared-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (75 loc) · 2.25 KB
/
Copy pathsecurity-checkov.yml
File metadata and controls
84 lines (75 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
name: Checkov Security Scan
on:
workflow_call:
inputs:
directory:
required: true
type: string
continue_on_error:
required: true
type: string
default: 'true'
var_file:
required: false
type: string
skip_check:
required: false
type: string
default: ''
output_format:
required: false
type: string
default: 'cli,sarif'
output_file_path:
required: false
type: string
default: 'console,results.sarif'
permissions:
contents: read
security-events: write
actions: read
pull-requests: write
jobs:
scan:
runs-on: ubuntu-latest
steps:
- name: 📦 Checkout Repository
uses: actions/checkout@v7
- name: 🧹 Cleanup Old SARIF
run: rm -f results.sarif || true
- name: 🛡️ Run Checkov (Docker-based)
id: checkov
continue-on-error: true
uses: bridgecrewio/checkov-action@v12
with:
directory: ${{ inputs.directory }}
framework: terraform
soft_fail: ${{ inputs.continue_on_error == 'true' }}
var_file: ${{ inputs.var_file }}
download_external_modules: false
skip_check: ${{ inputs.skip_check }}
output_format: ${{ inputs.output_format }}
output_file_path: ${{ inputs.output_file_path }}
- name: 📤 Upload SARIF to GitHub Security
if: always() && !cancelled()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: results.sarif
category: checkov
- name: 💬 Comment on PR with Checkov results
if: github.event_name == 'pull_request'
uses: clouddrove/checkov-sarif-view@v0.0.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
sarif_file: results.sarif
- name: ❌ Fail if Issues Found
if: always() && github.event_name == 'pull_request'
run: |
ISSUE_COUNT=$(jq '.runs[0].results | length' results.sarif)
echo "Checkov Issue Count: $ISSUE_COUNT"
if [ "$ISSUE_COUNT" -gt 0 ]; then
echo "::error::Checkov found $ISSUE_COUNT security issues. Failing the workflow."
exit 1
fi
...