- Loading the token from a file
- Creating or recreating an ACL policy
- Retrieving K/V entries via
curlandjq - 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 theCONSUL_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
Useconsul acl policy create to define a policy with the required rules. If the policy name already exists, choose a new one:
test456:
3. Verify Your Token and List K/V Entries
Clear your terminal and display the token: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:
| Header Type | Description | Header Example |
|---|---|---|
| X-Consul-Token | Consul-specific token header | X-Consul-Token: c7142d5a-aba1-78ba-f521-... |
| Authorization | Standard HTTP Bearer token | Authorization: Bearer c7142d5a-aba1-78ba... |
Method 1: X-Consul-Token Header
Method 2: Authorization Bearer Header
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.