dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

[BUG]: RBAC on update with input arrays causes error

Open rderbier opened this issue 1 year ago • 1 comments

What version of Dgraph are you using?

v23 or v24.0.1

What is the hardware spec (RAM, CPU, OS)?

Cloud

What steps will reproduce the bug?

Deploy schema

type User @auth(
  
      update: { 
        rule: "{ $role: { eq: \"ADMIN\" } }" 
      }
  
){
  email: String! @id
  note: String
}

# Dgraph.Authorization {"VerificationKey":"6ABBAA2014CFF00289D20D20DA296F67","header":"X-Dgraph-AuthToken","namespace":"https://dgraph.io/jwt/claims","Algo":"HS256","ClosedByDefault":true}

from Postman send GraphQL request

mutation MyMutation($input: [AddUserInput!]!, $upsert: Boolean) {
  addUser(input: $input, upsert: $upsert) {
    numUids
    user {
      email
    }
  }
}

with variables

{   "upsert": true,
    "input" : [
        {"email": "[email protected]"},
        {"email": "[email protected]"},
        {"email": "[email protected]"}
    ]
}

and header

X-Dgraph-AuthToken eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJodHRwczovL2RncmFwaC5pby9qd3QvY2xhaW1zIjp7InJvbGUiOiJBRE1JTiJ9fQ.DHYBRLpXfGxntOWTDQObq8_0PrPZfn_xVMAFZqE_zCM

The first invocation is successful ( add) The second invocation fails with

{
    "errors": [
        {
            "message": "mutation addUser failed because Dgraph execution failed because Some variables are declared multiple times.",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "addUser"
            ]
        }
    ],
    "data": {
        "addUser": null
    },
    "extensions": {
        "touched_uids": 6,
        "tracing": {
            "version": 1,
            "startTime": "2024-08-15T19:42:35.509121642Z",
            "endTime": "2024-08-15T19:42:35.513617509Z",
            "duration": 4495877,
            "execution": {
                "resolvers": [
                    {
                        "path": [
                            "addUser"
                        ],
                        "parentType": "Mutation",
                        "fieldName": "addUser",
                        "returnType": "AddUserPayload",
                        "startOffset": 154632,
                        "duration": 4330005,
                        "dgraph": [
                            {
                                "label": "preMutationQuery",
                                "startOffset": 216753,
                                "duration": 3521409
                            },
                            {
                                "label": "mutation",
                                "startOffset": 4068519,
                                "duration": 0
                            },
                            {
                                "label": "query",
                                "startOffset": 0,
                                "duration": 0
                            }
                        ]
                    }
                ]
            }
        }
    }
}

rderbier avatar Aug 15 '24 19:08 rderbier

@rderbier thank you so much for looking into this and opening the issue! Just to add my quick input - we are running into this currently in a production system and our workaround for now is to loop over our query and call it multiple times for lists. Obviously, this is not a great workaround for performance and I look forward to resolution! Thanks.

mwillfox avatar Aug 15 '24 19:08 mwillfox

Hi, it’s really unacceptable that this issue be closed. For one, I spent quite a bit of time helping to reproduce the problem and it’s a critical issue with RBAC. Second, we are paying for Dgraph Cloud and this issue is causing some of our workflows to become untenable due to performance problems since we cannot batch upsert. The issue needs to remain open and, in my opinion, should be prioritized.

mwillfox avatar Nov 29 '24 14:11 mwillfox