Skip to content
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

fix: validating certificate subject alternative names #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions controllers/kamajicontrolplane_controller_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package controllers
import (
"context"
"fmt"
"net"
"strings"

kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
Expand All @@ -20,6 +21,8 @@ import (
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/externalclusterreference"
)

var ErrUnsupportedCertificateSAN = errors.New("a certificate SAN must be made of host only with no port")

//+kubebuilder:rbac:groups=kamaji.clastix.io,resources=tenantcontrolplanes,verbs=get;list;watch;create;update

//nolint:funlen,gocognit,cyclop
Expand Down Expand Up @@ -141,6 +144,15 @@ func (r *KamajiControlPlaneReconciler) createOrUpdateTenantControlPlane(ctx cont
tcp.Spec.ControlPlane.Service.ServiceType = kcp.Spec.Network.ServiceType
tcp.Spec.ControlPlane.Service.AdditionalMetadata.Labels = kcp.Spec.Network.ServiceLabels
tcp.Spec.ControlPlane.Service.AdditionalMetadata.Annotations = kcp.Spec.Network.ServiceAnnotations

for _, i := range kcp.Spec.Network.CertSANs {
// validating CertSANs as soon as possible to avoid github.com/clastix/kamaji/issues/679:
// nil err means the entry is in the form of <HOST>:<PORT> which is not accepted
if _, _, err := net.SplitHostPort(i); err == nil {
return errors.Wrap(ErrUnsupportedCertificateSAN, fmt.Sprintf("entry %s is invalid", i))
}
}

tcp.Spec.NetworkProfile.CertSANs = kcp.Spec.Network.CertSANs
// Ingress
if kcp.Spec.Network.Ingress != nil {
Expand Down
Loading