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

Auth/Actions: Allow defining bool expression checks in action permissions #8825

Open
wawhal opened this issue Aug 20, 2022 · 0 comments
Open
Labels
a/authz Issues related to "authorization" and the policy engine after session claims are procesed c/actions Related to actions k/enhancement New feature or improve an existing feature k/v3-beta t/gql-services

Comments

@wawhal
Copy link
Contributor

wawhal commented Aug 20, 2022

Is your proposal related to a problem?

Motivation: We often find ourselves making queries to the database in the beginning of almost every action for verifying things like:

  • Checking whether user belongs to a desirable category/bucket/cohort.
  • Checking whether user has the right to modify an entity (ex: is the current user author of the article they're trying to mutate through an action).

Describe the solution you'd like

Hasura to allow defining action permissions based on bool checks built from data in the database, action arguments and session variables. This way, we can avoid writing a lot of repitetive validation by hand. Some sample solutions:

  • Checking whether a user is allowed to use a feature. This can be achieved by a bool expression:

     {
     	"_exists": {
     		"allowed_users": {
     			"id": {
     				"_eq": "x-hasura-user-id"
     			}
     		}
     	}
     }
    
  • Proceed with execution only if user is the author of an article. This can be achieved by a bool expression:

     {
     	"_exists": {
     		"articles": {
     			"id": {
     				"_eq": "$action-args.article_id"
     			},
     			"author_id": {
     			    "_eq": "x-hasura-user-id"
     			}
     		}
     	}
     }
    

Error definition

Since actions deal with custom business logic, it's important to allow defining custom errors (or error codes) about why the action invocation has failed. Most ideally, I'd like to configure this while defining permissions. Suggested solution:

  1. Allow defining multiple checks per role permission
  2. For each check, accept an error message and/or error-code
  3. Throw this error-message as a part of GraphQL error message and add the code to the extensions

I think this, combined with REST connectors would really be a big step towards improving DX in actions because.

Describe alternatives you've considered

Writing these permission rules by hand.

If the feature is approved, would you be willing to submit a PR?

No.

@wawhal wawhal added the k/enhancement New feature or improve an existing feature label Aug 20, 2022
@rikinsk rikinsk added c/actions Related to actions a/authz Issues related to "authorization" and the policy engine after session claims are procesed labels Aug 22, 2022
@robertjdominguez robertjdominguez changed the title allow defining bool expression checks in action permissions Auth: Allow defining bool expression checks in action permissions Aug 25, 2022
@robertjdominguez robertjdominguez changed the title Auth: Allow defining bool expression checks in action permissions Auth/Actions: Allow defining bool expression checks in action permissions Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/authz Issues related to "authorization" and the policy engine after session claims are procesed c/actions Related to actions k/enhancement New feature or improve an existing feature k/v3-beta t/gql-services
Projects
None yet
Development

No branches or pull requests

4 participants