Set up a mutual TLS Gateway
This tutorial shows how to set up a mutual TLS Gateway and configure authentication based on certificate details.
Prerequisites
Before you start, Set up a custom-domain
and prepare a certificate to expose a workload.
Steps
Export the following values as environment variables:
Click to copyexport DOMAIN_TO_EXPOSE_WORKLOADS={DOMAIN_NAME}NOTE:
DOMAIN_NAME
is the domain that you own, for example, api.mydomain.comCreate a Namespace and export its value as an environment variable. Run:
NOTE: Skip this step if you already have a Namespace
Click to copyexport NAMESPACE={NAMESPACE_NAME}kubectl create ns $NAMESPACEkubectl label namespace $NAMESPACE istio-injection=enabled --overwriteExport Gateway name, TLS secret name, and client root Certificate Authority (CA) crt file path:
Click to copyexport MTLS_GATEWAY_NAME=mtls-gatewayexport TLS_SECRET={TLS_SECRET_NAME} # The name of the TLS Secret that was created during the setup of the custom domain, for example, httpbin-tls-credentialsexport CLIENT_ROOT_CA_CRT_FILE={CLIENT_ROOT_CA_CRT_FILE}Create mTLS Gateway (mode: MUTUAL):
Click to copycat <<EOF | kubectl apply -f ----apiVersion: networking.istio.io/v1beta1kind: Gatewaymetadata:name: ${MTLS_GATEWAY_NAME}namespace: ${NAMESPACE}spec:selector:istio: ingressgatewayapp: istio-ingressgatewayservers:- port:number: 443name: httpsprotocol: HTTPStls:mode: MUTUALcredentialName: ${TLS_SECRET}minProtocolVersion: TLSV1_2cipherSuites:- ECDHE-RSA-CHACHA20-POLY1305- ECDHE-RSA-AES256-GCM-SHA384- ECDHE-RSA-AES256-SHA- ECDHE-RSA-AES128-GCM-SHA256- ECDHE-RSA-AES128-SHAhosts:- '*.${DOMAIN_TO_EXPOSE_WORKLOADS}'- port:number: 80name: httpprotocol: HTTPtls:httpsRedirect: truehosts:- '*.${DOMAIN_TO_EXPOSE_WORKLOADS}'EOFAdd client root CA to CA cert bundle secret for mTLS Gateway. Export the following value as an environment variable and run the command:
Click to copy# Add CA Cert to kyma-mtls-gatewayexport CLIENT_ROOT_CA_CRT_ENCODED=$(cat ${CLIENT_ROOT_CA_CRT_FILE}| base64)cat <<EOF | kubectl apply -f ----apiVersion: v1kind: Secretmetadata:name: ${TLS_SECRET}-cacertnamespace: istio-systemtype: Opaquedata:cacert: ${CLIENT_ROOT_CA_CRT_ENCODED}EOF