github.com/outbrain/consul@v1.4.5/website/source/docs/guides/agent-encryption.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Agent Communication Encryption" 4 sidebar_current: "docs-guides-agent-encryption" 5 description: |- 6 This guide covers how to encrypt both gossip and RPC communication. 7 --- 8 9 # Agent Communication Encryption 10 11 There are two different systems that need to be configured separately to encrypt communication within the cluster: gossip encryption and TLS. TLS is used to secure the RPC calls between agents. Gossip encryption is secured with a symmetric key, since gossip between nodes is done over UDP. In this guide we will configure both. 12 13 To complete the RPC encryption section, you must have [configured agent certificates](https://www.consul.io/docs/guides/creating-certificates.html). 14 15 ## Gossip Encryption 16 17 To enable gossip encryption, you need to use an encryption key when starting the Consul agent. The key can be simple set with the `encrypt` parameter in the agent configuration file. Alternatively, the encryption key can be placed in a seperate configuration file with only the `encrypt` field, since the agent can merge multiple configuration files. The key must be 16-bytes, Base64 encoded. 18 19 You can use the Consul CLI command, [`consul keygen`](/docs/commands/keygen.html), to generate a cryptographically suitable key. 20 21 ```sh 22 $ consul keygen 23 cg8StVXbQJ0gPvMd9o7yrg== 24 ``` 25 26 ### Enable Gossip Encryption: New Cluster 27 28 To enable gossip on a new cluster, we will add the encryption key parameter to the 29 agent configuration file and then pass the file at startup with the [`-config-dir`](https://www.consul.io/docs/agent/options.html#_config_dir) flag. 30 31 ```javascript 32 { 33 "data_dir": "/opt/consul", 34 "log_level": "INFO", 35 "node_name": "bulldog", 36 "server": true, 37 "encrypt": "JY34uTPZyfUE+6tinMYEVw==" 38 } 39 ``` 40 41 ```sh 42 $ consul agent -config-dir=/etc/consul.d/ 43 ==> Starting Consul agent... 44 ==> Starting Consul agent RPC... 45 ==> Consul agent running! 46 Node name: 'Armons-MacBook-Air.local' 47 Datacenter: 'dc1' 48 Server: false (bootstrap: false) 49 Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400) 50 Cluster Addr: 10.1.10.12 (LAN: 8301, WAN: 8302) 51 Gossip encrypt: true, RPC-TLS: false, TLS-Incoming: false 52 ... 53 ``` 54 55 "Encrypt: true" will be included in the output, if encryption is properly configured. 56 57 Note: all nodes within a cluster must share the same encryption key in order to send and receive cluster information, including clients and servers. Additionally, if you're using multiple WAN joined datacenters, be sure to use _the same encryption key_ in all datacenters. 58 59 ### Enable Gossip Encryption: Existing Cluster 60 61 Gossip encryption can also be enabled on an existing cluster, but requires several extra steps. The additional configuration of the agent configuration parameters, [`encrypt_verify_incoming`](/docs/agent/options.html#encrypt_verify_incoming) and [`encrypt_verify_outgoing`](/docs/agent/options.html#encrypt_verify_outgoing) is necessary. 62 63 **Step 1**: Generate an encryption key using `consul keygen`. 64 65 ```sh 66 $ consul keygen 67 JY34uTPZyfUE+6tinMYEVw== 68 ``` 69 70 **Step 2**: Set the [`encrypt`](/docs/agent/options.html#_encrypt) key, and set `encrypt_verify_incoming` and `encrypt_verify_outgoing` to `false` in the agent configuration file. Then initiate a rolling update of the cluster with these new values. After this step, the agents will be able to decrypt gossip but will not yet be sending encrypted traffic. 71 72 ```javascript 73 { 74 "data_dir": "/opt/consul", 75 "log_level": "INFO", 76 "node_name": "bulldog", 77 "server": true, 78 "encrypt": "JY34uTPZyfUE+6tinMYEVw==", 79 "encrypt_verify_incoming": false, 80 "encrypt_verify_outgoing": false 81 } 82 ``` 83 84 A rolling update can be made by restarting the Consul agents (clients and servers) in turn. `consul reload` or `kill -HUP <process_id>` is _not_ sufficient to change the gossip configuration. 85 86 **Step 3**: Update the `encrypt_verify_outgoing` setting to `true` and perform another rolling update of the cluster by restarting Consul on each agent. The agents will now be sending encrypted gossip but will still allow incoming unencrypted traffic. 87 88 ```javascript 89 { 90 "data_dir": "/opt/consul", 91 "log_level": "INFO", 92 "node_name": "bulldog", 93 "server": true, 94 "encrypt": "JY34uTPZyfUE+6tinMYEVw==", 95 "encrypt_verify_incoming": false, 96 "encrypt_verify_outgoing": true 97 } 98 ``` 99 100 **Step 4**: The previous step, enabling verify outgoing, must be completed on all agents before continuing. Update the `encrypt_verify_incoming` setting to `true` and perform a final rolling update of the cluster. 101 102 ```javascript 103 { 104 "data_dir": "/opt/consul", 105 "log_level": "INFO", 106 "node_name": "bulldog", 107 "server": true, 108 "encrypt": "JY34uTPZyfUE+6tinMYEVw==", 109 "encrypt_verify_incoming": true, 110 "encrypt_verify_outgoing": true 111 } 112 ``` 113 114 All the agents will now be strictly enforcing encrypted gossip. Note, the default 115 behavior of both `encrypt_verify_incoming` and `encrypt_verify_outgoing` is `true`. 116 We have set them in the configuration file as an explicit example. 117 118 ## TLS Encryption for RPC 119 120 Consul supports using TLS to verify the authenticity of servers and clients. To enable TLS, 121 Consul requires that all servers have certificates that are signed by a single 122 Certificate Authority. Clients may optionally authenticate with a client certificate generated by the same CA. Please see 123 [this tutorial on creating a CA and signing certificates](/docs/guides/creating-certificates.html). 124 125 TLS can be used to verify the authenticity of the servers with [`verify_outgoing`](/docs/agent/options.html#verify_outgoing) and [`verify_server_hostname`](/docs/agent/options.html#verify_server_hostname). It can also optionally verify client certificates when using [`verify_incoming`](/docs/agent/options.html#verify_incoming) 126 127 Review the [docs for specifics](https://www.consul.io/docs/agent/encryption.html). 128 129 In Consul version 0.8.4 and newer, migrating to TLS encrypted traffic on a running cluster 130 is supported. 131 132 ### Enable TLS: New Cluster 133 134 After TLS has been configured on all the agents, you can start the agents and RPC communication will be encrypted. 135 136 ```javascript 137 { 138 "data_dir": "/opt/consul", 139 "log_level": "INFO", 140 "node_name": "bulldog", 141 "server": true, 142 "encrypt": "JY34uTPZyfUE+6tinMYEVw==", 143 "verify_incoming": true, 144 "verify_outgoing": true, 145 "verify_server_hostname": true, 146 "ca_file": "consul-agent-ca.pem", 147 "cert_file": "consul-server-dc1-0.pem", 148 "key_file": "consul-server-dc1-0-key.pem" 149 } 150 ``` 151 152 Note, for clients, the default `cert_file` and `key_file` will be named according to their cluster for. For example, `consul-client-dc1-0.pem`. 153 154 The `verify_outgoing` parameter enables agents to verify the authenticity of Consul servers for outgoing connections. The `verify_server_hostname` parameter requires outgoing connections to perform hostname verification and is critically important to prevent compromised client agents from becoming servers and revealing all state to the attacker. Finally, the `verify_incoming` parameter enables the servers to verify the authenticity of all incoming connections. 155 156 ### Enable TLS: Existing Cluster 157 158 Enabling TLS on an existing cluster is supported. This process assumes a starting point of a running cluster with no TLS settings configured, and involves an intermediate step in order to get to full TLS encryption. 159 160 **Step 1**: [Generate the necessary keys and certificates](/docs/guides/creating-certificates.html), then set the `ca_file` or `ca_path`, `cert_file`, and `key_file` settings in the configuration for each agent. Make sure the `verify_outgoing` and `verify_incoming` options are set to `false`. HTTPS for the API can be enabled at this point by setting the [`https`](/docs/agent/options.html#http_port) port. 161 162 ```javascript 163 { 164 "data_dir": "/opt/consul", 165 "log_level": "INFO", 166 "node_name": "bulldog", 167 "server": true, 168 "encrypt": "JY34uTPZyfUE+6tinMYEVw==", 169 "verify_incoming": false, 170 "verify_outgoing": false, 171 "ca_file": "consul-agent-ca.pem", 172 "cert_file": "consul-server-dc1-0.pem", 173 "key_file": "consul-server-dc1-0-key.pem" 174 } 175 ``` 176 177 Next, perform a rolling restart of each agent in the cluster. After this step, TLS should be enabled everywhere but the agents will not yet be enforcing TLS. Again, `consul reload` or `kill -HUP <process_id>` is _not_ sufficient to update the configuration. 178 179 180 **Step 2**: (Optional, Enterprise-only) If applicable, set the `Use TLS` setting in any network areas to `true`. This can be done either through the [`consul operator area update`](/docs/commands/operator/area.html) command or the [Operator API](/api/operator/area.html). 181 182 **Step 3**: Change the `verify_incoming`, `verify_outgoing`, and `verify_server_hostname` to `true` then perform another rolling restart of each agent in the cluster. 183 184 ```javascript 185 { 186 "data_dir": "/opt/consul", 187 "log_level": "INFO", 188 "node_name": "bulldog", 189 "server": true, 190 "encrypt": "JY34uTPZyfUE+6tinMYEVw==", 191 "verify_incoming": true, 192 "verify_outgoing": true, 193 "verify_server_hostname": true, 194 "ca_file": "consul-agent-ca.pem", 195 "cert_file": "consul-server-dc1-0.pem", 196 "key_file": "consul-server-dc1-0-key.pem" 197 } 198 199 ``` 200 201 At this point, full TLS encryption for RPC communication is enabled. To disable `HTTP` 202 connections, which may still be in use by clients for API and CLI communications, update 203 the [agent configuration](https://www.consul.io/docs/agent/options.html#ports). 204 205 ## Summary 206 207 In this guide we configured both gossip encryption and TLS for RPC. Securing agent communication is a recommended set in setting up a production ready cluster. 208