Egress using Wildcard Hosts

    Suppose you want to enable egress traffic in Istio for the wikipedia.org sites in all languages. Each version of wikipedia.org in a particular language has its own hostname, e.g., en.wikipedia.org and de.wikipedia.org in the English and the German languages, respectively. You want to enable egress traffic by common configuration items for all the Wikipedia sites, without the need to specify every language’s site separately.

    • Install Istio using the demo configuration profile and with the blocking-by-default outbound traffic policy:

      You can run this task on an Istio configuration other than the demo profile as long as you make sure to , enable Envoy’s access logging, and in your installation. You will also need to add the second gateway using your own IstioOperator CR instead of the one shown in setup egress gateway with SNI proxy.

    • Deploy the sample app to use as a test source for sending requests. If you have automatic sidecar injection enabled, run the following command to deploy the sample app:

      1. $ kubectl apply -f @samples/sleep/sleep.yaml@

      Otherwise, manually inject the sidecar before deploying the sleep application with the following command:

      1. $ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)

      You can use any pod with curl installed as a test source.

    • Set the SOURCE_POD environment variable to the name of your source pod:

      1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})

    The first, and simplest, way to access a set of hosts within a common domain is by configuring a simple ServiceEntry with a wildcard host and calling the services directly from the sidecar. When calling services directly (i.e., not via an egress gateway), the configuration for a wildcard host is no different than that of any other (e.g., fully qualified) host, only much more convenient when there are many hosts within the common domain.

    Note that the configuration below can be easily bypassed by a malicious application. For a secure egress traffic control, direct the traffic through an egress gateway.

    Note that the DNS resolution cannot be used for wildcard hosts. This is why the NONE resolution (omitted since it is the default) is used in the service entry below.

    1. Define a ServiceEntry for *.wikipedia.org:

      1. $ kubectl exec "$SOURCE_POD" -c sleep -- sh -c 'curl -s https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
      2. <title>Wikipedia, the free encyclopedia</title>
      3. <title>Wikipedia Die freie Enzyklopädie</title>
    1. $ kubectl delete serviceentry wikipedia

    Wildcard configuration for a single hosting server

    When all wildcard hosts are served by a single server, the configuration for egress gateway-based access to a wildcard host is very similar to that of any host, with one exception: the configured route destination will not be the same as the configured host, i.e., the wildcard. It will instead be configured with the host of the single server for the set of domains.

    1. Create an egress Gateway for \.wikipedia.org*, a destination rule and a virtual service to direct the traffic through the egress gateway and from the egress gateway to the external service.

      1. $ kubectl apply -f - <<EOF
      2. apiVersion: networking.istio.io/v1alpha3
      3. kind: Gateway
      4. metadata:
      5. name: istio-egressgateway
      6. spec:
      7. selector:
      8. istio: egressgateway
      9. - port:
      10. number: 443
      11. name: https
      12. hosts:
      13. - "*.wikipedia.org"
      14. tls:
      15. mode: PASSTHROUGH
      16. ---
      17. apiVersion: networking.istio.io/v1alpha3
      18. kind: DestinationRule
      19. metadata:
      20. name: egressgateway-for-wikipedia
      21. spec:
      22. host: istio-egressgateway.istio-system.svc.cluster.local
      23. subsets:
      24. - name: wikipedia
      25. ---
      26. apiVersion: networking.istio.io/v1alpha3
      27. kind: VirtualService
      28. metadata:
      29. name: direct-wikipedia-through-egress-gateway
      30. spec:
      31. hosts:
      32. - "*.wikipedia.org"
      33. gateways:
      34. - mesh
      35. - istio-egressgateway
      36. tls:
      37. - match:
      38. - gateways:
      39. - mesh
      40. sniHosts:
      41. - "*.wikipedia.org"
      42. route:
      43. host: istio-egressgateway.istio-system.svc.cluster.local
      44. subset: wikipedia
      45. port:
      46. number: 443
      47. weight: 100
      48. - match:
      49. - gateways:
      50. - istio-egressgateway
      51. port: 443
      52. sniHosts:
      53. - "*.wikipedia.org"
      54. route:
      55. - destination:
      56. host: www.wikipedia.org
      57. port:
      58. number: 443
      59. weight: 100
      60. EOF
    2. Create a ServiceEntry for the destination server, .

    3. Send HTTPS requests to https://en.wikipedia.org and :

      1. $ kubectl exec "$SOURCE_POD" -c sleep -- sh -c 'curl -s https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
      2. <title>Wikipedia, the free encyclopedia</title>
      3. <title>Wikipedia Die freie Enzyklopädie</title>
    4. Check the statistics of the egress gateway’s proxy for the counter that corresponds to your requests to \.wikipedia.org*. If Istio is deployed in the istio-system namespace, the command to print the counter is:

      1. $ kubectl exec "$(kubectl get pod -l istio=egressgateway -n istio-system -o jsonpath='{.items[0].metadata.name}')" -c istio-proxy -n istio-system -- pilot-agent request GET clusters | grep '^outbound|443||www.wikipedia.org.*cx_total:'
      2. outbound|443||www.wikipedia.org::208.80.154.224:443::cx_total::2

    Cleanup wildcard configuration for a single hosting server

    1. $ kubectl delete serviceentry www-wikipedia
    2. $ kubectl delete gateway istio-egressgateway
    3. $ kubectl delete virtualservice direct-wikipedia-through-egress-gateway
    • Shutdown the sleep service:

    • Uninstall Istio from your cluster: