You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Policies are a Kubernetes object that augments the behavior of an object in a standard way. Policies can be attached to one object ("Direct Policy Attachment") or objects in a hierarchy ("Inherited Policy Attachment"). In both cases, Policies are implemented as CRDs, and they must include a _single_ `TargetRef` struct in the `spec` to identify how and where to apply the Policy. This `TargetRef` can include a `sectionName` to target specific matches within nested objects, such as a Listener within a Gateway or a specific Port on a Service.
306
+
Policies are a Kubernetes object that augments the behavior of an object in a standard way. Policies can be attached to one object ("Direct Policy Attachment") or objects in a hierarchy ("Inherited Policy Attachment"). In both cases, Policies are implemented as CRDs, and they must include a _single_ `TargetRef` struct in the `spec` to identify how and where to apply the Policy. The Policy GEP _may_ be extended to supported multiple `TargetRefs` and/or label selectors.
307
+
308
+
Policies do not need to support attaching to all resource Kinds. Implementations can choose which resources the Policy can be attached to.
309
+
310
+
#### Direct Policy Attachment
311
+
312
+
A Direct Policy Attachment is a Policy that references a single object -- such as a Gateway or HTTPRoute. It is tightly bound to one instance of a particular Kind within a single Namespace or an instance of a single Kind at the cluster-scope. It affects _only_ the object specified in its TargetRef.
313
+
314
+
A Direct Policy _may_ target a subsection of a resource using the `sectionName` field of the `targetRef`. This allows the Policy to target specific matches within nested objects, such as a Listener within a Gateway or a specific Port on a Service.
307
315
308
316
Example of a TargetRef that targets an entire Gateway:
309
317
@@ -326,15 +334,9 @@ targetRef:
326
334
namespace: default
327
335
```
328
336
329
-
There's also an open [GEP issue](https://github.com/kubernetes-sigs/gateway-api/issues/995) to add a name field to HTTPRouteRule and HTTPRouteMatch structs to allow users to identify different routes. Once implemented, Policies can target a specific rule or match in an HTTPRoute. The Policy GEP _may_ be extended to supported multiple `TargetRefs` and/or label selectors.
330
-
331
-
Policies do not need to support attaching to all resource Kinds. Implementations can choose which resources the Policy can be attached to.
332
-
333
-
#### Direct Policy Attachment
334
-
335
-
A Direct Policy Attachment is a Policy that references a single object -- such as a Gateway or HTTPRoute. It is tightly bound to one instance of a particular Kind within a single Namespace or an instance of a single Kind at the cluster-scope. It only modifies the behavior of the object that it's bound to.
337
+
There's also an open [GEP issue](https://github.com/kubernetes-sigs/gateway-api/issues/995) to add a name field to HTTPRouteRule and HTTPRouteMatch structs to allow users to identify different routes. Once implemented, Policies can target a specific rule or match in an HTTPRoute.
336
338
337
-
Example:
339
+
The BackendTLSPolicy is an example of a Direct Policy Attachment:
338
340
339
341
```yaml
340
342
apiVersion: gateway.networking.k8s.io/v1alpha2
@@ -355,7 +357,7 @@ spec:
355
357
hostname: secure-app.example.com
356
358
```
357
359
358
-
This BackendTLSPolicy is an example of a Direct Policy Attachment. It targets the `secure-app` Service in the `default` Namespace. The TLS configuration in the `backend-tls` Policy will be applied for all Routes that reference the `secure-app` Service.
360
+
This example targets the `secure-app` Service in the `default` Namespace. The TLS configuration in the `backend-tls` Policy will be applied for all Routes that reference the `secure-app` Service.
359
361
360
362
When to use Direct Policy Attachment:
361
363
@@ -445,6 +447,19 @@ Default values are given precedence from the bottom up. A default attached to a
445
447
446
448
Inherited Policies do not need to support policy attachment to each resource shown in the hierarchy. Implementations can choose which resources the Policy can attach to.
| Affects ONLY the object it targets | Affects more objects that the targeted object |
455
+
| Requires no extra knowledge beyond the Policy and target object | Requires knowledge of resources other than the Policy and target object to understand the state of the system |
456
+
| Does not include defaults or overrides | May include defaults and/or overrides |
457
+
| Should only support attaching to a single Kind | Can support attaching to multiple Kinds |
458
+
| May target a subsection of a resource using the `sectionName` field of the `targetRef` struct | Does not target a subsection of a resource |
459
+
460
+
461
+
> If a Policy can be used as an Inherited Policy, it MUST be treated as an Inherited Policy, regardless of whether a specific instance of the Policy is only affecting a single object.
These features are grouped because they all deal with client traffic. An Inherited Policy fits this group best because there is a use case where the Cluster Operator sets a sane default for client max body size or client keepalives that has to be overridden by an Application Developer because of the unique attributes of the Service they own.
723
+
These features are grouped because they all deal with client traffic.
724
+
725
+
An Inherited Policy fits this group best for the following reasons:
726
+
727
+
- A Cluster Operator may want to set defaults for client max body size or client keepalives.
728
+
- An Application Developer may want to override these defaults because of the unique attributes of their applications.
729
+
- Since these settings are available in the http, server, and location contexts, there is already inheritance involved. For example, setting the client max body size in the http context, sets the client max body size of all the servers and locations. While setting the client max body size of server `example.com` will override the size set in the http context.
730
+
- If this policy is applied to a Gateway is will affect all the Routes attached to the Gateway, which is one of the traits of an Inherited Policy.
709
731
710
732
#### Future Work
711
733
712
734
- Can add support for more `client_*` directives: `client_body_buffer_size`, `client_header_buffer_size`, etc.
713
735
714
736
#### Alternatives
715
737
716
-
- Direct Policy: A Direct Policy isn't a good fit for client settings because it does not support overrides and defaults.
738
+
- Direct Policy: A Direct Policy isn't a good fit because the NGINX directives included in this policy are available at the http, server, and location contexts. NGINX's inheritance behavior among these contexts does not suit Direct Policy attachment. A client settings policy attached to a Gateway will affect all the Routes attached to the Gateway. This violates the Direct Policy requirement that the policy should only affect the object it attaches to. If we only support attaching this policy to an HTTPRoute, we could use a Direct Policy. However, we want to allow the Cluster Operator to configure defaults for these client settings, which means we need to support attaching to Gateways as well as HTTPRoutes.
An Inherited Policy fits this group best for the following reasons (same reasons as [Client Settings](#client-settings):
909
+
910
+
- A Cluster Operator may want to set defaults for proxy settings.
911
+
- An Application Developer may want to override these defaults because of the unique attributes of their application.
912
+
- Since these settings are available in the http, server, and location contexts, there is already inheritance involved. For example, setting the proxy connect timeout in the http context, sets the proxy connect timeout of all the servers and locations. While setting the proxy connect timeout of server `example.com` will override the size set in the http context.
913
+
- If this policy is applied to a Gateway is will affect all the Routes attached to the Gateway, which is one of the traits of an Inherited Policy.
0 commit comments