Resource policies

This documentation is for an as-yet unreleased version of Cerbos. Choose 0.37.0 from the version picker at the top right or navigate to for the latest version.

Resource policies define rules for actions that can be performed on a given resource. A resource is an application-specific concept that applies to anything that requires access rules. For example, in an HR application, a resource can be as coarse-grained as a full employee record or as fine-grained as a single field in the record.

Multiple rules can be defined for the same action on a resource for different roles and/or with different conditions. If more than one rule matches a given input, then a rule specifying EFFECT_DENY will take precedence over one specifying EFFECT_ALLOW.

  resource: "album:object" (1)
  version: "default" (2)
  scope: "acme.corp" (3)
    - apatr_common_roles (4)
    import: (5)
      - apatr_common_variables
    local: (6)
      is_corporate_network: |-
    - actions: ['*'] (7)
      effect: EFFECT_ALLOW
        - owner (8)

    - actions: ['view']
      effect: EFFECT_ALLOW
        - user (9)
          expr: request.resource.attr.public == true
      output: (10)
          ruleActivated: |-
          conditionNotMet: |-

    - name: moderator_rule (11)
      actions: ['view', 'delete']
      effect: EFFECT_ALLOW
          expr: V.is_corporate_network
        - abuse_moderator
  schemas: (12)
      ref: cerbos:///principal.json (13)
      ref: cerbos:///album/object.json (14)
1 Kind of resource to which this policy applies.
2 Version of this policy. Policies are uniquely identified by the resource name and version pair. You can have multiple policy versions for the same resource (e.g. production vs. staging). The version value default is special as it is the default fallback when no version is specified in the request.
3 Optional scope for this policy.
4 Import a set of derived roles (optional).
5 Variable definitions to import (optional).
6 Local variable definitions (optional).
7 Actions can contain wildcards. Wildcards honour the : delimiter. E.g. a:*:d would match a:x:d but not a:x.
8 This rule applies to a derived role.
9 Rules can also refer directly to static roles. The special value * can be used to disregard roles when evaluating the rule.
10 Optional output for the action rule. You can define optional expressions to be evaluated as output depending on whether the rule is activated or not activated because of a condition failure.
11 Optional name for the rule.
12 Optional section for defining schemas that apply to this resource kind.
13 Optional schema for validating the principal attributes.
14 Optional schema for validating the resource attributes.