Skip to content

Create and manage a service account

What you will end up with

A workspace service account, a token issued for it, and the ability to revoke that token.

Prerequisites

export WS=ws-a

Why a service account rather than your own token

An exchanged token is tied to your provider session and cannot be revoked individually. A service-account token is issued directly by Xratu, is recorded by id, and can be revoked at any time. Use a service account for anything unattended. See Token lifetime, renewal, and revocation.

1. Create the account

xratu auth service-account-create ci-publisher \
  --workspace ${WS} \
  --description "CI pipeline that publishes blocks"

The account belongs to one workspace. Metadata may be attached with --metadata-json if you want to record ownership or a ticket reference alongside it.

2. Confirm it exists

xratu auth get service-accounts --workspace ${WS}

3. Issue a token

xratu auth issue-token \
  --for service-account:ci-publisher \
  --workspace ${WS} \
  --ttl-seconds 86400 \
  --reason "initial issuance"

Expected output

The response carries the token and, importantly, its id:

{
  "workspace_uuid": "...",
  "service_account_id": "...",
  "token_id": "...",
  "access_token": "...",
  "token_type": "bearer",
  "expires_at_epoch": 1234567890,
  "actor_id": "service-account:<workspace_uuid>:<service_account_id>"
}

Keep token_id. It is how you revoke this token later, and you cannot recover it from the token itself as an operator. Record it wherever you record the credential.

The resulting actor is service-account:<workspace_uuid>:<service_account_id>, which is what appears in audit records and what role bindings target.

A requested lifetime below 300 seconds is raised to 300. The CLI default is 86400.

4. Verify the token works

Use it directly, without touching your own profile:

xratu auth --token "<access_token>" whoami

--server and --token are options on auth itself rather than on its subcommands, so they come before the subcommand name.

actor_id reports the service-account actor rather than yours.

For a consumer that will use it permanently, give it its own profile:

xratu config profile set ci --endpoint "${CP_CLI_ENDPOINT}" --token "<access_token>"

The command omits --use, which leaves your own profile active.

5. Grant it permissions

A new service account can authenticate and little else. Bind a role to its actor:

xratu bind role admin \
  --to service-account:ci-publisher \
  --workspace ${WS}

Choose the narrowest role that lets the automation do its job.

6. Revoke a token

xratu auth revoke-token \
  --for service-account:ci-publisher \
  --workspace ${WS} \
  --token-id <token-id> \
  --reason "rotating credentials"

The reason defaults to manual_revocation. Revocation is audited with the actor, the token id and the reason.

Afterwards, a request carrying that token resolves to no actor, with a context of token_revoked_or_expired.

Rotating without downtime

Issue the replacement, deploy it, confirm the consumer works, then revoke the old id. Doing it in that order avoids a window where the automation has no valid credential, since both tokens are valid at once.

When it fails

404 service account not found. The name or the workspace is wrong. List them with xratu auth get service-accounts --workspace ${WS}.

409 service account is disabled. No new tokens can be issued for it. Existing tokens are unaffected, so revoke them explicitly if that is the intent.

400 token does not belong to target service account. The token id is real but belongs to a different account or workspace. Check which account you named.

404 token not found. The token id does not exist. It may already have been removed, or the id was mistyped.

The token authenticates but every command is refused. The account has no role bindings. Authentication and authorisation are separate; see step 5.

What changed

A service account exists in the workspace, one token has been issued for it and recorded by id, and any revocation you performed is in the audit trail. Your own identity and profile are untouched, provided you did not pass --use when storing the account's token.