Secure Gateways
The Control Ingress Traffic task2 describes how to configure an ingress gateway to expose an HTTP service to external traffic. This task shows how to expose a secure HTTPS service using either simple or mutual TLS.
Before you begin
Perform the steps in the Before you begin3. and Determining the ingress IP and ports sections of the Control Ingress Traffic4 task. After performing those steps you should have Istio and the httpbin5 service deployed, and the environment variables
INGRESS_HOST
andSECURE_INGRESS_PORT
set.For macOS users, verify that you use
curl
compiled with the LibreSSL6 library:If the previous command outputs a version of LibreSSL as shown, your
curl
command should work correctly with the instructions in this task. Otherwise, try a different implementation ofcurl
, for example on a Linux machine.
Generate client and server certificates and keys
For this task you can use your favorite tool to generate certificates and keys. The commands below use openssl7
Create a root certificate and private key to sign the certificates for your services:
Create a certificate and a private key for
httpbin.example.com
:
Configure a TLS ingress gateway for a single host
Ensure you have deployed the httpbin5 service from Before you begin3.
Create a secret for the ingress gateway:
Define a gateway with a
servers:
section for port 443, and specify values forcredentialName
to behttpbin-credential
. The values are the same as the secret’s name. The TLS mode should have the value ofSIMPLE
.Configure the gateway’s ingress traffic routes. Define the corresponding virtual service.
Send an HTTPS request to access the
httpbin
service through HTTPS:The
httpbin
service will return the 418 I’m a Teapot8 code.Delete the gateway’s secret and create a new one to change the ingress gateway’s credentials.
Access the
httpbin
service usingcurl
using the new certificate chain:If you try to access
httpbin
with the previous certificate chain, the attempt now fails.
Configure a TLS ingress gateway for multiple hosts
You can configure an ingress gateway for multiple hosts,
httpbin.example.com
and helloworld-v1.example.com
, for example. The ingress gateway
retrieves unique credentials corresponding to a specific credentialName
.
To restore the credentials for
httpbin
, delete its secret and create it again.Start the
helloworld-v1
sampleGenerate a certificate and a private key for
helloworld-v1.example.com
:Create the
helloworld-credential
secret:Define a gateway with two server sections for port 443. Set the value of
credentialName
on each port tohttpbin-credential
andhelloworld-credential
respectively. Set TLS mode toSIMPLE
.Configure the gateway’s traffic routes. Define the corresponding virtual service.
Send an HTTPS request to
helloworld-v1.example.com
:Send an HTTPS request to
httpbin.example.com
and still get a teapot in return:
Configure a mutual TLS ingress gateway
You can extend your gateway’s definition to support
mutual TLS9. Change
the credentials of the ingress gateway by deleting its secret and creating a new one.
The server uses the CA certificate to verify
its clients, and we must use the name cacert
to hold the CA certificate.
Change the gateway’s definition to set the TLS mode to
MUTUAL
.Attempt to send an HTTPS request using the prior approach and see how it fails:
Generate client certificate and private key:
Pass a client certificate and private key to
curl
and resend the request. Pass your client’s certificate with the--cert
flag and your private key with the--key
flag tocurl
.
Istio supports reading a few different Secret formats, to support integration with various tools such as cert-manager10:
- A TLS Secret with keys
tls.key
andtls.crt
, as described above. For mutual TLS, aca.crt
key can be used. - A generic Secret with keys
key
andcert
. For mutual TLS, acacert
key can be used. - A generic Secret with keys
key
andcert
. For mutual TLS, a separate generic Secret named<secret>-cacert
, with acacert
key. For example,httpbin-credential
haskey
andcert
, andhttpbin-credential-cacert
hascacert
.
Troubleshooting
Inspect the values of the
INGRESS_HOST
andSECURE_INGRESS_PORT
environment variables. Make sure they have valid values, according to the output of the following commands:Check the log of the
istio-ingressgateway
controller for error messages:If using macOS, verify you are using
curl
compiled with the LibreSSL6 library, as described in the Before you begin section.Verify that the secrets are successfully created in the
istio-system
namespace:httpbin-credential
andhelloworld-credential
should show in the secrets list.Check the logs to verify that the ingress gateway agent has pushed the key/certificate pair to the ingress gateway.
The log should show that the
httpbin-credential
secret was added. If using mutual TLS, then thehttpbin-credential-cacert
secret should also appear. Verify the log shows that the gateway agent receives SDS requests from the ingress gateway, that the resource’s name ishttpbin-credential
, and that the ingress gateway obtained the key/certificate pair. If using mutual TLS, the log should show key/certificate was sent to the ingress gateway, that the gateway agent received the SDS request with thehttpbin-credential-cacert
resource name, and that the ingress gateway obtained the root certificate.
Cleanup
Delete the gateway configuration, the virtual service definition, and the secrets:
Delete the certificates and keys:
Shutdown the
httpbin
andhelloworld-v1
services: