Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
    • View All Blogs
  1. Home
  2. Blog
  3. Engineering
  4. Downstream and Upstream Mutual TLS With an API Gateway
Engineering
January 20, 2022
6 min read

Downstream and Upstream Mutual TLS With an API Gateway

Sven Walther
Topics
API GatewayAPI Security
Share on Social

More on this topic

eBooks

Becoming a Secure API-First Company

eBooks

API Infrastructure: ESB versus API Gateway

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo

Like many developers and operations professionals, you may have had complicated experiences with security and certificates (encryption of the connection and authentication). Maybe so much so that you try to avoid working on them whenever possible.

If you're looking for a simpler way, Kong may be the answer. As with everything with Kong, the idea is to make things as lightweight as possible, including the complexity of setting up and maintaining certificate-based security.

For more on this API security, check out our "Security in a Multi-Cloud World" eBook

mTLS and API Gateway Use Cases

One of our global customers in the banking industry recently had a mature certificate infrastructure that needed adoption from internal and governmental regulations. Based on their previous experience with legacy gateways, they were afraid of the complexity of integrating the gateway into their certificate management system and making sure updates are propagated automatically to the gateway cluster. In their previous solution, this was a manual task. With the below Kong mTLS use cases, this was quick and easy.

When thinking about certificates in an API gateway context, you might immediately think about these two use cases:

  1. The gateway should present a certificate to the client.
  2. The gateway should authenticate a user/grant access based on the client's mutual TLS (mTLS).

But there are two more use cases you may want to consider:

  1. Kong presents the certificate to the backend (upstream).
  2. Kong sends the trust to the upstream (which certificate/s we allow the backend to present).

mtls api gateway solution

#1: Certificate Presented by Kong to the Client

Let's start with the certificate Kong serves to the client (the one you would see when opening the proxy in the browser).

The Default Certificate

When someone accesses a route exposed using Kong Gateway, the presented certificate by Kong should match the entered hostname (for example, proxy.example.com) so the client can trust that Kong established the connection.

The default certificate presented by Kong after installation is a self-signed certificate. If you want to change this default, copy your desired certificate and key on the machine and then set ssl_cert and ssl_cert_key in your /etc/kong/kong.conf.

Example:

Certificate Per Route

But what if Kong is listening on multiple different hostnames/FQDN? In this case, we need to present different certificates depending on the route. Examples might be different brandings (like api.myshoesbrand.com and api.myshirtsbrand.com) or also very common internal vs. external phasing routes (like api.interal.lan and api.mybrand.com).

