Skip to content

Commit 9a587d6

Browse files
committed
Merge branch 'master' into CLOUDP-324440-fix-rs-ids
2 parents c7f1de2 + a9fce45 commit 9a587d6

File tree

103 files changed

+2881
-686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2881
-686
lines changed

.evergreen-tasks.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ tasks:
254254
commands:
255255
- func: "e2e_test"
256256

257+
- name: e2e_mongodb_custom_roles
258+
tags: [ "patch-run" ]
259+
commands:
260+
- func: "e2e_test"
261+
257262
- name: e2e_replica_set_recovery
258263
tags: [ "patch-run" ]
259264
commands:
@@ -644,7 +649,7 @@ tasks:
644649
commands:
645650
- func: "e2e_test"
646651

647-
- name: e2e_replica_set_custom_roles
652+
- name: e2e_replica_set_ldap_custom_roles
648653
tags: [ "patch-run" ]
649654
commands:
650655
- func: "e2e_test"

.evergreen.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ task_groups:
728728
- e2e_replica_set_ldap_user_to_dn_mapping
729729
# e2e_replica_set_ldap_agent_auth
730730
- e2e_replica_set_ldap_agent_client_certs
731-
- e2e_replica_set_custom_roles
731+
- e2e_replica_set_ldap_custom_roles
732732
- e2e_replica_set_update_roles_no_privileges
733733
- e2e_replica_set_ldap_group_dn
734734
- e2e_replica_set_ldap_group_dn_with_x509_agent
@@ -911,6 +911,7 @@ task_groups:
911911
- e2e_tls_x509_configure_all_options_sc
912912
- e2e_tls_x509_sc
913913
- e2e_meko_mck_upgrade
914+
- e2e_mongodb_custom_roles
914915
- e2e_sharded_cluster_oidc_m2m_group
915916
- e2e_sharded_cluster_oidc_m2m_user
916917
- e2e_multi_cluster_oidc_m2m_group

.githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function regenerate_public_rbac_multi_cluster() {
113113
if echo "$git_last_changed" | grep -q 'public/tools/multicluster'; then
114114
echo 'regenerating multicluster RBAC public example'
115115
pushd public/tools/multicluster
116-
EXPORT_RBAC_SAMPLES="true" go test -run TestPrintingOutRolesServiceAccountsAndRoleBindings
116+
EXPORT_RBAC_SAMPLES="true" go test ./... -run TestPrintingOutRolesServiceAccountsAndRoleBindings
117117
popd
118118
git add public/samples/multi-cluster-cli-gitops
119119
fi

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ precommit:
6262
switch:
6363
@ scripts/dev/switch_context.sh $(context) $(additional_override)
6464

65+
switcht:
66+
@ scripts/dev/switch_context_by_test.sh $(test)
67+
6568
# builds the Operator binary file and docker image and pushes it to the remote registry if using a remote registry. Deploys it to
6669
# k8s cluster
6770
operator: configure-operator build-and-push-operator-image
@@ -322,9 +325,9 @@ deploy: manifests kustomize
322325
undeploy:
323326
$(KUSTOMIZE) build config/default | kubectl delete -f -
324327

325-
# Generate manifests e.g. CRD, RBAC etc.
328+
# Generate manifests e.g. CRD etc.
326329
manifests: controller-gen
327-
export PATH="$(PATH)"; export GOROOT=$(GOROOT); $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths=./... output:crd:artifacts:config=config/crd/bases
330+
export PATH="$(PATH)"; export GOROOT=$(GOROOT); $(CONTROLLER_GEN) $(CRD_OPTIONS) paths=./... output:crd:artifacts:config=config/crd/bases
328331
# copy the CRDs to the public folder
329332
cp config/crd/bases/* helm_chart/crds/
330333
cat "helm_chart/crds/"* > public/crds.yaml

PROJECT

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: mongodb.com
2-
layout: go.kubebuilder.io/v3
6+
layout:
7+
- go.kubebuilder.io/v3
8+
plugins:
9+
manifests.sdk.operatorframework.io/v2: {}
10+
scorecard.sdk.operatorframework.io/v2: {}
311
projectName: mongodb-kubernetes
412
repo: github.com/mongodb/mongodb-kubernetes
513
resources:
@@ -30,7 +38,13 @@ resources:
3038
kind: MongoDBUser
3139
path: github.com/mongodb/mongodb-kubernetes/api/v1
3240
version: v1
41+
- api:
42+
crdVersion: v1
43+
namespaced: false
44+
controller: false
45+
domain: mongodb.com
46+
group: mongodb
47+
kind: ClusterMongoDBRole
48+
path: github.com/mongodb/mongodb-kubernetes/api/v1
49+
version: v1
3350
version: "3"
34-
plugins:
35-
manifests.sdk.operatorframework.io/v2: {}
36-
scorecard.sdk.operatorframework.io/v2: {}

RELEASE_NOTES.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
[//]: # (Consider renaming or removing the header for next release, otherwise it appears as duplicate in the published release, e.g: https://github.com/mongodb/mongodb-enterprise-kubernetes/releases/tag/1.22.0 )
22
<!-- Next Release -->
33

4+
# MCK 1.2.0 Release Notes
5+
6+
## New Features
7+
8+
* Added new **ClusterMongoDBRole** CRD to support reusable roles across multiple MongoDB clusters.
9+
* This allows users to define roles once and reuse them in multiple **MongoDB** or **MongoDBMultiCluster** resources. The role can be referenced through the `.spec.security.roleRefs` field. Note that only one of `.spec.security.roles` and `.spec.security.roleRefs` can be used at a time.
10+
* **ClusterMongoDBRole** resources are treated by the operator as a custom role templates that are only used when referenced by the database resources.
11+
* The new resource is watched by default by the operator. This means that the operator will require a new **ClusterRole** and **ClusterRoleBinding** to be created in the cluster. **ClusterRole** and **ClusterRoleBinding** resources are created by default with the helm chart or the kubectl mongodb plugin.
12+
* To disable this behavior in the helm chart, set the `operator.enableClusterMongoDBRoles` value to `false`. This will disable the creation of the necessary RBAC resources for the **ClusterMongoDBRole** resource, as well as disable the watch for this resource.
13+
* To not install the necessary **ClusterRole** and **ClusterRoleBinding** with the kubectl mongodb plugin set the `--create-mongodb-roles-cluster-role` to false.
14+
* The new **ClusterMongoDBRole** resource is designed to be read-only, meaning it can be used by MongoDB deployments managed by different operators.
15+
* The **ClusterMongoDBRole** resource can be deleted at any time, but the operator will not delete any roles that were created using this resource. To properly remove access, you must **manually** remove the reference to the **ClusterMongoDBRole** in the **MongoDB** or **MongoDBMultiCluster** resources.
16+
* The reference documentation for this resource can be found here: **TODO** (link to documentation)
17+
* For more information please see: **TODO** (link to documentation)
18+
* **MongoDB**, **MongoDBMulti**: Added support for OpenID Connect (OIDC) user authentication.
19+
* OIDC authentication can be configured with `spec.security.authentication.modes=OIDC` and `spec.security.authentication.oidcProviderConfigs` settings.
20+
* Minimum MongoDB version requirements:
21+
* `7.0.11`, `8.0.0`
22+
* Only supported with MongoDB Enterprise Server
23+
* For more information please see:
24+
* [Secure Client Authentication with OIDC](https://www.mongodb.com/docs/kubernetes/upcoming/tutorial/secure-client-connections/) # TODO
25+
* [Manage Database Users using OIDC](https://www.mongodb.com/docs/kubernetes/upcoming/manage-users/) # TODO
26+
* [Authentication and Authorization with OIDC/OAuth 2.0](https://www.mongodb.com/docs/manual/core/oidc/security-oidc/)
27+
28+
<!-- Past Releases -->
29+
430
# MCK 1.1.0 Release Notes
531

632
## New Features
@@ -12,10 +38,8 @@
1238
* minimum MongoDB Community version: 8.0.
1339
* TLS must be disabled in MongoDB (communication between mongot and mongod is in plaintext for now).
1440

15-
<!-- Past Releases -->
1641
# MCK 1.0.1 Release Notes
1742

18-
1943
## Bug Fixes
2044
* Fix missing agent images in the operator bundle in OpenShift catalog and operatorhub.io.
2145
* **MongoDBCommunity** resource was missing from watched list in Helm Charts

api/v1/mdb/mongodb_roles_validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func isValidCIDR(cidr string) bool {
270270
return err == nil
271271
}
272272

273-
func roleIsCorrectlyConfigured(role MongoDbRole, mdbVersion string) v1.ValidationResult {
273+
func RoleIsCorrectlyConfigured(role MongoDBRole, mdbVersion string) v1.ValidationResult {
274274
// Extensive validation of the roles attribute
275275

276276
if role.Role == "" {
@@ -305,10 +305,10 @@ func roleIsCorrectlyConfigured(role MongoDbRole, mdbVersion string) v1.Validatio
305305
return v1.ValidationSuccess()
306306
}
307307

308-
func rolesAttributeisCorrectlyConfigured(d DbCommonSpec) v1.ValidationResult {
308+
func rolesAttributeIsCorrectlyConfigured(d DbCommonSpec) v1.ValidationResult {
309309
// Validate every single entry and return error on the first one that fails validation
310310
for _, role := range d.Security.Roles {
311-
if res := roleIsCorrectlyConfigured(role, d.Version); res.Level == v1.ErrorLevel {
311+
if res := RoleIsCorrectlyConfigured(role, d.Version); res.Level == v1.ErrorLevel {
312312
return v1.ValidationError("Error validating role - %s", res.Msg)
313313
}
314314
}

api/v1/mdb/mongodb_types.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,16 @@ type SharedConnectionSpec struct {
742742
CloudManagerConfig *PrivateCloudConfig `json:"cloudManager,omitempty"`
743743
}
744744

745+
// +kubebuilder:validation:XValidation:rule="!(has(self.roles) && has(self.roleRefs)) || !(self.roles.size() > 0 && self.roleRefs.size() > 0)",message="At most one of roles or roleRefs can be non-empty"
745746
type Security struct {
746747
TLSConfig *TLSConfig `json:"tls,omitempty"`
747748
Authentication *Authentication `json:"authentication,omitempty"`
748-
Roles []MongoDbRole `json:"roles,omitempty"`
749+
750+
// +optional
751+
Roles []MongoDBRole `json:"roles,omitempty"`
752+
753+
// +optional
754+
RoleRefs []MongoDBRoleRef `json:"roleRefs,omitempty"`
749755

750756
// +optional
751757
CertificatesSecretsPrefix string `json:"certsSecretPrefix"`
@@ -973,7 +979,16 @@ type InheritedRole struct {
973979
Role string `json:"role"`
974980
}
975981

976-
type MongoDbRole struct {
982+
type MongoDBRoleRef struct {
983+
// +kubebuilder:validation:Required
984+
Name string `json:"name"`
985+
986+
// +kubebuilder:validation:Enum=ClusterMongoDBRole
987+
// +kubebuilder:validation:Required
988+
Kind string `json:"kind"`
989+
}
990+
991+
type MongoDBRole struct {
977992
Role string `json:"role"`
978993
AuthenticationRestrictions []AuthenticationRestriction `json:"authenticationRestrictions,omitempty"`
979994
Db string `json:"db"`
@@ -1604,7 +1619,10 @@ func EnsureSecurity(sec *Security) *Security {
16041619
sec.TLSConfig = &TLSConfig{}
16051620
}
16061621
if sec.Roles == nil {
1607-
sec.Roles = make([]MongoDbRole, 0)
1622+
sec.Roles = make([]MongoDBRole, 0)
1623+
}
1624+
if sec.RoleRefs == nil {
1625+
sec.RoleRefs = make([]MongoDBRoleRef, 0)
16081626
}
16091627
return sec
16101628
}

api/v1/mdb/mongodb_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func CommonValidators(db DbCommonSpec) []func(d DbCommonSpec) v1.ValidationResul
394394
deploymentsMustHaveAgentModeInAuthModes,
395395
scramSha1AuthValidation,
396396
ldapAuthRequiresEnterprise,
397-
rolesAttributeisCorrectlyConfigured,
397+
rolesAttributeIsCorrectlyConfigured,
398398
agentModeIsSetIfMoreThanADeploymentAuthModeIsSet,
399399
ldapGroupDnIsSetIfLdapAuthzIsEnabledAndAgentsAreExternal,
400400
specWithExactlyOneSchema,

api/v1/mdb/mongodbbuilder.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ func (b *MongoDBBuilder) SetSecurityTLSEnabled() *MongoDBBuilder {
146146
return b
147147
}
148148

149+
func (b *MongoDBBuilder) SetRoles(roles []MongoDBRole) *MongoDBBuilder {
150+
if b.mdb.Spec.Security == nil {
151+
b.mdb.Spec.Security = &Security{}
152+
}
153+
b.mdb.Spec.Security.Roles = roles
154+
return b
155+
}
156+
157+
func (b *MongoDBBuilder) SetRoleRefs(roleRefs []MongoDBRoleRef) *MongoDBBuilder {
158+
if b.mdb.Spec.Security == nil {
159+
b.mdb.Spec.Security = &Security{}
160+
}
161+
b.mdb.Spec.Security.RoleRefs = roleRefs
162+
return b
163+
}
164+
149165
func (b *MongoDBBuilder) SetLabels(labels map[string]string) *MongoDBBuilder {
150166
b.mdb.Labels = labels
151167
return b

0 commit comments

Comments
 (0)