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:

  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"

  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

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:

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

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

Restriction

Any store definition other than the default one (named default) will be ignored,and there is thefore 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:

  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"

  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

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:

  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"

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

If no default certificate is provided, Traefik generates and uses a self-signed certificate.

TLS Options

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

Minimum TLS Version

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

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

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

Maximum TLS Version

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

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

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

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

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

Cipher Suites

See cipherSuites for more information.

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

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

  1. apiVersion: traefik.containo.us/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.

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

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

  1. apiVersion: traefik.containo.us/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, Traefik won't allow connections from clients connectionsthat do not specify a server_name extension.

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

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

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

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 certificate should be set in clientAuth.caFiles.

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.
  • VerifyClientCertIfGiven: if a certificate is provided, verifies if it is signed by a CA listed in clientAuth.caFiles. Otherwise proceeds without any certificate.
  • RequireAndVerifyClientCert: requires a certificate, which must be signed by a CA listed in clientAuth.caFiles.

  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"

  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

  1. apiVersion: traefik.containo.us/v1alpha1
  2. kind: TLSOption
  3. metadata:
  4. name: default
  5. namespace: default
  6. spec:
  7. clientAuth:
  8. secretNames:
  9. - secretCA
  10. clientAuthType: RequireAndVerifyClientCert