Skip to main content
You can create a root key and assign its permissions in the dashboard or through the API. Both methods control the same access. If you’re still deciding what your service or agent needs, start with Root key permissions. This guide creates a key for a debugging agent. The agent can read deployment status and runtime logs in the billing app’s staging environment. It cannot deploy changes or access other environments. The dashboard steps and API request below configure that same permission set.

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 the dashboard sidebar and click New Root Key. If you don’t see Root Keys in the sidebar, you don’t have the admin role.
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.
A policy groups a scope and its selected actions. Selecting the environment sets the boundary for the deployment and log permissions; it doesn’t automatically grant access to environment settings or variables. Use Add policy when the key needs another scope. Policies add access together, so a workspace-wide policy can make a narrower environment policy ineffective as a restriction. Templates are starting points, not least-privilege recommendations. For example, All read permissions includes more data than deployment status and logs, and Verify keys starts with every keyspace. Review both the resources and actions before saving. Changing Scope resets that policy’s selections. Use the API below if you need an expiry or a permission on one exact deployment rather than all deployments in the selected environment.

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.
Saving replaces the key’s permission set. To narrow access, remove broader policies as well as adding narrower ones. Clearing a search filter before reviewing helps you see selections that the filter hides. For rotation and deletion, see Root keys.

Create a key through the API

Authenticate with a root key that has unkey: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.
The response contains 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

Use rootKeys.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:
Replace 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.

Restrict a root key by IP address

An IP allowlist limits the source addresses that can authenticate with a root key. It accepts IPv4 addresses, IPv6 addresses, and CIDR ranges. It restricts your service’s calls to Unkey, not the end users whose API keys your service verifies. For applications hosted on Compute, use a firewall policy to restrict incoming client addresses. IP allowlists are a paid add-on. Contact support@unkey.com to add them to your workspace. Until the add-on is enabled, the dashboard shows a disabled field with a Contact support link. If the add-on is later disabled, root keys with saved allowlists still reject requests from addresses outside those lists. You cannot edit or clear the lists through the dashboard or API while the add-on is disabled.

Configure the allowlist in the dashboard

  1. Open Root Keys and choose Edit root key from the key’s row menu.
  2. In IP allowlist, enter one IP address or CIDR range per line.
  3. Include every outbound address your service uses to call Unkey, including NAT or proxy addresses.
  4. Click Save.
Leave the field empty for unrestricted IP access. Other authentication and permission checks still apply.

Configure the allowlist through the API

Send ipAllowlist to rootKeys.updateKey with the complete replacement list. The caller needs write on the target root key. The array accepts up to 100 entries. Use addresses and CIDR ranges, not hostnames or addresses with ports.
Replace key_xxx with the target key’s ID and the example networks with your service’s outbound addresses. Omit ipAllowlist to leave it unchanged. Send "ipAllowlist": [] to remove the IP restriction, subject to workspace enablement and the delegation rules below. An empty array is valid; an empty string inside the array is not. You can also set ipAllowlist in rootKeys.createKey. If you omit it, the new key inherits the caller’s allowlist. An unrestricted caller creates an unrestricted key. A restricted caller can provide a narrower list, but cannot provide a broader list or []. rootKeys.listKeys returns each key’s allowlist. Rotation preserves the existing list.

Delegation cannot widen network access

A restricted root key can create or update another key only within its own allowed networks. An update can expand the target’s existing list, but cannot allow addresses outside the caller’s networks. A restricted caller cannot clear the list or expand its own allowed networks. For example, a caller restricted to 198.51.100.0/24 can expand a target from 198.51.100.10 to 198.51.100.0/24. It cannot permit 203.0.113.10 or make the target unrestricted. Removing all IP restrictions requires an unrestricted caller or a dashboard admin, with the paid add-on enabled.

Verify the restriction

For example, restrict a root key to 203.0.113.10 and use it in the Authorization header of a keys.verifyKey request. A request from 203.0.113.10 passes root-key authentication and proceeds to verify the end-user key in the request body. The same request from 198.51.100.20 returns HTTP 401 before that key is verified, even if the end-user key is valid. The response matches a missing root key and does not reveal that the restricted key exists. It contains an error object, not a verification result in data.code.

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.
Last modified on October 31, 2026