Skip to main content

HashiCorp Vault and OpenBao CLI authentication

authentik: 2025.12.0+

You can use the authentik Agent to run the HashiCorp Vault CLI (vault) or the OpenBao CLI (bao) with your authentik credentials, without running vault login.

ak auth vault exchanges your authentik token for a token for the Vault application in authentik, uses it to log in to a JWT auth method in Vault, and runs the CLI with the resulting Vault token.

Prerequisites​

authentik configuration​

Create an application and provider in authentik for Vault​

  1. Log in to authentik as an administrator and open the authentik Admin interface.

  2. Navigate to Applications > Applications and click New Application to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)

    • Application: provide a descriptive name (e.g. vault), an optional group for the type of application, the policy engine mode, and optional UI settings. Note the application slug.
    • Choose a Provider Type: select OAuth2/OpenID Connect as the provider type.
    • Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
      • Set the Client Type to Public.
      • Set the Client ID to vault.
      • Select any available signing key.
      • Under Machine-to-Machine authentication settings add the authentik-cli provider to Federated OAuth2/OpenID Providers.
    • Configure Bindings (optional): you can create a binding (policy, group, or user) to manage access to the application.
  3. Click Submit to save the new application and provider.

The token that the authentik Agent requests has the openid, email, and profile scopes. The default profile scope mapping provides the preferred_username and groups claims that the Vault role below uses.

Vault configuration​

Enable a JWT auth method in Vault or OpenBao, point it to authentik, and create a role for authentik users. The OpenBao commands are the same, with bao in place of vault.

Use JWT mode

Configure the auth method with oidc_discovery_url only. If you also set oidc_client_id and oidc_client_secret, the auth method runs in OIDC mode, which is meant for browser logins and rejects the tokens of the authentik Agent. If you already have an OIDC auth method for browser logins, enable a separate auth method for the authentik Agent, for example at the path authentik-agent.

vault auth enable jwt
vault write auth/jwt/config \
oidc_discovery_url="https://authentik.company/application/o/<application_slug>/"
vault write auth/jwt/role/authentik \
role_type="jwt" \
bound_audiences="vault" \
user_claim="preferred_username" \
groups_claim="groups" \
token_policies="default" \
token_ttl="1h"
  • bound_audiences must match the Client ID of the provider.
  • token_policies sets the Vault policies that every user of this role gets. To give authentik groups their own Vault policies, create external groups with the accessor of this auth method.

Run the CLI with authentik credentials​

ak auth vault takes the following options, followed by -- and the arguments for the Vault CLI:

OptionRequiredDescription
-c, --client-idYesThe Client ID of the provider in authentik, for example vault.
-r, --roleYesThe name of the JWT role in Vault, for example authentik.
-a, --addressUnless VAULT_ADDR is setThe address of Vault, for example https://vault.company.
-m, --mountNoThe path of the JWT auth method. Defaults to jwt.
-b, --binNoThe CLI to run. Defaults to vault. Set it to bao for OpenBao.

To use the command in place of the CLI, add an alias to your shell configuration, for example to ~/.bashrc or ~/.zshrc:

alias vault='ak auth vault -c vault -r authentik -a https://vault.company --'

To verify, run vault token lookup (or bao token lookup). The output should show a token for your authentik username.

The CLI runs with VAULT_ADDR, VAULT_TOKEN, BAO_ADDR, and BAO_TOKEN set. The authentik Agent caches the Vault token on the device until the token expires, so later commands don't log in to Vault again. If you revoke the token in Vault, commands fail until the cached token expires.

Troubleshooting​

Errors from Vault are shown after Error in HTTP request:, together with the HTTP status code.

error configuring token validator: unsupported config type​

The auth method is configured for OIDC logins. Remove oidc_client_id and oidc_client_secret from its configuration, or use a separate auth method. Refer to Vault configuration.

error validating token: invalid audience (aud) claim​

bound_audiences of the role doesn't match the Client ID of the provider in authentik.

failed to exchange token​

authentik didn't issue a token for the Vault application. Possible causes:

  • The authentik-cli provider isn't listed in Federated OAuth2/OpenID Providers of the Vault provider.
  • A binding or policy denies you access to the Vault application.
  • The authorization.allowed_exchange_audiences setting of the authentik Agent doesn't include the Client ID.