From 9c279e7fae0e1f72d46bde3d6cc88ac4e95b5993 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Fri, 24 Sep 2021 14:02:10 +0300 Subject: [PATCH] fix(k8s/ns): validate ingress ctrl host pattern (#5662) * fix(k8s/ns): validate ingress ctrl host pattern * feat(kube/ns): validate ingress hostname --- .../views/resource-pools/create/createResourcePool.html | 5 +++++ .../resource-pools/create/createResourcePoolController.js | 2 +- app/kubernetes/views/resource-pools/edit/resourcePool.html | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/kubernetes/views/resource-pools/create/createResourcePool.html b/app/kubernetes/views/resource-pools/create/createResourcePool.html index 8529a0395..611c2bc45 100644 --- a/app/kubernetes/views/resource-pools/create/createResourcePool.html +++ b/app/kubernetes/views/resource-pools/create/createResourcePool.html @@ -269,6 +269,7 @@ ng-model="item.Host" ng-change="$ctrl.onChangeIngressHostname()" placeholder="foo" + pattern="[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*" required /> @@ -288,6 +289,10 @@ >

Hostname is required.

+

+ + This field must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com'). +

This hostname is already used. diff --git a/app/kubernetes/views/resource-pools/create/createResourcePoolController.js b/app/kubernetes/views/resource-pools/create/createResourcePoolController.js index 5cdc8accc..92149f4f9 100644 --- a/app/kubernetes/views/resource-pools/create/createResourcePoolController.js +++ b/app/kubernetes/views/resource-pools/create/createResourcePoolController.js @@ -34,7 +34,7 @@ class KubernetesCreateResourcePoolController { onChangeIngressHostname() { const state = this.state.duplicates.ingressHosts; const hosts = _.flatMap(this.formValues.IngressClasses, 'Hosts'); - const hostnames = _.map(hosts, 'Host'); + const hostnames = _.compact(hosts.map((h) => h.Host)); const hostnamesWithoutRemoved = _.filter(hostnames, (h) => !h.NeedsDeletion); const allHosts = _.flatMap(this.allIngresses, 'Hosts'); const formDuplicates = KubernetesFormValidationHelper.getDuplicates(hostnamesWithoutRemoved); diff --git a/app/kubernetes/views/resource-pools/edit/resourcePool.html b/app/kubernetes/views/resource-pools/edit/resourcePool.html index 29d39b3a4..d847527e0 100644 --- a/app/kubernetes/views/resource-pools/edit/resourcePool.html +++ b/app/kubernetes/views/resource-pools/edit/resourcePool.html @@ -221,6 +221,7 @@ ng-model="item.Host" ng-change="ctrl.onChangeIngressHostname()" placeholder="foo" + pattern="[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*" required /> @@ -240,6 +241,11 @@ >

Hostname is required.

+

+ + This field must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. + 'example.com'). +