@@ -6,6 +6,7 @@ package controllers
6
6
import (
7
7
"context"
8
8
"fmt"
9
+ "net"
9
10
"strings"
10
11
11
12
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
@@ -20,6 +21,8 @@ import (
20
21
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/externalclusterreference"
21
22
)
22
23
24
+ var ErrUnsupportedCertificateSAN = errors .New ("a certificate SAN must be made of host only with no port" )
25
+
23
26
//+kubebuilder:rbac:groups=kamaji.clastix.io,resources=tenantcontrolplanes,verbs=get;list;watch;create;update
24
27
25
28
//nolint:funlen,gocognit,cyclop
@@ -141,6 +144,15 @@ func (r *KamajiControlPlaneReconciler) createOrUpdateTenantControlPlane(ctx cont
141
144
tcp .Spec .ControlPlane .Service .ServiceType = kcp .Spec .Network .ServiceType
142
145
tcp .Spec .ControlPlane .Service .AdditionalMetadata .Labels = kcp .Spec .Network .ServiceLabels
143
146
tcp .Spec .ControlPlane .Service .AdditionalMetadata .Annotations = kcp .Spec .Network .ServiceAnnotations
147
+
148
+ for _ , i := range kcp .Spec .Network .CertSANs {
149
+ // validating CertSANs as soon as possible to avoid github.com/clastix/kamaji/issues/679:
150
+ // nil err means the entry is in the form of <HOST>:<PORT> which is not accepted
151
+ if _ , _ , err := net .SplitHostPort (i ); err == nil {
152
+ return errors .Wrap (ErrUnsupportedCertificateSAN , fmt .Sprintf ("entry %s is invalid" , i ))
153
+ }
154
+ }
155
+
144
156
tcp .Spec .NetworkProfile .CertSANs = kcp .Spec .Network .CertSANs
145
157
// Ingress
146
158
if kcp .Spec .Network .Ingress != nil {
0 commit comments