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

*: kill one's own connection doesn't require SUPER privilege #6954

Merged
merged 4 commits into from
Jul 5, 2018

Conversation

tiancaiamao
Copy link
Contributor

What have you changed? (mandatory)

kill tidb connID, if the user is the owner of that connection, there
is no need to check the SUPER privilege.
SessionManager interface is slightly modified.

What are the type of the changes (mandatory)?

  • Bug fix (non-breaking change which fixes an issue)

How has this PR been tested (mandatory)?

It's somehow difficult to test this change. I check it manually.

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| kill@127.0.0.1 |
+----------------+
1 row in set (0.00 sec)

mysql> show processlist;
+------+------+-----------+------+---------+------+-------+------------------+------+
| Id   | User | Host      | db   | Command | Time | State | Info             | Mem  |
+------+------+-----------+------+---------+------+-------+------------------+------+
|    3 | kill | 127.0.0.1 |      | Query   |    2 | 2     | select sleep(40) |    0 |
|    4 | kill | 127.0.0.1 |      | Query   |    0 | 2     | show processlist |    0 |
|    2 | root | 127.0.0.1 |      | Query   |    0 | 2     |                  |    0 |
+------+------+-----------+------+---------+------+-------+------------------+------+
3 rows in set (0.00 sec)

mysql> kill tidb 2;                 // Kill other's connection without SUPER privilege would fail.
ERROR 1105 (HY000): privilege check fail
mysql> kill tidb 3;                 // Kill the user's own connection.
Query OK, 0 rows affected (0.00 sec)

PTAL @jackysp

`kill tidb connID`, if the user is the owner of that connection, there
is no need to check the SUPER privilege.
SessionManager interface is slightly modified.
// If you have the SUPER privilege, you can kill all threads and statements.
// Otherwise, you can kill only your own threads and statements.
sm := b.ctx.GetSessionManager()
if sm != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Could the sm be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the test code

@@ -33,6 +33,6 @@ type ProcessInfo struct {
// SessionManager is an interface for session manage. Show processlist and
// kill statement rely on this interface.
type SessionManager interface {
ShowProcessList() []ProcessInfo
ShowProcessList() map[uint64]ProcessInfo
Copy link
Member

Choose a reason for hiding this comment

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

Add comment for the return value.

// Otherwise, you can kill only your own threads and statements.
sm := b.ctx.GetSessionManager()
if sm != nil {
processList := sm.ShowProcessList()
Copy link
Member

Choose a reason for hiding this comment

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

Could you add an interface for SessionManger like GetProcessByConnID(connID) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GetProcessByConnID make SessionManager more complex.
GetProcessByConnID can be implemented using ShowProcessList which is already in SessionManager
I assume Kill will not be too frequency so this choice would not hurt the performance.
@shenli

Copy link
Member

@shenli shenli Jul 4, 2018

Choose a reason for hiding this comment

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

So the interface ShowProcessList returns a map instead of a list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@shenli
Copy link
Member

shenli commented Jul 2, 2018

@tiancaiamao Please fix the CI.

@tiancaiamao
Copy link
Contributor Author

PTAL @shenli @zimulala

@jackysp
Copy link
Member

jackysp commented Jul 4, 2018

/run-all-tests

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 4, 2018
@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@coocood
Copy link
Member

coocood commented Jul 5, 2018

/run-all-tests

@coocood coocood merged commit 7682a74 into pingcap:master Jul 5, 2018
tiancaiamao added a commit to tiancaiamao/tidb that referenced this pull request Jul 6, 2018
…#6954)

`kill tidb connID`, if the user is the owner of that connection, there
is no need to check the SUPER privilege.
SessionManager interface is slightly modified.
@tiancaiamao tiancaiamao deleted the kill-self branch July 6, 2018 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants