2015-01-18 00:28:53 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "ACLs (HTTP)"
|
|
|
|
sidebar_current: "docs-agent-http-acl"
|
|
|
|
description: >
|
2015-02-05 16:52:29 +00:00
|
|
|
The ACL endpoints are used to create, update, destroy, and query ACL tokens.
|
2015-01-18 00:28:53 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# ACL HTTP Endpoint
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
The ACL endpoints are used to create, update, destroy, and query ACL tokens.
|
2015-01-18 00:28:53 +00:00
|
|
|
The following endpoints are supported:
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
* [`/v1/acl/create`](#acl_create): Creates a new token with a given policy
|
|
|
|
* [`/v1/acl/update`](#acl_update): Updates the policy of a token
|
2015-01-18 00:28:53 +00:00
|
|
|
* [`/v1/acl/destroy/<id>`](#acl_destroy): Destroys a given token
|
|
|
|
* [`/v1/acl/info/<id>`](#acl_info): Queries the policy of a given token
|
|
|
|
* [`/v1/acl/clone/<id>`](#acl_clone): Creates a new token by cloning an existing token
|
|
|
|
* [`/v1/acl/list`](#acl_list): Lists all the active tokens
|
2016-08-05 07:23:28 +00:00
|
|
|
* [`/v1/acl/replication`](#acl_replication_status): Checks status of ACL replication
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
### <a name="acl_create"></a> /v1/acl/create
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
The `create` endpoint is used to make a new token. A token has a name,
|
|
|
|
a type, and a set of ACL rules.
|
|
|
|
|
|
|
|
The `Name` property is opaque to Consul. To aid human operators, it should
|
|
|
|
be a meaningful indicator of the ACL's purpose.
|
|
|
|
|
|
|
|
Type is either `client` or `management`. A management token is comparable
|
|
|
|
to a root user and has the ability to perform any action including
|
|
|
|
creating, modifying, and deleting ACLs.
|
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
By contrast, a client token can only perform actions as permitted by the
|
2016-11-25 18:25:09 +00:00
|
|
|
rules associated. Client tokens can never manage ACLs. Given this limitation,
|
2015-02-05 16:52:29 +00:00
|
|
|
only a management token can be used to make requests to the `/v1/acl/create`
|
|
|
|
endpoint.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
In any Consul cluster, only a single datacenter is authoritative for ACLs, so
|
|
|
|
all requests are automatically routed to that datacenter regardless
|
2015-02-05 16:52:29 +00:00
|
|
|
of the agent to which the request is made.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
The create endpoint supports a JSON request body with the `PUT`. The request
|
2015-02-05 16:52:29 +00:00
|
|
|
body may take the form:
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"Name": "my-app-token",
|
|
|
|
"Type": "client",
|
|
|
|
"Rules": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
None of the fields are mandatory. In fact, no body needs to be `PUT` if the
|
2015-02-05 16:52:29 +00:00
|
|
|
defaults are to be used. The `Name` and `Rules` fields default to being
|
|
|
|
blank, and the `Type` defaults to "client".
|
|
|
|
|
2015-05-06 02:25:27 +00:00
|
|
|
The `ID` field may be provided, and if omitted a random UUID will be generated.
|
|
|
|
The security of the ACL system depends on the difficulty of guessing the token.
|
|
|
|
Tokens should not be generated in a predictable manner or with too little entropy.
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
The format of the `Rules` property is [documented here](/docs/internals/acl.html).
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
A successful response body will return the `ID` of the newly created ACL, like so:
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### <a name="acl_update"></a> /v1/acl/update
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
The update endpoint is used to modify the policy for a given ACL token. It
|
|
|
|
is very similar to the create endpoint; however, instead of generating a new
|
|
|
|
token ID, the `ID` field must be provided. As with [`/v1/acl/create`](#acl_create),
|
2015-05-06 02:25:27 +00:00
|
|
|
requests to this endpoint must be made with a management token. If the ID does not
|
2016-11-25 16:00:02 +00:00
|
|
|
exist, the ACL will be inserted. In this sense, create and update are identical.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
In any Consul cluster, only a single datacenter is authoritative for ACLs, so
|
|
|
|
all requests are automatically routed to that datacenter regardless
|
2015-02-05 16:52:29 +00:00
|
|
|
of the agent to which the request is made.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
The update endpoint requires a JSON request body to the `PUT`. The request
|
2015-02-05 16:52:29 +00:00
|
|
|
body may look like:
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
2016-08-01 15:46:43 +00:00
|
|
|
"ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e",
|
2015-01-18 00:28:53 +00:00
|
|
|
"Name": "my-app-token-updated",
|
|
|
|
"Type": "client",
|
|
|
|
"Rules": "# New Rules",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
Only the `ID` field is mandatory. The other fields provide defaults: the
|
|
|
|
`Name` and `Rules` fields default to being blank, and `Type` defaults to "client".
|
2015-01-18 00:28:53 +00:00
|
|
|
The format of `Rules` is [documented here](/docs/internals/acl.html).
|
|
|
|
|
|
|
|
### <a name="acl_destroy"></a> /v1/acl/destroy/\<id\>
|
|
|
|
|
2016-11-25 18:25:09 +00:00
|
|
|
The destroy endpoint must be hit with a `PUT`. This endpoint destroys the ACL
|
2015-02-05 16:52:29 +00:00
|
|
|
token identified by the `id` portion of the path.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
The request is automatically routed to the authoritative ACL datacenter.
|
|
|
|
Requests to this endpoint must be made with a management token.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
### <a name="acl_info"></a> /v1/acl/info/\<id\>
|
|
|
|
|
2016-11-25 18:25:09 +00:00
|
|
|
The info endpoint must be hit with a `GET`. This endpoint returns the ACL
|
2015-02-05 16:52:29 +00:00
|
|
|
token information identified by the `id` portion of the path.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"CreateIndex": 3,
|
|
|
|
"ModifyIndex": 3,
|
|
|
|
"ID": "8f246b77-f3e1-ff88-5b48-8ec93abf3e05",
|
|
|
|
"Name": "Client Token",
|
|
|
|
"Type": "client",
|
|
|
|
"Rules": "..."
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
If the ACL is not found, null is returned instead of a JSON list.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
### <a name="acl_clone"></a> /v1/acl/clone/\<id\>
|
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
The clone endpoint must be hit with a `PUT`. It clones the ACL identified
|
2015-02-05 16:52:29 +00:00
|
|
|
by the `id` portion of the path and returns a new token `ID`. This allows
|
|
|
|
a token to serve as a template for others, making it simple to generate new
|
|
|
|
tokens without complex rule management.
|
2015-01-18 00:28:53 +00:00
|
|
|
|
2015-02-05 16:52:29 +00:00
|
|
|
The request is automatically routed to the authoritative ACL datacenter.
|
|
|
|
Requests to this endpoint must be made with a management token.
|
|
|
|
|
2015-02-05 17:02:03 +00:00
|
|
|
As with `create`, a successful response body will return the `ID` of the newly
|
2015-02-05 16:52:29 +00:00
|
|
|
created ACL, like so:
|
2015-01-18 00:28:53 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### <a name="acl_list"></a> /v1/acl/list
|
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
The list endpoint must be hit with a `GET`. It lists all the active
|
2015-02-05 16:52:29 +00:00
|
|
|
ACL tokens. This is a privileged endpoint and requires a
|
2015-01-18 00:28:53 +00:00
|
|
|
management token.
|
|
|
|
|
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"CreateIndex": 3,
|
|
|
|
"ModifyIndex": 3,
|
|
|
|
"ID": "8f246b77-f3e1-ff88-5b48-8ec93abf3e05",
|
|
|
|
"Name": "Client Token",
|
|
|
|
"Type": "client",
|
|
|
|
"Rules": "..."
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
```
|
2016-08-05 07:23:28 +00:00
|
|
|
|
|
|
|
### <a name="acl_replication_status"></a> /v1/acl/replication
|
|
|
|
|
2016-08-17 17:21:59 +00:00
|
|
|
Available in Consul 0.7 and later, the endpoint must be hit with a
|
2016-11-25 16:00:02 +00:00
|
|
|
`GET` and returns the status of the [ACL replication](/docs/internals/acl.html#replication)
|
2016-08-17 17:21:59 +00:00
|
|
|
process in the datacenter. This is intended to be used by operators, or by
|
2016-08-05 07:23:28 +00:00
|
|
|
automation checking the health of ACL replication.
|
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
By default, the datacenter of the agent is queried; however, the `dc` can be provided
|
|
|
|
using the `?dc=` query parameter.
|
2016-08-05 07:23:28 +00:00
|
|
|
|
|
|
|
It returns a JSON body like this:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"Enabled": true,
|
|
|
|
"Running": true,
|
|
|
|
"SourceDatacenter": "dc1",
|
|
|
|
"ReplicatedIndex": 1976,
|
|
|
|
"LastSuccess": "2016-08-05T06:28:58Z",
|
|
|
|
"LastError": "2016-08-05T06:28:28Z"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
`Enabled` reports whether ACL replication is enabled for the datacenter.
|
|
|
|
|
|
|
|
`Running` reports whether the ACL replication process is running. The process
|
|
|
|
may take approximately 60 seconds to begin running after a leader election occurs.
|
|
|
|
|
|
|
|
`SourceDatacenter` is the authoritative ACL datacenter that ACLs are being
|
|
|
|
replicated from, and will match the
|
|
|
|
[`acl_datacenter`](/docs/agent/options.html#acl_datacenter) configuration.
|
|
|
|
|
|
|
|
`ReplicatedIndex` is the last index that was successfully replicated. You can
|
|
|
|
compare this to the `X-Consul-Index` header returned by the [`/v1/acl/list`](#acl_list)
|
|
|
|
endpoint to determine if the replication process has gotten all available
|
2016-11-25 16:00:02 +00:00
|
|
|
ACLs. Replication runs as a background process approximately every 30
|
2016-08-17 17:21:59 +00:00
|
|
|
seconds, and that local updates are rate limited to 100 updates/second, so so it
|
2016-08-05 07:23:28 +00:00
|
|
|
may take several minutes to perform the initial sync of a large set of ACLs.
|
|
|
|
After the initial sync, replica lag should be on the order of about 30 seconds.
|
|
|
|
|
2016-11-25 16:00:02 +00:00
|
|
|
`LastSuccess` is the UTC time of the last successful sync operation.
|
|
|
|
Since ACL replication is done with a blocking query, this may not update
|
|
|
|
for up to 5 minutes if there have been no ACL changes to replicate. A
|
|
|
|
zero value of "0001-01-01T00:00:00Z" will be present if no sync has been
|
|
|
|
successful.
|
2016-08-05 07:23:28 +00:00
|
|
|
|
|
|
|
`LastError` is the UTC time of the last error encountered during a sync operation.
|
|
|
|
If this time is later than `LastSuccess`, you can assume the replication process
|
|
|
|
is not in a good state. A zero value of "0001-01-01T00:00:00Z" will be present if
|
|
|
|
no sync has resulted in an error.
|
|
|
|
|
|
|
|
Please see the [ACL replication](/docs/internals/acl.html#replication)
|
|
|
|
section of the internals guide for more details.
|