Skip to content

Multiple namespaced schema doesn't like cross namespace action membership/principals #642

@tomlikestorock

Description

@tomlikestorock

Before opening, please confirm:

Bug Category

Schemas and Validation

Describe the bug

When a schema contains multiple namesapces, it is possible to generate an in operator hierarchy respect error that claims one of the namespace's actions are not a descendant of the others.

This manifests when one of the actions that is a transitive member of the other namespace's actions specifies an appliesTo that points to the other namespace as well.

This might not be a bug, it may be an edge case that I'm not aware of.

Expected behavior

Create a schema with two namespaces, entities and actions in each NS1, NS2. NS2 will have entities that are members of NS1's entities, and NS2 will have actions that are direct and transitive members of NS1's actions.

Have an action in NS2 be a transitive member of an NS1 action group, and specify that NS2's action applies to a principal type within NS1.

Reproduction steps

  1. Create the repro files as in this issue
  2. Run the following command: cedar validate --schema repro.cedarschema.json --policies repro.policy.txt --deny-warnings

Code Snippet

repro.cedarschema.json

{
    "NS1": {
        "entityTypes": {
            "PrincipalEntity": {},
            "SystemEntity1": {},
            "SystemEntity2": {
                "memberOfTypes": [
                    "SystemEntity1"
                ]
            }
        },
        "actions": {
            "Group1": {
                "appliesTo": {
                    "principalTypes": [],
                    "resourceTypes": []
                }
            }
        }
    },
    "NS2": {
        "entityTypes": {
            "SystemEntity1": {
                "memberOfTypes": [
                    "NS1::SystemEntity2"
                ]
            }
        },
        "actions": {
            "Group1": {
                "memberOf": [
                    {"id": "Group1", "type": "NS1::Action"}
                ],
                "appliesTo": {
                    "principalTypes": [],
                    "resourceTypes": []
                }
            },
            "Action1": {
                "memberOf": [
                    {"id": "Group1"}
                ],
                "appliesTo": {
                    "principalTypes": [
                        "NS1::PrincipalEntity"
                    ],
                    "resourceTypes": [
                        "NS2::SystemEntity1"
                    ]
                }
            }
        }
    }
}

repro.policy.txt

permit(
    principal in NS1::PrincipalEntity::"user1",
    action in NS1::Action::"Group1",
    resource in NS1::SystemEntity1::"entity1"
);

Log output

Validation Failed
Validation Errors:
validation error on `policy `policy0``: operands to `in` do not respect the entity hierarchy. `NS2::Action` is not a descendant of `NS1::Action`

NOTE:
Remove the entire "appliesTo" in NS2::Action::Action1 and get this:

Validation Failed
Validation Errors:
validation error on `policy `policy0``: policy is impossible. The policy expression evaluates to false for all valid requests

Additional configuration

No response

Operating System

No response

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. This is as high priority issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions