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:

  1. $ 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:

  1. $ curl --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" ...

To learn about alternative ways to authenticate, refer to the following documentation:

View catalog in Consul OSS

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.

  1. service_prefix "" {
  2. policy = "read"
  3. }
  4. node_prefix "" {
  5. policy = "read"
  6. }
  1. {
  2. "node_prefix": {
  3. "": [{
  4. "policy": "read"
  5. }]
  6. },
  7. "service_prefix": {
  8. "": [{
  9. "policy": "read"
  10. }]
  11. }
  12. }

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.

  1. $ consul acl policy create \
  2. -name "ui-view-catalog" -rules @ui-view-catalog.hcl \
  3. -description "Allow viewing the catalog"

Refer to Consul ACL Policy Create for details about the consul acl policy create command.

Send a PUT request to the /acl/policy endpoint and specify the policy rules in the request body to create a policy. The following example registers the policy defined in view-catalog.hcl. You must embed the policy rules in the Rules field of the request body.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/policy \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Name": "ui-view-catalog",
  5. "Description": "Allow viewing the catalog",
  6. "Rules": "service_prefix \"\" {\n policy = \"read\"\n}\nnode_prefix \"\" {\n policy = \"read\"\n}\n"
  7. }'

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.

  1. $ consul acl token create \
  2. -description "UI token to view the catalog" \
  3. -policy-name "ui-view-catalog"

Send a PUT request to the /acl/token endpoint and specify the policy name or ID in the request to create an ACL token linked to the policy. Refer to ACL Token HTTP API for additional information about using the API endpoint.

The following example creates an ACL token that you can use to login to the UI and view the catalog.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/token \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Policies": [
  5. {
  6. "Name": "ui-view-catalog"
  7. }
  8. ]
  9. }'

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.

  1. operator = "read"
  2. partition_prefix "" {
  3. namespace_prefix "" {
  4. service_prefix "" {
  5. policy = "read"
  6. }
  7. node_prefix "" {
  8. policy = "read"
  9. }
  10. }
  11. }
  1. {
  2. "partition_prefix": {
  3. "": [{
  4. "namespace_prefix": {
  5. "": [{
  6. "node_prefix": {
  7. "": [{
  8. "policy": "read"
  9. }]
  10. },
  11. "service_prefix": {
  12. "": [{
  13. "policy": "read"
  14. }]
  15. }
  16. }]
  17. }
  18. }]
  19. }
  20. }

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.

  1. $ consul acl policy create -partition "default" -namespace "default" \
  2. -name "ui-view-catalog" -rules @ui-view-catalog.hcl \
  3. -description "Allow viewing the catalog"

Refer to Consul ACL Policy Create for details about the consul acl policy create command.

Send a PUT request to the /acl/policy endpoint and specify the policy rules in the request body to create a policy. The following example registers the policy defined in view-catalog.hcl. You must embed the policy rules in the Rules field of the request body.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/policy \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Name": "ui-view-catalog",
  5. "Description": "Allow viewing the catalog",
  6. "Partition": "default",
  7. "Namespace": "default",
  8. "Rules": "partition_prefix \"\" {\n namespace_prefix \"\" {\n service_prefix \"\" {\n policy = \"read\"\n }\n node_prefix \"\" {\n policy = \"read\"\n }\n }\n}\n"
  9. }'

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.

  1. $ consul acl token create -partition "default" -namespace "default" \
  2. -description "UI token to view the catalog" \
  3. -policy-name "ui-view-catalog"

Send a PUT request to the /acl/token endpoint and specify the policy name or ID in the request to create an ACL token linked to the policy. Refer to ACL Token HTTP API for additional information about using the API endpoint.

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.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/token \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Policies": [
  5. {
  6. "Name": "ui-view-catalog"
  7. }
  8. ],
  9. "Partition": "default",
  10. "Namespace": "default"
  11. }'

View all resources in Consul OSS

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.

  1. acl = "read"
  2. key_prefix "" {
  3. policy = "read"
  4. }
  5. node_prefix "" {
  6. policy = "read"
  7. }
  8. operator = "read"
  9. service_prefix "" {
  10. policy = "read"
  11. intentions = "read"
  12. }
  1. {
  2. "acl": "read",
  3. "key_prefix": {
  4. "": [{
  5. "policy": "read"
  6. }]
  7. },
  8. "node_prefix": {
  9. "": [{
  10. "policy": "read"
  11. }]
  12. },
  13. "operator": "read",
  14. "service_prefix": {
  15. "": [{
  16. "intentions": "read",
  17. "policy": "read"
  18. }]
  19. }
  20. }

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.

  1. $ consul acl policy create \
  2. -name "ui-view-all" -rules @ui-view-all.hcl \
  3. -description "Allow viewing all resources"

