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

privilege: fix auth_socket bug, should only allow os user name to login #54032

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Jun 14, 2024

What problem does this PR solve?

Issue Number: close #54031

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  1. my os user is wangchao
$ whoami
wangchao
  1. create users:
> CREATE USER 'u1'@'localhost' IDENTIFIED WITH auth_socket;
Query OK, 0 rows affected
Time: 0.017s
> CREATE USER 'u2'@'localhost' IDENTIFIED WITH auth_socket AS "wangchao";
Query OK, 0 rows affected
Time: 0.012s
> CREATE USER 'wangchao'@'localhost' IDENTIFIED WITH auth_socket;
Query OK, 0 rows affected
Time: 0.025s
TiDB root@127.0.0.1:test> select host,user,authentication_string,plugin from mysql.user;
+-----------+----------+-----------------------+-----------------------+
| host      | user     | authentication_string | plugin                |
+-----------+----------+-----------------------+-----------------------+
| %         | root     |                       | mysql_native_password |
| localhost | u1       |                       | auth_socket           |
| localhost | u2       | wangchao              | auth_socket           |
| localhost | wangchao |                       | auth_socket           |
+-----------+----------+-----------------------+-----------------------+
4 rows in set
Time: 0.011s
  1. Try log in:

u1 is rejected because it is not same with os user:

$ mysql --comments -uu1 -S/tmp/tidb-4001.sock
ERROR 1045 (28000): Access denied for user 'u1'@'localhost' (using password: YES)

u2 is allowed because its authenticate string is same with os user:

$ mysql --comments -uu2 -S/tmp/tidb-4001.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2097182
Server version: 8.0.11-TiDB-None TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
...

wangchao is allowed because its the os user name:

> mysql --comments -uwangchao -S/tmp/tidb-4001.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2097184
Server version: 8.0.11-TiDB-None TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
...
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

fix `auth_socket` bug, should only allow os user name to login

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 14, 2024
Copy link

tiprow bot commented Jun 14, 2024

Hi @lcwangchao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 14, 2024
Copy link
Contributor

@dveeden dveeden left a comment

Choose a reason for hiding this comment

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

Is it possible to add tests to ensure this doesn't break again later on?

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 14, 2024
Copy link

ti-chi-bot bot commented Jun 14, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-14 09:44:33.48296416 +0000 UTC m=+717027.536276083: ☑️ agreed by CbcWestwolf.
  • 2024-06-14 10:00:06.156874583 +0000 UTC m=+717960.210186770: ☑️ agreed by dveeden.

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 10.00000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 55.0191%. Comparing base (21089fd) to head (78ef649).
Report is 4 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54032         +/-   ##
=================================================
- Coverage   72.5699%   55.0191%   -17.5509%     
=================================================
  Files          1515       1634        +119     
  Lines        434546     605962     +171416     
=================================================
+ Hits         315350     333395      +18045     
- Misses        99722     250261     +150539     
- Partials      19474      22306       +2832     
Flag Coverage Δ
integration 35.2783% <0.0000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 42.2162% <ø> (-0.0025%) ⬇️

Copy link

tiprow bot commented Jun 14, 2024

@lcwangchao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tidb_parser_test ea41978 link true /test tidb_parser_test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 17, 2024
pkg/server/conn.go Outdated Show resolved Hide resolved
Copy link

ti-chi-bot bot commented Jun 17, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CbcWestwolf, dveeden

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [CbcWestwolf,dveeden]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot merged commit 72d22d6 into pingcap:master Jun 17, 2024
21 checks passed
@lcwangchao lcwangchao deleted the fix_54031 branch June 17, 2024 07:29
@lcwangchao lcwangchao added needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. labels Jun 17, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 17, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #54049.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #54050.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #54051.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 17, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 17, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #54052.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TiDB does not reject connection for mismatched user when using auth_socket plugin
4 participants