-
Notifications
You must be signed in to change notification settings - Fork 176
220 lines (190 loc) · 7.37 KB
/
scanner-nvd-update.yaml
File metadata and controls
220 lines (190 loc) · 7.37 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: Scanner NVD update
on:
pull_request:
types:
- opened
- reopened
- synchronize
schedule:
- cron: '0 */6 * * *'
workflow_dispatch:
jobs:
fetch-nvd-feeds:
runs-on: ubuntu-latest
if: >
github.repository_owner == 'stackrox' &&
github.event_name == 'schedule' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'pr-update-scanner-nvd'))
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # ratchet:actions/setup-python@v6
with:
python-version: '3.10'
- name: Fetch NVD Feeds
run: |
set -eu
dir=$(mktemp -d)
python3 .github/workflows/scripts/scanner-update-nvd-feeds.py "$dir"
for f in "$dir"/*.nvd.json; do
if jq . "$f" >/dev/null 2>&1; then
echo "Validating and adding '$f' to nvd-feeds.zip"
zip -j nvd-feeds.zip "$f"
else
echo "Error: Invalid JSON file '$f'"
exit 1
fi
done
- uses: ./.github/actions/upload-artifact-with-retry
with:
name: nvd-feeds
path: nvd-feeds.zip
if-no-files-found: error
fetch-nvd-api:
runs-on: ubuntu-latest
if: >
github.event_name == 'schedule' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'pr-update-scanner-nvd'))
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # ratchet:actions/setup-python@v6
with:
python-version: '3.10'
- name: Fetch NVD API
env:
SCANNER_NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
SCANNER_NVD_URL: https://services.nvd.nist.gov/rest/json/cves/2.0
run: |
set -eu
dir=$(mktemp -d)
python3 .github/workflows/scripts/scanner-update-nvd-api.py "$dir"
for f in "$dir"/*.nvd.json; do
if jq . "$f" >/dev/null 2>&1; then
echo "Validating and adding '$f' to nvd-api.zip"
zip -j nvd-api.zip "$f"
else
echo "Error: Invalid JSON file '$f'"
exit 1
fi
done
- uses: ./.github/actions/upload-artifact-with-retry
with:
name: nvd-api
path: nvd-api.zip
if-no-files-found: error
upload-pr-nvd-feeds:
needs:
- fetch-nvd-feeds
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'pr-update-scanner-nvd')
steps:
# Checkout master to get the latest local actions
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/job-preamble
with:
free-disk-space: 50
gcp-account: ${{ secrets.GCP_SERVICE_ACCOUNT_STACKROX_CI }}
- name: Checkout specific reference
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Authenticate with test GCS bucket
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # ratchet:google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GOOGLE_SA_CIRCLECI_SCANNER }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # ratchet:google-github-actions/setup-gcloud@v3
- name: Download NVD
uses: ./.github/actions/download-artifact-with-retry
with:
name: nvd-feeds
path: .
# PR owner is responsible for verifying NVD bundle is generated
- name: Upload NVD Feeds to Google Cloud Storage
run: |
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
# Replace / with -, so the branch name isn't truncated when pushed to GCS.
dir=${branch////-}
case "$dir" in
dev|1.0.0)
echo "Error: branch $dir is protected. Choose a different branch name."
exit 1
esac
mkdir -p "$dir"
cp nvd-feeds.zip "$dir/"
gsutil -m cp -r "$dir" "gs://scanner-v4-test/nvd/"
# Checkout again to get the latest local actions for cleanup phase
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
if: always()
with:
fetch-depth: 0
upload-nvd-feeds:
needs:
- fetch-nvd-feeds
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.ref }}
- uses: ./.github/actions/download-artifact-with-retry
with:
name: nvd-feeds
path: .
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # ratchet:google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GOOGLE_SA_STACKROX_HUB_VULN_DUMP_UPLOADER }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # ratchet:google-github-actions/setup-gcloud@v3
- name: Upload NVD Feeds to Google Cloud Storage
run: |
gsutil cp nvd-feeds.zip "gs://definitions.stackrox.io/v4/nvd/nvd-feeds.zip"
upload-nvd-api:
needs:
- fetch-nvd-api
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.ref }}
- uses: ./.github/actions/download-artifact-with-retry
with:
name: nvd-api
path: .
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # ratchet:google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GOOGLE_SA_STACKROX_HUB_VULN_DUMP_UPLOADER }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # ratchet:google-github-actions/setup-gcloud@v3
- name: Upload NVD API to Google Cloud Storage
run:
gsutil cp nvd-api.zip "gs://definitions.stackrox.io/v4/nvd/nvd-api.zip"
send-notification:
needs:
- upload-nvd-feeds
- upload-nvd-api
runs-on: ubuntu-latest
if: ${{ failure() && github.ref_name == 'master' }}
steps:
- name: Send Slack notification on workflow failure
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"<${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}|Workflow ${{ github.workflow }}> failed in repository ${{ github.repository }}: Failed to update NVD CVEs"}' ${{ secrets.SLACK_ONCALL_SCANNER_WEBHOOK }}