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: remove any string concat #22523

Merged
merged 9 commits into from
Feb 3, 2021
Merged

Conversation

morgo
Copy link
Contributor

@morgo morgo commented Jan 25, 2021

What problem does this PR solve?

Part of https://github.com/pingcap/tidb-test/issues/1152

What is changed and how it works?

What's Changed:

This removes any string concatenation from the privilege package, and changes it to use ExecuteInternal. Because the privilege package loads whole tables and does not need any paramaterized SQL, it should work before/after #22499 is merged.

There was no risk of injection from the previous usage, since the concat did not include any user-supplied data. But it's possible a PR in the future may misunderstand this and introduce a security issue. The new approach is to define the sqls as const. Thus, temptations are reduced.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

Convered by existing tests.

Side effects

  • None

Release note

  • No release note

Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@@ -357,12 +373,7 @@ func (p *MySQLPrivilege) LoadRoleGraph(ctx sessionctx.Context) error {

// LoadUserTable loads the mysql.user table from database.
func (p *MySQLPrivilege) LoadUserTable(ctx sessionctx.Context) error {
userPrivCols := make([]string, 0, len(mysql.Priv2UserCol))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to keep this dynamic array. Won't we add more privUserCol in the future?

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 theory actually it should become rare. The new privileges added to MySQL are usually added with something called DYNAMIC privileges. We have a spec for adding it here: #22486

We have already extended the privileges table prior to add ad-hoc DYNAMIC privileges. I don't think we need to migrate these yet, but it does actually break MySQL compatibility since a mysqldump becomes non-restorable.

Copy link
Contributor

@xhebox xhebox Jan 26, 2021

Choose a reason for hiding this comment

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

It makes sense to me, though. I wonder that there should be a comment at the mysql.Priv2UserCol to remind the update of tidb.

It is also rare that internal column names will cause problems, even if they are using string concat. The new API could handle the problem, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets see what @tiancaiamao thinks. I am happy to take either approach, but prefer the comment if he is okay with that.

@bb7133
Copy link
Member

bb7133 commented Jan 29, 2021

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 29, 2021
@bb7133
Copy link
Member

bb7133 commented Jan 29, 2021

/merge

@ti-srebot
Copy link
Contributor

@bb7133 Oops! This PR requires at least 2 LGTMs to merge. The current number of LGTM is 1

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Feb 1, 2021
ti-srebot
ti-srebot previously approved these changes Feb 1, 2021
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Feb 1, 2021
@AilinKid
Copy link
Contributor

AilinKid commented Feb 1, 2021

/run-all-tests

@tiancaiamao
Copy link
Contributor

Please resolve conflicts, rest LGTM

@morgo
Copy link
Contributor Author

morgo commented Feb 2, 2021

I've fixed this to work against the changes in master. Execute has also been changed to ExecuteInternal in 8f319f7

@xhebox
Copy link
Contributor

xhebox commented Feb 2, 2021

/run-check_dev

@xhebox
Copy link
Contributor

xhebox commented Feb 2, 2021

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 2, 2021
@ti-srebot
Copy link
Contributor

/run-all-tests

@morgo
Copy link
Contributor Author

morgo commented Feb 2, 2021

(The PR needs approval before merge because I pushed new changes.)

@bb7133
Copy link
Member

bb7133 commented Feb 3, 2021

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 26086b2 into pingcap:master Feb 3, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Feb 3, 2021
@ti-srebot
Copy link
Contributor

cherry pick to release-3.0 in PR #22688

@ti-srebot
Copy link
Contributor

cherry pick to release-3.1 failed

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Feb 3, 2021
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #22689

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Feb 3, 2021
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0-rc in PR #22690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/privilege status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants