Service tokens
Create service tokens and scope each one to the resources and environments it needs.
A service token authenticates requests to the Management API, CLI, and MCP server for resources under your Knock account. Service tokens start with knock_st_.
Service tokens are account-wide. Each token's access decides which resources it can use and which environments it can reach, so you can give a CI pipeline, a script, or an agent only what it needs.
Who can manage service tokens
#To create, edit, or revoke service tokens, you need the owner or admin role, or a custom permission group that's allowed to manage service tokens.
A token takes the role of the member who creates it, and it can never hold a permission that role doesn't have. See what you can grant for how your role limits the access you give a token.
Create a service token
#- Go to Settings > Service tokens and click New token.
- Enter a Name that says what the token is for.
- Choose an Expiration. See expiration for the options.
- Set the token's access. A new token starts as Restricted with Read only access in every environment.
- Click Create token.
- Copy the token from the dialog and store it somewhere secure. Knock shows the token only once. After you close the dialog, the dashboard opens the token's page, where you can review its access.
Choose a token's access
#The Access control sets how much of the Management API the token can use:
- Full access. If you're an owner, the token can use every Management API endpoint in every environment. For any other role, the token gets every permission you can grant, in every environment.
- Restricted. The token can only do what you choose under Account access and Environment access.
A token with full access can change or delete anything, including in production. Use Restricted unless the token needs everything.
Each resource has access levels, and each level includes the ones before it. For example, Manage on workflows also grants Run and Read. Set a resource to None to leave it out.
Presets
#The Account access card and each environment card offer two presets:
- Read only. Grants the lowest level on each resource, so the token can read resources but not change them. It leaves out API keys, because an API key can trigger workflows through the Knock API.
- Read and write. Grants the highest level on each resource, so the token can take actions like running workflows, promoting commits, and reading API keys.
Neither preset grants Environments, Billing, Agent sessions, or Manage on Members. Both grant Read on Members. Set those resources yourself if the token needs them.
When you change a single resource's level, the card shows Custom.
Account access
#Account access applies across the whole account, not to one environment.
Environment access
#Environment access sets what the token can do inside each environment:
- All. The token has the same access in every environment, including environments created later.
- Granular. You set access for each environment on its own card. An environment created later starts with no access until you grant it on the token's page.
If you've enabled environments, use Granular to give a token different access in each one, such as Read and write in development and Read only in production, or to keep a token out of production. A token's access in the development environment also applies on its branches.
Switching from All to Granular preserves each environment's current access until you update it. Switching from Granular to All gives every environment the narrowest access they share, so the switch never widens what an environment can do. The dashboard asks you to confirm before it applies the change.
Environment access covers these resources:
What you can grant
#Your own role limits the access you can give a token:
- You can only grant permissions your role holds in each environment. The dashboard disables any level or preset you can't grant.
- Only owners can give a token full access or grant Billing.
- You can always narrow a token's access, even when it holds more than you could grant. When the token's role ranks above yours, such as an owner's token edited by an admin, narrowing is the only change you can make.
Change a token's access
#- Go to Settings > Service tokens and click the token.
- On the Permissions tab, change the token's access.
- Click Save permissions.
The change takes effect immediately in every environment it touches, including production. The audit log records each change to a token's access.
The token's Details tab summarizes its access, such as "Read and write in Development, Read only in Production," and shows who created the token, when it expires, and when it was last used.
Insufficient access errors
#When a token is used for a Management API, CLI, or MCP server action that it doesn't have access to, the request fails with a 403 and this message:
To fix it, change the token's access to include the resource and environment the request needs.
Expiration
#Set a token's expiration when you create it: No expiration, 1 day, 7 days, 14 days, 30 days, 90 days, or a Custom date. A custom date runs to the end of that day and must be at least 24 hours away. The field's tip shows the exact time the token stops working.
You can't change a token's expiration after you create it. To extend access, create a new token and revoke the old one.
Once a token expires, its requests fail with a 401, and Knock agent runs can't authenticate with it. The token's page shows when it stopped working. For a token with no expiration, the page shows a warning that long-lived credentials are a security risk.
Revoke a service token
#- Go to Settings > Service tokens.
- Open the token's three-dot menu and click Delete token.
Deleting a token revokes it immediately. From then on, requests that use it fail through the Management API, the CLI, and the MCP server.