Rules Reference

    The following table provides an overview of the resources you can use to create ACL rules.

    The following resources are not covered by ACL policies:

    • The Status API is used by servers when bootstrapping and exposes basic IP and port information about the servers, and does not allow modification of any state.
    • The datacenter listing operation of the similarly exposes the names of known Consul datacenters, and does not allow modification of any state.
    • The connect CA roots endpoint exposes just the public TLS certificate which other systems can use to verify the TLS connection with Consul.

    Consul Enterprise Namespace - In addition to directly-linked policies, roles, and service identities, Consul Enterprise enables ACL policies and roles to be defined in the (Consul Enterprise 1.7.0+).

    The following topics provide additional details about the available resources.

    ACL Resource Rules

    The acl resource controls access to ACL operations in the . Only one acl rule is allowed per policy. The value is set to one of the policy dispositions.

    The acl = "write" rule is also required to create snapshots. This is because all token secrets are contained within the snapshot.

    Rules for ACL resources do not use labels.

    In the following example, the acl rule is configured with write access to the ACL API. The rule enables the operator to read or write ACLs, as well as discover the secret ID of any token.

    Example acl rule

    Example acl rule

    HCL

    • HCL
    • JSON
    1. acl = "write"
    1. {
    2. "acl": "write"
    3. }
    1. {
    2. "acl": "write"
    3. }

    Admin Partition Rules

    Enterprise

    The partition and partition_prefix resource controls access to one or more admin partitions. You can include any number of namespace rules inside the admin partition.

    In the following example, the policy grants write access to the ex-namespace namespace, as well as namespaces prefixed with exns- in the example partition. The mesh resource is also scoped to the admin partition rule, which grants write access to mesh-level resources in the example partition.

    In addition, the policy grants read access to the ex-namespace namespace, as well as namespaces prefixed with exns- in all partitions containing the example- prefix. Read access is granted for mesh resource scoped within the associated partition.

    Example admin partition rules

    Example admin partition rules

    HCL

    Rules Reference - 图2

    • HCL
    • JSON
    1. partition "example" {
    2. mesh = "write"
    3. node "my-node" {
    4. policy = "write"
    5. }
    6. namespace "ex-namespace" {
    7. policy = "write"
    8. }
    9. namespace_prefix "exns-" {
    10. policy = "write"
    11. }
    12. }
    13. partition_prefix "example-" {
    14. mesh = "read"
    15. node "my-node" {
    16. policy = "read"
    17. }
    18. namespace "ex-namespace" {
    19. policy = "read"
    20. }
    21. }
    1. partition "example" {
    2. mesh = "write"
    3. node "my-node" {
    4. policy = "write"
    5. }
    6. namespace "ex-namespace" {
    7. policy = "write"
    8. }
    9. namespace_prefix "exns-" {
    10. policy = "write"
    11. }
    12. }
    13. partition_prefix "example-" {
    14. mesh = "read"
    15. node "my-node" {
    16. policy = "read"
    17. }
    18. namespace "ex-namespace" {
    19. policy = "read"
    20. }
    21. }
    1. {
    2. "partition": {
    3. "example": {
    4. "mesh": "write",
    5. "node": {
    6. "my-node": {
    7. "policy": "write"
    8. }
    9. },
    10. "namespace": {
    11. "ex-namespace": {
    12. "policy": "write"
    13. }
    14. },
    15. "namespace_prefix": {
    16. "exns-": {
    17. "policy": "write"
    18. }
    19. }
    20. }
    21. },
    22. "partition_prefix": {
    23. "example-": {
    24. "mesh": "read",
    25. "node": {
    26. "my-node": {
    27. "policy": "read"
    28. }
    29. },
    30. "namespace": {
    31. "ex-namespace": {
    32. "policy": "read"
    33. }
    34. }
    35. }
    36. }
    37. }
    1. {
    2. "partition": {
    3. "example": {
    4. "mesh": "write",
    5. "node": {
    6. "my-node": {
    7. "policy": "write"
    8. }
    9. },
    10. "namespace": {
    11. "ex-namespace": {
    12. "policy": "write"
    13. }
    14. },
    15. "namespace_prefix": {
    16. "exns-": {
    17. "policy": "write"
    18. }
    19. }
    20. }
    21. },
    22. "partition_prefix": {
    23. "example-": {
    24. "mesh": "read",
    25. "node": {
    26. "my-node": {
    27. "policy": "read"
    28. }
    29. },
    30. "namespace": {
    31. "ex-namespace": {
    32. "policy": "read"
    33. }
    34. }
    35. }
    36. }
    37. }

    Agent Rules

    The agent and agent_prefix resources control access to the utility operations in the , such as join and leave. All of the catalog-related operations are covered by the node or node_prefix and policies instead.

    Example agent rules

    Example agent rules

    HCL

    • HCL
    • JSON
    1. agent "foo" {
    2. policy = "write"
    3. }
    4. agent_prefix "" {
    5. policy = "read"
    6. }
    7. agent_prefix "bar" {
    8. policy = "deny"
    9. }
    1. agent "foo" {
    2. policy = "write"
    3. }
    4. agent_prefix "" {
    5. policy = "read"
    6. }
    7. agent_prefix "bar" {
    8. policy = "deny"
    9. }
    1. {
    2. "agent": {
    3. "foo": {
    4. "policy": "write"
    5. }
    6. },
    7. "agent_prefix": {
    8. "": {
    9. "policy": "read"
    10. },
    11. "bar": {
    12. "policy": "deny"
    13. }
    14. }
    15. }
    1. {
    2. "agent": {
    3. "foo": {
    4. "policy": "write"
    5. }
    6. },
    7. "agent_prefix": {
    8. "": {
    9. "policy": "read"
    10. },
    11. "bar": {
    12. "policy": "deny"
    13. }
    14. }
    15. }

    Agent rules are keyed by the node name they apply to. In the example above the rules allow read-write access to the node with the exact name foo, read-only access to any node name by using the empty prefix, and denies all access to any node name that starts with bar.

    Since Agent API utility operations may be required before an agent is joined to a cluster, or during an outage of the Consul servers or ACL datacenter, a special token may be configured with to allow write access to these operations even if no ACL resolution capability is available.

    The event and event_prefix resources control access to event operations in the Event API, such as firing events and listing events.

    Example event rules

    Example event rules

    HCL

    Rules Reference - 图4

    • HCL
    • JSON
    1. event_prefix "" {
    2. policy = "read"
    3. }
    4. event "deploy" {
    5. policy = "write"
    6. }
    1. event_prefix "" {
    2. policy = "read"
    3. }
    4. event "deploy" {
    5. policy = "write"
    6. }
    1. {
    2. "event_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "event": {
    8. "deploy": {
    9. "policy": "write"
    10. }
    11. }
    12. }
    1. {
    2. "event_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "event": {
    8. "deploy": {
    9. "policy": "write"
    10. }
    11. }
    12. }

    Event rules are labeled with the event name they apply to. In the example above, the rules allow read-only access to any event, and firing of the “deploy” event.

    The command uses events with the “_rexec” prefix during operation, so to enable this feature in a Consul environment with ACLs enabled, you will need to give agents a token with access to this event prefix, in addition to configuring disable_remote_exec to false.

    Key/Value Rules

    The key and key_prefix resources control access to key/value store operations in the KV API.

    Example key rules

    Example key rules

    HCL

    • HCL
    • JSON
    1. key_prefix "" {
    2. policy = "read"
    3. }
    4. policy = "write"
    5. }
    6. policy = "deny"
    7. }
    1. key_prefix "" {
    2. policy = "read"
    3. }
    4. key "foo" {
    5. policy = "write"
    6. }
    7. key "bar" {
    8. policy = "deny"
    9. }
    1. {
    2. "key_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "key": {
    8. "foo": {
    9. "policy": "write"
    10. },
    11. "bar": {
    12. "policy": "deny"
    13. }
    14. }
    15. }
    1. {
    2. "key_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "key": {
    8. "foo": {
    9. "policy": "write"
    10. },
    11. "bar": {
    12. "policy": "deny"
    13. }
    14. }
    15. }

    Key rules are labeled with the key name they apply to. In the example above, the rules allow read-only access to any key name with the empty prefix rule, allow read-write access to the “foo” key, and deny access to the “bar” key.

    Enable the list policy disposition (Consul 1.0+) by setting the acl.enable_key_list_policy parameter to true. The disposition provides recursive access to key entries. Refer to the documentation for additional information.

    In the following example, key resources that start with bar may be listed.

    Example ‘key’ rules

    HCL

    Rules Reference - 图6

    • HCL
    • JSON
    1. key_prefix "" {
    2. policy = "deny"
    3. }
    4. key_prefix "bar" {
    5. policy = "list"
    6. }
    7. key_prefix "baz" {
    8. policy = "read"
    9. }
    1. {
    2. "key_prefix": {
    3. "": {
    4. "policy": "deny"
    5. },
    6. "bar": {
    7. "policy": "list"
    8. },
    9. "baz": {
    10. "policy": "read"
    11. }
    12. }
    13. }
    1. {
    2. "key_prefix": {
    3. "": {
    4. "policy": "deny"
    5. },
    6. "bar": {
    7. "policy": "list"
    8. },
    9. "baz": {
    10. "policy": "read"
    11. }
    12. }
    13. }

    In the example above, the rules allow reading the key “baz”, and only allow recursive reads on the prefix “bar”.

    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.

    Sentinel Integration

    Enterprise

    Consul Enterprise supports additional optional fields for key write policies for integration.

    1. key "foo" {
    2. policy = "write"
    3. sentinel {
    4. code = <<EOF
    5. import "strings"
    6. main = rule { strings.has_suffix(value, "bar") }
    7. EOF
    8. enforcementlevel = "hard-mandatory"
    9. }
    10. }
    1. key "foo" {
    2. policy = "write"
    3. sentinel {
    4. code = <<EOF
    5. import "strings"
    6. main = rule { strings.has_suffix(value, "bar") }
    7. EOF
    8. enforcementlevel = "hard-mandatory"
    9. }
    10. }

    For more detailed information, see the Consul Sentinel documentation.

    Keyring Rules

    The keyring resource controls access to keyring operations in the Keyring API. Only one keyring policy is allowed per rule set. The value is set to one of the policy dispositions, but may be read and updated.

    Example keyring rule

    Example keyring rule

    HCL

    • HCL
    • JSON
    1. keyring = "write"
    1. keyring = "write"
    1. {
    2. "keyring": "write"
    3. }
    1. {
    2. "keyring": "write"
    3. }

    The mesh resource controls access to ingress gateways, terminating gateways, and mesh configuration entries. The following rule grants read and write access:

    Example mesh rule

    Example mesh rule

    HCL

    Rules Reference - 图8

    • HCL
    • JSON
    1. mesh = "write"
    1. mesh = "write"
    1. {
    2. "mesh": "write"
    3. }
    1. {
    2. "mesh": "write"
    3. }

    See for another example rule that uses the mesh resource.

    Namespace Rules

    Enterprise

    The namespace and namespace_prefix resource controls access to Consul namespaces. Namespaces define a scope of resources for which ACL rules apply. ACL rules, themselves, can then be defined to only to apply to specific namespaces.

    Consul 1.7.0 and later: The ability to add many types of resources to separate namespaces was added to 1.7.0.

    The following examples describe how namespace rules can be defined in a policy:

    Example namespace rules

    Example namespace rules

    HCL

    • HCL
    • JSON
    1. namespace_prefix "" {
    2. # grants permission to create and edit all namespaces
    3. policy = "write"
    4. # grant service:read for all services in all namespaces
    5. service_prefix "" {
    6. policy = "read"
    7. }
    8. # grant node:read for all nodes in all namespaces
    9. node_prefix "" {
    10. policy = "read"
    11. }
    12. }
    13. namespace "foo" {
    14. # grants permission to manage ACLs only for the foo namespace
    15. acl = "write"
    16. # grants permission to create and edit the foo namespace
    17. policy = "write"
    18. # grants write permissions to the KV for namespace foo
    19. key_prefix "" {
    20. policy = "write"
    21. }
    22. # grants write permissions for sessions for namespace foo
    23. session_prefix "" {
    24. policy = "write"
    25. }
    26. # grants service:write for all services in the foo namespace
    27. service_prefix "" {
    28. policy = "write"
    29. }
    30. # grants node:read for all nodes
    31. node_prefix "" {
    32. policy = "read"
    33. }
    34. }
    1. namespace_prefix "" {
    2. # grants permission to create and edit all namespaces
    3. policy = "write"
    4. # grant service:read for all services in all namespaces
    5. service_prefix "" {
    6. policy = "read"
    7. }
    8. # grant node:read for all nodes in all namespaces
    9. node_prefix "" {
    10. policy = "read"
    11. }
    12. }
    13. namespace "foo" {
    14. # grants permission to manage ACLs only for the foo namespace
    15. acl = "write"
    16. # grants permission to create and edit the foo namespace
    17. policy = "write"
    18. # grants write permissions to the KV for namespace foo
    19. key_prefix "" {
    20. policy = "write"
    21. }
    22. # grants write permissions for sessions for namespace foo
    23. session_prefix "" {
    24. policy = "write"
    25. }
    26. # grants service:write for all services in the foo namespace
    27. service_prefix "" {
    28. policy = "write"
    29. }
    30. # grants node:read for all nodes
    31. node_prefix "" {
    32. policy = "read"
    33. }
    34. }
    1. {
    2. "namespace_prefix": {
    3. "": {
    4. "policy": "write",
    5. "service_prefix": {
    6. "": {
    7. "policy": "read"
    8. }
    9. },
    10. "node_prefix": {
    11. "": {
    12. "policy": "read"
    13. }
    14. }
    15. }
    16. },
    17. "namespace": {
    18. "foo": {
    19. "acl": "write",
    20. "policy": "write",
    21. "key_prefix": {
    22. "": {
    23. "policy": "write"
    24. }
    25. },
    26. "session_prefix": {
    27. "": {
    28. "policy": "write"
    29. }
    30. },
    31. "service_prefix": {
    32. "": {
    33. "policy": "write"
    34. }
    35. },
    36. "node_prefix": {
    37. "": {
    38. "policy": "read"
    39. }
    40. }
    41. }
    42. }
    43. }
    1. {
    2. "namespace_prefix": {
    3. "policy": "write",
    4. "service_prefix": {
    5. "": {
    6. "policy": "read"
    7. }
    8. },
    9. "": {
    10. "policy": "read"
    11. }
    12. }
    13. }
    14. },
    15. "namespace": {
    16. "foo": {
    17. "acl": "write",
    18. "policy": "write",
    19. "key_prefix": {
    20. "": {
    21. "policy": "write"
    22. }
    23. },
    24. "session_prefix": {
    25. "": {
    26. "policy": "write"
    27. }
    28. },
    29. "service_prefix": {
    30. "": {
    31. "policy": "write"
    32. }
    33. },
    34. "node_prefix": {
    35. "": {
    36. "policy": "read"
    37. }
    38. }
    39. }
    40. }
    41. }

    The following restrictions apply when a rule is defined in any user-created namespace:

    1. operator rules are not allowed.
    2. rules are not allowed.
    3. keyring rules are not allowed.
    4. rules are not allowed.
    5. node rules that attempt to grant write privileges are not allowed.

    These restrictions do not apply to the default namespace created by Consul. In general all of the above are permissions that only an operator should have and thus granting these permissions can only be done within the default namespace.

    Rules and policies created within a namespace will inherit the namespace configuration. This means that rules and policies will be implicitly namespaced and do not need additional configuration. The restrictions outlined above will apply to these rules and policies. Additionally, rules and policies within a specific namespace are prevented from accessing resources in another namespace.

    The node and node_prefix resources control access to the following API behaviors:

    • node-level registration and read access to the
    • service discovery with the Health API
    • filtering results in operations, such as fetching the list of cluster members.

    You can use resource labels to scope the rule to a specific resource or set of resources.

    The following example rule uses an empty prefix label, which provides read-only access to all nodes. The rule also provides read-write access to the app node and denies all access to the admin node:

    Example node rules

    Example node rules

    HCL

    Rules Reference - 图10

    • HCL
    • JSON
    1. node_prefix "" {
    2. policy = "read"
    3. }
    4. node "app" {
    5. policy = "write"
    6. }
    7. node "admin" {
    8. policy = "deny"
    9. }
    1. node_prefix "" {
    2. policy = "read"
    3. }
    4. node "app" {
    5. policy = "write"
    6. }
    7. node "admin" {
    8. policy = "deny"
    9. }
    1. {
    2. "node_prefix": {
    3. "": {
    4. "policy": "read"
    5. },
    6. },
    7. "node": {
    8. "app": {
    9. "policy": "write"
    10. },
    11. "admin": {
    12. "policy": "deny"
    13. }
    14. }
    15. }

    Agents must be configured with write privileges for their own node name so that the agent can register their node metadata, tagged addresses, and other information in the catalog. If configured incorrectly, the agent will print an error to the console when it tries to sync its state with the catalog. Configure write access in the acl.tokens.agent parameter.

    The used by the agent should have read access to a given node so that the DNS interface can be queried.

    Node rules are used to filter query results when reading from the catalog or retrieving information from the health endpoints. This allows for configurations where a token has access to a given service name, but only on an allowed subset of node names.

    Consul agents check tokens locally when health checks are registered and when Consul performs periodic anti-entropy syncs. These actions may required an ACL token to complete. Use the following methods to configure ACL tokens for registration events:

    • Configure a global token in the parameter. This allows a single token to be used during all check registration operations.
    • Provide an ACL token with service and check definitions at registration time. This allows for greater flexibility and enables the use of multiple tokens on the same agent. Refer to the services and documentation for examples. Tokens may also be passed to the HTTP API for operations that require them.

    Operator Rules

    The operator resource controls access to cluster-level operations in the Operator API, other than the .

    Example operator rule

    Example operator rule

    HCL

    • HCL
    • JSON
    1. operator = "read"
    1. operator = "read"
    1. {
    2. "operator": "read"
    3. }
    1. {
    2. "operator": "read"
    3. }

    Prepared Query Rules

    The query and query_prefix resources control access to create, update, and delete prepared queries in the . Specify the resource label in query rules to determine the scope of the rule. The resource label in the following example is empty. As a result, the rules allow read-only access to query resources with any name. The rules also grant read-write access to the query named foo, which allows control of the query namespace to be delegated based on ACLs:

    Example query rules

    Example query rules

    HCL

    Rules Reference - 图12

    • HCL
    • JSON
    1. query_prefix "" {
    2. policy = "read"
    3. }
    4. query "foo" {
    5. policy = "write"
    6. }
    1. query_prefix "" {
    2. policy = "read"
    3. }
    4. query "foo" {
    5. policy = "write"
    6. }
    1. {
    2. "query_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "query": {
    8. "foo": {
    9. "policy": "write"
    10. }
    11. }
    12. }
    1. {
    2. "query_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "query": {
    8. "foo": {
    9. "policy": "write"
    10. }
    11. }
    12. }

    Executing queries is subject to node/node_prefix and service/service_prefix policies.

    There are a few variations when using ACLs with prepared queries, each of which uses ACLs in one of two ways: open, protected by unguessable IDs or closed, managed by ACL policies. These variations are covered here, with examples:

    • Static queries with no Name defined are not controlled by any ACL policies. These types of queries are meant to be ephemeral and not shared to untrusted clients, and they are only reachable if the prepared query ID is known. Since these IDs are generated using the same random ID scheme as ACL Tokens, it is infeasible to guess them. When listing all prepared queries, only a management token will be able to see these types, though clients can read instances for which they have an ID. An example use for this type is a query built by a startup script, tied to a session, and written to a configuration file for a process to use via DNS.

    • Static queries with a Name defined are controlled by the query and query_prefix ACL resources. Clients are required to have an ACL token with permissions on to access that query name. Clients can list or read queries for which they have “read” access based on their prefix, and similar they can update any queries for which they have “write” access. An example use for this type is a query with a well-known name (eg. prod-primary-customer-db) that is used and known by many clients to provide geo-failover behavior for a database.

    • Template queries queries work like static queries with a Name defined, except that a catch-all template with an empty Name requires an ACL token that can write to any query prefix.

    When prepared queries are executed via DNS lookups or HTTP requests, the ACL checks are run against the service being queried, similar to how ACLs work with other service lookups. There are several ways the ACL token is selected for this check:

    • If an ACL Token was captured when the prepared query was defined, it will be used to perform the service lookup. This allows queries to be executed by clients with lesser or even no ACL Token, so this should be used with care.

    • If no ACL Token was captured, then the client’s ACL Token will be used to perform the service lookup.

    • If no ACL Token was captured and the client has no ACL Token, then the anonymous token will be used to perform the service lookup.

    In the common case, the ACL Token of the invoker is used to test the ability to look up a service. If a Token was specified when the prepared query was created, the behavior changes and now the captured ACL Token set by the definer of the query is used when looking up a service.

    Capturing ACL Tokens is analogous to SECURITY DEFINER attribute which can be set on functions, and using the client’s ACL Token is similar to the complementary SECURITY INVOKER attribute.

    Prepared queries were originally introduced in Consul 0.6.0. The ACL behavior remained unchanged through version 0.6.3, but versions after 0.6.3 included changes that improve management of the prepared query namespace.

    These differences are outlined in the table below:

    OperationVersion <= 0.6.3Version > 0.6.3
    Create static query without NameThe 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.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.
    Create static query with NameThe 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.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.
    Manage static query without NameThe ACL Token used to create the query or a token with management privileges must be supplied in order to perform these operations.Any client with the ID of the query can perform these operations.
    Manage static query with a NameThe ACL token used to create the query or a token with management privileges must be supplied in order to perform these operations.Similar to create, the client token’s query ACL policy is used to determine if these operations are allowed.
    List queriesA token with management privileges is required to list any queries.The client token’s query ACL policy is used to determine which queries they can see. Only tokens with management privileges can see prepared queries without Name.
    Execute querySince 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.The captured token, client’s token, or anonymous token is used to filter the results, as described above.

    Service Rules

    The service and service_prefix resources control service-level registration and read access to the and service discovery with the Health API. Specify the resource label in service rules to set the scope of the rule. The resource label in the following example is empty. As a result, the rules allow read-only access to any service name with the empty prefix. The rules also allow read-write access to the app service and deny all access to the admin service:

    Example service rules

    Example service rules

    HCL

    • HCL
    • JSON
    1. service_prefix "" {
    2. policy = "read"
    3. }
    4. service "app" {
    5. policy = "write"
    6. }
    7. service "admin" {
    8. policy = "deny"
    9. }
    1. service_prefix "" {
    2. policy = "read"
    3. }
    4. service "app" {
    5. policy = "write"
    6. }
    7. service "admin" {
    8. policy = "deny"
    9. }
    1. {
    2. "service_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "service": {
    8. "app": {
    9. "policy": "write"
    10. },
    11. "admin": {
    12. "policy": "deny"
    13. }
    14. }
    15. }
    1. {
    2. "service_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "service": {
    8. "app": {
    9. "policy": "write"
    10. },
    11. "admin": {
    12. "policy": "deny"
    13. }
    14. }
    15. }

    Consul’s DNS interface is affected by restrictions on service rules. If the used by the agent does not have read access to a given service, then the DNS interface will return no records when queried for it.

    When reading from the catalog or retrieving information from the health endpoints, service rules are used to filter the results of the query.

    Service rules come into play when using the Agent API to register services or checks. The agent will check tokens locally as a service or check is registered, and Consul also performs periodic syncs, which may require an ACL token to complete. To accommodate this, Consul provides two methods of configuring ACL tokens to use for registration events:

    1. Using the acl.tokens.default configuration directive. This allows a single token to be configured globally and used during all service and check registration operations.
    2. Providing an ACL token with service and check definitions at registration time. This allows for greater flexibility and enables the use of multiple tokens on the same agent. Examples of what this looks like are available for both and checks. Tokens may also be passed to the for operations that require them. Note: all tokens passed to an agent are persisted on local disk to allow recovery from restarts. See -data-dir flag documentation for notes on securing access.

    In addition to ACLs, in Consul 0.9.0 and later, the agent must be configured with or enable_local_script_checks set to true in order to enable script checks.

    Service rules are also used to grant read or write access to intentions. The following policy provides read-write access to the “app” service, and explicitly grants intentions:read access to view intentions associated with the “app” service.

    Example service rule with intentions

    Example service rule with intentions

    HCL

    Rules Reference - 图14

    • HCL
    • JSON
    1. service "app" {
    2. policy = "write"
    3. intentions = "read"
    4. }
    1. service "app" {
    2. policy = "write"
    3. intentions = "read"
    4. }
    1. {
    2. "service": {
    3. "app": {
    4. "policy": "write",
    5. "intentions": "read"
    6. }
    7. }
    8. }
    1. {
    2. "service": {
    3. "app": {
    4. "policy": "write",
    5. "intentions": "read"
    6. }
    7. }
    8. }

    Refer to for more information about managing intentions access with service rules.

    The session and session_prefix resources controls access to Session API operations.

    Specify the resource label in session rules to set the scope of the rule. The resource label in the following example is empty. As a result, the rules allow read-only access to all sessions. The rules also allow creating sessions on the node named app and deny all access to any sessions on the admin node:

    Example session rules

    Example session rules

    HCL

    • HCL
    • JSON
    1. session_prefix "" {
    2. policy = "read"
    3. }
    4. session "app" {
    5. policy = "write"
    6. }
    7. session "admin" {
    8. policy = "deny"
    9. }
    1. session_prefix "" {
    2. policy = "read"
    3. }
    4. session "app" {
    5. policy = "write"
    6. }
    7. session "admin" {
    8. policy = "deny"
    9. }
    1. {
    2. "session_prefix": {
    3. "": {
    4. "policy": "read"
    5. }
    6. },
    7. "session": {
    8. "app": {
    9. "policy": "write"
    10. },
    11. "admin": {
    12. "policy": "deny"
    13. }