Skip to content

Commit

Permalink
strictly validate the usage of SubPolicies (#599)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Jun 26, 2024
1 parent c2eb98c commit fcee4b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions types/apis/v1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func validateHTTPFilterPolicy(policy *HTTPFilterPolicy, strict bool) error {
}

targetGateway = ref.Kind == "Gateway"

if len(policy.Spec.SubPolicies) > 0 {
if ref.Kind != "VirtualService" {
return errors.New("subPolicies can not be used with this referred target")
}
}
}
// HTTPFilterPolicy in embedded mode can have no targetRef

Expand Down
19 changes: 19 additions & 0 deletions types/apis/v1/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ func TestValidateHTTPFilterPolicy(t *testing.T) {
},
err: "targetRef.SectionName and SubPolicies can not be used together",
},
{
name: "targetRef to Gateway and also use SubPolicies",
policy: &HTTPFilterPolicy{
Spec: HTTPFilterPolicySpec{
TargetRef: &gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: "networking.istio.io",
Kind: "Gateway",
},
},
SubPolicies: []HTTPFilterSubPolicy{
{
SectionName: sectionName,
},
},
},
},
err: "subPolicies can not be used with this referred target",
},
{
name: "bad configuration",
policy: &HTTPFilterPolicy{
Expand Down

0 comments on commit fcee4b8

Please sign in to comment.