Alpha Release: This project is in early development. APIs and configuration may change. Not recommended for production use.
A high-performance, security-focused MQTT proxy gateway built in Rust
AegisGate sits between MQTT clients and brokers, providing multi-layered security inspection, rate limiting, and protocol validation. Built with async Rust (Tokio), it delivers low-latency proxying while defending against common attack vectors.
- Per-IP Rate Limiting: Token bucket algorithm with configurable burst capacity and refill rates
- Slowloris Attack Detection: Multi-layer timeout enforcement to prevent slow-data attacks
- HTTP Protocol Rejection: Detects and blocks HTTP traffic targeting MQTT ports
- MQTT Protocol Validation: Deep packet inspection of MQTT CONNECT packets
- Connection Resource Management: Automatic cleanup of idle connections and expired rate limit state
- MQTT 3.1/3.1.1: Full CONNECT packet validation
- Protocol Detection: Distinguishes between MQTT, HTTP, and malformed traffic
- Bidirectional Proxying: Zero-copy streaming between clients and upstream brokers
- Prometheus Metrics: Real-time connection statistics, rejection counters, and performance metrics
- Structured Logging: JSON-formatted logs with configurable verbosity
- Health Monitoring: Container health checks and readiness probes
AegisGate implements a multi-stage validation pipeline:
- Rate Limiting Layer: Per-IP token bucket filtering using concurrent hashmap
- Slowloris Protection: Protocol-agnostic timeout enforcement on initial connection
- HTTP Detection: Quick byte pattern matching followed by full HTTP parsing with size limits
- MQTT Validation: Fixed header inspection and CONNECT packet verification
- Proxy Layer: Bidirectional TCP stream forwarding to upstream broker
# Start AegisGate and EMQX broker
docker-compose up -d
# View logs
docker-compose logs -f aegis-proxy
# Access metrics
curl http://localhost:9090/metrics# Build release binary
cargo build --release --manifest-path crates/aegis-proxy/Cargo.toml
# Run with default config
./target/release/aegis-proxyConfiguration is managed via config/aegis_config.yaml.
proxy:
listen_address: "0.0.0.0:8080" # Proxy listening address
target_address: "127.0.0.1:1883" # Upstream MQTT broker
max_connect_remaining: 65536 # Max MQTT CONNECT packet size (bytes)limit:
max_tokens: 5.0 # Maximum burst capacity per IP
refill_rate: 1.0 # Tokens per second refill rate
cleanup_interval_secs: 60 # State cleanup interval
ip_idle_timeout_secs: 60 # Remove IPs idle longer than thisslowloris_protection:
first_packet_timeout_ms: 30000 # Time to receive first packet
packet_idle_timeout_ms: 10000 # Max idle time between bytes
connection_timeout_ms: 60000 # Total connection establishment timeout
mqtt_connect_timeout_ms: 30000 # MQTT CONNECT packet timeout
http_request_timeout_ms: 30000 # HTTP request line + headers timeout
max_http_header_size: 8192 # Max total HTTP header size (bytes)
max_http_header_count: 100 # Max number of HTTP headersfeatures:
enable_mqtt_inspection: true # MQTT protocol validation
enable_mqtt_full_inspection: true # Deep CONNECT packet inspection
enable_http_inspection: true # HTTP detection and rejection
enable_slowloris_protection: true # Timeout-based attack prevention
enable_rate_limiter: true # Per-IP rate limiting
enable_ebpf: false # eBPF fast-path (future)
enable_ml: false # ML anomaly detection (future)metrics:
enabled: true # Enable Prometheus endpoint
port: 9090 # Metrics server portAegisGate exposes Prometheus metrics on the configured metrics port (default: 9090).
aegis_active_connections: Current number of active proxy connectionsaegis_rejected_connections_total: Total connections rejected by rate limitingaegis_http_rejections_total: Total connections rejected due to HTTP protocol detectionaegis_slowloris_rejections_total: Total connections rejected due to Slowloris attacksaegis_protocol_rejections_total: Total connections rejected by MQTT validation
# View all metrics
curl http://localhost:9090/metrics
# Get active connections
curl -s http://localhost:9090/metrics | grep aegis_active_connections
# Get rejection statistics
curl -s http://localhost:9090/metrics | grep rejections_total- Rust 1.75 or later
- Cargo
- Docker and Docker Compose (for containerized testing)
# Development build
cargo build --manifest-path crates/aegis-proxy/Cargo.toml
# Release build
cargo build --release --manifest-path crates/aegis-proxy/Cargo.toml
# Run tests
cargo test --manifest-path crates/aegis-proxy/Cargo.toml# Build release binary
make build
# Run proxy
make run
# Run tests
make test
# Clean build artifacts
make clean# Build image
docker build -t aegisgate:latest .
# Run container
docker run -d \
-p 8080:8080 \
-p 9090:9090 \
-v $(pwd)/config:/app/config \
aegisgate:latest# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down- In-Memory State: Rate limit state is stored in-memory and cleared on restart
- Concurrent Processing: Uses Tokio async runtime with multi-threaded scheduler
- Zero-Copy Proxying: Efficient bidirectional streaming with minimal allocations
- Connection Pooling: Reuses backend connections when possible
- Rate Limits: Adjust
max_tokensandrefill_ratebased on expected client behavior - Timeouts: Configure Slowloris timeouts to balance legitimate slow connections vs attacks
- Network Isolation: Run AegisGate in a DMZ between untrusted clients and MQTT brokers
- Monitoring: Set up alerts on rejection metrics to detect attacks
- Regular Updates: Keep dependencies updated for security patches
- Supported protocols:
- MQTT 3.1 and 3.1.1: CONNECT packet validation and proxying are implemented and validated.
- Not supported (yet):
- MQTT 5.0 protocol semantics (properties, reason codes, AUTH exchanges, subscription identifiers, etc.)
- TLS / mTLS termination inside the proxy (TLS is planned but not available in the alpha)
- Persistent rate-limit storage (current state is in-memory; Redis backend planned)
- eBPF fast-path filtering and ML-based anomaly detection (planned)
- WebSocket transport and IPv6-specific rate-limit enhancements (planned)
- Practical implications:
- If you require TLS or mTLS today, terminate TLS before AegisGate (use nginx, traefik, HAProxy, or a cloud LB) and forward plaintext MQTT on a private network.
- If you rely on MQTT 5 features (properties, response topics, enhanced auth), do not place AegisGate inline until MQTT 5 support is added; alternatively use a TCP pass-through mode (disables packet inspection) if you need transparent forwarding.
- Rate-limiting counters are in-memory and will be lost on restart; for persistent counters wait for the Redis backend feature.
- Where to look:
- See the
CHANGELOG.mdUnreleased / Planned section for roadmap items and planned features.
- See the