TLS

Transport Layer Security

Certificates Definition

Automated

See the Let’s Encrypt page.

User defined

To add / remove TLS certificates, even when Traefik is already running, their definition can be added to the dynamic configuration, in the [[tls.certificates]] section:

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. certificates:
  4. - certFile: /path/to/domain.cert
  5. keyFile: /path/to/domain.key
  6. - certFile: /path/to/other-domain.cert
  7. keyFile: /path/to/other-domain.key

File (TOML)

  1. # Dynamic configuration
  2. [[tls.certificates]]
  3. certFile = "/path/to/domain.cert"
  4. keyFile = "/path/to/domain.key"
  5. [[tls.certificates]]
  6. certFile = "/path/to/other-domain.cert"
  7. keyFile = "/path/to/other-domain.key"

Restriction

In the above example, we’ve used the file provider to handle these definitions. It is the only available method to configure the certificates (as well as the options and the stores). However, in Kubernetes, the certificates can and must be provided by secrets.

Certificates Stores

In Traefik, certificates are grouped together in certificates stores, which are defined as such:

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. stores:
  4. default: {}

File (TOML)

  1. # Dynamic configuration
  2. [tls.stores]
  3. [tls.stores.default]

Restriction

Any store definition other than the default one (named default) will be ignored, and there is therefore only one globally available TLS store.

In the tls.certificates section, a list of stores can then be specified to indicate where the certificates should be stored:

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. certificates:
  4. - certFile: /path/to/domain.cert
  5. keyFile: /path/to/domain.key
  6. stores:
  7. - default
  8. # Note that since no store is defined,
  9. # the certificate below will be stored in the `default` store.
  10. - certFile: /path/to/other-domain.cert
  11. keyFile: /path/to/other-domain.key

File (TOML)

  1. # Dynamic configuration
  2. [[tls.certificates]]
  3. certFile = "/path/to/domain.cert"
  4. keyFile = "/path/to/domain.key"
  5. stores = ["default"]
  6. [[tls.certificates]]
  7. # Note that since no store is defined,
  8. # the certificate below will be stored in the `default` store.
  9. certFile = "/path/to/other-domain.cert"
  10. keyFile = "/path/to/other-domain.key"

Restriction

The stores list will actually be ignored and automatically set to ["default"].

Default Certificate

Traefik can use a default certificate for connections without a SNI, or without a matching domain. This default certificate should be defined in a TLS store:

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. stores:
  4. default:
  5. defaultCertificate:
  6. certFile: path/to/cert.crt
  7. keyFile: path/to/cert.key

File (TOML)

  1. # Dynamic configuration
  2. [tls.stores]
  3. [tls.stores.default]
  4. [tls.stores.default.defaultCertificate]
  5. certFile = "path/to/cert.crt"
  6. keyFile = "path/to/cert.key"

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSStore
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. defaultCertificate:
  8. secretName: default-certificate
  9. ---
  10. apiVersion: v1
  11. kind: Secret
  12. metadata:
  13. name: default-certificate
  14. namespace: default
  15. type: Opaque
  16. data:
  17. tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
  18. tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0=

If no defaultCertificate is provided, Traefik will use the generated one.

ACME Default Certificate

You can configure Traefik to use an ACME provider (like Let’s Encrypt) to generate the default certificate. The configuration to resolve the default certificate should be defined in a TLS store:

Precedence with the defaultGeneratedCert option

The defaultGeneratedCert definition takes precedence over the ACME default certificate configuration.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. stores:
  4. default:
  5. defaultGeneratedCert:
  6. resolver: myresolver
  7. domain:
  8. main: example.org
  9. sans:
  10. - foo.example.org
  11. - bar.example.org

File (TOML)

  1. # Dynamic configuration
  2. [tls.stores]
  3. [tls.stores.default.defaultGeneratedCert]
  4. resolver = "myresolver"
  5. [tls.stores.default.defaultGeneratedCert.domain]
  6. main = "example.org"
  7. sans = ["foo.example.org", "bar.example.org"]

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSStore
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. defaultGeneratedCert:
  8. resolver: myresolver
  9. domain:
  10. main: example.org
  11. sans:
  12. - foo.example.org
  13. - bar.example.org

Docker

  1. ## Dynamic configuration
  2. labels:
  3. - "traefik.tls.stores.default.defaultgeneratedcert.resolver=myresolver"
  4. - "traefik.tls.stores.default.defaultgeneratedcert.domain.main=example.org"
  5. - "traefik.tls.stores.default.defaultgeneratedcert.domain.sans=foo.example.org, bar.example.org"

Marathon

  1. labels: {
  2. "traefik.tls.stores.default.defaultgeneratedcert.resolver": "myresolver",
  3. "traefik.tls.stores.default.defaultgeneratedcert.domain.main": "example.org",
  4. "traefik.tls.stores.default.defaultgeneratedcert.domain.sans": "foo.example.org, bar.example.org",
  5. }

TLS Options

The TLS options allow one to configure some parameters of the TLS connection.

‘default’ TLS Option

The default option is special. When no tls options are specified in a tls router, the default option is used.
When specifying the default option explicitly, make sure not to specify provider namespace as the default option does not have one.
Conversely, for cross-provider references, for example, when referencing the file provider from a docker label, you must specify the provider namespace, for example:
traefik.http.routers.myrouter.tls.options=myoptions@file

TLSOption in Kubernetes

