Skip to content

Commit eb7df4d

Browse files
authored
Add CEL validation to SE and WG (#3302)
* Add CEL validation to SE and WG * fix bad validation
1 parent 6a5c0db commit eb7df4d

16 files changed

+600
-10
lines changed

kubernetes/customresourcedefinitions.gen.yaml

Lines changed: 224 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

networking/v1/service_entry_alias.gen.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

networking/v1/workload_group_alias.gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

networking/v1alpha3/service_entry.pb.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

networking/v1alpha3/service_entry.proto

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ option go_package = "istio.io/api/networking/v1alpha3";
427427
// Clients may not set this value. It is represented in RFC3339 form and is in UTC.
428428
// Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata"
429429
// +cue-gen:ServiceEntry:preserveUnknownFields:false
430+
// +cue-gen:ServiceEntry:spec:required
430431
// -->
431432
//
432433
// <!-- go code generation tags
@@ -436,6 +437,10 @@ option go_package = "istio.io/api/networking/v1alpha3";
436437
// +k8s:deepcopy-gen=true
437438
// istiostatus-override: ServiceEntryStatus: istio.io/api/networking/v1alpha3
438439
// -->
440+
// +kubebuilder:validation:XValidation:message="only one of WorkloadSelector or Endpoints can be set",rule="(has(self.workloadSelector)?1:0)+(has(self.endpoints)?1:0)<=1"
441+
// +kubebuilder:validation:XValidation:message="CIDR addresses are allowed only for NONE/STATIC resolution types",rule="!(has(self.addresses) && self.addresses.exists(k, k.contains('/')) && (self.resolution != 'STATIC' && self.resolution != 'NONE'))"
442+
// +kubebuilder:validation:XValidation:message="NONE mode cannot set endpoints",rule="(!has(self.resolution) || self.resolution == 'NONE') ? !has(self.endpoints) : true"
443+
// +kubebuilder:validation:XValidation:message="DNS_ROUND_ROBIN mode cannot have multiple endpoints",rule="(has(self.resolution) && self.resolution == 'DNS_ROUND_ROBIN') ? (!has(self.endpoints) || size(self.endpoints) == 1) : true"
439444
message ServiceEntry {
440445
// The hosts associated with the ServiceEntry. Could be a DNS
441446
// name with wildcard prefix.
@@ -460,7 +465,9 @@ message ServiceEntry {
460465
// 1. subjectAltNames: In addition to verifying the SANs of the
461466
// service accounts associated with the pods of the service, the
462467
// SANs specified here will also be verified.
463-
//
468+
// +kubebuilder:validation:MinItems=1
469+
// +kubebuilder:validation:MaxItems=256
470+
// +protoc-gen-crd:list-value-validation:XValidation:message="hostname cannot be wildcard",rule="self != '*'"
464471
repeated string hosts = 1 [(google.api.field_behavior) = REQUIRED];
465472

466473
// The virtual IP addresses associated with the service. Could be CIDR
@@ -477,11 +484,17 @@ message ServiceEntry {
477484
// simple TCP proxy, forwarding incoming traffic on a specified port to
478485
// the specified destination endpoint IP/host. Unix domain socket
479486
// addresses are not supported in this field.
487+
// +kubebuilder:validation:MaxItems=256
488+
// +protoc-gen-crd:list-value-validation:MaxLength=64
480489
repeated string addresses = 2;
481490

482491
// The ports associated with the external service. If the
483492
// Endpoints are Unix domain socket addresses, there must be exactly one
484493
// port.
494+
// +listType=map
495+
// +listMapKey=name
496+
// +kubebuilder:validation:MaxItems=256
497+
// +kubebuilder:validation:XValidation:message="port number cannot be duplicated",rule="self.all(l1, self.exists_one(l2, l1.number == l2.number))"
485498
repeated ServicePort ports = 3;
486499

487500
// Location specifies whether the service is part of Istio mesh or
@@ -600,19 +613,23 @@ message ServiceEntry {
600613
// ServicePort describes the properties of a specific port of a service.
601614
message ServicePort {
602615
// A valid non-negative integer port number.
616+
// +kubebuilder:validation:XValidation:message="port must be between 1-65535",rule="0 < self && self <= 65535"
603617
uint32 number = 1 [(google.api.field_behavior) = REQUIRED];
604618

605619
// The protocol exposed on the port.
606620
// MUST BE one of HTTP|HTTPS|GRPC|HTTP2|MONGO|TCP|TLS.
607621
// TLS implies the connection will be routed based on the SNI header to
608622
// the destination without terminating the TLS connection.
623+
// +kubebuilder:validation:MaxLength=256
609624
string protocol = 2;
610625

611626
// Label assigned to the port.
627+
// +kubebuilder:validation:MaxLength=256
612628
string name = 3 [(google.api.field_behavior) = REQUIRED];
613629

614630
// The port number on the endpoint where the traffic will be
615631
// received. If unset, default to `number`.
632+
// +kubebuilder:validation:XValidation:message="port must be between 1-65535",rule="0 < self && self <= 65535"
616633
uint32 target_port = 4;
617634
}
618635

networking/v1alpha3/sidecar.pb.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

networking/v1alpha3/sidecar.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ message WorkloadSelector {
552552
// on which the configuration should be applied. The scope of
553553
// label search is restricted to the configuration namespace in which the
554554
// the resource is present.
555+
// +kubebuilder:validation:MaxProperties=256
556+
// +protoc-gen-crd:map-value-validation:MaxLength=63
557+
// +protoc-gen-crd:map-value-validation:XValidation:message="wildcard is not supported in selector",rule="!self.contains('*')"
555558
map<string, string> labels = 1;
556559

557560
// $hide_from_docs

networking/v1alpha3/workload_group.pb.go

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

networking/v1alpha3/workload_group.pb.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)