Hi there I found an issue that I perceive as a bug...
# help
b
Hi there I found an issue that I perceive as a bug with role policies, if a user has two role policies with conditions
I have a single role policy
Copy code
"rolePolicy": {
        "role": "ug_132e420282a146868644925b2c591034",
        "parentRoles": [
          "inventory_sessions_read",
          "monitoring_dashboard_read"
        ],
        "scope": "bcaa9a67-5600-47a8-8bef-006a7105f974.data",
        "rules": [
          {
            "resource": "*",
            "allowActions": [
              "*"
            ],
            "condition": {
              "match": {
                "all": {
                  "of": [
                    {
                      "expr": "request.resource.attr.region in [\"west\"]"
                    }
                  ]
                }
              }
            }
          }
        ]
      }
Now I send a plan resources call and the response is
Copy code
"filterDebug": "(eq request.resource.attr.region \"west\")"
Now if I have a second policy
Copy code
"rolePolicy": {
        "role": "ug_132e420282a146868644925b2c591666",
        "parentRoles": [
          "inventory_sessions_read",
          "monitoring_dashboard_read"
        ],
        "scope": "bcaa9a67-5600-47a8-8bef-006a7105f974.data",
        "rules": [
          {
            "resource": "*",
            "allowActions": [
              "*"
            ],
            "condition": {
              "match": {
                "all": {
                  "of": [
                    {
                      "expr": "request.resource.attr.region in [\"east\"]"
                    }
                  ]
                }
              }
            }
          }
        ]
      }
If I send a planresources request with both roles as input, I get a weird double negative response:
Copy code
"filterDebug": "(not (or (not (eq request.resource.attr.region \"east\")) (not (eq request.resource.attr.region \"west\"))))"
Is that a bug? My expectation was
Copy code
"filterDebug": "(or (eq request.resource.attr.region \"east\") (eq request.resource.attr.region \"west\"))"
b
Cerbos Version: 0.46.0
s
Role policy rules are particularly fiddly to handle, but I agree, this output doesn't look quite right. I'll have a proper dig around tomorrow. Thanks for raising.
Thanks for this. There is a fix pending review. The double negative is actually expected. Role policy rules behave differently to resource policies; when you define a role policy rule, it's effectively saying: • The allowable actions defined for this resource are the only allowable actions for this resource (they act like an allow-list, implicitly denying anything else). • There must be a matching rule in a resource policy (in this scope or a parent scope) that also issues an allow. In order to evaluate both of these rule types together, a role policy rule is effectively "negated" (hence the
not (not (eq FOO))
), but I was incorrectly combining those specific rules with all other "normal" ones, hence the
or (not (eq FOO)) (not (eq BAR))
(the
or
being the culprit). I've made a change to separate this handling. The produced output will now be:
Copy code
"filterDebug": "(not (and (not (eq request.resource.attr.region \"east\")) (not (eq request.resource.attr.region \"west\"))))"
Note the
and
rather than the
or
. This seems a bit convoluted, but is logically equivalent to your expected result of:
Copy code
"filterDebug": "(or (eq request.resource.attr.region \"east\") (eq request.resource.attr.region \"west\"))"
Not the first time in my life I've been De Morgan'd 🙃. Thanks again.
😆 1
d
We can apply De Morgan’s laws during the filter normalisation stage to avoid double-negatives.
💯 1
b
Just want to mention that it is really nice to have such a quick turn around on issues the community reports. Thanks a lot guys
🙏 2
Hi folks, Following up with this: do you know when we might be able to expect the release for this fix?
s
Hello! We generally don't follow strict release cycles, so can't commit to a specific date, but I believe another release is pending for later on this week. In the meantime, you can target the dev image
<http://ghcr.io/cerbos/cerbos:dev|ghcr.io/cerbos/cerbos:dev>
which tracks the
main
branch in the repo.
👍 1