Skip to content

Commit b869d5d

Browse files
authored
Safeguard and against empty and invalid GW class names (#13081)
Signed-off-by: Yossi Mesika <[email protected]>
1 parent c70ad34 commit b869d5d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/kgateway/controller/gatewayclass.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"istio.io/istio/pkg/kube/controllers"
1313
"istio.io/istio/pkg/kube/kclient"
1414
"k8s.io/apimachinery/pkg/api/meta"
15+
apivalidation "k8s.io/apimachinery/pkg/api/validation"
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617
"k8s.io/apimachinery/pkg/types"
1718
"k8s.io/apimachinery/pkg/util/sets"
@@ -150,6 +151,11 @@ func (r *gatewayClassReconciler) reconcile(req types.NamespacedName) (rErr error
150151
func (r *gatewayClassReconciler) reconcileGatewayClasses() error {
151152
var errs []error
152153
for name, info := range r.classInfo {
154+
// Validate the GatewayClass name using Kubernetes object name validation
155+
if validationErrs := apivalidation.NameIsDNSSubdomain(name, false); len(validationErrs) > 0 {
156+
errs = append(errs, fmt.Errorf("invalid GatewayClass name %q: %v", name, validationErrs))
157+
continue
158+
}
153159
if err := r.reconcileGatewayClass(name, info); err != nil {
154160
errs = append(errs, err)
155161
}

pkg/kgateway/controller/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ func GetDefaultClassInfo(
402402
}
403403
applyGatewayClassParametersRef(classInfos[gatewayClassName], gatewayClassName, refOverrides, false)
404404
}
405-
// Only enable waypoint gateway class if it's enabled in the settings
406-
if globalSettings.EnableWaypoint {
405+
// Only enable waypoint gateway class if it's enabled in the settings and the name isn't empty
406+
if globalSettings.EnableWaypoint && waypointGatewayClassName != "" {
407407
classInfos[waypointGatewayClassName] = &deployer.GatewayClassInfo{
408408
Description: "Specialized class for Istio ambient mesh waypoint proxies.",
409409
Labels: map[string]string{},

0 commit comments

Comments
 (0)