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

Support JSON arrays in session variables #1799

Closed
wants to merge 10 commits into from

Conversation

nizar-m
Copy link
Contributor

@nizar-m nizar-m commented Mar 18, 2019

Description

Setting the permission

echo '
type: create_insert_permission
args:
  role: user
  permission:
    set: {}
    check:
      id:
        _in: X-Hasura-Allowed-Ids
    columns:
    - id
  table:
    schema: public
    name: foo
' | yaml2json - | curl  -H 'content-type: application/json' -d @- 'http://localhost:8080/v1/query'

The following query will fail (because id: 28 is NOT in X-Hasura-Allowed-Ids: [21,23,25,27])

echo '
query: |
  mutation f {
    insert_food(objects: [{id: 28}]) {
      affected_rows
    }
  }' | yaml2json - | curl -H 'x-hasura-allowed-ids: [21,23,25,27]' -H 'x-hasura-role: user'   -H 'content-type: application/json' -d @- 'http://localhost:8080/v1alpha1/graphql'  

with the following response

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_food.args.objects",
        "code": "permission-error"
      },
      "message": "Check constraint violation. insert check constraint failed"
    }
  ]
}

while the following query gets through (as id: 23 is in X-Hasura-Allowed-Ids: [21,23,25,27])

echo '
query: |
  mutation f {
    insert_food(objects: [{id: 23}]) {
      affected_rows
    }
  }' | yaml2json - | curl -H 'x-hasura-allowed-ids: [21,23,25,27]' -H 'x-hasura-role: user'   -H 'content-type: application/json' -d @- 'http://localhost:8080/v1alpha1/graphql'  

Affected components

  • Server
  • Console
  • Docs
  • Tests

Related Issues

#1452
#1333

Solution and Design

  • @nizar-m: Make server handle JSON arrays in session variables
    • For array session variables as input for IN operator, use the following as the boolean expression
      column_value IN (SELECT json_array_elements_text(sessionVar))
  • @rikinsk: Make console accept session variable name (string) also as input for _in and _nin boolean expressions
  • @dsandip: Docs for JSON arrays in session variables

Steps to test and verify

Limitations, known bugs & workarounds

@nizar-m nizar-m requested a review from 0x777 as a code owner March 18, 2019 06:35
@coco98
Copy link
Contributor

coco98 commented Mar 18, 2019

@nizar-m Can you share the permission rule you used to set this up as well?

@hasura-bot
Copy link
Contributor

Review app for commit 9d61823 deployed to Heroku: https://hge-ci-pull-1799.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1799-9d61823

@coco98
Copy link
Contributor

coco98 commented Mar 19, 2019

@dsandip This should potentially also have an associated section in auth docs that talk about how and when to use this feature. Especially important in enterprise type scenarios when ownership information is outside the database.

Like:

  • role: manager
  • permission: select from this table if account_id in x-hasura-allowed-accounts

And the list of allowed accounts for the manager comes from an external database.

@netlify
Copy link

netlify bot commented Mar 19, 2019

Deploy preview for hasura-docs ready!

Built with commit 06abe03

https://deploy-preview-1799--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit 00864a5 deployed to Heroku: https://hge-ci-pull-1799.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1799-00864a5

@coco98
Copy link
Contributor

coco98 commented Mar 22, 2019

@nizar-m @dsandip Has this been reviewed by @rakeshkky or @ecthiender ?

@dsandip
Copy link
Member

dsandip commented Mar 22, 2019

@coco98 No, not yet

@dsandip dsandip added c/console Related to console c/server Related to server labels Mar 25, 2019
@rikinsk-zz
Copy link

Added console code to handle session variable value for array operators.

The UX seems slightly odd. Couldn't come up with something more intuitive. Please share feedback / suggestions if any.

@hasura-bot
Copy link
Contributor

Review app for commit 20202f5 deployed to Heroku: https://hge-ci-pull-1799.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1799-20202f5

@hasura-bot
Copy link
Contributor

Review app for commit e362ee8 deployed to Heroku: https://hge-ci-pull-1799.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1799-e362ee8

@thesems
Copy link

thesems commented May 7, 2019

This is really nice! When will it be ready?

@valstu
Copy link

valstu commented Jun 7, 2019

Great, this will solve many current workarounds 👍

@0x777
Copy link
Member

0x777 commented Jul 10, 2019

added in #2475

@0x777 0x777 closed this Jul 10, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-1799.herokuapp.com is deleted

@gugaevkirill
Copy link

gugaevkirill commented Aug 17, 2023

Sorry, is somebody working on this?
We're waiting for that feature too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/console Related to console c/server Related to server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet