Skip to content

Commit 1f504cf

Browse files
committed
Merge branch 'master' into feature/mk-oidc-crd-propagation
# Conflicts: # api/v1/mdb/mongodb_types.go
2 parents 15a1cbc + 212aaf2 commit 1f504cf

File tree

14 files changed

+297
-111
lines changed

14 files changed

+297
-111
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
* @mongodb/kubernetes-hosted
2-
3-
helm_chart/crds/ @dan-mckean @vinilage

api/v1/mdb/mongodb_types.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,14 +807,6 @@ func (s *Security) IsTLSEnabled() bool {
807807
return s.CertificatesSecretsPrefix != ""
808808
}
809809

810-
func (s *Security) IsOIDCEnabled() bool {
811-
if s == nil || s.Authentication == nil || !s.Authentication.Enabled {
812-
return false
813-
}
814-
815-
return s.Authentication.IsOIDCEnabled()
816-
}
817-
818810
// GetAgentMechanism returns the authentication mechanism that the agents will be using.
819811
// The agents will use X509 if it is the only mechanism specified, otherwise they will use SCRAM if specified
820812
// and no auth if no mechanisms exist.
@@ -1007,16 +999,28 @@ type AgentAuthentication struct {
1007999
// IsX509Enabled determines if X509 is to be enabled at the project level
10081000
// it does not necessarily mean that the agents are using X509 authentication
10091001
func (a *Authentication) IsX509Enabled() bool {
1002+
if a == nil || !a.Enabled {
1003+
return false
1004+
}
1005+
10101006
return stringutil.Contains(a.GetModes(), util.X509)
10111007
}
10121008

10131009
// IsLDAPEnabled determines if LDAP is to be enabled at the project level
10141010
func (a *Authentication) IsLDAPEnabled() bool {
1011+
if a == nil || !a.Enabled {
1012+
return false
1013+
}
1014+
10151015
return stringutil.Contains(a.GetModes(), util.LDAP)
10161016
}
10171017

10181018
// IsOIDCEnabled determines if OIDC is to be enabled at the project level
10191019
func (a *Authentication) IsOIDCEnabled() bool {
1020+
if a == nil || !a.Enabled {
1021+
return false
1022+
}
1023+
10201024
return stringutil.Contains(a.GetModes(), util.OIDC)
10211025
}
10221026

api/v1/mdb/mongodb_types_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,20 @@ func TestGetAuthenticationIsEnabledMethods(t *testing.T) {
8383
expectedLDAP: false,
8484
expectedOIDC: false,
8585
},
86+
{
87+
name: "Empty authentication mode list",
88+
authentication: &Authentication{
89+
Enabled: true,
90+
},
91+
expectedX509: false,
92+
expectedLDAP: false,
93+
expectedOIDC: false,
94+
},
8695
{
8796
name: "Authentication with x509 only",
8897
authentication: &Authentication{
89-
Modes: []AuthMode{util.X509},
98+
Enabled: true,
99+
Modes: []AuthMode{util.X509},
90100
},
91101
expectedX509: true,
92102
expectedLDAP: false,
@@ -95,7 +105,8 @@ func TestGetAuthenticationIsEnabledMethods(t *testing.T) {
95105
{
96106
name: "Authentication with LDAP only",
97107
authentication: &Authentication{
98-
Modes: []AuthMode{util.LDAP},
108+
Enabled: true,
109+
Modes: []AuthMode{util.LDAP},
99110
},
100111
expectedX509: false,
101112
expectedLDAP: true,
@@ -104,7 +115,8 @@ func TestGetAuthenticationIsEnabledMethods(t *testing.T) {
104115
{
105116
name: "Authentication with OIDC only",
106117
authentication: &Authentication{
107-
Modes: []AuthMode{util.OIDC},
118+
Enabled: true,
119+
Modes: []AuthMode{util.OIDC},
108120
},
109121
expectedX509: false,
110122
expectedLDAP: false,
@@ -113,7 +125,8 @@ func TestGetAuthenticationIsEnabledMethods(t *testing.T) {
113125
{
114126
name: "Authentication with multiple modes",
115127
authentication: &Authentication{
116-
Modes: []AuthMode{util.X509, util.LDAP, util.OIDC, util.SCRAM},
128+
Enabled: true,
129+
Modes: []AuthMode{util.X509, util.LDAP, util.OIDC, util.SCRAM},
117130
},
118131
expectedX509: true,
119132
expectedLDAP: true,

api/v1/mdb/mongodb_validation.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func deploymentsMustHaveTLSInX509Env(d DbCommonSpec) v1.ValidationResult {
5454
if authSpec == nil {
5555
return v1.ValidationSuccess()
5656
}
57-
if authSpec.Enabled && authSpec.IsX509Enabled() && !d.GetSecurity().IsTLSEnabled() {
57+
if authSpec.IsX509Enabled() && !d.GetSecurity().IsTLSEnabled() {
5858
return v1.ValidationError("Cannot have a non-tls deployment when x509 authentication is enabled")
5959
}
6060
return v1.ValidationSuccess()
@@ -107,11 +107,15 @@ func scramSha1AuthValidation(d DbCommonSpec) v1.ValidationResult {
107107

108108
func oidcAuthValidators(db DbCommonSpec) []func(DbCommonSpec) v1.ValidationResult {
109109
validators := make([]func(DbCommonSpec) v1.ValidationResult, 0)
110-
if !db.Security.IsOIDCEnabled() {
110+
if db.Security == nil || db.Security.Authentication == nil {
111111
return validators
112112
}
113113

114114
authentication := db.Security.Authentication
115+
if !authentication.IsOIDCEnabled() {
116+
return validators
117+
}
118+
115119
validators = append(validators, oidcAuthModeValidator(authentication))
116120
validators = append(validators, oidcAuthRequiresEnterprise)
117121

api/v1/om/opsmanager_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ func ensureSecurityWithSCRAM(specSecurity *mdbv1.Security) *mdbv1.Security {
633633
specSecurity = &mdbv1.Security{TLSConfig: &mdbv1.TLSConfig{}}
634634
}
635635
// the only allowed authentication is SCRAM - it's implicit to the user and hidden from him
636-
specSecurity.Authentication = &mdbv1.Authentication{Modes: []mdbv1.AuthMode{util.SCRAM}}
636+
specSecurity.Authentication = &mdbv1.Authentication{Enabled: true, Modes: []mdbv1.AuthMode{util.SCRAM}}
637637
return specSecurity
638638
}
639639

controllers/operator/mongodbshardedcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ func (r *ShardedClusterReconcileHelper) doShardedClusterProcessing(ctx context.C
10141014
}
10151015

10161016
security := sc.Spec.Security
1017-
if security.Authentication != nil && security.Authentication.Enabled && security.Authentication.IsX509Enabled() && !sc.Spec.GetSecurity().IsTLSEnabled() {
1017+
if security.Authentication.IsX509Enabled() && !security.IsTLSEnabled() {
10181018
return workflow.Invalid("cannot have a non-tls deployment when x509 authentication is enabled")
10191019
}
10201020

controllers/operator/mongodbstandalone_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (r *ReconcileMongoDbStandalone) Reconcile(ctx context.Context, request reco
177177
// cannot have a non-tls deployment in an x509 environment
178178
// TODO move to webhook validations
179179
security := s.Spec.Security
180-
if security.Authentication != nil && security.Authentication.Enabled && security.Authentication.IsX509Enabled() && !s.Spec.GetSecurity().IsTLSEnabled() {
180+
if security.Authentication.IsX509Enabled() && !security.IsTLSEnabled() {
181181
return r.updateStatus(ctx, s, workflow.Invalid("cannot have a non-tls deployment when x509 authentication is enabled"), log)
182182
}
183183

docker/mongodb-kubernetes-tests/tests/multicluster_shardedcluster/multi_cluster_sharded_disaster_recovery.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
try_load,
1212
update_configmap,
1313
)
14-
from kubetester.kubetester import (
15-
KubernetesTester,
16-
ensure_ent_version,
17-
)
14+
from kubetester.kubetester import KubernetesTester, ensure_ent_version
1815
from kubetester.kubetester import fixture as yaml_fixture
1916
from kubetester.kubetester import (
2017
get_env_var_or_fail,

docker/mongodb-kubernetes-tests/tests/opsmanager/om_ops_manager_backup_sharded_cluster.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
from tests.shardedcluster.conftest import (
2424
enable_multi_cluster_deployment as enable_multi_cluster_deployment_mdb,
2525
)
26-
from tests.shardedcluster.conftest import (
27-
get_mongos_service_names,
28-
)
26+
from tests.shardedcluster.conftest import get_mongos_service_names
2927

3028
HEAD_PATH = "/head/"
3129
S3_SECRET_NAME = "my-s3-secret"

docker/mongodb-kubernetes-tests/tests/opsmanager/om_ops_manager_upgrade.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from kubernetes.client.rest import ApiException
88
from kubetester import MongoDB, try_load
99
from kubetester.awss3client import AwsS3Client
10-
from kubetester.kubetester import (
11-
ensure_ent_version,
12-
)
10+
from kubetester.kubetester import ensure_ent_version
1311
from kubetester.kubetester import fixture as yaml_fixture
1412
from kubetester.kubetester import (
1513
is_default_architecture_static,

0 commit comments

Comments
 (0)