-
Notifications
You must be signed in to change notification settings - Fork 17
CLOUDP-290847: Remove cert hash annotations #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,12 +171,32 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request | |
return r.updateStatus(ctx, &mrs, workflow.Failed(err), log) | ||
} | ||
|
||
// If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the | ||
// correct tlsCertPath, with the new tls design, this path has the certHash in it(so that cert can be rotated | ||
// without pod restart). | ||
tlsCertPath := "" | ||
internalClusterCertPath := "" | ||
if mrs.Spec.Security.IsTLSEnabled() { | ||
certSecretName := mrs.Spec.GetSecurity().MemberCertificateSecretName(mrs.Name) | ||
internalClusterCertSecretName := mrs.Spec.GetSecurity().InternalClusterAuthSecretName(mrs.Name) | ||
tlsCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, certSecretName, "", log) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that func (r *ReconcileCommonController) tlsCertHashAndPath(ctx, ...) (string, string) {
tlsCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, certSecretName, "", log)
if tlsCertHash == "" {
return "", ""
}
return tlsCertHash, fmt.Sprintf("%s/%s", util.TLSCertMountPath, tlsCertHash)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to leave this out of the scope of this PR. Here I want to make a minimal change so that I can progress with my main goal (agent cert rotation). There are more places where we read the secret and calculate the hash and I have a feeling that after adding agent cert rotation it will be a bit more clear if there is a pattern which we can abstract somehow. I'll look into this if I have time left after implementing agent cert rotation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understand. In that case can you add TODO item for improving this later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a to do in another branch (I'll eventually push the to do or a change to #389). Don't want to push to this branch and wait for CI again. |
||
internalClusterCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, internalClusterCertSecretName, "", log) | ||
|
||
if internalClusterCertHash != "" { | ||
internalClusterCertPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, internalClusterCertHash) | ||
} | ||
|
||
if tlsCertHash != "" { | ||
tlsCertPath = fmt.Sprintf("%s/%s", util.TLSCertMountPath, tlsCertHash) | ||
} | ||
} | ||
|
||
// Recovery prevents some deadlocks that can occur during reconciliation, e.g. the setting of an incorrect automation | ||
// configuration and a subsequent attempt to overwrite it later, the operator would be stuck in Pending phase. | ||
// See CLOUDP-189433 and CLOUDP-229222 for more details. | ||
if recovery.ShouldTriggerRecovery(mrs.Status.Phase != mdbstatus.PhaseRunning, mrs.Status.LastTransition) { | ||
log.Warnf("Triggering Automatic Recovery. The MongoDB resource %s/%s is in %s state since %s", mrs.Namespace, mrs.Name, mrs.Status.Phase, mrs.Status.LastTransition) | ||
automationConfigError := r.updateOmDeploymentRs(ctx, conn, mrs, true, log) | ||
automationConfigError := r.updateOmDeploymentRs(ctx, conn, mrs, tlsCertPath, internalClusterCertPath, true, log) | ||
reconcileStatus := r.reconcileMemberResources(ctx, &mrs, log, conn, projectConfig) | ||
if !reconcileStatus.IsOK() { | ||
log.Errorf("Recovery failed because of reconcile errors, %v", reconcileStatus) | ||
|
@@ -188,7 +208,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request | |
|
||
status := workflow.RunInGivenOrder(publishAutomationConfigFirst, | ||
func() workflow.Status { | ||
if err := r.updateOmDeploymentRs(ctx, conn, mrs, false, log); err != nil { | ||
if err := r.updateOmDeploymentRs(ctx, conn, mrs, tlsCertPath, internalClusterCertPath, false, log); err != nil { | ||
return workflow.Failed(err) | ||
} | ||
return workflow.OK() | ||
|
@@ -499,7 +519,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) reconcileStatefulSets(ctx context.Cont | |
mconstruct.WithClusterNum(clusterNum), | ||
Replicas(replicasThisReconciliation), | ||
mconstruct.WithStsOverride(&stsOverride), | ||
mconstruct.WithAnnotations(mrs.Name, certHash), | ||
mconstruct.WithAnnotations(mrs.Name), | ||
mconstruct.WithServiceName(mrs.MultiHeadlessServiceName(clusterNum)), | ||
PodEnvVars(newPodVars(conn, projectConfig, mrs.Spec.LogLevel)), | ||
CurrentAgentAuthMechanism(currentAgentAuthMode), | ||
|
@@ -677,7 +697,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Conte | |
|
||
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated | ||
// to automation agents in containers | ||
func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Context, conn om.Connection, mrs mdbmultiv1.MongoDBMultiCluster, isRecovering bool, log *zap.SugaredLogger) error { | ||
func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Context, conn om.Connection, mrs mdbmultiv1.MongoDBMultiCluster, tlsCertPath, internalClusterCertPath string, isRecovering bool, log *zap.SugaredLogger) error { | ||
reachableHostnames := make([]string, 0) | ||
|
||
clusterSpecList, err := mrs.GetClusterSpecItems() | ||
|
@@ -725,28 +745,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |
} | ||
log.Debugf("Existing process Ids: %+v", processIds) | ||
|
||
certificateFileName := "" | ||
internalClusterPath := "" | ||
|
||
// If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the | ||
// correct certFilePath, with the new tls design, this path has the certHash in it(so that cert can be rotated | ||
// without pod restart), we can get the cert hash from any of the statefulset, here we pick the statefulset in the first cluster. | ||
if mrs.Spec.Security.IsTLSEnabled() { | ||
firstStatefulSet, err := r.firstStatefulSet(ctx, &mrs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if hash := firstStatefulSet.Annotations[util.InternalCertAnnotationKey]; hash != "" { | ||
internalClusterPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, hash) | ||
} | ||
|
||
if certificateHash := firstStatefulSet.Annotations[certs.CertHashAnnotationKey]; certificateHash != "" { | ||
certificateFileName = fmt.Sprintf("%s/%s", util.TLSCertMountPath, certificateHash) | ||
} | ||
} | ||
|
||
processes, err := process.CreateMongodProcessesWithLimitMulti(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, mrs, certificateFileName) | ||
processes, err := process.CreateMongodProcessesWithLimitMulti(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, mrs, tlsCertPath) | ||
if err != nil && !isRecovering { | ||
return err | ||
} | ||
|
@@ -759,7 +758,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |
caFilePath := fmt.Sprintf("%s/ca-pem", util.TLSCaMountPath) | ||
|
||
agentCertSecretName := mrs.GetSecurity().AgentClientCertificateSecretName(mrs.GetName()) | ||
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, rs.GetProcessNames(), &mrs, agentCertSecretName, caFilePath, internalClusterPath, isRecovering, log) | ||
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, rs.GetProcessNames(), &mrs, agentCertSecretName, caFilePath, internalClusterCertPath, isRecovering, log) | ||
if !status.IsOK() && !isRecovering { | ||
return xerrors.Errorf("failed to enable Authentication for MongoDB Multi Replicaset") | ||
} | ||
|
@@ -768,7 +767,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |
|
||
err = conn.ReadUpdateDeployment( | ||
func(d om.Deployment) error { | ||
return ReconcileReplicaSetAC(ctx, d, mrs.Spec.DbCommonSpec, lastMongodbConfig, mrs.Name, rs, caFilePath, internalClusterPath, nil, log) | ||
return ReconcileReplicaSetAC(ctx, d, mrs.Spec.DbCommonSpec, lastMongodbConfig, mrs.Name, rs, caFilePath, internalClusterCertPath, nil, log) | ||
}, | ||
log, | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.