Skip to content

Commit

Permalink
Addition of user's groups in ACL Check error
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Sep 21, 2021
1 parent 1bec3dd commit aa90f25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion go/vt/vttablet/tabletserver/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ func (qre *QueryExecutor) checkAccess(authorized *tableacl.ACLResult, tableName
}

if qre.tsv.qe.strictTableACL {
errStr := fmt.Sprintf("%s command denied to user '%s' for table '%s' (ACL check error)", qre.plan.PlanID.String(), callerID.Username, tableName)
groupStr := ""
if len(callerID.Groups) > 0 {
groupStr = fmt.Sprintf(", in groups [%s],", strings.Join(callerID.Groups, ", "))
}
errStr := fmt.Sprintf("%s command denied to user '%s'%s for table '%s' (ACL check error)", qre.plan.PlanID.String(), callerID.Username, groupStr, tableName)
qre.tsv.Stats().TableaclDenied.Add(statsKey, 1)
qre.tsv.qe.accessCheckerLogger.Infof("%s", errStr)
return vterrors.Errorf(vtrpcpb.Code_PERMISSION_DENIED, "%s", errStr)
Expand Down
6 changes: 4 additions & 2 deletions go/vt/vttablet/tabletserver/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,15 @@ func TestQueryExecutorMessageStreamACL(t *testing.T) {

callerID = &querypb.VTGateCallerID{
Username: "u2",
Groups: []string{"non-admin"},
}
qre.ctx = callerid.NewContext(context.Background(), nil, callerID)
// Should fail because u2 does not have permission.
err = qre.MessageStream(func(qr *sqltypes.Result) error {
return io.EOF
})

assert.EqualError(t, err, `MessageStream command denied to user 'u2' for table 'msg' (ACL check error)`)
assert.EqualError(t, err, `MessageStream command denied to user 'u2', in groups [non-admin], for table 'msg' (ACL check error)`)
if code := vterrors.Code(err); code != vtrpcpb.Code_PERMISSION_DENIED {
t.Fatalf("qre.Execute: %v, want %v", code, vtrpcpb.Code_PERMISSION_DENIED)
}
Expand Down Expand Up @@ -1009,6 +1010,7 @@ func TestQueryExecutorTableAclExemptACL(t *testing.T) {
username := "u2"
callerID := &querypb.VTGateCallerID{
Username: username,
Groups: []string{"eng", "beta"},
}
ctx := callerid.NewContext(context.Background(), nil, callerID)

Expand All @@ -1034,7 +1036,7 @@ func TestQueryExecutorTableAclExemptACL(t *testing.T) {
if code := vterrors.Code(err); code != vtrpcpb.Code_PERMISSION_DENIED {
t.Fatalf("qre.Execute: %v, want %v", code, vtrpcpb.Code_PERMISSION_DENIED)
}
assert.EqualError(t, err, `Select command denied to user 'u2' for table 'test_table' (ACL check error)`)
assert.EqualError(t, err, `Select command denied to user 'u2', in groups [eng, beta], for table 'test_table' (ACL check error)`)

// table acl should be ignored since this is an exempt user.
username = "exempt-acl"
Expand Down

0 comments on commit aa90f25

Please sign in to comment.