我有安装了Istio的kubernetes集群。我有两个Pod,例如sleep1和sleep2(装有curl的容器)。我想将istio配置为允许从sleep1到www.google.com的流量,并禁止从sleep2到www.google.com的流量。

因此,我创建了ServiceEntry:

---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: google
spec:
  hosts:
  - www.google.com
  - google.com
  ports:
  - name: http-port
    protocol: HTTP
    number: 80
  resolution: DNS

网关
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-egressgateway
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 80
      name: http-port
      protocol: HTTP
    hosts:
    - "*"

两个virtualServices(网格->出口,出口-> google)
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: mesh-to-egress
spec:
  hosts:
  - www.google.com
  - google.com
  gateways:
  - mesh
  http:
  - match:
    - gateways:
      - mesh
      port: 80
    route:
    - destination:
        host: istio-egressgateway.istio-system.svc.cluster.local
        port:
          number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: egress-to-google-int
spec:
  hosts:
  - www.google.com
  - google.com
  gateways:
  - istio-egressgateway
  http:
  - match:
    - gateways:
      - istio-egressgateway
      port: 80
    route:
    - destination:
        host: google.com
        port:
          number: 80
      weight: 100

结果,我可以从两个 pod 中 curl 谷歌。

还有一个问题:我可以允许从sleep1到www.google.com的流量,并禁止从sleep2到www.google.com的流量吗?我知道这可能与kubernetes NetworkPolicy和黑名单/白名单(https://istio.io/docs/tasks/policy-enforcement/denial-and-list/)有关,但是这两种方法均禁止(允许)特定IP的流量,或者我错过了什么?

最佳答案

您可以为sleep1sleep2创建不同的服务帐户。然后,您使用create an RBAC policy限制对istio-egressgateway策略的访问,因此sleep2将无法通过出口网关访问任何出口流量。这应该可以禁止来自群集的,不是源自出口网关的任何出口流量。参见https://istio.io/docs/tasks/traffic-management/egress/egress-gateway/#additional-security-considerations

如果要允许sleep2访问其他服务,而不是www.google.com,则可以使用Mixer规则和处理程序,请参见this blog post。它显示了如何允许特定URL到达特定服务帐户。

关于kubernetes - 关于istio导出流量的细化政策,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57824931/

10-12 23:37