Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
58af860
Aikido Agent standalone
tudor-timcu Oct 13, 2025
b03c31b
1.3.7
tudor-timcu Oct 13, 2025
54eb2b8
Agent support multiple servers
tudor-timcu Oct 13, 2025
2aa8b05
Fix
tudor-timcu Oct 13, 2025
4f08c60
Fix
tudor-timcu Oct 13, 2025
42e3b92
Using mutex guards to sync access to servers map
tudor-timcu Oct 16, 2025
7eaf13b
Partial commit
tudor-timcu Oct 17, 2025
9183f50
Fixes
tudor-timcu Oct 17, 2025
153da6f
Fix
tudor-timcu Oct 18, 2025
29da8f6
Fixes
tudor-timcu Oct 18, 2025
c43db43
Fix
tudor-timcu Oct 18, 2025
777ee67
f
tudor-timcu Oct 18, 2025
6635cf7
Refactor gRPC server methods to handle nil server cases and improve s…
tudor-timcu Oct 20, 2025
6641e37
Version 2.0.1
tudor-timcu Oct 20, 2025
ca14a7c
Run tests
tudor-timcu Oct 20, 2025
f73feac
Remove token prints
tudor-timcu Oct 20, 2025
dc88606
Cleaner diff
tudor-timcu Oct 20, 2025
d90c271
Rename
tudor-timcu Oct 20, 2025
1e060e1
Remove unused
tudor-timcu Oct 20, 2025
c2c66f9
Cleanup
tudor-timcu Oct 20, 2025
d55f597
Improvements
tudor-timcu Oct 20, 2025
1e6f199
Stop all running Aikido Agents
tudor-timcu Oct 20, 2025
9cc58c4
1.4.0
tudor-timcu Oct 20, 2025
6734c8b
Fixes
tudor-timcu Oct 20, 2025
4bdaf6a
Fixes
tudor-timcu Oct 20, 2025
a1518cb
Fixes
tudor-timcu Oct 20, 2025
d4e0a64
Fixes
tudor-timcu Oct 20, 2025
53d2236
Fixed sync
tudor-timcu Oct 20, 2025
7daa188
Check faster
tudor-timcu Oct 20, 2025
ccca106
Sigterm
tudor-timcu Oct 20, 2025
a30d2eb
2 minutes
tudor-timcu Oct 21, 2025
2f68b3d
nginx + php-fpm tests work with pool conf
tudor-timcu Oct 21, 2025
dab5069
f
tudor-timcu Oct 21, 2025
1facbea
Fix
tudor-timcu Oct 21, 2025
754f5e7
Fix
tudor-timcu Oct 21, 2025
6a12847
Fix
tudor-timcu Oct 21, 2025
7d5223f
F
tudor-timcu Oct 21, 2025
94cd179
test
tudor-timcu Oct 21, 2025
c825acd
Fixes
tudor-timcu Oct 21, 2025
8307294
f
tudor-timcu Oct 21, 2025
32812c5
Fixed
tudor-timcu Oct 21, 2025
0cf07f8
Test
tudor-timcu Oct 21, 2025
f310da5
Extended support for apache-mod-php multi-site, that reuses the same …
tudor-timcu Oct 21, 2025
623a849
Support for apache mod-php
tudor-timcu Oct 22, 2025
b517300
Test back
tudor-timcu Oct 22, 2025
463142e
Fixes
tudor-timcu Oct 22, 2025
7033efd
Fixes
tudor-timcu Oct 22, 2025
0e0b114
Fix
tudor-timcu Oct 22, 2025
0ee4d94
f
tudor-timcu Oct 22, 2025
99e7937
test
tudor-timcu Oct 22, 2025
7b80646
Cleanup and simplify
tudor-timcu Oct 22, 2025
babdf7c
Fixes
tudor-timcu Oct 22, 2025
a81c220
F
tudor-timcu Oct 22, 2025
42f4806
Fixes
tudor-timcu Oct 22, 2025
acae366
Remove pid
tudor-timcu Oct 22, 2025
14f784f
Remove token from Init
tudor-timcu Oct 22, 2025
61d0e70
F
tudor-timcu Oct 22, 2025
5446fb3
Fix
tudor-timcu Oct 23, 2025
414a3ba
Logger changes
tudor-timcu Oct 23, 2025
d6afdcb
Fix logger
tudor-timcu Oct 23, 2025
aca53eb
Fix
tudor-timcu Oct 23, 2025
51ffebf
Fix
tudor-timcu Oct 23, 2025
2fe416c
Fixes
tudor-timcu Oct 23, 2025
7da639d
Fix test
tudor-timcu Oct 23, 2025
2a2adf8
Merge branch 'main' into one-agent
tudor-timcu Oct 23, 2025
d8e728a
Sync
tudor-timcu Oct 23, 2025
98e3550
Fix
tudor-timcu Oct 23, 2025
683321c
Fix
tudor-timcu Oct 23, 2025
7fd491c
Fix
tudor-timcu Oct 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ Prerequisites:

