Kong的Admin API爲Services, Routes, Plugins, Consumers, and Credentials的管理和配置提供了一個RESTful接口。由於這個API容許對Kong進行徹底控制,因此確保這個API可以安全的訪問很是重要。本文描述了保護管理API的幾種可能方法。node
Minimal Listening Footprint(不多聽足跡)
默認狀況下,從它的0.12.0版本開始,Kong將只接受來自本地接口的請求,這在它的默認admin_listen值中指定:
admin_listen = 127.0.0.1:8001
若是您更改此值,請始終確保將偵聽佔用最小化,以免將管理API暴露給第三方,這可能嚴重損害整個Kong集羣的安全性。例如,經過使用0.0.0.0:8001這樣的值,避免將Kong綁定到全部接口。nginx
若是管理API必須公開在本地主機接口以外,則網絡安全最佳實踐要求儘量限制網絡層訪問。考慮這樣一種環境:Kong在私有網絡接口上監聽,但只能被IP範圍的一小部分訪問。在這種狀況下,基於主機的防火牆(例如iptables)在限制輸入流量範圍方面很是有用。例如:api
# 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自己的代理。經過這種方式,能夠使用Kong自己爲管理API提供細粒度的訪問控制。這樣的環境須要引導一個新服務,該服務將admin_listen地址定義爲服務的url。例如:bash
# 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.服務器
Kong做爲一個HTTP守護進程與Nginx緊密耦合,所以能夠使用定製的Nginx配置集成到環境中。經過這種方式,具備複雜安全/訪問控制需求的用例能夠使用Nginx/OpenResty的所有功能來構建服務器/位置塊,以便在必要時容納管理API。這容許此類環境利用本地Nginx受權和身份驗證機制、ACL模塊等,此外還提供可在其上構建自定義/複雜安全控制的OpenResty環境。
有關將Kong集成到定製Nginx配置中的更多信息,請參見Custom Nginx configuration & embedding Kong。網絡
此功能僅在企業版中可用。
企業用戶能夠配置基於角色的訪問控制,以確保對管理API的訪問安全。RBAC容許基於用戶角色和權限模型對資源訪問進行細粒度控制。用戶被分配到一個或多個角色,每一個角色又擁有一個或多個授予或拒絕訪問特定資源的權限。經過這種方式,能夠增強對特定管理API資源的細粒度控制,同時擴展以容許複雜的、特定於大小寫的使用。
若是您不是Kong企業客戶,您能夠經過如下方式contacting us查詢咱們的企業報價app