2019-05-01 21:11:23 +00:00
|
|
|
---
|
2020-09-01 15:14:13 +00:00
|
|
|
layout: commands
|
2020-04-07 18:55:19 +00:00
|
|
|
page_title: 'Commands: ACL Policy Create'
|
2023-01-26 18:42:13 +00:00
|
|
|
description: |
|
|
|
|
The `consul acl policy create` command creates new ACL policies that authorize read and write access in the service mesh.
|
2019-05-01 21:11:23 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Consul ACL Policy Create
|
|
|
|
|
|
|
|
Command: `consul acl policy create`
|
|
|
|
|
2023-01-25 16:52:43 +00:00
|
|
|
Corresponding HTTP API Endpoint: [\[PUT\] /v1/acl/policy](/consul/api-docs/acl/policies#create-a-policy)
|
2022-01-10 17:40:11 +00:00
|
|
|
|
2023-01-27 15:17:07 +00:00
|
|
|
The `acl policy create` command creates new policies.
|
|
|
|
|
|
|
|
The `-rules` parameter value allow loading the value from stdin, a file or the raw value.
|
|
|
|
To use stdin pass `-` as the value. To load the value from a file prefix the value with an `@`. Any other
|
2019-05-01 21:11:23 +00:00
|
|
|
values will be used directly.
|
|
|
|
|
2023-01-25 16:52:43 +00:00
|
|
|
The table below shows this command's [required ACLs](/consul/api-docs/api-structure#authentication). Configuration of
|
|
|
|
[blocking queries](/consul/api-docs/features/blocking) and [agent caching](/consul/api-docs/features/caching)
|
2022-01-10 21:44:56 +00:00
|
|
|
are not supported from commands, but may be from the corresponding HTTP endpoint.
|
|
|
|
|
|
|
|
| ACL Required |
|
|
|
|
| ------------ |
|
|
|
|
| `acl:write` |
|
|
|
|
|
2019-05-01 21:11:23 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
Usage: `consul acl policy create [options] [args]`
|
|
|
|
|
|
|
|
#### Command Options
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-description=<string>` - A description of the policy.
|
2019-05-01 21:11:23 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-meta` - Indicates that policy metadata such as the content hash and raft
|
|
|
|
indices should be shown for each entry.
|
2019-05-01 21:11:23 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-name=<string>` - The new policy's name. This flag is required.
|
2019-05-01 21:11:23 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-rules=<string>` - The policy rules. May be prefixed with '@' to indicate that the
|
|
|
|
value is a file path to load the rules from. '-' may also be given
|
|
|
|
to indicate that the rules are available on stdin.
|
2019-05-01 21:11:23 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-valid-datacenter=<value>` - Datacenter that the policy should be valid within.
|
|
|
|
This flag may be specified multiple times.
|
2019-05-01 21:11:23 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-format={pretty|json}` - Command output format. The default value is `pretty`.
|
2020-03-26 16:03:22 +00:00
|
|
|
|
2019-12-06 16:14:56 +00:00
|
|
|
#### Enterprise Options
|
|
|
|
|
2024-07-18 17:02:45 +00:00
|
|
|
@include 'cli-http-api-partition-options.mdx'
|
2022-07-27 06:17:11 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
@include 'http_api_namespace_options.mdx'
|
2019-12-06 16:14:56 +00:00
|
|
|
|
2022-07-27 06:17:11 +00:00
|
|
|
#### API Options
|
|
|
|
|
|
|
|
@include 'http_api_options_client.mdx'
|
|
|
|
|
|
|
|
@include 'http_api_options_server.mdx'
|
2021-12-15 01:55:21 +00:00
|
|
|
|
2019-05-01 21:11:23 +00:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
Create a new policy that is valid in all datacenters:
|
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2019-05-01 21:11:23 +00:00
|
|
|
$ consul acl policy create -name "acl-replication" -description "Policy capable of replicating ACL policies" -rules 'acl = "read"'
|
|
|
|
ID: 35b8ecb0-707c-ee18-2002-81b238b54b38
|
|
|
|
Name: acl-replication
|
|
|
|
Description: Policy capable of replicating ACL policies
|
|
|
|
Datacenters:
|
|
|
|
Rules:
|
|
|
|
acl = "read"
|
|
|
|
```
|
|
|
|
|
|
|
|
Create a new policy valid only in specific datacenters with rules read from a file:
|
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2019-05-01 21:11:23 +00:00
|
|
|
$ consul acl policy create -name "replication" -description "Replication" -rules @rules.hcl -valid-datacenter dc1 -valid-datacenter dc2
|
|
|
|
ID: ca44555b-a2d8-94de-d763-88caffdaf11f
|
|
|
|
Name: replication
|
|
|
|
Description: Replication
|
|
|
|
Datacenters: dc1, dc2
|
|
|
|
Rules:
|
|
|
|
acl = "read"
|
|
|
|
service_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
intentions = "read"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|