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
- Open Settings, then API Keys.
- Select Create Key.
- Enter a name, for example
GitHub Actions. - Leave Full access on for a key that can do everything, or turn it off and tick the permissions the key needs.
- 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
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>
| Command | What it does |
|---|---|
api-key scopes | Lists the scopes your organization can grant. |
api-key create | Creates a key and prints its secret once. |
api-key list | Lists 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.
| Resource | Actions |
|---|---|
workflow | read, create, edit, publish, run, cancel |
test-run | read, run, cancel |
external-test-run | read, create, edit, complete |
external-test-comment | read, create |
property | read, create |
sandbox | read, publish, create, run, delete, edit, exec |
credential | read, create, edit |
tag | read, create, edit, delete |
attachment | read, create, delete |
issue | read, create |
utility | read, create, edit, delete, send |
prompt | read, create, edit, delete |
feedback | create |
product-map | read, 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
| Scope | Allows |
|---|---|
sandbox:read | View sandboxes, pushes, secret names and pull request previews. It includes each sandbox's test logins. |
sandbox:publish | Push an image (cofactor sandbox push). |
sandbox:create | Claim a sandbox (cofactor sandbox claim). |
sandbox:run | Run an action (cofactor sandbox run) or a sign-in check (cofactor sandbox auth-check). |
sandbox:delete | Destroy a sandbox (cofactor sandbox destroy). |
sandbox:edit | Connect an application to a repository and set or remove secrets. |
sandbox:exec | Run 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.
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.
| Status | Message | Fix |
|---|---|---|
| 401 | Invalid or expired API key | The key is wrong, revoked or expired. Create a new one. |
| 403 | This 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.