Skip to content

Commit 528d9fa

Browse files
Merge pull request #678 from stuggi/tlse_galera
[tlse] enable galera tls for internal TLS
2 parents 9929981 + 24c5040 commit 528d9fa

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/openstack/galera.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import (
55
"fmt"
66
"strings"
77

8+
certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
9+
"github.com/openstack-k8s-operators/lib-common/modules/certmanager"
810
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
911
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
12+
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
13+
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
1014
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
1115

1216
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1317

1418
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
1519
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
"k8s.io/utils/ptr"
1621
ctrl "sigs.k8s.io/controller-runtime"
1722
)
1823

@@ -38,6 +43,34 @@ func ReconcileGaleras(
3843
var inprogress []string = []string{}
3944

4045
for name, spec := range instance.Spec.Galera.Templates {
46+
hostname := fmt.Sprintf("%s.%s.svc", name, instance.Namespace)
47+
48+
// Galera gets always configured to support TLS connections.
49+
// If TLS can/must be used is a per user configuration.
50+
certRequest := certmanager.CertificateRequest{
51+
IssuerName: tls.DefaultCAPrefix + string(service.EndpointInternal),
52+
CertName: fmt.Sprintf("galera-%s-svc", name),
53+
Hostnames: []string{hostname},
54+
Usages: []certmgrv1.KeyUsage{
55+
"key encipherment",
56+
"digital signature",
57+
"server auth",
58+
"client auth",
59+
},
60+
}
61+
certSecret, ctrlResult, err := certmanager.EnsureCert(
62+
ctx,
63+
helper,
64+
certRequest)
65+
if err != nil {
66+
return ctrlResult, err
67+
} else if (ctrlResult != ctrl.Result{}) {
68+
return ctrlResult, nil
69+
}
70+
71+
spec.TLS.Ca.CaBundleSecretName = instance.Status.TLS.CaBundleSecretName
72+
spec.TLS.SecretName = ptr.To(certSecret.Name)
73+
4174
status, err := reconcileGalera(ctx, instance, helper, name, &spec)
4275

4376
switch status {
@@ -106,6 +139,7 @@ func reconcileGalera(
106139
Log.Info("Reconciling Galera", "Galera.Namespace", instance.Namespace, "Galera.Name", name)
107140
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), galera, func() error {
108141
spec.DeepCopyInto(&galera.Spec)
142+
109143
err := controllerutil.SetControllerReference(helper.GetBeforeObject(), galera, helper.GetScheme())
110144
if err != nil {
111145
return err

tests/functional/base_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ func CreateNames(openstackControlplaneName types.NamespacedName) Names {
9494
},
9595
DBCertName: types.NamespacedName{
9696
Namespace: openstackControlplaneName.Namespace,
97-
Name: "cert-openstack-svc",
97+
Name: "cert-galera-openstack-svc",
9898
},
9999
DBCell1Name: types.NamespacedName{
100100
Namespace: openstackControlplaneName.Namespace,
101101
Name: "openstack-cell1",
102102
},
103103
DBCell1CertName: types.NamespacedName{
104104
Namespace: openstackControlplaneName.Namespace,
105-
Name: "cert-openstack-cell1-svc",
105+
Name: "cert-galera-openstack-cell1-svc",
106106
},
107107
RabbitMQName: types.NamespacedName{
108108
Namespace: openstackControlplaneName.Namespace,

0 commit comments

Comments
 (0)