-
Notifications
You must be signed in to change notification settings - Fork 0
431 lines (373 loc) · 14.4 KB
/
build.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_call:
jobs:
build_libs:
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler protobuf-compiler-grpc
- name: GO setup
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Get Aikido version
run: |
AIKIDO_VERSION=$(grep '#define PHP_AIKIDO_VERSION' lib/php-extension/include/php_aikido.h | awk -F'"' '{print $2}')
echo $AIKIDO_VERSION
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
echo "AIKIDO_INTERNALS_REPO=https://api.github.com/repos/AikidoSec/zen-internals" >> $GITHUB_ENV
- name: Build Aikido Agent
run: |
cd lib
protoc --go_out=agent --go-grpc_out=agent ipc.proto
cd agent
go get main/ipc/protos
go get google.golang.org/grpc
go get github.com/stretchr/testify/assert
go test ./...
go build -ldflags "-s -w" -buildmode=c-shared -o ../../build/aikido-agent.so
ls -l ../../build
- name: Build Aikido Request Processor
run: |
ls -l ${{ github.workspace }}/build/
cd lib
protoc --go_out=request-processor --go-grpc_out=request-processor ipc.proto
cd request-processor
go mod tidy
go get google.golang.org/grpc
go get github.com/stretchr/testify/assert
go get github.com/seancfoley/ipaddress-go/ipaddr
go get main/ipc/protos
go test ./...
go build -ldflags "-s -w" -buildmode=c-shared -o ../../build/aikido-request-processor.so
ls -l ../../build
- name: Archive agent
uses: actions/upload-artifact@v4
if: always()
with:
name: aikido-agent
if-no-files-found: error
path: |
${{ github.workspace }}/build/aikido-agent.so
- name: Archive request processor
uses: actions/upload-artifact@v4
if: always()
with:
name: aikido-request-processor
if-no-files-found: error
path: |
${{ github.workspace }}/build/aikido-request-processor.so
build_php_extension:
runs-on: ubuntu-20.04
strategy:
matrix:
php_version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y autoconf bison re2c libxml2-dev libssl-dev libcurl4-gnutls-dev
- name: Get Aikido version
run: |
AIKIDO_VERSION=$(grep '#define PHP_AIKIDO_VERSION' lib/php-extension/include/php_aikido.h | awk -F'"' '{print $2}')
echo $AIKIDO_VERSION
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
echo "AIKIDO_ARTIFACT=aikido-extension-php-${{ matrix.php_version }}" >> $GITHUB_ENV
- name: Setup PHP
uses: AikidoSec/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: curl
coverage: none
- name: Check PHP setup
run: |
which php
php -v
php -i
- name: Build extension
run: |
cd ${{ github.workspace }}
rm -rf build
mkdir build
cd lib/php-extension
phpize
cd ../../build
CXX=g++ CXXFLAGS="-fPIC -O2 -I../lib/php-extension/include" LDFLAGS="-lstdc++" ../lib/php-extension/configure
make
- name: Version Aikido extension
run: |
cd ${{ github.workspace }}/build/modules
mv aikido.so ${{ env.AIKIDO_ARTIFACT }}.so
- name: Archive build artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ env.AIKIDO_ARTIFACT }}
if-no-files-found: error
path: |
${{ github.workspace }}/build/modules/${{ env.AIKIDO_ARTIFACT }}.so
${{ github.workspace }}/tests/*.diff
build_rpm:
runs-on: ubuntu-latest
container:
image: centos:latest
needs: [ build_libs, build_php_extension ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install rpmdevtools
run: |
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum -y install epel-release
yum -y install rpmdevtools
yum -y install jq
- name: Get Aikido version
run: |
AIKIDO_VERSION=$(grep '#define PHP_AIKIDO_VERSION' lib/php-extension/include/php_aikido.h | awk -F'"' '{print $2}')
echo $AIKIDO_VERSION
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
echo "AIKIDO_LIBZEN=libzen_internals_x86_64-unknown-linux-gnu.so" >> $GITHUB_ENV
echo "AIKIDO_LIBZEN_VERSION=0.1.31" >> $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: |
aikido-extension-php-*
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: |
aikido-agent*
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: |
aikido-request-processor*
- name: Download Aikido Zen Internals Lib
run: |
curl -L -O https://github.com/AikidoSec/zen-internals/releases/download/v${{ env.AIKIDO_LIBZEN_VERSION }}/${{ env.AIKIDO_LIBZEN }}
- name: Prepare rpm package
run: |
mv aikido-agent/aikido-agent.so package/rpm/opt/aikido/aikido-agent.so
mv aikido-request-processor/aikido-request-processor.so package/rpm/opt/aikido/aikido-request-processor.so
mv ${{ env.AIKIDO_LIBZEN }} package/rpm/opt/aikido/${{ env.AIKIDO_LIBZEN }}
mv aikido-extension-php-*/build/modules/aikido-extension-php-* package/rpm/opt/aikido/
mv package/rpm/opt/aikido package/rpm/opt/aikido-${{ env.AIKIDO_VERSION }}
chmod 777 package/rpm/opt/aikido-${{ env.AIKIDO_VERSION }}/*
rpmdev-setuptree
mkdir -p ~/rpmbuild/SOURCES/aikido-php-firewall-${{ env.AIKIDO_VERSION }}
cp -rf package/rpm/opt ~/rpmbuild/SOURCES/aikido-php-firewall-${{ env.AIKIDO_VERSION }}/
cp -f package/rpm/aikido.spec ~/rpmbuild/SPECS/
- name: Setup RPM for prod
run: |
echo "AIKIDO_ARTIFACT=aikido-php-firewall-$AIKIDO_VERSION-1.x86_64.rpm" >> $GITHUB_ENV
echo "AIKIDO_ARTIFACT_RELEASE=aikido-php-firewall.x86_64.rpm" >> $GITHUB_ENV
sed -i "s/aikido.so/aikido-${{ env.AIKIDO_VERSION }}.so/" ~/rpmbuild/SOURCES/aikido-php-firewall-${{ env.AIKIDO_VERSION }}/opt/aikido-${{ env.AIKIDO_VERSION }}/aikido.ini
- name: Build rpm package
run: |
cd ~/rpmbuild/SOURCES
tar czvf ~/rpmbuild/SOURCES/aikido-php-firewall-${{ env.AIKIDO_VERSION }}.tar.gz *
rm -rf ~/rpmbuild/SOURCES/aikido-php-firewall-${{ env.AIKIDO_VERSION }}
rpmbuild -ba ~/rpmbuild/SPECS/aikido.spec
ls -l ~/rpmbuild/RPMS/x86_64/
mv ~/rpmbuild/RPMS/x86_64/${{ env.AIKIDO_ARTIFACT }} ~/rpmbuild/RPMS/x86_64/${{ env.AIKIDO_ARTIFACT_RELEASE }}
- name: Check rpm dependencies
run: |
yum deplist ~/rpmbuild/RPMS/x86_64/${{ env.AIKIDO_ARTIFACT_RELEASE }} | grep -E "GLIBC_2.32|GLIBC_2.34|GLIBCXX_3.4.29" && exit 1 || exit 0
- name: Archive rpm package
uses: actions/upload-artifact@v4
with:
name: ${{ env.AIKIDO_ARTIFACT_RELEASE }}
if-no-files-found: error
path: |
~/rpmbuild/RPMS/x86_64/${{ env.AIKIDO_ARTIFACT_RELEASE }}
build_deb:
runs-on: ubuntu-20.04
needs: [ build_rpm ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: |
aikido-php-firewall*
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y alien
- name: Get Aikido version
run: |
AIKIDO_VERSION=$(grep '#define PHP_AIKIDO_VERSION' lib/php-extension/include/php_aikido.h | awk -F'"' '{print $2}')
echo $AIKIDO_VERSION
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
echo "AIKIDO_RPM=aikido-php-firewall.x86_64.rpm" >> $GITHUB_ENV
echo "AIKIDO_ARTIFACT=aikido-php-firewall.x86_64.deb" >> $GITHUB_ENV
- name: Build deb
run: |
ls -R
sudo alien --to-deb --scripts --keep-version ${{ env.AIKIDO_RPM }}/${{ env.AIKIDO_RPM }}
ls -R
mv aikido-php-firewall_${{ env.AIKIDO_VERSION }}-1_amd64.deb ${{ env.AIKIDO_ARTIFACT }}
- name: Archive deb package
uses: actions/upload-artifact@v4
with:
name: ${{ env.AIKIDO_ARTIFACT }}
if-no-files-found: error
path: |
${{ env.AIKIDO_ARTIFACT }}
test_php_centos:
runs-on: ubuntu-latest
container:
image: centos:latest
needs: [ build_rpm ]
strategy:
matrix:
php_version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
server: ['nginx-php-fpm', 'apache-mod-php', 'php-built-in']
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup
run: |
cat /etc/centos-release
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum install -y yum-utils
yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.4.rpm
yum -y install gcc python3-devel
pip3 install flask
pip3 install requests
pip3 install pandas
pip3 install psutil
yum install -y httpd
dnf --assumeyes module reset php
dnf --assumeyes --nogpgcheck module install php:remi-${{ matrix.php_version }}
dnf --assumeyes install php-pdo
yum install -y mod_php
yum install -y nginx
yum install -y php-fpm
- name: Check PHP setup
run: |
php -v
php -i
- name: Get Aikido version
run: |
AIKIDO_VERSION=$(grep '#define PHP_AIKIDO_VERSION' lib/php-extension/include/php_aikido.h | awk -F'"' '{print $2}')
echo $AIKIDO_VERSION
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
echo "AIKIDO_RPM=aikido-php-firewall.x86_64.rpm" >> $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: |
aikido-php-firewall*
- name: Install RPM
run: |
rpm -Uvh --oldpackage ${{ env.AIKIDO_RPM }}/${{ env.AIKIDO_RPM }}
- name: Run CLI tests
run: |
export TEST_PHP_EXECUTABLE=/usr/bin/php
php lib/php-extension/run-tests.php ./tests/cli
- name: Run ${{ matrix.server }} server tests
run: |
cd tools
python3 run_server_tests.py ../tests/server ../tests/testlib --server=${{ matrix.server }}
test_php_ubuntu:
runs-on: ${{ matrix.os }}
needs: [ build_deb ]
strategy:
matrix:
os: ['ubuntu-latest', 'ubuntu-20.04']
php_version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
server: ['nginx-php-fpm', 'apache-mod-php', 'php-built-in']
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: |
aikido-php-firewall*
- name: Set env
run: |
AIKIDO_VERSION=$(grep '#define PHP_AIKIDO_VERSION' lib/php-extension/include/php_aikido.h | awk -F'"' '{print $2}')
echo $AIKIDO_VERSION
echo "AIKIDO_VERSION=$AIKIDO_VERSION" >> $GITHUB_ENV
echo "AIKIDO_DEB=aikido-php-firewall.x86_64.deb" >> $GITHUB_ENV
- name: Setup nginx & php-fpm
run: |
sudo apt-get install -y nginx php-fpm
- name: Setup Apache (mod_php)
run: |
sudo apt-get install -y nginx php-fpm
sudo apt-get install -y apache2
sudo a2dismod mpm_event
sudo a2dismod mpm_worker
sudo a2enmod mpm_prefork
sudo a2enmod rewrite
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: curl
coverage: none
- name: Check PHP setup
run: |
php_versions=("php7.3" "php7.4" "php8.0" "php8.1" "php8.2" "php8.3")
for version in "${php_versions[@]}"; do
if a2query -m "$version" > /dev/null 2>&1; then
echo "Disabling $version..."
sudo a2dismod "$version"
else
echo "$version is not installed."
fi
done
sudo apt-get update
sudo apt install libapache2-mod-php${{ matrix.php_version }}
sudo a2enmod php${{ matrix.php_version }}
php -i
- name: Setup Python
run: |
sudo apt-get install -y python3-flask python3-pandas python3-psutil
python --version
- name: Install DEB
run: |
sudo dpkg -i -E ${{ env.AIKIDO_DEB }}/${{ env.AIKIDO_DEB }}
- name: Run CLI tests
if: matrix.os == 'ubuntu-latest'
run: |
cd ${{ github.workspace }}
php lib/php-extension/run-tests.php ./tests/cli
- name: Run ${{ matrix.server }} server tests
run: |
cd tools
sudo python3 run_server_tests.py ../tests/server ../tests/testlib --server=${{ matrix.server }}
- name: Archive test artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-aikido-${{ env.AIKIDO_VERSION }}-${{ matrix.os }}-php-${{ matrix.php_version }}
if-no-files-found: ignore
path: |
${{ github.workspace }}/tests/cli/**/*.diff