Introduction
Learn how to configure the AppRole authentication method in HashiCorp Vault using direct API calls. This guide covers:- Enabling the AppRole auth method
- Creating an AppRole with specific policies
- Retrieving the
Role IDandSecret ID - Authenticating with the generated credentials
Prerequisites
- A running Vault server at
http://127.0.0.1:8200 - A valid Vault token exported as an environment variable:
Never commit your
VAULT_TOKEN or any sensitive credentials to version control.1. Enable the AppRole Auth Method
First, enable the AppRole authentication backend:-
Create an
auth.jsonfile: -
Use
curlto enable AppRole: -
Verify the mount:
approle/.
2. Create an AppRole with Policies
Define which policies this AppRole will use:-
Create
policies.json: -
Create the AppRole named
vaultcourse:
3. Fetch the Role ID
Each AppRole has a uniqueRole ID. Retrieve it:
data.role_id in the JSON response.
4. Generate a Secret ID
Generate theSecret ID needed alongside the Role ID:
data.secret_iddata.secret_id_accessor
Quick Reference Table
| Step | Endpoint | Method | Description |
|---|---|---|---|
| 1 | /v1/sys/auth/approle | POST | Enable AppRole auth method |
| 2 | /v1/auth/approle/role/vaultcourse | POST | Create an AppRole with specified policies |
| 3 | /v1/auth/approle/role/vaultcourse/role-id | GET | Retrieve the AppRole Role ID |
| 4 | /v1/auth/approle/role/vaultcourse/secret-id | POST | Generate the Secret ID |
| 5 | /v1/auth/approle/login | POST | Authenticate using Role ID and Secret ID |