-
Notifications
You must be signed in to change notification settings - Fork 621
Adding SectionName to PolicyTargetReference #2283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
aff53f9
14dd664
c5462eb
ad14e97
448e059
b27c73a
7e89e17
6bce55b
62bf73a
2144daa
f637a20
d7beeee
d426c47
a61ea7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1244,20 +1244,44 @@ level. The implementations that support this policy attachment model will have | |
| the same behavior and semantics, although they may not be able to support | ||
| attachment of all types of policy at all potential attachment points. | ||
|
|
||
| ### Apply Policies to Sections of a Resource (Future Extension) | ||
| Although initially out of scope, it would be helpful to be able to target | ||
| specific matches within nested objects. For example, it may be useful to attach | ||
| policies to a specific Gateway listener or Route rule. This section explores | ||
| what that could look like. | ||
|
|
||
| Each Route rule or Gateway listener should be expanded with an optional name | ||
| field. The target ref would be expanded with an optional sectionName field that | ||
| could be used to refer to that specific section of the resource. It would refer | ||
| to the following concepts on these resources: | ||
|
|
||
| * Gateway.Listeners.Name | ||
| * xRoute.Rules.Name | ||
| ### Apply Policies to Sections of a Resource | ||
| Policies can target specific matches within nested objects. For instance, rather than | ||
| applying a policy to the entire Gateway, we may want to attach it to a particular Gateway listener. | ||
|
|
||
| To achieve this, an optional `sectionName` field can be set in the `targetRef` of a policy | ||
| to refer to a specific listener within the target Gateway. | ||
|
|
||
| ```yaml | ||
| apiVersion: gateway.networking.k8s.io/v1beta1 | ||
| kind: Gateway | ||
| metadata: | ||
| name: foo-gateway | ||
| spec: | ||
| gatewayClassName: foo-lb | ||
| listeners: | ||
| - name: bar | ||
| ... | ||
| --- | ||
| apiVersion: networking.acme.io/v1alpha2 | ||
| kind: AuthenticationPolicy | ||
| metadata: | ||
| name: foo | ||
| spec: | ||
| provider: | ||
| issuer: "https://oidc.example.com" | ||
| targetRef: | ||
| name: foo-gateway | ||
| group: gateway.networking.k8s.io | ||
| kind: Gateway | ||
zhaohuabing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sectionName: bar | ||
| ``` | ||
|
|
||
| The `sectionName` field can also be used to target a specific section of other resources: | ||
|
|
||
| * Service.Ports.Name | ||
| * xRoute.Rules.Name | ||
|
|
||
| For example, the RetryPolicy below applies to a RouteRule inside an HTTPRoute. | ||
|
|
||
| ```yaml | ||
| apiVersion: gateway.networking.k8s.io/v1alpha2 | ||
|
|
@@ -1292,43 +1316,8 @@ spec: | |
| sectionName: bar | ||
| ``` | ||
|
|
||
| This would require adding a `SectionName` field to the PolicyTargetReference: | ||
| ```go | ||
| type PolicyTargetReference struct { | ||
| // SectionName is the name of a section within the target resource. When | ||
| // unspecified, this targets the entire resource. In the following | ||
| // resources, SectionName is interpreted as the following: | ||
| // * Gateway: Listener Name | ||
| // * Route: Rule Name | ||
| // * Service: Port Name | ||
| // | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=253 | ||
| // +optional | ||
| SectionName string `json:"sectionName,omitempty"` | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| This would also require adding a `Name` field to Gateway listeners and Route | ||
| rules: | ||
|
|
||
| ```go | ||
| type Listener struct { | ||
| // Name is the name of the Listener. If more than one Listener is present | ||
| // each Listener MUST specify a name. The names of Listeners MUST be unique | ||
| // within a Gateway. | ||
| // | ||
| // Support: Core | ||
| // | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=253 | ||
| // +optional | ||
| Name string `json:"name,omitempty"` | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| This would require adding a `Name` field to those sub-resources that currently lack a name. For example, | ||
| a `Name` field could be added to the `RouteRule` object: | ||
zhaohuabing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```go | ||
| type RouteRule struct { | ||
| // Name is the name of the Route rule. If more than one Route Rule is | ||
|
|
@@ -1345,6 +1334,13 @@ type RouteRule struct { | |
| } | ||
| ``` | ||
|
|
||
| If a `sectionName` is specified, but does not exist on the targeted object, the Policy must fail to attach, | ||
| and the policy implementation should record a `resolvedRefs` or similar Condition in the Policy's status. | ||
|
|
||
| Note that the `sectionName` is currently intended to be used only for Direct Policy Attachment. Inherited Policies | ||
| are always applied to the entire object. The `DirectPolicyTargetReference` API can be used to apply a direct Policy | ||
| to a section of an object. | ||
|
||
|
|
||
| ### Advantages | ||
| * Incredibly flexible approach that should work well for both ingress and mesh | ||
| * Conceptually similar to existing ServicePolicy proposal and BackendPolicy | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.