Skip to content

Commit d483f60

Browse files
committed
🌱 add support for Checkov SAST tool
Signed-off-by: Adam Korczynski <[email protected]>
1 parent 6a4529c commit d483f60

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

checker/raw_result.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ const (
286286
PysaWorkflow SASTWorkflowType = "Pysa"
287287
// QodanaWorkflow represents a workflow that runs Qodana.
288288
QodanaWorkflow SASTWorkflowType = "Qodana"
289+
// CheckovWorkflow represents a workflow that runs Checkov.
290+
CheckovWorkflow SASTWorkflowType = "Checkov"
289291
)
290292

291293
// SASTWorkflow represents a SAST workflow.

checks/raw/sast.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ func SAST(c *checker.CheckRequest) (checker.SASTData, error) {
8787
}
8888
data.Workflows = append(data.Workflows, qodanaWorkflows...)
8989

90+
CheckovWorkflows, err := getSastUsesWorkflows(c, "^bridgecrewio/checkov-action$", checker.CheckovWorkflow)
91+
if err != nil {
92+
return data, err
93+
}
94+
data.Workflows = append(data.Workflows, CheckovWorkflows...)
95+
9096
return data, nil
9197
}
9298

checks/raw/sast_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ func TestSAST(t *testing.T) {
195195
},
196196
},
197197
},
198+
{
199+
name: "Has Checkov",
200+
files: []string{".github/workflows/github-checkov-workflow.yaml"},
201+
commits: []clients.Commit{
202+
{
203+
AssociatedMergeRequest: clients.PullRequest{
204+
Number: 1,
205+
},
206+
},
207+
},
208+
expected: checker.SASTData{
209+
Workflows: []checker.SASTWorkflow{
210+
{
211+
Type: checker.CheckovWorkflow,
212+
File: checker.File{
213+
Path: ".github/workflows/github-checkov-workflow.yaml",
214+
Offset: checker.OffsetDefault,
215+
Type: finding.FileTypeSource,
216+
},
217+
},
218+
},
219+
},
220+
},
198221
}
199222
for _, tt := range tests {
200223
t.Run(tt.name, func(t *testing.T) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: checkov
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the "main" branch
6+
push:
7+
branches: [ "main", "master" ]
8+
pull_request:
9+
branches: [ "main", "master" ]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
15+
jobs:
16+
# This workflow contains a single job called "scan"
17+
scan:
18+
permissions:
19+
contents: read # for actions/checkout to fetch code
20+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
21+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
22+
23+
# The type of runner that the job will run on
24+
runs-on: ubuntu-latest
25+
26+
# Steps represent a sequence of tasks that will be executed as part of the job
27+
steps:
28+
# Checks-out your repository under $GITHUB_WORKSPACE, so follow-up steps can access it
29+
- uses: actions/checkout@v3
30+
31+
- name: Checkov GitHub Action
32+
uses: bridgecrewio/checkov-action@v12
33+
with:
34+
# This will add both a CLI output to the console and create a results.sarif file
35+
output_format: cli,sarif
36+
output_file_path: console,results.sarif
37+
38+
- name: Upload SARIF file
39+
uses: github/codeql-action/upload-sarif@v2
40+
41+
# Results are generated only on a success or failure
42+
# this is required since GitHub by default won't run the next step
43+
# when the previous one has failed. Security checks that do not pass will 'fail'.
44+
# An alternative is to add `continue-on-error: true` to the previous step
45+
# Or 'soft_fail: true' to checkov.
46+
if: success() || failure()
47+
with:
48+
sarif_file: results.sarif

0 commit comments

Comments
 (0)