Skip to content

Commit 226f07f

Browse files
authored
feat(user): Use super users to replace root user (#601)
fix: #592
1 parent 0276c25 commit 226f07f

8 files changed

+73
-42
lines changed

api/v1alpha1/mysqlcluster_types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,26 @@ type MysqlClusterSpec struct {
9797
// +kubebuilder:default:=6
9898
BackupScheduleJobsHistoryLimit *int `json:"backupScheduleJobsHistoryLimit,omitempty"`
9999

100-
// Containing CA (ca.crt) and server cert (tls.crt) ,server private key (tls.key) for SSL
101-
//+optional
100+
// Containing CA (ca.crt) and server cert (tls.crt), server private key (tls.key) for SSL
101+
// +optional
102102
TlsSecretName string `json:"tlsSecretName,omitempty"`
103103
}
104104

105105
// MysqlOpts defines the options of MySQL container.
106106
type MysqlOpts struct {
107+
// Unchangeable: Use super users instead
107108
// Password for the root user, can be empty or 8~32 characters long.
108109
// Only be a combination of uppercase letters, lowercase letters, numbers or special characters.
109110
// Special characters are supported: @#$%^&*_+-=.
110111
// +optional
111112
// +kubebuilder:default:=""
112-
// +kubebuilder:validation:Pattern="^$|^[A-Za-z0-9@#$%^&*_+\\-=]{8,32}$"
113+
// +kubebuilder:validation:Enum=""
113114
RootPassword string `json:"rootPassword,omitempty"`
114115

116+
// Unchangeable: Use super users instead.
115117
// The root user's host.
116118
// +optional
119+
// +kubebuilder:validation:Enum=localhost
117120
// +kubebuilder:default:="localhost"
118121
RootHost string `json:"rootHost,omitempty"`
119122

charts/mysql-operator/crds/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,19 @@ spec:
205205
type: object
206206
rootHost:
207207
default: localhost
208-
description: The root user's host.
208+
description: 'Unchangeable: Use super users instead. The root
209+
user''s host.'
210+
enum:
211+
- localhost
209212
type: string
210213
rootPassword:
211214
default: ""
212-
description: 'Password for the root user, can be empty or 8~32
213-
characters long. Only be a combination of uppercase letters,
214-
lowercase letters, numbers or special characters. Special characters
215-
are supported: @#$%^&*_+-=.'
216-
pattern: ^$|^[A-Za-z0-9@#$%^&*_+\-=]{8,32}$
215+
description: 'Unchangeable: Use super users instead Password for
216+
the root user, can be empty or 8~32 characters long. Only be
217+
a combination of uppercase letters, lowercase letters, numbers
218+
or special characters. Special characters are supported: @#$%^&*_+-=.'
219+
enum:
220+
- ""
217221
type: string
218222
user:
219223
default: radondb_usr
@@ -1265,7 +1269,7 @@ spec:
12651269
path.
12661270
type: string
12671271
tlsSecretName:
1268-
description: Containing CA (ca.crt) and server cert (tls.crt) ,server
1272+
description: Containing CA (ca.crt) and server cert (tls.crt), server
12691273
private key (tls.key) for SSL
12701274
type: string
12711275
xenonOpts:

config/crd/bases/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,19 @@ spec:
205205
type: object
206206
rootHost:
207207
default: localhost
208-
description: The root user's host.
208+
description: 'Unchangeable: Use super users instead. The root
209+
user''s host.'
210+
enum:
211+
- localhost
209212
type: string
210213
rootPassword:
211214
default: ""
212-
description: 'Password for the root user, can be empty or 8~32
213-
characters long. Only be a combination of uppercase letters,
214-
lowercase letters, numbers or special characters. Special characters
215-
are supported: @#$%^&*_+-=.'
216-
pattern: ^$|^[A-Za-z0-9@#$%^&*_+\-=]{8,32}$
215+
description: 'Unchangeable: Use super users instead Password for
216+
the root user, can be empty or 8~32 characters long. Only be
217+
a combination of uppercase letters, lowercase letters, numbers
218+
or special characters. Special characters are supported: @#$%^&*_+-=.'
219+
enum:
220+
- ""
217221
type: string
218222
user:
219223
default: radondb_usr
@@ -1265,7 +1269,7 @@ spec:
12651269
path.
12661270
type: string
12671271
tlsSecretName:
1268-
description: Containing CA (ca.crt) and server cert (tls.crt) ,server
1272+
description: Containing CA (ca.crt) and server cert (tls.crt), server
12691273
private key (tls.key) for SSL
12701274
type: string
12711275
xenonOpts:

config/samples/mysql_v1alpha1_mysqlcluster.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ spec:
1818
# such as nfsServerAddress: "10.233.55.172"
1919
# nfsServerAddress:
2020
mysqlOpts:
21-
rootPassword: "RadonDB@123"
22-
rootHost: localhost
2321
user: radondb_usr
2422
password: RadonDB@123
2523
database: radondb

config/samples/mysql_v1alpha1_mysqlcluster_mysql8.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ spec:
1414
# restoreFrom:
1515

1616
mysqlOpts:
17-
rootPassword: "RadonDB@123"
18-
rootHost: localhost
1917
user: radondb_usr
2018
password: RadonDB@123
2119
database: radondb

config/samples/mysql_v1alpha1_mysqlcluster_podAntiAffinity.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ spec:
1414
# restoreFrom:
1515

1616
mysqlOpts:
17-
rootPassword: "RadonDB@123"
18-
rootHost: localhost
1917
user: radondb_usr
2018
password: RadonDB@123
2119
database: radondb
Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,51 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
# Corresponding to the user's secretName
6+
name: sample-user-password
7+
data:
8+
# The key corresponding to the user's secretKey
9+
# RadonDB@123
10+
superUser: UmFkb25EQkAxMjM=
11+
normalUser: UmFkb25EQkAxMjM=
12+
---
13+
apiVersion: mysql.radondb.com/v1alpha1
14+
kind: MysqlUser
15+
metadata:
16+
name: super-user
17+
spec:
18+
## MySQL user name.
19+
user: super_user
20+
withGrantOption: true
21+
tlsOptions:
22+
type: NONE
23+
hosts:
24+
- "%"
25+
permissions:
26+
- database: "*"
27+
tables:
28+
- "*"
29+
privileges:
30+
- ALL
31+
## Specify the cluster where the user is located.
32+
userOwner:
33+
clusterName: sample
34+
nameSpace: default
35+
## Specify the secret object for user.
36+
secretSelector:
37+
secretName: sample-user-password
38+
secretKey: superUser
39+
---
140
apiVersion: mysql.radondb.com/v1alpha1
241
kind: MysqlUser
342
metadata:
4-
name: sample-user-cr
43+
name: normal-user
544
spec:
6-
## User to operate.
7-
user: sample_user
45+
## MySQL user name.
46+
user: normal_user
847
withGrantOption: false
9-
tlsOptions:
10-
## NONE/SSL/X509
48+
tlsOptions:
1149
type: NONE
1250
hosts:
1351
- "%"
@@ -16,12 +54,12 @@ spec:
1654
tables:
1755
- "*"
1856
privileges:
19-
- SELECT
57+
- USAGE
2058
## Specify the cluster where the user is located.
2159
userOwner:
2260
clusterName: sample
2361
nameSpace: default
2462
## Specify the secret object for user.
2563
secretSelector:
2664
secretName: sample-user-password
27-
secretKey: pwdForSample
65+
secretKey: normalUser

config/samples/mysqluser_secret.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)