github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/website/source/docs/agent/encryption.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Gossip and RPC Encryption" 4 sidebar_current: "docs-agent-encryption" 5 description: |- 6 Learn how to configure Nomad to encrypt HTTP, RPC, and Serf traffic. 7 --- 8 9 # Encryption 10 11 The Nomad agent supports encrypting all of its network traffic. There are 12 two separate encryption systems, one for gossip traffic, and one for HTTP and 13 RPC. 14 15 ## Gossip 16 17 Enabling gossip encryption only requires that you set an encryption key when 18 starting the Nomad server. The key can be set via the 19 [`encrypt`](/docs/agent/configuration/server.html#encrypt) parameter: the value 20 of this setting is a server configuration file containing the encryption key. 21 22 The key must be 16-bytes, base64 encoded. As a convenience, Nomad provides the 23 [`nomad keygen`](/docs/commands/keygen.html) command to generate a cryptographically suitable key: 24 25 ```sh 26 $ nomad keygen 27 cg8StVXbQJ0gPvMd9o7yrg== 28 ``` 29 30 With that key, you can enable gossip encryption on the agent. 31 32 33 ## HTTP, RPC, and Raft Encryption with TLS 34 35 Nomad supports using TLS to verify the authenticity of servers and clients. To 36 enable this, Nomad requires that all clients and servers have key pairs that are 37 generated and signed by a Certificate Authority. This can be a private CA. 38 39 TLS can be used to verify the authenticity of the servers and clients. The 40 configuration option [`verify_server_hostname`][tls] causes Nomad to verify that 41 a certificate is provided that is signed by the Certificate Authority from the 42 [`ca_file`][tls] for TLS connections. 43 44 If `verify_server_hostname` is set, then outgoing connections perform 45 hostname verification. Unlike traditional HTTPS browser validation, all servers 46 must have a certificate valid for `server.<region>.nomad` or the client will 47 reject the handshake. It is also recommended for the certificate to sign 48 `localhost` such that the CLI can validate the server name. 49 50 TLS is used to secure the RPC calls between agents, but gossip between nodes is 51 done over UDP and is secured using a symmetric key. See above for enabling 52 gossip encryption. 53 54 ### Configuring the command line tool 55 56 If you have HTTPS enabled for your Nomad agent, you must export environment 57 variables for the command line tool to also use HTTPS: 58 59 ```sh 60 # NOMAD_ADDR defaults to http://, so set it to https 61 # Alternatively you can use the -address flag 62 export NOMAD_ADDR=https://127.0.0.1:4646 63 64 # Set the location of your CA certificate 65 # Alternatively you can use the -ca-cert flag 66 export NOMAD_CACERT=/path/to/ca.pem 67 ``` 68 69 Run any command except `agent` with `-h` to see all environment variables and 70 flags. For example: `nomad status -h` 71 72 By default HTTPS does not validate client certificates, so you do not need to 73 give the command line tool access to any private keys. 74 75 ### Network Isolation with TLS 76 77 If you want to isolate Nomad agents on a network with TLS you need to enable 78 both [`verify_https_client`][tls] and [`verify_server_hostname`][tls]. This 79 will cause agents to require client certificates for all incoming HTTPS 80 connections as well as verify proper names on all other certificates. 81 82 Consul will not attempt to health check agents with `verify_https_client` set 83 as it is unable to use client certificates. 84 85 ## Encryption Examples 86 87 ### TLS Configuration using `cfssl` 88 89 While [Vault's PKI backend][vault] is an ideal solution for managing 90 certificates and other secrets in a production environment, it's useful to use 91 simpler command line tools when learning how to configure TLS and your [PKI]. 92 93 [`cfssl`][cfssl] is a tool for working with TLS certificates and certificate 94 authorities similar to [OpenSSL's][openssl] `x509` command line tool. 95 96 Once you have the `cfssl` command line tool installed, the first step to 97 setting up TLS is to create a Certificate Authority (CA) certificate. The 98 following command will generate a suitable example CA CSR, certificate, and 99 key: 100 101 ```shell 102 # Run in the directory where you want to store certificates 103 $ cfssl print-defaults csr | cfssl gencert -initca - | cfssljson -bare ca 104 ``` 105 106 Next create a `nomad-csr.json` which contains the configuration for the actual 107 certificate you'll be using in Nomad: 108 109 ```json 110 { 111 "CN": "global.nomad", 112 "hosts": [ 113 "server.global.nomad", 114 "client.global.nomad", 115 "localhost" 116 ] 117 } 118 ``` 119 120 This will create a certificate suitable for both clients and servers in the 121 `global` (default) region. 122 123 In production Nomad agents should have a certificate valid for the name 124 `${ROLE}.${REGION}.nomad` where role is either `client` or `server` depending 125 on the node's role. 126 127 Create a certificate signed by your CA: 128 129 ```shell 130 $ cfssl gencert -ca ca.pem -ca-key ca-key.pem nomad-csr.json | cfssljson -bare nomad 131 ``` 132 133 You've now successfully generated self-signed certificates! You should see the 134 following files: 135 136 - `ca.pem` - the CA certificate. This corresponds to the Nomad `ca_file` 137 parameter in the Nomad [`tls` stanza][tls]. 138 139 - `ca-key.pem` - the CA private key. This is used to sign CSRs and should 140 **not** be included in the Nomad [`tls` stanza][tls]. 141 142 - `nomad.pem` - the Nomad certificate for the region. This corresponds to the 143 `cert_file` parameter in the Nomad [`tls` stanza][tls]. 144 145 - `nomad-key.pem` - the Nomad private key. This corresponds to the `key_file` 146 parameter in the Nomad [`tls` stanza][tls]. 147 148 - `*.csr` - the certificate signing request. This is temporary for generating 149 certificates and should **not** be included in the Nomad [`tls` stanza][tls]. 150 151 In your Nomad configuration add the `tls` stanza: 152 153 ```hcl 154 tls { 155 http = true 156 rpc = true 157 158 ca_file = "ca.pem" 159 cert_file = "nomad.pem" 160 key_file = "nomad-key.pem" 161 162 verify_server_hostname = true 163 } 164 ``` 165 166 [vault]: https://www.vaultproject.io/docs/secrets/pki/ 167 [PKI]: https://en.wikipedia.org/wiki/Public_key_infrastructure 168 [cfssl]: https://cfssl.org/ 169 [openssl]: https://www.openssl.org/ 170 [tls]: /docs/agent/configuration/tls.html "Nomad TLS Configuration"