Configuring an instance policy
Limit what every user and token can do across all accounts on your self-hosted instance.
The instance_policy config value is a policy applied to every API request on your instance. It can only take access away: whatever a user's role or a JWT allows, the instance policy is intersected with it, so nothing can exceed the instance policy.
Use it to enforce a rule across every account on the instance, for example turning off access to recordings, or stopping account settings from being changed.
It uses the same format as JWT policies.
Writing the policy
The value is a JSON object, stored as a string. It must follow these rules:
Include
"version": 3. A policy without a version is read as a legacy version 1 policy and will be rejected as invalid.Include
"*": {}. Any resource the policy does not name falls back to*. Without it every unnamed resource is denied, which blocks almost all access to the instance.List
permissionsonly to restrict them. Leavingpermissionsout of a resource leaves it unrestricted. Listing them allows only those actions:create,read,update,delete. An empty list[]denies the resource entirely.Use only supported resource names. An unknown resource makes the whole policy invalid. Your instance lists the supported resources at
/api/1/policy/schema.
The instance policy cannot grant anything. Listing all four permissions on a resource does not give a user more than their role already allows.
Example policies
Deny access to session recordings on every account:
{
"version": 3,
"*": {},
"recordings": { "permissions": [] }
}Allow account settings to be viewed, but not changed:
Only allow access to devices whose custom data has region set to eu:
Setting instance_policy
You can set the policy in three ways. The API service reads configuration only at startup, so whichever you use, restart the API service for the new value to take effect.
From the dashboard
Firstly make sure you have configured at least one superuser in your instance.
Open
/admin/configurationon your instance while logged in as a superuser. e.g. https://example.com/admin/configurationEnter a new configuration key called "instance_policy". The value should be your policy JSON.
Save and restart the API service for the new value to take effect.
From the API
As a superuser, send the policy as a JSON string in the value field. The value must be a string: a JSON object is rejected with invalid_config.
To remove the policy, send a DELETE to the same URL. Either way, restart the API service afterwards.
With an environment variable
Set an instance_policy environment variable on the api service. For Helm deployments, see Environment Variables. An environment variable takes precedence over the value stored in the database.
Checking the policy
GET /api/1/service/configurationlists configuration values as a superuser, but shortens each value to its first and last three characters, so it confirms the key is set rather than showing the policy.GET /api/1/policy/currentreturns the effective policy for the user or token making the request, with the instance policy already applied. Call it as an agent or with an agent JWT to see what they can do. Called as a superuser, it shows the superuser policy instead.
Recovering from an invalid policy
An invalid policy is only detected when the first request arrives after a restart, and from then on the dashboard and API refuse every request. To recover:
Set the
instance_policyenvironment variable on the api service to a policy that restricts nothing:{"version":3,"*":{}}. This takes precedence over the invalid value in the database.Restart the API service.
Fix or delete
instance_policyat/admin/configuration.Remove the environment variable and restart the API service again.
Last updated