##### x86_64
```
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.x86_64.rpm
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.x86_64.rpm
```

##### arm64 / aarch64
```
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.aarch64.rpm
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.aarch64.rpm
```

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

##### x86_64
```
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.x86_64.deb
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.x86_64.deb
dpkg -i -E ./aikido-php-firewall.x86_64.deb
```

##### arm64 / aarch64
```
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.aarch64.deb
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.aarch64.deb
dpkg -i -E ./aikido-php-firewall.aarch64.deb
```

Expand Down
2 changes: 1 addition & 1 deletion docs/aws-elastic-beanstalk.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```
commands:
aikido-php-firewall:
command: "rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.x86_64.rpm"
command: "rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.x86_64.rpm"
ignoreErrors: true
files:
Expand Down
2 changes: 1 addition & 1 deletion docs/fly-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Create a script to install the Aikido PHP Firewall during deployment:
#!/usr/bin/env bash
cd /tmp

curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.x86_64.deb
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.x86_64.deb
dpkg -i -E ./aikido-php-firewall.x86_64.deb
```

Expand Down
2 changes: 1 addition & 1 deletion docs/laravel-forge.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cd /tmp

# Install commands from the "Manual install" section below, based on your OS

curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.6/aikido-php-firewall.x86_64.deb
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.4.0/aikido-php-firewall.x86_64.deb
dpkg -i -E ./aikido-php-firewall.x86_64.deb

# Restarting the php services in order to load the Aikido PHP Firewall
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package globals
package aikido_types

