istio: AUTO_SNI does not respect Authority rewrite

Is this the right place to submit this?

  • This is not a security vulnerability or a crashing bug
  • This is not a question about how to use Istio

Bug Description

I installed istio version 1.21.0 via Helm into a cluster. After that I made a deploy of my application. I need DR because on the application side, HTTPS works, not HTTP. The settings concerning Istio are:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: preapproved-service
  namespace: cnv-preprod
spec:
  host: preapproved-service
  trafficPolicy:
    tls:
      mode: SIMPLE
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: preapproved-service
  namespace: cnv-preprod
spec:
  gateways:
    - istio-ingress/cnv-ingress-gateway-https
  hosts:
    - preprod-cnv-srv.example.com
  http:
    - match:
        - uri:
            prefix: /preapproved-service
      name: preapproved-service
      rewrite:
        uri: /
      route:
        - destination:
            host: preapproved-service
            port:
              number: 8080
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: cnv-ingress-gateway-https
  namespace: istio-ingress
spec:
  selector:
    istio: ingressgateway
  servers:
    - hosts:
        - preprod-cnv-srv.example.com
      port:
        name: https
        number: 443
        protocol: HTTPS
      tls:
        credentialName: tls-certs-opaque-preprod-cnv-srv
        mode: SIMPLE

After I try to connect my application: https://preprod-cnv-srv.example.com/preapproved-service/healthCheck and see the error:

upstream connect error or disconnect/reset before headers. retried and the latest reset reason: remote connection failure, transport failure reason: TLS_error:|268435581:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED:TLS_error_end:TLS_error_end

When I downgrade istiod from 1.21.0 to 1.20.1 (my dev and test clusters using this version of istio) the error disappears. The configuration does not change in any way. Probably it’s not a bug and something wrong in my configuration, I don’t know for sure

Version

PS .\istioctl.exe version --kubeconfig C:\Users\Vladimir.Fomin\.kube\preprod-cnv-kubeconfig.yaml
client version: 1.20.1
control plane version: 1.21.0
data plane version: 1.20.1 (2 proxies)

helm version --short
v3.14.0+g3fc9f4b

Additional Information

bug-report.log

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 26 (19 by maintainers)

Most upvoted comments

My PR (https://github.com/envoyproxy/envoy/issues/35330) in envoy got merged. It improves both Auto-SNI and Auto-SAN behavior such that host manipulation happening at route level will be taken into account when computing SNI/SAN. No adjustments from Istio-side are needed as the new behavior is also the new default for envoy. You should see the new behavior in Istio 1.24 once we update to the latest envoy release. For the time being, we will retain the AUTO_SNI env flag for users affected by this issue, it will be removed in Istio 1.25

I will close this issue, please let me know if you still encounter auto-sni issues in 1.24

OK so I think before it was setting empty SNI, and now service.internal.foo, which is wrong IMO. I cannot find the original issue but there was some discussion that this should respect the rewrite @kfaseela

I am on vacation currently, @leosarra do you think you will be able to fix this?

I remember checking some weeks ago why envoy ignores the rewrite if auto sni is enabled. I will need to check again but I recall it being intended, I feel that we will have to disable auto sni if we have a rewrite in a VS. This week I have limited availability but perhaps I can manage to take a look.

Hi,

I’m not 100% sure if this is related, but we face the same issue when using an VirtualService to expose an external Service (ServiceEntry) via Istio IngressGateway.

We can fix the problem, if we define the SNI explicitly within the DestinationRule for our ServiceEntry (see examples below).

But IMHO this was kind of breaking change for us (worked without the SNI override within 1.20.x, but was broken in 1.21.3) @howardjohn. Actually, I would have thought, that the AUTO_SNI setting would not influence the SNI header if the Authority has been overriden using the Rewrite functionality of the VirtualService.

Our setup basically looks like this and worked with Istio 1.20.x: Internal URL -> Istio IngressGateway -> VirtualService -> ServiceEntry (external URL) + DestinationRule (HTTPS mode, Simple TLS)

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: service-external-foo
  namespace: some-other-namespace
spec:
  gateways:
  - istio-ingress/my-gateway # GW implemented by the Istio IngressGateway
  hosts:
  - service.internal.foo # This is the downstream URL, served by the Istio IngressGateway
  http:
  - match:
    - uri:
        exact: "/some/path"
    rewrite:
      authority: service.external.foo # We did this because of HTTP Host & SNI and seems to work until 1.21.x
    route:
    - destination:
        host: service.external.foo # This is the ServiceEntry, see below
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: service-external-foo
  namespace: istio-ingress # Namespace of the Istio IngressGateway
spec:
  host: service.external.foo
  trafficPolicy:
    portLevelSettings:
      - port:
          number: 443
        tls:
          mode: SIMPLE
          # sni: service.external.foo # Adding this line fixes the problem. But worked without this in Istio 1.20.
---
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: service-external-foo
  namespace: istio-ingress # Namespace of the Istio IngressGateway
spec:
  hosts:
    - service.external.foo
  location: MESH_EXTERNAL
  ports:
    - name: https
      number: 443
      protocol: HTTPS
  resolution: DNS

Code-wise the AUTO_SNI flag handling looks correct. @DMSwimTech could you raise a separate issue with a small POC to reproduce it so that we can take a deeper look?

I will open an issue in envoy. If the Envoy community agrees on the approach I can take care of performing the changes there (and any adaptation that may be require from Istio side)

@vsfomin we also experienced this when upgrading from 1.20 to 1.22 but solved it with the SNI option like this:

spec:
  host: <hostname>
  trafficPolicy:
    tls:
      mode: SIMPLE
      sni: <hostname>

https://istio.io/latest/docs/reference/config/networking/destination-rule/#ClientTLSSettings:

SNI string to present to the server during TLS handshake. If unspecified, SNI will be automatically set based on downstream HTTP host/authority header for SIMPLE and MUTUAL TLS modes.

Maybe try to add InsecureSkipVerify in DR