Egress

Allowing access to the Internet and out-of-mesh services (Egress)

This document describes the steps required to enable access to the Internet and services external to the service mesh, referred to as Egress traffic.

OSM redirects all outbound traffic from a pod within the mesh to the pod’s sidecar proxy. Outbound traffic can be classified into two categories:

  1. Traffic to services within the mesh cluster, referred to as in-mesh traffic
  2. Traffic to services external to the mesh cluster, referred to as egress traffic

While in-mesh traffic is routed based on L7 traffic policies, egress traffic is routed differently and is not subject to in-mesh traffic policies. OSM supports access to external services as a passthrough without subjecting such traffic to filtering policies.

Configuring Egress

There are two mechanisms to configure Egress:

  1. Using the Egress policy API: to provide fine grained access control over external traffic
  2. Using the mesh-wide global egress passthrough setting: the setting is toggled on or off and affects all pods in the mesh, enabling which allows traffic destined to destinations outside the mesh to egress the pod.

1. Configuring Egress policies

OSM supports configuring fine grained policies for traffic destined to external endpoints using its Egress policy API. To use this feature, enable it if not enabled:

  1. # Replace osm-system with the namespace where OSM is installed
  2. kubectl patch meshconfig osm-mesh-config -n osm-system -p '{"spec":{"featureFlags":{"enableEgressPolicy":true}}}' --type=merge

Refer to the Egress policy demo and API documentation on how to configure policies for routing egress traffic for various protocols.

2. Configuring mesh-wide Egress passthrough

Enabling mesh-wide Egress passthrough to external destinations

Egress can be enabled mesh-wide during OSM install or post install. When egress is enabled mesh-wide, outbound traffic from pods are allowed to egress the pod as long as the traffic does not match in-mesh traffic policies that otherwise deny the traffic.

  1. During OSM install (default osm.enableEgress=false):

    1. osm install --set osm.enableEgress=true
  2. After OSM has been installed:

    osm-controller retrieves the egress configuration from the osm-mesh-config MeshConfig custom resource in the osm mesh control plane namespace (osm-system by default). Use kubectl patch to set enableEgress to true in the osm-mesh-config resource.

    1. # Replace osm-system with the namespace where OSM is installed
    2. kubectl patch meshconfig osm-mesh-config -n osm-system -p '{"spec":{"traffic":{"enableEgress":true}}}' --type=merge

Disabling mesh-wide Egress passthrough to external destinations

Similar to enabling egress, mesh-wide egress can be disabled during OSM install or post install.

  1. During OSM install:

    1. osm install --set osm.enableEgress=false
  2. After OSM has been installed: Use kubectl patch to set enableEgress to false in the osm-mesh-config resource.

    1. # Replace osm-system with the namespace where OSM is installed
    2. kubectl patch meshconfig osm-mesh-config -n osm-system -p '{"spec":{"traffic":{"enableEgress":false}}}' --type=merge

With egress disabled, traffic from pods within the mesh will not be able to access external services outside the cluster.

How it works

When egress is enabled mesh-wide, OSM controller programs every Envoy proxy sidecar in the mesh with a wildcard rule that matches outbound destinations that do not correspond to in-mesh services. The wildcard rule that matches such external traffic simply proxies the traffic as is to its original destination without subjecting them to L4 or L7 traffic policies.

OSM supports egress for traffic that uses TCP as the underlying transport. This includes raw TCP traffic, HTTP, HTTPS, gRPC etc.

Since mesh-wide egress is a global setting and operates as a passthrough to unknown destinations, fine grained access control (such as applying TCP or HTTP routing policies) over egress traffic is not possible.

Refer to the Egress passthrough demo to learn more.

Envoy configurations

When egress is globally enabled in the mesh, OSM controller programs each Envoy proxy sidecar to match external or unknown destinations using a default filter chain on the outbound listener configuration. The default filter chain is named outbound-egress-filter-chain as seen in the below configuration snippet. Any traffic that matches the default egress filter chain on the outbound listener is proxied to its original destination via the passthrough-outbound cluster.

  1. {
  2. "name": "outbound-listener",
  3. "active_state": {
  4. "version_info": "7",
  5. "listener": {
  6. "@type": "type.googleapis.com/envoy.config.listener.v3.Listener",
  7. "name": "outbound-listener",
  8. "address": {
  9. "socket_address": {
  10. "address": "0.0.0.0",
  11. "port_value": 15001
  12. }
  13. },
  14. "listener_filters": [
  15. {
  16. "name": "envoy.filters.listener.original_dst"
  17. }
  18. ],
  19. "traffic_direction": "OUTBOUND",
  20. "default_filter_chain": {
  21. "filters": [
  22. {
  23. "name": "envoy.filters.network.tcp_proxy",
  24. "typed_config": {
  25. "@type": "type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy",
  26. "stat_prefix": "passthrough-outbound",
  27. "cluster": "passthrough-outbound"
  28. }
  29. }
  30. ],
  31. "name": "outbound-egress-filter-chain"
  32. }
  33. },
  34. "last_updated": "2021-03-16T22:26:46.676Z"
  35. }
  36. }