Introduction
Secure communication is essential in today’s digital landscape. TLS/SSL protocol and Public Key Infrastructure (PKI) play a crucial role in ensuring encrypted and authenticated connections. This document provides a comprehensive walkthrough on configuring TLS/SSL, managing certificates for the Tyk Gateway and Dashboard. In this section, we delve into the following key topics:- Enabling TLS in Tyk components: Learn how to enable and configure TLS/SSL for Tyk Gateway and Dashboard to secure your communication.
- TLS Support in Tyk: Understand the supported TLS versions, cipher suites, their configurations, and best practices for secure communication.
- Configuring Tyk Certificate Storage: Discover how to manage and store certificates for seamless TLS configuration in Tyk. Explore advanced TLS settings for enhanced security.
- Self Signed Certificates: Learn how to configure and use self-signed certificates for secure communication in Tyk.
- Configuring Internal Proxy Setup: Set up internal proxies with TLS to ensure secure communication within your architecture.
Certificates
If you have had to configure an SSL server or SSH access, the following information below should be familiar to you. Let’s start with certificate definition. Here is what Wikipedia says:In cryptography, a public key certificate, also known as a digital certificate or identity certificate, is an electronic document used to prove the ownership of a public key. The certificate includes information about the key, information about the identity of its owner (called the subject), and the digital signature of an entity that has verified the certificate’s contents (called the issuer). If the signature is valid, and the software examining the certificate trusts the issuer, then it can use that key to communicate securely with the certificate’s subject.When it comes to authorization, it is enough for the server that has a public client certificate in its trusted certificate storage to trust it. However, if you need to send a request to the server protected by mutual TLS, or need to configure the TLS server itself, you also need to have a private key, used while generating the certificate, to sign the request. Using Tyk, you have two main certificate use cases:
- Certificates without public keys used for client authorization and authentication
- Certificates with private keys used for upstream access, and server certificates (in other words when we need to sign and encrypt the request or response).
PEM format
Before a certificate can be used by Tyk, it must be encoded into PEM format. If you are using anopenssl
command to generate certificates, it should use PEM by default. A nice bonus of the PEM format is that it allows having multiple entries inside the same file. So in cases where a certificate also requires a private key, you can just concatenate the two files together.
Enable TLS/SSL in Tyk components
TLS protocol is supported by all Tyk components. You can enable TLS in Tyk Gateway and Dashboard by modifying thetyk.conf
and tyk_analytics.conf
files.
For self signed certificates additional consideration has to be taken place, refer to the section below.
Gateway
You’ll need to add the following to your tyk.conf as the minimum to enable TLS for the Gateway:Dashboard
You’ll need to add the following to your tyk_analytics.conf as the minimum to enable TLS for the Dashboard:true
so that your Dashboard URL starts with HTTPS.
If you are using self-signed certs or are in a test environment, you can tell Tyk to ignore validation on certs Mutual TLS support
Testing TLS/SSL Configuration
Restart the servers/containers and they should now be using SSL:MDCB
Mutual TLS configuration in an MDCB environment has specific requirements. An MDCB environment consists of a Control Plane and multiple Data Planes that, using MDCB, sync configuration. The Control Plane and Data Plane deployments usually do not share any secrets; thus a certificate with private keys encoded with secret in the Control Plane will not be accessible to Data Plane gateways. To solve this issue, you need to setsecurity.private_certificate_encoding_secret
in the MDCB configuration file to the same value as specified in your management Gateway configuration file. By knowing the original secret, MDCB will be able to decode private keys, and
send them to client without password. Using a secure connection between Data Plane Gateways and MDCB is required in this case. See MDCB setup page for use_ssl usage.
TLS/SSL Configuration
TLS is configured in thehttp_server_options
section of your Gateway and Dashboard configuration files. This has the following structure, common to both components:
min_version
andmax_version
are optional and allow you to configure the versions of TLS from which Tyk will accept connectionsssl_ciphers
allows you to select the cipher suite that will be used to negotiate connections- you can enter multiple certificates to be used in the encryption that will be applied for different domain names, this enables you to have multiple TLS certs for your Gateways or Dashboard domains if they are providing access to different domains via the same IP
Supported TLS Versions
You need to use the following values for setting the TLSmin_version
and max_version
. The numbers associated with the TLS versions represent protocol version numbers used in the TLS protocol specification. These are standardized numerical values assigned by the Internet Engineering Task Force (IETF) to identify each TLS version during communication.
TLS Version | Value to Use |
---|---|
1.0 (see note) | 769 |
1.1 (see note) | 770 |
1.2 | 771 |
1.3 | 772 |
- minimum TLS version: 1.2
-
maximum TLS version: 1.3
Tyk uses Golang libraries to provide TLS functionality, so the range of TLS versions supported by the Gateway is dependent upon the underlying library. Support for TLS 1.0 and 1.1 was removed in Go 1.22 (which was adopted in Tyk 5.3.6/5.6.0), so these are no longer supported by Tyk.
Supported TLS Cipher Suites
The strength of encryption is determined by the cipher that is negotiated between client & server; each version of the TLS protocol provides a suite of available ciphers. TLS 1.3 protocol does not allow the setting of custom ciphers, and is designed to automatically pick the most secure cipher. When using earlier TLS protocols, you can deliberately choose the ciphers to be used using thehttp_server_options
config option ssl_ciphers
in tyk.conf
and tyk-analytics.conf
. This takes an array of strings as its value. Each string must be one of the allowed cipher suites as defined at https://golang.org/pkg/crypto/tls/#pkg-constants
For example:
Validate Hostname against Common Name
From v2.9.3 you can force the validation of the hostname against the common name, both at the Gateway level via yourtyk.conf
and at the API level.
Set
ssl_force_common_name_check
to true
in your tyk.conf
file.Dynamically setting SSL certificates for custom domains
If you include certificateID or certificate path to an API definitioncertificates
field, Gateway will dynamically load this ceritficate for your custom domain, so you will not need to restart the process. You can do it from the Dashboard UI too, in the custom domain section.
Let say the domain certificate is stored in secret named
my-test-tls
in the same namespace as this ApiDefinition resource httpbin
. You can provide the domain certificate in certificate_secret_names
field. Tyk Operator will help you retrieve the certificate from secret and upload it to Tyk.linenostart=1, hl_lines=["10-11"]}
Certificate Management
Tyk provides two options to manage certificates: plain files or certificate storage with a separate API. All configuration options, which require specifying certificates, support both plain file paths or certificate IDs. You are able to mix them up, and Tyk will automatically distinguish file names from certificate IDs. The Tyk Gateway and Dashboard Admin APIs provide endpoints to create, remove, list, and see information about certificates. For the Gateway, the endpoints are:- Create:
POST /tyk/certs
with PEM body. Returns{"id": "<cert-id>", ... }
- Delete:
DELETE /tyk/certs/<cert-id>
- Get info:
GET /tyk/certs/<cert-id>
. Returns meta info about the certificate, something similar to:
- Get info about multiple certificates:
GET /tyk/certs/<cert-id1>,<cert-id2>,<cert-id3>
. Returns array of meta info objects, similar to above. - List all certificate IDs:
GET /tyk/certs
. Returns something similar to:
- Endpoints start with
/api
instead of/tyk
, e.g./api/certs
,/api/certs/<cert-id>
, etc. - All certificates are managed in the context of the organization. In other words, certificates are not shared between organizations.
security.private_certificate_encoding_secret
secret, defined in tyk.conf
file. Otherwise, the certificate will use the secret value in tyk.conf
.
Using Tyk Certificate Storage
In Tyk Gateway 2.4 and Tyk Dashboard 1.4 we added Mutual TLS support including special Certificate storage, which is used to store all kinds of certificates from public to server certificates with private keys. In order to add new server certificates to the Gateway:- Ensure that both private key and certificates are in PEM format
- Concatenate Cert and Key files to single file
- Go to “Certificates” section of the Tyk Dashboard, upload certificate, and you will get a unique ID response
-
Set it to the Tyk Gateway using one of the approaches below:
- Using your
tyk.conf
:
- Using environment variables (handy for Multi-Cloud installation and Docker in general):
TYK_GW_HTTPSERVEROPTIONS_SSLCERTIFICATES=<cert-id>
(if you want to set multiple certificates just separate them using a comma.)
DNSNames
.Prior to Tyk v5, the Domain could also be extracted from the now deprecatedSubject.CommonName
field. - Using your
Self Signed Certificates
Self signed certificates can be managed in multiple ways. Best practice dictates that you store certificates in the standard certificate store on the local system, e.g./etc/ssl/certs
For example, if you are using a self-signed cert on the Dashboard, in order for the Gateway to trust it, add it to the Gateway’s certificate store in /etc/ssl/certs
Alternatively, you can disable the verification of SSL certs in the component configurations below. You shouln’t do this in production!
Creating a self-signed certificate pair
You can create self-signed client and server certificates with this command:common name
specify a domain, or just pass -subj "/CN=localhost"
to OpenSSL command. Then follow our TLS and SSL Guide.
To get certificate SHA256 fingerprint use the following command:
Using self-signed certificates with Tyk Gateway
You can sethttp_server_options.ssl_insecure_skip_verify
to true
in your tyk.conf to allow the use of self-signed certificates when connecting to the Gateway.
Using self-signed certificates with Tyk Dashboard
You can sethttp_server_options.ssl_insecure_skip_verify
to true
in your tyk_analytics.conf to allow the use of self-signed certificates when connecting to the Dashboard.