Kong 是一个云原生、快速、可扩展和分布式的微服务抽象层(也称为 API 网关或 API 中间件)。它通过插件提供了丰富的流量控制、安全、监控和运维功能。
参考 APISIX 联动雷池 的准备工作。
自定义插件可以通过 LuaRocks 安装。Lua 插件以 .rock 格式分发,这是一个自包含的包,可以从本地或远程服务器安装。
如果您使用了官方的 Kong Gateway 安装包,则 LuaRocks 实用程序应该已经安装在您的系统中。
luarocks install kong-safeline
plugins = bundled,safeline # Comma-separated list of plugins this node
# should load. By default, only plugins
# bundled in official distributions are
# loaded via the `bundled` keyword.
kong restart
在某个 service 上启用 safeline 插件:
config 中的 detector_host 和 safeline_port 是雷池检测引擎的地址和端口,是在准备工作中配置的。
curl -X POST http://localhost:8001/services/{service}/plugins \
--data "name=safeline" \
--data "config.host=<detector_host>" \
--data "config.port=<detector_port>"
模拟简单的 SQL 注入攻击访问 kong ,如果返回 403 Forbidden,说明防护生效。
$ curl -X POST http://localhost:8000?1=1%20and%202=2
# you will receive a 403 Forbidden response
{"code": 403, "success":false, "message": "blocked by Chaitin SafeLine Web Application Firewall", "event_id": "8b41a021ea9541c89bb88f3773b4da24"}
打开雷池的控制台界面,可以看到雷池记录了完整的攻击信息。
如果在使用过程中遇到问题,可以加入 SDK 讨论群