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

build: add support for identity backlinks to permissions package #1323

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

jonbretman
Copy link
Member

  • Updated permissions package to support backlinks from ctx.identity
  • Updated permissions tests
  • Added quick integration test for function permissions that uses a backlink

I strongly feel that we should update the runtime permissions stuff to use the permissions package SQL generation so that we can be sure behaviour is the same between runtime and functions. Looking at the runtime code I don't think this should be too tricky as ultimately we just execute some SQL

@jonbretman jonbretman requested a review from a team December 15, 2023 11:06
@davenewza
Copy link
Contributor

davenewza commented Dec 18, 2023

I strongly feel that we should update the runtime permissions stuff to use the permissions package SQL generation so that we can be sure behaviour is the same between runtime and functions. Looking at the runtime code I don't think this should be too tricky as ultimately we just execute some SQL

@jonbretman Having two independent expression-to-SQL builders is just silly (which I think we both agree on). But if we do move runtime permissions to use this permissions package, then we still end up with two independent expression-to-SQL builders because @where uses the query builder in the actions package. This means that every time we add a some feature or fix some bug for expressions, we will need to implement it in two places ...we're doubling the work needed.

I am still more in favour of having functions permissions rather use the actions package query builder instead, because then we have one SQL builder AND because I think the action builder package is covering more use cases, has more tests, and should be more battle-hardened by now (by virtue of action @where and @permission expressions having been more thoroughly used and tested and fixed).

I think we're a little stuck on this point. Perhaps it's also due to me feeling more comfortable with the runtime permissions code and you feeling more comfortable with the functions permissions code. But at the end of the day I also just want this unified.

Copy link
Contributor

@davenewza davenewza left a comment

Choose a reason for hiding this comment

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

Looks good!

Maybe we need some tests which test cases such as:

Backlinking to some field:

create createFilm() {
    @permission(expression: ctx.identity.user.isTeller)
}

And something a little more complicated:

create admit() with (film.id) {
    @permission(expression: admit.identity.user.age >= admit.film.ageRestriction)
}

And backlinking deeper down the relationship graph:

create createFilm() {
    @permission(expression: ctx.identity.user.team in film.teams.team)
}

@jonbretman
Copy link
Member Author

jonbretman commented Dec 18, 2023

I strongly feel that we should update the runtime permissions stuff to use the permissions package SQL generation so that we can be sure behaviour is the same between runtime and functions. Looking at the runtime code I don't think this should be too tricky as ultimately we just execute some SQL

@jonbretman Having two independent expression-to-SQL builders is just silly (which I think we both agree on). But if we do move runtime permissions to use this permissions package, then we still end up with two independent expression-to-SQL builders because @where uses the query builder in the actions package. This means that every time we add a some feature or fix some bug for expressions, we will need to implement it in two places ...we're doubling the work needed.

I am still more in favour of having functions permissions rather use the actions package query builder instead, because then we have one SQL builder AND because I think the action builder package is covering more use cases, has more tests, and should be more battle-hardened by now (by virtue of action @where and @permission expressions having been more thoroughly used and tested and fixed).

I think we're a little stuck on this point. Perhaps it's also due to me feeling more comfortable with the runtime permissions code and you feeling more comfortable with the functions permissions code. But at the end of the day I also just want this unified.

@davenewza if you have an idea on technically how to use the runtime actions query builder (in Go) in functions (in other languages) I'm very happy to discuss it - but personally I can't think of a viable way of doing this. Go's WASM support just isn't there, and calling out to the runtime for every query will be way too slow.

I also think the @where stuff is different - those only apply to non-function actions, but permissions cover both runtime actions and functions.

@jonbretman
Copy link
Member Author

Looks good!

Maybe we need some tests which test cases such as:

Backlinking to some field:

create createFilm() {
    @permission(expression: ctx.identity.user.isTeller)
}

And something a little more complicated:

create admit() with (film.id) {
    @permission(expression: admit.identity.user.age >= admit.film.ageRestriction)
}

And backlinking deeper down the relationship graph:

create createFilm() {
    @permission(expression: ctx.identity.user.team in film.teams.team)
}

Good idea - I'll add some like this.

@jonbretman jonbretman force-pushed the permissions-backlinks branch from c5fd7ba to 89f6216 Compare December 19, 2023 12:22
@jonbretman jonbretman merged commit 5a4004f into main Dec 19, 2023
10 checks passed
@jonbretman jonbretman deleted the permissions-backlinks branch December 19, 2023 16:00
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

Successfully merging this pull request may close these issues.

3 participants