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
Copy file name to clipboardExpand all lines: doc/auth.md
+66-9
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,8 @@ The auth scheme specify rules for:
39
39
40
40
Each auth rule can declare specific `routeSelectors` and `when` conditions for the rule to apply.
41
41
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
+
42
44
#### High-level example and field definition
43
45
44
46
```yaml
@@ -47,7 +49,7 @@ kind: AuthPolicy
47
49
metadata:
48
50
name: my-auth-policy
49
51
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.
51
53
# It can be a Gateway API HTTPRoute or Gateway resource.
52
54
# It can only refer to objects in the same namespace as the AuthPolicy.
53
55
targetRef:
@@ -71,9 +73,16 @@ spec:
71
73
# Use it for filtering attributes not supported by HTTPRouteRule or with AuthPolicies that target a Gateway.
72
74
# Check out https://github.com/Kuadrant/architecture/blob/main/rfcs/0002-well-known-attributes.md to learn more
73
75
# about the Well-known Attributes that can be used in this field.
76
+
# Equivalent to if otherwise declared within `defaults`.
74
77
when: […]
75
78
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`.
77
86
rules:
78
87
# Authentication rules to enforce.
79
88
# At least one config must evaluate to a valid identity object for the auth request to be successful.
@@ -141,6 +150,34 @@ spec:
141
150
callbacks:
142
151
"my-webhook":
143
152
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: {…}
144
181
```
145
182
146
183
Check out the [API reference](reference/authpolicy.md) for a full specification of the AuthPolicy CRD.
@@ -213,11 +250,13 @@ Expected behavior:
213
250
214
251
### Targeting a Gateway networking resource
215
252
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.
217
256
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.
219
258
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.
221
260
222
261
Target a Gateway HTTPRoute by setting the `spec.targetRef` field of the AuthPolicy as follows:
223
262
@@ -231,7 +270,8 @@ spec:
231
270
group: gateway.networking.k8s.io
232
271
kind: Gateway
233
272
name: <Gateway Name>
234
-
rules: {…}
273
+
defaults: # alternatively: `overrides`
274
+
rules: {…}
235
275
```
236
276
237
277
```
@@ -255,13 +295,15 @@ spec:
255
295
256
296
#### Overlapping Gateway and HTTPRoute AuthPolicies
257
297
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.
259
301
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):
261
303
- AuthPolicy A → HTTPRoute A (`a.toystore.com`) → Gateway G (`*.com`)
262
304
- AuthPolicy B → HTTPRoute B (`b.toystore.com`) → Gateway G (`*.com`)
263
305
- AuthPolicy W → HTTPRoute W (`*.toystore.com`) → Gateway G (`*.com`)
264
-
- AuthPolicy G → Gateway G (`*.com`)
306
+
- AuthPolicy G (defaults) → Gateway G (`*.com`)
265
307
266
308
Expected behavior:
267
309
- Request to `a.toystore.com` → AuthPolicy A will be enforced
@@ -270,6 +312,21 @@ Expected behavior:
270
312
- Request to `other.com` (suppose a route exists) → AuthPolicy G will be enforced
271
313
- Request to `yet-another.net` (suppose a route and gateway exist) → No AuthPolicy will be enforced
272
314
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
+
273
330
### Route selectors
274
331
275
332
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