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

executor: cleanup entries from mysql.db on revoke #38370

Merged
merged 10 commits into from
Oct 11, 2022
12 changes: 12 additions & 0 deletions executor/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ func (e *RevokeExec) revokeDBPriv(internalSession sessionctx.Context, priv *ast.
}
sqlexec.MustFormatSQL(sql, " WHERE User=%? AND Host=%? AND DB=%?", userName, host, dbName)

_, err = internalSession.(sqlexec.SQLExecutor).ExecuteInternal(ctx, sql.String())
if err != nil {
return err
}

sql = new(strings.Builder)
sqlexec.MustFormatSQL(sql, "DELETE FROM %n.%n WHERE User=%? AND Host=%? AND DB=%?", mysql.SystemDB, mysql.DBTable, userName, host, dbName)

for _, v := range append(mysql.AllDBPrivs, mysql.GrantPriv) {
privSQL := " AND " + mysql.Priv2UserCol[v] + "='N'"
sqlexec.MustFormatSQL(sql, privSQL)
dveeden marked this conversation as resolved.
Show resolved Hide resolved
}
_, err = internalSession.(sqlexec.SQLExecutor).ExecuteInternal(ctx, sql.String())
return err
}
Expand Down
9 changes: 8 additions & 1 deletion executor/revoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ func TestRevokeDBScope(t *testing.T) {

tk.MustQuery(check).Check(testkit.Rows("Y"))
tk.MustExec(sql)
tk.MustQuery(check).Check(testkit.Rows("N"))
if v == mysql.TriggerPriv {
dveeden marked this conversation as resolved.
Show resolved Hide resolved
// TriggerPriv is the last privilege, when all privs are
// removed, then the record should be removed as well.
// https://github.com/pingcap/tidb/issues/38363
tk.MustQuery(check).Check(testkit.Rows())
} else {
tk.MustQuery(check).Check(testkit.Rows("N"))
}
}
}

Expand Down