Skip to content

Commit 1708641

Browse files
authored
Improve validation for targetRefs (#3312)
Per https://gateway-api.sigs.k8s.io/geps/gep-2648/?h=targetrefs#multiple, only 16 max allowed -- which is quite reasonable. Additionally, consistently allow only workloadSelector OR targetRef; we had this only on some types
1 parent 54d9596 commit 1708641

15 files changed

+53
-7
lines changed

extensions/v1alpha1/wasm.pb.go

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

extensions/v1alpha1/wasm.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ option go_package="istio.io/api/extensions/v1alpha1";
236236
// +genclient
237237
// +k8s:deepcopy-gen=true
238238
// -->
239+
// +kubebuilder:validation:XValidation:message="only one of targetRefs or selector can be set",rule="(has(self.selector)?1:0)+(has(self.targetRef)?1:0)+(has(self.targetRefs)?1:0)<=1"
239240
message WasmPlugin {
240241
// Criteria used to select the specific set of pods/VMs on which
241242
// this plugin configuration should be applied. If omitted, this
@@ -267,6 +268,7 @@ message WasmPlugin {
267268
// from misinterpreting the policy as namespace-wide during the upgrade process.
268269
//
269270
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
271+
// +kubebuilder:validation:MaxItems=16
270272
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 16;
271273

272274
// URL of a Wasm module or OCI container. If no scheme is present,

kubernetes/customresourcedefinitions.gen.yaml

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

networking/v1alpha3/envoy_filter.pb.go

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

networking/v1alpha3/envoy_filter.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ option go_package = "istio.io/api/networking/v1alpha3";
421421
// +genclient
422422
// +k8s:deepcopy-gen=true
423423
// -->
424+
// +kubebuilder:validation:XValidation:message="only one of targetRefs or workloadSelector can be set",rule="(has(self.workloadSelector)?1:0)+(has(self.targetRefs)?1:0)<=1"
424425
message EnvoyFilter {
425426
// `ApplyTo` specifies where in the Envoy configuration, the given patch should be applied.
426427
enum ApplyTo {
@@ -866,6 +867,7 @@ message EnvoyFilter {
866867
// from misinterpreting the policy as namespace-wide during the upgrade process.
867868
//
868869
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
870+
// +kubebuilder:validation:MaxItems=16
869871
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 6;
870872

871873
// One or more patches with match conditions.

security/v1/authorization_policy_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.

security/v1/request_authentication_alias.gen.go

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

security/v1beta1/authorization_policy.pb.go

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

security/v1beta1/authorization_policy.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ option go_package="istio.io/api/security/v1beta1";
270270
// +genclient
271271
// +k8s:deepcopy-gen=true
272272
// -->
273+
// +kubebuilder:validation:XValidation:message="only one of targetRefs or selector can be set",rule="(has(self.selector)?1:0)+(has(self.targetRef)?1:0)+(has(self.targetRefs)?1:0)<=1"
273274
message AuthorizationPolicy {
274275
// Optional. The selector decides where to apply the authorization policy. The selector will match with workloads
275276
// in the same namespace as the authorization policy. If the authorization policy is in the root namespace, the selector
@@ -300,6 +301,7 @@ message AuthorizationPolicy {
300301
// from misinterpreting the policy as namespace-wide during the upgrade process.
301302
//
302303
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
304+
// +kubebuilder:validation:MaxItems=16
303305
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 6;
304306

305307
// Optional. A list of rules to match the request. A match occurs when at least one rule matches the request.

security/v1beta1/request_authentication.pb.go

Lines changed: 2 additions & 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)