Skip to content

Commit 499e740

Browse files
committed
Add agent cert hash annotation to the STS
1 parent cc73fde commit 499e740

6 files changed

+21
-0
lines changed

controllers/operator/construct/database_construction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type DatabaseStatefulSetOptions struct {
9595
PodVars *env.PodEnvVars
9696
CurrentAgentAuthMode string
9797
CertificateHash string
98+
AgentCertificateHash string
9899
PrometheusTLSCertHash string
99100
InternalClusterHash string
100101
ServicePort int32

controllers/operator/database_statefulset_options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func CertificateHash(hash string) func(options *construct.DatabaseStatefulSetOpt
5454
}
5555
}
5656

57+
// AgentCertificateHash will assign the given AgentCertificateHash during StatefulSet construction.
58+
func AgentCertificateHash(hash string) func(options *construct.DatabaseStatefulSetOptions) {
59+
return func(options *construct.DatabaseStatefulSetOptions) {
60+
options.AgentCertificateHash = hash
61+
}
62+
}
63+
5764
// InternalClusterHash will assign the given InternalClusterHash during StatefulSet construction.
5865
func InternalClusterHash(hash string) func(options *construct.DatabaseStatefulSetOptions) {
5966
return func(options *construct.DatabaseStatefulSetOptions) {

controllers/operator/mongodbmultireplicaset_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,11 @@ func (r *ReconcileMongoDbMultiReplicaSet) reconcileStatefulSets(ctx context.Cont
493493
return workflow.Failed(err)
494494
}
495495

496+
agentCertSecretName := mrs.GetSecurity().AgentClientCertificateSecretName(mrs.Name).Name
497+
496498
// get cert hash of tls secret if it exists
497499
certHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, mrsConfig.CertSecretName, "", log)
500+
agentCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, agentCertSecretName, "", log)
498501
internalCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, mrsConfig.InternalClusterSecretName, "", log)
499502
log.Debugf("Creating StatefulSet %s with %d replicas in cluster: %s", mrs.MultiStatefulsetName(clusterNum), replicasThisReconciliation, item.ClusterName)
500503

@@ -524,6 +527,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) reconcileStatefulSets(ctx context.Cont
524527
PodEnvVars(newPodVars(conn, projectConfig, mrs.Spec.LogLevel)),
525528
CurrentAgentAuthMechanism(currentAgentAuthMode),
526529
CertificateHash(certHash),
530+
AgentCertificateHash(agentCertHash),
527531
InternalClusterHash(internalCertHash),
528532
WithLabels(mrs.GetOwnerLabels()),
529533
WithAdditionalMongodConfig(mrs.Spec.GetAdditionalMongodConfig()),

controllers/operator/mongodbreplicaset_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,15 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
200200

201201
tlsCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, rs.Namespace, rsCertsConfig.CertSecretName, databaseSecretPath, log)
202202
internalClusterCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, rs.Namespace, rsCertsConfig.InternalClusterSecretName, databaseSecretPath, log)
203+
agentCertSecretName := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name).Name
204+
agentCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, rs.Namespace, agentCertSecretName, databaseSecretPath, log)
203205

204206
rsConfig := construct.ReplicaSetOptions(
205207
PodEnvVars(newPodVars(conn, projectConfig, rs.Spec.LogLevel)),
206208
CurrentAgentAuthMechanism(currentAgentAuthMode),
207209
CertificateHash(tlsCertHash),
208210
InternalClusterHash(internalClusterCertHash),
211+
AgentCertificateHash(agentCertHash),
209212
PrometheusTLSCertHash(prometheusCertHash),
210213
WithVaultConfig(vaultConfig),
211214
WithLabels(rs.Labels),

controllers/operator/mongodbshardedcluster_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ func (r *ShardedClusterReconcileHelper) getConfigServerOptions(ctx context.Conte
22802280
PodEnvVars(opts.podEnvVars),
22812281
CurrentAgentAuthMechanism(opts.currentAgentAuthMode),
22822282
CertificateHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, certSecretName, databaseSecretPath, log)),
2283+
AgentCertificateHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, opts.agentCertSecretName, databaseSecretPath, log)),
22832284
InternalClusterHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, internalClusterSecretName, databaseSecretPath, log)),
22842285
PrometheusTLSCertHash(opts.prometheusCertHash),
22852286
WithVaultConfig(vaultConfig),
@@ -2311,6 +2312,7 @@ func (r *ShardedClusterReconcileHelper) getMongosOptions(ctx context.Context, sc
23112312
PodEnvVars(opts.podEnvVars),
23122313
CurrentAgentAuthMechanism(opts.currentAgentAuthMode),
23132314
CertificateHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, certSecretName, vaultConfig.DatabaseSecretPath, log)),
2315+
AgentCertificateHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, opts.agentCertSecretName, vaultConfig.DatabaseSecretPath, log)),
23142316
InternalClusterHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, internalClusterSecretName, vaultConfig.DatabaseSecretPath, log)),
23152317
PrometheusTLSCertHash(opts.prometheusCertHash),
23162318
WithVaultConfig(vaultConfig),
@@ -2341,6 +2343,7 @@ func (r *ShardedClusterReconcileHelper) getShardOptions(ctx context.Context, sc
23412343
PodEnvVars(opts.podEnvVars),
23422344
CurrentAgentAuthMechanism(opts.currentAgentAuthMode),
23432345
CertificateHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, certSecretName, databaseSecretPath, log)),
2346+
AgentCertificateHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, opts.agentCertSecretName, databaseSecretPath, log)),
23442347
InternalClusterHash(enterprisepem.ReadHashFromSecret(ctx, r.commonController.SecretClient, sc.Namespace, internalClusterSecretName, databaseSecretPath, log)),
23452348
PrometheusTLSCertHash(opts.prometheusCertHash),
23462349
WithVaultConfig(vaultConfig),

controllers/operator/mongodbstandalone_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,11 @@ func (r *ReconcileMongoDbStandalone) Reconcile(ctx context.Context, request reco
243243
}
244244
}
245245

246+
agentCertSecretName := s.GetSecurity().AgentClientCertificateSecretName(s.Name).Name
247+
246248
standaloneOpts := construct.StandaloneOptions(
247249
CertificateHash(pem.ReadHashFromSecret(ctx, r.SecretClient, s.Namespace, standaloneCertSecretName, databaseSecretPath, log)),
250+
AgentCertificateHash(pem.ReadHashFromSecret(ctx, r.SecretClient, s.Namespace, agentCertSecretName, databaseSecretPath, log)),
248251
CurrentAgentAuthMechanism(currentAgentAuthMode),
249252
PodEnvVars(podVars),
250253
WithVaultConfig(vaultConfig),

0 commit comments

Comments
 (0)