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

Experimental Reflection apis #98

Merged
merged 2 commits into from
May 1, 2024

Conversation

josephschorr
Copy link
Member

No description provided.

@josephschorr josephschorr force-pushed the reflection-apis branch 2 times, most recently from 3cce8c6 to b717a13 Compare April 17, 2024 18:46
@josephschorr josephschorr marked this pull request as ready for review April 24, 2024 15:37
// permissions that compute based off a set of relations. For example, if a schema has a relation
// `viewer` and a permission `view` defined as `permission view = viewer + editor`, then the
// computable permissions for the relation `viewer` will include `view`.
rpc ExperimentalComputablePermissions(ExperimentalComputablePermissionsRequest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name confused me on the first read (and the inverse one) - can you explain why this API is better than e.g. returning an expression tree?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because understanding how to walk the expression tree is a non-trivial task, especially as we add more operations to the schema

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would just be a AST and the leaf nodes will all be relations, right? So even as we add operations we still just have a tree with relations as leaves. Internal nodes are (op, []children) where a child is either another internal node or a leaf (relation) node?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite; it would have to take into account subject relations/permissions as well, and distinguish between the relation used on the left hand side of an arrow vs the right side ones. In particular, the right side of arrows are inferred based on the type system, and an AST would not show that information directly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we could come up with an AST that:

  • has enough info that consumers can understand the shape of the expressions
  • is simple enough that you can use it to determine the answers to basic questions (like what permission is affected by what relation) without needing to understand the full details of the tree

but this is experimental and nothing stops us from adding that in the future, so I'll leave it.

// permissions that compute based off a set of relations. For example, if a schema has a relation
// `viewer` and a permission `view` defined as `permission view = viewer + editor`, then the
// computable permissions for the relation `viewer` will include `view`.
rpc ExperimentalComputablePermissions(ExperimentalComputablePermissionsRequest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we could come up with an AST that:

  • has enough info that consumers can understand the shape of the expressions
  • is simple enough that you can use it to determine the answers to basic questions (like what permission is affected by what relation) without needing to understand the full details of the tree

but this is experimental and nothing stops us from adding that in the future, so I'll leave it.


message ExperimentalComputablePermissionsRequest {
Consistency consistency = 1;
repeated ExpRelationReference relations = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about including a filter so that you can avoid objects you're not interested in? i.e. when looking up the effects of a relationship that is used in an arrow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A filter for the response you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - you may be querying for changes to folder#parent and want to ignore changes in document#view for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


// optional_definition_name_match is a regex that is matched against the definition or caveat name.
// If not specified, will be ignored.
string optional_definition_name_match = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these regexes and not strings? I would've expected them to be more like the filters in the Permissions service

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purposefully to allow for prefix matching or other forms of matching. For example, you might want to filter to definitions under prefix someteam/

@josephschorr josephschorr merged commit 6db92be into authzed:main May 1, 2024
2 checks passed
@josephschorr josephschorr deleted the reflection-apis branch May 1, 2024 15:42
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Comment on lines +218 to +228
// optional_definition_name_match is a regex that is matched against the definition or caveat name.
// If not specified, will be ignored.
string optional_definition_name_match = 1;

// optional_relation_or_permission_name_match is a regex that is matched against the relation or permission name.
// If not specified, will be ignored.
string optional_relation_or_permission_name_match = 2;

// kind_filters is a list of kinds to filter on. If not specified, will be ignored. If multiple are specified,
// the filter will be applied in an OR fashion.
repeated KindFilter kind_filters = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephschorr when kind==caveat, the optional_definition makes sense, but optional_relation does not. IMHO a more type-safe way to model this is to have multiple types of KindFilter (CaveatFilter, ObjectFilter, RelationFilter), then remove both optional arguments, and only have repeated KindFilter kind_filters be a one of those types. The part I'm not sure is if you can create a repeated oneof

However, the ExperimentalReflectSchemaRequest already has a repeated ExpSchemaFilter, so why having the repeated KindFilter in ExpSchemaFilter? If superfluous, we could make kind_filters as I described and drop the repeated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part I'm not sure is if you can create a repeated oneof

You cannot; we'd have to create another message for the field and then repeat that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you thoughts on this I wrote?

However, the ExperimentalReflectSchemaRequest already has a repeated ExpSchemaFilter, so why having the repeated KindFilter in ExpSchemaFilter? If superfluous, we could make kind_filters as I described and drop the repeated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can likely drop the repeated from in here, yes

ZedToken read_at = 3;
}

message ExpSchemaFilter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All types should probably have a comment describing it

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

Successfully merging this pull request may close these issues.

4 participants