@@ -30,6 +30,7 @@ import (
30
30
"github.com/mongodb/mongodb-kubernetes/controllers/operator/authentication"
31
31
"github.com/mongodb/mongodb-kubernetes/controllers/operator/certs"
32
32
"github.com/mongodb/mongodb-kubernetes/controllers/operator/construct"
33
+ enterprisepem "github.com/mongodb/mongodb-kubernetes/controllers/operator/pem"
33
34
"github.com/mongodb/mongodb-kubernetes/controllers/operator/secrets"
34
35
"github.com/mongodb/mongodb-kubernetes/controllers/operator/watch"
35
36
"github.com/mongodb/mongodb-kubernetes/controllers/operator/workflow"
@@ -231,7 +232,7 @@ func (r *ReconcileCommonController) SetupCommonWatchers(watcherResource WatcherR
231
232
} else {
232
233
secretNames = []string {security .MemberCertificateSecretName (resourceNameForSecret )}
233
234
if security .ShouldUseX509 ("" ) {
234
- secretNames = append (secretNames , security .AgentClientCertificateSecretName (resourceNameForSecret ). Name )
235
+ secretNames = append (secretNames , security .AgentClientCertificateSecretName (resourceNameForSecret ))
235
236
}
236
237
}
237
238
r .resourceWatcher .RegisterWatchedTLSResources (objectToReconcile , security .TLSConfig .CA , secretNames )
@@ -504,6 +505,7 @@ func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context,
504
505
return workflow .Failed (xerrors .Errorf ("error configuring agent subjects: %w" , err )), false
505
506
}
506
507
authOpts .AgentsShouldUseClientAuthentication = ar .GetSecurity ().ShouldUseClientCertificates ()
508
+ authOpts .AutoPEMKeyFilePath = util .PvcMmsHomeMountPath + "/" + util .AgentSecretName + "/" + agentCertSecretSelector .Key
507
509
}
508
510
if ar .GetSecurity ().ShouldUseLDAP (ac .Auth .AutoAuthMechanism ) {
509
511
secretRef := ar .GetSecurity ().Authentication .Agents .AutomationPasswordSecretRef
@@ -595,16 +597,22 @@ func (r *ReconcileCommonController) readAgentSubjectsFromSecret(ctx context.Cont
595
597
}
596
598
597
599
func (r * ReconcileCommonController ) clearProjectAuthenticationSettings (ctx context.Context , conn om.Connection , mdb * mdbv1.MongoDB , processNames []string , log * zap.SugaredLogger ) error {
598
- secretKeySelector := mdb .Spec .Security .AgentClientCertificateSecretName (mdb .Name )
600
+ agentCertSecretName := mdb .Spec .Security .AgentClientCertificateSecretName (mdb .Name )
601
+
599
602
agentSecret := & corev1.Secret {}
600
- if err := r .client .Get (ctx , kube .ObjectKey (mdb .Namespace , secretKeySelector . Name ), agentSecret ); client .IgnoreNotFound (err ) != nil {
603
+ if err := r .client .Get (ctx , kube .ObjectKey (mdb .Namespace , agentCertSecretName ), agentSecret ); client .IgnoreNotFound (err ) != nil {
601
604
return nil
602
605
}
603
606
604
607
if agentSecret .Type == corev1 .SecretTypeTLS {
605
- secretKeySelector . Name = fmt .Sprintf ("%s%s" , secretKeySelector . Name , certs .OperatorGeneratedCertSuffix )
608
+ agentCertSecretName = fmt .Sprintf ("%s%s" , agentCertSecretName , certs .OperatorGeneratedCertSuffix )
606
609
}
607
610
611
+ agentCertHash := enterprisepem .ReadHashFromSecret (ctx , r .SecretClient , mdb .Namespace , agentCertSecretName , "" , log )
612
+ secretKeySelector := corev1.SecretKeySelector {
613
+ LocalObjectReference : corev1.LocalObjectReference {Name : agentCertSecretName },
614
+ Key : agentCertHash ,
615
+ }
608
616
userOpts , err := r .readAgentSubjectsFromSecret (ctx , mdb .Namespace , secretKeySelector , log )
609
617
err = client .IgnoreNotFound (err )
610
618
if err != nil {
@@ -631,7 +639,7 @@ func (r *ReconcileCommonController) ensureX509SecretAndCheckTLSType(ctx context.
631
639
if ! security .IsTLSEnabled () {
632
640
return workflow .Failed (xerrors .Errorf ("Authentication mode for project is x509 but this MDB resource is not TLS enabled" ))
633
641
}
634
- agentSecretName := security .AgentClientCertificateSecretName (configurator .GetName ()). Name
642
+ agentSecretName := security .AgentClientCertificateSecretName (configurator .GetName ())
635
643
err := certs .VerifyAndEnsureClientCertificatesForAgentsAndTLSType (ctx , configurator .GetSecretReadClient (), configurator .GetSecretWriteClient (), kube .ObjectKey (configurator .GetNamespace (), agentSecretName ), log )
636
644
if err != nil {
637
645
return workflow .Failed (err )
0 commit comments