1. Creating Tokens via CLI
Usevault token create flags to define token type, TTL, and renewal behavior.
Common Flags
| Flag | Purpose | Example |
|---|---|---|
-type | Specifies the token type (service or batch) | -type="batch" |
-ttl | Sets a time-to-live (non-renewable) | -ttl="60s" |
-period | Creates a renewable (periodic) token | -period="24h" |
By default, Vault issues a non-renewable service token when no
-type or -period is provided.Example: Periodic Token (24h)
- The
-period="24h"flag makes the token periodic and renewable. - Omit
-periodto create a one-time service token. - Use
-type="batch"with-ttlto generate a batch token.
2. Configuring Token Types in an Auth Method
You can predefine token types for roles within an auth method. This example uses AppRole Auth Method:-
Enable AppRole
-
Create Roles with Specific Token Settings
-
Batch Token Role (TTL = 60s)
-
Periodic Token Role (Period = 72h)
-
Batch Token Role (TTL = 60s)
| Role | Token Type | Duration | Description |
|---|---|---|---|
| training | batch | 60s (TTL) | Short-lived, non-renewable batch token |
| jenkins | service → periodic | 72h (renewable) | Renewable periodic service token |
Roles without an explicit
token_type default to service tokens. Ensure you set token_type or period for the desired behavior.Summary
You have two methods to control Vault token types and lifecycles:-
CLI/API Flags:
-typefor service or batch-ttlfor non-renewable duration-periodfor renewable tokens
-
Auth Method Configuration:
- Set
token_type,token_ttl, andperiodin role definitions
- Set