Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
507 lines (491 loc) · 18 KB
/
Copy pathdocker-compose.yml
File metadata and controls
507 lines (491 loc) · 18 KB
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
services:
# ── Certificate permission fixer ────────────────────────────────────
# Certbot writes certs as root; the proxy runs as UID 1000 and needs
# read access. This runs once before the proxy starts.
cert-init:
image: alpine:latest
container_name: infraguard-cert-init
volumes:
- certs:/etc/letsencrypt
entrypoint: /bin/sh
command: ["-c", "chmod -R a+rX /etc/letsencrypt 2>/dev/null; true"]
restart: "no"
# ── Data directory permission fixer ──────────────────────────────────
# The bind-mounted ./data directory may be created by Docker as root.
# This runs once to ensure UID 1000 (infraguard) can read/write it.
data-init:
image: alpine:latest
container_name: infraguard-data-init
volumes:
- ./data:/app/data
entrypoint: /bin/sh
command: ["-c", "mkdir -p /app/data/profiles && chown -R 1000:1000 /app/data"]
restart: "no"
# ── Reverse proxy (core redirector) ─────────────────────────────────
proxy:
build: .
container_name: infraguard-proxy
restart: unless-stopped
env_file: .env
environment:
# Bind embedded API to all interfaces so the dashboard container
# can reach it over the Docker network for forwarding mutations.
# Port 8080 is NOT exposed to the host - only reachable within
# the infraguard bridge network.
- INFRAGUARD_API_BIND=0.0.0.0
# Self-signed cert dir; the tmpfs at /app/.infraguard would work
# too but the explicit override survives future rootfs tweaks.
- INFRAGUARD_SELF_SIGNED_DIR=/app/.infraguard/tls
# Config-history git repo. Home is read-only in this container,
# so land the audit repo on the writable data volume.
- INFRAGUARD_CONFIG_HISTORY=/app/data/config-history.git
depends_on:
cert-init:
condition: service_completed_successfully
data-init:
condition: service_completed_successfully
ports:
- "443:443"
- "443:443/udp" # HTTP/3 QUIC when enabled via listeners: [{protocol: h3}]
- "80:80"
volumes:
# rw so dashboard-driven mutations (drop-action, plugin toggle,
# profile swap) can persist back to config.yaml. Set :ro to lock
# the config against runtime writes.
- ./config:/app/config
- ./examples:/app/examples:ro
- ./rules:/app/rules:ro
- ./pages:/app/pages:ro
- ./data:/app/data:rw
- certs:/app/certs:ro
- geoip:/app/geoip:ro
# ── Security hardening ────────────────────────────────────────────
read_only: true
tmpfs:
# Writable tmpfs for temp files (age-identity, pip cache, etc.)
- /tmp:noexec,nosuid,nodev,size=64m,uid=1000,gid=1000
# Writable tmpfs for self-signed cert generation
- /app/.infraguard:noexec,nosuid,nodev,size=10m,uid=1000,gid=1000
security_opt:
- no-new-privileges:true
# Use the default seccomp profile (blocks ~44 dangerous syscalls)
# A custom profile can be layered on top via:
# - seccomp=/path/to/infraguard-seccomp.json
cap_drop:
- ALL
cap_add:
# Required to bind to privileged ports 443/80
- NET_BIND_SERVICE
# ── Resource limits ────────────────────────────────────────────────
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
reservations:
cpus: "0.25"
memory: 128M
# ── Health check ───────────────────────────────────────────────────
healthcheck:
test:
- "CMD"
- "python3"
- "-c"
- |
import urllib.request, ssl, os
p = os.environ.get('INFRAGUARD_HEALTH_PATH', 'health').strip('/')
# Health check runs against localhost with self-signed cert; unverified context is intentional
urllib.request.urlopen(
f'https://127.0.0.1:443/{p}',
context=ssl._create_unverified_context()
)
interval: 30s
timeout: 10s
retries: 5
start_period: 15s
command: ["run", "-c", "/app/config/config.yaml", "--port", "443"]
networks:
- infraguard
# ── Web dashboard ───────────────────────────────────────────────────
dashboard:
build: .
container_name: infraguard-dashboard
restart: unless-stopped
env_file: .env
environment:
- INFRAGUARD_PROXY_API=http://infraguard-proxy:8080
- INFRAGUARD_OLLAMA_URL=http://infraguard-ollama:11434
# Land any writes that might land here (drop-action fallback, cert
# regen) on the writable tmpfs instead of the read-only /home.
- INFRAGUARD_SELF_SIGNED_DIR=/app/.infraguard/tls
- INFRAGUARD_CONFIG_HISTORY=/app/data/config-history.git
ports:
- "8080:8080"
volumes:
- ./config:/app/config:ro
- ./examples:/app/examples:ro
- ./rules:/app/rules:ro
- ./data:/app/data
- certs:/app/certs:ro
- geoip:/app/geoip:ro
# ── Security hardening ────────────────────────────────────────────
read_only: true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=64m,uid=1000,gid=1000
- /app/.infraguard:noexec,nosuid,nodev,size=10m,uid=1000,gid=1000
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
# No cap_add needed: dashboard binds to 8080 (unprivileged)
# ── Resource limits ────────────────────────────────────────────────
deploy:
resources:
limits:
cpus: "0.5"
memory: 256M
reservations:
cpus: "0.1"
memory: 64M
# ── Health check ───────────────────────────────────────────────────
healthcheck:
test:
- "CMD"
- "python3"
- "-c"
- |
import urllib.request, ssl
# Dashboard runs on 8080 with TLS; unverified context is intentional for localhost
urllib.request.urlopen(
'https://127.0.0.1:8080/',
context=ssl._create_unverified_context()
)
interval: 30s
timeout: 10s
retries: 5
start_period: 20s
command: ["dashboard", "-c", "/app/config/config.yaml", "--tls"]
depends_on:
data-init:
condition: service_completed_successfully
proxy:
condition: service_healthy
networks:
- infraguard
# ── Let's Encrypt (optional) ────────────────────────────────────────
# Automatically obtains and renews TLS certificates via certbot.
# Enable by setting INFRAGUARD_LETSENCRYPT=true in .env.
#
# Requirements:
# - Port 80 must be reachable from the internet
# - INFRAGUARD_DOMAIN must resolve to this host
# - INFRAGUARD_DOMAIN_EMAIL must be a valid email
#
# Certs are written to the shared "certs" volume at:
# /etc/letsencrypt/live/${INFRAGUARD_DOMAIN}/fullchain.pem
# /etc/letsencrypt/live/${INFRAGUARD_DOMAIN}/privkey.pem
#
# After first run, restart the proxy to pick up the new certs.
# docker compose --profile letsencrypt up certbot
certbot:
image: certbot/certbot:latest
container_name: infraguard-certbot
profiles: ["letsencrypt"]
env_file: .env
volumes:
- certs:/etc/letsencrypt
- certbot-www:/var/www/certbot
entrypoint: /bin/sh
command:
- -c
- |
if [ "$${INFRAGUARD_LETSENCRYPT}" = "true" ]; then
certbot certonly --standalone \
--non-interactive --agree-tos \
--email $${INFRAGUARD_DOMAIN_EMAIL} \
-d $${INFRAGUARD_DOMAIN} \
--preferred-challenges http \
&& chmod -R a+rX /etc/letsencrypt/live /etc/letsencrypt/archive \
&& echo "Certificate obtained for $${INFRAGUARD_DOMAIN}"
else
echo "Let's Encrypt disabled (INFRAGUARD_LETSENCRYPT != true)"
fi
ports:
- "80:80"
networks:
- infraguard
# Renewal runs on a schedule (every 12 hours)
certbot-renew:
image: certbot/certbot:latest
container_name: infraguard-certbot-renew
profiles: ["letsencrypt"]
env_file: .env
volumes:
- certs:/etc/letsencrypt
- certbot-www:/var/www/certbot
entrypoint: /bin/sh
command: -c 'trap exit TERM; while :; do certbot renew --quiet --deploy-hook "chmod -R a+rX /etc/letsencrypt/live /etc/letsencrypt/archive"; sleep 43200; done'
depends_on:
certbot:
condition: service_completed_successfully
networks:
- infraguard
# ── GeoIP database downloader ────────────────────────────────────────
# Downloads GeoLite2 databases from GitHub on first run.
# Run with: docker compose up geoip-update
# Databases are stored in the "geoip" volume at /geoip/*.mmdb
geoip-update:
image: alpine/curl:latest
container_name: infraguard-geoip-update
profiles: ["geoip"]
volumes:
- geoip:/geoip
entrypoint: /bin/sh
command:
- -c
- |
echo "Downloading GeoLite2 databases..."
curl -sSL -o /geoip/GeoLite2-City.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb && echo " City DB downloaded"
curl -sSL -o /geoip/GeoLite2-ASN.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-ASN.mmdb && echo " ASN DB downloaded"
curl -sSL -o /geoip/GeoLite2-Country.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-Country.mmdb && echo " Country DB downloaded"
ls -lh /geoip/*.mmdb
echo "Done."
# ── Redis (shared state for horizontally-scaled deploys) ─────────────
# Enables replay-cache, circuit-breaker, session, and rate-limit state
# to be shared across multiple proxy replicas.
#
# Enable with: docker compose --profile scale up -d
# Then set state.backend: redis in config.yaml (defaults to redis://redis:6379/0).
redis:
image: redis:7-alpine
container_name: infraguard-redis
profiles: ["scale"]
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes", "--maxmemory", "256mb", "--maxmemory-policy", "allkeys-lru"]
user: redis
volumes:
- redis-data:/data
read_only: false
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
networks:
- infraguard
# ── Additional redirector node (scale with --scale proxy-node=N) ────
# Requires the `scale` profile so Redis is up. Without a shared state
# backend this is broken - see comments on the redis service above.
#
# Enable with:
# docker compose --profile scale up -d --scale proxy-node=3
proxy-node:
build: .
profiles: ["scale"]
restart: unless-stopped
env_file: .env
depends_on:
redis:
condition: service_healthy
ports:
- "443"
volumes:
- ./config:/app/config:ro
- ./examples:/app/examples:ro
- ./data:/app/data
- certs:/app/certs:ro
read_only: true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=64m,uid=1000,gid=1000
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
command: ["run", "-c", "/app/config/config.yaml"]
networks:
- infraguard
# ── Command Post (multi-instance aggregator) ─────────────────────────
# Aggregates stats, requests, and live events from multiple InfraGuard
# instances into a single dashboard.
# Enable with: docker compose --profile command-post up -d command-post
# Access at: http://localhost:9090
command-post:
build: .
container_name: infraguard-command-post
profiles: ["command-post"]
restart: unless-stopped
env_file: .env
environment:
INFRAGUARD_SELF_SIGNED_DIR: /tmp/tls
ports:
- "9090:9090"
volumes:
- ./config:/app/config:ro
- certs:/app/certs:ro
# ── Security hardening ────────────────────────────────────────────
read_only: true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=32m,uid=1000,gid=1000
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
# No cap_add needed: command-post binds to 9090 (unprivileged)
# ── Resource limits ────────────────────────────────────────────────
deploy:
resources:
limits:
cpus: "0.5"
memory: 256M
reservations:
cpus: "0.1"
memory: 64M
# ── Health check ───────────────────────────────────────────────────
healthcheck:
test:
- "CMD"
- "python3"
- "-c"
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:9090/health')"
interval: 30s
timeout: 10s
retries: 5
start_period: 15s
command: ["command-post", "-c", "/app/config/command-post.yaml", "--port", "9090"]
networks:
- infraguard
# ── PwnDrop payload delivery (optional) ──────────────────────────────
# Self-hosted file hosting for serving payloads via content routes.
# Enable with: docker compose --profile pwndrop up -d pwndrop
# Access PwnDrop UI at https://localhost:8443
# InfraGuard reaches it internally at http://pwndrop:80
pwndrop:
build:
context: ./vendor/pwndrop
dockerfile: Dockerfile
container_name: infraguard-pwndrop
profiles: ["pwndrop"]
restart: unless-stopped
env_file: .env
ports:
- "8443:443"
volumes:
- pwndrop-data:/pwndrop/data
- certs:/pwndrop/certs:ro
- ./config/pwndrop.ini:/pwndrop/pwndrop.ini
# ── Security hardening ────────────────────────────────────────────
read_only: true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=32m
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE # pwndrop binds to 443 internally
# ── Resource limits ────────────────────────────────────────────────
deploy:
resources:
limits:
cpus: "0.5"
memory: 256M
reservations:
cpus: "0.1"
memory: 64M
networks:
- infraguard
# ── Ollama AI assistant (optional) ────────────────────────────────────
# Provides AI-assisted C2 profile generation and troubleshooting via
# the dashboard's chat panel.
# Enable with: docker compose --profile ollama up -d ollama
# First run will pull the model (~5 GB): docker compose --profile ollama exec ollama ollama pull qwen3:8b
ollama:
image: ollama/ollama:latest
container_name: infraguard-ollama
profiles: ["ollama"]
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama-data:/root/.ollama
deploy:
resources:
limits:
cpus: "4.0"
memory: 8G
reservations:
cpus: "0.5"
memory: 1G
networks:
- infraguard
# ── Observability stack (opt-in, v0.5) ───────────────────────────────
# OpenTelemetry collector + Prometheus + Grafana. Enable with:
# docker compose --profile observability up -d
# Then set observability.otel.enabled=true and endpoint=http://otel:4318
# in config.yaml. Grafana dashboard is auto-provisioned from
# deploy/grafana/infraguard.json.
otel:
image: otel/opentelemetry-collector-contrib:latest
container_name: infraguard-otel
profiles: ["observability"]
restart: unless-stopped
command: ["--config=/etc/otel/config.yaml"]
volumes:
- ./deploy/otel/config.yaml:/etc/otel/config.yaml:ro
ports:
- "4318:4318" # OTLP HTTP
- "4317:4317" # OTLP gRPC
networks:
- infraguard
prometheus:
image: prom/prometheus:latest
container_name: infraguard-prometheus
profiles: ["observability"]
restart: unless-stopped
volumes:
- ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus-data:/prometheus
ports:
- "9091:9090"
networks:
- infraguard
grafana:
image: grafana/grafana:latest
container_name: infraguard-grafana
profiles: ["observability"]
restart: unless-stopped
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin}
- GF_AUTH_ANONYMOUS_ENABLED=false
volumes:
- grafana-data:/var/lib/grafana
- ./deploy/grafana:/etc/grafana/provisioning/dashboards:ro
depends_on:
- prometheus
ports:
- "3000:3000"
networks:
- infraguard
volumes:
certs:
certbot-www:
geoip:
pwndrop-data:
ollama-data:
redis-data:
prometheus-data:
grafana-data:
networks:
infraguard:
driver: bridge