Token auth method
The token auth method is built-in and automatically available at /auth/token. It
allows users to authenticate using a token, as well to create new tokens, revoke
secrets by token, and more.
When any other auth method returns an identity, Stronghold core invokes the token method to create a new unique token for that identity.
The token store can also be used to bypass any other auth method: you can create tokens directly, as well as perform a variety of other operations on tokens such as renewal and revocation.
Authentication
Via the CLI
To log in with a token, run the following command:
- Stronghold in Deckhouse Platform
- Stronghold in Linux
d8 stronghold login token=<TOKEN>stronghold login token=<TOKEN>Where <TOKEN> is the token value.
Via the API
The token is set directly as a header for the HTTP API. The header should be
either X-Vault-Token: <TOKEN> or Authorization: Bearer <TOKEN>, where <TOKEN> is the token value.
Creating tokens
Tokens are created with d8 stronghold token create (the auth/token/create endpoint). By default, a new token becomes a child of the token that makes the request and can only receive a subset of its policies. For more on token properties, see Tokens.
Service token
A service token is the default. It is persisted in Stronghold, supports renewal, revocation, and child tokens, and has an accessor:
d8 stronghold token create -policy="app-read" -ttl=1h -display-name="app-1"Batch token
A batch token is not persisted in Stronghold, cannot be renewed or manually revoked, and has no accessor. It fits large numbers of short-lived operations:
d8 stronghold token create -type=batch -policy="app-read" -ttl=15mOrphan token
An orphan token has no parent and is not revoked when the token that created it is revoked. Creating one requires access to auth/token/create-orphan or the sudo capability on auth/token/create:
d8 stronghold token create -orphan -policy="app-read" -ttl=24hPeriodic token
A periodic token has no maximum lifetime: on every renewal, its TTL is reset to the period. The token expires if it is not renewed within the period:
d8 stronghold token create -period=1h -policy="app-read"Explicit max TTL
The -explicit-max-ttl flag sets a hard limit on the token lifetime that renewal cannot exceed, including for periodic tokens:
d8 stronghold token create -policy="app-read" -ttl=1h -explicit-max-ttl=8hUse limit
The -use-limit flag sets how many times the token can be used. Once the limit is reached, the token is revoked:
d8 stronghold token create -policy="app-read" -use-limit=3 -ttl=10mOther parameters
| CLI flag | API parameter | Description |
|---|---|---|
-policy | policies | Token policies. The flag can be repeated. |
-no-default-policy | no_default_policy | Do not attach the default policy. |
-ttl | ttl | Initial token TTL. |
-explicit-max-ttl | explicit_max_ttl | Hard maximum TTL. |
-period | period | Renewal period of a periodic token. |
-renewable | renewable | Whether renewal is allowed. Defaults to true. |
-orphan | no_parent | Create a token without a parent. |
-type | type | Token type: service or batch. |
-use-limit | num_uses | Maximum number of uses. |
-display-name | display_name | Token display name. |
-metadata | meta | Arbitrary key=value metadata. |
-entity-alias | entity_alias | Entity alias to associate with the token. |
-role | — | Create the token from a token store role. |
Token store roles
A token store role (auth/token/roles/<ROLE_NAME>) defines the properties of tokens issued through it: allowed policies, token type, TTL, period, orphan flag, and more. Roles let you allow creating tokens with policies the calling token does not have, without granting it sudo.
Create a role:
d8 stronghold write auth/token/roles/ci-deploy allowed_policies="deploy" disallowed_policies="admin" orphan=true token_type=service token_period=1h token_explicit_max_ttl=24h renewable=trueKey role parameters:
Parameter Description allowed_policies,allowed_policies_globPolicies that can be assigned to the token. disallowed_policies,disallowed_policies_globPolicies that must not be requested. orphanIssue orphan tokens. token_typeToken type: serviceorbatch.token_periodPeriod for periodic tokens. token_explicit_max_ttlExplicit maximum TTL. token_num_usesToken use limit. token_bound_cidrsCIDR blocks the token can be used from. renewableWhether tokens can be renewed. path_suffixToken path suffix for later prefix-based revocation. allowed_entity_aliasesAllowed entity aliases. Issue a token from the role:
d8 stronghold token create -role=ci-deployThe calling token needs the
updatecapability onauth/token/create/ci-deploy.View roles:
d8 stronghold list auth/token/roles d8 stronghold read auth/token/roles/ci-deploy
Looking up, renewing, and revoking tokens
In the commands below, <TOKEN> is the value of the token to look up, renew or revoke.
Look up the current token:
d8 stronghold token lookupLook up another token:
d8 stronghold token lookup <TOKEN>Renew the current token, or another token requesting a new TTL:
d8 stronghold token renew d8 stronghold token renew -increment=1h <TOKEN>Revoke a token together with all its child tokens and leases:
d8 stronghold token revoke <TOKEN>Revoke only the token itself; its direct children become orphans:
d8 stronghold token revoke -mode=orphan <TOKEN>Revoke the current token:
d8 stronghold token revoke -selfCheck token capabilities on a path:
d8 stronghold token capabilities <TOKEN> secret/data/app
Working with accessors
An accessor is a reference to a token that lets you look up, renew, and revoke the token without knowing its value. The accessor is returned when a token is created (the token_accessor field) and in token lookup output (the accessor field). Batch tokens have no accessor.
In the commands below, <ACCESSOR> is the token accessor.
Look up a token by accessor:
d8 stronghold token lookup -accessor <ACCESSOR>Renew a token by accessor:
d8 stronghold token renew -accessor <ACCESSOR>Revoke a token by accessor:
d8 stronghold token revoke -accessor <ACCESSOR>Check token capabilities by accessor:
d8 stronghold write sys/capabilities-accessor accessor=<ACCESSOR> paths=secret/data/appList the accessors of all tokens (requires
sudo):d8 stronghold list auth/token/accessors
The accessor list allows revoking any token. Grant access to auth/token/accessors to administrators only.
Tidying the token store
The auth/token/tidy endpoint removes stale entries from the token store, such as accessors of expired tokens:
d8 stronghold write -force auth/token/tidy