Skip to content

Commit

Permalink
fix(GraphQL): Fix auth rewriting for nested queries when RBAC rule is…
Browse files Browse the repository at this point in the history
… true. (#6053)

* Fix auth rewriting for nested queries when RBAC rule is true.
  • Loading branch information
Arijit Das authored Jul 27, 2020
1 parent c51d007 commit 3e3a53f
Show file tree
Hide file tree
Showing 8 changed files with 527 additions and 90 deletions.
47 changes: 47 additions & 0 deletions graphql/e2e/auth/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,50 @@ query($USER: String!) {
id: ID!
email: String! @dgraph(pred: "IOw80vnV") @search(by: [hash])
}

type Contact @auth(
query: { rule: "{$ContactRole: { eq: \"ADMINISTRATOR\"}}" }
) {
id: ID!
nickName: String @search(by: [exact, term, fulltext, regexp])
adminTasks: [AdminTask] @hasInverse(field: forContact)
tasks: [Task] @hasInverse(field: forContact)
}

type AdminTask @auth(
query: { rule: "{$TaskRole: { eq: \"ADMINISTRATOR\"}}" }
) {
id: ID!
name: String @search(by: [exact, term, fulltext, regexp])
occurrances: [TaskOccurance] @hasInverse(field: adminTask)
forContact: Contact @hasInverse(field: adminTasks)
}

type Task {
id: ID!
name: String @search(by: [exact, term, fulltext, regexp])
occurrances: [TaskOccurance] @hasInverse(field: task)
forContact: Contact @hasInverse(field: tasks)
}

type TaskOccurance @auth(
query: { and : [
{rule: "{$TaskOccuranceRole: { eq: \"ADMINISTRATOR\"}}"},
{rule: """
query($TaskOccuranceRole: String!) {
queryTaskOccurance(filter: {role: { eq: $TaskOccuranceRole}}) {
__typename
}
}
"""}
] }
) {
id: ID!
due: DateTime @search
comp: DateTime @search
task: Task @hasInverse(field: occurrances)
adminTask: AdminTask @hasInverse(field: occurrances)
isPublic: Boolean @search
role: String @search(by: [exact, term, fulltext, regexp])
}

54 changes: 47 additions & 7 deletions graphql/resolve/auth_add_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "secret":
{ "aSecret": "it is",
Expand Down Expand Up @@ -35,6 +37,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "secrets":
[
Expand Down Expand Up @@ -64,6 +68,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "secret":
{ "aSecret": "it is",
Expand Down Expand Up @@ -94,6 +100,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "secrets":
[
Expand Down Expand Up @@ -125,6 +133,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "col":
{ "inProject": { "projID": "0x123" },
Expand Down Expand Up @@ -191,6 +201,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "col":
{
Expand Down Expand Up @@ -257,6 +269,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "col1":
{ "inProject": { "projID": "0x123" },
Expand Down Expand Up @@ -334,6 +348,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "col1":
{ "inProject": { "projID": "0x123" },
Expand Down Expand Up @@ -418,6 +434,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "col":
{ "inProject": { "projID": "0x123" },
Expand Down Expand Up @@ -493,6 +511,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "col":
{ "inProject": { "projID": "0x123" },
Expand Down Expand Up @@ -569,6 +589,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{
"proj": {
Expand Down Expand Up @@ -658,6 +680,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{
"proj": {
Expand Down Expand Up @@ -748,6 +772,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "log":
{ "logs": "log123",
Expand All @@ -769,7 +795,9 @@
}
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
variables: |
{ "log":
{ "logs": "log123",
Expand All @@ -789,7 +817,9 @@
}
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
variables: |
{
"proj": {
Expand All @@ -811,7 +841,9 @@
}
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
variables: |
{
"proj": {
Expand Down Expand Up @@ -850,7 +882,9 @@
}
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
variables: |
{ "issue":
{ "msg": "log123",
Expand Down Expand Up @@ -900,7 +934,9 @@
}
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
variables: |
{ "issue":
{ "msg": "log123",
Expand Down Expand Up @@ -950,7 +986,9 @@
}
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
variables: |
{ "log":
{ "logs": "log123",
Expand All @@ -971,7 +1009,9 @@
}
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
variables: |
{ "log":
{ "logs": "log123",
Expand Down
48 changes: 39 additions & 9 deletions graphql/resolve/auth_delete_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
msg
}
}
jwtvar:
USER: "user1"
variables: |
{ "filter": { "aSecret": { "anyofterms": "auth is applied" } } }
dgmutations:
Expand All @@ -29,6 +31,8 @@
msg
}
}
jwtvar:
USER: "user1"
variables: |
{ "filter": { "title": { "anyofterms": "auth is applied" } } }
dgmutations:
Expand Down Expand Up @@ -90,6 +94,8 @@
}
}
}
jwtvar:
USER: "user1"
variables: |
{ "filter": { "title": { "anyofterms": "auth is applied" } } }
dgmutations:
Expand Down Expand Up @@ -206,7 +212,9 @@
{
"projs" : ["0x01", "0x02"]
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand Down Expand Up @@ -244,7 +252,9 @@
"id": ["0x1", "0x2"]
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand All @@ -269,6 +279,8 @@
"username": { "eq": "userxyz" }
}
}
jwtvar:
USER: "user1"
dgmutations:
- deletejson: |
[
Expand Down Expand Up @@ -297,6 +309,8 @@
msg
}
}
jwtvar:
USER: "user1"
variables: |
{ "filter":
{
Expand Down Expand Up @@ -331,7 +345,9 @@
"id": ["0x1", "0x2"]
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand Down Expand Up @@ -359,7 +375,9 @@
"id": ["0x1", "0x2"]
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand Down Expand Up @@ -392,7 +410,9 @@
{
"ids" : ["0x01", "0x02"]
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
dgmutations:
- deletejson: |
[{ "uid": "uid(x)" }]
Expand All @@ -416,6 +436,8 @@
{
"ids" : ["0x01", "0x02"]
}
jwtvar:
USER: "user1"
dgmutations:
- deletejson: |
[{ "uid": "uid(x)" }]
Expand All @@ -442,7 +464,9 @@
"id": ["0x1", "0x2"]
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand Down Expand Up @@ -474,7 +498,9 @@
"id": ["0x1", "0x2"]
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand All @@ -498,7 +524,9 @@
"id": ["0x1", "0x2"]
}
}
role: "USER"
jwtvar:
ROLE: "USER"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand All @@ -522,7 +550,9 @@
"id": ["0x1", "0x2"]
}
}
role: "ADMIN"
jwtvar:
ROLE: "ADMIN"
USER: "user1"
dgmutations:
- deletejson: |
[{
Expand Down
Loading

0 comments on commit 3e3a53f

Please sign in to comment.