Skip to content

Commit

Permalink
chore: simplify example to show logs. (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs authored Oct 23, 2024
1 parent 3ae0aca commit c8eca00
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 38 deletions.
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logs
5 changes: 4 additions & 1 deletion example/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
SecDefaultAction "phase:4,log,auditlog,pass"
SecDefaultAction "phase:5,log,auditlog,pass"
SecRuleEngine On
SecDebugLog /dev/stdout
SecDebugLog /home/coraza/logs/debug.log
SecDebugLogLevel 9
SecRule REQUEST_URI "@streq /admin" "id:101,phase:1,t:lowercase,deny,status:403"
SecRule REQUEST_BODY "@rx maliciouspayload" "id:102,phase:2,t:lowercase,deny,status:403"
SecRule RESPONSE_STATUS "@rx 406" "id:103,phase:3,t:lowercase,deny,status:403"
SecResponseBodyAccess On
SecResponseBodyMimeType application/json
SecRule RESPONSE_BODY "@contains responsebodycode" "id:104,phase:4,t:lowercase,deny,status:403"
SecAuditEngine On
SecAuditLog /home/coraza/logs/audit.log
SecAuditLogFormat json
`
}

Expand Down
37 changes: 1 addition & 36 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,16 @@ services:
ports:
- 8081:8081

chown:
image: alpine:3.20
command:
- /bin/sh
- -c
- chown -R 101:101 /home/caddy/logs
volumes:
- logs:/home/caddy/logs:rw

caddy:
depends_on:
- httpbin
build:
context: ..
dockerfile: ./example/Dockerfile
volumes:
- logs:/home/caddy/logs:rw
- ./logs:/home/coraza/logs:rw
- ./403.html:/etc/caddy/custom-pages/403.html:ro
ports:
- 8080:8080
environment:
- HTTPBIN_HOST=httpbin

caddy-logs:
depends_on:
- caddy
- coraza-logs
image: debian:12-slim
entrypoint: bash
command:
- -c
- tail -c +0 -f /home/caddy/logs/caddy.log
volumes:
- logs:/home/caddy/logs:ro

coraza-logs:
depends_on:
- caddy
image: debian:12-slim
entrypoint: bash
command:
- -c
- tail -c +0 -f /home/caddy/logs/caddy.log | grep --line-buffered "http.handlers.waf"
volumes:
- logs:/home/caddy/logs:ro

volumes:
logs:
2 changes: 1 addition & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func BuildExample() error {

// RunExample spins up the test environment, access at http://localhost:8080. Requires docker.
func RunExample() error {
return sh.RunV("docker", "compose", "--file", "example/docker-compose.yml", "up", "-d", "caddy-logs")
return sh.RunV("docker", "compose", "--file", "example/docker-compose.yml", "up", "-d", "caddy")
}

// TeardownExample tears down the test environment. Requires docker.
Expand Down

0 comments on commit c8eca00

Please sign in to comment.