Mutual TLS (mTLS)
Set up an mTLS listener on the gateway.
About this guide
In this guide, you learn how to set up an mTLS Gateway. Before the client application and the Gateway establish a connection, both parties must exchange certificates to verify their identities. After a TLS connection is established, the TLS connection is terminated at the Gateway and the unencrypted HTTP traffic is forwarded to the backend destination.
Before you begin
Follow the Get started guide to install Gloo Gateway and deploy the httpbin sample app.
Make sure that you have the OpenSSL version of openssl, not LibreSSL. The openssl version must be at least 1.1.
- Check your
openssl
version. If you see LibreSSL in the output, continue to the next step. - Install the OpenSSL version (not LibreSSL). For example, you might use Homebrew.
- Review the output of the OpenSSL installation for the path of the binary file. You can choose to export the binary to your path, or call the entire path whenever the following steps use an
openssl
command.- For example,
openssl
might be installed along the following path:/usr/local/opt/openssl@3/bin/
- To run commands, you can append the path so that your terminal uses this installed version of OpenSSL, and not the default LibreSSL.
/usr/local/opt/openssl@3/bin/openssl req -new -newkey rsa:4096 -x509 -sha256 -days 3650...
- For example,
- Check your
Decide whether to set up an HTTP listener inline on the Gateway resource or as a separate ListenerSet resource. Note that ListenerSets are an experimental feature in the upstream Kubernetes Gateway API project, and subject to change. For more information, see the Listener overview.
Create self-signed TLS certificates
Create self-signed TLS certificates that you use for the mutual TLS connection between your client application (curl
) and the gateway proxy.
Self-signed certificates are used for demonstration purposes. Do not use self-signed certificates in production environments. Instead, use certificates that are issued from a trust Certificate Authority.
Create a root certificate for the
example.com
domain. You use this certificate to sign the certificate for your client and gateway later.Create a gateway certificate that is signed by the root CA certificate that you created in the previous step.
Create a Kubernetes secret to store your gateway TLS certificate. You create the secret in the same cluster and namespace that the gateway is deployed to. By including a
rootca
certificate, Gloo Gateway is automatically configured for mutual TLS with the downstream application.You can also runglooctl create secret tls --name https --certchain example_certs/gateway.crt --privatekey example_certs/gateway.key --rootca example_certs/example.com.crt
to create the secret with theglooctl
command line.Create a client certificate and private key. You use these credentials later when sending a request to the gateway proxy. The client certificate is signed with the same root CA certificate that you used for the gateway proxy.
Set up an mTLS listener
Create a Gateway that is configured with the TLS certificates that you set up earlier.
Create an HTTPRoute for the httpbin app and add it to the HTTPS gateway that you created.
Verify that the HTTPRoute is applied successfully.
Example output: Notice in the
status
section that the parentRef is either the Gateway or the ListenerSet, depending on how you attached the HTTPRoute.Verify that the listener now has a route attached.
Get the external address of the gateway and save it in an environment variable. Note that it might take a few seconds for the gateway address to become available.
Send a request to the httpbin app. Verify that you see the TLS handshake and that you get back a 200 HTTP response code.
Example output:
Cleanup
Remove the routing resources for the HTTPS route, including the Kubernetes secret that holds the TLS certificate and key.
Remove the
example_certs
directory that stores your TLS credentials.