微服务之API网关:Kong:插件介绍:认证插件ip-restriction之黑白名单 - Go语言中文社区

微服务之API网关:Kong:插件介绍:认证插件ip-restriction之黑白名单


这里写图片描述
kong目前提供了37个插件,其中商业收费7个,30个开源免费的插件,可以设定到api/服务/路由粒度上。

环境设定

操作 详细
概要与安装 https://blog.csdn.net/liumiaocn/article/details/80442222
kong路由功能 https://blog.csdn.net/liumiaocn/article/details/80466616

插件功能

类别 免费/收费 name 插件名 使用场景
认证 免费 basic-auth Basic Authentication 对于服务或者路由提供用户名/密码基本认证机制
认证 免费 key-auth Key Authentication 对于服务或者路由提供用关键字认证机制
认证 收费 - OpenID Connect 提供与三方OpenID的集成方式
认证 免费 oauth2 OAuth 2.0 Authentication 添加OAuth 2.0认证
认证 收费 - OAuth 2.0 Introspection 提供与三方OAuth 2.0认证服务器的集成方式
认证 免费 hmac-auth HMAC Authentication 提供HMAC(Hashed Message Authentication Code)签名认证方式
认证 免费 jwt JWT 提供JWT(JSON WEB Token)的认证方式
认证 免费 ldap-auth LDAP Authentication 提供了与LDAP认证服务器的集成方式
安全 免费 acl ACL 通过ACL(Access Control List)的组名称对服务或者路由进行黑白名单的访问控制
安全 免费 cors CORS 对服务或者路由提供CORS支持
安全 免费 ip-restriction IP Restriction 通过IP地址对服务或者路由进行黑白名单的访问控制
安全 免费 bot-detection Bot Detection 对服务或者路由提供机器人检出并能进行黑白名单的设定
安全 免费 ssl Dynamic SSL 对路由或者API提供ssl支持
流量控制 收费 - EE Canary Release 提供金丝雀发布支持
流量控制 收费 - EE Forward Proxy 提供企业内网中前向代理的支持
流量控制 收费 - EE Proxy Caching 提供代理缓存的加速功能
流量控制 免费 request-size-limiting Request Size Limiting 可以对请求的body的size进行限制
流量控制 免费 rate-limiting Rate Limiting 提供对给定时间段HTTP请求数目的控制功能
流量控制 收费 - EE Rate Limiting CE版本Rate Limiting的强化
流量控制 免费 response-ratelimiting Response Rate Limiting 基于用户响应Header的信息,提供对HTTP请求数目的控制功能
流量控制 免费 request-termination Request Termination 根据响应的状态码和信息,可停止对某个服务或者路由的流量
Serverless 免费 aws-lambda AWS Lambda 调用和管理AWS Lambda函数
Serverless 免费 openwhisk Apache OpenWhisk 调用和管理OpenWhisk
分析&监控 免费 zipkin Zipkin 提供兼容zipkin的方式对用户请求进行追踪
分析&监控 免费 datadog Datadog 可将API的指标信息在datadog上进行可视化地展示
分析&监控 免费 runscope Runscope 结合runscope进行API性能测试和监控
转换 免费 request-transformer Request Transformer 通过kong对请求进行转换
转换 收费 - EE request Transformer request Transformer的强化版
转换 免费 response-transformer Response Transformer 通过kong对响应进行转换
转换 免费 correlation-id Correlation ID 通过kong实现请求和响应之间的关联
日志 免费 tcp-log TCP 发送请求和响应日志到TCP服务器
日志 免费 udp-log UDP 发送请求和响应日志到UDP服务器
日志 免费 http-log HTTP 发送请求和响应日志到HTTP服务器
日志 免费 file-log File 发送请求和响应日志到磁盘的文件中
日志 免费 statsd StatsD 发送请求和响应日志到StatsD服务器
日志 免费 syslog Syslog 发送请求和响应日志到syslog中
日志 免费 syslog Loggly 发送请求和响应日志到Loggly服务器

api信息

[root@kong ~]# curl http://localhost:8001/apis
{"total":2,"data":[{"created_at":1527303008505,"strip_uri":true,"id":"28513d56-43d7-49f2-9e64-9a7a0698e24f","hosts":["userhost"],"name":"userapi","http_if_terminated":false,"https_only":false,"retries":5,"preserve_host":false,"upstream_connect_timeout":60000,"upstream_read_timeout":60000,"upstream_send_timeout":60000,"upstream_url":"http://192.168.163.117:9001/"},{"created_at":1527303019963,"strip_uri":true,"id":"992b9c3b-889a-4c15-94b5-561ac9fb1cc9","hosts":["orghost"],"name":"orgapi","http_if_terminated":false,"https_only":false,"retries":5,"preserve_host":false,"upstream_connect_timeout":60000,"upstream_read_timeout":60000,"upstream_send_timeout":60000,"upstream_url":"http://192.168.163.117:9002/"}]}
[root@kong ~]#

设定ip-restriction插件

事前插件信息确认

[root@kong ~]# curl http://localhost:8001/plugins
{"total":0,"data":[]}
[root@kong ~]# 

设定ip-restriction插件

[root@kong ~]# curl -X POST http://localhost:8001/apis/userapi/plugins 
>      --data "name=ip-restriction"  
>      --data "config.blacklist=172.17.0.3/16"
{"created_at":1527303305000,"config":{"blacklist":["172.17.0.3/16"]},"id":"3341a3f8-1d87-4960-9da1-232718d2b89d","name":"ip-restriction","api_id":"28513d56-43d7-49f2-9e64-9a7a0698e24f","enabled":true}
[root@kong ~]# 

设定后插件信息确认

[root@kong ~]# curl http://localhost:8001/plugins
{"total":1,"data":[{"created_at":1527303305000,"config":{"blacklist":["172.17.0.3/16"]},"id":"3341a3f8-1d87-4960-9da1-232718d2b89d","name":"ip-restriction","api_id":"28513d56-43d7-49f2-9e64-9a7a0698e24f","enabled":true}]}
[root@kong ~]# 

blacklist确认

由于设定blacklist为172.17.0.3/16,所以IP为172.17.0.3和172.17.0.2的两个容器内都被限制了访问,从如下的容器中得到了确认

172.17.0.3被限制

[root@kong ~]# docker exec -it trusting_liskov sh
/ # ip ad |grep 172
    inet 172.17.0.3/16 scope global eth0
/ # 
/ # curl -H 'Host: userhost' http://192.168.163.117:8000
{"message":"Your IP address is not allowed"}
/ #

172.17.0.2被限制

[root@kong ~]# docker exec -it optimistic_stallman sh
/ # ip ad |grep 172
    inet 172.17.0.2/16 scope global eth0
/ # 
/ # curl -H 'Host: userhost' http://192.168.163.117:8000
{"message":"Your IP address is not allowed"}
/ #

192.168.163.117可正常访问

[root@kong ~]# curl -H 'Host: userhost' http://192.168.163.117:8000
Hello, Service :User Service
[root@kong ~]# ip ad |grep 192
    inet 192.168.163.117/24 brd 192.168.163.255 scope global enp0s3
[root@kong ~]# 
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/liumiaocn/article/details/80488524
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 19:58:01
  • 阅读 ( 1829 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