Skip to content

Commit

Permalink
fix(groot): do not upsert groot for all namespaces on restart (#7917) (
Browse files Browse the repository at this point in the history
…#7924)

Earlier, whenever the alpha starts(or restarts), we were upserting guardian and groot for all the namespaces. This is not actually needed.
The change was made in the PR #7759 to fix a bulk loader edge case.
This PR fixes that by generating the required RDFs in the bulk loader itself. Essentially, it inserts the ACL RDFs when force loading into non-Galaxy namespace.

(cherry picked from commit 6730f10)
  • Loading branch information
NamanJain8 authored Jun 24, 2021
1 parent 17f52bc commit 0ab2352
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
17 changes: 17 additions & 0 deletions dgraph/cmd/bulk/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/dgraph-io/dgo/v210/protos/api"
"github.com/dgraph-io/dgraph/chunker"
"github.com/dgraph-io/dgraph/ee/acl"
"github.com/dgraph-io/dgraph/gql"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/protos/pb"
Expand Down Expand Up @@ -215,6 +216,8 @@ func (m *mapper) writeMapEntriesToFile(cbuf *z.Buffer, shardIdx int) {
x.Check(err)
}

var once sync.Once

func (m *mapper) run(inputFormat chunker.InputFormat) {
chunk := chunker.NewChunker(inputFormat, 1000)
nquads := chunk.NQuads()
Expand All @@ -227,6 +230,20 @@ func (m *mapper) run(inputFormat chunker.InputFormat) {
}
}
}
once.Do(func() {
if m.opt.Namespace != math.MaxUint64 && m.opt.Namespace != x.GalaxyNamespace {
// Insert ACL related RDFs force uploading the data into non-galaxy namespace.
aclNquads := make([]*api.NQuad, 0)
aclNquads = append(aclNquads, acl.CreateGroupNQuads(x.GuardiansId)...)
aclNquads = append(aclNquads, acl.CreateUserNQuads(x.GrootId, "password")...)
aclNquads = append(aclNquads, &api.NQuad{
Subject: "_:newuser",
Predicate: "dgraph.user.group",
ObjectId: "_:newgroup",
})
nquads.Push(aclNquads...)
}
})
nquads.Flush()
}()

Expand Down
4 changes: 3 additions & 1 deletion dgraph/cmd/bulk/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func init() {
flag.Bool("new_uids", false,
"Ignore UIDs in load files and assign new ones.")
flag.Uint64("force-namespace", math.MaxUint64,
"Namespace onto which to load the data. If not set, will preserve the namespace.")
"Namespace onto which to load the data. If not set, will preserve the namespace."+
" When using this flag to load data into specific namespace, make sure that the "+
"load data do not have ACL data.")

flag.String("badger", BulkBadgerDefaults, z.NewSuperFlagHelp(BulkBadgerDefaults).
Head("Badger options (Refer to badger documentation for all possible options)").
Expand Down
5 changes: 1 addition & 4 deletions edgraph/access_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,7 @@ func ResetAcl(closer *z.Closer) {
// The acl feature is not turned on.
return
}

for ns := range schema.State().Namespaces() {
upsertGuardianAndGroot(closer, ns)
}
upsertGuardianAndGroot(closer, x.GalaxyNamespace)
}

// Note: The handling of closer should be done by caller.
Expand Down
43 changes: 41 additions & 2 deletions ee/acl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package acl

import (
"github.com/dgraph-io/dgo/v210/protos/api"
"github.com/dgraph-io/dgraph/x"
"github.com/spf13/cobra"
)
Expand All @@ -30,6 +31,44 @@ func init() {
Use: "acl",
Short: "Enterprise feature. Not supported in oss version",
Annotations: map[string]string{"group": "security"},
},
Acl.Cmd.SetHelpTemplate(x.NonRootTemplate)
}
CmdAcl.Cmd.SetHelpTemplate(x.NonRootTemplate)
}

// CreateUserNQuads creates the NQuads needed to store a user with the given ID and
// password in the ACL system.
func CreateUserNQuads(userId, password string) []*api.NQuad {
return []*api.NQuad{
{
Subject: "_:newuser",
Predicate: "dgraph.xid",
ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: userId}},
},
{
Subject: "_:newuser",
Predicate: "dgraph.password",
ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: password}},
},
{
Subject: "_:newuser",
Predicate: "dgraph.type",
ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: "dgraph.type.User"}},
},
}
}

// CreateGroupNQuads cretes NQuads needed to store a group with the give ID.
func CreateGroupNQuads(groupId string) []*api.NQuad {
return []*api.NQuad{
{
Subject: "_:newgroup",
Predicate: "dgraph.xid",
ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: groupId}},
},
{
Subject: "_:newgroup",
Predicate: "dgraph.type",
ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: "dgraph.type.Group"}},
},
}
}

0 comments on commit 0ab2352

Please sign in to comment.