- Declare types that can be referenced in rules and facts (including facts stored as data).
- Provide built-in declarations for permissions, roles, and relations, along with shorthand rules for RBAC and ReBAC.
| Type | Description |
|---|---|
resource | An object to which actions can be applied. |
actor | An entity that can be granted permissions. |
actor or resource.
Example minimal blocks:
Global Block
A policy can define oneglobal block to store permissions and roles accessible from any other resource. This is typically used for global roles.
global keyword:
Permissions, Roles, and Relations
These declarations simplify writing RBAC and ReBAC shorthand rules.| Feature | Description |
|---|---|
permissions | Actions that Actors can perform on this resource. |
roles | Roles an Actors can have in relation to this resource. |
relations | Links from this resource to other resources. |
- Values must be
Stringliterals, e.g."read"(case-sensitive). - Each can be declared at most once per block, i.e. you cannot declare
rolestwice. - All values across
permissions,rolesandrelationsmust be unique within the block, e.g. you can’t declareroleswith the value"writer"and also declare arelationsnamed"writer". - A feature must be declared before it can be referenced in shorthan
Permissions
Permissions define the actions that Actors can perform on a resource. They are declared as an array of strings.
String matching one of the values declared in permissions. For example:
Roles
roles define Actors in relation to a resource. They are declared as an array of strings.
String matching one of the values declared in roles. For example:
Relations
Roles classify the relationship between this and others resources.relation declaration must be key-value pairs, whose:
- Key is an unquoted string (i.e. an identifier)
- Value is the type of the related object
String for the relation name (e.g. "parent"), and a value of the related type (e.g. Organization). For example:
Shorthand Rules
If a resource block declarespermissions, roles, or relations, you can write shorthand rules:
if statement is the result that is granted if the right-hand side evaluates to true.
Shorthand rules expand into full rules when loaded.
Left-Hand Side Expressions
The left-hand side can be:- A role (
"contributor"). - A permission (
"read"). - The
roleorpermissionkeywords (any role or permission).
"read" if "contributor";, the left-hand side "read" expands to:
Repository resource block, the resource type in the expanded rule is Repository.
Right-Hand Side Expressions
The right-hand side of theif statement is an expression that specifies the conditions under which the left-hand side is true.
For most expression types (roles, permissions, or relations), the shorthand rule will only succeed if additional supporting statements—facts or other rules—are present in the policy. These statements must follow the schema of the expanded predicate for that expression (referred to below as $rhs_pred)
Examples of valid right-hand sides include:
- A role (
"contributor"). This grants specific permissions to a role ("read" if "contributor"). - A permission (
"read"). This groups common permissions to reduce repetition ("read.issues" if "read"). - A role or permission on a related resource (
"reader" on "parent"). This grants roles or permissions across resource types—assigning a role or permission on one resource to a role on a related resource. The granted role or permission must be declared on the related resource type, and the relation must be declared on the current resource type. - Rule call syntax (
is_public(resource)). This calls a rule with arguments to check an attribute or condition. The syntax is a rule name followed by a list of arguments. Arguments can be primitive values (strings"open"or numbers0) or the keywordresource, which refers to the resource declared in the enclosing resource block.
and and or.
Statements Supporting Right-Hand Side Expressions
Right-hand side expressions other than rule calls (e.g. roles) require additional statements (i.e. facts or additional rules) to succeed.Expansion Semantics
Shorthand rules are expanded to full Polar rules when they are loaded.Without Relation
$lhs_pred and $rhs_pred are derived from the shorthand expression types of $lhs and $rhs:
| Shorthand expression type | Expanded predicate |
|---|---|
| Permission | has_permission |
| Role | has_role |
$Type in the resource position is the type declared by the enclosing resource block.
For example, in resource Repository {...}, $Type is Repository.
For this shorthand rule to be usable in authorization checks, your policy must also define supporting statements—facts or rules—that match the schema of the right-hand side predicate.
For example:
With Relation
$lhs_pred and $rhs_pred follow the same semantics as expansion without relation.
$rel must be a declared relation on the current resource type. The has_relation rule is required to access the related object that $rhs_pred references.
For this shorthand rule to be usable in authorization checks, your policy must also define supporting statements that match the schema of the right-hand side predicate.
For example:
Global Block Expansion
A global block expands to rules that reference theGlobal type.
$lhs_pred and $rhs_pred depend on the shorthand expression type of $lhs and $rhs:
| Shorthand expression type | Expanded predicate |
|---|---|
| Permission | has_permission |
| Role | has_role |
- To satisfy this rule, add supporting facts matching the right-hand side schema.
- The schema of the right-hand side’s expanded predicate differs from non-
globalexpansions.globalright-hand side predicates do not expect aresourcevalue.
Referencing Resources
Whether declared as an actororresource, refer to a resource by its type name (e.g., ResourceName`) followed by a string identifier in curly braces:
Polymorphism
Polar applies polymorphism within resource blocks: The abstract typeActor works with any type declared in an actor block when used in has_role or has_permission.
Actor is a subtype of Resource. Any variable of type Resource can also be an Actor.Because all actors are also resources, we use the term “resource blocks” to cover both. For details, see
extends documentation.
actor vs. resource
Actor is a subtype of Resource, meaning any Actor can also be used where a Resource is expected.- Actor: something that can be assigned roles or permissions (e.g.,
User, ServiceAccount).- Resource: something you grant permissions to (e.g.,
Repository, Document).
Choose based on shorthand rule expansion:
- If it needs to appear as the first argument of
has_roleorhas_permission, make it anactor. - Otherwise, make it a
resource.