Skip to content

Commit ef6f30f

Browse files
committed
ML-powered behavioral anomaly detector that learns normal log patterns and flags deviations using Isolation Forest
1 parent 086643d commit ef6f30f

20 files changed

Lines changed: 419 additions & 38 deletions

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DATABASE_URL=stackdog.db
77
RUST_BACKTRACE=full
88

99
# Log Sniff Configuration
10-
#STACKDOG_LOG_SOURCES=/var/log/syslog,/var/log/auth.log
10+
#STACKDOG_LOG_SOURCES=/var/log/syslog,/var/log/auth.log,/var/log/nginx/access.log
1111
#STACKDOG_SNIFF_INTERVAL=30
1212
#STACKDOG_SNIFF_OUTPUT_DIR=./stackdog-logs/
1313
#STACKDOG_SERVE_SNIFF_ENABLED=true

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ docker volume create stackdog-data
8383

8484
docker run --rm -it \
8585
--name stackdog \
86-
-p 5000:5000 \
86+
--network host \
87+
--cap-add=NET_ADMIN \
8788
-e APP_HOST=0.0.0.0 \
8889
-e APP_PORT=5000 \
8990
-e DATABASE_URL=/data/stackdog.db \
@@ -92,6 +93,8 @@ docker run --rm -it \
9293
trydirect/stackdog:latest
9394
```
9495

96+
> **Note:** `--network host` and `--cap-add=NET_ADMIN` are required for IP banning (iptables/nftables) to work. Without them, firewall rules from inside the container cannot affect host traffic.
97+
9598
Then open another shell and hit the API:
9699

97100
```bash
@@ -127,7 +130,8 @@ docker build -f docker/backend/Dockerfile -t stackdog-local .
127130

128131
docker run --rm -it \
129132
--name stackdog-local \
130-
-p 5000:5000 \
133+
--network host \
134+
--cap-add=NET_ADMIN \
131135
-e APP_HOST=0.0.0.0 \
132136
-e APP_PORT=5000 \
133137
-e DATABASE_URL=/data/stackdog.db \
@@ -151,10 +155,12 @@ This starts:
151155

152156
The compose stack uses:
153157

154-
- `stackdog` service — builds `docker/backend/Dockerfile`, runs `stackdog serve`, and mounts `/var/run/docker.sock`
158+
- `stackdog` service — builds `docker/backend/Dockerfile`, runs `stackdog serve`, mounts `/var/run/docker.sock`, uses `network_mode: host`, and adds `NET_ADMIN` capability for IP banning
155159
- `stackdog-ui` service — builds the React app and serves it with Nginx
156160
- `stackdog-data` volume — persists the SQLite database between restarts
157161

162+
> **Prerequisite for IP banning:** The `network_mode: host` and `cap_add: NET_ADMIN` settings are required so that `iptables`/`nftables` rules applied inside the container affect the host's network stack. Without them, IP ban firewall rules cannot reach host traffic.
163+
158164
To stop it:
159165

160166
```bash

docker-compose.app.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ services:
55
dockerfile: docker/backend/Dockerfile
66
command: ["serve"]
77
container_name: stackdog
8+
network_mode: host
9+
cap_add:
10+
- NET_ADMIN
811
environment:
912
APP_HOST: 0.0.0.0
1013
APP_PORT: 5000
1114
DATABASE_URL: /data/stackdog.db
12-
ports:
13-
- "5000:5000"
15+
STACKDOG_SNIFF_INTERVAL: 30
1416
volumes:
1517
- stackdog-data:/data
1618
- /var/run/docker.sock:/var/run/docker.sock

docker-compose.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
services:
22
stackdog:
33
image: trydirect/stackdog:latest
4-
ports:
5-
- target: 5000
6-
published: 5000
4+
network_mode: host
5+
cap_add:
6+
- NET_ADMIN
77
environment:
88
APP_HOST: 0.0.0.0
99
APP_PORT: 5000
1010
DATABASE_URL: /data/stackdog.db
11-
STACKDOG_SNIFF_INTERVAL: 600
11+
STACKDOG_SNIFF_INTERVAL: 30
1212
STACKDOG_AI_PROVIDER: openai
1313
STACKDOG_AI_API_URL: https://api.openai.com/v1
1414
STACKDOG_AI_MODEL: gpt-4o-mini
1515
STACKDOG_AI_API_KEY: <yourkeyhere>
1616
STACKDOG_SLACK_WEBHOOK_URL: <yourslackchannelwebhook?
17-
STACKDOG_LOG_SOURCES: /var/log/syslog,/var/log/auth.log
17+
STACKDOG_LOG_SOURCES: /var/log/syslog,/var/log/auth.log,/var/log/nginx/access.log
1818
restart: unless-stopped
1919
volumes:
2020
- source: stackdog-data
@@ -23,13 +23,7 @@ services:
2323
- source: /var/run/docker.sock
2424
target: /var/run/docker.sock
2525
type: bind
26-
networks:
27-
- default_network
2826
command: serve
2927
volumes:
3028
stackdog-data:
3129
name: stackdog-data
32-
networks:
33-
default_network:
34-
external: true
35-
name: default_network

install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ main() {
155155
echo ""
156156
echo " Run: stackdog --help"
157157
echo ""
158+
echo " Prerequisites for IP banning (optional):"
159+
echo " - nftables or iptables must be installed"
160+
echo " - The binary requires root or CAP_NET_ADMIN to manage firewall rules"
161+
echo " - See https://stackdog.stacker.my/docs for full setup guide"
162+
echo ""
158163
}
159164

160165
main "$@"

0 commit comments

Comments
 (0)