Using an External HTTPS Proxy

    This example shows how to enable access to an external HTTPS proxy. Since applications use the HTTP method to establish connections with HTTPS proxies, configuring traffic to an external HTTPS proxy is different from configuring traffic to external HTTP and HTTPS services.

    • Setup Istio by following the instructions in the Installation guide.

      The egress gateway and access logging will be enabled if you install the .

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

      Zip

      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})
    • Enable Envoy’s access logging

    To simulate a legacy proxy and only for this example, you deploy an HTTPS proxy inside your cluster. Also, to simulate a more realistic proxy that is running outside of your cluster, you will address the proxy’s pod by its IP address and not by the domain name of a Kubernetes service. This example uses but you can use any HTTPS proxy that supports HTTP CONNECT.

      1. $ kubectl create namespace external
    1. Create a configuration file for the Squid proxy.

      1. $ cat <<EOF > ./proxy.conf
      2. http_port 3128
      3. acl SSL_ports port 443
      4. acl CONNECT method CONNECT
      5. http_access deny CONNECT !SSL_ports
      6. http_access allow localhost manager
      7. http_access deny manager
      8. http_access allow all
      9. coredump_dir /var/spool/squid
      10. EOF
    2. Create a Kubernetes ConfigMap to hold the configuration of the proxy:

      1. $ kubectl create configmap proxy-configmap -n external --from-file=squid.conf=./proxy.conf
    3. Deploy a container with Squid:

      1. $ kubectl apply -f - <<EOF
      2. apiVersion: apps/v1
      3. kind: Deployment
      4. metadata:
      5. name: squid
      6. namespace: external
      7. replicas: 1
      8. selector:
      9. matchLabels:
      10. app: squid
      11. metadata:
      12. labels:
      13. app: squid
      14. spec:
      15. volumes:
      16. - name: proxy-config
      17. configMap:
      18. name: proxy-configmap
      19. containers:
      20. - name: squid
      21. image: sameersbn/squid:3.5.27
      22. imagePullPolicy: IfNotPresent
      23. volumeMounts:
      24. - name: proxy-config
      25. mountPath: /etc/squid
      26. readOnly: true
      27. EOF
    4. Deploy the sample in the external namespace to test traffic to the proxy without Istio traffic control.

      Zip

    5. Obtain the IP address of the proxy pod and define the PROXY_IP environment variable to store it:

      1. $ export PROXY_IP="$(kubectl get pod -n external -l app=squid -o jsonpath={.items..podIP})"
    6. Define the PROXY_PORT environment variable to store the port of your proxy. In this case, Squid uses port 3128.

      1. $ export PROXY_PORT=3128
    7. Send a request from the sleep pod in the external namespace to an external service via the proxy:

      1. $ kubectl exec "$(kubectl get pod -n external -l app=sleep -o jsonpath={.items..metadata.name})" -n external -- sh -c "HTTPS_PROXY=$PROXY_IP:$PROXY_PORT curl https://en.wikipedia.org/wiki/Main_Page" | grep -o "<title>.*</title>"
      2. <title>Wikipedia, the free encyclopedia</title>
    8. Check the access log of the proxy for your request:

      1. $ kubectl exec "$(kubectl get pod -n external -l app=squid -o jsonpath={.items..metadata.name})" -n external -- tail /var/log/squid/access.log
      2. 1544160065.248 228 172.30.109.89 TCP_TUNNEL/200 87633 CONNECT en.wikipedia.org:443 - HIER_DIRECT/91.198.174.192 -

    So far, you completed the following tasks without Istio:

    • You deployed the HTTPS proxy.
    • You used curl to access the wikipedia.org external service through the proxy.

    Next, you must configure the traffic from the Istio-enabled pods to use the HTTPS proxy.

      1. kind: ServiceEntry
      2. metadata:
      3. name: proxy
      4. spec:
      5. hosts:
      6. - my-company-proxy.com # ignored
      7. addresses:
      8. - $PROXY_IP/32
      9. ports:
      10. - number: $PROXY_PORT
      11. name: tcp
      12. protocol: TCP
      13. location: MESH_EXTERNAL
      14. EOF
    1. Send a request from the sleep pod in the default namespace. Because the sleep pod has a sidecar, Istio controls its traffic.

      1. $ kubectl exec "$SOURCE_POD" -c sleep -- sh -c "HTTPS_PROXY=$PROXY_IP:$PROXY_PORT curl https://en.wikipedia.org/wiki/Main_Page" | grep -o "<title>.*</title>"
      2. <title>Wikipedia, the free encyclopedia</title>
    2. Check the Istio sidecar proxy’s logs for your request:

    3. Check the access log of the proxy for your request:

      1. $ kubectl exec "$(kubectl get pod -n external -l app=squid -o jsonpath={.items..metadata.name})" -n external -- tail /var/log/squid/access.log
      2. 1544160065.248 228 172.30.109.89 TCP_TUNNEL/200 87633 CONNECT en.wikipedia.org:443 - HIER_DIRECT/91.198.174.192 -

    In this example, you took the following steps:

    1. Deployed an HTTPS proxy to simulate an external proxy.
    2. Created a TCP service entry to enable Istio-controlled traffic to the external proxy.

    Note that you must not create service entries for the external services you access through the external proxy, like wikipedia.org. This is because from Istio’s point of view the requests are sent to the external proxy only; Istio is not aware of the fact that the external proxy forwards the requests further.

    1. Shutdown the service:

      Zip

      1. $ kubectl delete -f @samples/sleep/sleep.yaml@
    2. Shutdown the service in the external namespace:

      Zip

      1. $ kubectl delete -f @samples/sleep/sleep.yaml@ -n external
    3. Shutdown the Squid proxy, remove the ConfigMap and the configuration file:

      1. $ kubectl delete -n external deployment squid
      2. $ kubectl delete -n external configmap proxy-configmap
      3. $ rm ./proxy.conf
    4. Delete the external namespace:

      1. $ kubectl delete namespace external