-
Notifications
You must be signed in to change notification settings - Fork 92
298 lines (252 loc) · 8.44 KB
/
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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
name: CI
on:
push:
branches:
- 'master'
tags:
- '*'
paths-ignore:
- '**/README.md'
- '.github/RELEASE.md'
- 'docs'
pull_request:
paths-ignore:
- '**/README.md'
- '.github/RELEASE.md'
- 'docs'
env:
image_name: intellabs/kafl
jobs:
ansible-lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Setup ansible venv
working-directory: deploy
run: |
make venv
- name: Install ansible-lint
working-directory: deploy
run: |
./venv/bin/pip install wheel
./venv/bin/pip install ansible-lint==6.16.0
# ignore 'meta-no-info', since we don't need to publish our roles to Ansible Galaxy
- name: Run ansible-lint
working-directory: deploy
run: |
./venv/bin/ansible-lint -x 'meta-no-info' -x galaxy -x 'yaml[octal-values]' -x no-changed-when -x risky-file-permissions --exclude venv
check-mode:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Run deployment in check mode (dry-run)
run: make deploy -- --check
local:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
# shallow clone for CI speed
- name: Setup ansible extra vars in JSON file
run: |
echo '{"git_clone_depth": 1}' >> parameters.json
working-directory: deploy
# skip tags related to non-existent hardware/configuration in the CI runner environment
- name: Test userspace deployment
run: >
make deploy --
--skip-tags "hardware_check,kvm_device"
--extra-vars "@parameters.json"
remote:
runs-on: ubuntu-20.04
services:
ssh:
image: wenzel/sshd:ubuntu22.04
ports:
# open SSH
- 5000:22
env:
ROOT_PASSWORD: toor
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
# shallow clone for CI speed
- name: Setup ansible extra vars in JSON file
run: |
echo '{"git_clone_depth": 1}' >> parameters.json
working-directory: deploy
- name: Setup ansible
run: |
make venv
working-directory: deploy
# the service container runs is accessible on 127.0.0.1:5000
- name: Setup inventory
run: |
venv/bin/python - << '__HERE__'
import yaml
with open("host_vars/localhost.yml", "w") as f:
data = {
"ansible_port": 5000,
"ansible_user": "root",
"ansible_ssh_pass": "toor",
"ansible_ssh_common_args": "-o StrictHostKeyChecking=no"
}
yaml.dump(data, f)
__HERE__
working-directory: deploy
- name: Install Python3 on service container
run: |
venv/bin/ansible all -i inventory -m raw -a "apt update"
venv/bin/ansible all -i inventory -m raw -a "apt install -y python3"
working-directory: deploy
- name: Upgrade packages
run: venv/bin/ansible all -i inventory -m ansible.builtin.apt -a "upgrade=dist"
working-directory: deploy
# skip tags related to non-existent hardware/configuration in the CI runner environment
- name: Test userspace deployment
run: >
make deploy --
--skip-tags "hardware_check,kvm_device,update_grub,reboot_kernel"
--extra-vars "@parameters.json"
docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
path: kafl
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.2.1
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4.1.1
with:
images: ${{ env.image_name }}
flavor: |
latest=true
- name: Build image
uses: docker/build-push-action@v3
with:
context: kafl/
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
# TODO: refactor in a separate in security.yml workflow
- name: Run Snyk to check Docker image for vulnerabilities
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
image: ${{ steps.meta.outputs.tags }}
# TODO: this action seems broken
# https://github.com/IntelLabs/kAFL/issues/161
continue-on-error: true
# - name: Upload result to GitHub Code Scanning
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: snyk.sarif
- run: mkdir bench-logs
- uses: actions/checkout@v3
with:
repository: docker/docker-bench-security
ref: 5a8d6434e6ebd70cb8bb465fce4ae5ed2a572eac
path: bench
# build image since dockerhub one is out of date
- name: Build Docker Bench for Security image
uses: docker/build-push-action@v3
with:
context: bench/
push: false
tags: docker-bench-security
load: true # load build result into docker
- name: Run Docker Bench for Security
run: >
docker run --net host --pid host --userns host --cap-add audit_control
-e DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST
-v /var/lib:/var/lib
-v /var/run/docker.sock:/var/run/docker.sock
-v /usr/lib/systemd:/usr/lib/systemd
-v /etc:/etc --label docker_bench_security
-v ${{ github.workspace }}/bench-logs:/usr/local/bin/log
docker-bench-security
-l log/log_file
-c container_images
-i intellabs/kafl
- uses: actions/upload-artifact@v3
with:
name: docker-bench-security
path: bench-logs/
push-docker-image:
runs-on: ubuntu-latest
needs: [docker-image]
if: ${{ github.event_name == 'push' }}
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.2.1
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4.1.1
with:
images: ${{ env.image_name }}
flavor: |
latest=true
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update Docker Hub description
uses: Wenzel/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.image_name }}
readme-filepath: ./.github/DOCKER.md
release:
# this job makes an official Github release
needs: [ansible-lint, check-mode, local, remote, docker-image]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
upload_url: ${{ steps.step_upload_url.outputs.upload_url }}
steps:
- uses: actions/checkout@v3
- name: Get the version
id: get_version
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
# only create release if tag start by 'v*'
- name: Create a Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_version.outputs.version }}
body_path: ${{ github.workspace }}/.github/RELEASE.md
if: startsWith(github.ref, 'refs/tags/v')
- id: step_upload_url
run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT