2019-01-09 21:07:20 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
page_title: ACL System
description: >-
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.
2019-01-09 21:07:20 +00:00
---
# ACL System
2020-10-14 15:23:05 +00:00
-> **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/acl/acl-legacy).
2020-04-09 00:09:01 +00:00
2019-01-09 21:07:20 +00:00
Consul provides an optional Access Control List (ACL) system which can be used to control access to data and APIs.
The ACL is [Capability-based](https://en.wikipedia.org/wiki/Capability-based_security), relying on tokens which
are associated with policies to determine which fine grained rules can be applied. Consul's capability based
2020-04-06 20:27:35 +00:00
ACL system is very similar to the design of [AWS IAM](https://aws.amazon.com/iam/).
2019-10-14 15:40:35 +00:00
2020-08-17 16:17:51 +00:00
To learn how to setup the ACL system on an existing Consul datacenter, use the [Bootstrapping The ACL System tutorial](https://learn.hashicorp.com/tutorials/consul/access-control-setup?utm_source=consul.io&utm_medium=docs).
2019-01-09 21:07:20 +00:00
## ACL System Overview
The ACL system is designed to be easy to use and fast to enforce while providing administrative insight.
2021-08-12 17:50:49 +00:00
The diagram below shows the relationships between most of the components of the ACL system:
![ACL system component relationships](/img/acl-token-policy-rule-relationship.png)
2019-01-09 21:07:20 +00:00
At the highest level, there are two major components to the ACL system:
2020-04-06 20:27:35 +00:00
- **ACL Policies** - Policies allow the grouping of a set of rules into a logical unit that can be reused and linked with
many tokens.
2019-01-09 21:07:20 +00:00
2020-04-06 20:27:35 +00:00
- **ACL Tokens** - Requests to Consul are authorized by using bearer token. Each ACL token has a public
Accessor ID which is used to name a token, and a Secret ID which is used as the bearer token used to
make requests to Consul.
2019-01-09 21:07:20 +00:00
2019-05-01 21:11:23 +00:00
For many scenarios policies and tokens are sufficient, but more advanced setups
may benefit from additional components in the ACL system:
2020-04-06 20:27:35 +00:00
- **ACL Roles** - Roles allow for the grouping of a set of policies and service
identities into a reusable higher-level entity that can be applied to many
tokens. (Added in Consul 1.5.0)
2019-05-01 21:11:23 +00:00
2020-04-06 20:27:35 +00:00
- **ACL Service Identities** - Service identities are a policy template for
expressing a link to a policy suitable for use in [Consul
2020-04-09 23:20:00 +00:00
Connect](/docs/connect). At authorization time this acts like an
2020-04-06 20:27:35 +00:00
additional policy was attached, the contents of which are described further
below. These are directly attached to tokens and roles and are not
independently configured. (Added in Consul 1.5.0)
2020-07-08 23:09:00 +00:00
2020-06-16 16:54:27 +00:00
- **ACL Node Identities** - Node identities are a policy template for
expressing a link to a policy suitable for use as an [Consul `agent` token
](/docs/agent/options#acl_tokens_agent). At authorization time this acts like an
additional policy was attached, the contents of which are described further
below. These are directly attached to tokens and roles and are not
independently configured. (Added in Consul 1.8.1)
2019-05-01 21:11:23 +00:00
2020-04-06 20:27:35 +00:00
- **ACL Auth Methods and Binding Rules** - To learn more about these topics,
2020-05-13 19:14:03 +00:00
see the [auth methods documentation page](/docs/acl/auth-methods).
2019-05-01 21:11:23 +00:00
2020-04-06 20:27:35 +00:00
ACL tokens, policies, roles, auth methods, and binding rules are managed by
2020-04-09 23:46:54 +00:00
Consul operators via Consul's [ACL API](/api/acl/acl),
2020-10-14 15:23:05 +00:00
[ACL CLI](/commands/acl), or systems like
2020-04-09 23:20:00 +00:00
[HashiCorp's Vault](https://www.vaultproject.io/docs/secrets/consul).
2019-01-09 21:07:20 +00:00
2020-04-06 20:27:35 +00:00
If the ACL system becomes inoperable, you can follow the
2020-08-17 16:17:51 +00:00
[reset procedure](https://learn.hashicorp.com/tutorials/consul/access-control-troubleshoot#reset-the-acl-system) at any time.
2019-10-24 17:22:08 +00:00
2019-01-09 21:07:20 +00:00
### ACL Policies
An ACL policy is a named set of rules and is composed of the following elements:
2020-04-06 20:27:35 +00:00
- **ID** - The policy's auto-generated public identifier.
- **Name** - A unique meaningful name for the policy.
- **Description** - A human readable description of the policy. (Optional)
2020-04-09 23:46:54 +00:00
- **Rules** - Set of rules granting or denying permissions. See the [Rule Specification](/docs/acl/acl-rules#rule-specification) documentation for more details.
2020-04-06 20:27:35 +00:00
- **Datacenters** - A list of datacenters the policy is valid within.
2020-04-23 22:13:18 +00:00
- **Namespace** - <EnterpriseAlert inline /> - The namespace this policy resides within. (Added in Consul Enterprise 1.7.0)
2019-12-06 16:14:56 +00:00
2020-09-01 15:14:13 +00:00
-> **Consul Enterprise Namespacing** - Rules defined in a policy in any namespace other than `default` will be [restricted](/docs/acl/acl-rules#namespace-rules) to being able to grant a subset of the overall privileges and only affecting that single namespace.
2019-01-09 21:07:20 +00:00
#### Builtin Policies
2020-04-06 20:27:35 +00:00
- **Global Management** - Grants unrestricted privileges to any token that uses it. When created it will be named `global-management`
and will be assigned the reserved ID of `00000000-0000-0000-0000-000000000001`. This policy can be renamed but modification
of anything else including the rule set and datacenter scoping will be prevented by Consul.
2019-01-09 21:07:20 +00:00
2020-04-23 22:13:18 +00:00
- **Namespace Management** - <EnterpriseAlert inline /> - Every namespace created will have a policy injected with the name `namespace-management`. This policy gets injected with a randomized UUID and may be managed like any other user-defined policy
2020-04-06 20:27:35 +00:00
within the Namespace. (Added in Consul Enterprise 1.7.0)
2019-12-06 16:14:56 +00:00
2019-05-01 21:11:23 +00:00
### ACL Service Identities
-> Added in Consul 1.5.0
2020-04-09 23:46:54 +00:00
An ACL service identity is an [ACL policy](/docs/acl/acl-system#acl-policies) template for expressing a link to a policy
2020-04-09 23:20:00 +00:00
suitable for use in [Consul Connect](/docs/connect). They are usable
2019-05-01 21:11:23 +00:00
on both tokens and roles and are composed of the following elements:
2020-04-06 20:27:35 +00:00
- **Service Name** - The name of the service.
- **Datacenters** - A list of datacenters the effective policy is valid within. (Optional)
2019-05-01 21:11:23 +00:00
Services participating in the service mesh will need privileges to both _be
discovered_ and to _discover other healthy service instances_. Suitable
policies tend to all look nearly identical so a service identity is a policy
template to aid in avoiding boilerplate policy creation.
2019-05-06 20:11:06 +00:00
During the authorization process, the configured service identity is automatically
applied as a policy with the following preconfigured [ACL
2020-04-09 23:46:54 +00:00
rules](/docs/acl/acl-system#acl-rules-and-scope):
2019-05-01 21:11:23 +00:00
```hcl
2020-04-09 00:09:01 +00:00
# Allow the service and its sidecar proxy to register into the catalog.
2019-05-01 21:11:23 +00:00
service "<Service Name>" {
policy = "write"
}
service "<Service Name>-sidecar-proxy" {
policy = "write"
}
2020-04-09 00:09:01 +00:00
# Allow for any potential upstreams to be resolved.
2019-05-01 21:11:23 +00:00
service_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
```
2020-04-09 23:46:54 +00:00
The [API documentation for roles](/api/acl/roles#sample-payload) has some
2019-05-01 21:11:23 +00:00
examples of using a service identity.
2020-04-06 20:27:35 +00:00
-> **Consul Enterprise Namespacing** - Service Identity rules will be scoped to the single namespace that
2019-12-06 16:14:56 +00:00
the corresponding ACL Token or Role resides within.
2020-06-16 16:54:27 +00:00
### ACL Node Identities
-> Added in Consul 1.8.1
An ACL node identity is an [ACL policy](/docs/acl/acl-system#acl-policies) template for expressing a link to a policy
suitable for use as an [Consul `agent` token](/docs/agent/options#acl_tokens_agent). They are usable
on both tokens and roles and are composed of the following elements:
- **Node Name** - The name of the node to grant access to.
- **Datacenter** - The datacenter that the node resides within.
During the authorization process, the configured node identity is automatically
applied as a policy with the following preconfigured [ACL
rules](/docs/acl/acl-system#acl-rules-and-scope):
```hcl
# Allow the agent to register its own node in the Catalog and update its network coordinates
node "<Node Name>" {
policy = "write"
}
# Allows the agent to detect and diff services registered to itself. This is used during
# anti-entropy to reconcile difference between the agents knowledge of registered
# services and checks in comparison with what is known in the Catalog.
service_prefix "" {
policy = "read"
}
```
-> **Consul Enterprise Namespacing** - Node Identities can only be applied to tokens and roles in the `default` namespace.
The synthetic policy rules allow for `service:read` permissions on all services in all namespaces.
2019-05-01 21:11:23 +00:00
### ACL Roles
-> Added in Consul 1.5.0
An ACL role is a named set of policies and service identities and is composed
of the following elements:
2020-04-06 20:27:35 +00:00
- **ID** - The role's auto-generated public identifier.
- **Name** - A unique meaningful name for the role.
- **Description** - A human readable description of the role. (Optional)
- **Policy Set** - The list of policies that are applicable for the role.
- **Service Identity Set** - The list of service identities that are applicable for the role.
2020-04-23 22:13:18 +00:00
- **Namespace** <EnterpriseAlert inline /> - The namespace this policy resides within. (Added in Consul Enterprise 1.7.0)
2019-12-06 16:14:56 +00:00
-> **Consul Enterprise Namespacing** - Roles may only link to policies defined in the same namespace as the role itself.
2019-05-01 21:11:23 +00:00
2019-01-09 21:07:20 +00:00
### ACL Tokens
ACL tokens are used to determine if the caller is authorized to perform an action. An ACL token is composed of the following
elements:
2020-04-06 20:27:35 +00:00
- **Accessor ID** - The token's public identifier.
- **Secret ID** -The bearer token used when making requests to Consul.
- **Description** - A human readable description of the token. (Optional)
- **Policy Set** - The list of policies that are applicable for the token.
- **Role Set** - The list of roles that are applicable for the token. (Added in Consul 1.5.0)
- **Service Identity Set** - The list of service identities that are applicable for the token. (Added in Consul 1.5.0)
- **Locality** - Indicates whether the token should be local to the datacenter it was created within or created in
the primary datacenter and globally replicated.
- **Expiration Time** - The time at which this token is revoked. (Optional; Added in Consul 1.5.0)
2020-04-23 22:13:18 +00:00
- **Namespace** <EnterpriseAlert inline /> - The namespace this policy resides within. (Added in Consul Enterprise 1.7.0)
2019-12-06 16:14:56 +00:00
-> **Consul Enterprise Namespacing** - Tokens may only link to policies and roles defined in the same namespace as
the token itself.
2019-01-09 21:07:20 +00:00
#### Builtin Tokens
During cluster bootstrapping when ACLs are enabled both the special `anonymous` and the `master` token will be
injected.
2020-04-06 20:27:35 +00:00
- **Anonymous Token** - The anonymous token is used when a request is made to Consul without specifying a bearer token.
The anonymous token's description and policies may be updated but Consul will prevent this token's deletion. When created,
it will be assigned `00000000-0000-0000-0000-000000000002` for its Accessor ID and `anonymous` for its Secret ID.
2019-01-09 21:07:20 +00:00
2020-04-06 20:27:35 +00:00
- **Master Token** - When a master token is present within the Consul configuration, it is created and will be linked
With the builtin Global Management policy giving it unrestricted privileges. The master token is created with the Secret ID
set to the value of the configuration entry.
2019-01-09 21:07:20 +00:00
#### Authorization
The token Secret ID is passed along with each RPC request to the servers. Consul's
2020-04-09 23:20:00 +00:00
[HTTP endpoints](/api) can accept tokens via the `token`
2020-04-06 20:27:35 +00:00
query string parameter, the `X-Consul-Token` request header, or an
2019-01-09 21:07:20 +00:00
[RFC6750](https://tools.ietf.org/html/rfc6750) authorization bearer token. Consul's
2020-04-09 23:20:00 +00:00
[CLI commands](/docs/commands) can accept tokens via the
2019-05-01 21:11:23 +00:00
`token` argument, or the `CONSUL_HTTP_TOKEN` environment variable. The CLI
commands can also accept token values stored in files with the `token-file`
argument, or the `CONSUL_HTTP_TOKEN_FILE` environment variable.
2019-01-09 21:07:20 +00:00
If no token is provided for an HTTP request then Consul will use the default ACL token
if it has been configured. If no default ACL token was configured then the anonymous
token will be used.
#### ACL Rules and Scope
2019-05-01 21:11:23 +00:00
The rules from all policies, roles, and service identities linked with a token are combined to form that token's
2020-05-29 18:19:16 +00:00
effective rule set. Policy rules can be defined in either an allowlist or denylist
2020-04-09 23:46:54 +00:00
mode depending on the configuration of [`acl_default_policy`](/docs/agent/options#acl_default_policy).
2019-01-09 21:07:20 +00:00
If the default policy is to "deny" access to all resources, then policy rules can be set to
2020-05-29 18:19:16 +00:00
allowlist access to specific resources. Conversely, if the default policy is “allow” then policy rules can
2019-01-09 21:07:20 +00:00
be used to explicitly deny access to resources.
The following table summarizes the ACL resources that are available for constructing
rules:
2021-08-12 17:50:49 +00:00
| Resource | Scope |
| --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`acl`](/docs/acl/acl-rules#acl-resource-rules) | Operations for managing the ACL system [ACL API](/api/acl/acl) |
| [`agent`](/docs/acl/acl-rules#agent-rules) | Utility operations in the [Agent API](/api/agent), other than service and check registration |
| [`event`](/docs/acl/acl-rules#event-rules) | Listing and firing events in the [Event API](/api/event) |
| [`key`](/docs/acl/acl-rules#key-value-rules) | Key/value store operations in the [KV Store API](/api/kv) |
| [`keyring`](/docs/acl/acl-rules#keyring-rules) | Keyring operations in the [Keyring API](/api/operator/keyring) |
| [`node`](/docs/acl/acl-rules#node-rules) | Node-level catalog operations in the [Catalog API](/api/catalog), [Health API](/api/health), [Prepared Query API](/api/query), [Network Coordinate API](/api/coordinate), and [Agent API](/api/agent) |
| [`operator`](/docs/acl/acl-rules#operator-rules) | Cluster-level operations in the [Operator API](/api/operator), other than the [Keyring API](/api/operator/keyring) |
| [`query`](/docs/acl/acl-rules#prepared-query-rules) | Prepared query operations in the [Prepared Query API](/api/query) |
| [`service`](/docs/acl/acl-rules#service-rules) | Service-level catalog operations in the [Catalog API](/api/catalog), [Health API](/api/health), [Intentions API](/api/connect/intentions), [Prepared Query API](/api/query), and [Agent API](/api/agent) |
| [`session`](/docs/acl/acl-rules#session-rules) | Session operations in the [Session API](/api/session) |
2020-04-09 23:46:54 +00:00
Since Consul snapshots actually contain ACL tokens, the [Snapshot API](/api/snapshot)
2019-01-09 21:07:20 +00:00
requires a token with "write" privileges for the ACL system.
The following resources are not covered by ACL policies:
2020-04-09 23:46:54 +00:00
1. The [Status API](/api/status) is used by servers when bootstrapping and exposes
2020-04-06 20:27:35 +00:00
basic IP and port information about the servers, and does not allow modification
of any state.
2019-01-09 21:07:20 +00:00
2. The datacenter listing operation of the
2020-04-09 23:46:54 +00:00
[Catalog API](/api/catalog#list-datacenters) similarly exposes the names of known
2020-04-06 20:27:35 +00:00
Consul datacenters, and does not allow modification of any state.
2019-01-09 21:07:20 +00:00
2020-04-09 23:46:54 +00:00
3. The [connect CA roots endpoint](/api/connect/ca#list-ca-root-certificates) exposes just the public TLS certificate which other systems can use to verify the TLS connection with Consul.
2019-01-09 21:07:20 +00:00
2019-03-15 14:35:33 +00:00
Constructing rules from these policies is covered in detail on the
2020-04-09 23:46:54 +00:00
[ACL Rules](/docs/acl/acl-rules) page.
2019-01-09 21:07:20 +00:00
2019-12-06 16:14:56 +00:00
-> **Consul Enterprise Namespacing** - In addition to directly linked policies, roles and service identities, Consul Enterprise
2020-04-09 23:20:00 +00:00
will include the ACL policies and roles defined in the [Namespaces definition](/docs/enterprise/namespaces#namespace-definition). (Added in Consul Enterprise 1.7.0)
2019-12-06 16:14:56 +00:00
2019-01-09 21:07:20 +00:00
## Configuring ACLs
ACLs are configured using several different configuration options. These are marked
as to whether they are set on servers, clients, or both.
2020-04-09 23:46:54 +00:00
| Configuration Option | Servers | Clients | Purpose |
| -------------------------------------------------------------- | ---------- | ---------- | ---------------------------------------------------------------------- |
| [`acl.enabled`](/docs/agent/options#acl_enabled) | `REQUIRED` | `REQUIRED` | Controls whether ACLs are enabled |
2020-07-08 23:09:00 +00:00
| [`acl.default_policy`](/docs/agent/options#acl_default_policy) | `OPTIONAL` | `N/A` | Determines allowlist or denylist mode |
2020-04-09 23:46:54 +00:00
| [`acl.down_policy`](/docs/agent/options#acl_down_policy) | `OPTIONAL` | `OPTIONAL` | Determines what to do when the remote token or policy resolution fails |
| [`acl.role_ttl`](/docs/agent/options#acl_role_ttl) | `OPTIONAL` | `OPTIONAL` | Determines time-to-live for cached ACL Roles |
| [`acl.policy_ttl`](/docs/agent/options#acl_policy_ttl) | `OPTIONAL` | `OPTIONAL` | Determines time-to-live for cached ACL Policies |
| [`acl.token_ttl`](/docs/agent/options#acl_token_ttl) | `OPTIONAL` | `OPTIONAL` | Determines time-to-live for cached ACL Tokens |
2019-01-09 21:07:20 +00:00
A number of special tokens can also be configured which allow for bootstrapping the ACL
system, or accessing Consul in special situations:
2020-04-09 23:46:54 +00:00
| Special Token | Servers | Clients | Purpose |
| ------------------------------------------------------------------------ | ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`acl.tokens.agent_master`](/docs/agent/options#acl_tokens_agent_master) | `OPTIONAL` | `OPTIONAL` | Special token that can be used to access [Agent API](/api/agent) 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 |
| [`acl.tokens.agent`](/docs/agent/options#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 |
2020-09-01 15:14:13 +00:00
| [`acl.tokens.master`](/docs/agent/options#acl_tokens_master) | `OPTIONAL` | `N/A` | Special token used to bootstrap the ACL system, check the [Bootstrapping ACLs](https://learn.hashicorp.com/tutorials/consul/access-control-setup-production) tutorial for more details |
2020-04-09 23:46:54 +00:00
| [`acl.tokens.default`](/docs/agent/options#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 |
2019-01-09 21:07:20 +00:00
2020-04-09 23:46:54 +00:00
All of these tokens except the `master` token can all be introduced or updated via the [/v1/agent/token API](/api/agent#update-acl-tokens).
2019-01-09 21:07:20 +00:00
#### ACL Agent Master Token
2020-04-09 23:46:54 +00:00
Since the [`acl.tokens.agent_master`](/docs/agent/options#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
2019-01-09 21:07:20 +00:00
2019-05-01 21:11:23 +00:00
```hcl
2019-01-09 21:07:20 +00:00
agent "<node name of agent>" {
policy = "write"
}
node_prefix "" {
policy = "read"
}
```
#### ACL Agent Token
2021-05-29 00:02:59 +00:00
The [`acl.tokens.agent`](/docs/agent/options#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#acl_tokens_default), though if the `acl.tokens.agent` isn't configured the `acl.tokens.default` will be used. The ACL agent token is used for the following operations by the agent:
2019-01-09 21:07:20 +00:00
2020-04-09 23:46:54 +00:00
1. Updating the agent's node entry using the [Catalog API](/api/catalog), including updating its node metadata, tagged addresses, and network coordinates
2. Performing [anti-entropy](/docs/internals/anti-entropy) syncing, in particular reading the node metadata and services registered with the catalog
2020-10-14 15:23:05 +00:00
3. Reading and writing the special `_rexec` section of the KV store when executing [`consul exec`](/commands/exec) commands
2019-01-09 21:07:20 +00:00
Here's an example policy sufficient to accomplish the above for a node called `mynode`:
2019-05-01 21:11:23 +00:00
```hcl
2019-01-09 21:07:20 +00:00
node "mynode" {
policy = "write"
}
service_prefix "" {
policy = "read"
}
key_prefix "_rexec" {
policy = "write"
}
```
2020-04-09 23:46:54 +00:00
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#disable_remote_exec), the default, then the `key_prefix` policy can be omitted.
2019-01-09 21:07:20 +00:00
## Next Steps
2020-08-17 16:17:51 +00:00
Setup ACLs with the [Bootstrapping the ACL System tutorial](https://learn.hashicorp.com/tutorials/consul/access-control-setup-production?utm_source=consul.io&utm_medium=docs) or continue reading about
2020-04-09 23:46:54 +00:00
[ACL rules](/docs/acl/acl-rules).