Policy Guards
A Policy Guard applies the same permission rules to several projects in your Permit.io workspace and locks those permissions so project members can't change them. This page is for workspace administrators who need one baseline policy across projects, and explains what a Policy Guard contains, how Permit applies it, and when to use it. To create one, see the Policy Guard API guide.
What is a Policy Guard?
A Policy Guard is an organization-level set of permission rules, attached to a list of projects. You manage Policy Guards with the Permit API. The API groups the endpoints under the Policy Guards (EAP) tag.
A Policy Guard has two parts:
| Part | What it holds |
|---|---|
| Scope | A unique key and the list of projects the Policy Guard applies to. |
| Rules | Permission rules. Each rule names a resource and an action, plus a role, a user set, a resource set, or a supported combination, and whether the permission is allowed. |

How Permit applies a Policy Guard
-
Every environment in the scope. When you add a project to a scope, Permit marks each environment of that project as guarded and applies the scope's rules to each environment. When you add a rule, Permit applies it to every environment of every project in the scope.
-
Missing objects are created. If an environment has no resource, action, or role with the key a rule uses, Permit creates it. Rules reference objects by key, not by ID, because IDs are unique to each environment.
-
Guarded permissions are locked. In a guarded environment, a change to a permission that a Policy Guard rule covers fails with a
403 Forbiddenerror. The permission stays as the rule sets it until you remove the rule or remove the project from the scope. -
The environment's own record is locked. You can't delete a guarded environment or change the fields
PATCHaccepts (name,description,custom_branch_name,jwks, andsettings).PATCHandDELETE /v2/projects/{proj_id}/envs/{env_id}fail with a403 Forbiddenerror for every caller, including workspace owners and organization API keys. To change those fields or delete the environment, remove its project from the scope first, then add the project back if you still want it guarded. Removing the project marks all of its environments as no longer guarded until you add it back. When you add it back, Permit marks them as guarded right away and applies the scope's rules in a background task. The task doesn't revert every change made while the project was out of the scope, so check the environments' permissions after it finishes. -
The environment's project and organization can't be deleted.
DELETE /v2/projects/{proj_id}andDELETE /v2/orgs/{org_id}fail with a403 Forbiddenerror for every caller while any environment they would remove is guarded. The error names one of those environments. To delete the project, remove it from the scope first. To delete the organization, delete its scope first. -
The environment's data sources and URL mapping rules are locked. In a guarded environment, these requests fail with a
403 Forbiddenerror for every caller allowed to make them, including workspace owners and organization API keys:PUTandDELETE /v2/projects/{proj_id}/{env_id}/opal_scope, which set the external data sources the environment's policy decision points (PDPs) load. See Use an external data source.POST /v2/facts/{proj_id}/{env_id}/proxy_configs, andPATCHandDELETE /v2/facts/{proj_id}/{env_id}/proxy_configs/{proxy_config_id}, which hold the URL mapping rules. See Regex URL mapping.
GETrequests on both still work. To change a data source or a mapping rule, including to replace a credential that one of them holds, remove the project from the scope, make the change, then add the project back. -
The project's policy source is locked. The policy source is the code the PDPs of the project's environments run: the policy Permit generates, or the environment branches of the project's active policy repository (see GitOps). A request that changes the policy source of a project with a guarded environment fails with a
403 Forbiddenerror for every caller allowed to make it:PUT /v2/projects/{proj_id}/repos/{repo_id}/activatefor a repository other than the active one.PUT /v2/projects/{proj_id}/repos/disablewhile a repository is active. Disabling it switches the project back to the policy Permit generates.POST /v2/projects/{proj_id}/reposwithactivate_when_validatedset totrue.DELETE /v2/projects/{proj_id}/repos/{repo_id}for a repository that is the active repository of any project with a guarded environment.PATCH /v2/projects/{proj_id}that changesactive_policy_repo_id.
Requests that keep the policy source still work, such as creating a repository without activation or activating the active repository again. To change the policy source, remove the project from the scope (for a repository delete, every project whose active repository it is), make the change, then add the projects back. A new deploy key needs the same steps, because Permit has no request that replaces the deploy key of a repository: a new key takes a new repository and its activation.
When a Policy Guard refuses a change to a guarded environment's record, data sources or URL mapping rules, a change to a project's policy source, or a project or organization delete, the 403 response has the error code POLICY_GUARD_PROTECTED. If the project isn't in a scope, or the organization has no scope, follow the steps in the error message. A refused change to a permission that a Policy Guard rule covers has the error code FORBIDDEN_ACCESS, not POLICY_GUARD_PROTECTED.
Rule types
A rule always includes resource_key and action_key. The rest of the rule decides who it applies to:
| Rule applies to | Fields to set |
|---|---|
| A role | role_key |
| A user set (attribute-based access control, ABAC) | user_set |
| A resource set with a role | resource_set and role_key |
| A resource set with a user set | resource_set and user_set |
Permit rejects a rule that sets both role_key and user_set without a resource_set.
Roles in Policy Guard rules are environment-level roles, as in role-based access control (RBAC). Rules have no field for relationship-based access control (ReBAC) resource roles or relationships.
Who can manage Policy Guards
The Policy Guard endpoints accept an organization API key, or a signed-in member with the Workspace Owner role. Any other caller gets a 403 Forbidden error that asks for an organization API key or workspace admin permissions. See API key types for the difference between organization, project, and environment API keys.
When to use a Policy Guard
- One rule for many projects. For example, only the
adminrole can create documents in every project of the workspace. - Protect a baseline from project-level edits. Project members can edit the rest of the policy, but not the permissions a Policy Guard locks.
- Review the enforced baseline in one place. List a scope's rules with the API to see which permissions every project in the scope enforces.