cedar-policy / cedar-docs

Documentation for Cedar policy language
https://docs.cedarpolicy.com
Apache License 2.0
22 stars 19 forks source link

[Cedar Doc Issue] `is` in scope doesn't work #84

Closed apexskier closed 7 months ago

apexskier commented 7 months ago

What were you trying to do?

I want to use the is syntax to constrain a policy to a type of entity.

In the playground, I set a policy:

permit (
    principal is PhotoApp::User,
    action == PhotoApp::Action::"viewPhoto",
    resource == PhotoApp::Photo::"vacationPhoto.jpg"
);

What is wrong and why?

This results in the error:

Unrecognized token `is` found at 23:25 Expected one of "!=", "%", "&&", "(", ")", "*", "+", ",", "-", ".", "/", ":", "::", "<", "<=", "==", ">", ">=", "[", "]", "{", "||", "}", ELSE, HAS, IN, LIKE or THEN
Cedar Language Playground - Google Chrome - 2024-02-08 at 15 11 45@2x

According to https://github.com/cedar-policy/cedar-docs/blob/da246161813df303a975fa3423b0752bd64510a3/docs/collections/_policies/syntax-policy.md?plain=1#L118, this is allowed.

What do we need to do to fix this?

Either fix the source to ensure this is allowed, or update the docs to clarify it's not.

This works in the when body of a policy, but the docs imply strongly to me it works in the scope since it's nested within the #term-policy-scope section.

apexskier commented 7 months ago

https://github.com/cedar-policy/cedar-examples/blob/b3f3d0912678a853001c30e79a5e60e00f2fdb07/tinytodo/policies.cedar#L52 also implies this is supported

mwhicks1 commented 7 months ago

Hi apexskier -- The Cedar playground is running an older version of Cedar -- 2.4.3 if I recall correctly. If you try your example using the command-line interface with version 3.0.x it should work.

mwhicks1 commented 7 months ago

Closing this issue as it is not a docs issue, but rather a difference between the Cedar playground (running 2.4.3) and the docs version (3.0.1). Added issue https://github.com/cedar-policy/cedar-docs/issues/85 to host older versions of docs, especially those on the playground.