Skip to main content
Welcome to the final lab of this guide. Here you’ll leverage an existing bootstrap ACL token to authenticate HTTP requests against the Consul Key/Value (K/V) store. This demonstration covers:
  1. Loading the token from a file
  2. Creating or recreating an ACL policy
  3. Retrieving K/V entries via curl and jq
  4. Two authentication methods for the Consul API
Before proceeding, ensure Consul is running and you have access to the consul binary. For more details, see the Consul documentation.

1. Export the ACL Token

Set the CONSUL_HTTP_TOKEN_FILE environment variable to read your token from token.txt:
Keep your token file secure. Avoid committing it to version control or sharing it publicly.

2. Create (or Recreate) an ACL Policy

Use consul acl policy create to define a policy with the required rules. If the policy name already exists, choose a new one:
Sample output after creating test456:

3. Verify Your Token and List K/V Entries

Clear your terminal and display the token:
Then list all keys in the K/V store:
Expected output:

4. Authenticate API Requests

Now that you know the key (apps/eCommerce/database_host) and have your ACL token, you can fetch its value using the Consul HTTP API. Below are two supported methods:

Method 1: X-Consul-Token Header

Response:

Method 2: Authorization Bearer Header

The JSON payload returned is identical to Method 1.
You’ve now learned how to authenticate Consul API requests using an ACL token—either via X-Consul-Token or the standard Authorization: Bearer header. For more information, refer to the Consul API KV documentation.

Watch Video

Practice Lab