如何在 ISTIO 中配置 TLS 源?

vik*_*ikp 5 kubernetes istio envoyproxy mtls

Istio 不会通过 TLS 发起路由到外部 HTTPs 服务。

我有一个包含两个容器的 pod: - 应用程序 - ISTIO 代理

应用程序调用位于https://someurl.somedomain.com/v1/some-service 的外部第三方 API

应用程序通过调用http://someurl.somedomain.com/v1/some-service向该服务发送 HTTP 请求- 注意它是 HTTP 而不是 HTTPs。

然后我在 ISTIO 中配置了以下内容:

  • 将 HTTP 流量路由到端口 443 的虚拟服务:
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: someservice-vs
spec:
  hosts:
  - someurl.somedomain.com
  http:
  - match:
    - port: 80    
    route:
    - destination:
        host: someurl.somedomain.com
        port:
          number: 443      
    timeout: 40s
    retries:
      attempts: 10
      perTryTimeout: 4s      
      retryOn: gateway-error,connect-failure,refused-stream,retriable-4xx,5xx 
Run Code Online (Sandbox Code Playgroud)
  • 允许流量流出的服务入口。如您所见,我们指定服务在网格外部,我们打开了 443 和 80,它们都使用 HTTP,但 443 配置为 TLS 发起。
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: someservice-se
spec:
  hosts:
  - someurl.somedomain.com
  location: MESH_EXTERNAL
  ports:
  - number: 443
    name: http-port-for-tls-origination
    protocol: HTTP
  - number: 80
    name: http-port
    protocol: HTTP
  resolution: DNS

Run Code Online (Sandbox Code Playgroud)

最后,我有一个将简单 TLS 应用于传出流量的目标规则:


---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: someservice-destinationrule
spec:
  host: someurl.somedomain.com
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
    portLevelSettings:
    - port:
        number: 443
      tls:
        mode: SIMPLE # initiates HTTPS when accessing someurl.somedomain.com 

Run Code Online (Sandbox Code Playgroud)

出于某种原因,这不起作用,当我从我的应用程序容器调用服务时得到 404,这表明流量没有通过 TLS 加密。

我使用 TLS 发起的原因是因为我需要在我的虚拟服务中应用重试,我只能使用 HTTP 路由执行此操作,否则 ISTIO 无法看到请求并使用它。

我已经挠了两天了,需要一些帮助,请:-)

Rob*_*zer 1

我认为它应该像这样工作:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: someservice-vs
spec:
  hosts:
    - someurl.somedomain.com
  http:
    - match:
        - port: 80
      route:
        - destination:
            host: someurl.somedomain.com
      timeout: 40s
      retries:
        attempts: 10
        perTryTimeout: 4s
        retryOn: gateway-error,connect-failure,refused-stream,retriable-4xx,5xx
---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: someservice-se
spec:
  hosts:
    - someurl.somedomain.com
  location: MESH_EXTERNAL
  ports:
    - number: 80
      protocol: HTTP
      name: http
  endpoints:
    - address: someurl.somedomain.com
      ports:
        http: 443
  resolution: DNS
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: someservice-destinationrule
spec:
  host: someurl.somedomain.com
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
    tls:
      mode: SIMPLE # initiates HTTPS when accessing someurl.somedomain.com
Run Code Online (Sandbox Code Playgroud)

让 ServiceEntry 侦听端口 80,但端点地址指向端口 443。然后 DestinationRule 对所有目标端口 80 应用 TLS,最终通过集群的端点转发到端口 443。