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

fix(/commit): protect the commit endpoint via acl #7608

Merged
merged 9 commits into from
Mar 24, 2021

Conversation

NamanJain8
Copy link
Contributor

@NamanJain8 NamanJain8 commented Mar 18, 2021

/commit endpoint was not ACL protected. In a multi-tenant system, it could be disastrous where a malicious user can commit or abort the transactions of any namespace. This PR fixes this.

Fixes DGRAPH-3129


This change is Reviewable

Copy link
Contributor Author

@NamanJain8 NamanJain8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 7 files reviewed, 1 unresolved discussion (waiting on @manishrjain, @martinmr, and @vvbalaji-dgraph)


edgraph/server.go, line 1471 at r1 (raw file):

	txn := posting.Oracle().GetTxn(startTs)
	if txn == nil {

TODO: Check if this nil check is necessary. Currently, added it as a failsafe.

Copy link
Contributor

@aman-bansal aman-bansal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 7 files at r1.
Reviewable status: 2 of 7 files reviewed, 2 unresolved discussions (waiting on @manishrjain, @martinmr, @NamanJain8, and @vvbalaji-dgraph)


edgraph/server.go, line 1490 at r1 (raw file):

	}

	if x.WorkerConfig.AclEnabled {

I believe this wont work. you need to wait for all the raft entries to catchup.
see this if err := posting.Oracle().WaitForTs(ctx, m.StartTs); err != nil { return err }

then only you can ensure that txn would be there

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Do address @aman-bansal 's review comments.

Reviewed 7 of 7 files at r1.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @martinmr, @NamanJain8, and @vvbalaji-dgraph)


dgraph/cmd/alpha/http.go, line 507 at r1 (raw file):

	tctx, err := (&edgraph.Server{}).CommitOrAbort(ctx, tc)
	switch {
	case tctx.Aborted == true:

no need to say == true.


edgraph/server.go, line 1476 at r1 (raw file):

	if txn.Namespace != ns {
		return errors.New("Please log in into correct namespace.")

Mention the namespace that the user has. Don't mention the namespace that the txn has.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @aman-bansal, @martinmr, @NamanJain8, and @vvbalaji-dgraph)


edgraph/server.go, line 1471 at r1 (raw file):

Previously, NamanJain8 (Naman Jain) wrote…

TODO: Check if this nil check is necessary. Currently, added it as a failsafe.

we can return an error, that txn is not there.


edgraph/server.go, line 1490 at r1 (raw file):

Previously, aman-bansal (aman bansal) wrote…

I believe this wont work. you need to wait for all the raft entries to catchup.
see this if err := posting.Oracle().WaitForTs(ctx, m.StartTs); err != nil { return err }

then only you can ensure that txn would be there

That won't help. Because StartTs is assigned before mutations are applied. So, a server could be already at startTs, but not have the mutations.

Typically, the server which does the mutations, also gets the commit request. That way, the txn would be in the cache.

@NamanJain8 NamanJain8 marked this pull request as draft March 23, 2021 16:08
@NamanJain8 NamanJain8 marked this pull request as ready for review March 23, 2021 18:29
Copy link
Contributor

@ahsanbarkati ahsanbarkati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@NamanJain8 NamanJain8 requested a review from aman-bansal March 24, 2021 16:50
@NamanJain8 NamanJain8 dismissed aman-bansal’s stale review March 24, 2021 16:52

The changes requested are no longer valid. Discussed the PR with Manish and Ahsan, its good to merge.

@NamanJain8 NamanJain8 merged commit 6c0e3aa into release/v21.03 Mar 24, 2021
@NamanJain8 NamanJain8 deleted the naman/acl-commit branch March 24, 2021 16:53
aman-bansal pushed a commit that referenced this pull request Mar 25, 2021
/commit endpoint was not ACL protected. In a multi-tenant system, it could be disastrous where a malicious user can commit or abort the transactions of any namespace. This PR partially fixes the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants