Skip to content

Commit 5a7240e

Browse files
authored
Agent with full support for Apache (mod-php) multi-site configurations (#312)
1 parent 917d611 commit 5a7240e

File tree

35 files changed

+394
-245
lines changed

35 files changed

+394
-245
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ on:
1111

1212
jobs:
1313
build_libs:
14-
runs-on: ${{ matrix.os }}
14+
name: Build Go libs${{ matrix.arch }}
15+
runs-on: ubuntu-24.04${{ matrix.arch }}
1516
container:
1617
image: ghcr.io/aikidosec/firewall-php-build-libs:v1
1718
strategy:
1819
matrix:
19-
os: [ ubuntu-24.04, ubuntu-24.04-arm ]
20+
arch: [ '', '-arm' ]
2021
fail-fast: false
2122

2223
steps:
@@ -78,12 +79,13 @@ jobs:
7879
${{ github.workspace }}/build/aikido-request-processor.so
7980
8081
build_php_extension:
81-
runs-on: ${{ matrix.os }}
82+
name: Build php${{ matrix.php_version }} extension${{ matrix.arch }}
83+
runs-on: ubuntu-24.04${{ matrix.arch }}
8284
container: ghcr.io/aikidosec/firewall-php-build-extension:${{ matrix.php_version }}-v1
8385
strategy:
8486
matrix:
8587
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
86-
os: [ ubuntu-24.04, ubuntu-24.04-arm ]
88+
arch: [ '', '-arm' ]
8789
fail-fast: false
8890

8991
steps:
@@ -133,12 +135,13 @@ jobs:
133135
${{ github.workspace }}/tests/*.diff
134136
135137
build_rpm:
136-
runs-on: ${{ matrix.os }}
138+
name: Build rpm${{ matrix.arch }}
139+
runs-on: ubuntu-24.04${{ matrix.arch }}
137140
container:
138141
image: quay.io/centos/centos:stream9
139142
strategy:
140143
matrix:
141-
os: ['ubuntu-24.04', 'ubuntu-24.04-arm']
144+
arch: ['', '-arm']
142145
fail-fast: false
143146
needs: [ build_libs, build_php_extension ]
144147
steps:
@@ -227,12 +230,13 @@ jobs:
227230
~/rpmbuild/RPMS/${{ env.ARCH }}/${{ env.AIKIDO_ARTIFACT_RELEASE }}
228231
229232
build_deb:
230-
runs-on: ${{ matrix.os }}
233+
name: Build deb${{ matrix.arch }}
234+
runs-on: ubuntu-24.04${{ matrix.arch }}
231235
container:
232236
image: ubuntu:22.04
233237
strategy:
234238
matrix:
235-
os: [ ubuntu-24.04, ubuntu-24.04-arm ]
239+
arch: [ '', '-arm' ]
236240
fail-fast: false
237241
needs: [ build_rpm ]
238242
steps:
@@ -295,7 +299,8 @@ jobs:
295299
${{ env.AIKIDO_ARTIFACT }}
296300
297301
test_php_centos:
298-
runs-on: ${{ matrix.os }}
302+
name: CentOS php-${{ matrix.php_version }} ${{ matrix.server }}${{ matrix.arch }}
303+
runs-on: ubuntu-24.04${{ matrix.arch }}
299304
container:
300305
image: ghcr.io/aikidosec/firewall-php-test-centos:${{ matrix.php_version }}-v1
301306
options: --privileged
@@ -304,7 +309,7 @@ jobs:
304309
matrix:
305310
php_version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
306311
server: ['nginx-php-fpm', 'apache-mod-php', 'php-built-in']
307-
os: ['ubuntu-24.04', 'ubuntu-24.04-arm']
312+
arch: ['', '-arm']
308313
fail-fast: false
309314

310315
steps:
@@ -377,17 +382,18 @@ jobs:
377382
- name: Run ${{ matrix.server }} server tests
378383
run: |
379384
cd tools
380-
python3 run_server_tests.py ../tests/server ../tests/testlib --server=${{ matrix.server }}
385+
python3 run_server_tests.py ../tests/server ../tests/testlib --server=${{ matrix.server }} --max-runs=3
381386
382387
test_php_ubuntu:
383-
runs-on: ${{ matrix.os }}
388+
name: Ubuntu php-${{ matrix.php_version }} ${{ matrix.server }}${{ matrix.arch }}
389+
runs-on: ubuntu-24.04${{ matrix.arch }}
384390
container:
385391
image: ghcr.io/aikidosec/firewall-php-test-ubuntu:${{ matrix.php_version }}-v1
386392
options: --privileged
387393
needs: [ build_deb ]
388394
strategy:
389395
matrix:
390-
os: ['ubuntu-24.04', 'ubuntu-24.04-arm']
396+
arch: ['', '-arm']
391397
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
392398
server: ['nginx-php-fpm', 'apache-mod-php', 'php-built-in']
393399
fail-fast: false
@@ -434,26 +440,17 @@ jobs:
434440
dpkg -i -E ${{ env.AIKIDO_DEB }}/${{ env.AIKIDO_DEB }}
435441
436442
- name: Run CLI tests
437-
if: matrix.os == 'ubuntu-24.04' || matrix.os == 'ubuntu-24.04-arm'
438443
run: |
439444
php lib/php-extension/run-tests.php ./tests/cli
440445
441446
- name: Run ${{ matrix.server }} server tests
442447
run: |
448+
. /etc/apache2/envvars
443449
cd tools
444-
python3 run_server_tests.py ../tests/server ../tests/testlib --server=${{ matrix.server }}
445-
446-
- name: Archive test artifacts
447-
uses: actions/upload-artifact@v4
448-
if: always()
449-
with:
450-
name: test-results-aikido-${{ env.AIKIDO_VERSION }}-${{ matrix.os }}-php-${{ matrix.php_version }}
451-
if-no-files-found: ignore
452-
path: |
453-
${{ github.workspace }}/tests/cli/**/*.diff
450+
python3 run_server_tests.py ../tests/server ../tests/testlib --server=${{ matrix.server }} --max-runs=3
454451
455452
test_php_qa_action_controlling_tests_apache_mod_php:
456-
name: Tests (apache2 - mod_php)
453+
name: QA apache-mod-php
457454
runs-on: ubuntu-latest
458455
needs: [ build_deb ]
459456
steps:
@@ -480,7 +477,7 @@ jobs:
480477
echo "#!/usr/bin/env bash" > ./zen-demo-php/.fly/scripts/aikido.sh
481478
echo "dpkg -i -E \"/var/www/html/aikido-php-firewall.\$(uname -i).deb\"" >> ./zen-demo-php/.fly/scripts/aikido.sh
482479
- name: Run Firewall QA Tests
483-
uses: AikidoSec/firewall-tester-action@add-control-server-tests
480+
uses: AikidoSec/firewall-tester-action@releases/v1
484481
with:
485482
dockerfile_path: ./zen-demo-php/Dockerfile
486483
extra_args: '--env-file=./zen-demo-php/.env.example -e APP_KEY=base64:W2v6u6VR4lURkxuMT9xZ6pdhXSt5rxsmWTbd1HGqlIM='
@@ -489,7 +486,7 @@ jobs:
489486
test_type: control
490487

491488
test_php_qa_action_controlling_tests_apache_php_fpm:
492-
name: Tests (apache2 - php-fpm)
489+
name: QA apache-php-fpm
493490
runs-on: ubuntu-latest
494491
needs: [ build_deb ]
495492
steps:
@@ -516,7 +513,7 @@ jobs:
516513
echo "#!/usr/bin/env bash" > ./zen-demo-php/.fly/scripts/aikido.sh
517514
echo "dpkg -i -E \"/var/www/html/aikido-php-firewall.\$(uname -i).deb\"" >> ./zen-demo-php/.fly/scripts/aikido.sh
518515
- name: Run Firewall QA Tests
519-
uses: AikidoSec/firewall-tester-action@add-control-server-tests
516+
uses: AikidoSec/firewall-tester-action@releases/v1
520517
with:
521518
dockerfile_path: ./zen-demo-php/Dockerfile
522519
extra_args: '--env-file=./zen-demo-php/.env.example -e APP_KEY=base64:W2v6u6VR4lURkxuMT9xZ6pdhXSt5rxsmWTbd1HGqlIM='
@@ -525,7 +522,7 @@ jobs:
525522
test_type: control
526523

527524
test_php_qa_action_controlling_tests_nginx_php_fpm:
528-
name: Tests (nginx - php-fpm)
525+
name: QA nginx-php-fpm
529526
runs-on: ubuntu-latest
530527
needs: [ build_deb ]
531528
steps:
@@ -552,7 +549,7 @@ jobs:
552549
echo "#!/usr/bin/env bash" > ./zen-demo-php/.fly/scripts/aikido.sh
553550
echo "dpkg -i -E \"/var/www/html/aikido-php-firewall.\$(uname -i).deb\"" >> ./zen-demo-php/.fly/scripts/aikido.sh
554551
- name: Run Firewall QA Tests
555-
uses: AikidoSec/firewall-tester-action@add-control-server-tests
552+
uses: AikidoSec/firewall-tester-action@releases/v1
556553
with:
557554
dockerfile_path: ./zen-demo-php/Dockerfile
558555
extra_args: '--env-file=./zen-demo-php/.env.example -e APP_KEY=base64:W2v6u6VR4lURkxuMT9xZ6pdhXSt5rxsmWTbd1HGqlIM='

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ Prerequisites:
3939

4040
##### x86_64
4141
```
42-
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.x86_64.rpm
42+
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.x86_64.rpm
4343
```
4444

4545
##### arm64 / aarch64
4646
```
47-
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.aarch64.rpm
47+
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.aarch64.rpm
4848
```
4949

5050
#### For Debian-based Systems (Debian, Ubuntu)
5151

5252
##### x86_64
5353
```
54-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.x86_64.deb
54+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.x86_64.deb
5555
dpkg -i -E ./aikido-php-firewall.x86_64.deb
5656
```
5757

5858
##### arm64 / aarch64
5959
```
60-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.aarch64.deb
60+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.aarch64.deb
6161
dpkg -i -E ./aikido-php-firewall.aarch64.deb
6262
```
6363

docs/aws-elastic-beanstalk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
```
55
commands:
66
aikido-php-firewall:
7-
command: "rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.x86_64.rpm"
7+
command: "rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.x86_64.rpm"
88
ignoreErrors: true
99
1010
files:

docs/fly-io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Create a script to install the Aikido PHP Firewall during deployment:
3232
#!/usr/bin/env bash
3333
cd /tmp
3434

35-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.x86_64.deb
35+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.x86_64.deb
3636
dpkg -i -E ./aikido-php-firewall.x86_64.deb
3737
```
3838

docs/laravel-forge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cd /tmp
2121
2222
# Install commands from the "Manual install" section below, based on your OS
2323
24-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.5/aikido-php-firewall.x86_64.deb
24+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.6/aikido-php-firewall.x86_64.deb
2525
dpkg -i -E ./aikido-php-firewall.x86_64.deb
2626
2727
# Restarting the php services in order to load the Aikido PHP Firewall

lib/agent/aikido_types/init_data.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ func NewServerDataPolling() *ServerDataPolling {
129129
}
130130
}
131131

