Skip to content

Commit

Permalink
Improve validation for targetRefs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
howardjohn committed Sep 12, 2024
1 parent 169f6c4 commit ee310a8
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 5 deletions.
2 changes: 2 additions & 0 deletions extensions/v1alpha1/wasm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions extensions/v1alpha1/wasm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ option go_package="istio.io/api/extensions/v1alpha1";
// +genclient
// +k8s:deepcopy-gen=true
// -->
// +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"
message WasmPlugin {
// Criteria used to select the specific set of pods/VMs on which
// this plugin configuration should be applied. If omitted, this
Expand Down Expand Up @@ -267,6 +268,7 @@ message WasmPlugin {
// from misinterpreting the policy as namespace-wide during the upgrade process.
//
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
// +kubebuilder:validation:MaxItems=16
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 16;

// URL of a Wasm module or OCI container. If no scheme is present,
Expand Down
30 changes: 28 additions & 2 deletions kubernetes/customresourcedefinitions.gen.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions networking/v1alpha3/envoy_filter.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions networking/v1alpha3/envoy_filter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ option go_package = "istio.io/api/networking/v1alpha3";
// +genclient
// +k8s:deepcopy-gen=true
// -->
// +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"
message EnvoyFilter {
// `ApplyTo` specifies where in the Envoy configuration, the given patch should be applied.
enum ApplyTo {
Expand Down Expand Up @@ -866,6 +867,7 @@ message EnvoyFilter {
// from misinterpreting the policy as namespace-wide during the upgrade process.
//
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
// +kubebuilder:validation:MaxItems=16
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 6;

// One or more patches with match conditions.
Expand Down
1 change: 1 addition & 0 deletions security/v1/authorization_policy_alias.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion security/v1/request_authentication_alias.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions security/v1beta1/authorization_policy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions security/v1beta1/authorization_policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ option go_package="istio.io/api/security/v1beta1";
// +genclient
// +k8s:deepcopy-gen=true
// -->
// +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"
message AuthorizationPolicy {
// Optional. The selector decides where to apply the authorization policy. The selector will match with workloads
// in the same namespace as the authorization policy. If the authorization policy is in the root namespace, the selector
Expand Down Expand Up @@ -300,6 +301,7 @@ message AuthorizationPolicy {
// from misinterpreting the policy as namespace-wide during the upgrade process.
//
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
// +kubebuilder:validation:MaxItems=16
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 6;

// Optional. A list of rules to match the request. A match occurs when at least one rule matches the request.
Expand Down
3 changes: 2 additions & 1 deletion security/v1beta1/request_authentication.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion security/v1beta1/request_authentication.proto
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ option go_package="istio.io/api/security/v1beta1";
// +genclient
// +k8s:deepcopy-gen=true
// -->
// +kubebuilder:validation:XValidation:message="only one of targetRefs or workloadSelector can be set",rule="(has(self.selector)?1:0)+(has(self.targetRef)?1:0)+(has(self.targetRefs)?1:0)<=1"
// +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"
message RequestAuthentication {
// Optional. The selector decides where to apply the request authentication policy. The selector will match with workloads
// in the same namespace as the request authentication policy. If the request authentication policy is in the root namespace,
Expand Down Expand Up @@ -275,6 +275,7 @@ message RequestAuthentication {
// from misinterpreting the policy as namespace-wide during the upgrade process.
//
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
// +kubebuilder:validation:MaxItems=16
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 4;

// Define the list of JWTs that can be validated at the selected workloads' proxy. A valid token
Expand Down
1 change: 1 addition & 0 deletions telemetry/v1/telemetry_alias.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions telemetry/v1alpha1/telemetry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions telemetry/v1alpha1/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ option go_package = "istio.io/api/telemetry/v1alpha1";
// +genclient
// +k8s:deepcopy-gen=true
// -->
// +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"
message Telemetry {
// Optional. The selector decides where to apply the policy.
// If not set, the policy will be applied to all workloads in the
Expand Down Expand Up @@ -286,6 +287,7 @@ message Telemetry {
// from misinterpreting the policy as namespace-wide during the upgrade process.
//
// NOTE: Waypoint proxies are required to use this field for policies to apply; `selector` policies will be ignored.
// +kubebuilder:validation:MaxItems=16
repeated istio.type.v1beta1.PolicyTargetReference targetRefs = 6;

// Optional. Tracing configures the tracing behavior for all
Expand Down

0 comments on commit ee310a8

Please sign in to comment.