1---
2layout: "docs"
3page_title: "Security Model"
4sidebar_current: "docs-internals-security"
5description: |-
6  Consul relies on both a lightweight gossip mechanism and an RPC system to provide various features. Both of the systems have different security mechanisms that stem from their designs. However, the security mechanisms of Consul have a common goal: to provide confidentiality, integrity, and authentication.
7---
8
9# Security Model
10
11Consul relies on both a lightweight gossip mechanism and an RPC system
12to provide various features. Both of the systems have different security
13mechanisms that stem from their designs. However, the security mechanisms
14of Consul have a common goal: to provide
15[confidentiality, integrity, and authentication](https://en.wikipedia.org/wiki/Information_security).
16
17The [gossip protocol](/docs/internals/gossip.html) is powered by [Serf](https://www.serf.io/),
18which uses a symmetric key, or shared secret, cryptosystem. There are more
19details on the security of [Serf here](https://www.serf.io/docs/internals/security.html).
20For details on how to enable Serf's gossip encryption in Consul, see the
21[encryption doc here](/docs/agent/encryption.html).
22
23The RPC system supports using end-to-end TLS with optional client authentication.
24[TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) is a widely deployed asymmetric
25cryptosystem and is the foundation of security on the Web.
26
27This means Consul communication is protected against eavesdropping, tampering,
28and spoofing. This makes it possible to run Consul over untrusted networks such
29as EC2 and other shared hosting providers.
30
31## Secure Configuration
32
33The Consul threat model is only applicable if Consul is running in a secure
34configuration. Consul does not operate in a secure-by-default configuration. If
35any of the settings below are not enabled, then parts of this threat model are
36going to be invalid. Additional security precautions must also be taken for
37items outside of Consul's threat model as noted in sections below.
38
39* **ACLs enabled with default deny.** Consul must be configured to use ACLs with
40  a whitelist (default deny) approach. This forces all requests to have explicit
41  anonymous access or provide an ACL token.
42
43* **Encryption enabled.** TCP and UDP encryption must be enabled and configured
44  to prevent plaintext communication between Consul agents. At a minimum,
45  `verify_outgoing` should be enabled to verify server authenticity with each
46  server having a unique TLS certificate. `verify_server_hostname` is also
47  required to prevent a compromised agent restarting as a server and being given
48  access to all secrets.
49
50    `verify_incoming` provides additional agent verification via mutual
51  authentication, but isn't _strictly_ necessary to enforce the threat model
52  since requests must also contain a valid ACL token. The subtlety is that
53  currently `verify_incoming = false` will allow servers to still accept
54  un-encrypted connections from clients (to allow for gradual TLS rollout). That
55  alone doesn't violate the threat model, but any misconfigured client that
56  chooses not to use TLS will violate the model. We recommend setting this to
57  true. If it is left as false care must be taken to ensure all consul clients
58  use `verify_outgoing = true` as noted above, but also all external API/UI
59  access must be via HTTPS with HTTP listeners disabled.
60
61### Known Insecure Configurations
62
63In addition to configuring the non-default settings above, Consul has several
64non-default options that potentially present additional security risks.
65
66* **Script checks enabled with network-exposed API.** If a Consul agent (client
67  or server) exposes its HTTP API to the network beyond localhost,
68  [`enable_script_checks`](/docs/agent/options.html#_enable_script_checks) must
69  be `false` otherwise, even with ACLs configured, script checks present a
70  remote code execution threat.
71  [`enable_local_script_checks`](/docs/agent/options.html#_enable_local_script_checks)
72  provides a secure alternative if the HTTP API must be exposed and is available
73  from 1.3.0 on. This feature was also back-ported to patch releases 0.9.4,
74  1.1.1, and 1.2.4 [as described here](https://www.hashicorp.com/blog/protecting-consul-from-rce-risk-in-specific-configurations).
75
76* **Remote exec enabled.** Consul includes a [`consul exec`
77  feature](/docs/commands/exec.html) allowing execution of arbitrary commands
78  across the cluster. This is disabled by default since 0.8.0. We recommend
79  leaving it disabled. If enabled, extreme care must be taken to ensure correct
80  ACLs restrict access, for example any management token grants access to
81  execute arbitrary code on the cluster.
82
83* **Verify Server Hostname Used Alone.** From version 0.5.1 to 1.4.0 we documented that
84  `verify_server_hostname` being `true` _implied_ `verify_outgoing` however due
85  to a bug this was not the case so setting _only_ `verify_server_hostname`
86  results in plaintext communication between client and server. See
87  [CVE-2018-19653](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-19653)
88  for more details. This is fixed in 1.4.1.
89
90## Threat Model
91
92The following are parts of the Consul threat model:
93
94* **Consul agent-to-agent communication.** Communication between Consul agents should be secure from eavesdropping. This requires transport encryption to be enabled on the cluster and covers both TCP and UDP traffic.
95
96* **Consul agent-to-CA communication.** Communication between the Consul server and the configured certificate authority provider for Connect is always encrypted.
97
98* **Tampering of data in transit.** Any tampering should be detectable and cause Consul to avoid processing the request.
99
100* **Access to data without authentication or authorization.** All requests must be authenticated and authorized. This requires that ACLs are enabled on the cluster with a default deny mode.
101
102* **State modification or corruption due to malicious messages.** Ill-formatted messages are discarded and well-formatted messages require authentication and authorization.
103
104* **Non-server members accessing raw data.**  All servers must join the cluster (with proper authentication and authorization) to begin participating in Raft. Raft data is transmitted over TLS.
105
106* **Denial of Service against a node.** DoS attacks against a node should not compromise the security stance of the software.
107
108* **Connect-based Service-to-Service communication.** Communications between two Connect-enabled services (natively or by proxy) should be secure from eavesdropping and provide authentication. This is achieved via mutual TLS.
109
110The following are _not_ part of the Consul threat model for Consul server agents:
111
112* **Access (read or write) to the Consul data directory.** All Consul servers, including non-leaders, persist the full set of Consul state to this directory. The data includes all KV, service registrations, ACL tokens, Connect CA configuration, and more. Any read or write to this directory allows an attacker to access and tamper with that data.
113
114* **Access (read or write) to the Consul configuration directory.** Consul configuration can enable or disable the ACL system, modify data directory paths, and more. Any read or write of this directory allows an attacker to reconfigure many aspects of Consul. By disabling the ACL system, this may give an attacker access to all Consul data.
115
116* **Memory access to a running Consul server agent.** If an attacker is able to inspect the memory state of a running Consul server agent the confidentiality of almost all Consul data may be compromised. If you're using an external Connect CA, the root private key material is never available to the Consul process and can be considered safe. Service Connect TLS certificates should be considered compromised; they are never persisted by server agents but do exist in-memory during at least the duration of a Sign request.
117
118The following are _not_ part of the Consul threat model for Consul client agents:
119
120* **Access (read or write) to the Consul data directory.** Consul clients will use the data directory to cache local state. This includes local services, associated ACL tokens, Connect TLS certificates, and more. Read or write access to this directory will allow an attacker to access this data. This data is typically a smaller subset of the full data of the cluster.
121
122* **Access (read or write) to the Consul configuration directory.** Consul client configuration files contain the address and port information of services, default ACL tokens for the agent, and more. Access to Consul configuration could enable an attacker to change the port of a service to a malicious port, register new services, and more. Further, some service definitions have ACL tokens attached that could be used cluster-wide to impersonate that service. An attacker cannot change cluster-wide configurations such as disabling the ACL system.
123
124* **Memory access to a running Consul client agent.** The blast radius of this is much smaller than a server agent but the confidentiality of a subset of data can still be compromised. Particularly, any data requested against the agent's API including services, KV, and Connect information may be compromised. If a particular set of data on the server was never requested by the agent, it never enters the agent's memory since replication only exists between servers. An attacker could also potentially extract ACL tokens used for service registration on this agent, since the tokens must be stored in-memory alongside the registered service.
125
126* **Network access to a local Connect proxy or service.** Communications between a service and a Connect-aware proxy are generally unencrypted and must happen over a trusted network. This is typically a loopback device. This requires that other processes on the same machine are trusted, or more complex isolation mechanisms are used such as network namespaces. This also requires that external processes cannot communicate to the Connect service or proxy (except on the inbound port). Therefore, non-native Connect applications should only bind to non-public addresses.
127
128* **Improperly Implemented Connect proxy or service.** A Connect proxy or natively integrated service must correctly serve a valid leaf certificate, verify the inbound TLS client certificate, and call the Consul agent-local authorize endpoint. If any of this isn't performed correctly, the proxy or service may allow unauthenticated or unauthorized connections.
129
130## External Threat Overview
131
132There are four components that affect the Consul threat model: the server agent, the client agent, the Connect CA, and Consul API clients (including proxies for Connect).
133
134The server agent participates in leader election and data replication via Raft. All communications with other agents is encrypted. Data is stored at rest unencrypted in the configured data directory. The stored data includes ACL tokens and TLS certificates. If the built-in CA is used with Connect, root certificate private keys are also stored on disk. External CA providers do not store data in this directory. This data directory must be carefully protected to prevent an attacker from impersonating a server or specific ACL user. We plan to introduce further mitigations (including at least partial data encryption) to the data directory over time, but the data directory should always be considered secret.
135
136For a client agent to join a cluster, it must provide a valid ACL token with node:write capabilities. The join request and all other API requests between the client and server agents communicate via TLS. Clients serve the Consul API and forward all requests to a server over a shared TLS connection. Each request contains an ACL token which is used for both authentication and authorization. Requests that do not provide an ACL token inherit the agent-configurable default ACL token.
137
138The Connect CA provider is responsible for storing the private key of the root (or intermediate) certificate used to sign and verify connections established via Connect. Consul server agents communicate with the CA provider via an encrypted method. This method is dependent on the CA provider in use. Consul provides a built-in CA which performs all operations locally on the server agent. Consul itself does not store any private key material except for the built-in CA.
139
140Consul API clients (the agent itself, the built-in UI, external software) must communicate to a Consul agent over TLS and must provide an ACL token per request for authentication and authorization.
141
142## Network Ports
143
144For configuring network rules to support Consul, please see [Ports Used](/docs/agent/options.html#ports)
145for a listing of network ports used by Consul and details about which features
146they are used for.
147