Skip to content

Commit 766d03d

Browse files
authored
Merge pull request #1747 from rabbitmq/fix/cluster-operator-1616
Fix CA certs overriding server certs
2 parents 4ad3a5f + 77d8bf2 commit 766d03d

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

api/v1beta1/rabbitmqcluster_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ type PersistentVolumeClaim struct {
350350
Spec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
351351
}
352352

353-
// Allows for the configuration of TLS certificates to be used by RabbitMQ. Also allows for non-TLS traffic to be disabled.
353+
// TLSSpec allows for the configuration of TLS certificates to be used by RabbitMQ. Also allows for non-TLS traffic to be disabled.
354354
type TLSSpec struct {
355355
// Name of a Secret in the same Namespace as the RabbitmqCluster, containing the server's private key & public certificate for TLS.
356356
// The Secret must store these as tls.key and tls.crt, respectively.
357-
// This Secret can be created by running `kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key`
357+
// This Secret can be created by running `kubectl create secret tls tls-secret --cert=path/to/tls.crt --key=path/to/tls.key`
358358
SecretName string `json:"secretName,omitempty"`
359359
// Name of a Secret in the same Namespace as the RabbitmqCluster, containing the Certificate Authority's public certificate for TLS.
360360
// The Secret must store this as ca.crt.
361-
// This Secret can be created by running `kubectl create secret generic ca-secret --from-file=ca.crt=path/to/ca.cert`
361+
// This Secret can be created by running `kubectl create secret generic ca-secret --from-file=ca.crt=path/to/ca.crt`
362362
// Used for mTLS, and TLS for rabbitmq_web_stomp and rabbitmq_web_mqtt.
363363
CaSecretName string `json:"caSecretName,omitempty"`
364364
// When set to true, the RabbitmqCluster disables non-TLS listeners for RabbitMQ, management plugin and for any enabled plugins in the following list: stomp, mqtt, web_stomp, web_mqtt.

controllers/reconcile_tls.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (r *RabbitmqClusterReconciler) checkTLSSecrets(ctx context.Context, rabbitm
6060

6161
// Mutual TLS: check if CA certificate is stored in a separate secret
6262
if rabbitmqCluster.MutualTLSEnabled() {
63+
// This is an optimisation to avoid reading the same secret twice
6364
if !rabbitmqCluster.SingleTLSSecret() {
6465
secretName := rabbitmqCluster.Spec.TLS.CaSecretName
6566
logger.V(1).Info("mutual TLS enabled, looking for CA certificate secret", "secret", secretName)

controllers/reconcile_tls_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ var _ = Describe("Reconcile TLS", func() {
5858
Name: "tls-secret",
5959
},
6060
Optional: ptr.To(true),
61+
Items: []corev1.KeyToPath{
62+
{Key: "tls.crt", Path: "tls.crt"},
63+
{Key: "tls.key", Path: "tls.key"},
64+
},
65+
},
66+
},
67+
{
68+
Secret: &corev1.SecretProjection{
69+
LocalObjectReference: corev1.LocalObjectReference{
70+
Name: "tls-secret",
71+
},
72+
Optional: ptr.To(true),
73+
Items: []corev1.KeyToPath{{Key: "ca.crt", Path: "ca.crt"}},
6174
},
6275
},
6376
},

docs/api/rabbitmq.com.ref.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ created from the StatefulSet VolumeClaimTemplates.
539539
[id="{anchor_prefix}-github-com-rabbitmq-cluster-operator-v2-api-v1beta1-tlsspec"]
540540
==== TLSSpec
541541

542-
Allows for the configuration of TLS certificates to be used by RabbitMQ. Also allows for non-TLS traffic to be disabled.
542+
TLSSpec allows for the configuration of TLS certificates to be used by RabbitMQ. Also allows for non-TLS traffic to be disabled.
543543

544544
.Appears In:
545545
****
@@ -551,10 +551,10 @@ Allows for the configuration of TLS certificates to be used by RabbitMQ. Also al
551551
| Field | Description
552552
| *`secretName`* __string__ | Name of a Secret in the same Namespace as the RabbitmqCluster, containing the server's private key & public certificate for TLS.
553553
The Secret must store these as tls.key and tls.crt, respectively.
554-
This Secret can be created by running `kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key`
554+
This Secret can be created by running `kubectl create secret tls tls-secret --cert=path/to/tls.crt --key=path/to/tls.key`
555555
| *`caSecretName`* __string__ | Name of a Secret in the same Namespace as the RabbitmqCluster, containing the Certificate Authority's public certificate for TLS.
556556
The Secret must store this as ca.crt.
557-
This Secret can be created by running `kubectl create secret generic ca-secret --from-file=ca.crt=path/to/ca.cert`
557+
This Secret can be created by running `kubectl create secret generic ca-secret --from-file=ca.crt=path/to/ca.crt`
558558
Used for mTLS, and TLS for rabbitmq_web_stomp and rabbitmq_web_mqtt.
559559
| *`disableNonTLSListeners`* __boolean__ | When set to true, the RabbitmqCluster disables non-TLS listeners for RabbitMQ, management plugin and for any enabled plugins in the following list: stomp, mqtt, web_stomp, web_mqtt.
560560
Only TLS-enabled clients will be able to connect.

internal/resource/statefulset.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ func (builder *StatefulSetBuilder) podTemplateSpec(previousPodAnnotations map[st
523523
Name: tlsSpec.SecretName,
524524
},
525525
Optional: &secretEnforced,
526+
Items: []corev1.KeyToPath{
527+
{Key: "tls.crt", Path: "tls.crt"},
528+
{Key: "tls.key", Path: "tls.key"},
529+
},
526530
},
527531
},
528532
},
@@ -531,11 +535,14 @@ func (builder *StatefulSetBuilder) podTemplateSpec(previousPodAnnotations map[st
531535
},
532536
}
533537