132+
type ServerKey struct {
133+
ServerPID int32
134+
Token string
135+
}
136+
132137
type ServerData struct {
133138
// Logger for the server
134139
Logger *log.AikidoLogger

lib/agent/cloud/cloud.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
func Init(server *ServerData) {
99
server.StatsData.StartedAt = utils.GetTime()
1010
server.StatsData.MonitoredSinkTimings = make(map[string]MonitoredSinkTimings)
11-
SendStartEvent(server)
11+
12+
CheckConfigUpdatedAt(server)
1213

1314
utils.StartPollingRoutine(server.PollingData.HeartbeatRoutineChannel, server.PollingData.HeartbeatTicker, SendHeartbeatEvent, server)
1415
utils.StartPollingRoutine(server.PollingData.ConfigPollingRoutineChannel, server.PollingData.ConfigPollingTicker, CheckConfigUpdatedAt, server)

lib/agent/cloud/event.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
. "main/aikido_types"
1010
"main/config"
1111
"main/log"
12+
"main/utils"
1213
"net/http"
1314
"net/url"
1415
)
@@ -32,11 +33,11 @@ func SendCloudRequest(server *ServerData, endpoint string, route string, method
3233
return nil, fmt.Errorf("failed to marshal payload: %v", err)
3334
}
3435

35-
log.Infof(server.Logger, "Sending %s request to %s with size %d and content: %s", method, apiEndpoint, len(jsonData), jsonData)
36+
log.Infof(server.Logger, "[%s] Sending %s request to %s with size %d and content: %s", utils.AnonymizeToken(token), method, apiEndpoint, len(jsonData), jsonData)
3637

3738
req, err = http.NewRequest(method, apiEndpoint, bytes.NewBuffer(jsonData))
3839
} else {
39-
log.Infof(server.Logger, "Sending %s request to %s", method, apiEndpoint)
40+
log.Infof(server.Logger, "[%s] Sending %s request to %s", utils.AnonymizeToken(token), method, apiEndpoint)
4041
req, err = http.NewRequest(method, apiEndpoint, nil)
4142
}
4243

