Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 using HVAC with "approle" authentication to pull secret from Hashivault

Need some help please!!!

I have working code to pull a secret out of Hashi using the Management token, but... I need to switch this around to use the "approle" type authentication and do not understand the authentication differences.

My original code used something like this:

def vault(KEY):
    VAULT_SERVER = "https://myserver.nowhere.com:8243"
    TOKEN = "s.xxxxxxxxxxxxxxxxxxxxxxxx"
    PATH = "/secret/vault/200245/mbop200245/nonprod/testautomation/dev"
    CLIENT = hvac.Client(url=VAULT_SERVER, token=TOKEN)
    VAULT = CLIENT.read(path=PATH)
    SECRETS = VAULT['data']
    ID_PASSWORD = SECRETS[KEY]
    return ID_PASSWORD

Anyone have any code examples of using hvac with "approle"? I know how to do this in API (using Insomnia) but struggling with what hvac expects... and where...

Thanks!!!

like image 789
CTinMich Avatar asked Jul 27 '26 11:07

CTinMich


1 Answers

Have you tried the docs? There is a whole section on Approle: https://hvac.readthedocs.io/en/stable/usage/auth_methods/approle.html

In particular, there is this snippet for authentication:

import hvac
client = hvac.Client()


client.auth.approle.login(
    role_id='<some_role_id>',
    secret_id='<some_secret_id>',
)
like image 150
lxop Avatar answered Jul 30 '26 08:07

lxop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!