Refer to Consul ACL Policy Create for details about the consul acl policy create command.

Send a PUT request to the /acl/policy endpoint and specify the policy rules in the request body to create a policy. The following example registers the policy defined in ui-view-all.hcl. You must embed the policy rules in the Rules field of the request body.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/policy \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Name": "ui-view-all",
  5. "Description": "Allow viewing all resources",
  6. "Rules": "acl = \"read\"\nkey_prefix \"\" {\n policy = \"read\"\n}\nnode_prefix \"\" {\n policy = \"read\"\n}\noperator = \"read\"\nservice_prefix \"\" {\n policy = \"read\"\n intentions = \"read\"\n}\n"
  7. }'

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.

  1. $ consul acl token create \
  2. -description "UI token to view all resources" \
  3. -policy-name "ui-view-all"

Send a PUT request to the /acl/token endpoint and specify the policy name or ID in the request to create an ACL token linked to the policy. Refer to ACL Token HTTP API for additional information about using the API endpoint.

The following example creates an ACL token that you can use to login to the UI and view the catalog.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/token \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Policies": [
  5. {
  6. "Name": "ui-view-all"
  7. }
  8. ]
  9. }'

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.

  1. operator = "read"
  2. partition_prefix "" {
  3. namespace_prefix "" {
  4. acl = "read"
  5. key_prefix "" {
  6. policy = "read"
  7. }
  8. node_prefix "" {
  9. policy = "read"
  10. }
  11. service_prefix "" {
  12. policy = "read"
  13. intentions = "read"
  14. }
  15. }
  16. }
  1. {
  2. "operator": "read",
  3. "partition_prefix": {
  4. "": [{
  5. "namespace_prefix": {
  6. "": [{
  7. "acl": "read",
  8. "key_prefix": {
  9. "": [{
  10. "policy": "read"
  11. }]
  12. },
  13. "node_prefix": {
  14. "": [{
  15. "policy": "read"
  16. }]
  17. },
  18. "service_prefix": {
  19. "": [{
  20. "intentions": "read",
  21. "policy": "read"
  22. }]
  23. }
  24. }]
  25. }
  26. }]
  27. }
  28. }

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.

  1. $ consul acl policy create -partition "default" -namespace "default" \
  2. -name "ui-view-all" -rules @ui-view-all.hcl \
  3. -description "Allow viewing all resources"

Refer to Consul ACL Policy Create for details about the consul acl policy create command.

Send a PUT request to the /acl/policy endpoint and specify the policy rules in the request body to create a policy. The following example registers the policy defined in ui-view-all.hcl. You must embed the policy rules in the Rules field of the request body.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/policy \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Name": "ui-view-all",
  5. "Description": "Allow viewing all resources",
  6. "Partition": "default",
  7. "Namespace": "default",
  8. "Rules": "operator = \"read\"\npartition_prefix \"\" {\n namespace_prefix \"\" {\n acl = \"read\"\n key_prefix \"\" {\n policy = \"read\"\n }\n node_prefix \"\" {\n policy = \"read\"\n }\n service_prefix \"\" {\n policy = \"read\"\n intentions = \"read\"\n }\n }\n}\n"
  9. }'

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.

  1. $ consul acl token create -partition "default" -namespace "default" \
  2. -description "UI token to view all resources" \
  3. -policy-name "ui-view-all"

Send a PUT request to the /acl/token endpoint and specify the policy name or ID in the request to create an ACL token linked to the policy. Refer to ACL Token HTTP API for additional information about using the API endpoint.

You can specify an admin partition and namespace when creating tokens in Consul Enterprise. The token is only valid in the specified scopes. Because the policy was created in the default partition and default namespace, the token must also be created in the default partition and default namespace.

  1. $ curl --request PUT http://127.0.0.1:8500/v1/acl/token \
  2. --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
  3. --data '{
  4. "Policies": [
  5. {
  6. "Name": "ui-view-all"
  7. }
  8. ],
  9. "Partition": "default",
  10. "Namespace": "default"
  11. }'