-
Notifications
You must be signed in to change notification settings - Fork 6
158 lines (156 loc) · 6.93 KB
/
security-ci.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Security Scan CI
on:
pull_request:
push:
branches:
- 'master'
jobs:
oss-scan:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
- name: Download Snyk CLI
run: |
curl https://static.snyk.io/cli/latest/snyk-linux -o ${{ github.workspace }}/snyk && chmod +x ${{ github.workspace }}/snyk
shell: bash
- name: Snyk Scan
continue-on-error: true
run: |
cd ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
${{ github.workspace }}/snyk --version
${{ github.workspace }}/snyk test --json-file-output=scan_result.json --project-name=${{ github.event.repository.name }} --file=go.mod
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
shell: bash
- name: Parse File for OSS
shell: bash
continue-on-error: true
run: |
cd ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
cat > parse-oss.py <<EOF
import json
def parse_snyk_oss_result():
json_file_path = 'scan_result.json'
with open(json_file_path) as json_file:
data = json.load(json_file)
output_file_path = './oss-scan-result.txt'
results = []
vulnerabilities = data['vulnerabilities']
for vulnerability in vulnerabilities:
if 'type' not in vulnerability or vulnerability['type'] != 'license':
title = vulnerability['title']
package_name = vulnerability['packageName']
severity = vulnerability['severity']
cve = vulnerability['identifiers']['CVE']
fix_version = vulnerability['fixedIn']
introduced = vulnerability['from']
result = {
'Title': title,
'Severity': severity,
'Package Name': package_name,
'CVEs': cve,
'Fix Version(s)': fix_version,
'Introduced': introduced
}
results.append(result)
with open(output_file_path, 'w') as file:
file.write("|Title|Severity|Package Name|CVEs|Fix version|Introduced|\n")
file.write("|---|---|---|---|---|---|\n")
for result in results:
file.write(f"{result['Title']} | ")
file.write(f"{result['Severity']} | ")
file.write(f"{result['Package Name']} | ")
file.write(f"{result['CVEs']} | ")
file.write(f"{result['Fix Version(s)']} | ")
file.write(f"{result['Introduced']} |")
file.write("\n")
file.write(f"\nTotal issues: {len(results)}")
file.close()
parse_snyk_oss_result()
EOF
python3 parse-oss.py
- name: Parse File for License
shell: bash
continue-on-error: true
run: |
cd ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
cat > parse-license.py <<EOF
import json
def parse_snyk_license_result():
json_file_path = 'scan_result.json'
with open(json_file_path) as json_file:
data = json.load(json_file)
output_file_path = './license-scan-result.txt'
results = []
vulnerabilities = data['vulnerabilities']
for vulnerability in vulnerabilities:
if 'type' in vulnerability and vulnerability['type'] == 'license':
title = vulnerability['title']
package_name = vulnerability['name']
version = vulnerability['version']
severity = vulnerability['severity']
license = vulnerability['license']
introduced = vulnerability['from']
result = {
'Title': title,
'Package Name': package_name,
'Package Version': version,
'Severity': severity,
'License Info': license,
'Introduced': introduced
}
results.append(result)
with open(output_file_path, 'w') as file:
file.write("|Title|Package Name|Package Version|Severity|License Info|Introduced|\n")
file.write("|---|---|---|---|---|---|\n")
for result in results:
file.write(f"{result['Title']} | ")
file.write(f"{result['Package Name']} | ")
file.write(f"{result['Package Version']} | ")
file.write(f"{result['Severity']} | ")
file.write(f"{result['License Info']} | ")
file.write(f"{result['Introduced']} |")
file.write("\n")
file.write(f"\nTotal License Issues: {len(results)}")
file.close()
parse_snyk_license_result()
EOF
python3 parse-license.py
- name: Create OSS comment on PR
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
uses: actions/github-script@v6
continue-on-error: true
with:
script: |
const fs = require('fs');
const filePath = '${{ github.workspace }}/go/src/github.com/${{ github.repository }}/oss-scan-result.txt';
const content = fs.readFileSync(filePath, 'utf8');
const body = `**OSS Scan Results:**\n\n${content}`;
github.rest.issues.createComment({
issue_number: context.payload.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
- name: Create License comment on PR
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
uses: actions/github-script@v6
continue-on-error: true
with:
script: |
const fs = require('fs');
const filePath = '${{ github.workspace }}/go/src/github.com/${{ github.repository }}/license-scan-result.txt';
const content = fs.readFileSync(filePath, 'utf8');
const body = `**License Evaluation Results:**\n\n${content}`;
github.rest.issues.createComment({
issue_number: context.payload.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});