HAProxy Enterprise Documentation 1.6r2

set ssl tls-key

Rotate the load balancer's session ticket encryption key used to encrypt TLS session tickets.


When the load balancer and a client exchange messages over TLS, they share a secret key to encrypt their communication. This key is called a session key and it lasts only as long as the TLS session. Each new TLS session uses a unique key, which makes it difficult for an attacker to exploit.

Generating a session key costs the load balancer CPU time, which can add up when managing many clients. By asking each client to store their session key locally and reuse it between visits, the load balancer offloads some work and speeds up the time it takes to establish a TLS connection. The client can send their old session key to the load balancer to resume their session, negating the need to create a new one.

To make this secure, the load balancer uses a secret key known only to it to encrypt the session key in a package called a session ticket before sending it to the client. Only the load balancer can decrypt the ticket. The load balancer's secret key should be changed at least every 24 hours in case an attacker steals it.

The set ssl tls-key command rotates in a new secret key to replace the current one.


TLS session tickets are enabled by default in HAProxy Enterprise because they are enabled by default in the underlying OpenSSL library, which provides the load balancer's TLS features. Without any tuning, OpenSSL uses its own secret key, which it stores in memory, to encrypt session tickets. By defining your own secret key, you can share it across a cluster of load balancers, making it possible to operate in an active-active state. You also gain the ability to rotate the key using the set ssl tls-key command.

Generate initial secret keys

In this example, we generate secret keys for a website named test.local.

  1. Create a directory to hold your secret keys:

    $ sudo mkdir /etc/ssl/tls-ticket-keys
  2. Generate three secret keys and store them in the file /etc/ssl/tls-ticket-keys/test.local.key by calling the following command three times:

    $ echo "`openssl rand 48 | openssl base64 -A`" | \
      sudo tee -a /etc/ssl/tls-ticket-keys/test.local.key > /dev/null
  3. Add the tls-ticket-keys parameter to the bind line in the frontend or listen section of your configuration.

    This points to the file containing a list of secret keys to use upon startup.

    frontend fe_main
       bind :80
       bind :443 ssl  crt /etc/hapee-1.6/certs/site.pem  tls-ticket-keys /etc/ssl/tls-ticket-keys/test.local.key
       http-request redirect scheme https unless { ssl_fc }
       default_backend webservers

Rotate the secret key

Follow these steps to rotate in a new secret key for encrypting TLS session tickets:

  1. To view the current list of keys, call show tls-keys with the path to the key file:

    $ echo "show tls-keys /etc/ssl/tls-ticket-keys/test.local.key" | \
      sudo socat stdio /var/run/hapee-1.6/hapee-lb.sock
    # id secret
    # 0 (/etc/ssl/tls-ticket-keys/test.local.key)
    0.0 ilwevZCJtyCYBI4rIKswr8S+F6FDyWYsJ4ckkpXs5JxiX0jCfuxzwabjISsx98z0
    0.1 mvkfpn6Hb3ugXF44ETcsMYf8+1Cb7yMTvAFIGtyWL+ASIKsTYOL5tRq5JwlztcjV
    0.2 2TlY5ms3h2Jhuhd5i3QhGT6Lh4vHZvx/N3AuSpQ+f7ZpwAkXTADFcuBZlL+yRJk+
  2. Create a new key by calling the set ssl tls-key command with two parameters:

    • the path to the key file

    • the openssl command to generate a new key

    $ echo "set ssl tls-key \
      /etc/ssl/tls-ticket-keys/test.local.key \
      $(openssl rand 48 | openssl base64 -A)" | \
      sudo socat stdio /var/run/hapee-1.6/hapee-lb.sock
    TLS ticket key updated!
  3. Call show tls-keys again to see that a new key has been added to the third row and the first two rows rotated down:

    $ echo "show tls-keys /etc/ssl/tls-ticket-keys/test.local.key" | \
      sudo socat stdio /var/run/hapee-1.6/hapee-lb.sock
    # id secret
    # 0 (/etc/ssl/tls-ticket-keys/test.local.key)
    0.0 mvkfpn6Hb3ugXF44ETcsMYf8+1Cb7yMTvAFIGtyWL+ASIKsTYOL5tRq5JwlztcjV
    0.1 2TlY5ms3h2Jhuhd5i3QhGT6Lh4vHZvx/N3AuSpQ+f7ZpwAkXTADFcuBZlL+yRJk+
    0.2 l9zwhvrtA49SOtnj5Vd+s3S0qK4C2Z+usRf9ITF8afvdVyrzkxNl0Au8zeboDev8

    HAProxy Enterprise uses the second from the last key (the middle one) to encrypt new session tickets. The others are still used to decrypt older session tickets. If the key used to encrypt a session ticket no longer exists, the client creates a new session.

See also

Next up

set table