我的配置:GKE群集v.1.15.7-gke.23istio:1.4.3
Istio使用默认的防火墙规则以Loadbalacner的身份创建了istio-ingressgateway服务:
我的目标是在规则上更新过滤器,仅允许从允许列表IP地址访问端点。
可以通过istio实现吗?
AFAIK不能仅通过istio配置来影响GCP防火墙上的istio-ingressgateway负载均衡器默认规则。
但是,
这种过滤可以通过使用istio策略来实现。这样,请求将到达istio-ingressgateway
,但是如果IP地址未列入白名单,则策略将拒绝该请求。
根据istio文档:
Istio支持基于IP地址的白名单和黑名单。您可以将Istio配置为接受或拒绝来自特定IP地址或子网的请求。
验证您可以访问在
productpage
找到的Bookinfohttp://$GATEWAY_URL/productpage
。一旦应用以下规则,您将无法访问它。为在入口网关处将子网list列入白名单的
"10.57.0.0\16"
适配器应用配置:$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.4/samples/bookinfo/policy/mixer-rule-deny-ip.yaml)
mixer-rule-deny-ip.yaml
的内容:
apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: whitelistip
spec:
compiledAdapter: listchecker
params:
# providerUrl: ordinarily black and white lists are maintained
# externally and fetched asynchronously using the providerUrl.
overrides: ["10.57.0.0/16"] # overrides provide a static list
blacklist: false
entryType: IP_ADDRESSES
---
apiVersion: config.istio.io/v1alpha2
kind: instance
metadata:
name: sourceip
spec:
compiledTemplate: listentry
params:
value: source.ip | ip("0.0.0.0")
---
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: checkip
spec:
match: source.labels["istio"] == "ingressgateway"
actions:
- handler: whitelistip
instances: [ sourceip ]
---
- 尝试访问
productpage
处的Bookinfohttp://$GATEWAY_URL/productpage
,并确认您收到类似以下错误:PERMISSION_DENIED:staticversion.istio-system:<your mesh source ip> is not whitelisted
文档中的示例具有Before you begin部分,因此请确保满足Enabling Policy Enforcement的要求。