Create a key in the dashboard
You need the workspace admin role to manage root keys in the dashboard.1
Open the root key form
Open Root Keys in your workspace and click New Root Key.
2
Name the key
Enter a name such as
billing-staging-debugger that describes the key’s job.3
Start a custom policy
Under Permissions, select Start new. The policy editor opens with no actions selected.
4
Choose the environment
Set Scope to Environments, then select the billing app’s staging environment instead of all environments.
5
Select the actions
Select Read on Deployments and Runtime logs. Leave the other actions and resources unselected.
6
Review and create the key
Close the policy editor with its × button to review the summary. Check every policy on the key, then click Create key.
7
Store the secret
Use the copy button beside the key and save the secret in your secret manager. Unkey shows it only once. Click Done after saving it.
Edit permissions in the dashboard
Open the key’s row menu and select Edit root key. Change its policies, review the complete selection, then click Save changes.Create a key through the API
Authenticate with a root key that hasunkey:v1:ws_xxx:rootKeys/*#write and covers every permission you’re assigning. If you don’t have a management key yet, create one in the dashboard first. Keep that credential in trusted automation, not in the agent that receives the new key.
This request creates a debugging key that expires in one hour. IDs ending in _xxx are placeholders. Replace each one with the full resource ID, not a name or slug. Use the billing app’s ID for app_xxx and its staging environment’s ID for env_xxx. Set UNKEY_ROOT_KEY through your secret manager or environment, rather than putting the secret in the script.
data.key, the secret shown only once, and data.keyId, the ID used to manage the key. Store the secret without sending it to CI logs or application logs. Give the agent the new secret, not UNKEY_ROOT_KEY.
The permissions array is required. Every entry must be a supported resource/action combination in the authenticated workspace and fit within the caller’s permissions. The API accepts an empty array, but that key grants no resource access.
expires is a future Unix timestamp in milliseconds. If the caller’s root key expires sooner than one hour from now, use an earlier expiry. An expiring caller must set an expiry no later than its own. A nonexpiring caller can omit expires or use null for a key with no expiry, but use a short lifetime for temporary tasks.
Replace permissions through the API
UserootKeys.updateKey with the target keyId and the complete permission list you want to keep. The caller needs write on that root key and must cover every permission in the replacement list.
For example, narrow the debugging key to one deployment:
key_xxx with data.keyId from creation and d_xxx with the deployment’s ID. This request removes the environment-wide deployment permissions and replaces them with permissions on that deployment. It doesn’t append to the existing list.
Omitting permissions leaves the existing permissions unchanged. Sending "permissions": [] removes all permissions. An expiring root key can only update keys that expire no later than itself.
Verify the resulting access
Call an operation the key needs, then check a read outside its scope. For the single-deployment debugging key,deployments.getDeployment on the deployment represented by d_xxx must succeed, while a lookup of a different deployment must fail.
If a request fails unexpectedly, compare its required action and resource IDs with the full permission list. Check list filters too: a request for all deployments asks for more access than a request scoped to one environment. See permission troubleshooting.