Search code examples
python-3.xhashicorp-vault

Vault token lookup - Python


I'm trying to renew token and trying to output token info. How can i get token_lookup details using hvac.

checked with the following without any luck.

VAULT_URL = "https://vault.com"
VAULT_TOKEN = ".sasassasas"

client = hvac.Client(url=VAULT_URL, verify=False, token=VAULT_TOKEN)


auth = client.is_authenticated()
print(auth)
response = client.read(path="secret/apps/USERNAME/v1")
print(response)
renew_state = client.renew_token()
print(renew_state)
lookup = client.lookup_token(token=VAULT_TOKEN)
print(lookup). ## this one failed with

hvac.exceptions.Forbidden: 1 error occurred:


Solution

  • This is a permissions issue that may be due to the associated policy with the token. It may also be due to the underlying API where you are invoking against an endpoint for renewing a different token instead of the same token, and also using the old bindings. If you update the code for both:

    client.auth.token.renew_self()
    

    then that will fix two issues and may also fix root cause. Otherwise, you will need to fix the authorization policy (currently not shared in question). Documentation for corrected method can be found here.