Kong(V1.0.2) Securing the Admin API

Introduction

Kong的Admin API为Services, Routes, Plugins, Consumers, and Credentials的管理和配置提供了一个RESTful接口。因为这个API允许对Kong进行完全控制,所以确保这个API能够安全的访问非常重要。本文描述了保护管理API的几种可能方法。

网络层访问限制

Minimal Listening Footprint(很少听足迹

默认情况下,从它的0.12.0版本开始,Kong将只接受来自本地接口的请求,这在它的默认admin_listen值中指定:

admin_listen = 127.0.0.1:8001

如果您更改此值,请始终确保将侦听占用最小化,以避免将管理API暴露给第三方,这可能严重损害整个Kong集群的安全性。例如,通过使用0.0.0.0:8001这样的值,避免将Kong绑定到所有接口。

Layer 3/4 Network Controls层3/4网络控制

如果管理API必须公开在本地主机接口之外,则网络安全最佳实践要求尽可能限制网络层访问。考虑这样一种环境:Kong在私有网络接口上监听,但只能被IP范围的一小部分访问。在这种情况下,基于主机的防火墙(例如iptables)在限制输入流量范围方面非常有用。例如:

# assume that Kong is listening on the address defined below, as defined as a
# /24 CIDR block, and only a select few hosts in this range should have access

grep admin_listen /etc/kong/kong.conf
admin_listen 10.10.10.3:8001

# explicitly allow TCP packets on port 8001 from the Kong node itself
# this is not necessary if Admin API requests are not sent from the node
iptables -A INPUT -s 10.10.10.3 -m tcp -p tcp --dport 8001 -j ACCEPT

# explicitly allow TCP packets on port 8001 from the following addresses
iptables -A INPUT -s 10.10.10.4 -m tcp -p tcp --dport 8001 -j ACCEPT
iptables -A INPUT -s 10.10.10.5 -m tcp -p tcp --dport 8001 -j ACCEPT

# drop all TCP packets on port 8001 not in the above IP list
iptables -A INPUT -m tcp -p tcp --dport 8001 -j DROP

我们鼓励使用其他控件,如在网络设备级别应用的类似acl,但不属于本文的范围。

Kong API Loopback(API回送)

Kong的路由设计允许它充当管理API本身的代理。通过这种方式,可以使用Kong本身为管理API提供细粒度的访问控制。这样的环境需要引导一个新服务,该服务将admin_listen地址定义为服务的url。例如:

# assume that Kong has defined admin_listen as 127.0.0.1:8001, and we want to
# reach the Admin API via the url `/admin-api`
curl -X POST http://localhost:8001/services \
  --data name=admin-api \
  --data host=localhost \
  --data port=8001

curl -X POST http://localhost:8001/services/admin-api/routes \
  --data paths[]=/admin-api

# we can now transparently reach the Admin API through the proxy server
curl localhost:8000/admin-api/apis
{
   "data":[
      {
         "uris":[
            "\/admin-api"
         ],
         "id":"653b21bd-4d81-4573-ba00-177cc0108dec",
         "upstream_read_timeout":60000,
         "preserve_host":false,
         "created_at":1496351805000,
         "upstream_connect_timeout":60000,
         "upstream_url":"http:\/\/localhost:8001",
         "strip_uri":true,
         "https_only":false,
         "name":"admin-api",
         "http_if_terminated":true,
         "upstream_send_timeout":60000,
         "retries":5
      }
   ],
   "total":1
}

From here, simply apply desired Kong-specific security controls (such as basic or key authentication, IP restrictions, or access control lists) as you would normally to any other Kong API.

 

Custom Nginx Configuration

Kong作为一个HTTP守护进程与Nginx紧密耦合,因此可以使用定制的Nginx配置集成到环境中。通过这种方式,具有复杂安全/访问控制需求的用例可以使用Nginx/OpenResty的全部功能来构建服务器/位置块,以便在必要时容纳管理API。这允许此类环境利用本地Nginx授权和身份验证机制、ACL模块等,此外还提供可在其上构建自定义/复杂安全控制的OpenResty环境。
有关将Kong集成到定制Nginx配置中的更多信息,请参见Custom Nginx configuration & embedding Kong

Role Based Access Control(基于角色的访问控制)

此功能仅在企业版中可用。

企业用户可以配置基于角色的访问控制,以确保对管理API的访问安全。RBAC允许基于用户角色和权限模型对资源访问进行细粒度控制。用户被分配到一个或多个角色,每个角色又拥有一个或多个授予或拒绝访问特定资源的权限。通过这种方式,可以加强对特定管理API资源的细粒度控制,同时扩展以允许复杂的、特定于大小写的使用。

如果您不是Kong企业客户,您可以通过以下方式contacting us查询我们的企业报价

 

posted on 2019-02-15 18:23  duanxz  阅读(808)  评论(0编辑  收藏  举报