Skip to content

OpenBao AppRole “invalid role or secret ID”: secret ID used up

Securitytested on OpenBao v2.7.1

“invalid role or secret ID” sounds like a wrong role ID, but it is almost always a secret ID past its use limit or lifetime. That is exactly how AppRole is meant to work: secret IDs are throwaway passes.

Symptom

ROLE_ID=$(bao read -field=role_id auth/approle/role/webshop/role-id)
SECRET_ID=$(bao write -f -field=secret_id auth/approle/role/webshop/secret-id)
bao write auth/approle/login role_id=$ROLE_ID secret_id=$SECRET_ID
bao write auth/approle/login role_id=$ROLE_ID secret_id=$SECRET_ID
Key                     Value
---                     -----
token                   s.nFjFikeldgveVuN6umToj95T
token_duration          20m
token_policies          ["default" "webshop-read"]
token_meta_role_name    webshop
Error writing data to auth/approle/login: Error making API request.
Code: 400. Errors:

* invalid role or secret ID

The first login works, the second with the same secret ID does not.

Diagnosis

The values shown when the secret ID is created tell you the use limit and lifetime.

secret_id             c0fbd747-8419-035d-be8d-6c2f3e7e5b47
secret_id_accessor    1737860f-c4c6-26a2-d5e3-a65bca0c008f
secret_id_num_uses    1
secret_id_ttl         10m

Causes

num_uses 1Use limit reached

With secret_id_num_uses=1 every secret ID is valid exactly once. The second login is rejected.

ttlSecret ID expired

secret_id_ttl=10m: after ten minutes the secret ID is worthless, even if it was never used.

CIDRSource IP does not match the binding

With secret_id_bound_cidrs OpenBao rejects logins from other addresses – with its own, clearer message.

bao write auth/approle/role/webshop secret_id_bound_cidrs=10.0.0.0/8
SECRET_ID=$(bao write -f -field=secret_id auth/approle/role/webshop/secret-id)
bao write auth/approle/login role_id=$ROLE_ID secret_id=$SECRET_ID
Code: 400. Errors:

* source address "127.0.0.1" unauthorized by CIDR restrictions on the role: %!w(<nil>)

Fix

Create a new secret ID for every login (or hand it over with response wrapping) and use it right away.
SECRET_ID=$(bao write -f -field=secret_id auth/approle/role/webshop/secret-id)
curl -s -X POST -d "{\"role_id\":\"$ROLE_ID\",\"secret_id\":\"$SECRET_ID\"}" \
  $BAO_ADDR/v1/auth/approle/login | jq -c '.auth | {policies, lease_duration, metadata}'
{"policies":["default","webshop-read"],"lease_duration":1200,
 "metadata":{"role_name":"webshop"}}

Don't: Do not set the use limit to 0 (unlimited) just so an app can reuse the secret ID – then it is a permanent password.

▶
Break it yourself and find it – free
OpenBao hands-on, Day 3: auth methods – userpass, AppRole with secret IDs, CIDR binding and response wrapping.
Go to day 3 →

FAQ

Why is there no bao login -method=approle?

The CLI has no login helper for AppRole; you write directly to auth/approle/login.

What does %!w(<nil>) in the CIDR message mean?

A formatting bug in OpenBao v2.7.1, not a problem with your configuration.

Related error patterns

More