This guide demonstrates a client within the service mesh accessing destinations external to the mesh using OSM’s Egress policy API.
Prerequisites
- Kubernetes cluster running Kubernetes v1.22.9 or greater.
- Have OSM installed.
- Have
kubectl
available to interact with the API server. - Have
osm
CLI available for managing the service mesh.
Demo
-
Enable egress policy if not enabled by disabling global mesh-wide egress to unknown destinations:
-
Deploy the
curl
client into thecurl
namespace after enrolling its namespace to the mesh.Confirm the
curl
client pod is up and running.
HTTP Egress
-
Confirm the
curl
client is unable make the HTTP requesthttp://httpbin.org:80/get
to thehttpbin.org
website on port80
. -
Apply an Egress policy to allow the
curl
client’s ServiceAccount to access thehttpbin.org
website on port80
serving thehttp
protocol. -
Confirm the
curl
client is able to make successful HTTP requests tohttp://httpbin.org:80/get
. -
Confirm the
curl
client can no longer make successful HTTP requests tohttp://httpbin.org:80/get
when the above policy is removed.
HTTPS Egress
Since HTTPS traffic is encrypted with TLS, OSM routes HTTPS based traffic by proxying it to its original destination as a TCP stream. The Server Name Indication (SNI) indicated by the HTTPS client application in the TLS handshake is matched against hosts specified in the Egress policy.
-
Confirm the
curl
client is unable make the HTTPS requesthttps://httpbin.org:443/get
to thehttpbin.org
website on port443
. -
Apply an Egress policy to allow the
curl
client’s ServiceAccount to access thehttpbin.org
website on port443
serving thehttps
protocol. -
Confirm the
curl
client is able to make successful HTTPS requests tohttps://httpbin.org:443/get
. -
Confirm the
curl
client can no longer make successful HTTPS requests tohttps://httpbin.org:443/get
when the above policy is removed.
TCP Egress
TCP based Egress traffic is matched against the destination port and IP address ranges specified in an egress policy. If an IP address range is not specified, traffic will be matched only based on the destination port.
-
Confirm the
curl
client is unable make the HTTPS requesthttps://openservicemesh.io:443
to theopenservicemesh.io
website on port443
. Since HTTPS uses TCP as the underlying transport protocol, TCP based routing should implicitly enable access to any HTTP(s) host on the specified port. -
Apply an Egress policy to allow the
curl
client’s ServiceAccount to access the any destination on port443
serving thetcp
protocol.Note: For
server-first
protocols such asMySQL
,PostgreSQL
, etc., where the server initiates the first bytes of data between the client and server, the protocol must be set totcp-server-first
to indicate to OSM to not perform protocol detection on the port. Protocol detection relies on inspecting the initial bytes of a connection, which is incompatible withserver-first
protocols. When the port’s protocol is set totcp-server-first
, protocol detection is skipped for that port number. It is also important to note thatserver-first
port numbers must not be used for other application ports that require protocol detection to performed, which means the port numbers used forserver-first
protocols must not be used with other protocols such asHTTP
andTCP
that require protocol detection to be performed. -
Confirm the
curl
client is able to make successful HTTPS requests tohttps://openservicemesh.io:443
. -
Confirm the
curl
client can no longer make successful HTTPS requests tohttps://openservicemesh.io:443
when the above policy is removed.
HTTP Egress with SMI route matches
HTTP Egress policies can specify SMI HTTPRouteGroup matches for fine grained traffic control based on HTTP methods, headers and paths.
-
Confirm the
curl
client is unable make HTTP requests tohttp://httpbin.org:80/get
andhttp://httpbin.org:80/status/200
to thehttpbin.org
website on port80
. -
Apply an SMI HTTPRouteGroup resource to allow access to the HTTP path
/get
and an Egress policy to access thehttpbin.org
on website port80
that matches on the SMI HTTPRouteGroup. -
Confirm the
curl
client is able to make successful HTTP requests tohttp://httpbin.org:80/get
. -
Confirm the
curl
client is unable to make successful HTTP requests tohttp://httpbin.org:80/status/200
. -
Update the matching SMI HTTPRouteGroup resource to allow requests to HTTP paths matching the regex
/status.*
. -
Confirm the
curl
client can now make successful HTTP requests tohttp://httpbin.org:80/status/200
.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.