Docs/API keys
#

API keys

Create, scope and revoke Cofactor API keys for CI and scripts. Key prefix, Full access and Legacy keys, the cofactor api-key commands, the sandbox scopes and the COFACTOR_API_TOKEN variable.

An API key lets CI, scripts and the CLI act for your organization without a person signing in. Each key has scopes that decide what it can do. Only organization admins can create, list and revoke keys.

A key starts with cnry_. Cofactor shows the whole key once, when you create it, and stores only a hash.

Create a key in the app

  1. Open Settings, then API Keys.
  2. Select Create Key.
  3. Enter a name, for example GitHub Actions.
  4. Leave Full access on for a key that can do everything, or turn it off and tick the permissions the key needs.
  5. Select Create Key, then copy the key from the dialog.

The app has no expiry field. To give a key an expiry date, create it with the CLI.

Create a key with the CLI

bash
cofactor api-key scopes
cofactor api-key create --name "CI image push" \
  --scope sandbox:read --scope sandbox:publish --scope property:read
cofactor api-key list
cofactor api-key revoke <id>
CommandWhat it does
api-key scopesLists the scopes your organization can grant.
api-key createCreates a key and prints its secret once.
api-key listLists keys. It never shows secrets.
api-key revoke <id>Stops a key working at once.

create takes --name (required), --scope (required, repeatable) and --expires-at <date> (without it the key never expires). A scope is resource:action, resource:* for every action on a resource, or * for full access.

The Permissions column in Settings > API Keys shows Full access for a key with *, the scope names for a scoped key, No access for a key with no scopes, and Legacy for a legacy full-access key. A Legacy key can call only the routes that accepted API keys before scopes existed.

Scopes

* grants everything, and workflow:* grants every action on workflows. The one exception is sandbox:exec, which sandbox:* does not include. Grant it by name or use full access.

ResourceActions
workflowread, create, edit, publish, run, cancel
test-runread, run, cancel
external-test-runread, create, edit, complete
external-test-commentread, create
propertyread, create
sandboxread, publish, create, run, delete, edit, exec
credentialread, create, edit
tagread, create, edit, delete
attachmentread, create, delete
issueread, create
utilityread, create, edit, delete, send
promptread, create, edit, delete
feedbackcreate
product-mapread, create, edit, delete

test-run:run covers cofactor test-suite run and creating and changing suites. Run cofactor api-key scopes for the exact list your organization can grant.

Sandbox scopes

ScopeAllows
sandbox:readView sandboxes, pushes, secret names and pull request previews. It includes each sandbox's test logins.
sandbox:publishPush an image (cofactor sandbox push).
sandbox:createClaim a sandbox (cofactor sandbox claim).
sandbox:runRun an action (cofactor sandbox run) or a sign-in check (cofactor sandbox auth-check).
sandbox:deleteDestroy a sandbox (cofactor sandbox destroy).
sandbox:editConnect an application to a repository and set or remove secrets.
sandbox:execRun a shell command (cofactor sandbox exec), sync files and open a port tunnel. The command can read the sandbox's secrets, so grant it with care.

A CI job that pushes images needs sandbox:read, sandbox:publish and property:read to name the application. Add sandbox:create and sandbox:delete if it also claims and destroys a sandbox. See Set up sandboxes from a pushed image.

Because sandbox:read returns working logins, give the key only to jobs that need it.

Use a key in CI

Store the key as a secret in your CI system and expose it as COFACTOR_API_TOKEN. Create one key per pipeline, so you can revoke one without breaking the others.

bash
export COFACTOR_API_TOKEN=cnry_your_api_key
cofactor test-suite run --suite "Checkout" --application "Acme web"

To call the API directly, send the key as a bearer token: Authorization: Bearer cnry_your_api_key.

StatusMessageFix
401Invalid or expired API keyThe key is wrong, revoked or expired. Create a new one.
403This API key does not have the required scope for this endpoint.Add the scope the command needs.

Revoke a key

In Settings > API Keys, select the trash icon on the key and confirm. In the CLI, run cofactor api-key revoke <id>. The key stops working at once.

Go deeper