When looking at the route object, we notice the hosts parameter that we can use to limit the hosts being listened on and the snis parameter (SNI stands for "server name indication“).

Example on how to create a route for a specific hostname:

http -f admin.kong.internal.lan/services/myservice/routes name=myRoute hosts=api.internal.lan

But how do we define an SNI and which certificates it shall use? Well, you might have guessed it already. There is an API for that: SNI API endpoint.

Now that we attached an SNI to a route, how do we add the certificate to the SNI? There's an API to upload a certificate.

The actual order is the exact opposite of how we just went through it:

  1. Upload the certificate (I do expect you have created it already and have put the files into the current folder)
    http -f admin.kong.internal.lan/certificates cert=@myCert.crt key=@myCert.key tags=myCert
  2. Create an SNI and link to the uploaded certificate (the above command created the id)
    http -f admin.kong.internal.lan/snis name=api.interal.lan certificate.id=the-certificate-id-you-got-from-above-upload
  3. Create a route linking to the SNI (the above command created the id)
    http -f admin.kong.internal.lan/services/myservice/routes name=myInternalRoute hosts=api.internal.lan snis=the-sni-id-you-got-from-above-upload

Let's Encrypt

If you want to automate the whole process using Let's Encrypt, look at the ACME plugin that integrates Kong with Let's Encrypt to create and auto-update certificates. We won't cover the details of this, as the Let's Encrypt setup is out of scope for this blog post.

Technical Guide: Secure Your Web, Mobile Applications and APIs using the Kong Gateway

#2: mTLS for Clients

Note: While all the other documentation here is true for both Kong and Kong Enterprise, mTLS is an enterprise-only plugin.

Authenticating consumers based on certificates is a prevalent mechanism, especially for (but not limited to) financial users of Kong. Each client gets its own certificate to present on every API call to prove its identity.

Authentication

The mTLS plugin has one parameter called ca_certificates. As the name already tells us, we need to specify one or multiple CAs, which we'll use as the trusted source. Only incoming certificates that use those CAs will be trusted.

And similar to the above, we need to upload those CAs in advance using the ca_certificates API endpoint.

Uploading a CA to Kong is achieved with:

When we have uploaded the certificate, we can now reference it when configuring the mTLS-auth plugin, for example:

Authorization

Now that we authenticated the incoming certificate, how do we make sure not every certificate issued by the CA is allowed to make the call?

For this, the mTLS plugin provides two parameters:

  1. By default, the parameter skip_consumer_lookup is set to false, so there must be a matching consumer in Kong. If no consumer is found, the call gets denied. We can do all the typical consumer-based steps if we find a consumer, even adding the consumer to one or multiple groups using the ACL plugin.
  2. Depending on the contents of your certificate, it already might contain group membership information (see parameter authenticated_group_by). If so, we can directly use those extracted groups with the ACL plugin even without consumer matching in place.

#3: Certificate Presented by Kong to the Upstream

The trust between the gateway and the backend system can be secured using certificates. This time, Kong presents a certificate to the upstream to prove its identity. This use case is about the backend validating that an accepted incoming call came from Kong Gateway and not another intermediary.

The Default Certificate

Kong presents a self-signed certificate (the default) after installation to the upstream. If you want to change this default:

  1. Copy your desired certificate and key to the machine.
  2. Enable client_ssl.
  3. Set client_ssl_cert and client_ssl_cert_key in your /etc/kong/kong.conf.

Example:

Certificate Per Service

Sometimes we need to present different certificates to different upstreams to override the default certificate on a per-service level.

We can use the service object client_certificate parameter to specify the presented certificate.

As discussed above, check out the API to upload a certificate.

  1. Upload the certificate (I do expect you have created it already and have put the files into the current folder)
    http -f admin.kong.internal.lan/certificates cert=@myCert.crt key=@myCert.key tags=myCert

Attach the certificate to all calls for a specific service (the id got returned from the previous call)
http -f admin.kong.internal.lan/services/my_sensitive_backend url=https://sensitive.internal.lan client_certificate.id=the_id_from_previous_upload

#4: Trusting the Upstream's Certificate

We can limit the trusted certificates Kong expects from the upstreams by changing the lua_ssl_trusted_certificate. This is used when Kong Gateway is sure that the connected backend is connected and there's no service in the middle. We're achieving two-way mutual trust in combination with the above #3.

Example:

Conclusion

Certificates can play a vital role in the trusted connections to your clients and your backend systems. Using them, you can achieve both the encryption of the traffic on the transport level and create (mutual) trust between the connected systems.

Certificate configurations can often be very complex. Handling all of this within Kong keeps it simple. It can be integrated into existing certificate management systems to automate all the configurations.

Try out these examples yourself by getting a Kong installation. If you have any questions, do not hesitate to contact us.

Topics
API GatewayAPI Security
Share on Social
Sven Walther

Recommended posts

Unlocking API Analytics for Product Managers

Kong Logo
EngineeringSeptember 9, 2025

Meet Emily. She’s an API product manager at ACME, Inc., an ecommerce company that runs on dozens of APIs. One morning, her team lead asks a simple question: “Who’s our top API consumer, and which of your APIs are causing the most issues right now?”

Christian Heidenreich

How to Build a Multi-LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 31, 2025

In the last two parts of this series, we discussed How to Strengthen a ReAct AI Agent with Kong AI Gateway and How to Build a Single-LLM AI Agent with Kong AI Gateway and LangGraph . In this third and final part, we're going to evolve the AI Agen

Claudio Acquaviva

How to Build a Single LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 24, 2025

In my previous post, we discussed how we can implement a basic AI Agent with Kong AI Gateway. In part two of this series, we're going to review LangGraph fundamentals, rewrite the AI Agent and explore how Kong AI Gateway can be used to protect an LLM

Claudio Acquaviva

How to Strengthen a ReAct AI Agent with Kong AI Gateway

Kong Logo
EngineeringJuly 15, 2025

This is part one of a series exploring how Kong AI Gateway can be used in an AI Agent development with LangGraph. The series comprises three parts: Basic ReAct AI Agent with Kong AI Gateway Single LLM ReAct AI Agent with Kong AI Gateway and LangGr

Claudio Acquaviva

Build Your Own Internal RAG Agent with Kong AI Gateway

Kong Logo
EngineeringJuly 9, 2025

What Is RAG, and Why Should You Use It? RAG (Retrieval-Augmented Generation) is not a new concept in AI, and unsurprisingly, when talking to companies, everyone seems to have their own interpretation of how to implement it. So, let’s start with a r

Antoine Jacquemin

AI Gateway Benchmark: Kong AI Gateway, Portkey, and LiteLLM

Kong Logo
EngineeringJuly 7, 2025

In February 2024, Kong became the first API platform to launch a dedicated AI gateway, designed to bring production-grade performance, observability, and policy enforcement to GenAI workloads. At its core, Kong’s AI Gateway provides a universal API

Claudio Acquaviva

Scalable Architectures with Vue Micro Frontends: A Developer-Centric Approach

Kong Logo
EngineeringJanuary 9, 2024

In this article, which is based on my talk at VueConf Toronto 2023, we'll explore how to harness the power of Vue.js and micro frontends to create scalable, modular architectures that prioritize the developer experience. We'll unveil practical strate

Adam DeHaven

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
Powering the API world

Increase developer productivity, security, and performance at scale with the unified platform for API management, AI gateways, service mesh, and ingress controller.

Sign up for Kong newsletter

Platform
Kong KonnectKong GatewayKong AI GatewayKong InsomniaDeveloper PortalGateway ManagerCloud GatewayGet a Demo
Explore More
Open Banking API SolutionsAPI Governance SolutionsIstio API Gateway IntegrationKubernetes API ManagementAPI Gateway: Build vs BuyKong vs PostmanKong vs MuleSoftKong vs Apigee
Documentation
Kong Konnect DocsKong Gateway DocsKong Mesh DocsKong AI GatewayKong Insomnia DocsKong Plugin Hub
Open Source
Kong GatewayKumaInsomniaKong Community
Company
About KongCustomersCareersPressEventsContactPricing
  • Terms•
  • Privacy•
  • Trust and Compliance•
  • © Kong Inc. 2025