Vault Tokens · Topic 1 of 3

Service and Batch Tokens

Vault Associate (003): compare service and batch tokens, choose the right type for a use case, and create tokens with the right type, policy and TTL.

  • 4 min
In a nutshell
  • Service tokens support renewal, revocation, children, accessors and cubbyholes; batch tokens support none of these.
  • Batch tokens are not stored by Vault, so they are cheap to create at scale.
  • The hvs. prefix is service, hvb. is batch, and the default type for vault token create is service.

What it is

Vault issues a token after every successful login, and the token is what Vault checks on each authenticated request. There are two main kinds. Service tokens are the standard, full-featured tokens, and batch tokens are lightweight encrypted blobs.

You choose the type by the job. You then create the token with the CLI, the API, or by logging in to an auth method that is configured to issue it.

Needwhat will the token doPick typeservice or batchCreatevault token createUsepolicies and TTL apply

How it works

Service versus batch

A service token is stored by Vault, which is why it can be renewed, revoked and used as a parent. A batch token is not stored, so creating one has no storage cost and scales well.

FeatureServiceBatch
Prefixhvs.hvb.
Stored by VaultYesNo
RenewableYesNo
Manually revocableYesNo
Can create child tokensYesNo
Can be a root tokenYesNo
Can be periodicYesNo
Has an accessorYesNo
Has a cubbyholeYesNo
Explicit max TTLYesNo, fixed TTL only
Parent revoked (if not orphan)RevokedStops working
Dynamic secret leases assigned toThe token itselfThe parent (if not orphan)
Usable across performance replication clustersNoYes, if orphan

The prefixes apply to Vault 1.10 and later. Older versions used s. and b..

Choosing the type

Pick service by default. You need it when the client must renew, revoke early, create child tokens, use a cubbyhole or hold a periodic token.

Pick batch when many short-lived clients each need a token and the cost of storing every token would hurt. A fleet of containers starting at once is one example.

Creating tokens

vault token create makes a service token unless you ask otherwise. The new token gets the default policy plus any you list, and with no -policy it takes all of the calling token's policies.

vault token create -policy=app-read -ttl=1h
vault token create -type=batch -policy=app-read -ttl=30m
vault token create -policy=app-read -use-limit=3
vault token create -no-default-policy -policy=app-read
FlagEffect
-policyAttaches a policy; repeat for more
-ttlInitial lifetime
-typeservice (default) or batch
-use-limitUses before the token is revoked; 0 is unlimited
-renewableAllows renewal; true by default
-no-default-policyLeaves out the default policy
-roleCreates the token from a token store role

Unless the caller is root or has sudo on auth/token/create, the policies on a new token must be a subset of the caller's own.

Every successful login also returns a token. It is a service token unless the auth method's role or the mount's token_type setting asks for batch. The API equivalent of the command is POST /auth/token/create, with type as a parameter.

How the exam asks about this

  • "Thousands of short-lived containers each need a token, and storage cost is a concern." Batch tokens, because they are not stored.
  • "An application must renew its token before it expires." A service token, since batch tokens are not renewable.
  • "A token lookup shows an ID starting with hvb. and no accessor." It is a batch token.

What to remember for the exam

  • Service tokens support renewal, revocation, children, accessors and cubbyholes; batch tokens support none of these.
  • Batch tokens are not stored by Vault, so they are cheap to create at scale.
  • The hvs. prefix is service, hvb. is batch, and the default type for vault token create is service.
  • A batch token cannot be renewed at all; it lives for its fixed TTL.
  • A token created with -policy also gets default unless you pass -no-default-policy.
  • A token with a use limit is revoked after its last use even if TTL remains.
Watch out

Do not rely on the exact structure of a token. The docs say token structure is undocumented and may change, so scripts must not parse the inside of a token.

Common mistakes

Assuming batch tokens are better. They are lighter, but they lose renewal, early revocation and child tokens. If any of those is needed, the answer is service.

Forgetting the default policy. A token created with -policy=app-read also carries default. Only -no-default-policy removes it.

Expecting a batch token to be listed or looked up like a service token. A batch token has no accessor, so accessor based commands cannot reach it. Its lookup output shows the accessor as n/a.

Check yourself

  • Which token type is not stored by Vault?

    The batch token. Because nothing is stored, creating one is cheap, but it cannot be renewed, revoked manually or used to create children.

  • Which command creates a batch token with the policy app-read?

    vault token create -type=batch -policy=app-read. Without -type, the command creates a service token.

  • What happens to a token created with -use-limit=3 on its fourth request?

    Vault has already revoked it after the third use, so the request is rejected even if its TTL has not run out.

Topic 1 of 3 in Vault Tokens

Test yourself on Vault Tokens

The full HashiCorp Vault Associate 003 question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by HashiCorp. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.