Search and contents

Management API tokens: the lifecycle

This is the life of one management API token, from the mint to the revoke, in the order things happen. It says who does what at each step and what the service records. The commands, the routes and the token file's format are in the Management API operations guide; this page points back to it for detail and does not repeat it.

What a token is

A token is a bearer secret for one node. Each mint draws 32 new random bytes, and the node stores only the SHA-256 of them, with an id and a list of scopes, in its token file. Nothing else holds the plaintext: it is printed (or saved to a file) once, at the mint, and cannot be recovered.

Three things follow, and the rest of this page leans on them:

  • A person who needs access on three nodes holds three different tokens. They share nothing but an id that the site chose to reuse.
  • The id is a label, not a secret. It appears in the Activity Log (readable with the read scope), in every sign-off record the token decides, in management_tokens.sh list, and in the node's list of retired ids. The secret is the plaintext token.
  • The scopes are fixed at the mint (the list is in one table). There is no command that adds one. To change what a holder may do, mint a new token and revoke the old one.

The stages

StageWhoWhat happensRecorded
Mint Admin, on the node, as the service user mint_management_token.sh writes the hash, id, scopes and expiry to the token file and shows the plaintext once. It needs an expiry, or --no-expiry for a token only a system holds Activity Log entry, written first. A node whose log cannot be reached refuses the mint and leaves no token
Hand over Admin to holder The plaintext goes to the holder by a channel the site trusts. --save-to FILE writes it to a new 0600 file instead of printing it Nothing. The admin keeps the mapping from id to person
Hold The holder The plaintext lives in the holder's own 0600 file (the command wrapper reads it) or is typed into the review page, which keeps it in memory only Nothing
Rotate The holder, through the API POST /v1/tokens/rotate with the token replaces its secret under the same id and scopes, renews the expiry and returns the new secret once. The old secret works for a grace window (five minutes unless the node says otherwise) so a lost response can be retried Activity Log entry, written first. A node whose log cannot be reached refuses the rotation and the old secret stays
Expire The service, on every request From the token's expires_at, the instant included, the service answers the token 401, the same as an unknown one. No restart or reload The service's log names the id (expired token 'NAME'); nothing in the Activity Log
Re-expire Admin, on the node management_tokens.sh set-expiry --id NAME --expires-in 90d gives an existing token an expiry, or a new one, and changes nothing else: the secret stays Activity Log entry, written first. A node whose log cannot be reached refuses it
Reset Admin, on the node management_tokens.sh reset --id NAME --save-to FILE gives the id a new secret under the same scopes and ends the old secret at once, with no grace window. It works on an expired token and gives it an expiry again Activity Log entry, written first. A node whose log cannot be reached refuses the reset, with no override
Use The service, on every request The presented token is hashed and compared with every stored hash; the route's scope must be among the token's scopes A failure goes to the service log (the id if one matched, the caller's address and the route, never the token), not to the Activity Log
Revoke Admin, on the node; or an administrator with an admin token, from the token administration page or POST /v1/admin/tokens/{token_id}/revoke management_tokens.sh revoke --id NAME, the page's Revoke or the route removes the entry and retires the id, the same way each time; the service refuses the token on its next request The same Activity Log entry from each (the page's and the route's names the admin token that asked). The removal is never held up by the log
Retired The node The id is on a list beside the token file, and mint refuses it from then on management_tokens.sh list --revoked shows each id and when

The service follows the token file: it re-reads it when it changes, so a mint or a revoke takes effect on the next request, with no restart. A request already past authentication when its token is removed finishes normally. If a change to the file cannot be loaded, the tokens read before it stay in force, which means a token that change was meant to remove still works. GET /v1/status reports token_file.state as reload_failed when that happens.

What an admin token can and cannot do

An admin token lets an administrator who has no shell on the node see and end tokens from a browser or a script. It is the most powerful bearer secret a node has, so it stands alone and always expires.

  • It can list this node's tokens (ids, scopes, expiries, retired ids; never a secret or hash) with GET /v1/admin/tokens or the page, and revoke any one of them but its own with POST /v1/admin/tokens/{token_id}/revoke, on this node only.
  • It cannot mint a token, give one an expiry, reset one or revoke itself (409 own_token): those stay with the shell, so the node always keeps the administrator who is acting, and a new secret is never shown in a browser. It reaches no other node: the token is revoked on each other node by the cascade, or by hand there. It opens no other route: not even GET /v1/status, which answers it 403. The two routes any token may call on itself, rotation and the one that tells it its own scopes (GET /v1/tokens/self), are the exception, and an admin token calls both like any other.
  • It is minted on the node, like any token, and never by the install: deployment/mint_management_token.sh --id NAME --scope admin --expires-in 90d. admin is refused beside another scope and with --no-expiry, so an administrator's reviews and their administration are two tokens with two ids. doctor.sh and GET /v1/status count the tokens that carry it.

Choosing the id

The id is the only name a token has, and it outlives the token: a retired id is never issued again.

  • Use letters, digits, ., _ and -, up to 64, starting with a letter or digit. An email address does not fit, because of the @.
  • Prefer an opaque, stable label, such as E004217 or reviewer-0042, and keep the person it stands for in the admin's own records. A name or an address in the id puts personal data into the Activity Log, into every sign-off record that token decides, and into the revoked list.
  • Name a reviewer's token for the reviewer alone, one token each, so a sign-off shows who decided. Name a system's token for the system and its purpose (monitoring, ci-sync).
  • Use one id for one person on every node they hold a token on. A node that is told an id is revoked removes the token with that id wherever it is, so the same id on two different people's tokens takes both away.

Scopes that need care

  • configure. A token with this scope stages a config that did not come from the repository (one carried in a bundle, or a draft made on the appliance), puts the prior staged config back, and is the only token that can send a credential (to the draft). It changes what the Node does at its next start by more than a sync token can, because a sync can only stage what the repository holds.
    • Give it to the integrator who commissions the node, never to a monitoring system, and let it expire.
    • Each use that stages or changes a credential is written to this node's Activity Log under the token's id (config_bundle, config_rollback, config_draft, config_export, config_credentials and config_assist).
  • correlation. A token with this scope asks this node's peers for an order's trail or genealogy (the order routes). What comes back holds the peers' Activity Log entries and identity attributes.
    • Give it to the people who look into an order, not to a monitoring system, one token each.
    • Each request is written to this node's Activity Log under the token's id (correlation_request), so the id shows who asked about which order.

Expiry

A token is minted with an expiry, except one minted with --no-expiry for a system such as a read-only monitor. --no-expiry is refused for a token with the signoff, sync, check, configure, alerts, correlation or admin scope, which a person holds.

  • How far out. The expiry is no further out than MANAGEMENT_TOKEN_MAX_LIFETIME_DAYS from the moment it is set (default 180).
  • What it is for. It is the backstop for a token nobody remembers to revoke: a token left unused for its whole life stops working by itself. It is not a control on someone who keeps rotating, so it does not replace revoke.
  • What renews it. A holder's rotation, an admin's reset, and set-expiry for a token that exists.
  • Where to see it. management_tokens.sh list shows each expiry ((expired) once it has passed, never for none). doctor.sh warns for a token with none, one near its end and one that has ended.
  • The never marker. A token minted with --no-expiry carries a never marker in the file, so a read-only monitor is counted but not warned about. set-expiry removes the marker with the choice it recorded.

The rules are in Token expiry.

Rotating a token

A holder rotates their own token with POST /v1/tokens/rotate, sending the token as the bearer token (the call). The id and scopes stay, so the Activity Log shows one person's decisions under one id, and the expiry is renewed, so a holder who rotates before it lapses never needs an admin. The answer holds the new secret once; store it first. The old secret still works for the grace window (MANAGEMENT_TOKEN_ROTATION_GRACE_SECONDS, default 300), so if the answer was lost, call again with the old secret and take the new one that comes back. Do this on each node the person holds a token on. A token that has already expired cannot rotate.

The command wrapper rotates for its holder. deployment/kindred_management.sh rotates the token file it reads when a call's answer says fewer than 30 days are left, after the call and without changing its answer, so a person or a script that uses it at least once in the last month of the token's life does not need an admin (how, and what it reports). Give each script or machine its own token: a rotation ends the old secret after the grace window, and every other copy of it stops working then.

The grace window leaves the old secret usable after the rotation, so rotation does not answer a leak: for a token that may be in other hands, an admin resets it.

Resetting a token

An admin resets a token when its holder cannot rotate it (the secret is lost, a rotation's response was lost and the window has passed, or the token has expired) and when it has leaked:

deployment/management_tokens.sh reset --id NAME --save-to FILE

The id and the scopes stay, so the Activity Log shows one person's decisions under one id. The old secret, and any a rotation was still keeping, stops working at once. The new secret is shown once, or written to a new 0600 file with --save-to, and handed over like a minted one. An expired token gets an expiry again (now plus MANAGEMENT_TOKEN_LIFETIME_DAYS, else the ceiling, unless --expires-in or --expires-at says otherwise). A reset is per node, and it is refused for an id that does not exist or was revoked. The cases, with the commands for each, are in the recovery runbook.

A person who has left is revoked, not reset: a reset leaves the id live and issues a working secret.

When a person leaves

A runbook for one person who holds tokens on one or more nodes. It names the limits of what a revoke reaches as it goes. Run each command as the service user, on the node named, from anywhere (the scripts find the checkout themselves). NAME is a token id.

Before you start. Have the admin's own record of which ids the person holds and on which nodes. The service keeps no owner for a token and cannot search by person, so that record is the source of truth and step 1 only cross-checks it. For steps 5 and 6 you need a token carrying read on each node, in the file deployment/kindred_management.sh reads.

  1. Find the tokens the person held. On each node:

    deployment/management_tokens.sh list
    

    Look for the person's id and for every other id minted for them since (E004217, E004217-2). If the site did not name ids by a convention, the list alone cannot say whose a token is. The mints on the node, with the time and the account that ran each, narrow it:

    deployment/kindred_management.sh activity-log task_type=token_minted limit=1000 \
      | jq -r '.entries[] | [.occurred_at, .reference_ids.minted_token_id, .reference_ids.scopes, .reference_ids.operator] | @tsv'
    

    That is the first 1000 mints; a longer log answers a next_cursor to pass back as cursor=. It names who minted a token and not who holds it.

  2. If a token is the node's only one, mint another first. revoke refuses the only token left, because the service would keep honouring it. Mint a replacement under a new id (deployment/mint_management_token.sh --id NEW --scope read --expires-in 90d --save-to FILE, with the scopes the node's operators need) and then go on. On a node whose Activity Log is down this cannot be done, because a mint is refused without it: the last token cannot be revoked until the log is back.

  3. Revoke each id on one node.

    deployment/management_tokens.sh revoke --id NAME
    

    It prints Revoked token 'NAME' (scopes: ...) and the service refuses the token from its next request. The id is retired there and mint will not issue it again. no token has the id means the node holds none (the cascade may have removed it first; list --revoked shows it). If the command says the Activity Log entry was not written, the token is revoked all the same: note it down, and the entry is written when the log can next be reached.

    An administrator with an admin token can do this step from the token administration page instead, on each node; it leaves the same files and the same Activity Log entry.

  4. Cover the other nodes. Run the revocation cascade once, from your own session, with the nodes file of the site. It revokes on every node it lists, in one command, and names each node it did not reach:

    deployment/management_tokens.sh revoke --id NAME --nodes nodes.txt
    

    The cascade is the only way a revoke reaches another node: no node reads another's list (the limits are under Revocations across nodes). Where the cascade cannot be used, run steps 2 and 3 on each node.

  5. Confirm on every node.

    deployment/management_tokens.sh list --revoked
    deployment/doctor.sh
    deployment/kindred_management.sh status | jq '{token_file}'
    
    • list --revoked names NAME with a time. list no longer shows it.
    • doctor.sh prints, under tokens, that the file loads and how many revoked ids are on file (it counts them and does not name them, so look for the count to have risen by the number revoked), and a WARNING if Activity Log entries are waiting to be written. Its exit status is unchanged by that warning.
    • token_file.state is loaded. If it is reload_failed, the service is still honouring the tokens it read before the file changed, so the revoked token still works: put the file right first.
    • doctor.sh, on a loopback bind with no token, also asks the running service for GET /v1/revocations and expects 404: a node does not list its revoked ids for another node to pull.

    The person's own token cannot be tried unless you hold its secret, and you normally do not.

  6. Check the Activity Log.

    deployment/kindred_management.sh activity-log reference_id=NAME \
      | jq -c '.entries[] | {occurred_at, task_type, outcome, reference_ids}'
    

    reference_id without a key matches the id wherever an entry names it. Expect the token_minted entry, the token_revoked entry (on a node the cascade reached, one that names the administrator's identity), and the person's earlier decisions and syncs, which show what they did. After the revoke's time, no entry other than those token entries should name the id, bar one for a request already in flight when the token was removed: a later decision or sync means the token was still honoured then. Read what the log does not hold: reads and refused attempts are not in it. A refused request is only a line in the service's log, with the caller's address and the route. The revoked token's own attempts name its id, so this finds them:

    sudo journalctl -u kindred-management --since '1 day ago' | grep "revoked token 'NAME'"
    

    A revoke made before the node kept the token's hash, or a token taken out of the file by hand, is logged as unknown token instead.

What this does not cover. These are the known limits:

  • A node the revoke does not reach. A node is revoked only by the cascade or by hand, so a node the cascade could not reach (it is down, or has stopped accepting the administrator's certificate) goes on honouring the token until a retry reaches it. Nothing lists the nodes a site has; the admin's record is the only list, and a node missing from it is missed without a sign. The cascade reports each node of its list that it did not reach, and a sweep of a range reports a node the list omitted.
  • Tokens held on other hosts. A revoke ends the token at the nodes. It does not remove the person's file or browser tab holding the plaintext, and nothing tells anyone to. The copy is dead where the revoke has reached and live anywhere it has not.
  • An expiry is the only backstop. A token that a revoke missed stays valid until someone finds the node and revokes it there, or until its expiry (at most MANAGEMENT_TOKEN_MAX_LIFETIME_DAYS, 180 by default, from the mint). A token minted with --no-expiry has no backstop; that is allowed only for a token that carries none of signoff, sync, check, configure, correlation and admin. A token with no expiry on file has none either, and no marker, until management_tokens.sh set-expiry gives it one, and doctor.sh warns for each (it does not warn for a token minted with --no-expiry, which carries the marker).
  • An id with no retired-list entry is on no list, and so is not carried to other nodes. The local revoke refuses an id that has no token on the node, which costs nothing: with no token there is nothing to refuse (the cascade does list such an id, as retired_only). A node the cascade has not reached can mint a retired id again, which is why one id names one person on every node.
  • A decision the person already made stands. Revoking ends the token; it does not undo or flag the records the token decided. Read them with kindred_management.sh signoffs, with a signoff token.

A person who must lose access at once is revoked on every node by the cascade, and by hand on any node it missed.

Revocation cascade

One command revokes a token id on every node of a site, from the administrator's own session, and keeps a record of the nodes it missed. The flags, the nodes file and the output are in Revoking on every node: the cascade tool; this section is when to use it.

It acts as an administrator, not as a token: the administrator has a certificate from the site CA (urn:kindred:SITE:admin-NAME), listed in MANAGEMENT_ADMIN_IDENTITIES on each node, and the tool refuses to run unless the certificate and its key are yours and mode 0600. It asks each node to retire the id and remove its token, and the node answers with what it did. A node counts as done when the id can no longer be used there and as missed when it can: no answer, a failure, or withheld, the node's only token, which the node keeps because a token file with none is refused. The exit status is 0 only when every node in the nodes file is done, so a script or a person cannot mistake a partial revoke for a whole one.

Keep a nodes file with the site's records, one address per node, including the node you are on. The cascade never touches this machine's token file.

Scenario 1: a person leaves

  1. From your own session, with the id you gave the person (the same id on every node they held a token on; see Choosing the id):

    deployment/management_tokens.sh revoke --id E004217 --nodes nodes.txt
    
  2. Read the lines. Each node is done (removed) (the token is gone), done (retired_only) (the node held none; the id can never be minted there) or done (already_retired). The summary ends with Missed: none. when every node is done and the exit status is 0.

  3. Add --range 10.20.0.0/24 once, now and then, to find a node the nodes file omits: a node of your site that answers there and is not in the file is printed as found, not expected. It is not revoked; add it to the file and run again.

  4. A node that answered withheld held the person's token as its only one, and it still works. Mint a replacement on that node (see the steps in When a person leaves), then run revoke --retry.

  5. Confirm as in the runbook's last steps (list --revoked, the Activity Log). The cascade's entries name your administrator identity, the id and the result on each node.

Scenario 2: a node comes back online after an outage

A node that was down misses the run, and until it is reached it can still honour the token, and its operators can mint the id again. The tool wrote it to its state file (~/.kindred-admin/.revocation_retry_state, mode 0600), which survives a closed terminal.

deployment/management_tokens.sh revoke --status            # what is still missed, per id
deployment/management_tokens.sh revoke --retry             # every id with a missed node
deployment/management_tokens.sh revoke --retry --id E004217

--retry asks only the nodes recorded as missed, so the nodes already done are not touched again. When it leaves none missed it empties the state file and exits 0; while any remain it exits 1 and keeps them. Repeat it until it exits 0. A node that is down for good is a decision for the administrator. Until it is reached, its line stays in the state file, in --status and in the summary of every run for that id, and those runs exit 1. When the node is out of service, or you have revoked on it by hand, say so: revoke --id E004217 --forget 10.20.0.13:8470. Do not delete the state file to make the warning go away: it holds the other ids too.

Scenario 3: the administrator's certificate is renewed

The tool reads the certificate and key from files, so a renewal is replacing them.

  1. Issue the new certificate (deployment/issue_node_certificate.sh SITE admin-NAME, with --force to reissue). Keep the identity the same and nothing on the nodes changes. A new identity (a different administrator, or a rename) must be added to MANAGEMENT_ADMIN_IDENTITIES on every node, which needs a restart there, before it can revoke anything; remove the old one afterward.
  2. Replace admin.crt and admin.key in ~/.kindred-admin/ (or the files --cert and --key name) and set the mode: chmod 600 ~/.kindred-admin/admin.crt ~/.kindred-admin/admin.key. The tool refuses anything else, and says so before it connects.
  3. If the site's CA was replaced too, replace trust-bundle.pem with the new bundle.
  4. Check with revoke --status: its first line reports the certificate's identity and the date it expires, or why it is refused. A run with an expired certificate stops before any connection, so a missed renewal never half-revokes a site. The state file survives a renewal, and --retry works with the new certificate.

What does not exist

These do not exist.

  • No node-to-node revoke. A node never tells another to revoke: revoke and mint run on the node, the admin token's page and route revoke on the node that serves them, and the cascade is run by an administrator, from outside, against the nodes they list. A node nobody lists is not told.
  • No owner for a token, by design. Kindred has no users, only tokens; the id is a label. Whose a token is, is the admin's record.
  • No central list. Every node has its own token file and its own list of retired ids. Back the two up together, because restoring a token file alone would let a retired id be issued again.

Where to look

QuestionWhere
What are the scopes, and which route needs which? Scopes, then Routes
How are the token file and the retired list stored? Tokens
How does a holder replace their own token? Rotating your own token
A secret is lost, a token has expired or leaked, or the Activity Log is down The recovery runbook
What does a mint, a rotation, a reset or a revoke write to the log? Token actions in the Activity Log
How do I list or revoke tokens from a browser? The token administration page and Revoking a token from the API
How do I revoke an id on every node, and retry the ones missed? Revocation cascade, then the tool's flags
How does a revoke reach the other nodes? Revocations across nodes
How do I tell a refused token from one without the scope? The 401 and 403 rows of the answers table in the operations guide

Release: v0.11.0