https://cerbos.dev logo
#help
Title
# help
d

Dmitry Meyerson

08/03/2023, 6:32 PM
hi all, I have a validation issue with a role I’m defining - details in 🧵
Copy code
apiVersion: api.cerbos.dev/v1
description: Common dynamic roles based on locale and group memberships
derivedRoles:
  name: common_roles_based_on_locale_and_groups
  definitions:
  - name: APPLE-READ
    parentRoles:
    - USER
    condition:
      match:
        expr: '"APPLE - READ" in P.attr.my-awesome-groups'
when i try to validate my policies - meaning when I run
Copy code
docker run -i -t -v $(PWD)/policies/:/policies <http://ghcr.io/cerbos/cerbos:0.26.0|ghcr.io/cerbos/cerbos:0.26.0> compile /policies
I get the following
Copy code
Compilation errors
derived_roles/base_roles.yaml: Invalid expression in derived role 'APPLE-READ' (#6) (failed to compile `"APPLE- READ" in P.attr.my-awesome-groups` [undeclared reference to 'awesome' (in container ''), undeclared reference to 'groups' (in container '')])
so its clearly interpretting “-” as operator
do I need to escape it? not sure what happens at complication time
short version - I write valid yaml - but cerbos will not compile is there are “-”s in my expressions
does Cerbos does not support attribute names with hyphens?
a

Alex Olivier (Cerbos)

08/03/2023, 7:10 PM
Hey
Let me quickly replicate this in the playground
d

Dmitry Meyerson

08/03/2023, 7:13 PM
hello
ok
a

Alex Olivier (Cerbos)

08/03/2023, 7:15 PM
Copy code
apiVersion: api.cerbos.dev/v1
description: Common dynamic roles based on locale and group memberships
derivedRoles:
  name: common_roles_based_on_locale_and_groups
  definitions:
  - name: APPLE-READ
    parentRoles:
    - USER
    condition:
      match:
        expr: >
          "APPLE - READ" in P.attr["my-awesome-groups"]
This is actually an edge case in CEL which I don't run into that often, but using the
-
in the string leads to a parsing error so using the index-style reference works
d

Dmitry Meyerson

08/03/2023, 7:17 PM
ic - let me try this
ok that seems to make it work!
thank you !
a

Alex Olivier (Cerbos)

08/03/2023, 7:19 PM
Good. I’ll make a note to add that into the docs.
2 Views