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 support for --initialize-secure and --initialize-insecure #28487

Merged
merged 5 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ type Security struct {
// EnableSEM prevents SUPER users from having full access.
EnableSEM bool `toml:"enable-sem" json:"enable-sem"`
// Allow automatic TLS certificate generation
AutoTLS bool `toml:"auto-tls" json:"auto-tls"`
MinTLSVersion string `toml:"tls-version" json:"tls-version"`
RSAKeySize int `toml:"rsa-key-size" json:"rsa-key-size"`
AutoTLS bool `toml:"auto-tls" json:"auto-tls"`
MinTLSVersion string `toml:"tls-version" json:"tls-version"`
RSAKeySize int `toml:"rsa-key-size" json:"rsa-key-size"`
SecureBootstrap bool `toml:"secure-bootstrap" json:"secure-bootstrap"`
}

// The ErrConfigValidationFailed error is used so that external callers can do a type assertion
Expand Down
13 changes: 11 additions & 2 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,9 +1659,18 @@ func doDDLWorks(s Session) {
func doDMLWorks(s Session) {
mustExecute(s, "BEGIN")

// Insert a default user with empty password.
mustExecute(s, `INSERT HIGH_PRIORITY INTO mysql.user VALUES
if config.GetGlobalConfig().Security.SecureBootstrap {
// TODO:
// change "mysql_native_password" to "auth_socket"
// When these PRs are merged:
// https://github.com/pingcap/tidb/pull/27561
// https://github.com/pingcap/tidb/pull/28486
mustExecute(s, `INSERT HIGH_PRIORITY INTO mysql.user VALUES
("localhost", "root", "", "mysql_native_password", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y")`)
} else {
mustExecute(s, `INSERT HIGH_PRIORITY INTO mysql.user VALUES
("%", "root", "", "mysql_native_password", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y")`)
}

// Init global system variables table.
values := make([]string, 0, len(variable.GetSysVars()))
Expand Down
23 changes: 23 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const (
nmProxyProtocolNetworks = "proxy-protocol-networks"
nmProxyProtocolHeaderTimeout = "proxy-protocol-header-timeout"
nmAffinityCPU = "affinity-cpus"

nmInitializeSecure = "initialize-secure"
nmInitializeInsecure = "initialize-insecure"
)

var (
Expand Down Expand Up @@ -152,6 +155,10 @@ var (
// PROXY Protocol
proxyProtocolNetworks = flag.String(nmProxyProtocolNetworks, "", "proxy protocol networks allowed IP or *, empty mean disable proxy protocol support")
proxyProtocolHeaderTimeout = flag.Uint(nmProxyProtocolHeaderTimeout, 5, "proxy protocol header read timeout, unit is second.")

// Security
initializeSecure = flagBoolean(nmInitializeSecure, false, "bootstrap tidb-server in secure mode")
initializeInsecure = flagBoolean(nmInitializeInsecure, true, "bootstrap tidb-server in insecure mode")
)

func main() {
Expand Down Expand Up @@ -500,6 +507,22 @@ func overrideConfig(cfg *config.Config) {
if actualFlags[nmProxyProtocolHeaderTimeout] {
cfg.ProxyProtocol.HeaderTimeout = *proxyProtocolHeaderTimeout
}

// Security
// Sanity check:
if actualFlags[nmInitializeSecure] && actualFlags[nmInitializeInsecure] {
err = fmt.Errorf("the options --initialize-insecure and --initialize-secure are mutually exclusive")
terror.MustNil(err)
}
// The option --initialize-secure=true ensures that a secure bootstrap is used.
if actualFlags[nmInitializeSecure] {
cfg.Security.SecureBootstrap = *initializeSecure
}
// The option --initialize-insecure=true/false was used.
// Store the inverted value of this to the secure bootstrap cfg item
if actualFlags[nmInitializeInsecure] {
cfg.Security.SecureBootstrap = !*initializeInsecure
}
}

func setGlobalVars() {
Expand Down