534-
if builder.Instance.MutualTLSEnabled() && !builder.Instance.SingleTLSSecret() {
538+
if builder.Instance.MutualTLSEnabled() {
535539
caSecretProjection := corev1.VolumeProjection{
536540
Secret: &corev1.SecretProjection{
537541
LocalObjectReference: corev1.LocalObjectReference{Name: tlsSpec.CaSecretName},
538542
Optional: &secretEnforced,
543+
Items: []corev1.KeyToPath{
544+
{Key: "ca.crt", Path: "ca.crt"},
545+
},
539546
},
540547
}
541548
tlsProjectedVolume.VolumeSource.Projected.Sources = append(tlsProjectedVolume.VolumeSource.Projected.Sources, caSecretProjection)

internal/resource/statefulset_test.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ var _ = Describe("StatefulSet", func() {
530530
Name: "tls-secret",
531531
},
532532
Optional: ptr.To(true),
533+
Items: []corev1.KeyToPath{
534+
{Key: "tls.crt", Path: "tls.crt"},
535+
{Key: "tls.key", Path: "tls.key"},
536+
},
533537
},
534538
},
535539
},
@@ -621,28 +625,6 @@ var _ = Describe("StatefulSet", func() {
621625
}))
622626
})
623627

624-
When("Mutual TLS (same secret) is enabled", func() {
625-
It("opens tls ports when rabbitmq_web_mqtt and rabbitmq_web_stomp are configured", func() {
626-
instance.Spec.TLS.SecretName = "tls-secret"
627-
instance.Spec.TLS.CaSecretName = "tls-secret"
628-
instance.Spec.Rabbitmq.AdditionalPlugins = []rabbitmqv1beta1.Plugin{"rabbitmq_web_mqtt", "rabbitmq_web_stomp"}
629-
Expect(stsBuilder.Update(statefulSet)).To(Succeed())
630-
631-
rabbitmqContainerSpec := extractContainer(statefulSet.Spec.Template.Spec.Containers, "rabbitmq")
632-
633-
Expect(rabbitmqContainerSpec.Ports).To(ContainElements([]corev1.ContainerPort{
634-
{
635-
Name: "web-mqtt-tls",
636-
ContainerPort: 15676,
637-
},
638-
{
639-
Name: "web-stomp-tls",
640-
ContainerPort: 15673,
641-
},
642-
}))
643-
})
644-
})
645-
646628
When("Mutual TLS (different secret) is enabled", func() {
647629
It("adds the CA cert secret to tls project volume", func() {
648630
instance.Spec.TLS.SecretName = "tls-secret"
@@ -660,6 +642,10 @@ var _ = Describe("StatefulSet", func() {
660642
Name: "tls-secret",
661643
},
662644
Optional: ptr.To(true),
645+
Items: []corev1.KeyToPath{
646+
{Key: "tls.crt", Path: "tls.crt"},
647+
{Key: "tls.key", Path: "tls.key"},
648+
},
663649
},
664650
},
665651
{
@@ -668,6 +654,9 @@ var _ = Describe("StatefulSet", func() {
668654
Name: "mutual-tls-secret",
669655
},
670656
Optional: ptr.To(true),
657+
Items: []corev1.KeyToPath{
658+
{Key: "ca.crt", Path: "ca.crt"},
659+
},
671660
},
672661
},
673662
},

0 commit comments

Comments
 (0)