-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(ACL): The Acl cache should be updated on restart and restore #7926
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
32867fc
Refresh ACLs on restart
ahsanbarkati 60e6e5f
Fix oss build
ahsanbarkati 53c50fe
Minor fix
ahsanbarkati 61b31db
Merge branch 'release/v21.03-slash' of https://github.com/dgraph-io/d…
minhaj-shakeel 548f088
reset ACL cache after online restore
minhaj-shakeel 517b641
remove unnecessary groot upset
minhaj-shakeel 7a5e40e
add test case for restore
minhaj-shakeel 3873c76
remove dgosx
minhaj-shakeel aa4fe5d
add license
minhaj-shakeel 042e49f
fix oss build
minhaj-shakeel a3afc8f
fix systest
minhaj-shakeel db26166
update go mod
minhaj-shakeel da984e3
Merge branch 'release/v21.03-slash' into ahsan/fix-acl-restart
minhaj-shakeel d01a8fd
gofmt
minhaj-shakeel eff9572
address comments
minhaj-shakeel 479035c
minor fix
minhaj-shakeel 5f4aa02
fix Read lock
minhaj-shakeel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12345678901234567890123456789012 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/dgraph-io/dgo/v210" | ||
"github.com/dgraph-io/dgo/v210/protos/api" | ||
"github.com/dgraph-io/dgraph/graphql/e2e/common" | ||
"github.com/dgraph-io/dgraph/testutil" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// disableDraining disables draining mode before each test for increased reliability. | ||
func disableDraining(t *testing.T) { | ||
drainRequest := `mutation draining { | ||
draining(enable: false) { | ||
response { | ||
code | ||
message | ||
} | ||
} | ||
}` | ||
|
||
params := testutil.GraphQLParams{ | ||
Query: drainRequest, | ||
} | ||
b, err := json.Marshal(params) | ||
require.NoError(t, err) | ||
|
||
token := testutil.Login(t, &testutil.LoginParams{UserID: "groot", Passwd: "password", Namespace: 0}) | ||
|
||
client := &http.Client{} | ||
req, err := http.NewRequest("POST", testutil.AdminUrl(), bytes.NewBuffer(b)) | ||
require.Nil(t, err) | ||
req.Header.Add("content-type", "application/json") | ||
req.Header.Add("X-Dgraph-AccessToken", token.AccessJwt) | ||
|
||
resp, err := client.Do(req) | ||
require.NoError(t, err) | ||
buf, err := ioutil.ReadAll(resp.Body) | ||
fmt.Println(string(buf)) | ||
require.NoError(t, err) | ||
require.Contains(t, string(buf), "draining mode has been set to false") | ||
} | ||
|
||
func sendRestoreRequest(t *testing.T, location, backupId string, backupNum int) { | ||
if location == "" { | ||
location = "/data/backup2" | ||
} | ||
params := &testutil.GraphQLParams{ | ||
Query: `mutation restore($location: String!, $backupId: String, $backupNum: Int) { | ||
restore(input: {location: $location, backupId: $backupId, backupNum: $backupNum}) { | ||
code | ||
message | ||
} | ||
}`, | ||
Variables: map[string]interface{}{ | ||
"location": location, | ||
"backupId": backupId, | ||
"backupNum": backupNum, | ||
}, | ||
} | ||
|
||
token := testutil.Login(t, &testutil.LoginParams{UserID: "groot", Passwd: "password", Namespace: 0}) | ||
resp := testutil.MakeGQLRequestWithAccessJwt(t, params, token.AccessJwt) | ||
resp.RequireNoGraphQLErrors(t) | ||
|
||
var restoreResp struct { | ||
Restore struct { | ||
Code string | ||
Message string | ||
RestoreId int | ||
} | ||
} | ||
require.NoError(t, json.Unmarshal(resp.Data, &restoreResp)) | ||
require.Equal(t, restoreResp.Restore.Code, "Success") | ||
} | ||
|
||
func TestAclCacheRestore(t *testing.T) { | ||
disableDraining(t) | ||
conn, err := grpc.Dial(testutil.SockAddr, grpc.WithInsecure()) | ||
require.NoError(t, err) | ||
dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) | ||
dg.Login(context.Background(), "groot", "password") | ||
|
||
sendRestoreRequest(t, "/backups", "beautiful_merkle9", 1) | ||
testutil.WaitForRestore(t, dg) | ||
|
||
token := testutil.Login(t, | ||
&testutil.LoginParams{UserID: "alice1", Passwd: "password", Namespace: 0}) | ||
params := &common.GraphQLParams{ | ||
Query: `query{ | ||
queryPerson{ | ||
name | ||
age | ||
} | ||
}`, | ||
|
||
Headers: make(http.Header), | ||
} | ||
params.Headers.Set("X-Dgraph-AccessToken", token.AccessJwt) | ||
|
||
resp := params.ExecuteAsPost(t, common.GraphqlURL) | ||
require.Nil(t, resp.Errors) | ||
|
||
expected := ` | ||
{ | ||
"queryPerson": [ | ||
{ | ||
"name": "MinhajSh", | ||
"age": 20 | ||
} | ||
] | ||
} | ||
` | ||
require.JSONEq(t, expected, string(resp.Data)) | ||
} |
Binary file added
BIN
+1.92 KB
systest/acl/restore/data/backups/dgraph.20210707.064957.946/r10306-g1.backup
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Manifests":[{"type":"full","since":0,"read_ts":10306,"groups":{"1":["0-dgraph.xid","0-dgraph.acl.rule","0-dgraph.drop.op","0-dgraph.graphql.p_query","0-Person.name","0-dgraph.user.group","0-dgraph.rule.predicate","0-dgraph.rule.permission","0-dgraph.graphql.schema","0-Person.age","0-dgraph.password","0-dgraph.graphql.xid","0-dgraph.type"]},"backup_id":"beautiful_merkle9","backup_num":1,"version":2105,"path":"dgraph.20210707.064957.946","encrypted":false,"drop_operations":[{}],"compression":"snappy"}]} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return. Why need to wait