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

*: add security enhanced mode part 1 #23978

Merged
merged 6 commits into from
Apr 15, 2021

Conversation

morgo
Copy link
Contributor

@morgo morgo commented Apr 12, 2021

What problem does this PR solve?

Problem Summary:

This implements the first of presumably 3-4 PRs to add security enhanced mode. I have a branch available which has almost all of the changes, but it has gotten too large to be reviewed easily.

I will handle the restricted variables / status variables / restricted_user_admin etc in followup PRs.

What is changed and how it works?

Proposal: https://github.com/pingcap/tidb/blob/master/docs/design/2021-03-09-security-enhanced-mode.md

What's Changed:

This introduces some of the basic functionality:

  • A config setting to enable/disable SEM (with a sysvar that is scoped NONE to see if you are on a server with it enabled).
  • Hard disabling of SELECT INTO OUTFILE and SHOW CONFIG (security risks)
  • Modification of the privilege manager to check for an additional role if SEM is enabled on secure tables.
  • The proposals have also been updated to consistently name dynamic privileges as "RESTRICTED__ADMIN and note that mysql.* privileges should be read only, like information_schema (recently introduced requirement from chatting to @SunRunAway ).

How it Works:

The restrictions are plugged directly into the privilege manager so that there are no risks from certain operations being missed in scope.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

  • Increased code complexity.
  • Breaking backward compatibility (when enabled; by default it is backward compatible)

Release note

  • The 'Security Enhanced Mode' has been introduced. When enabled, it prevents users with the SUPER privilege from performing certain high risk operations. The design is inspired by Security Enhanced (SE) Linux and AppArmor.

@morgo morgo requested review from a team as code owners April 12, 2021 23:47
@morgo morgo requested review from XuHuaiyu and removed request for a team April 12, 2021 23:47
@ti-chi-bot ti-chi-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 12, 2021
Comment on lines 536 to 539
if cfg.Experimental.EnableEnhancedSecurity {
security.Enable()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only real change to this file. The other changes are just cleaning up inconsistencies.

@zhouqiang-cl
Copy link
Contributor

/run-all-tests tidb-test=pr/1181

@tiancaiamao
Copy link
Contributor

/LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 13, 2021
errors.toml Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
util/security/security.go Outdated Show resolved Hide resolved
Comment on lines +62 to +83
var (
semEnabled int32
)

// Enable enables SEM. This is intended to be used by the test-suite.
// Dynamic configuration by users may be a security risk.
func Enable() {
atomic.StoreInt32(&semEnabled, 1)
variable.SetSysVar(variable.TiDBEnableEnhancedSecurity, variable.BoolOn)
}

// Disable disables SEM. This is intended to be used by the test-suite.
// Dynamic configuration by users may be a security risk.
func Disable() {
atomic.StoreInt32(&semEnabled, 0)
variable.SetSysVar(variable.TiDBEnableEnhancedSecurity, variable.BoolOff)
}

// IsEnabled checks if Security Enhanced Mode (SEM) is enabled
func IsEnabled() bool {
return atomic.LoadInt32(&semEnabled) == 1
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to use atomics because I noticed collations used this pattern. Even though there was no race on using the config element, it might have triggered the race detector.

@bb7133
Copy link
Member

bb7133 commented Apr 14, 2021

/LGTM

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • bb7133
  • tiancaiamao

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 14, 2021
@bb7133
Copy link
Member

bb7133 commented Apr 14, 2021

Please resolve the conflicts.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 14, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 14, 2021
@morgo
Copy link
Contributor Author

morgo commented Apr 14, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 0552070

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 14, 2021
@morgo
Copy link
Contributor Author

morgo commented Apr 14, 2021

/run-sqllogic-test-1
/run-unit-test

@morgo
Copy link
Contributor Author

morgo commented Apr 14, 2021

/run-all-tests

@bb7133
Copy link
Member

bb7133 commented Apr 14, 2021

Do we need to merge tidb-test/#1181?

@morgo
Copy link
Contributor Author

morgo commented Apr 14, 2021

Do we need to merge tidb-test/#1181?

No, this is related to a different PR. But yes, it would be great to merge it :-)

@bb7133
Copy link
Member

bb7133 commented Apr 14, 2021

/merge

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Apr 14, 2021
@morgo
Copy link
Contributor Author

morgo commented Apr 14, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 7b47277

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 14, 2021
@ti-chi-bot
Copy link
Member

@morgo: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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 ti-community-infra/tichi repository.

@morgo
Copy link
Contributor Author

morgo commented Apr 15, 2021

/merge

@ti-chi-bot ti-chi-bot merged commit 4072172 into pingcap:master Apr 15, 2021
@morgo morgo deleted the security-enhanced-mode-1 branch April 16, 2021 01:56
@morgo morgo mentioned this pull request May 19, 2021
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/config component/expression sig/sql-infra SIG: SQL Infra size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. 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.

5 participants