Skip to content

Commit

Permalink
*: fix permissions of brie RESTORE to be RESTORE_ADMIN (#25039) (#25227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jun 15, 2021
1 parent 0fc8d82 commit 987ff3b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions executor/brie.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,14 @@ func (gs *tidbGlueSession) CreateSession(store kv.Storage) (glue.Session, error)
}

// Execute implements glue.Session
// These queries execute without privilege checking, since the calling statements
// such as BACKUP and RESTORE have already been privilege checked.
func (gs *tidbGlueSession) Execute(ctx context.Context, sql string) error {
// FIXME: br relies on a deprecated API, it may be unsafe
_, err := gs.se.(sqlexec.SQLExecutor).Execute(ctx, sql)
stmt, err := gs.se.(sqlexec.RestrictedSQLExecutor).ParseWithParams(ctx, sql)
if err != nil {
return err
}
_, _, err = gs.se.(sqlexec.RestrictedSQLExecutor).ExecRestrictedStmt(ctx, stmt)
return err
}

Expand Down
1 change: 1 addition & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func (s *testSuiteP1) TestShow(c *C) {
"Update Tables To update existing rows",
"Usage Server Admin No privileges - allow connect only",
"BACKUP_ADMIN Server Admin ",
"RESTORE_ADMIN Server Admin ",
"SYSTEM_VARIABLES_ADMIN Server Admin ",
"ROLE_ADMIN Server Admin ",
"CONNECTION_ADMIN Server Admin ",
Expand Down
4 changes: 2 additions & 2 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ func (s *testPlanSuite) TestVisitInfo(c *C) {
{
sql: "RESTORE DATABASE test FROM 'local:///tmp/a'",
ans: []visitInfo{
{mysql.ExtendedPriv, "", "", "", ErrSpecificAccessDenied, false, "BACKUP_ADMIN", false},
{mysql.ExtendedPriv, "", "", "", ErrSpecificAccessDenied, false, "RESTORE_ADMIN", false},
},
},
{
Expand All @@ -1269,7 +1269,7 @@ func (s *testPlanSuite) TestVisitInfo(c *C) {
{
sql: "SHOW RESTORES",
ans: []visitInfo{
{mysql.ExtendedPriv, "", "", "", ErrSpecificAccessDenied, false, "BACKUP_ADMIN", false},
{mysql.ExtendedPriv, "", "", "", ErrSpecificAccessDenied, false, "RESTORE_ADMIN", false},
},
},
{
Expand Down
14 changes: 11 additions & 3 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2255,9 +2255,12 @@ func (b *PlanBuilder) buildShow(ctx context.Context, show *ast.ShowStmt) (Plan,
case ast.ShowCreateView:
err := ErrSpecificAccessDenied.GenWithStackByArgs("SHOW VIEW")
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.ShowViewPriv, show.Table.Schema.L, show.Table.Name.L, "", err)
case ast.ShowBackups, ast.ShowRestores:
case ast.ShowBackups:
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or BACKUP_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "BACKUP_ADMIN", false, err)
case ast.ShowRestores:
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or RESTORE_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "RESTORE_ADMIN", false, err)
case ast.ShowTableNextRowId:
p := &ShowNextRowID{TableName: show.Table}
p.setSchemaAndNames(buildShowNextRowID())
Expand Down Expand Up @@ -2353,8 +2356,13 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (Plan,
b.visitInfo = collectVisitInfoFromGrantStmt(b.ctx, b.visitInfo, raw)
case *ast.BRIEStmt:
p.setSchemaAndNames(buildBRIESchema())
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or BACKUP_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "BACKUP_ADMIN", false, err)
if raw.Kind == ast.BRIEKindRestore {
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or RESTORE_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "RESTORE_ADMIN", false, err)
} else {
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or BACKUP_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "BACKUP_ADMIN", false, err)
}
case *ast.GrantRoleStmt:
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or ROLE_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "ROLE_ADMIN", false, err)
Expand Down
1 change: 1 addition & 0 deletions privilege/privileges/privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var SkipWithGrant = false
var _ privilege.Manager = (*UserPrivileges)(nil)
var dynamicPrivs = []string{
"BACKUP_ADMIN",
"RESTORE_ADMIN",
"SYSTEM_VARIABLES_ADMIN",
"ROLE_ADMIN",
"CONNECTION_ADMIN",
Expand Down

0 comments on commit 987ff3b

Please sign in to comment.