Skip to content

Commit f58548f

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

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-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+
// TrivyWorkflow represents a workflow that runs Trivy.
290+
TrivyWorkflow SASTWorkflowType = "Trivy"
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+
trivyWorkflows, err := getSastUsesWorkflows(c, "^aquasecurity/trivy-action$", checker.TrivyWorkflow)
91+
if err != nil {
92+
return data, err
93+
}
94+
data.Workflows = append(data.Workflows, trivyWorkflows...)
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 Trivy",
200+
files: []string{".github/workflows/github-trivy-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.TrivyWorkflow,
212+
File: checker.File{
213+
Path: ".github/workflows/github-trivy-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
- name: Build an image from Dockerfile
15+
run: docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
16+
- name: Run Trivy vulnerability scanner
17+
uses: aquasecurity/[email protected]
18+
with:
19+
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
20+
format: 'table'
21+
exit-code: '1'
22+
ignore-unfixed: true
23+
vuln-type: 'os,library'
24+
severity: 'CRITICAL,HIGH'

0 commit comments

Comments
 (0)