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

Enable arbitrary nesting of arrow operators #15

Open
jzelinskie opened this issue Aug 17, 2021 · 7 comments
Open

Enable arbitrary nesting of arrow operators #15

jzelinskie opened this issue Aug 17, 2021 · 7 comments
Labels
area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) priority/2 medium This needs to be done

Comments

@jzelinskie
Copy link
Member

jzelinskie commented Aug 17, 2021

The arrow operator can only be used once in an expression (e.g. org->admin), but should be able to support traversing an arbitrary number of relations (e.g. namespace->org->admin, tenant->namespace->org->admin->member).

This would allow for nested arrows in schema

@jzelinskie jzelinskie added priority/2 medium This needs to be done area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Aug 17, 2021
@jzelinskie
Copy link
Member Author

jzelinskie commented Jul 11, 2023

I just wanted to add documentation here that you can achieve this today by creating intermediary permissions on objects.
This is what we've been recommending and what lots of folks have used successfully.

For example:

definition token {}
definition user {
    relation access_tokens: token
}

definition team {
    relation member: user

    // Helper for documents to reach the access tokens
    permission member_tokens = member->access_tokens
}

definition document {
    relation writer_teams: team
    relation reader_teams: team

    // This expands to writer_teams->member->access_tokens
    permission edit = writer_teams->member_tokens
    permission view = reader_teams + edit
}

@yuhan-zhang-zip
Copy link

This can be implemented via introducing a intermediate schema layer. So developers can define multiple hops, like writer_teams->member->access_tokens. When spicedb server bootstrap, it could generate the corresponding intermediate permissions on objects so that the generated schema can work with the current system.

@birdayz
Copy link

birdayz commented Jan 19, 2024

Any plans to implement this?
Without, hierarchical relationships are really verbose and hard to maintain.

@josephschorr
Copy link
Member

@birdayz Yes, likely as part of #1437, since it will involve schema changes anyway

@jorihardman-aumni
Copy link

jorihardman-aumni commented Dec 12, 2024

We have a highly hierarchical relationship graph, and many of our most nested entities have permissions that are defined via relationships our users (subjects) have at the top of the hierarchy. In order to facilitate these highly-nested permissions, we need to build out a significant number of proxy permissions that aren't ultimately used by our application logic. Having nested arrows would allow us to only define permissions that we intend to use in applications which would greatly simplify our schema.

The existence of a permission implies that it will be used for domain decisions, and that's often not the case for our schema.

Contrived example:

Permission check of interest: nested_entity_3:some-entity-3#edit@user:some-user

# This is our subject 100% of the time
user {}

org {
  relation member: user
}

nested_entity_1 {
  relation owner_org: org

  # This is a proxy permission - it will not actually be used in application logic.
  permission edit: owner_org->member
}

nested_entity_2 {
  relation owner_entity_1: nested_entity_1

  # This is a proxy permission - it will not actually be used in application logic.
  permission edit: owner_entity_1->edit
}

nested_entity_3 {
  relation owner_entity_2: nested_entity_2

  # This is the permission we actually care about for domain decisions.
  permission edit: owner_entity_2->edit
}

But would be nice to have:

# This is our subject 100% of the time
user {}

org {
  relation member: user
}

nested_entity_1 {
  relation owner_org: org
}

nested_entity_2 {
  relation owner_entity_1: nested_entity_1
}

nested_entity_3 {
  relation owner_entity_2: nested_entity_2
  permission edit: owner_entity_2->owner_entity_1->owner_org->member
}

@thackerc
Copy link

@birdayz Yes, likely as part of #1437, since it will involve schema changes anyway

I see there is a preview version of composable schemas. Are you still hoping to include nested arrows at the same time?

@josephschorr
Copy link
Member

@thackerc We plan to do it; composable schemas has enabled it, but it is not quite scheduled yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) priority/2 medium This needs to be done
Projects
None yet
Development

No branches or pull requests

6 participants