hasura / hasura/graphql-engine

Create permission check with a session variable in the LHS

Open
#3,685 17 comments 41 reactions 1 assignee Claimed by @0x777 View on GitHub
a/authz c/server c/v3-engine p/medium v3
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

Today one can use a session variable in a permission check on the right side of the equation (e.g. `'user_id' _eq 'X-Hasura-User-Id'`). Being able to create a permission checks entirely from a session variables would be amazing (e.g. `'X-Hasura-User-Permissions' _includes 'project_write'`).

Our JWT token looks something like the below. On authentication, we lookup the user permissions, given their role, and assign them a token that includes a list of their permissions. When their role is changed, or the role<->permissions mapping in the db changes, tokens are refreshed (in addition to short expiration, etc).

```json
{
"iat": 1578806077,
"exp": 1578806977,
"iss": "xyz",
"https://xyz.com/jwt/claims": {
"x-hasura-default-role": "workspace_user",
"x-hasura-permissions": ["projects_read", "projects_add", "workspace_write", "...etc"],
"x-hasura-allowed-roles": ["anonymous", "user", "workspace_user"],
"x-hasura-workspace-id": "48",
"x-hasura-user-id": "3"
}
}
```

WIth Hasura's current permission system, we have to do something like this to check that the user has the appropriate permission. It involves actually looking up the permission from a table as part of the db query (rather than using the info that is already in the JWT token / session):

Screen Shot 2020-01-12 at 5 06 33 PM

Ideally, we'd be able to do something like this and create a permission check from just session values. This is much simpler, and keeps the generated DB queries clean since Hasura does not need to add extra logic to join/lookup permissions table - the info is already in the session itself.

Screen Shot 2020-01-12 at 5 23 51 PM

Curious if you all have already considered a feature like this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.