lib/agent/constants/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package constants
22

33
const (
4-
Version = "1.4.5"
4+
Version = "1.4.6"
55
SocketPath = "/run/aikido-" + Version + "/aikido-agent.sock"
66
PidPath = "/run/aikido-" + Version + "/aikido-agent.pid"
77
ConfigUpdatedAtMethod = "GET"

lib/agent/globals/globals.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77

88
var Machine MachineData
99

10-
var Servers = make(map[string]*ServerData)
10+
var Servers = make(map[ServerKey]*ServerData)
11+
var PastDeletedServers = make(map[ServerKey]bool)
1112
var ServersMutex sync.RWMutex
1213

13-
func GetServer(token string) *ServerData {
14+
func GetServer(serverKey ServerKey) *ServerData {
1415
ServersMutex.RLock()
1516
defer ServersMutex.RUnlock()
1617

17-
server, exists := Servers[token]
18+
server, exists := Servers[serverKey]
1819
if !exists {
1920
return nil
2021
}
@@ -32,26 +33,34 @@ func GetServers() []*ServerData {
3233
return servers
3334
}
3435

35-
func GetServersTokens() []string {
36+
func GetServersKeys() []ServerKey {
3637
ServersMutex.RLock()
3738
defer ServersMutex.RUnlock()
3839

39-
tokens := []string{}
40-
for token := range Servers {
41-
tokens = append(tokens, token)
40+
serverKeys := []ServerKey{}
41+
for serverKey := range Servers {
42+
serverKeys = append(serverKeys, serverKey)
4243
}
43-
return tokens
44+
return serverKeys
4445
}
4546

46-
func CreateServer(token string) *ServerData {
47+
func CreateServer(ServerKey ServerKey) *ServerData {
4748
ServersMutex.Lock()
4849
defer ServersMutex.Unlock()
49-
Servers[token] = NewServerData()
50-
return Servers[token]
50+
Servers[ServerKey] = NewServerData()
51+
return Servers[ServerKey]
5152
}
5253

53-
func DeleteServer(token string) {
54+
func DeleteServer(ServerKey ServerKey) {
5455
ServersMutex.Lock()
5556
defer ServersMutex.Unlock()
56-
delete(Servers, token)
57+
delete(Servers, ServerKey)
58+
PastDeletedServers[ServerKey] = true
59+
}
60+
61+
func IsPastDeletedServer(ServerKey ServerKey) bool {
62+
ServersMutex.RLock()
63+
defer ServersMutex.RUnlock()
64+
_, exists := PastDeletedServers[ServerKey]
65+
return exists
5766
}

0 commit comments

Comments
 (0)