When using the TLSOption resource in Kubernetes, one might setup a default set of options that, if not explicitly overwritten, should apply to all ingresses.
To achieve that, you’ll have to create a TLSOption resource with the name default. There may exist only one TLSOption with the name default (across all namespaces) - otherwise they will be dropped.
To explicitly use a different TLSOption (and using the Kubernetes Ingress resources) you’ll have to add an annotation to the Ingress in the following form: traefik.ingress.kubernetes.io/router.tls.options: <resource-namespace>-<resource-name>@kubernetescrd

Minimum TLS Version

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. minVersion: VersionTLS12
  6. mintls13:
  7. minVersion: VersionTLS13

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. minVersion = "VersionTLS12"
  5. [tls.options.mintls13]
  6. minVersion = "VersionTLS13"

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. minVersion: VersionTLS12
  8. ---
  9. apiVersion: traefik.io/v1alpha1
  10. kind: TLSOption
  11. metadata:
  12. name: mintls13
  13. namespace: default
  14. spec:
  15. minVersion: VersionTLS13

Maximum TLS Version

We discourage the use of this setting to disable TLS1.3.

The recommended approach is to update the clients to support TLS1.3.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. maxVersion: VersionTLS13
  6. maxtls12:
  7. maxVersion: VersionTLS12

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. maxVersion = "VersionTLS13"
  5. [tls.options.maxtls12]
  6. maxVersion = "VersionTLS12"

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. maxVersion: VersionTLS13
  8. ---
  9. apiVersion: traefik.io/v1alpha1
  10. kind: TLSOption
  11. metadata:
  12. name: maxtls12
  13. namespace: default
  14. spec:
  15. maxVersion: VersionTLS12

Cipher Suites

See cipherSuites for more information.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. cipherSuites:
  6. - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. cipherSuites = [
  5. "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
  6. ]

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. cipherSuites:
  8. - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

TLS 1.3

Cipher suites defined for TLS 1.2 and below cannot be used in TLS 1.3, and vice versa. (https://tools.ietf.org/html/rfc8446)
With TLS 1.3, the cipher suites are not configurable (all supported cipher suites are safe in this case). https://golang.org/doc/go1.12#tls_1_3

Curve Preferences

This option allows to set the preferred elliptic curves in a specific order.

The names of the curves defined by crypto (e.g. CurveP521) and the RFC defined names (e. g. secp521r1) can be used.

See CurveID for more information.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. curvePreferences:
  6. - CurveP521
  7. - CurveP384

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. curvePreferences = ["CurveP521", "CurveP384"]

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. curvePreferences:
  8. - CurveP521
  9. - CurveP384

Strict SNI Checking

With strict SNI checking enabled, Traefik won’t allow connections from clients that do not specify a server_name extension or don’t match any of the configured certificates. The default certificate is irrelevant on that matter.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. sniStrict: true

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. sniStrict = true

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. sniStrict: true

ALPN Protocols

Optional, Default=”h2, http/1.1, acme-tls/1”

This option allows to specify the list of supported application level protocols for the TLS handshake, in order of preference. If the client supports ALPN, the selected protocol will be one from this list, and the connection will fail if there is no mutually supported protocol.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. alpnProtocols:
  6. - http/1.1
  7. - h2

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. alpnProtocols = ["http/1.1", "h2"]

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. alpnProtocols:
  8. - http/1.1
  9. - h2

Client Authentication (mTLS)

Traefik supports mutual authentication, through the clientAuth section.

For authentication policies that require verification of the client certificate, the certificate authority for the certificates should be set in clientAuth.caFiles.

In Kubernetes environment, CA certificate can be set in clientAuth.secretNames. See TLSOption resource for more details.

The clientAuth.clientAuthType option governs the behaviour as follows:

  • NoClientCert: disregards any client certificate.
  • RequestClientCert: asks for a certificate but proceeds anyway if none is provided.
  • RequireAnyClientCert: requires a certificate but does not verify if it is signed by a CA listed in clientAuth.caFiles or in clientAuth.secretNames.
  • VerifyClientCertIfGiven: if a certificate is provided, verifies if it is signed by a CA listed in clientAuth.caFiles or in clientAuth.secretNames. Otherwise proceeds without any certificate.
  • RequireAndVerifyClientCert: requires a certificate, which must be signed by a CA listed in clientAuth.caFiles or in clientAuth.secretNames.

File (YAML)

  1. # Dynamic configuration
  2. tls:
  3. options:
  4. default:
  5. clientAuth:
  6. # in PEM format. each file can contain multiple CAs.
  7. caFiles:
  8. - tests/clientca1.crt
  9. - tests/clientca2.crt
  10. clientAuthType: RequireAndVerifyClientCert

File (TOML)

  1. # Dynamic configuration
  2. [tls.options]
  3. [tls.options.default]
  4. [tls.options.default.clientAuth]
  5. # in PEM format. each file can contain multiple CAs.
  6. caFiles = ["tests/clientca1.crt", "tests/clientca2.crt"]
  7. clientAuthType = "RequireAndVerifyClientCert"

Kubernetes

  1. apiVersion: traefik.io/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. clientAuth:
  8. # the CA certificate is extracted from key `tls.ca` or `ca.crt` of the given secrets.
  9. secretNames:
  10. - secretCA
  11. clientAuthType: RequireAndVerifyClientCert

Using Traefik for Business Applications?

If you are using Traefik in your organization, consider our enterprise-grade solutions:

These tools help businesses discover, deploy, secure, and manage microservices and APIs easily, at scale, across any environment.