fix(k8s/ns): validate ingress ctrl host pattern (#5662)

* fix(k8s/ns): validate ingress ctrl host pattern

* feat(kube/ns): validate ingress hostname
pull/5782/head
Chaim Lev-Ari 2021-09-24 14:02:10 +03:00 committed by GitHub
parent d14c7b0309
commit 9c279e7fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -269,6 +269,7 @@
ng-model="item.Host" ng-model="item.Host"
ng-change="$ctrl.onChangeIngressHostname()" ng-change="$ctrl.onChangeIngressHostname()"
placeholder="foo" placeholder="foo"
pattern="[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*"
required required
/> />
</div> </div>
@ -288,6 +289,10 @@
> >
<ng-messages for="resourcePoolCreationForm['hostname_' + ic.IngressClass.Name + '_' + $index].$error"> <ng-messages for="resourcePoolCreationForm['hostname_' + ic.IngressClass.Name + '_' + $index].$error">
<p ng-message="required"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Hostname is required.</p> <p ng-message="required"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Hostname is required.</p>
<p ng-message="pattern">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
This field must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com').
</p>
</ng-messages> </ng-messages>
<p ng-if="$ctrl.state.duplicates.ingressHosts.refs[ic.IngressClass.Name][$index] !== undefined"> <p ng-if="$ctrl.state.duplicates.ingressHosts.refs[ic.IngressClass.Name][$index] !== undefined">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> This hostname is already used. <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> This hostname is already used.

View File

@ -34,7 +34,7 @@ class KubernetesCreateResourcePoolController {
onChangeIngressHostname() { onChangeIngressHostname() {
const state = this.state.duplicates.ingressHosts; const state = this.state.duplicates.ingressHosts;
const hosts = _.flatMap(this.formValues.IngressClasses, 'Hosts'); 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 hostnamesWithoutRemoved = _.filter(hostnames, (h) => !h.NeedsDeletion);
const allHosts = _.flatMap(this.allIngresses, 'Hosts'); const allHosts = _.flatMap(this.allIngresses, 'Hosts');
const formDuplicates = KubernetesFormValidationHelper.getDuplicates(hostnamesWithoutRemoved); const formDuplicates = KubernetesFormValidationHelper.getDuplicates(hostnamesWithoutRemoved);

View File

@ -221,6 +221,7 @@
ng-model="item.Host" ng-model="item.Host"
ng-change="ctrl.onChangeIngressHostname()" ng-change="ctrl.onChangeIngressHostname()"
placeholder="foo" placeholder="foo"
pattern="[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*"
required required
/> />
</div> </div>
@ -240,6 +241,11 @@
> >
<ng-messages for="resourcePoolEditForm['hostname_' + ic.IngressClass.Name + '_' + $index].$error"> <ng-messages for="resourcePoolEditForm['hostname_' + ic.IngressClass.Name + '_' + $index].$error">
<p ng-message="required"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Hostname is required.</p> <p ng-message="required"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Hostname is required.</p>
<p ng-message="pattern">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
This field must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g.
'example.com').
</p>
</ng-messages> </ng-messages>
<p ng-if="item.Duplicate"> <p ng-if="item.Duplicate">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>