-
Notifications
You must be signed in to change notification settings - Fork 3.5k
71 lines (62 loc) · 2.26 KB
/
vulnerability-scan.yml
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
name: PR Vulnerability Scan
on: pull_request
permissions:
pull-requests: write
contents: write
jobs:
snyk:
name: Snyk Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/golang@master
continue-on-error: true # To make sure that PR comment is made
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
args: --severity-threshold=high --json-file-output=snyk.json
- name: Format Snyk Message
uses: sergeysova/jq-action@v2
id: snyk-message
with:
cmd: jq -r '.vulnerabilities[] | "* **\(.severity)** - [\(.identifiers.CVE[0])] \(.title) in \(.moduleName) v\(.version). Fixed in \(.fixedIn)\n"' snyk.json > snyk.txt
- name: Comment on PR with Snyk scan results
uses: mshick/add-pr-comment@v2
with:
message-id: snyk-${{ github.event.number }}
message-path: snyk.txt
trivy:
name: Trivy Scan
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Loki Image
run: |
IMAGE_TAG="$(./tools/image-tag)"
make loki-image
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "docker.io/grafana/loki:${{ env.IMAGE_TAG }}"
format: "json"
output: "trivy.json"
- name: Format Trivy Message
uses: sergeysova/jq-action@v2
id: trivy-message
with:
cmd: jq -r '.Results[] | .Vulnerabilities[] | "* **\(.Severity)** [\(.Title)](\(.PrimaryURL)) in \(.PkgName) v\(.InstalledVersion). Fixed in v\(.FixedVersion)\n"' trivy.json
multiline: true
- name: Write Trivy message to file
run: |
echo "Trivy scan found the following vulnerabilities:" > trivy.txt
printf "${{ steps.trivy-message.outputs.value }}" >> trivy.txt
- name: Comment on PR with Trivy scan results
uses: mshick/add-pr-comment@v2
with:
message-id: trivy-${{ github.event.number }}
message-path: trivy.txt