Consul
Create a UI token
This topic describes how to create a token that you can use to view resources in the Consul UI.
Introduction
To navigate the Consul UI when ACLs are enabled, log into the UI with a token linked to policies that grant an appropriate set of permissions. The UI is unable to display resources that the token does not have permission to access.
Requirements
Core ACL functionality is available in all versions of Consul.
Authentication
You must provide an ACL token linked to a policy with acl:write
permissions to create and modify ACL tokens and policies using the CLI or API.
You can provide the token manually using the -token
option on the command line, but we recommend setting the CONSUL_HTTP_TOKEN
environment variable to simplify your workflow:
$ export CONSUL_HTTP_TOKEN=<acl-token-secret-id>
The Consul CLI automatically reads the CONSUL_HTTP_TOKEN
environment variable so that you do not have to pass the token to every Consul CLI command.
To authenticate calls to the Consul HTTP API, you must provide the token in the X-Consul-Token
header for each call:
$ curl --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" ...
To learn about alternative ways to authenticate, refer to the following documentation:
View catalog in Consul CE
This section describes how to create a token that grants read-only access to the catalog. This token allows users to view the catalog without the ability to make changes. To create the ACL token, define a policy, create the policy, and then link the policy to a token.
Define a policy
You can send policy definitions as command line or API arguments or define them in an external HCL or JSON file. Refer to ACL Rules for details about all of the rules you can use in your policies.
The following example policy is defined in a file. The policy allows users that login with the token to view all services and nodes in the catalog.
service_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
Register the policy with Consul
After defining the policies, you can register them with Consul using the command line or API endpoint.
Run the consul acl policy create
command and specify the policy rules to create a policy. The following example registers a policy defined in ui-view-catalog.hcl
.
$ consul acl policy create \
-name "ui-view-catalog" -rules @ui-view-catalog.hcl \
-description "Allow viewing the catalog"
Refer to Consul ACL Policy Create for details about the consul acl policy create
command.
Link the policy to a token
After registering the policies into Consul, you can create and link tokens using the Consul command line or API endpoint. You can also enable Consul to dynamically create tokens from trusted external systems using an auth method.
Run the consul acl token create
command and specify the policy name or ID to create a token linked to the policy. Refer to Consul ACL Token Create for details about the consul acl token create
command.
The following command creates the ACL token linked to the policy ui-view-catalog
.
$ consul acl token create \
-description "UI token to view the catalog" \
-policy-name "ui-view-catalog"
View catalog in Consul Enterprise
This section describes how to create a token that grants read-only access to the catalog. This token allows users to view the catalog without the ability to make changes. To create the ACL token, define a policy, create the policy, and then link the policy to a token.
Define a policy
You can send policy definitions as command line or API arguments or define them in an external HCL or JSON file. Refer to ACL Rules for details about all of the rules you can use in your policies.
The following example policy is defined in a file. The following policy allows users that log in with the token to view services and nodes in the catalog in any partition and in any namespace. The operator:read
permission is needed to list partitions. Without this permission, you can still view resources within a partition but cannot easily navigate to other partitions in the Consul UI.
operator = "read"
partition_prefix "" {
namespace_prefix "" {
service_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
}
}
Register the policy with Consul
After defining the policies, you can register them with Consul using the command line or API endpoint.
Run the consul acl policy create
command and specify the policy rules to create a policy. The following example registers a policy defined in ui-view-catalog.hcl
.
You can specify an admin partition and namespace when registering policies in Consul Enterprise. Policies are only valid in the scopes specified during registration, but you can grant tokens registered in the default
partition permission to access resources in a different partition than where the token was registered. Refer to the admin partition documentation for additional information.
The following example registers the policy in the default
partition and the default
namespace because the policy grants cross-partition and cross-namespace access.
$ consul acl policy create -partition "default" -namespace "default" \
-name "ui-view-catalog" -rules @ui-view-catalog.hcl \
-description "Allow viewing the catalog"
Refer to Consul ACL Policy Create for details about the consul acl policy create
command.
Link the policy to a token
After registering the policies into Consul, you can create and link tokens using the Consul command line or API endpoint. You can also enable Consul to dynamically create tokens from trusted external systems using an auth method.
Run the consul acl token create
command and specify the policy name or ID to create a token linked to the policy. Refer to Consul ACL Token Create for details about the consul acl token create
command.
$ consul acl token create -partition "default" -namespace "default" \
-description "UI token to view the catalog" \
-policy-name "ui-view-catalog"
View all resources in Consul CE
This section describes how to create a token with read-only access to all resources in the Consul UI. This token allows users to view any resources without the ability to make changes. To create the ACL token, define a policy, create the policy, and then link the policy to a token.
Define a policy
You can send policy definitions as command line or API arguments or define them in an external HCL or JSON file. Refer to ACL Rules for details about all of the rules you can use in your policies.
The following example policy is defined in a file. The policy allows users that log in with the token to view all services and nodes in the catalog, all objects in the key/value store, all intentions, and all ACL resources. The acl:read
permission does not allow viewing the token secret ids.
acl = "read"
key_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
operator = "read"
service_prefix "" {
policy = "read"
intentions = "read"
}
Register the policy with Consul
After defining the policies, you can register them with Consul using the command line or API endpoint.
Run the consul acl policy create
command and specify the policy rules to create a policy. The following example registers a policy defined in ui-view-all.hcl
.
$ consul acl policy create \
-name "ui-view-all" -rules @ui-view-all.hcl \
-description "Allow viewing all resources"
Refer to Consul ACL Policy Create for details about the consul acl policy create
command.
Link the policy to a token
After registering the policies into Consul, you can create and link tokens using the Consul command line or API endpoint. You can also enable Consul to dynamically create tokens from trusted external systems using an auth method.
Run the consul acl token create
command and specify the policy name or ID to create a token linked to the policy. Refer to Consul ACL Token Create for details about the consul acl token create
command.
The following command creates the ACL token linked to the policy ui-view-all
.
$ consul acl token create \
-description "UI token to view all resources" \
-policy-name "ui-view-all"
View all resources in Consul Enterprise
This section describes how to create a token with read-only access to all resources in the Consul UI. This token allows users to view any resources without the ability to make changes. To create the ACL token, define a policy, create the policy, and then link the policy to a token.
Define a policy
You can send policy definitions as command line or API arguments or define them in an external HCL or JSON file. Refer to ACL Rules for details about all of the rules you can use in your policies.
The following example policy is defined in a file. The policy allows users that log in with the token to view all services and nodes in the catalog, all objects in the key-value store, all intentions, and all ACL resources in any namespace and any partition. The acl:read
permission does not allow viewing the token secret ids.
operator = "read"
partition_prefix "" {
namespace_prefix "" {
acl = "read"
key_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
service_prefix "" {
policy = "read"
intentions = "read"
}
}
}
Register the policy with Consul
After defining the policies, you can register them with Consul using the command line or API endpoint.
Run the consul acl policy create
command and specify the policy rules to create a policy. The following example registers a policy defined in ui-view-all.hcl
.
You can specify an admin partition and namespace when creating policies in Consul Enterprise. The policy is only valid in the specified scopes. Because the policy grants cross-partition and cross-namespace access, the policy must be created in the default
partition and the default
namespace.
$ consul acl policy create -partition "default" -namespace "default" \
-name "ui-view-all" -rules @ui-view-all.hcl \
-description "Allow viewing all resources"
Refer to Consul ACL Policy Create for details about the consul acl policy create
command.
Link the policy to a token
After registering the policies into Consul, you can create and link tokens using the Consul command line or API endpoint. You can also enable Consul to dynamically create tokens from trusted external systems using an auth method.
Run the consul acl token create
command and specify the policy name or ID to create a token linked to the policy. Refer to Consul ACL Token Create for details about the consul acl token create
command.
$ consul acl token create -partition "default" -namespace "default" \
-description "UI token to view all resources" \
-policy-name "ui-view-all"