Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cedar Doc Issue] like not correctly documented #147

Open
tpaulus opened this issue Nov 22, 2024 · 1 comment
Open

[Cedar Doc Issue] like not correctly documented #147

tpaulus opened this issue Nov 22, 2024 · 1 comment

Comments

@tpaulus
Copy link

tpaulus commented Nov 22, 2024

What were you trying to do?
Load a policy from JSON.

What is wrong and why?
In Cedar 4.2.2 converting a policy from the JSON representation where the pattern field of the like condition operator fails if it is a string.

What do we need to do to fix this?
The pattern attribute of the like operator expects a array of either wildcards or literals, not a string.

Examples

Bad (as documented)

{
  "effect": "permit",
  "principal": {
    "op": "in",
    "entity": {
      "type": "IAM::User",
      "id": "user"
    }
  },
  "action": {
    "op": "in",
    "entity": {
      "type": "Role::Memberships::Action",
      "id": "role"
    }
  },
  "resource": {
    "op": "in",
    "entity": {
      "type": "IAM::Account",
      "id": "account"
    }
  },
  "conditions": [
    {
      "kind": "when",
      "body": {
        "!": {
          "arg": {
            "like": {
              "left": {
                ".": {
                  "left": {
                    "Var": "context"
                  },
                  "attr": "requestHostname"
                }
              },
              "pattern": "*api.*cloudflare.com"
            }
          }
        }
      }
    }
  ]
}

Good (as generated by Cedar when converting from Human form)

{
  "effect": "permit",
  "principal": {
    "op": "in",
    "entity": {
      "type": "IAM::User",
      "id": "user"
    }
  },
  "action": {
    "op": "in",
    "entity": {
      "type": "Role::Memberships::Action",
      "id": "role"
    }
  },
  "resource": {
    "op": "in",
    "entity": {
      "type": "IAM::Account",
      "id": "account"
    }
  },
  "conditions": [
    {
      "kind": "when",
      "body": {
        "!": {
          "arg": {
            "like": {
              "left": {
                ".": {
                  "left": {
                    "Var": "context"
                  },
                  "attr": "requestHostname"
                }
              },
              "pattern": [
                "Wildcard",
                {
                  "Literal": "a"
                },
                {
                  "Literal": "p"
                },
                {
                  "Literal": "i"
                },
                {
                  "Literal": "."
                },
                "Wildcard",
                {
                  "Literal": "c"
                },
                {
                  "Literal": "l"
                },
                {
                  "Literal": "o"
                },
                {
                  "Literal": "u"
                },
                {
                  "Literal": "d"
                },
                {
                  "Literal": "f"
                },
                {
                  "Literal": "l"
                },
                {
                  "Literal": "a"
                },
                {
                  "Literal": "r"
                },
                {
                  "Literal": "e"
                },
                {
                  "Literal": "."
                },
                {
                  "Literal": "c"
                },
                {
                  "Literal": "o"
                },
                {
                  "Literal": "m"
                }
              ]
            }
          }
        }
      }
    }
  ]
}
@john-h-kastner-aws
Copy link
Contributor

good catch. looks like it was never updated for cedar-policy/cedar#622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants