APISIX Official Doc: https://apisix.apache.org/docs/apisix/plugins/chaitin-waf/
Apache APISIX is a cloud-native API gateway that provides load balancing, dynamic upstream configuration, canary releases, circuit breaking, authentication, and observability. SafeLine is a web application firewall (WAF) developed by Chaitin Technology that inspects HTTP requests and protects web applications and APIs. Starting with APISIX 3.5.0, the built-in chaitin-waf plugin can send requests to SafeLine for inspection.
1. Check the requirements
- Apache APISIX: 3.5.0 or later
- SafeLine: 5.6.0 or later
An online SafeLine upgrade may reset compose.yaml. If that happens, repeat the detector configuration below and recreate the containers before reconnecting APISIX.
2. Configure the SafeLine detector
SafeLine Community Edition uses a Unix socket by default. To let APISIX connect over TCP, open /data/safeline/resources/detector/detector.yml and add:
bind_addr: 0.0.0.0
listen_port: 8000
These settings override the corresponding defaults inside the container. In /data/safeline/compose.yaml, add the following under the detect service to publish the detector port:
ports:
- "8000:8000"
From the SafeLine installation directory, recreate the containers:
docker compose down
docker compose up -d
If SafeLine and APISIX run on the same host, both use port 9443 by default. To avoid a conflict, change MGT_PORT in SafeLine’s .env file and restart SafeLine.
3. Install APISIX
The article uses the Docker deployment of APISIX 3.5.0 as an example. Clone the Apache apisix-docker repository, then run:
cd apisix-docker/compose
echo 'APISIX_DOCKER_TAG=3.5.0-debian' >> .env
docker compose -f docker-compose-release.yaml up -d
The gateway listens at http://127.0.0.1:9080/, and the Admin API listens at http://127.0.0.1:9180/.
4. Connect APISIX to SafeLine
Use the APISIX Admin API to register the SafeLine detector and enable the plugin on a route. Replace <APISIX_ADMIN_KEY> with your own Admin API key and replace the example IP addresses with those of your detector host and upstream server.
Register the detector:
curl -X PUT 'http://127.0.0.1:9180/apisix/admin/plugin_metadata/chaitin-waf' \
-H 'X-API-KEY: <APISIX_ADMIN_KEY>' \
-d '{"nodes":[{"host":"192.168.99.11","port":8000}]}'
Create a route that enables chaitin-waf and proxies requests to the upstream server:
curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/1' \
-H 'X-API-KEY: <APISIX_ADMIN_KEY>' \
-d '{
"uri": "/*",
"plugins": {"chaitin-waf": {}},
"upstream": {
"type": "roundrobin",
"nodes": {"192.168.99.12:80": 1}
}
}'
5. Verify that the WAF is working
Send a normal request to http://127.0.0.1:9080/ and confirm that APISIX returns the upstream page. Next, send a simulated SQL injection request to your test deployment. In the article’s example, SafeLine blocks the request with HTTP 403, returns an event_id, and records the event in the SafeLine console.
6. Keep SafeLine-managed sites protected
After switching the detector from a Unix socket to TCP, sites configured directly in the SafeLine console also need NGINX to reach the detector over HTTP.
- Copy
/data/safeline/resources/nginx/safeline_unix.confto/data/safeline/resources/nginx/safeline_http.conf. - In
nginx.conf, comment outinclude /etc/nginx/safeline_unix.conf;and addinclude /etc/nginx/safeline_http.conf;. - Use
docker inspectto find the IP address of thesafeline-detectorcontainer. - In
safeline_http.conf, replace the Unix socket entry in thedetector_serverupstream withserver <DETECTOR_IP>:8000;, using the IP address from the previous step.
If you run into problems, please join SafeLine discord server: https://discord.gg/dy3JT7dkmY
Or contact support@cyberserval.com (Cyberserval is a subsidiary of Chaitin Tech, handling overseas business).
Top comments (0)