Troubleshooting Runbook¶
LeWAF Production Troubleshooting Guide
This runbook provides step-by-step troubleshooting procedures for common issues, performance problems, and emergency situations.
Table of Contents¶
- Quick Reference
- Common Issues
- Performance Issues
- Configuration Issues
- Storage Issues
- Rule Issues
- Body Processing Issues
- Integration Issues
- Emergency Procedures
- Log Analysis
- Diagnostic Commands
Quick Reference¶
Severity Levels¶
| Level | Response Time | Description |
|---|---|---|
| P0 - Critical | Immediate | Service down, data loss |
| P1 - High | < 1 hour | Major feature broken |
| P2 - Medium | < 4 hours | Minor feature broken |
| P3 - Low | < 24 hours | Enhancement or minor bug |
Error Code Categories¶
See error-codes.md for complete reference.
| Category | Code Range | Description |
|---|---|---|
| Configuration | WAF-0xxx | Configuration errors |
| Parsing | PARSE-1xxx | Rule parsing errors |
| Rule Evaluation | RULE-2xxx | Rule execution errors |
| Body Processing | BODY-3xxx | Request body errors |
| Operators | OP-4xxx | Operator errors |
| Integration | INT-5xxx | Framework integration errors |
| Storage | STORE-6xxx | Backend storage errors |
| Proxy | PROXY-7xxx | Upstream proxy errors |
Common Issues¶
Issue 1: High Latency (P1)¶
Symptoms: - Requests taking > 500ms - Timeout errors - Increased response times
Diagnosis:
# Check current latency
curl -w "@curl-format.txt" -o /dev/null -s http://localhost:8000/health
# Monitor request times in logs
grep "request_duration" /app/logs/audit.log | tail -50
# Check resource usage
top -p $(pgrep -f lewaf)
Common Causes:
- Too many rules enabled
-
Solution: Reduce paranoia level or disable unused rules
-
Large request bodies
-
Solution: Check body size limits
-
Regex performance
-
Solution: Profile rules to identify slow regexes
-
Storage backend slow
- Solution: Check Redis/database latency
Resolution Steps:
- Identify bottleneck (rules vs. body processing vs. storage)
- Apply appropriate optimization
- Monitor latency improvement
- Document changes
Issue 2: High Memory Usage (P1)¶
Symptoms: - Memory usage > 80% - OOM kills - Swap usage increasing
Diagnosis:
# Check memory usage
ps aux | grep lewaf
free -h
# Python memory profiling
pip install memory_profiler
python -m memory_profiler lewaf_app.py
Common Causes:
- Large collections in memory
- Error Code: STORE-6001
-
Solution: Use Redis for persistent collections
-
Request body buffering
-
Solution: Reduce body limit
-
Memory leak
- Solution: Restart service, collect heap dump
Resolution Steps:
- Check if memory leak or legitimate growth
- If leak: restart service, schedule investigation
- If growth: tune body limits and collection size
- Monitor memory after changes
Issue 3: Service Won't Start (P0)¶
Symptoms: - Service fails to start - Immediate crash - Exit code != 0
Diagnosis:
# Check service status
systemctl status lewaf
# Check logs
journalctl -u lewaf -n 50 --no-pager
# Manual start for debugging
/usr/bin/lewaf --config /etc/lewaf/lewaf.conf --debug
Common Causes:
- Configuration file not found
- Error Code: WAF-0002
-
Solution: Verify file path and permissions
-
Invalid configuration syntax
- Error Code: WAF-0003
-
Solution: Fix syntax error
-
Port already in use
- Error Code: INT-5001
-
Solution: Change port or kill existing process
-
Missing dependencies
- Solution: Install dependencies
Resolution Steps:
- Check error message for error code
- Refer to error code documentation
- Fix underlying issue
- Verify service starts successfully
- Check logs for warnings
Issue 4: Requests Being Blocked Incorrectly (P2)¶
Symptoms: - Legitimate requests blocked - False positives - Error Code: RULE-2xxx
Diagnosis:
# Check audit logs for blocked requests
grep '"action":"block"' /app/logs/audit.log | tail -20
# Find which rule triggered
grep 'rule_id' /app/logs/audit.log | grep <transaction_id>
# Check anomaly score
grep 'anomaly_score' /app/logs/audit.log | grep <transaction_id>
Common Causes:
- Paranoia level too high
-
Solution: Reduce paranoia level
-
Specific rule too strict
-
Solution: Disable or tune rule
-
Anomaly threshold too low
- Solution: Increase threshold
Resolution Steps:
- Identify transaction ID from application logs
- Search audit logs for transaction details
- Identify triggering rule(s)
- Evaluate if true or false positive
- If false positive: create rule exception
- Test with original request
- Document exception in runbook
Issue 5: Request Bodies Not Being Inspected (P2)¶
Symptoms: - POST requests not checked - File uploads not scanned - ARGS_POST variables empty
Diagnosis:
# Check if body inspection is enabled
grep "SecRequestBodyAccess" /etc/lewaf/lewaf.conf
# Check body processor logs
grep "BODY-" /app/logs/audit.log | tail -20
# Test body inspection
curl -X POST -d "test=value" http://localhost:8000/test -v
Common Causes:
- Body access disabled
-
Solution: Enable in configuration
-
Body size exceeds limit
- Error Code: BODY-3003
-
Solution: Increase limit or reject large bodies
-
Content-Type not recognized
- Error Code: BODY-3001 (JSON), BODY-3002 (XML)
-
Solution: Add content type to allowed list
-
Body processor failed
- Error Code: BODY-3001, BODY-3002, BODY-3004
- Solution: Check REQBODY_ERROR variable
Resolution Steps:
- Verify SecRequestBodyAccess On
- Check body size limits
- Verify Content-Type header
- Check for body processor errors
- Test with sample request
Issue 6: Storage Backend Connection Failed (P1)¶
Symptoms: - Collections not persisting - Connection errors in logs - Error Code: STORE-6001
Diagnosis:
# Test Redis connection
redis-cli -h <redis-host> -p 6379 ping
# Check connection in logs
grep "STORE-6001" /app/logs/audit.log
# Verify environment variable
echo $LEWAF_REDIS_URL
Common Causes:
-
Redis not running
-
Wrong connection URL
-
Solution: Fix environment variable
-
Network connectivity
-
Authentication required
Resolution Steps:
- Verify Redis is running
- Test network connectivity
- Verify connection string
- Check authentication
- Restart LeWAF service
Performance Issues¶
High CPU Usage¶
Diagnosis:
# Check CPU usage
top -p $(pgrep -f lewaf)
# Python profiling
python -m cProfile -o profile.stats lewaf_app.py
python -m pstats profile.stats
Common Causes:
- Too many regex evaluations
-
Solution: Optimize rules, reduce paranoia level
-
Transformation overhead
-
Solution: Minimize transformations
-
Large request rate
- Solution: Scale horizontally, add instances
Slow Rule Evaluation¶
Diagnosis:
# Enable rule performance logging
SecDebugLogLevel 9
# Find slow rules
grep "Rule.*took" /app/logs/debug.log | sort -k6 -n | tail -20
Solutions:
- Optimize regex patterns
- Use anchors (^, $)
- Avoid greedy quantifiers (.*)
-
Use possessive quantifiers where possible
-
Disable unused rules
-
Use rule caching
Configuration Issues¶
Include File Not Found¶
Error Code: PARSE-1002
Solutions:
-
Check file path
-
Use absolute paths
-
Check permissions
Unknown Operator¶
Error Code: PARSE-1003
Solutions:
-
Fix typo
-
Check operator is registered
Storage Issues¶
Collection Data Lost¶
Error Code: STORE-6002
Diagnosis:
# Check if using memory storage (non-persistent)
grep "storage_backend" /etc/lewaf/lewaf.conf
# Check Redis data
redis-cli
> KEYS lewaf:*
Solutions:
-
Use persistent backend
-
Enable Redis persistence
Rule Issues¶
Rule Parsing Failed¶
Error Code: PARSE-1001
Diagnosis:
# Test rule syntax
lewaf-tool validate-rule "SecRule ARGS \"@rx ^attack$\" \"id:1000,phase:2,deny\""
Common Syntax Errors:
-
Missing quotes
-
Invalid action syntax
Rule Not Triggering¶
Diagnosis:
# Enable debug logging
SecDebugLogLevel 9
# Check rule execution
grep "Rule 1000" /app/logs/debug.log
Common Causes:
-
Wrong phase
-
Variable not populated
-
Transformation changes value
Body Processing Issues¶
JSON Parsing Failed¶
Error Code: BODY-3001
Diagnosis:
# Check request body
grep "BODY-3001" /app/logs/audit.log
# Get body snippet from error
grep "body_snippet" /app/logs/audit.log | grep <transaction_id>
Solutions:
-
Validate JSON before sending
-
Set error variables for inspection
XML Parsing Failed¶
Error Code: BODY-3002
Solutions:
-
Validate XML
-
Check encoding
Multipart Parsing Failed¶
Error Code: BODY-3004
Solutions:
-
Verify Content-Type header
-
Check boundary in body
Integration Issues¶
ASGI Middleware Error¶
Error Code: INT-5001
Diagnosis:
# Check middleware initialization
grep "INT-5001" /app/logs/audit.log
# Verify middleware is registered
# In FastAPI
app.add_middleware(LeWAFMiddleware)
Solutions:
-
Check middleware order
-
Verify WAF instance is passed
Emergency Procedures¶
Procedure 1: Immediate Service Disable¶
When: Service causing widespread issues (P0)
Steps:
# 1. Disable WAF (bypass mode)
echo "SecRuleEngine DetectionOnly" > /etc/lewaf/bypass.conf
systemctl restart lewaf
# 2. Or remove from request path
# In nginx:
proxy_pass http://backend; # Skip WAF
# 3. Monitor for issue resolution
tail -f /var/log/nginx/access.log
Procedure 2: Emergency Restart¶
When: Service unresponsive, high resource usage
Steps:
# 1. Graceful restart
systemctl restart lewaf
# 2. If hung, force kill
pkill -9 -f lewaf
systemctl start lewaf
# 3. Verify service is running
systemctl status lewaf
curl http://localhost:8000/health
Procedure 3: Rollback Configuration¶
When: Recent config change caused issues
Steps:
# 1. Restore previous config
cp /etc/lewaf/lewaf.conf.backup /etc/lewaf/lewaf.conf
# 2. Validate config
lewaf --config /etc/lewaf/lewaf.conf --test
# 3. Restart service
systemctl restart lewaf
# 4. Verify
curl http://localhost:8000/health
Procedure 4: Enable Debug Logging¶
When: Need detailed diagnostics
Steps:
# 1. Edit config
SecDebugLogLevel 9
SecDebugLog /app/logs/debug.log
# 2. Restart service
systemctl restart lewaf
# 3. Monitor debug log
tail -f /app/logs/debug.log
# 4. Disable after debugging (performance impact)
SecDebugLogLevel 0
systemctl restart lewaf
Log Analysis¶
Structured Log Format¶
All errors follow this format:
{
"timestamp": "2025-11-13T10:30:45.123Z",
"error_code": "BODY-3001",
"error_category": "body_processing",
"message": "Invalid JSON syntax",
"context": {
"transaction_id": "tx-123",
"rule_id": 1000,
"phase": 2,
"variable": "ARGS:id"
}
}
Common Log Patterns¶
1. Find all errors for a transaction:
2. Count errors by type:
3. Find slow requests:
grep "request_duration" /app/logs/audit.log | \
jq 'select(.request_duration > 1.0)' | \
jq -r '[.timestamp, .request_duration, .transaction_id] | @tsv'
4. Analyze blocked requests:
grep '"action":"block"' /app/logs/audit.log | \
jq -r '[.timestamp, .transaction_id, .rule_id, .message] | @tsv'
Diagnostic Commands¶
System Health¶
# Service status
systemctl status lewaf
# Resource usage
top -p $(pgrep -f lewaf)
ps aux | grep lewaf
# Network connections
netstat -tulpn | grep 8000
ss -tulpn | grep 8000
Log Analysis¶
# Recent errors
tail -100 /app/logs/audit.log | grep "error_code"
# Error counts
grep "error_code" /app/logs/audit.log | \
jq -r .error_code | sort | uniq -c
# Transaction search
grep "tx-123" /app/logs/audit.log | jq .
Configuration Validation¶
# Test configuration
lewaf --config /etc/lewaf/lewaf.conf --test
# Validate rules
lewaf-tool validate-rules /app/rules/*.conf
# Check syntax
grep -n "SecRule" /etc/lewaf/lewaf.conf | head -20
Performance Analysis¶
# Request latency
curl -w "@curl-format.txt" -o /dev/null -s http://localhost:8000/test
# Where curl-format.txt contains:
# time_total: %{time_total}\n
# Rule performance
grep "Rule.*took" /app/logs/debug.log | sort -k6 -n | tail -20
Next Steps¶
- Error Codes Reference: See error-codes.md
- Performance Tuning: See ../performance/tuning.md
- Security Hardening: See ../security/hardening.md
- Monitoring: See ../monitoring/prometheus.md
Questions or Issues? - GitHub Issues: https://github.com/abilian/lewaf/issues - Documentation: https://lewaf.readthedocs.io