Ingress Gateway without TLS Termination
The Securing Gateways with HTTPS task describes how to configure HTTPS ingress access to an HTTP service. This example describes how to configure HTTPS ingress access to an HTTPS service, i.e., configure an ingress gateway to perform SNI passthrough, instead of TLS termination on incoming requests.
The example HTTPS service used for this task is a simple NGINX server. In the following steps you first deploy the NGINX service in your Kubernetes cluster. Then you configure a gateway to provide ingress access to the service via host nginx.example.com.
Istio includes beta support for the Kubernetes Gateway API and intends to make it the default API for traffic management in the future. The following instructions allow you to choose to use either the Gateway API or the Istio configuration API when configuring traffic management in the mesh. Follow instructions under either the Gateway API or Istio classic tab, according to your preference.
Note that the Kubernetes Gateway API CRDs do not come installed by default on most Kubernetes clusters, so make sure they are installed before using the Gateway API:
$ kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \{ kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v0.6.2" | kubectl apply -f -; }
This document uses experimental features of the Kubernetes Gateway API. Make sure to install the experimental CRDs before using the Gateway API:
$ kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=v0.6.2" | kubectl apply -f -
Before you begin
Setup Istio by following the instructions in the Installation guide.
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 openssl:
Create a root certificate and private key to sign the certificate for your services:
$ mkdir example_certs$ openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -subj '/O=example Inc./CN=example.com' -keyout example_certs/example.com.key -out example_certs/example.com.crt
Create a certificate and a private key for
nginx.example.com:$ openssl req -out example_certs/nginx.example.com.csr -newkey rsa:2048 -nodes -keyout example_certs/nginx.example.com.key -subj "/CN=nginx.example.com/O=some organization"$ openssl x509 -req -sha256 -days 365 -CA example_certs/example.com.crt -CAkey example_certs/example.com.key -set_serial 0 -in example_certs/nginx.example.com.csr -out example_certs/nginx.example.com.crt
Deploy an NGINX server
Create a Kubernetes Secret to hold the server’s certificate.
$ kubectl create secret tls nginx-server-certs \--key example_certs/nginx.example.com.key \--cert example_certs/nginx.example.com.crt
Create a configuration file for the NGINX server:
$ cat <<\EOF > ./nginx.confevents {}http {log_format main '$remote_addr - $remote_user [$time_local] $status ''"$request" $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main;error_log /var/log/nginx/error.log;server {listen 443 ssl;root /usr/share/nginx/html;index index.html;server_name nginx.example.com;ssl_certificate /etc/nginx-server-certs/tls.crt;ssl_certificate_key /etc/nginx-server-certs/tls.key;}}EOF
Create a Kubernetes ConfigMap to hold the configuration of the NGINX server:
$ kubectl create configmap nginx-configmap --from-file=nginx.conf=./nginx.conf
Deploy the NGINX server:
$ cat <<EOF | kubectl apply -f -apiVersion: v1kind: Servicemetadata:name: my-nginxlabels:run: my-nginxspec:ports:- port: 443protocol: TCPselector:run: my-nginx---apiVersion: apps/v1kind: Deploymentmetadata:name: my-nginxspec:selector:matchLabels:run: my-nginxreplicas: 1template:metadata:labels:run: my-nginxsidecar.istio.io/inject: "true"spec:containers:- name: my-nginximage: nginxports:- containerPort: 443volumeMounts:- name: nginx-configmountPath: /etc/nginxreadOnly: true- name: nginx-server-certsmountPath: /etc/nginx-server-certsreadOnly: truevolumes:- name: nginx-configconfigMap:name: nginx-configmap- name: nginx-server-certssecret:secretName: nginx-server-certsEOF
To test that the NGINX server was deployed successfully, send a request to the server from its sidecar proxy without checking the server’s certificate (use the
-koption ofcurl). Ensure that the server’s certificate is printed correctly, i.e.,common name (CN)is equal tonginx.example.com.$ kubectl exec "$(kubectl get pod -l run=my-nginx -o jsonpath={.items..metadata.name})" -c istio-proxy -- curl -sS -v -k --resolve nginx.example.com:443:127.0.0.1 https://nginx.example.com...SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384ALPN, server accepted to use http/1.1Server certificate:subject: CN=nginx.example.com; O=some organizationstart date: May 27 14:18:47 2020 GMTexpire date: May 27 14:18:47 2021 GMTissuer: O=example Inc.; CN=example.comSSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.> GET / HTTP/1.1> User-Agent: curl/7.58.0> Host: nginx.example.com...< HTTP/1.1 200 OK< Server: nginx/1.17.10...<!DOCTYPE html><html><head><title>Welcome to nginx!</title>...
Configure an ingress gateway
- Define a
Gatewayexposing port 443 with passthrough TLS mode. This instructs the gateway to pass the ingress traffic “as is”, without terminating TLS:
$ kubectl apply -f - <<EOFapiVersion: networking.istio.io/v1alpha3kind: Gatewaymetadata:name: mygatewayspec:selector:istio: ingressgateway # use istio default ingress gatewayservers:- port:number: 443name: httpsprotocol: HTTPStls:mode: PASSTHROUGHhosts:- nginx.example.comEOF
$ kubectl apply -f - <<EOFapiVersion: gateway.networking.k8s.io/v1beta1kind: Gatewaymetadata:name: mygatewayspec:gatewayClassName: istiolisteners:- name: httpshostname: "nginx.example.com"port: 443protocol: TLStls:mode: PassthroughallowedRoutes:namespaces:from: AllEOF
- Configure routes for traffic entering via the
Gateway:
$ kubectl apply -f - <<EOFapiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: nginxspec:hosts:- nginx.example.comgateways:- mygatewaytls:- match:- port: 443sniHosts:- nginx.example.comroute:- destination:host: my-nginxport:number: 443EOF
$ kubectl apply -f - <<EOFapiVersion: gateway.networking.k8s.io/v1alpha2kind: TLSRoutemetadata:name: nginxspec:parentRefs:- name: mygatewayhostnames:- "nginx.example.com"rules:- backendRefs:- name: my-nginxport: 443EOF
- Determine the ingress IP and port:
Follow the instructions in Determining the ingress IP and ports to set the SECURE_INGRESS_PORT and INGRESS_HOST environment variables.
Use the following commands to set the SECURE_INGRESS_PORT and INGRESS_HOST environment variables:
$ kubectl wait --for=condition=programmed gtw mygateway$ export INGRESS_HOST=$(kubectl get gtw mygateway -o jsonpath='{.status.addresses[0].value}')$ export SECURE_INGRESS_PORT=$(kubectl get gtw mygateway -o jsonpath='{.spec.listeners[?(@.name=="https")].port}')
Access the NGINX service from outside the cluster. Note that the correct certificate is returned by the server and it is successfully verified (SSL certificate verify ok is printed).
$ curl -v --resolve "nginx.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST" --cacert example_certs/example.com.crt "https://nginx.example.com:$SECURE_INGRESS_PORT"Server certificate:subject: CN=nginx.example.com; O=some organizationstart date: Wed, 15 Aug 2018 07:29:07 GMTexpire date: Sun, 25 Aug 2019 07:29:07 GMTissuer: O=example Inc.; CN=example.comSSL certificate verify ok.< HTTP/1.1 200 OK< Server: nginx/1.15.2...<html><head><title>Welcome to nginx!</title>
Cleanup
- Delete the gateway configuration and route:
$ kubectl delete gateway mygateway$ kubectl delete virtualservice nginx
$ kubectl delete gtw mygateway$ kubectl delete tlsroute nginx
Remove the NGINX resources and configuration file:
$ kubectl delete secret nginx-server-certs$ kubectl delete configmap nginx-configmap$ kubectl delete service my-nginx$ kubectl delete deployment my-nginx$ rm ./nginx.conf
Delete the certificates and keys:
$ rm -rf ./example_certs