Martin Carlsson
04/21/2025, 5:16 AMDennis (Cerbos)
{
  "expression": {
    "operator": "eq",
    "operands": [
      {
        "variable": "request.resource.attr.status"
      },
      {
        "value": "PENDING_APPROVAL"
      }
    ]
  }
}
It’s straightforward to translate this particular AST to SQL.
Unless you’re using an ORM for which we have an adapter, you must write a translation layer yourself.Martin Carlsson
04/21/2025, 6:06 AMconst planResources = await cerbos.planResources({ principal: user, action: "view", resource: { kind: "settings" } })
console.log("planResources:", planResources);
This is my output:
planResources: {
  cerbosCallId: '01JSBF155R27JZ7H3N7KZJ7XBE',
  requestId: 'bce23d54-84ac-496e-b085-e03872e2f43d',
  validationErrors: [],
  metadata: undefined,
  kind: 'KIND_ALWAYS_ALLOWED'
}
And this is my policy:
apiVersion: api.cerbos.dev/v1
resourcePolicy:
  resource: settings
  version: default
  rules:
    - actions:
        - view
      roles:
        - admin
      effect: EFFECT_ALLOW
How do I get the AST, and how do I update the policy so it works with the AST?Dennis (Cerbos)
KIND_ALWAYS_ALLOWED means that this principal can view all resources, so no authorization filter is required.Martin Carlsson
04/21/2025, 6:09 AMMartin Carlsson
04/21/2025, 6:11 AMapiVersion: api.cerbos.dev/v1
resourcePolicy:
  resource: report
  version: default
  rules:
    - actions:
        - create
      roles:
        - admin
      effect: EFFECT_ALLOW
    - actions:
        - delete
      roles:
        - admin
      effect: EFFECT_ALLOW
    - actions:
        - update
      roles:
        - admin
      effect: EFFECT_ALLOW
    - actions:
        - view
      roles:
        - admin
        - partner
      effect: EFFECT_ALLOW
The partner may only see reports that are draft and active, but not inactive.Dennis (Cerbos)
Dennis (Cerbos)
- actions:
        - view
      roles:
        - admin
      effect: EFFECT_ALLOW
    - actions:
        - view
      roles:
        - partner
      effect: EFFECT_ALLOW
      condition:
        match:
          expr: request.resource.attr.status in ["DRAFT", "ACTIVE"]Dennis (Cerbos)
{
  "requestId": "query-plan",
  "action": "view",
  "resourceKind": "report",
  "filter": {
    "kind": "KIND_CONDITIONAL",
    "condition": {
      "expression": {
        "operator": "in",
        "operands": [
          {
            "variable": "request.resource.attr.status"
          },
          {
            "value": [
              "DRAFT",
              "ACTIVE"
            ]
          }
        ]
      }
    }
  }
}Martin Carlsson
04/21/2025, 6:29 AMplanResources: {
  cerbosCallId: '01JSBGF546XKTK419CW20CMQGW',
  requestId: '89e753f8-0212-4888-9dfb-a28c46872aca',
  validationErrors: [],
  metadata: undefined,
  kind: 'KIND_CONDITIONAL',
  condition: PlanExpression {
    operator: 'in',
    operands: [ [PlanExpressionVariable], [PlanExpressionValue] ]
  }
}
I am not sure I'm using the SDK correctly:
const planResources: PlanResourcesResponse = await cerbos.planResources({ principal: user, action: "view", resource: { kind: "settings" } })
console.log("planResources:", planResources);Dennis (Cerbos)
Dennis (Cerbos)
kind: “settings”I assume you renamed
report to settings in the policy file.Martin Carlsson
04/21/2025, 6:36 AMMartin Carlsson
04/21/2025, 6:37 AMMartin Carlsson
04/21/2025, 6:37 AM{
  "cerbosCallId": "01JSBGY422BSRMN04MHC483499",
  "requestId": "bfd8b6f0-ab5b-41c2-a05b-36fc55f57663",
  "validationErrors": [],
  "kind": "KIND_CONDITIONAL",
  "condition": {
    "operator": "in",
    "operands": [
      {
        "name": "request.resource.attr.status"
      },
      {
        "value": [
          "DRAFT",
          "ACTIVE"
        ]
      }
    ]
  }
}Dennis (Cerbos)