2014-02-08 00:41:03 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
page_title: Encryption
2020-04-13 18:40:26 +00:00
sidebar_title: Encryption
2020-04-07 18:55:19 +00:00
description: >-
The Consul agent supports encrypting all of its network traffic. The exact
method of encryption is described on the encryption internals page. There are
two separate encryption systems, one for gossip traffic and one for RPC.
2014-02-08 00:41:03 +00:00
---
# Encryption
2014-02-18 23:30:07 +00:00
The Consul agent supports encrypting all of its network traffic. The exact
2020-04-09 23:46:54 +00:00
method of encryption is described on the [encryption internals page](/docs/internals/security).
2015-01-31 23:33:29 +00:00
There are two separate encryption systems, one for gossip traffic and one for RPC.
2019-10-14 15:40:35 +00:00
2020-08-17 16:17:51 +00:00
To configure the encryption systems on a new cluster, review this following tutorials to
[enable gossip encryption](https://learn.hashicorp.com/tutorials/consul/gossip-encryption-secure?utm_source=consul.io&utm_medium=docs) and
[TLS encryption for agent communication](https://learn.hashicorp.com/tutorials/consul/tls-encryption-secure?utm_source=consul.io&utm_medium=docs).
2014-02-08 00:41:03 +00:00
2014-04-07 22:06:26 +00:00
## Gossip Encryption
2014-02-08 00:41:03 +00:00
2014-04-07 22:06:26 +00:00
Enabling gossip encryption only requires that you set an encryption key when
2019-03-12 15:26:40 +00:00
starting the Consul agent. The key can be set via the `encrypt` parameter.
2015-01-31 23:33:29 +00:00
2018-03-02 15:41:09 +00:00
~> **WAN Joined Datacenters Note:** If using multiple WAN joined datacenters, be sure to use _the same encryption key_ in all datacenters.
2019-07-30 15:45:41 +00:00
The key must be 32-bytes, Base64 encoded. As a convenience, Consul provides the
2020-04-09 23:46:54 +00:00
[`consul keygen`](/docs/commands/keygen) command to generate a
2015-03-24 19:30:35 +00:00
cryptographically suitable key:
2014-02-08 00:41:03 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2014-02-18 23:30:07 +00:00
$ consul keygen
2019-07-30 15:45:41 +00:00
pUqJrVyVRj5jsiYEkM/tFQYfWyJIv4s3XkvDwy7Cu5s=
2014-02-08 00:41:03 +00:00
```
2015-01-31 23:33:29 +00:00
With that key, you can enable encryption on the agent. If encryption is enabled,
2020-04-09 23:46:54 +00:00
the output of [`consul agent`](/docs/commands/agent) will include "Encrypt: true":
2014-02-08 00:41:03 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2014-07-15 16:50:39 +00:00
$ cat encrypt.json
2019-07-30 15:45:41 +00:00
{"encrypt": "pUqJrVyVRj5jsiYEkM/tFQYfWyJIv4s3XkvDwy7Cu5s="}
2014-07-15 16:50:39 +00:00
2016-09-27 02:47:35 +00:00
$ consul agent -data-dir=/tmp/consul -config-file=encrypt.json
2016-03-07 20:23:45 +00:00
==> WARNING: LAN keyring exists but -encrypt given, using keyring
==> WARNING: WAN keyring exists but -encrypt given, using keyring
2014-02-18 23:30:07 +00:00
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
Node name: 'Armons-MacBook-Air.local'
Datacenter: 'dc1'
Server: false (bootstrap: false)
2016-03-07 20:23:45 +00:00
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
Cluster Addr: 10.1.10.12 (LAN: 8301, WAN: 8302)
Gossip encrypt: true, RPC-TLS: false, TLS-Incoming: false
2014-02-08 00:41:03 +00:00
...
```
2014-02-18 23:30:07 +00:00
All nodes within a Consul cluster must share the same encryption key in
2014-02-08 00:41:03 +00:00
order to send and receive cluster information.
2017-05-30 15:51:37 +00:00
## Configuring Gossip Encryption on an existing cluster
As of version 0.8.4, Consul supports upshifting to encrypted gossip on a running cluster
2020-08-17 16:17:51 +00:00
through the following process. Review this [step-by-step tutorial](https://learn.hashicorp.com/tutorials/consul/gossip-encryption-secure#enable-gossip-encryption-existing-cluster)
2018-12-19 18:41:25 +00:00
to encrypt gossip on an existing cluster.
2017-05-30 15:51:37 +00:00
2016-12-22 08:51:20 +00:00
## RPC Encryption with TLS
2014-04-07 22:06:26 +00:00
2015-01-31 23:33:29 +00:00
Consul supports using TLS to verify the authenticity of servers and clients. To enable this,
Consul requires that all clients and servers have key pairs that are generated by a single
Certificate Authority. This can be a private CA, used only internally. The
CA then signs keys for each of the agents, as in
2020-08-17 16:17:51 +00:00
[this tutorial on generating both a CA and signing keys](https://learn.hashicorp.com/tutorials/consul/tls-encryption-secure).
2014-04-07 22:06:26 +00:00
2020-07-21 16:38:03 +00:00
~> Certificates need to be created with x509v3 extendedKeyUsage attributes for both clientAuth and serverAuth since Consul uses a single cert/key pair for both server and client communications.
2015-02-01 03:05:00 +00:00
TLS can be used to verify the authenticity of the servers or verify the authenticity of clients.
2020-04-09 23:46:54 +00:00
These modes are controlled by the [`verify_outgoing`](/docs/agent/options#verify_outgoing),
[`verify_server_hostname`](/docs/agent/options#verify_server_hostname),
and [`verify_incoming`](/docs/agent/options#verify_incoming) options, respectively.
2015-03-24 19:30:35 +00:00
2020-04-09 23:46:54 +00:00
If [`verify_outgoing`](/docs/agent/options#verify_outgoing) is set, agents verify the
2015-03-24 19:30:35 +00:00
authenticity of Consul for outgoing connections. Server nodes must present a certificate signed
2017-05-10 21:25:48 +00:00
by a common certificate authority present on all agents, set via the agent's
2020-04-09 23:46:54 +00:00
[`ca_file`](/docs/agent/options#ca_file) and [`ca_path`](/docs/agent/options#ca_path)
options. All server nodes must have an appropriate key pair set using [`cert_file`](/docs/agent/options#cert_file) and [`key_file`](/docs/agent/options#key_file).
2015-03-24 19:30:35 +00:00
2020-04-09 23:46:54 +00:00
If [`verify_server_hostname`](/docs/agent/options#verify_server_hostname) is set, then
2015-05-11 23:22:10 +00:00
outgoing connections perform hostname verification. All servers must have a certificate
2016-11-25 16:00:02 +00:00
valid for `server.<datacenter>.<domain>` or the client will reject the handshake. This is
2015-05-11 23:22:10 +00:00
a new configuration as of 0.5.1, and it is used to prevent a compromised client from being
2016-11-25 16:00:02 +00:00
able to restart in server mode and perform a MITM (Man-In-The-Middle) attack. New deployments should set this
2015-05-11 23:22:10 +00:00
to true, and generate the proper certificates, but this is defaulted to false to avoid breaking
existing deployments.
2020-04-09 23:46:54 +00:00
If [`verify_incoming`](/docs/agent/options#verify_incoming) is set, the servers verify the
2015-03-24 19:30:35 +00:00
authenticity of all incoming connections. All clients must have a valid key pair set using
2020-04-09 23:46:54 +00:00
[`cert_file`](/docs/agent/options#cert_file) and
[`key_file`](/docs/agent/options#key_file). Servers will
2015-03-24 19:30:35 +00:00
also disallow any non-TLS connections. To force clients to use TLS,
2020-04-09 23:46:54 +00:00
[`verify_outgoing`](/docs/agent/options#verify_outgoing) must also be set.
2014-04-07 22:06:26 +00:00
TLS is used to secure the RPC calls between agents, but gossip between nodes is done over UDP
and is secured using a symmetric key. See above for enabling gossip encryption.
2017-05-10 21:25:48 +00:00
## Configuring TLS on an existing cluster
2017-06-08 04:31:48 +00:00
As of version 0.8.4, Consul supports migrating to TLS-encrypted traffic on a running cluster
2019-07-18 03:36:36 +00:00
without downtime. This process assumes a starting point with no TLS settings configured and involves
an intermediate step in order to get to full TLS encryption. Review the
2020-09-21 14:08:00 +00:00
[Securing RPC Communication with TLS Encryption tutorial](https://learn.hashicorp.com/tutorials/consul/tls-encryption-secure)
2019-07-18 03:36:36 +00:00
for the step-by-step process to configure TLS on a new or existing cluster. Note the call outs there
2020-04-06 20:27:35 +00:00
for existing cluster configuration.