Skip to content

Commit 8e75639

Browse files
authored
docs: defaults & overrides (#575)
* docs: defaults & overrides * fix: typos
1 parent b3758bd commit 8e75639

File tree

2 files changed

+150
-66
lines changed

2 files changed

+150
-66
lines changed

doc/auth.md

+66-9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ The auth scheme specify rules for:
3939

4040
Each auth rule can declare specific `routeSelectors` and `when` conditions for the rule to apply.
4141

42+
The auth scheme (`rules`), as well as conditions and named patterns can be declared at the top-level level of the spec (with the semantics of _defaults_) or alternatively within explicit `defaults` or `overrides` blocks.
43+
4244
#### High-level example and field definition
4345

4446
```yaml
@@ -47,7 +49,7 @@ kind: AuthPolicy
4749
metadata:
4850
name: my-auth-policy
4951
spec:
50-
# Reference to an existing networking resource to attach the policy to.
52+
# Reference to an existing networking resource to attach the policy to. REQUIRED.
5153
# It can be a Gateway API HTTPRoute or Gateway resource.
5254
# It can only refer to objects in the same namespace as the AuthPolicy.
5355
targetRef:
@@ -71,9 +73,16 @@ spec:
7173
# Use it for filtering attributes not supported by HTTPRouteRule or with AuthPolicies that target a Gateway.
7274
# Check out https://github.com/Kuadrant/architecture/blob/main/rfcs/0002-well-known-attributes.md to learn more
7375
# about the Well-known Attributes that can be used in this field.
76+
# Equivalent to if otherwise declared within `defaults`.
7477
when: […]
7578

76-
# The auth rules to apply to the network traffic routed through the targeted resource
79+
# Sets of common patterns of selector-operator-value triples, to be referred by name in `when` conditions
80+
# and pattern-matching rules. Often employed to avoid repetition in the policy.
81+
# Equivalent to if otherwise declared within `defaults`.
82+
patterns: {…}
83+
84+
# The auth rules to apply to the network traffic routed through the targeted resource.
85+
# Equivalent to if otherwise declared within `defaults`.
7786
rules:
7887
# Authentication rules to enforce.
7988
# At least one config must evaluate to a valid identity object for the auth request to be successful.
@@ -141,6 +150,34 @@ spec:
141150
callbacks:
142151
"my-webhook":
143152
http: {…}
153+
154+
# Explicit defaults. Used in policies that target a Gateway object to express default rules to be enforced on
155+
# routes that lack a more specific policy attached to.
156+
# Mutually exclusive with `overrides` and with declaring the `rules`, `when` and `patterns` at the top-level of
157+
# the spec.
158+
defaults:
159+
rules:
160+
authentication: {…}
161+
metadata: {…}
162+
authorization: {…}
163+
response: {…}
164+
callbacks: {…}
165+
when: […]
166+
patterns: {…}
167+
168+
# Overrides. Used in policies that target a Gateway object to be enforced on all routes linked to the gateway,
169+
# thus also overriding any more specific policy occasionally attached to any of those routes.
170+
# Mutually exclusive with `defaults` and with declaring `rules`, `when` and `patterns` at the top-level of
171+
# the spec.
172+
overrides:
173+
rules:
174+
authentication: {…}
175+
metadata: {…}
176+
authorization: {…}
177+
response: {…}
178+
callbacks: {…}
179+
when: […]
180+
patterns: {…}
144181
```
145182
146183
Check out the [API reference](reference/authpolicy.md) for a full specification of the AuthPolicy CRD.
@@ -213,11 +250,13 @@ Expected behavior:
213250
214251
### Targeting a Gateway networking resource
215252
216-
When an AuthPolicy targets a Gateway, the policy will be enforced to all HTTP traffic hitting the gateway, unless a more specific AuthPolicy targeting a matching HTTPRoute exists.
253+
An AuthPolicy that targets a Gateway can declare a block of _defaults_ (`spec.defaults`) or a block of _overrides_ (`spec.overrides`). As a standard, gateway policies that do not specify neither defaults nor overrides, act as defaults.
254+
255+
When declaring _defaults_, an AuthPolicy which targets a Gateway will be enforced to all HTTP traffic hitting the gateway, unless a more specific AuthPolicy targeting a matching HTTPRoute exists. Any new HTTPRoute referrencing the gateway as parent will be automatically covered by the default AuthPolicy, as well as changes in the existing HTTPRoutes.
217256
218-
Any new HTTPRoute referrencing the gateway as parent will be automatically covered by the AuthPolicy that targets the Gateway, as well as changes in the existing HTTPRoutes.
257+
_Defaults_ provide cluster operators with the ability to protect the infrastructure against unplanned and malicious network traffic attempt, such as by setting preemptive "deny-all" policies on hostnames and hostname wildcards.
219258
220-
This effectively provides cluster operators with the ability to set _defaults_ to protect the infrastructure against unplanned and malicious network traffic attempt, such as by setting preemptive "deny-all" policies for hostnames and hostname wildcards.
259+
Inversely, a gateway policy that specify _overrides_ declares a set of rules to be enforced on _all routes attached to the gateway_, thus atomically replacing any more specific policy occasionally attached to any of those routes.
221260
222261
Target a Gateway HTTPRoute by setting the `spec.targetRef` field of the AuthPolicy as follows:
223262
@@ -231,7 +270,8 @@ spec:
231270
group: gateway.networking.k8s.io
232271
kind: Gateway
233272
name: <Gateway Name>
234-
rules: {…}
273+
defaults: # alternatively: `overrides`
274+
rules: {…}
235275
```
236276

237277
```
@@ -255,13 +295,15 @@ spec:
255295

256296
#### Overlapping Gateway and HTTPRoute AuthPolicies
257297

258-
Gateway-targeted AuthPolicies will serve as a default to protect all traffic routed through the gateway until a more specific HTTPRoute-targeted AuthPolicy exists, in which case the HTTPRoute AuthPolicy prevails.
298+
Two possible semantics are to be considered here – gateway policy _defaults_ vs gateway policy _overrides_.
299+
300+
Gateway AuthPolicies that declare _defaults_ (or alternatively neither defaults nor overrides) protect all traffic routed through the gateway except where a more specific HTTPRoute AuthPolicy exists, in which case the HTTPRoute AuthPolicy prevails.
259301

260-
Example with 4 AuthPolicies, 3 HTTPRoutes and 1 Gateway (plus 2 HTTPRoute and 2 Gateways without AuthPolicies attached):
302+
Example with 4 AuthPolicies, 3 HTTPRoutes and 1 Gateway _default_ (plus 2 HTTPRoute and 2 Gateways without AuthPolicies attached):
261303
- AuthPolicy A → HTTPRoute A (`a.toystore.com`) → Gateway G (`*.com`)
262304
- AuthPolicy B → HTTPRoute B (`b.toystore.com`) → Gateway G (`*.com`)
263305
- AuthPolicy W → HTTPRoute W (`*.toystore.com`) → Gateway G (`*.com`)
264-
- AuthPolicy G → Gateway G (`*.com`)
306+
- AuthPolicy G (defaults) → Gateway G (`*.com`)
265307

266308
Expected behavior:
267309
- Request to `a.toystore.com` → AuthPolicy A will be enforced
@@ -270,6 +312,21 @@ Expected behavior:
270312
- Request to `other.com` (suppose a route exists) → AuthPolicy G will be enforced
271313
- Request to `yet-another.net` (suppose a route and gateway exist) → No AuthPolicy will be enforced
272314

315+
Gateway AuthPolicies that declare _overrides_ protect all traffic routed through the gateway, regardless of existence of any more specific HTTPRoute AuthPolicy.
316+
317+
Example with 4 AuthPolicies, 3 HTTPRoutes and 1 Gateway _override_ (plus 2 HTTPRoute and 2 Gateways without AuthPolicies attached):
318+
- AuthPolicy A → HTTPRoute A (`a.toystore.com`) → Gateway G (`*.com`)
319+
- AuthPolicy B → HTTPRoute B (`b.toystore.com`) → Gateway G (`*.com`)
320+
- AuthPolicy W → HTTPRoute W (`*.toystore.com`) → Gateway G (`*.com`)
321+
- AuthPolicy G (overrides) → Gateway G (`*.com`)
322+
323+
Expected behavior:
324+
- Request to `a.toystore.com` → AuthPolicy G will be enforced
325+
- Request to `b.toystore.com` → AuthPolicy G will be enforced
326+
- Request to `other.toystore.com` → AuthPolicy G will be enforced
327+
- Request to `other.com` (suppose a route exists) → AuthPolicy G will be enforced
328+
- Request to `yet-another.net` (suppose a route and gateway exist) → No AuthPolicy will be enforced
329+
273330
### Route selectors
274331

275332
Route selectors allow targeting sections of a HTTPRoute, by specifying sets of HTTPRouteMatches and/or hostnames that make the policy controller look up within the HTTPRoute spec for compatible declarations, and select the corresponding HTTPRouteRules and hostnames, to then build conditions that activate the policy or policy rule.

0 commit comments

Comments
 (0)