Skip to content

Commit 747293b

Browse files
lmicciniclaude
andcommitted
Add mTLS client cert creation for Redis
Create a cert-manager Certificate with ClientAuth usage when Redis mTLS is configured (SslVerifyMode Request or Require), following the same pattern as Memcached mTLS in memcached.go. The client cert secret (cert-<name>-mtls) is wired into redis.Spec.TLS.MTLS.AuthCertSecret.SecretName so the infra-operator mounts it into the Redis pods and configures tls-auth-clients accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 785148b commit 747293b

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

‎internal/openstack/redis.go‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func reconcileRedis(
213213
helper.GetLogger().Info("Reconciling Redis", "Redis.Namespace", instance.Namespace, "Redis.Name", name)
214214

215215
tlsCert := ""
216+
mtlsCert := ""
216217
if instance.Spec.TLS.PodLevel.Enabled {
217218
clusterDomain := clusterdns.GetDNSClusterDomain()
218219
certRequest := certmanager.CertificateRequest{
@@ -253,6 +254,43 @@ func reconcileRedis(
253254
}
254255

255256
tlsCert = certSecret.Name
257+
258+
// mTLS client cert
259+
if spec.TLS.MTLS.SslVerifyMode == "Request" || spec.TLS.MTLS.SslVerifyMode == "Require" {
260+
helper.GetLogger().Info("Reconciling Redis mTLS", "Redis.Namespace", instance.Namespace, "Redis.Name", name)
261+
certRequest = certmanager.CertificateRequest{
262+
IssuerName: instance.GetInternalIssuer(),
263+
CertName: fmt.Sprintf("%s-mtls", redis.Name),
264+
Hostnames: []string{
265+
fmt.Sprintf("*.%s.svc", instance.Namespace),
266+
fmt.Sprintf("*.%s.svc.%s", instance.Namespace, clusterDomain),
267+
},
268+
Usages: []certmgrv1.KeyUsage{
269+
certmgrv1.UsageKeyEncipherment,
270+
certmgrv1.UsageDigitalSignature,
271+
certmgrv1.UsageClientAuth,
272+
},
273+
Labels: map[string]string{ServiceCertSelector: ""},
274+
}
275+
if instance.Spec.TLS.PodLevel.Internal.Cert.Duration != nil {
276+
certRequest.Duration = &instance.Spec.TLS.PodLevel.Internal.Cert.Duration.Duration
277+
}
278+
if instance.Spec.TLS.PodLevel.Internal.Cert.RenewBefore != nil {
279+
certRequest.RenewBefore = &instance.Spec.TLS.PodLevel.Internal.Cert.RenewBefore.Duration
280+
}
281+
certSecret, ctrlResult, err = certmanager.EnsureCert(
282+
ctx,
283+
helper,
284+
certRequest,
285+
nil)
286+
if err != nil {
287+
return redisFailed, redis, ctrlResult, err
288+
} else if (ctrlResult != ctrl.Result{}) {
289+
return redisCreating, redis, ctrlResult, nil
290+
}
291+
292+
mtlsCert = certSecret.Name
293+
}
256294
}
257295

258296
if spec.NodeSelector == nil {
@@ -270,9 +308,11 @@ func reconcileRedis(
270308
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), redis, func() error {
271309
spec.DeepCopyInto(&redis.Spec.RedisSpecCore)
272310
if tlsCert != "" {
273-
274311
redis.Spec.TLS.SecretName = ptr.To(tlsCert)
275312
}
313+
if mtlsCert != "" {
314+
redis.Spec.TLS.MTLS.AuthCertSecret.SecretName = ptr.To(mtlsCert)
315+
}
276316
redis.Spec.TLS.CaBundleSecretName = tls.CABundleSecret
277317

278318
redis.Spec.ContainerImage = *version.Status.ContainerImages.InfraRedisImage

0 commit comments

Comments
 (0)