Egress TLS Origination

    Consider a legacy application that performs HTTP calls to external sites. Suppose the organization that operates theapplication receives a new requirement which states that all the external traffic must be encrypted. With Istio,this requirement can be achieved just by configuration, without changing any code in the application.The application can send unencrypted HTTP requests and Istio will then encrypt them for the application.

    Another benefit of sending unencrypted HTTP requests from the source, and letting Istio perform the TLS upgrade,is that Istio can produce better telemetry and provide more routing control for requests that are not encrypted.

    Before you begin

    • Setup Istio by following the instructions in the .

    • Start the sleep sample which will be used as a test source for external calls.

    If you have enabled , deploy the sleep application:

    Zip

    Otherwise, you have to manually inject the sidecar before deploying the sleep application:

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

    Note that any pod that you can exec and curl from will do for the procedures below.

    • Create a shell variable to hold the name of the source pod for sending requests to external services.If you used the sleep sample, run:
    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})

    First start by configuring access to an external service, edition.cnn.com,using the same technique shown in the task.This time, however, use a single ServiceEntry to enable both HTTP and HTTPS access to the service.

    • Create a ServiceEntry and VirtualService to enable access to edition.cnn.com:
    • Make a request to the external HTTP service:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
    2. HTTP/1.1 301 Moved Permanently
    3. ...
    4. location: https://edition.cnn.com/politics
    5. ...
    6. HTTP/1.1 200 OK
    7. Content-Type: text/html; charset=utf-8
    8. ...
    9. Content-Length: 151654
    10. ...

    Notice the -L flag of curl which instructs curl to follow redirects.In this case, the server returned a redirect response (301 Moved Permanently)for the HTTP request to .The redirect response instructs the client to send an additional request, this time using HTTPS, to https://edition.cnn.com/politics.For the second request, the server returned the requested content and a 200 OK status code.

    Although the curl command handled the redirection transparently, there are two issues here.The first issue is the redundant request, which doubles the latency of fetching the content of .The second issue is that the path of the URL, politics in this case, is sent in clear text.If there is an attacker who sniffs the communication between your application and edition.cnn.com,the attacker would know which specific topics of edition.cnn.com the application fetched.For privacy reasons, you might want to prevent such disclosure.

    Both of these issues can be resolved by configuring Istio to perform TLS origination.

    TLS origination for egress traffic

    • Redefine your ServiceEntry and from the previous section to rewrite the HTTP request portand add a DestinationRule to perform TLS origination.
    1. apiVersion: networking.istio.io/v1alpha3
    2. kind: ServiceEntry
    3. metadata:
    4. name: edition-cnn-com
    5. spec:
    6. hosts:
    7. - edition.cnn.com
    8. ports:
    9. - number: 80
    10. name: http-port
    11. protocol: HTTP
    12. - number: 443
    13. name: https-port-for-tls-origination
    14. protocol: HTTPS
    15. resolution: DNS
    16. ---
    17. apiVersion: networking.istio.io/v1alpha3
    18. kind: VirtualService
    19. metadata:
    20. name: edition-cnn-com
    21. spec:
    22. hosts:
    23. - edition.cnn.com
    24. http:
    25. - match:
    26. - port: 80
    27. host: edition.cnn.com
    28. port:
    29. number: 443
    30. ---
    31. apiVersion: networking.istio.io/v1alpha3
    32. kind: DestinationRule
    33. metadata:
    34. name: edition-cnn-com
    35. spec:
    36. host: edition.cnn.com
    37. trafficPolicy:
    38. loadBalancer:
    39. simple: ROUND_ROBIN
    40. portLevelSettings:
    41. - port:
    42. number: 443
    43. tls:
    44. mode: SIMPLE # initiates HTTPS when accessing edition.cnn.com
    45. EOF

    As you can see, the VirtualService redirects HTTP requests on port 80 to port 443 where the correspondingDestinationRule then performs the TLS origination.Notice that unlike the ServiceEntry in the previous section, this time the protocol on port 443 is HTTP, instead of HTTPS.This is because clients will only send HTTP requests and Istio will upgrade the connection to HTTPS.

    • Send an HTTP request to , as in the previous section:

    This time you receive 200 OK as the first and the only response. Istio performed TLS origination for curl sothe original HTTP request was forwarded to edition.cnn.com as HTTPS. The server returned the content directly,without the need for redirection. You eliminated the double round trip between the client and the server, and therequest left the mesh encrypted, without disclosing the fact that your application fetched the politics sectionof edition.cnn.com.

    Note that you used the same command as in the previous section. For applications that access external servicesprogrammatically, the code does not need to be changed. You get the benefits of TLS origination by configuring Istio,without changing a line of code.

    Because the traffic between the application pod and the sidecar proxy on the local host is still unencrypted,an attacker that is able to penetrate the node of your application would still be able to see the unencryptedcommunication on the local network of the node. In some environments a strict security requirementmight state that all the traffic must be encrypted, even on the local network of the nodes.With such a strict requirement, applications should use HTTPS (TLS) only. The TLS origination described in thisexample would not be sufficient.

    Also note that even with HTTPS originated by the application, an attacker could know that requests to edition.cnn.comare being sent by inspecting Server Name Indication (SNI).The SNI field is sent unencrypted during the TLS handshake. Using HTTPS prevents the attackers from knowing specifictopics and articles but does not prevent an attackers from learning that edition.cnn.com is accessed.

    Cleanup

    • Remove the Istio configuration items you created:
    1. $ kubectl delete serviceentry edition-cnn-com
    2. $ kubectl delete virtualservice edition-cnn-com
    • Shutdown the sleep service:

      Secure Control of Egress Traffic in Istio, part 3

      Use Istio Egress Traffic Control to prevent attacks involving egress traffic.

      Secure Control of Egress Traffic in Istio, part 1

      Attacks involving egress traffic and requirements for egress traffic control.

      Verifies the performance impact of adding an egress gateway.

      Consuming External MongoDB Services

      Describes a simple scenario based on Istio's Bookinfo example.

      Describes how to configure Istio for monitoring and access policies of HTTP egress traffic.