【问题标题】:Create firewall on GCP through istio通过 istio 在 GCP 上创建防火墙
【发布时间】:2020-05-27 18:56:36
【问题描述】:

我的配置: GKE 集群 v. 1.15.7-gke.23 istio:1.4.3

Istio 使用默认防火墙规则将 istio-ingressgateway 服务创建为 Loadbalacner:

  • 类型:入口
  • 目标:GKE 集群上的虚拟机
  • 过滤器:0.0.0.0/0
  • 协议/端口:tcp:15020,tcp:80, tcp:443, tcp:15029,tcp:15030,tcp:15031,tcp:15032,tcp:15443

我的目标是更新规则上的 过滤器,只允许从允许列表 IP 地址访问端点。

可以通过istio实现吗?

【问题讨论】:

    标签: kubernetes google-cloud-platform google-kubernetes-engine istio


    【解决方案1】:

    AFAIK 不可能仅从 istio 配置影响 GCP 防火墙上的 istio-ingressgateway Loadbalancer 默认规则。


    然而,

    这种过滤可以通过使用 istio 策略来实现。这样请求将到达istio-ingressgateway,但如果 IP 地址未列入白名单,则会被策略拒绝。

    根据istio 文档:

    Istio 支持基于 IP 地址的白名单黑名单。您可以将 Istio 配置为接受或拒绝来自特定 IP 地址或子网的请求。

    1. 确认您可以访问位于 http://$GATEWAY_URL/productpage 的 Bookinfo productpage。应用以下规则后,您将无法访问它。

    2. 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 ]
    ---
    
    1. 尝试访问 Bookinfo productpage http://$GATEWAY_URL/productpage 并验证您是否收到类似于以下内容的错误:PERMISSION_DENIED:staticversion.istio-system:<your mesh source ip> is not whitelisted

    文档中的示例包含Before you begin 部分,因此请确保满足Enabling Policy Enforcement 的要求。

    编辑:

    为了澄清,

    Istio 和 GCP 防火墙规则在不同级别上工作。 Istio 仅在其网格内启用,也就是说,无论您在哪里注入了 sidecar。

    为了使istio-ingressgateway 工作,GCE 提​​供了一个网络负载均衡器,它具有一些预先配置的规则,完全独立于 Istio 网格。

    所以基本上:GCE 防火墙规则只会影响连接到集群的网络负载均衡器,以允许流量进入 Istio 网格,并且 Istio 中的过滤规则将仅适用于其中的所有 Pod/服务/端点网格。

    【讨论】:

    • 这不是在回答问题。您只需让 Istio 不接受对特定 IP 范围的某些请求,但此防火墙规则仍然对所有人开放。
    • 你是对的。我已经编辑了我的答案来解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2011-04-05
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    相关资源
    最近更新 更多