Skip to content

Commit 82f4dc9

Browse files
authored
CLOUDP-66799: Configure SCRAM users (#99)
1 parent ffd7897 commit 82f4dc9

File tree

29 files changed

+915
-195
lines changed

29 files changed

+915
-195
lines changed

deploy/crds/mongodb.com_mongodb_crd.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ spec:
5353
description: Security configures security features, such as TLS, and
5454
authentication settings for a deployment
5555
properties:
56+
authentication:
57+
properties:
58+
modes:
59+
description: Modes is an array specifying which authentication
60+
methods should be enabled
61+
items:
62+
enum:
63+
- SCRAM
64+
type: string
65+
type: array
66+
required:
67+
- modes
68+
type: object
5669
tls:
5770
description: TLS configuration for both client-server and server-server
5871
communication
@@ -101,11 +114,61 @@ spec:
101114
enum:
102115
- ReplicaSet
103116
type: string
117+
users:
118+
description: Users specifies the MongoDB users that should be configured
119+
in your deployment
120+
items:
121+
properties:
122+
db:
123+
description: DB is the database the user is stored in. Defaults
124+
to "admin"
125+
type: string
126+
name:
127+
description: Name is the username of the user
128+
type: string
129+
passwordSecretRef:
130+
description: PasswordSecretRef is a reference to the secret containing
131+
this user's password
132+
properties:
133+
key:
134+
description: Key is the key in the secret storing this password.
135+
Defaults to "password"
136+
type: string
137+
name:
138+
description: Name is the name of the secret storing this user's
139+
password
140+
type: string
141+
required:
142+
- name
143+
type: object
144+
roles:
145+
description: Roles is an array of roles assigned to this user
146+
items:
147+
description: Role is the database role this user should have
148+
properties:
149+
db:
150+
description: DB is the database the role can act on
151+
type: string
152+
name:
153+
description: Name is the name of the role
154+
type: string
155+
required:
156+
- db
157+
- name
158+
type: object
159+
type: array
160+
required:
161+
- name
162+
- passwordSecretRef
163+
- roles
164+
type: object
165+
type: array
104166
version:
105167
description: Version defines which version of MongoDB will be used
106168
type: string
107169
required:
108170
- type
171+
- users
109172
- version
110173
type: object
111174
status:

deploy/crds/mongodb.com_v1_mongodb_scram_cr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ spec:
88
version: "4.2.6"
99
security:
1010
authentication:
11-
enabled: true
1211
modes: ["SCRAM"]
1312
users:
1413
- name: my-user

pkg/apis/mongodb/v1/mongodb_types.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const (
2626
Running Phase = "Running"
2727
)
2828

29+
const (
30+
defaultPasswordKey = "password"
31+
)
32+
2933
// MongoDBSpec defines the desired state of MongoDB
3034
type MongoDBSpec struct {
3135
// Members is the number of members in the replica set
@@ -48,7 +52,7 @@ type MongoDBSpec struct {
4852

4953
// Users specifies the MongoDB users that should be configured in your deployment
5054
// +required
51-
Users []MongoDBUser `json:"-"` // `json:"users"`
55+
Users []MongoDBUser `json:"users"`
5256

5357
// +optional
5458
StatefulSetConfiguration StatefulSetConfiguration `json:"statefulSet,omitempty"`
@@ -112,6 +116,21 @@ type MongoDBUser struct {
112116
Roles []Role `json:"roles"`
113117
}
114118

119+
func (m MongoDBUser) GetPasswordSecretKey() string {
120+
if m.PasswordSecretRef.Key == "" {
121+
return defaultPasswordKey
122+
}
123+
return m.PasswordSecretRef.Key
124+
}
125+
126+
func (m MongoDBUser) GetPasswordSecretName() string {
127+
return m.PasswordSecretRef.Name
128+
}
129+
130+
func (m MongoDBUser) GetUserName() string {
131+
return m.Name
132+
}
133+
115134
// SecretKeyReference is a reference to the secret containing the user's password
116135
type SecretKeyReference struct {
117136
// Name is the name of the secret storing this user's password
@@ -132,7 +151,7 @@ type Role struct {
132151

133152
type Security struct {
134153
// +optional
135-
Authentication Authentication `json:"-"` //`json:"authentication"`
154+
Authentication Authentication `json:"authentication"`
136155
// TLS configuration for both client-server and server-server communication
137156
// +optional
138157
TLS TLS `json:"tls"`
@@ -167,9 +186,6 @@ type LocalObjectReference struct {
167186
}
168187

169188
type Authentication struct {
170-
// Enabled specifies if authentication should be enabled
171-
Enabled bool `json:"enabled"`
172-
173189
// Modes is an array specifying which authentication methods should be enabled
174190
Modes []AuthMode `json:"modes"`
175191
}
@@ -230,7 +246,7 @@ func (m MongoDB) ServiceName() string {
230246
return m.Name + "-svc"
231247
}
232248

233-
func (m MongoDB) ConfigMapName() string {
249+
func (m MongoDB) AutomationConfigSecretName() string {
234250
return m.Name + "-config"
235251
}
236252

@@ -256,7 +272,7 @@ func (m MongoDB) NamespacedName() types.NamespacedName {
256272
}
257273

258274
func (m *MongoDB) ScramCredentialsNamespacedName() types.NamespacedName {
259-
return types.NamespacedName{Name: "agent-scram-credentials", Namespace: m.Namespace}
275+
return types.NamespacedName{Name: fmt.Sprintf("%s-agent-scram-credentials", m.Name), Namespace: m.Namespace}
260276
}
261277

262278
// GetFCV returns the feature compatibility version. If no FeatureCompatibilityVersion is specified.

0 commit comments

Comments
 (0)