const (
Version = "1.3.6"
Version = "1.4.0"
ConfigUpdatedAtMethod = "GET"
ConfigUpdatedAtAPI = "/config"
ConfigAPIMethod = "GET"
Expand All @@ -16,7 +16,5 @@ const (
MaxAttackDetectedEventsPerInterval = 100
AttackDetectedEventsIntervalInMs = 60 * 60 * 1000 // 1 hour
MinStatsCollectedForRelevantMetrics = 1000
MaxNumberOfStoredUsers = 2000
MaxNumberOfStoredRoutes = 5000
MaxNumberOfStoredHostnames = 2000
MinServerInactivityForCleanup = 10 * 60 * 1000 // 10 minutes
)
132 changes: 126 additions & 6 deletions lib/agent/aikido_types/init_data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package aikido_types

import "sync"
import (
"sync"
"time"
)

type MachineData struct {
HostName string `json:"hostname"`
Expand All @@ -11,16 +14,18 @@ type MachineData struct {
}

type EnvironmentConfigData struct {
SocketPath string `json:"socket_path"` // '/run/aikido-{version}/aikido-{datetime}-{randint}.sock'
PlatformName string `json:"platform_name"` // PHP platform name (fpm-fcgi, cli-server, ...)
PlatformVersion string `json:"platform_version"` // PHP version
Endpoint string `json:"endpoint,omitempty"` // default: 'https://guard.aikido.dev/'
ConfigEndpoint string `json:"config_endpoint,omitempty"` // default: 'https://runtime.aikido.dev/'
SocketPath string `json:"socket_path"` // '/run/aikido-{version}/aikido-{datetime}-{randint}.sock'
DiskLogs bool `json:"disk_logs"` // default: false
LogLevel string `json:"log_level"` // default: 'INFO'
}

type AikidoConfigData struct {
ConfigMutex sync.Mutex
PlatformName string `json:"platform_name"` // PHP platform name (fpm-fcgi, cli-server, ...)
PlatformVersion string `json:"platform_version"` // PHP version
Token string `json:"token,omitempty"` // default: ''
Endpoint string `json:"endpoint,omitempty"` // default: 'https://guard.aikido.dev/'
ConfigEndpoint string `json:"config_endpoint,omitempty"` // default: 'https://runtime.aikido.dev/'
LogLevel string `json:"log_level,omitempty"` // default: 'INFO'
DiskLogs bool `json:"disk_logs,omitempty"` // default: false
Blocking bool `json:"blocking,omitempty"` // default: false
Expand Down Expand Up @@ -93,3 +98,118 @@ type CloudConfigUpdatedAt struct {
ServiceId int `json:"serviceId"`
ConfigUpdatedAt int64 `json:"configUpdatedAt"`
}

type ServerDataPolling struct {
HeartbeatRoutineChannel chan struct{}
HeartbeatTicker *time.Ticker
ConfigPollingRoutineChannel chan struct{}
ConfigPollingTicker *time.Ticker
RateLimitingChannel chan struct{}
RateLimitingTicker *time.Ticker
}

func NewServerDataPolling() *ServerDataPolling {
return &ServerDataPolling{
HeartbeatRoutineChannel: make(chan struct{}),
HeartbeatTicker: time.NewTicker(10 * time.Minute),
ConfigPollingRoutineChannel: make(chan struct{}),
ConfigPollingTicker: time.NewTicker(1 * time.Minute),
RateLimitingChannel: make(chan struct{}),
RateLimitingTicker: time.NewTicker(MinRateLimitingIntervalInMs * time.Millisecond),
}
}

type ServerData struct {
// Aikido config that contains info about endpoint, log_level, token, ...
AikidoConfig AikidoConfigData

// Cloud config that is obtain as a result from sending events to cloud or pulling the config when it changes
CloudConfig CloudConfigData

// Config mutex used to sync access to configuration data across the multiple go routines that we run in parallel
CloudConfigMutex sync.Mutex

// Polling data for the server, including mutex used to sync access to polling data across the go routines
PollingData *ServerDataPolling

// List of outgoing hostnames, their ports and number of hits, collected from the requests
Hostnames map[string]map[uint32]uint64
HostnamesQueue Queue[string]

// Hostnames mutex used to sync access to hostnames data across the go routines
HostnamesMutex sync.Mutex

// List of routes and their methods and count of calls collect from the requests
// [method][route] = hits
Routes map[string]map[string]*Route
RoutesQueue Queue[string]

// Routes mutex used to sync access to routes data across the go routines
RoutesMutex sync.Mutex

// Global stats data, including mutex used to sync access to stats data across the go routines
StatsData StatsDataType

// Rate limiting map, which holds the current rate limiting state for each configured route
// map[(method, route)] -> RateLimitingValue
// method can also be '*'
RateLimitingMap map[RateLimitingKey]*RateLimitingValue

// Rate limiting wildcard map, which holds the current rate limiting state for each configured wildcard route
// map[method] -> (RouteRegex, RateLimitingValue)
// method can also be '*'
RateLimitingWildcardMap map[RateLimitingKey]*RateLimitingWildcardValue

// Rate limiting mutex used to sync access across the go routines
RateLimitingMutex sync.RWMutex

// Users map, which holds the current users and their data
Users map[string]User
UsersQueue Queue[string]

// Users mutex used to sync access across the go routines
UsersMutex sync.Mutex

// List of identified packages and their versions
Packages map[string]Package

// Packages mutex used to sync access to packages data across the go routines
PackagesMutex sync.Mutex

// MiddlewareInstalled boolean value to be reported on heartbeat events
MiddlewareInstalled uint32

// Got some request info passed via gRPC to the Agent
GotTraffic uint32

// Last time this server established a gRPC connection
LastConnectionTime int64

// Did we log a token error?
LoggedTokenError uint32

// Attacks detected events timestamps vector, used to limit the number of attacks reported to cloud
AttackDetectedEventsSentAt []int64

// Attack detected events timestamps vector mutex used to sync access across the go routines
AttackDetectedEventsSentAtMutex sync.Mutex
}

const MaxNumberOfStoredHostnames = 2000
const MaxNumberOfStoredUsers = 2000
const MaxNumberOfStoredRoutes = 5000

func NewServerData() *ServerData {
return &ServerData{
Hostnames: make(map[string]map[uint32]uint64),
HostnamesQueue: NewQueue[string](MaxNumberOfStoredHostnames),
Routes: make(map[string]map[string]*Route),
RoutesQueue: NewQueue[string](MaxNumberOfStoredRoutes),
RateLimitingMap: make(map[RateLimitingKey]*RateLimitingValue),
RateLimitingWildcardMap: make(map[RateLimitingKey]*RateLimitingWildcardValue),
Users: make(map[string]User),
UsersQueue: NewQueue[string](MaxNumberOfStoredUsers),
Packages: make(map[string]Package),
PollingData: NewServerDataPolling(),
}
}
1 change: 1 addition & 0 deletions lib/agent/aikido_types/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aikido_types

import (
"testing"

"github.com/stretchr/testify/assert"
)

Expand Down
27 changes: 9 additions & 18 deletions lib/agent/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@ package cloud

import (
. "main/aikido_types"
"main/globals"
"main/utils"
"time"
)

var (
HeartbeatRoutineChannel = make(chan struct{})
HeartBeatTicker = time.NewTicker(10 * time.Minute)
ConfigPollingRoutineChannel = make(chan struct{})
ConfigPollingTicker = time.NewTicker(1 * time.Minute)
)

func Init() {
SendStartEvent()
utils.StartPollingRoutine(HeartbeatRoutineChannel, HeartBeatTicker, SendHeartbeatEvent)
utils.StartPollingRoutine(ConfigPollingRoutineChannel, ConfigPollingTicker, CheckConfigUpdatedAt)
func Init(server *ServerData) {
server.StatsData.StartedAt = utils.GetTime()
server.StatsData.MonitoredSinkTimings = make(map[string]MonitoredSinkTimings)
SendStartEvent(server)

globals.StatsData.StartedAt = utils.GetTime()
globals.StatsData.MonitoredSinkTimings = make(map[string]MonitoredSinkTimings)
utils.StartPollingRoutine(server.PollingData.HeartbeatRoutineChannel, server.PollingData.HeartbeatTicker, SendHeartbeatEvent, server)
utils.StartPollingRoutine(server.PollingData.ConfigPollingRoutineChannel, server.PollingData.ConfigPollingTicker, CheckConfigUpdatedAt, server)
}

func Uninit() {
utils.StopPollingRoutine(HeartbeatRoutineChannel)
utils.StopPollingRoutine(ConfigPollingRoutineChannel)
func Uninit(server *ServerData) {
utils.StopPollingRoutine(server.PollingData.HeartbeatRoutineChannel)
utils.StopPollingRoutine(server.PollingData.ConfigPollingRoutineChannel)
}
Loading
Loading