github.com/KyaXTeam/consul@v1.4.5/website/source/docs/guides/acl-legacy.html.md (about)

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