github.com/outbrain/consul@v1.4.5/website/source/docs/agent/acl-system.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "ACL System"
     4  sidebar_current: "docs-agent-acl-system"
     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.4.0 and later:** This guide only applies in Consul versions 1.4.0 and later. The documentation for the legacy ACL system is [here](/docs/guides/acl-legacy.html)
    10  
    11  # ACL System
    12  
    13  Consul provides an optional Access Control List (ACL) system which can be used to control access to data and APIs.
    14  The ACL is [Capability-based](https://en.wikipedia.org/wiki/Capability-based_security), relying on tokens which
    15  are associated with policies to determine which fine grained rules can be applied. Consul's capability based
    16  ACL system is very similar to the design of [AWS IAM](https://aws.amazon.com/iam/).
    17  
    18  ## ACL System Overview
    19  
    20  The ACL system is designed to be easy to use and fast to enforce while providing administrative insight.
    21  At the highest level, there are two major components to the ACL system:
    22  
    23   * **ACL Policies** - Policies allow the grouping of a set of rules into a logical unit that can be reused and linked with
    24   many tokens.
    25  
    26   * **ACL Tokens** - Requests to Consul are authorized by using bearer token. Each ACL token has a public
    27   Accessor ID which is used to name a token, and a Secret ID which is used as the bearer token used to
    28   make requests to Consul.
    29  
    30   ACL tokens and policies are managed by Consul operators via Consul's
    31  [ACL API](/api/acl/acl.html), [ACL CLI](/docs/commands/acl.html), or systems like
    32  [HashiCorp's Vault](https://www.vaultproject.io/docs/secrets/consul/index.html).
    33  
    34  ### ACL Policies
    35  
    36  An ACL policy is a named set of rules and is composed of the following elements:
    37  
    38  * **ID** - The policies auto-generated public identifier.
    39  * **Name** - A unique meaningful name for the policy.
    40  * **Rules** - Set of rules granting or denying permissions. See the [Rule Specification](/docs/agent/acl-rules.html#rule-specification) documentation for more details.
    41  * **Datacenters** - A list of datacenters the policy is valid within.
    42  
    43  #### Builtin Policies
    44  
    45  * **Global Management** - Grants unrestricted privileges to any token that uses it. When created it will be named `global-management`
    46  and will be assigned the reserved ID of `00000000-0000-0000-0000-000000000001`. This policy can be renamed but modification
    47  of anything else including the rule set and datacenter scoping will be prevented by Consul.
    48  
    49  ### ACL Tokens
    50  
    51  ACL tokens are used to determine if the caller is authorized to perform an action. An ACL token is composed of the following
    52  elements:
    53  
    54  * **Accessor ID** - The token's public identifier.
    55  * **Secret ID** -The bearer token used when making requests to Consul.
    56  * **Description** - A human readable description of the token. (Optional)
    57  * **Policy Set** - The list of policies that are applicable for the token.
    58  * **Locality** - Indicates whether the token should be local to the datacenter it was created within or created in
    59  the primary datacenter and globally replicated.
    60  
    61  #### Builtin Tokens
    62  
    63  During cluster bootstrapping when ACLs are enabled both the special `anonymous` and the `master` token will be
    64  injected.
    65  
    66  * **Anonymous Token** - The anonymous token is used when a request is made to Consul without specifying a bearer token.
    67  The anonymous token's description and policies may be updated but Consul will prevent this tokens deletion. When created,
    68  it will be assigned `00000000-0000-0000-0000-000000000002` for its Accessor ID and `anonymous` for its Secret ID.
    69  
    70  * **Master Token** - When a master token is present within the Consul configuration, it is created and will be linked
    71  With the builtin Global Management policy giving it unrestricted privileges. The master token is created with the Secret ID
    72  set to the value of the configuration entry.
    73  
    74  #### Authorization
    75  
    76  The token Secret ID is passed along with each RPC request to the servers. Consul's
    77  [HTTP endpoints](/api/index.html) can accept tokens via the `token`
    78  query string parameter, the `X-Consul-Token` request header, or an 
    79  [RFC6750](https://tools.ietf.org/html/rfc6750) authorization bearer token. Consul's
    80  [CLI commands](/docs/commands/index.html) can accept tokens via the
    81  `token` argument, or the `CONSUL_HTTP_TOKEN` environment variable.
    82  
    83  If no token is provided for an HTTP request then Consul will use the default ACL token
    84  if it has been configured. If no default ACL token was configured then the anonymous
    85  token will be used.
    86  
    87  #### ACL Rules and Scope
    88  
    89  The rules from all policies linked with a token are combined to form that token's
    90  effective rule set. Policy rules can be defined in either a whitelist or blacklist
    91  mode depending on the configuration of [`acl_default_policy`](/docs/agent/options.html#acl_default_policy).
    92  If the default policy is to "deny" access to all resources, then policy rules can be set to
    93  whitelist access to specific resources. Conversely, if the default policy is “allow” then policy rules can
    94  be used to explicitly deny access to resources.
    95  
    96  The following table summarizes the ACL resources that are available for constructing
    97  rules:
    98  
    99  | Resource                   | Scope |
   100  | ------------------------ | ----- |
   101  | [`acl`](#acl-rules)              | Operations for managing the ACL system [ACL API](/api/acl/acl.html) |
   102  | [`agent`](#agent-rules)          | Utility operations in the [Agent API](/api/agent.html), other than service and check registration |
   103  | [`event`](#event-rules)          | Listing and firing events in the [Event API](/api/event.html) |
   104  | [`key`](#key-value-rules)        | Key/value store operations in the [KV Store API](/api/kv.html) |
   105  | [`keyring`](#keyring-rules)      | Keyring operations in the [Keyring API](/api/operator/keyring.html) |
   106  | [`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) |
   107  | [`operator`](#operator-rules)    | Cluster-level operations in the [Operator API](/api/operator.html), other than the [Keyring API](/api/operator/keyring.html) |
   108  | [`query`](#prepared-query-rules) | Prepared query operations in the [Prepared Query API](/api/query.html)
   109  | [`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) |
   110  | [`session`](#session-rules)      | Session operations in the [Session API](/api/session.html) |
   111  
   112  Since Consul snapshots actually contain ACL tokens, the [Snapshot API](/api/snapshot.html)
   113  requires a token with "write" privileges for the ACL system.
   114  
   115  The following resources are not covered by ACL policies:
   116  
   117  1. The [Status API](/api/status.html) is used by servers when bootstrapping and exposes
   118  basic IP and port information about the servers, and does not allow modification
   119  of any state.
   120  
   121  2. The datacenter listing operation of the
   122  [Catalog API](/api/catalog.html#list-datacenters) similarly exposes the names of known
   123  Consul datacenters, and does not allow modification of any state.
   124  
   125  3. The [connect CA roots endpoint](/api/connect/ca.html#list-ca-root-certificates) exposes just the public TLS certificate which other systems can use to verify the TLS connection with Consul.
   126  
   127  Constructing rules from these policies is covered in detail on the
   128  [ACL Rules](/docs/agent/acl-rules.html) page.
   129  
   130  ## Configuring ACLs
   131  
   132  ACLs are configured using several different configuration options. These are marked
   133  as to whether they are set on servers, clients, or both.
   134  
   135  | Configuration Option | Servers | Clients | Purpose |
   136  | -------------------- | ------- | ------- | ------- |
   137  | [`acl.enabled`](/docs/agent/options.html#acl_enabled) | `REQUIRED` | `REQUIRED` | Controls whether ACLs are enabled |
   138  | [`acl.default_policy`](/docs/agent/options.html#acl_default_policy) | `OPTIONAL` | `N/A` | Determines whitelist or blacklist mode |
   139  | [`acl.down_policy`](/docs/agent/options.html#acl_down_policy) | `OPTIONAL` | `OPTIONAL` | Determines what to do when the remote token or policy resolution fails |
   140  | [`acl.policy_ttl`](/docs/agent/options.html#acl_policy_ttl) | `OPTIONAL` | `OPTIONAL` | Determines time-to-live for cached ACL Policies |
   141  | [`acl.token_ttl`](/docs/agent/options.html#acl_token_ttl) | `OPTIONAL` | `OPTIONAL` | Determines time-to-live for cached ACL Tokens |
   142  
   143  A number of special tokens can also be configured which allow for bootstrapping the ACL
   144  system, or accessing Consul in special situations:
   145  
   146  | Special Token | Servers | Clients | Purpose |
   147  | ------------- | ------- | ------- | ------- |
   148  | [`acl.tokens.agent_master`](/docs/agent/options.html#acl_tokens_agent_master) | `OPTIONAL` | `OPTIONAL` | Special token that can be used to access [Agent API](/api/agent.html) when remote bearer token resolution fails; 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 |
   149  | [`acl.tokens.agent`](/docs/agent/options.html#acl_tokens_agent) | `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 |
   150  | [`acl.tokens.master`](/docs/agent/options.html#acl_tokens_master) | `OPTIONAL` | `N/A` | Special token used to bootstrap the ACL system, see the [Bootstrapping ACLs](https://learn.hashicorp.com/consul/advanced/day-1-operations/acl-guide) guide for more details |
   151  | [`acl.tokens.default`](/docs/agent/options.html#acl_tokens_default) | `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 |
   152  
   153  All of these tokens except the `master` token can all be introduced or updated via the [/v1/agent/token API](/api/agent.html#update-acl-tokens).
   154  
   155  #### ACL Agent Master Token
   156  
   157  Since the [`acl.tokens.agent_master`](/docs/agent/options.html#acl_tokens_agent_master) 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
   158  
   159  ```text
   160  agent "<node name of agent>" {
   161    policy = "write"
   162  }
   163  node_prefix "" {
   164    policy = "read"
   165  }
   166  ```
   167  
   168  #### ACL Agent Token
   169  
   170  The [`acl.tokens.agent`](/docs/agent/options.html#acl_tokens_agent) 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.tokens.default`](/docs/agent/options.html#acl_tokens_default), though if the `acl.tokens.agent_token` isn't configured the `acl.tokens.default` will be used. The ACL agent token is used for the following operations by the agent:
   171  
   172  1. Updating the agent's node entry using the [Catalog API](/api/catalog.html), including updating its node metadata, tagged addresses, and network coordinates
   173  2. Performing [anti-entropy](/docs/internals/anti-entropy.html) syncing, in particular reading the node metadata and services registered with the catalog
   174  3. Reading and writing the special `_rexec` section of the KV store when executing [`consul exec`](/docs/commands/exec.html) commands
   175  
   176  Here's an example policy sufficient to accomplish the above for a node called `mynode`:
   177  
   178  ```text
   179  node "mynode" {
   180    policy = "write"
   181  }
   182  service_prefix "" {
   183    policy = "read"
   184  }
   185  key_prefix "_rexec" {
   186    policy = "write"
   187  }
   188  ```
   189  
   190  The `service_prefix` 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_prefix` policy can be omitted.
   191  
   192  ## Next Steps
   193  
   194  Setup ACLs with the [Boostrapping guide](/docs/guides/acl.html) or continue reading about
   195  [ACL rules](/docs/agent/acl-rules.html).