Advanced Web Application Firewall · Group AA3 · Model Engineering College
This directory contains the full Rust data plane and control plane for NexusWAF. It runs the reverse proxy, executes the layered request pipeline, exposes operator APIs, persists attack/config data, and integrates with the RL policy service from nexus-ml.
Gateway: Axum/Hyper reverse proxy
Pipeline: rate limit · lexical · grammar · rules · anomaly · policy · optional semantic ML
Control Plane: REST + gRPC + metrics endpoints
Runtime Features: GPS rule synthesis · Slack alerting · TLS/Certbot · PostgreSQL-backed logs
nexus-core/
├── config/
│ ├── default.toml # Main runtime config
│ └── rules.toml # Active ruleset loaded by nexus-rules
├── proto/
│ └── policy.proto # Shared gRPC contract with nexus-ml
├── nexus-gateway/
│ ├── src/main.rs # CLI entrypoint
│ ├── src/server.rs # HTTP/HTTPS, REST, gRPC, metrics servers
│ ├── src/proxy.rs # Reverse proxy + verdict handling
│ ├── src/state.rs # Shared app state + reload/runtime wiring
│ ├── src/alerting.rs # Slack alert delivery
│ └── src/tls.rs # Static TLS + Certbot runtime
├── nexus-control/
│ ├── src/http.rs # REST control-plane routes
│ ├── src/server.rs # gRPC control services
│ ├── src/ops.rs # Stats, GPS, policy ops, rules/config actions
│ └── src/stats.rs # API response models
├── nexus-pipeline/
│ └── src/pipeline.rs # Layer execution order and final verdict logic
├── nexus-policy/
│ ├── src/lib.rs # RL policy layer + gRPC client
│ ├── src/proto.rs # Generated tonic bindings
│ └── build.rs # Proto compilation
├── nexus-ml-client/ # Semantic ML client/layer (optional path)
├── nexus-lex/ # Signature / regex scanner
├── nexus-grammar/ # Grammar / parser-based inspection
├── nexus-rules/ # TOML rule engine
├── nexus-anomaly/ # Baseline / anomaly detection
├── nexus-rate/ # Per-IP rate limiting
├── nexus-lb/ # Upstream health checks + balancing
├── nexus-store/ # PostgreSQL / Influx persistence
├── nexus-metrics/ # Prometheus exporter
├── nexus-telemetry/ # Policy telemetry window for adaptive control
├── nexus-config/ # Config schema, loader, env overrides
└── Cargo.toml # Workspace manifest
- Rust stable toolchain
- PostgreSQL running for
attack_logs, ruleset versions, and config events - Optional: InfluxDB for time-series metrics
- Optional: Python
nexus-mlpolicy service on127.0.0.1:50052
cd nexus-core/
cargo buildThe default runtime config is:
config/default.toml
Important defaults:
- Proxy listener:
0.0.0.0:8080 - Control gRPC:
0.0.0.0:9090 - Control REST:
0.0.0.0:9091 - Metrics:
0.0.0.0:9092 - Policy service:
http://127.0.0.1:50052 - Rules file:
config/rules.toml
If you are running RL policy only, keep:
[pipeline]
ml_enabled = falseIf you later enable the separate semantic ML classifier, point [ml].endpoint to that service, not to the RL policy port.
cargo run -p nexus-gateway -- --config config/default.toml checkThis verifies:
- gateway/control/metrics bind addresses
- TLS mode
- upstream definitions
- config schema validity
At minimum, start PostgreSQL and ensure the configured database is reachable.
To enable RL policy decisions and feedback ingestion, start the policy service from nexus-ml:
python ../nexus-ml/src/integration/policy_service.py \
--checkpoint ../nexus-ml/checkpoints/best.pt \
--port 50052 \
--feedback-log ../nexus-ml/data/live/policy_events.jsonl \
--online-train \
--online-save ../nexus-ml/checkpoints/live-online.ptcargo run -p nexus-gateway -- --config config/default.toml startUseful companion commands:
cargo run -p nexus-gateway -- --config config/default.toml status
cargo run -p nexus-gateway -- --config config/default.toml tokenHealth:
curl http://127.0.0.1:9091/api/healthStats:
curl -H "Authorization: Bearer <ADMIN_TOKEN>" http://127.0.0.1:9091/api/statsPolicy service snapshot:
curl -H "Authorization: Bearer <ADMIN_TOKEN>" http://127.0.0.1:9091/api/policyManual RL replay updates:
curl -X POST http://127.0.0.1:9091/api/policy/train \
-H "Authorization: Bearer <ADMIN_TOKEN>" \
-H "Content-Type: application/json" \
-d "{\"gradient_updates\":25,\"replay_from_log_limit\":500}"The request path is intentionally layered from cheapest to most expensive:
nexus-ratenexus-lexnexus-grammarnexus-rulesnexus-anomalynexus-policynexus-ml-client(only when enabled and not skipped)
This lets the gateway:
- block obvious attacks early
- route suspicious-but-uncertain traffic through deeper analysis
- feed final outcomes back to the RL policy agent
GET /api/health
GET /api/statsGET /api/logsGET /api/logs/:idGET /api/rulesPOST /api/rulesPOST /api/rules/synthesizeGET /api/rules/versionsGET /api/configGET /api/config/logsGET /api/policyGET /api/policy/eventsPOST /api/policy/train
- Proxy traffic:
gateway.listen_addr - Control gRPC:
gateway.control_addr - Control REST:
gateway.rest_addr - Prometheus metrics:
gateway.metrics_addr
[gateway]
listen_addr = "0.0.0.0:8080"
rest_addr = "0.0.0.0:9091"
control_addr = "0.0.0.0:9090"
metrics_addr = "0.0.0.0:9092"[policy]
enabled = true
endpoint = "http://127.0.0.1:50052"
feedback_enabled = true
feedback_batch_size = 64
feedback_flush_ms = 1000[pipeline]
ml_enabled = false
[ml]
endpoint = "http://127.0.0.1:50053"[gps]
enabled = true
[slack]
enabled = false
[gateway.tls]
enabled = falsenexus-core calls the RL policy service over gRPC using proto/policy.proto:
PolicyService.Decidefor action selectionPolicyService.ReportEventsfor live feedback ingestionPolicyService.ListFeedbackEventsfor dashboard visibilityPolicyService.TrainPolicyfor manual replay updates
The React dashboard consumes the protected REST control plane exposed by nexus-control and provides operator views for:
- dashboard metrics
- attack/config logs
- GPS rule synthesis
- policy status and JSONL tail
- manual RL training
- configuration visibility
nexus-controlis a library crate embedded into the gateway runtime; you do not start it as a separate binary.- Full workspace builds can fail if a running
nexus-gateway.exeis still locking the existing binary on Windows. Stop the running process before rebuilding the whole workspace. nexus-telemetryandnexus-metricsare intentionally different:nexus-telemetrykeeps short in-memory policy/load signalsnexus-metricsexposes Prometheus-friendly runtime counters