<p>My use case is the following I want o intercept calls to the LDAP in 172.28.0.3:389 and forward to 172.28.0.3:636 with TLS.</p>
<p>I have followed the steps of <a href="https://istio.io/v1.6/docs/tasks/traffic-management/egress/egress-tls-origination/" rel="nofollow noreferrer">egress tls originate</a> and it works fine. Now I am trying to use the gateway, unfortunately I am having problems setting up the ports. I have basically copied and paste the setup of <a href="https://istio.io/v1.6/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/#perform-tls-origination-with-an-egress-gateway" rel="nofollow noreferrer">documentation</a> and adapted the protocols from HTTP and HTTPS to TCP and the ports 80 and 443 to 389 and 636 respectively:</p>
<pre><code>    apiVersion: networking.istio.io/v1alpha3
    kind: ServiceEntry
    metadata:
      name: cnn
    spec:
      hosts:
      - ldap.host
      addresses:
      - 172.28.0.3
      ports:
      - number: 389
        name: tcp
        protocol: TCP
      - number: 636
        name: tcp-secure
        protocol: TCP
      resolution: STATIC
      endpoints:
       - address: 172.28.0.3

------ 


apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-egressgateway
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 389 # I am not sure about this
      name: tpc-port-for-tls-origination
      protocol: tcp
    hosts:
    - ldap.host
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: egressgateway-for-cnn
spec:
  host: istio-egressgateway.istio-system.svc.cluster.local
  subsets:
  - name: cnn


apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: direct-cnn-through-egress-gateway
spec:
  hosts:
  - ldap.host
  gateways:
  - istio-egressgateway
  - mesh
  tcp: # I AM NOT SURE ABOUT THIS PART
  - match:
    - gateways:
      - mesh
      port: 389
    route:
    - destination:
        host: istio-egressgateway.istio-system.svc.cluster.local
        subset: cnn
        port:
          number: 389
      weight: 100
  - match:
    - gateways:
      - istio-egressgateway
      port: 389
    route:
    - destination:
        host: ldap.host
        port:
          number: 636
      weight: 100
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: originate-tls-for-edition-cnn-com
spec:
  host: ldap.host
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
    portLevelSettings:
    - port:
        number: 636
      tls:
        mode: SIMPLE # initiates HTTPS for connections to edition.cnn.com
</code></pre>
<p>I have the feeling that the problem is on the <code>VirtualService</code>, however I have tried many things but without success, any hint what might be the issue would be highly appreciated.</p>

Learner
<p>Looking into this post and previous post: it looks like you are interested with external <a href="https://istio.io/v1.6/docs/concepts/security/#authentication" rel="nofollow noreferrer">custom authentication</a> provider which support LDAP integration. For example you can use <a href="https://www.keycloak.org/" rel="nofollow noreferrer">keycloak</a>, <a href="https://auth0.com/" rel="nofollow noreferrer">Auth0</a>, <a href="https://developers.google.com/identity/protocols/oauth2/openid-connect" rel="nofollow noreferrer">Google Auth</a>.</p>
<p>This documentation shows an external authentication, that it can be <a href="https://www.keycloak.org/2018/02/keycloak-and-istio.html" rel="nofollow noreferrer">integrated with istio</a>. Please note that the documentation may be outdated (02/2018).</p>
<hr />
<p>Here you can find <a href="https://serverfault.com/questions/1006234/how-to-implement-user-authentication-with-istio-along-with-ldap-or-other-compone">similar problem</a>:</p>
<blockquote>
<p>As far as I'm concerned LDAP is not working in  <a href="https://github.com/istio/istio/issues/15972#issuecomment-517340074" rel="nofollow noreferrer">istio</a>.
Workaround here would be either  <a href="https://www.keycloak.org/" rel="nofollow noreferrer">keycloak</a>  or  <a href="https://auth0.com/" rel="nofollow noreferrer">auth0</a>
You can integrate both of them with istio, but it's just for authentication, It won't work as LDAP itself, at least as far as I know.</p>
</blockquote>
<hr />
<p>You can also eanble authentication with JSON Web Token (JWT) validation. Istio takes care of the task of validating the JWT tokens in the incoming user requests. So if you implement Istio JWT authentication feature, your application code doesn’t need to bother about the JWT token validation. Istio will do it for you. Not JWT token generation. Istio will not generate the tokens for you. You have to have an Authentication micro-service that generates the token.
<a href="https://stackoverflow.com/questions/60483362/how-to-integrate-openidconnect-with-istio">Here</a> is thread on how to authenticate end users using JWT.</p>
