github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/website/source/docs/acl/acl-legacy.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "ACL System (Legacy)" 4 sidebar_current: "docs-acl-legacy" 5 description: |- 6 Consul provides an optional Access Control List (ACL) system which can be used to control access to data and APIs. The ACL system is a Capability-based system that relies on tokens which can have fine grained rules applied to them. It is very similar to AWS IAM in many ways. 7 --- 8 9 -> **1.3.0 and earlier:** This guide only applies in Consul versions 1.3.0 and before. If you are using the 1.4.0 or later please use the updated guide [here](/docs/acl/acl.html) 10 11 12 ~> **Alert: Deprecation Notice** 13 The ACL system described here was Consul's original ACL implementation. In Consul 1.4.0 14 the ACL system was rewritten and the legacy system was deprecated. The new ACL system information can be found [here](/docs/acl/acl-system.html). 15 16 17 The legacy documentation has two sections. 18 19 - The [New ACL System Differences](#new-acl-system-differences) section 20 details the differences between ACLs in Consul 1.4.0 and older versions. You should read this section before upgrading to Consul 1.4.0 and [migrating](/docs/acl/acl-migrate-tokens.html)tokens. 21 - The [Legacy ACL System documentation](#legacy-acl-system) section details the 22 ACL system in Consul 1.3.0 and older. 23 24 # New ACL System Differences 25 26 The [ACL System documentation](/docs/acl/acl-system.html) and [legacy ACL 27 guide](/docs/acl/acl-legacy.html) describes the new and old systems in 28 detail. Below is a summary of the changes that need to be considered when 29 migrating legacy tokens to the new system. 30 31 ### Token and Policy Separation 32 33 You can use a single policy in the new system for all tokens that share access 34 rules. For example, all tokens created using the clone endpoint in the legacy 35 system can be represented with a single policy and a set of tokens that map to 36 that policy. 37 38 ### Rule Syntax Changes 39 40 The most significant change is that rules with selectors _no longer prefix match 41 by default_. In the legacy system the following rules would grant access to 42 nodes, services and keys _prefixed_ with foo. 43 44 ``` 45 node "foo" { policy = "write" } 46 service "foo" { policy = "write" } 47 key "foo" { policy = "write" } 48 ``` 49 50 In the new system the same syntax will only perform _exact_ match on the whole 51 node name, service name or key. 52 53 In general, exact match is what most operators intended most of the time so the 54 same policy can be kept, however if you rely on prefix match behavior then using 55 the same syntax will break behavior. 56 57 Prefix matching can be expressed in the new ACL system explicitly, making the 58 following rules in the new system exactly the same as the rules above in the 59 old. 60 61 ``` 62 node_prefix "foo" { policy = "write" } 63 service_prefix "foo" { policy = "write" } 64 key_prefix "foo" { policy = "write" } 65 ``` 66 67 ### API Separation 68 69 The "old" API endpoints below continue to work for backwards compatibility but 70 will continue to create or show only "legacy" tokens that can't take full 71 advantage of the new ACL system improvements. They are documented fully under 72 [Legacy Tokens](/api/acl/legacy.html). 73 74 - [`PUT /acl/create` - Create Legacy Token](/api/acl/legacy.html#create-acl-token) 75 - [`PUT /acl/update` - Update Legacy Token](/api/acl/legacy.html#update-acl-token) 76 - [`PUT /acl/destroy/:uuid` - Delete Legacy Token](/api/acl/legacy.html#delete-acl-token) 77 - [`GET /acl/info/:uuid` - Read Legacy Token](/api/acl/legacy.html#read-acl-token) 78 - [`PUT /acl/clone/:uuid` - Clone Legacy Token](/api/acl/legacy.html#clone-acl-token) 79 - [`GET /acl/list` - List Legacy Tokens](/api/acl/legacy.html#list-acls) 80 81 The new ACL system includes new API endpoints to manage 82 the [ACL System](/api/acl/acl.html), [Tokens](/api/acl/tokens.html) 83 and [Policies](/api/acl/policies.html). 84 85 86 # Legacy ACL System 87 88 Consul provides an optional Access Control List (ACL) system which can be used to control 89 access to data and APIs. The ACL is 90 [Capability-based](https://en.wikipedia.org/wiki/Capability-based_security), relying 91 on tokens to which fine grained rules can be applied. It is very similar to 92 [AWS IAM](http://aws.amazon.com/iam/) in many ways. 93 94 ## ACL System Overview 95 96 The ACL system is designed to be easy to use, fast to enforce, and flexible to new policies, 97 all while providing administrative insight. 98 99 #### ACL Tokens 100 101 The ACL system is based on tokens, which are managed by Consul operators via Consul's 102 [ACL API](/api/acl/acl.html), or systems like 103 [HashiCorp's Vault](https://www.vaultproject.io/docs/secrets/consul/index.html). 104 105 Every token has an ID, name, type, and rule set. The ID is a randomly generated 106 UUID, making it infeasible to guess. The name is opaque to Consul and human readable. 107 The type is either "client" (meaning the token cannot modify ACL rules) or "management" 108 (meaning the token is allowed to perform all actions). 109 110 The token ID is passed along with each RPC request to the servers. Consul's 111 [HTTP endpoints](/api/index.html) can accept tokens via the `token` 112 query string parameter, or the `X-Consul-Token` request header, or Authorization Bearer 113 token [RFC6750](https://tools.ietf.org/html/rfc6750). Consul's 114 [CLI commands](/docs/commands/index.html) can accept tokens via the 115 `token` argument, or the `CONSUL_HTTP_TOKEN` environment variable. 116 117 If no token is provided, the rules associated with a special, configurable anonymous 118 token are automatically applied. The anonymous token is managed using the 119 [ACL API](/api/acl/acl.html) like any other ACL token, but using `anonymous` for the ID. 120 121 #### ACL Rules and Scope 122 123 Tokens are bound to a set of rules that control which Consul resources the token 124 has access to. Policies can be defined in either a whitelist or blacklist mode 125 depending on the configuration of 126 [`acl_default_policy`](/docs/agent/options.html#acl_default_policy). If the default 127 policy is to "deny" all actions, then token rules can be set to whitelist specific 128 actions. In the inverse, the "allow" all default behavior is a blacklist where rules 129 are used to prohibit actions. By default, Consul will allow all actions. 130 131 The following table summarizes the ACL policies that are available for constructing 132 rules: 133 134 | Policy | Scope | 135 | ------------------------ | ----- | 136 | [`agent`](#agent-rules) | Utility operations in the [Agent API](/api/agent.html), other than service and check registration | 137 | [`event`](#event-rules) | Listing and firing events in the [Event API](/api/event.html) | 138 | [`key`](#key-value-rules) | Key/value store operations in the [KV Store API](/api/kv.html) | 139 | [`keyring`](#keyring-rules) | Keyring operations in the [Keyring API](/api/operator/keyring.html) | 140 | [`node`](#node-rules) | Node-level catalog operations in the [Catalog API](/api/catalog.html), [Health API](/api/health.html), [Prepared Query API](/api/query.html), [Network Coordinate API](/api/coordinate.html), and [Agent API](/api/agent.html) | 141 | [`operator`](#operator-rules) | Cluster-level operations in the [Operator API](/api/operator.html), other than the [Keyring API](/api/operator/keyring.html) | 142 | [`query`](#prepared-query-rules) | Prepared query operations in the [Prepared Query API](/api/query.html) 143 | [`service`](#service-rules) | Service-level catalog operations in the [Catalog API](/api/catalog.html), [Health API](/api/health.html), [Prepared Query API](/api/query.html), and [Agent API](/api/agent.html) | 144 | [`session`](#session-rules) | Session operations in the [Session API](/api/session.html) | 145 146 Since Consul snapshots actually contain ACL tokens, the 147 [Snapshot API](/api/snapshot.html) requires a management token for snapshot operations 148 and does not use a special policy. 149 150 The following resources are not covered by ACL policies: 151 152 1. The [Status API](/api/status.html) is used by servers when bootstrapping and exposes 153 basic IP and port information about the servers, and does not allow modification 154 of any state. 155 156 2. The datacenter listing operation of the 157 [Catalog API](/api/catalog.html#list-datacenters) similarly exposes the names of known 158 Consul datacenters, and does not allow modification of any state. 159 160 Constructing rules from these policies is covered in detail in the 161 [Rule Specification](#rule-specification) section below. 162 163 #### ACL Datacenter 164 165 All nodes (clients and servers) must be configured with a 166 [`primary_datacenter`](/docs/agent/options.html#primary_datacenter) which enables ACL 167 enforcement but also specifies the authoritative datacenter. Consul relies on 168 [RPC forwarding](/docs/internals/architecture.html) to support multi-datacenter 169 configurations. However, because requests can be made across datacenter boundaries, 170 ACL tokens must be valid globally. To avoid consistency issues, a single datacenter 171 is considered authoritative and stores the canonical set of tokens. 172 173 When a request is made to an agent in a non-authoritative datacenter, it must be 174 resolved into the appropriate policy. This is done by reading the token from the 175 authoritative server and caching the result for a configurable 176 [`acl_ttl`](/docs/agent/options.html#acl_ttl). The implication of caching is that 177 the cache TTL is an upper bound on the staleness of policy that is enforced. It is 178 possible to set a zero TTL, but this has adverse performance impacts, as every 179 request requires refreshing the policy via an RPC call. 180 181 During an outage of the ACL datacenter, or loss of connectivity, the cache will be 182 used as long as the TTL is valid, or the cache may be extended if the 183 [`acl_down_policy`](/docs/agent/options.html#acl_down_policy) is set accordingly. 184 This configuration also allows the ACL system to fail open or closed. 185 [ACL replication](#replication) is also available to allow for the full set of ACL 186 tokens to be replicated for use during an outage. 187 188 ## Configuring ACLs 189 190 ACLs are configured using several different configuration options. These are marked 191 as to whether they are set on servers, clients, or both. 192 193 | Configuration Option | Servers | Clients | Purpose | 194 | -------------------- | ------- | ------- | ------- | 195 | [`primary_datacenter`](/docs/agent/options.html#primary_datacenter) | `REQUIRED` | `REQUIRED` | Master control that enables ACLs by defining the authoritative Consul datacenter for ACLs | 196 | [`acl_default_policy`](/docs/agent/options.html#acl_default_policy_legacy) | `OPTIONAL` | `N/A` | Determines whitelist or blacklist mode | 197 | [`acl_down_policy`](/docs/agent/options.html#acl_down_policy_legacy) | `OPTIONAL` | `OPTIONAL` | Determines what to do when the ACL datacenter is offline | 198 | [`acl_ttl`](/docs/agent/options.html#acl_ttl_legacy) | `OPTIONAL` | `OPTIONAL` | Determines time-to-live for cached ACLs | 199 200 There are some additional configuration items related to [ACL replication](#replication) and 201 [Version 8 ACL support](#version_8_acls). These are discussed in those respective sections 202 below. 203 204 A number of special tokens can also be configured which allow for bootstrapping the ACL 205 system, or accessing Consul in special situations: 206 207 | Special Token | Servers | Clients | Purpose | 208 | ------------- | ------- | ------- | ------- | 209 | [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token_legacy) | `OPTIONAL` | `OPTIONAL` | Special token that can be used to access [Agent API](/api/agent.html) when the ACL datacenter isn't available, or servers are offline (for clients); used for setting up the cluster such as doing initial join operations, see the [ACL Agent Master Token](#acl-agent-master-token) section for more details | 210 | [`acl_agent_token`](/docs/agent/options.html#acl_agent_token_legacy) | `OPTIONAL` | `OPTIONAL` | Special token that is used for an agent's internal operations, see the [ACL Agent Token](#acl-agent-token) section for more details | 211 | [`acl_master_token`](/docs/agent/options.html#acl_master_token_legacy) | `REQUIRED` | `N/A` | Special token used to bootstrap the ACL system, see the [Bootstrapping ACLs](#bootstrapping-acls) section for more details | 212 | [`acl_token`](/docs/agent/options.html#acl_token_legacy) | `OPTIONAL` | `OPTIONAL` | Default token to use for client requests where no token is supplied; this is often configured with read-only access to services to enable DNS service discovery on agents | 213 214 In Consul 0.9.1 and later, the agent ACL tokens can be introduced or updated via the 215 [/v1/agent/token API](/api/agent.html#update-acl-tokens). 216 217 #### ACL Agent Master Token 218 219 Since the [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token_legacy) is designed to be used when the Consul servers are not available, its policy is managed locally on the agent and does not need to have a token defined on the Consul servers via the ACL API. Once set, it implicitly has the following policy associated with it (the `node` policy was added in Consul 0.9.0): 220 221 ```text 222 agent "<node name of agent>" { 223 policy = "write" 224 } 225 node "" { 226 policy = "read" 227 } 228 ``` 229 230 In Consul 0.9.1 and later, the agent ACL tokens can be introduced or updated via the 231 [/v1/agent/token API](/api/agent.html#update-acl-tokens). 232 233 #### ACL Agent Token 234 235 The [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) is a special token that is used for an agent's internal operations. It isn't used directly for any user-initiated operations like the [`acl_token`](/docs/agent/options.html#acl_token), though if the `acl_agent_token` isn't configured the `acl_token` will be used. The ACL agent token is used for the following operations by the agent: 236 237 1. Updating the agent's node entry using the [Catalog API](/api/catalog.html), including updating its node metadata, tagged addresses, and network coordinates 238 2. Performing [anti-entropy](/docs/internals/anti-entropy.html) syncing, in particular reading the node metadata and services registered with the catalog 239 3. Reading and writing the special `_rexec` section of the KV store when executing [`consul exec`](/docs/commands/exec.html) commands 240 241 Here's an example policy sufficient to accomplish the above for a node called `mynode`: 242 243 ```text 244 node "mynode" { 245 policy = "write" 246 } 247 service "" { 248 policy = "read" 249 } 250 key "_rexec" { 251 policy = "write" 252 } 253 ``` 254 255 The `service` policy needs `read` access for any services that can be registered on the agent. If [remote exec is disabled](/docs/agent/options.html#disable_remote_exec), the default, then the `key` policy can be omitted. 256 257 In Consul 0.9.1 and later, the agent ACL tokens can be introduced or updated via the 258 [/v1/agent/token API](/api/agent.html#update-acl-tokens). 259 260 ## Bootstrapping ACLs 261 262 Bootstrapping ACLs on a new cluster requires a few steps, outlined in the examples in this 263 section. 264 265 #### Enable ACLs on the Consul Servers 266 267 The first step for bootstrapping ACLs is to enable ACLs on the Consul servers in the ACL 268 datacenter. In this example, we are configuring the following: 269 270 1. An ACL datacenter of "dc1", which is where these servers are 271 2. An ACL master token of "b1gs33cr3t"; see below for an alternative using the [/v1/acl/bootstrap API](/api/acl/acl.html#bootstrap-acls) 272 3. A default policy of "deny" which means we are in whitelist mode 273 4. A down policy of "extend-cache" which means that we will ignore token TTLs during an 274 outage 275 276 Here's the corresponding JSON configuration file: 277 278 ```json 279 { 280 "primary_datacenter": "dc1", 281 "acl_master_token": "b1gs33cr3t", 282 "acl_default_policy": "deny", 283 "acl_down_policy": "extend-cache" 284 } 285 ``` 286 287 The servers will need to be restarted to load the new configuration. Please take care 288 to start the servers one at a time, and ensure each server has joined and is operating 289 correctly before starting another. 290 291 The [`acl_master_token`](/docs/agent/options.html#acl_master_token) will be created 292 as a "management" type token automatically. The 293 [`acl_master_token`](/docs/agent/options.html#acl_master_token) is only installed when 294 a server acquires cluster leadership. If you would like to install or change the 295 [`acl_master_token`](/docs/agent/options.html#acl_master_token), set the new value for 296 [`acl_master_token`](/docs/agent/options.html#acl_master_token) in the configuration 297 for all servers. Once this is done, restart the current leader to force a leader election. 298 299 In Consul 0.9.1 and later, you can use the [/v1/acl/bootstrap API](/api/acl/acl.html#bootstrap-acls) 300 to make the initial master token, so a token never needs to be placed into a configuration 301 file. To use this approach, omit `acl_master_token` from the above config and then call the API: 302 303 ```text 304 $ curl \ 305 --request PUT \ 306 http://127.0.0.1:8500/v1/acl/bootstrap 307 308 {"ID":"fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1"} 309 ``` 310 311 The returned token is the initial management token, which is randomly generated by Consul. 312 It's only possible to bootstrap one time, and bootstrapping will be disabled if a master 313 token was configured and created. 314 315 Once the ACL system is bootstrapped, ACL tokens can be managed through the 316 [ACL API](/api/acl/acl.html). 317 318 #### Create an Agent Token 319 320 After the servers are restarted above, you will see new errors in the logs of the Consul 321 servers related to permission denied errors: 322 323 ``` 324 2017/07/08 23:38:24 [WARN] agent: Node info update blocked by ACLs 325 2017/07/08 23:38:44 [WARN] agent: Coordinate update blocked by ACLs 326 ``` 327 328 These errors are because the agent doesn't yet have a properly configured 329 [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) that it can use for its 330 own internal operations like updating its node information in the catalog and performing 331 [anti-entropy](/docs/internals/anti-entropy.html) syncing. We can create a token using the 332 ACL API, and the ACL master token we set in the previous step: 333 334 ```text 335 $ curl \ 336 --request PUT \ 337 --header "X-Consul-Token: b1gs33cr3t" \ 338 --data \ 339 '{ 340 "Name": "Agent Token", 341 "Type": "client", 342 "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"read\" }" 343 }' http://127.0.0.1:8500/v1/acl/create 344 345 {"ID":"fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1"} 346 ``` 347 348 The returned value is the newly-created token. We can now add this to our Consul server 349 configuration and restart the servers once more to apply it: 350 351 ```json 352 { 353 "primary_datacenter": "dc1", 354 "acl_master_token": "b1gs33cr3t", 355 "acl_default_policy": "deny", 356 "acl_down_policy": "extend-cache", 357 "acl_agent_token": "fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1" 358 } 359 ``` 360 361 In Consul 0.9.1 and later you can also introduce the agent token using an API, 362 so it doesn't need to be set in the configuration file: 363 364 ```text 365 $ curl \ 366 --request PUT \ 367 --header "X-Consul-Token: b1gs33cr3t" \ 368 --data \ 369 '{ 370 "Token": "fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1" 371 }' http://127.0.0.1:8500/v1/agent/token/acl_agent_token 372 ``` 373 374 With that ACL agent token set, the servers will be able to sync themselves with the 375 catalog: 376 377 ``` 378 2017/07/08 23:42:59 [INFO] agent: Synced node info 379 ``` 380 381 See the [ACL Agent Token](#acl-agent-token) section for more details. 382 383 #### Enable ACLs on the Consul Clients 384 385 Since ACL enforcement also occurs on the Consul clients, we need to also restart them 386 with a configuration file that enables ACLs: 387 388 ```json 389 { 390 "primary_datacenter": "dc1", 391 "acl_down_policy": "extend-cache", 392 "acl_agent_token": "fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1" 393 } 394 ``` 395 396 Similar to the previous example, in Consul 0.9.1 and later you can also introduce the 397 agent token using an API, so it doesn't need to be set in the configuration file: 398 399 ```text 400 $ curl \ 401 --request PUT \ 402 --header "X-Consul-Token: b1gs33cr3t" \ 403 --data \ 404 '{ 405 "Token": "fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1" 406 }' http://127.0.0.1:8500/v1/agent/token/acl_agent_token 407 ``` 408 409 We used the same ACL agent token that we created for the servers, which will work since 410 it was not specific to any node or set of service prefixes. In a more locked-down 411 environment it is recommended that each client get an ACL agent token with `node` write 412 privileges for just its own node name prefix, and `service` read privileges for just the 413 service prefixes expected to be registered on that client. 414 415 [Anti-entropy](/docs/internals/anti-entropy.html) syncing requires the ACL agent token 416 to have `service` read privileges for all services that may be registered with the agent, 417 so generally an empty `service` prefix can be used, as shown in the example. 418 419 Clients will report similar permission denied errors until they are restarted with an ACL 420 agent token. 421 422 #### Set an Anonymous Policy (Optional) 423 424 At this point ACLs are bootstrapped with ACL agent tokens configured, but there are no 425 other policies set up. Even basic operations like `consul members` will be restricted 426 by the ACL default policy of "deny": 427 428 ``` 429 $ consul members 430 ``` 431 432 We don't get an error since the ACL has filtered what we see, and we aren't allowed to 433 see any nodes by default. 434 435 If we supply the token we created above we will be able to see a listing of nodes because 436 it has write privileges to an empty `node` prefix, meaning it has access to all nodes: 437 438 ``` 439 $ CONSUL_HTTP_TOKEN=fe3b8d40-0ee0-8783-6cc2-ab1aa9bb16c1 consul members 440 Node Address Status Type Build Protocol DC 441 node-1 127.0.0.1:8301 alive server 0.9.0dev 2 dc1 442 node-2 127.0.0.2:8301 alive client 0.9.0dev 2 dc1 443 ``` 444 445 It's pretty common in many environments to allow listing of all nodes, even without a 446 token. The policies associated with the special anonymous token can be updated to 447 configure Consul's behavior when no token is supplied. The anonymous token is managed 448 like any other ACL token, except that `anonymous` is used for the ID. In this example 449 we will give the anonymous token read privileges for all nodes: 450 451 ```text 452 $ curl \ 453 --request PUT \ 454 --header "X-Consul-Token: b1gs33cr3t" \ 455 --data \ 456 '{ 457 "ID": "anonymous", 458 "Type": "client", 459 "Rules": "node \"\" { policy = \"read\" }" 460 }' http://127.0.0.1:8500/v1/acl/update 461 462 {"ID":"anonymous"} 463 ``` 464 465 The anonymous token is implicitly used if no token is supplied, so now we can run 466 `consul members` without supplying a token and we will be able to see the nodes: 467 468 ``` 469 $ consul members 470 Node Address Status Type Build Protocol DC 471 node-1 127.0.0.1:8301 alive server 0.9.0dev 2 dc1 472 node-2 127.0.0.2:8301 alive client 0.9.0dev 2 dc1 473 ``` 474 475 The anonymous token is also used for DNS lookups since there's no way to pass a 476 token as part of a DNS request. Here's an example lookup for the "consul" service: 477 478 ``` 479 $ dig @127.0.0.1 -p 8600 consul.service.consul 480 481 ; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 consul.service.consul 482 ; (1 server found) 483 ;; global options: +cmd 484 ;; Got answer: 485 ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 9648 486 ;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 487 ;; WARNING: recursion requested but not available 488 489 ;; QUESTION SECTION: 490 ;consul.service.consul. IN A 491 492 ;; AUTHORITY SECTION: 493 consul. 0 IN SOA ns.consul. postmaster.consul. 1499584110 3600 600 86400 0 494 495 ;; Query time: 2 msec 496 ;; SERVER: 127.0.0.1#8600(127.0.0.1) 497 ;; WHEN: Sun Jul 9 00:08:30 2017 498 ;; MSG SIZE rcvd: 89 499 ``` 500 501 Now we get an `NXDOMAIN` error because the anonymous token doesn't have access to the 502 "consul" service. Let's add that to the anonymous token's policy: 503 504 ```text 505 $ curl \ 506 --request PUT \ 507 --header "X-Consul-Token: b1gs33cr3t" \ 508 --data \ 509 '{ 510 "ID": "anonymous", 511 "Type": "client", 512 "Rules": "node \"\" { policy = \"read\" } service \"consul\" { policy = \"read\" }" 513 }' http://127.0.0.1:8500/v1/acl/update 514 515 {"ID":"anonymous"} 516 ``` 517 518 With that new policy in place, the DNS lookup will succeed: 519 520 ``` 521 $ dig @127.0.0.1 -p 8600 consul.service.consul 522 523 ; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 consul.service.consul 524 ; (1 server found) 525 ;; global options: +cmd 526 ;; Got answer: 527 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46006 528 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 529 ;; WARNING: recursion requested but not available 530 531 ;; QUESTION SECTION: 532 ;consul.service.consul. IN A 533 534 ;; ANSWER SECTION: 535 consul.service.consul. 0 IN A 127.0.0.1 536 537 ;; Query time: 0 msec 538 ;; SERVER: 127.0.0.1#8600(127.0.0.1) 539 ;; WHEN: Sun Jul 9 00:11:14 2017 540 ;; MSG SIZE rcvd: 55 541 ``` 542 543 The next section shows an alternative to the anonymous token. 544 545 #### Set Agent-Specific Default Tokens (Optional) 546 547 An alternative to the anonymous token is the [`acl_token`](/docs/agent/options.html#acl_token) 548 configuration item. When a request is made to a particular Consul agent and no token is 549 supplied, the [`acl_token`](/docs/agent/options.html#acl_token) will be used for the token, 550 instead of being left empty which would normally invoke the anonymous token. 551 552 In Consul 0.9.1 and later, the agent ACL tokens can be introduced or updated via the 553 [/v1/agent/token API](/api/agent.html#update-acl-tokens). 554 555 This behaves very similarly to the anonymous token, but can be configured differently on each 556 agent, if desired. For example, this allows more fine grained control of what DNS requests a 557 given agent can service, or can give the agent read access to some key-value store prefixes by 558 default. 559 560 If using [`acl_token`](/docs/agent/options.html#acl_token), then it's likely the anonymous 561 token will have a more restrictive policy than shown in the examples here. 562 563 #### Create Tokens for UI Use (Optional) 564 565 If you utilize the Consul UI with a restrictive ACL policy, as above, the UI will 566 not function fully using the anonymous ACL token. It is recommended 567 that a UI-specific ACL token is used, which can be set in the UI during the 568 web browser session to authenticate the interface. 569 570 ```text 571 $ curl \ 572 --request PUT \ 573 --header "X-Consul-Token: b1gs33cr3t" \ 574 --data \ 575 '{ 576 "Name": "UI Token", 577 "Type": "client", 578 "Rules": "key \"\" { policy = \"write\" } node \"\" { policy = \"read\" } service \"\" { policy = \"read\" }" 579 }' http://127.0.0.1:8500/v1/acl/create 580 {"ID":"d0a9f330-2f9d-0a8c-d2af-1e9ceda354e6"} 581 ``` 582 583 The token can then be set on the "settings" page of the UI. 584 585 #### Next Steps 586 587 The examples above configure a basic ACL environment with the ability to see all nodes 588 by default, and limited access to just the "consul" service. The [ACL API](/api/acl/acl.html) 589 can be used to create tokens for applications specific to their intended use, and to create 590 more specific ACL agent tokens for each agent's expected role. 591 592 Also see [HashiCorp's Vault](https://www.vaultproject.io/docs/secrets/consul/index.html), which 593 has an integration with Consul that allows it to generate ACL tokens on the fly and to manage 594 their lifetimes. 595 596 ## Rule Specification 597 598 A core part of the ACL system is the rule language which is used to describe the policy 599 that must be enforced. Most of the ACL rules are prefix-based, allowing operators to 600 define different namespaces within Consul's resource areas like the catalog and key/value 601 store, in order to delegate responsibility for these namespaces. Policies can have several 602 dispositions: 603 604 * `read`: allow the resource to be read but not modified 605 * `write`: allow the resource to be read and modified 606 * `deny`: do not allow the resource to be read or modified 607 608 With prefix-based rules, the most specific prefix match determines the action. This 609 allows for flexible rules like an empty prefix to allow read-only access to all 610 resources, along with some specific prefixes that allow write access or that are 611 denied all access. 612 613 We make use of the 614 [HashiCorp Configuration Language (HCL)](https://github.com/hashicorp/hcl/) to specify 615 rules. This language is human readable and interoperable with JSON making it easy to 616 machine-generate. Rules can make use of one or more policies. 617 618 Specification in the HCL format looks like: 619 620 ```text 621 # These control access to the key/value store. 622 key "" { 623 policy = "read" 624 } 625 key "foo/" { 626 policy = "write" 627 } 628 key "foo/private/" { 629 policy = "deny" 630 } 631 632 # This controls access to cluster-wide Consul operator information. 633 operator = "read" 634 ``` 635 636 This is equivalent to the following JSON input: 637 638 ```javascript 639 { 640 "key": { 641 "": { 642 "policy": "read" 643 }, 644 "foo/": { 645 "policy": "write" 646 }, 647 "foo/private/": { 648 "policy": "deny" 649 } 650 }, 651 "operator": "read" 652 } 653 ``` 654 655 The [ACL API](/api/acl/acl.html) allows either HCL or JSON to be used to define the content 656 of the rules section. 657 658 Here's a sample request using the HCL form: 659 660 ```text 661 $ curl \ 662 --request PUT \ 663 --data \ 664 '{ 665 "Name": "my-app-token", 666 "Type": "client", 667 "Rules": "key \"\" { policy = \"read\" } key \"foo/\" { policy = \"write\" } key \"foo/private/\" { policy = \"deny\" } operator = \"read\"" 668 }' http://127.0.0.1:8500/v1/acl/create?token=<management token> 669 ``` 670 671 Here's an equivalent request using the JSON form: 672 673 ```text 674 $ curl \ 675 --request PUT \ 676 --data \ 677 '{ 678 "Name": "my-app-token", 679 "Type": "client", 680 "Rules": "{\"key\":{\"\":{\"policy\":\"read\"},\"foo/\":{\"policy\":\"write\"},\"foo/private\":{\"policy\":\"deny\"}},\"operator\":\"read\"}" 681 }' http://127.0.0.1:8500/v1/acl/create?token=<management token> 682 ``` 683 684 On success, the token ID is returned: 685 686 ```json 687 { 688 "ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e" 689 } 690 ``` 691 692 This token ID can then be passed into Consul's HTTP APIs via the `token` 693 query string parameter, or the `X-Consul-Token` request header, or Authorization 694 Bearer token header, or Consul's CLI commands via the `token` argument, 695 or the `CONSUL_HTTP_TOKEN` environment variable. 696 697 #### Agent Rules 698 699 The `agent` policy controls access to the utility operations in the [Agent API](/api/agent.html), 700 such as join and leave. All of the catalog-related operations are covered by the [`node`](#node-rules) 701 and [`service`](#service-rules) policies instead. 702 703 Agent rules look like this: 704 705 ```text 706 agent "" { 707 policy = "read" 708 } 709 agent "foo" { 710 policy = "write" 711 } 712 agent "bar" { 713 policy = "deny" 714 } 715 ``` 716 717 Agent rules are keyed by the node name prefix they apply to, using the longest prefix match rule. In 718 the example above, the rules allow read-only access to any node name with the empty prefix, allow 719 read-write access to any node name that starts with "foo", and deny all access to any node name that 720 starts with "bar". 721 722 Since [Agent API](/api/agent.html) utility operations may be required before an agent is joined to 723 a cluster, or during an outage of the Consul servers or ACL datacenter, a special token may be 724 configured with [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token) to allow 725 write access to these operations even if no ACL resolution capability is available. 726 727 #### Event Rules 728 729 The `event` policy controls access to event operations in the [Event API](/api/event.html), such as 730 firing events and listing events. 731 732 Event rules look like this: 733 734 ```text 735 event "" { 736 policy = "read" 737 } 738 event "deploy" { 739 policy = "write" 740 } 741 ``` 742 743 Event rules are keyed by the event name prefix they apply to, using the longest prefix match rule. 744 In the example above, the rules allow read-only access to any event, and firing of any event that 745 starts with "deploy". 746 747 The [`consul exec`](/docs/commands/exec.html) command uses events with the "_rexec" prefix during 748 operation, so to enable this feature in a Consul environment with ACLs enabled, you will need to 749 give agents a token with access to this event prefix, in addition to configuring 750 [`disable_remote_exec`](/docs/agent/options.html#disable_remote_exec) to `false`. 751 752 #### Key/Value Rules 753 754 The `key` policy controls access to key/value store operations in the [KV API](/api/kv.html). Key 755 rules look like this: 756 757 ```text 758 key "" { 759 policy = "read" 760 } 761 key "foo" { 762 policy = "write" 763 } 764 key "bar" { 765 policy = "deny" 766 } 767 ``` 768 769 Key rules are keyed by the key name prefix they apply to, using the longest prefix match rule. In 770 the example above, the rules allow read-only access to any key name with the empty prefix, allow 771 read-write access to any key name that starts with "foo", and deny all access to any key name that 772 starts with "bar". 773 774 #### List Policy for Keys 775 776 Consul 1.0 introduces a new `list` policy for keys that is only enforced when opted in via the boolean config param "acl_enable_key_list_policy". 777 `list` controls access to recursively list entries and keys, and enables more fine grained policies. With "acl_enable_key_list_policy", 778 recursive reads via [the KV API](/api/kv.html#recurse) with an invalid token result in a 403. Example: 779 780 ```text 781 key "" { 782 policy = "deny" 783 } 784 785 key "bar" { 786 policy = "list" 787 } 788 789 key "baz" { 790 policy = "read" 791 } 792 ``` 793 794 In the example above, the rules allow reading the key "baz", and only allow recursive reads on the prefix "bar". 795 796 A token with `write` access on a prefix also has `list` access. A token with `list` access on a prefix also has `read` access on all its suffixes. 797 798 #### Sentinel Integration 799 800 Consul Enterprise supports additional optional fields for key write policies for 801 [Sentinel](https://docs.hashicorp.com/sentinel/app/consul/) integration. An example key rule with a 802 Sentinel code policy looks like this: 803 804 ```text 805 key "foo" { 806 policy = "write" 807 sentinel { 808 code = <<EOF 809 import "strings" 810 main = rule { strings.has_suffix(value, "bar") } 811 EOF 812 enforcementlevel = "hard-mandatory" 813 } 814 } 815 ``` 816 817 For more detailed documentation, see the [Consul Sentinel Guide](/docs/guides/sentinel.html). 818 819 #### Keyring Rules 820 821 The `keyring` policy controls access to keyring operations in the 822 [Keyring API](/api/operator/keyring.html). 823 824 Keyring rules look like this: 825 826 ```text 827 keyring = "write" 828 ``` 829 830 There's only one keyring policy allowed per rule set, and its value is set to one of the policy 831 dispositions. In the example above, the keyring may be read and updated. 832 833 #### Node Rules 834 835 The `node` policy controls node-level registration and read access to the [Catalog API](/api/catalog.html), 836 service discovery with the [Health API](/api/health.html), and filters results in [Agent API](/api/agent.html) 837 operations like fetching the list of cluster members. 838 839 Node rules look like this: 840 841 ```text 842 node "" { 843 policy = "read" 844 } 845 node "app" { 846 policy = "write" 847 } 848 node "admin" { 849 policy = "deny" 850 } 851 ``` 852 853 Node rules are keyed by the node name prefix they apply to, using the longest prefix match rule. In 854 the example above, the rules allow read-only access to any node name with the empty prefix, allow 855 read-write access to any node name that starts with "app", and deny all access to any node name that 856 starts with "admin". 857 858 Agents need to be configured with an [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) 859 with at least "write" privileges to their own node name in order to register their information with 860 the catalog, such as node metadata and tagged addresses. If this is configured incorrectly, the agent 861 will print an error to the console when it tries to sync its state with the catalog. 862 863 Consul's DNS interface is also affected by restrictions on node rules. If the 864 [`acl_token`](/docs/agent/options.html#acl_token) used by the agent does not have "read" access to a 865 given node, then the DNS interface will return no records when queried for it. 866 867 When reading from the catalog or retrieving information from the health endpoints, node rules are 868 used to filter the results of the query. This allows for configurations where a token has access 869 to a given service name, but only on an allowed subset of node names. 870 871 Node rules come into play when using the [Agent API](/api/agent.html) to register node-level 872 checks. The agent will check tokens locally as a check is registered, and Consul also performs 873 periodic [anti-entropy](/docs/internals/anti-entropy.html) syncs, which may require an 874 ACL token to complete. To accommodate this, Consul provides two methods of configuring ACL tokens 875 to use for registration events: 876 877 1. Using the [acl_token](/docs/agent/options.html#acl_token) configuration 878 directive. This allows a single token to be configured globally and used 879 during all check registration operations. 880 2. Providing an ACL token with service and check definitions at 881 registration time. This allows for greater flexibility and enables the use 882 of multiple tokens on the same agent. Examples of what this looks like are 883 available for both [services](/docs/agent/services.html) and 884 [checks](/docs/agent/checks.html). Tokens may also be passed to the 885 [HTTP API](/api/index.html) for operations that require them. 886 887 In addition to ACLs, in Consul 0.9.0 and later, the agent must be configured with 888 [`enable_script_checks`](/docs/agent/options.html#_enable_script_checks) set to `true` in order to enable 889 script checks. 890 891 #### Operator Rules 892 893 The `operator` policy controls access to cluster-level operations in the 894 [Operator API](/api/operator.html), other than the [Keyring API](/api/operator/keyring.html). 895 896 Operator rules look like this: 897 898 ```text 899 operator = "read" 900 ``` 901 902 There's only one operator policy allowed per rule set, and its value is set to one of the policy 903 dispositions. In the example above, the token could be used to query the operator endpoints for 904 diagnostic purposes but not make any changes. 905 906 #### Prepared Query Rules 907 908 The `query` policy controls access to create, update, and delete prepared queries in the 909 [Prepared Query API](/api/query.html). Executing queries is subject to `node` and `service` 910 policies, as will be explained below. 911 912 Query rules look like this: 913 914 ```text 915 query "" { 916 policy = "read" 917 } 918 query "foo" { 919 policy = "write" 920 } 921 ``` 922 923 Query rules are keyed by the query name prefix they apply to, using the longest prefix match rule. In 924 the example above, the rules allow read-only access to any query name with the empty prefix, and allow 925 read-write access to any query name that starts with "foo". This allows control of the query namespace 926 to be delegated based on ACLs. 927 928 There are a few variations when using ACLs with prepared queries, each of which uses ACLs in one of two 929 ways: open, protected by unguessable IDs or closed, managed by ACL policies. These variations are covered 930 here, with examples: 931 932 * Static queries with no `Name` defined are not controlled by any ACL policies. 933 These types of queries are meant to be ephemeral and not shared to untrusted 934 clients, and they are only reachable if the prepared query ID is known. Since 935 these IDs are generated using the same random ID scheme as ACL Tokens, it is 936 infeasible to guess them. When listing all prepared queries, only a management 937 token will be able to see these types, though clients can read instances for 938 which they have an ID. An example use for this type is a query built by a 939 startup script, tied to a session, and written to a configuration file for a 940 process to use via DNS. 941 942 * Static queries with a `Name` defined are controlled by the `query` ACL policy. 943 Clients are required to have an ACL token with a prefix sufficient to cover 944 the name they are trying to manage, with a longest prefix match providing a 945 way to define more specific policies. Clients can list or read queries for 946 which they have "read" access based on their prefix, and similar they can 947 update any queries for which they have "write" access. An example use for 948 this type is a query with a well-known name (eg. `prod-master-customer-db`) 949 that is used and known by many clients to provide geo-failover behavior for 950 a database. 951 952 * [Template queries](/api/query.html#templates) 953 queries work like static queries with a `Name` defined, except that a catch-all 954 template with an empty `Name` requires an ACL token that can write to any query 955 prefix. 956 957 When prepared queries are executed via DNS lookups or HTTP requests, the ACL 958 checks are run against the service being queried, similar to how ACLs work with 959 other service lookups. There are several ways the ACL token is selected for this 960 check: 961 962 * If an ACL Token was captured when the prepared query was defined, it will be 963 used to perform the service lookup. This allows queries to be executed by 964 clients with lesser or even no ACL Token, so this should be used with care. 965 966 * If no ACL Token was captured, then the client's ACL Token will be used to 967 perform the service lookup. 968 969 * If no ACL Token was captured and the client has no ACL Token, then the 970 anonymous token will be used to perform the service lookup. 971 972 In the common case, the ACL Token of the invoker is used 973 to test the ability to look up a service. If a `Token` was specified when the 974 prepared query was created, the behavior changes and now the captured 975 ACL Token set by the definer of the query is used when looking up a service. 976 977 Capturing ACL Tokens is analogous to 978 [PostgreSQL’s](http://www.postgresql.org/docs/current/static/sql-createfunction.html) 979 `SECURITY DEFINER` attribute which can be set on functions, and using the client's ACL 980 Token is similar to the complementary `SECURITY INVOKER` attribute. 981 982 Prepared queries were originally introduced in Consul 0.6.0, and ACL behavior remained 983 unchanged through version 0.6.3, but was then changed to allow better management of the 984 prepared query namespace. 985 986 These differences are outlined in the table below: 987 988 <table class="table table-bordered table-striped"> 989 <tr> 990 <th>Operation</th> 991 <th>Version <= 0.6.3 </th> 992 <th>Version > 0.6.3 </th> 993 </tr> 994 <tr> 995 <td>Create static query without `Name`</td> 996 <td>The ACL Token used to create the prepared query is checked to make sure it can access the service being queried. This token is captured as the `Token` to use when executing the prepared query.</td> 997 <td>No ACL policies are used as long as no `Name` is defined. No `Token` is captured by default unless specifically supplied by the client when creating the query.</td> 998 </tr> 999 <tr> 1000 <td>Create static query with `Name`</td> 1001 <td>The ACL Token used to create the prepared query is checked to make sure it can access the service being queried. This token is captured as the `Token` to use when executing the prepared query.</td> 1002 <td>The client token's `query` ACL policy is used to determine if the client is allowed to register a query for the given `Name`. No `Token` is captured by default unless specifically supplied by the client when creating the query.</td> 1003 </tr> 1004 <tr> 1005 <td>Manage static query without `Name`</td> 1006 <td>The ACL Token used to create the query, or a management token must be supplied in order to perform these operations.</td> 1007 <td>Any client with the ID of the query can perform these operations.</td> 1008 </tr> 1009 <tr> 1010 <td>Manage static query with a `Name`</td> 1011 <td>The ACL token used to create the query, or a management token must be supplied in order to perform these operations.</td> 1012 <td>Similar to create, the client token's `query` ACL policy is used to determine if these operations are allowed.</td> 1013 </tr> 1014 <tr> 1015 <td>List queries</td> 1016 <td>A management token is required to list any queries.</td> 1017 <td>The client token's `query` ACL policy is used to determine which queries they can see. Only management tokens can see prepared queries without `Name`.</td> 1018 </tr> 1019 <tr> 1020 <td>Execute query</td> 1021 <td>Since a `Token` is always captured when a query is created, that is used to check access to the service being queried. Any token supplied by the client is ignored.</td> 1022 <td>The captured token, client's token, or anonymous token is used to filter the results, as described above.</td> 1023 </tr> 1024 </table> 1025 1026 #### Service Rules 1027 1028 The `service` policy controls service-level registration and read access to the [Catalog API](/api/catalog.html) 1029 and service discovery with the [Health API](/api/health.html). 1030 1031 Service rules look like this: 1032 1033 ```text 1034 service "" { 1035 policy = "read" 1036 } 1037 service "app" { 1038 policy = "write" 1039 } 1040 service "admin" { 1041 policy = "deny" 1042 } 1043 ``` 1044 1045 Service rules are keyed by the service name prefix they apply to, using the longest prefix match rule. In 1046 the example above, the rules allow read-only access to any service name with the empty prefix, allow 1047 read-write access to any service name that starts with "app", and deny all access to any service name that 1048 starts with "admin". 1049 1050 Consul's DNS interface is affected by restrictions on service rules. If the 1051 [`acl_token`](/docs/agent/options.html#acl_token) used by the agent does not have "read" access to a 1052 given service, then the DNS interface will return no records when queried for it. 1053 1054 When reading from the catalog or retrieving information from the health endpoints, service rules are 1055 used to filter the results of the query. 1056 1057 Service rules come into play when using the [Agent API](/api/agent.html) to register services or 1058 checks. The agent will check tokens locally as a service or check is registered, and Consul also 1059 performs periodic [anti-entropy](/docs/internals/anti-entropy.html) syncs, which may require an 1060 ACL token to complete. To accommodate this, Consul provides two methods of configuring ACL tokens 1061 to use for registration events: 1062 1063 1. Using the [acl_token](/docs/agent/options.html#acl_token) configuration 1064 directive. This allows a single token to be configured globally and used 1065 during all service and check registration operations. 1066 2. Providing an ACL token with service and check definitions at registration 1067 time. This allows for greater flexibility and enables the use of multiple 1068 tokens on the same agent. Examples of what this looks like are available for 1069 both [services](/docs/agent/services.html) and 1070 [checks](/docs/agent/checks.html). Tokens may also be passed to the [HTTP 1071 API](/api/index.html) for operations that require them. **Note:** all tokens 1072 passed to an agent are persisted on local disk to allow recovery from 1073 restarts. See [`-data-dir` flag 1074 documentation](/docs/agent/options.html#acl_token) for notes on securing 1075 access. 1076 1077 In addition to ACLs, in Consul 0.9.0 and later, the agent must be configured with 1078 [`enable_script_checks`](/docs/agent/options.html#_enable_script_checks) or 1079 [`enable_local_script_checks`](/docs/agent/options.html#_enable_local_script_checks) 1080 set to `true` in order to enable script checks. 1081 1082 1083 #### Session Rules 1084 1085 The `session` policy controls access to [Session API](/api/session.html) operations. 1086 1087 Session rules look like this: 1088 1089 ```text 1090 session "" { 1091 policy = "read" 1092 } 1093 session "app" { 1094 policy = "write" 1095 } 1096 session "admin" { 1097 policy = "deny" 1098 } 1099 ``` 1100 1101 Session rules are keyed by the node name prefix they apply to, using the longest prefix match rule. In 1102 the example above, the rules allow read-only access to sessions on node name with the empty prefix, allow 1103 creating sessions on any node name that starts with "app", and deny all access to any sessions on a node 1104 name that starts with "admin". 1105 1106 ## Advanced Topics 1107 1108 <a name="replication"></a> 1109 #### Outages and ACL Replication 1110 1111 The Consul ACL system is designed with flexible rules to accommodate for an outage 1112 of the [`primary_datacenter`](/docs/agent/options.html#primary_datacenter) or networking 1113 issues preventing access to it. In this case, it may be impossible for 1114 agents in non-authoritative datacenters to resolve tokens. Consul provides 1115 a number of configurable [`acl_down_policy`](/docs/agent/options.html#acl_down_policy) 1116 choices to tune behavior. It is possible to deny or permit all actions or to ignore 1117 cache TTLs and enter a fail-safe mode. The default is to ignore cache TTLs 1118 for any previously resolved tokens and to deny any uncached tokens. 1119 1120 Consul 0.7 added an ACL Replication capability that can allow non-authoritative 1121 datacenter agents to resolve even uncached tokens. This is enabled by setting an 1122 [`acl_replication_token`](/docs/agent/options.html#acl_replication_token) in the 1123 configuration on the servers in the non-authoritative datacenters. In Consul 1124 0.9.1 and later you can enable ACL replication using 1125 [`enable_acl_replication`](/docs/agent/options.html#enable_acl_replication) and 1126 then set the token later using the 1127 [agent token API](/api/agent.html#update-acl-tokens) on each server. This can 1128 also be used to rotate the token without restarting the Consul servers. 1129 1130 With replication enabled, the servers will maintain a replica of the authoritative 1131 datacenter's full set of ACLs on the non-authoritative servers. The ACL replication 1132 token needs to be a valid ACL token with management privileges, it can also be the 1133 same as the master ACL token. 1134 1135 Replication occurs with a background process that looks for new ACLs approximately 1136 every 30 seconds. Replicated changes are written at a rate that's throttled to 1137 100 updates/second, so it may take several minutes to perform the initial sync of 1138 a large set of ACLs. 1139 1140 If there's a partition or other outage affecting the authoritative datacenter, 1141 and the [`acl_down_policy`](/docs/agent/options.html#acl_down_policy) 1142 is set to "extend-cache", tokens will be resolved during the outage using the 1143 replicated set of ACLs. An [ACL replication status](/api/acl/acl.html#acl_replication_status) 1144 endpoint is available to monitor the health of the replication process. 1145 Also note that in recent versions of Consul (greater than 1.2.0), using 1146 `acl_down_policy = "async-cache"` refreshes token asynchronously when an ACL is 1147 already cached and is expired while similar semantics than "extend-cache". 1148 It allows to avoid having issues when connectivity with the authoritative is not completely 1149 broken, but very slow. 1150 1151 Locally-resolved ACLs will be cached using the [`acl_ttl`](/docs/agent/options.html#acl_ttl) 1152 setting of the non-authoritative datacenter, so these entries may persist in the 1153 cache for up to the TTL, even after the authoritative datacenter comes back online. 1154 1155 ACL replication can also be used to migrate ACLs from one datacenter to another 1156 using a process like this: 1157 1158 1. Enable ACL replication in all datacenters to allow continuation of service 1159 during the migration, and to populate the target datacenter. Verify replication 1160 is healthy and caught up to the current ACL index in the target datacenter 1161 using the [ACL replication status](/api/acl/acl.html#acl_replication_status) 1162 endpoint. 1163 2. Turn down the old authoritative datacenter servers. 1164 3. Rolling restart the agents in the target datacenter and change the 1165 `primary_datacenter` servers to itself. This will automatically turn off 1166 replication and will enable the datacenter to start acting as the authoritative 1167 datacenter, using its replicated ACLs from before. 1168 3. Rolling restart the agents in other datacenters and change their `primary_datacenter` 1169 configuration to the target datacenter. 1170 1171 <a name="version_8_acls"></a> 1172 #### Complete ACL Coverage in Consul 0.8 1173 1174 Consul 0.8 added many more ACL policy types and brought ACL enforcement to Consul 1175 agents for the first time. To ease the transition to Consul 0.8 for existing ACL 1176 users, there's a configuration option to disable these new features. To disable 1177 support for these new ACLs, set the 1178 [`acl_enforce_version_8`](/docs/agent/options.html#acl_enforce_version_8) configuration 1179 option to `false` on Consul clients and servers. 1180 1181 Here's a summary of the new features: 1182 1183 * Agents now check [`node`](#node-rules) and [`service`](#service-rules) ACL policies 1184 for catalog-related operations in `/v1/agent` endpoints, such as service and check 1185 registration and health check updates. 1186 * Agents enforce a new [`agent`](#agent-rules) ACL policy for utility operations in 1187 `/v1/agent` endpoints, such as joins and leaves. 1188 * A new [`node`](#node-rules) ACL policy is enforced throughout Consul, providing a 1189 mechanism to restrict registration and discovery of nodes by name. This also applies 1190 to service discovery, so provides an additional dimension for controlling access to 1191 services. 1192 * A new [`session`](#session-rules) ACL policy controls the ability to create session 1193 objects by node name. 1194 * Anonymous prepared queries (non-templates without a `Name`) now require a valid 1195 session, which ties their creation to the new [`session`](#session-rules) ACL policy. 1196 * The existing [`event`](#event-rules) ACL policy has been applied to the 1197 `/v1/event/list` endpoint. 1198 1199 Two new configuration options are used once version 8 ACLs are enabled: 1200 1201 * [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token) is used as 1202 a special access token that has `agent` ACL policy `write` privileges on each agent where 1203 it is configured, as well as `node` ACL policy `read` privileges for all nodes. This token 1204 should only be used by operators during outages when Consul servers aren't available to 1205 resolve ACL tokens. Applications should use regular ACL tokens during normal operation. 1206 * [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) is used internally by 1207 Consul agents to perform operations to the service catalog when registering themselves 1208 or sending network coordinates to the servers. This token must at least have `node` ACL 1209 policy `write` access to the node name it will register as in order to register any 1210 node-level information like metadata or tagged addresses. 1211 1212 Since clients now resolve ACLs locally, the [`acl_down_policy`](/docs/agent/options.html#acl_down_policy) 1213 now applies to Consul clients as well as Consul servers. This will determine what the 1214 client will do in the event that the servers are down. 1215 1216 Consul clients must have [`primary_datacenter`](/docs/agent/options.html#primary_datacenter) configured 1217 in order to enable agent-level ACL features. If this is set, the agents will contact the Consul 1218 servers to determine if ACLs are enabled at the cluster level. If they detect that ACLs are not 1219 enabled, they will check at most every 2 minutes to see if they have become enabled, and will 1220 start enforcing ACLs automatically. If an agent has an `primary_datacenter` defined, operators will 1221 need to use the [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token) to 1222 perform agent-level operations if the Consul servers aren't present (such as for a manual join 1223 to the cluster), unless the [`acl_down_policy`](/docs/agent/options.html#acl_down_policy) on the 1224 agent is set to "allow". 1225 1226 Non-server agents do not need to have the 1227 [`acl_master_token`](/docs/agent/options.html#acl_master_token) configured; it is not 1228 used by agents in any way.