Auth Methods: userpass & AppRole
An auth method checks some proof of identity and returns a token with policies. Vault has many; which one fits depends on who is logging in:
| Who | Auth method |
|---|---|
| People | oidc (SSO through Okta, Entra ID, Google, Keycloak, …), ldap; userpass for labs and break-glass accounts |
| CI jobs | jwt with the CI system's OIDC token (JWT/OIDC Auth for CI) |
| Kubernetes pods | kubernetes with the pod's service-account token (Kubernetes Auth) |
| Cloud VMs and functions | aws, azure, gcp (the platform's signed identity) |
| Anything else (VMs on-prem, legacy apps) | approle, cert (TLS client certificates) |
The rule of thumb: prefer methods where the platform vouches for the identity (OIDC, Kubernetes, cloud IAM), because then nobody has to distribute a secret zero. AppRole is the fallback when no platform identity exists.
Auth methods are mounted under auth/ like engines are mounted at paths: vault auth enable approle creates auth/approle/.
userpass
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
printf 'path "secret/data/linkly/*" {\n capabilities = ["read"]\n}\n' | vault policy write linkly-read - > /dev/null
vault auth enable userpass
vault write auth/userpass/users/ada password='lab-only-pw' token_policies=linkly-read token_ttl=1h > /dev/null
# log in through the API path (vault login would also store the token in ~/.vault-token)
vault write -format=json auth/userpass/login/ada password='lab-only-pw' \
| jq '.auth | {token_policies, lease_duration, metadata}'
vault write auth/userpass/login/ada password='guess' 2>&1 | grep -E '^\*'Success! Enabled userpass auth method at: userpass/
{
"token_policies": [
"default",
"linkly-read"
],
"lease_duration": 3600,
"metadata": {
"username": "ada"
}
}
* invalid username or password
token_policies, token_ttl, token_max_ttl, token_type and token_bound_cidrs are the same token parameters on every auth method's users and roles, so what you learn here applies to all of them.
AppRole: a role id and a secret id
AppRole splits the credential in two:
role_id: like a username. Not secret on its own; often baked into the VM image or the deployment config.secret_id: like a password, generated per instance, ideally single-use and short-lived, delivered by a trusted orchestrator at deploy time.
An attacker needs both. The orchestrator that delivers the secret_id should never see the role_id, and the other way round.
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
vault kv put -mount=secret linkly/db password='c0rrect-h0rse' > /dev/null
printf 'path "secret/data/linkly/*" {\n capabilities = ["read"]\n}\n' | vault policy write linkly-read - > /dev/null
vault auth enable approle > /dev/null
vault write auth/approle/role/linkly token_policies=linkly-read token_ttl=20m token_max_ttl=1h \
secret_id_ttl=10m secret_id_num_uses=1 > /dev/null
vault read -format=json auth/approle/role/linkly | jq -c '.data | {token_policies, token_ttl, secret_id_num_uses, secret_id_ttl}'
ROLE_ID=$(vault read -field=role_id auth/approle/role/linkly/role-id)
SECRET_ID=$(vault write -f -field=secret_id auth/approle/role/linkly/secret-id)
echo "--- first login"
APP_TOKEN=$(vault write -field=token auth/approle/login role_id=$ROLE_ID secret_id=$SECRET_ID)
VAULT_TOKEN=$APP_TOKEN vault kv get -mount=secret -field=password linkly/db; echo
echo "--- replaying the same secret_id"
vault write auth/approle/login role_id=$ROLE_ID secret_id=$SECRET_ID 2>&1 | grep -E '^\*'{"token_policies":["linkly-read"],"token_ttl":1200,"secret_id_num_uses":1,"secret_id_ttl":600}
--- first login
c0rrect-h0rse
--- replaying the same secret_id
* invalid role or secret ID
The second login failed because secret_id_num_uses=1: a stolen, already-used secret id is worthless, and a failed login by the real instance is a signal that someone else used it first.
Response wrapping: delivering secret zero
How does the secret_id reach the instance without passing through logs and config systems in plain text? Response wrapping: Vault stores the response in a single-use cubbyhole and returns a wrapping token instead. Only the first unwrap succeeds:
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
vault auth enable approle > /dev/null
vault write auth/approle/role/linkly token_policies=default secret_id_num_uses=1 > /dev/null
# the orchestrator asks for a wrapped secret id, valid for 60 seconds
WRAP=$(vault write -f -wrap-ttl=60s -field=wrapping_token auth/approle/role/linkly/secret-id)
vault token lookup -format=json $WRAP | jq -c '.data | {policies, num_uses, ttl_le_60: (.ttl <= 60)}'
# the instance unwraps it once
vault unwrap -format=json $WRAP | jq -c '.data | {has_secret_id: (.secret_id | length > 0), secret_id_num_uses}'
# anyone who intercepted the wrapping token is too late, and the failure is visible
vault unwrap $WRAP 2>&1 | grep -E '^\*'{"policies":["response-wrapping"],"num_uses":1,"ttl_le_60":true}
{"has_secret_id":true,"secret_id_num_uses":1}
* wrapping token is not valid or does not exist
If the instance's own unwrap fails, the wrapping token was used by someone else: treat it as an incident and revoke the role's secret ids (vault write -f auth/approle/role/linkly/secret-id/destroy … or regenerate).
Test yourself
In AppRole, which part should be short-lived and single-use?
- The role_id
- The secret_id
- The policy
- The mount path
What does response wrapping protect against?
- Slow networks
- Undetected interception: the wrapped response can be unwrapped only once, so a thief's use makes the real recipient's unwrap fail
- Expired policies
- Vault being sealed
Why prefer Kubernetes, cloud or CI OIDC auth over AppRole where possible?
- They are faster
- The platform vouches for the identity, so no secret zero has to be distributed
- AppRole is deprecated
- They don't need policies