3
3
This resource allows users to define the authorization policy between
4
4
applications and clients.
5
5
6
- There are two high level concepts, ` TrafficRole ` and ` TrafficRoleBinding ` . A
7
- ` TrafficRole ` describes a resource that will be receiving requests and what
8
- traffic can be issued to that resource. As an example, a ` TrafficRole ` could be
9
- configured to reference a pod and only allow ` GET ` requests to a specific
10
- endpoint on that service.
11
-
12
- The ` TrafficRoleBinding ` associates a client's identity with a ` TrafficRole ` .
13
- This client can then issue requests to the configured resource using the allowed
14
- paths and methods. The design of Kubernetes RBAC has been heavily borrowed from.
15
-
16
- TrafficRoles are designed to work in an additive fashion and all traffic is
17
- denied by default. See [ tradeoffs] ( #policy-tradeoffs ) for more details on that
18
- decision.
19
-
20
6
## Specification
21
7
22
- ### TrafficRole
23
-
24
- A ` TrafficRole ` contains a list of rules that have: resources, methods and
25
- paths. These work in concert to define what an authorized client can request.
26
-
27
- Resources reference Kubernetes objects. These can be anything such as
28
- deployments, services and pods. The resource concretely defines the resource
29
- that will be serving the traffic itself either as a group (ex. deployment) or a
30
- pod itself.
31
-
32
- The full list of resources that can be referenced is:
33
-
34
- * pods
35
- * replicationscontrollers
36
- * services
37
- * daemonsets
38
- * deployments
39
- * replicasets
40
- * statefulets
41
- * jobs
42
-
43
- Methods describe the HTTP method that is allowed for the referenced resource.
44
- This is limited to existing HTTP methods. It is possible to use ` * ` to allow any
45
- value instead of enumerating them all.
46
-
47
- Paths describe the HTTP path that a referenced resource serves. The path is a
48
- regex and is anchored (` ^ ` ) to the start of the URI. See [ use cases]
49
- (#policy-use-cases) for some examples about how these can be generated
50
- automatically without user interaction.
51
-
52
- Bringing everything together, an example specification:
8
+ ### HTTPService
53
9
54
10
``` yaml
55
- kind : TrafficRole
11
+ kind : HTTPService
56
12
apiVersion : v1beta1
57
13
metadata :
58
- name : path-specific
14
+ name : foo
59
15
namespace : default
60
- rules :
61
- - resources :
62
- - name : foo
63
- kind : Deployment
16
+ resources :
17
+ # v1.ObjectReference
18
+ - kind : Service
19
+ name : foo
20
+ routes :
21
+ - name : admin
64
22
methods :
65
23
- GET
66
- paths :
67
- - ' /authors/\d+'
24
+ pathRegex : " /admin/.*"
25
+ - name : default
26
+ methods : ["*"]
27
+ pathRegex : " .*"
68
28
` ` `
69
29
70
- This specification can be used to grant access to the ` foo` deployment for `GET`
71
- requests to paths like `/authors/1234`. An accompanying `TrafficRoleBinding`
72
- would allow authorized clients to request this path.
73
-
74
- Note that `namespace` is *not* part of the resource references. The resources
75
- must be within the same namespace that a `TrafficRole` resides in. See
76
- [tradeoffs](#policy-tradeoffs) for a discussion on why this is.
77
-
78
- While it is convenient to be extremely specific, most policies will be a little
79
- bit more general. The following `TrafficRole` can be used to grant access to the
80
- ` foo` service and by association the endpoints that service selects. Any method
81
- and path would be accessible.
30
+ ### gRPCService
82
31
83
32
` ` ` yaml
84
- kind: TrafficRole
33
+ kind : gRPCService
85
34
apiVersion : v1beta1
86
35
metadata :
87
- name: service-specific
36
+ name : foo
88
37
namespace : default
89
- rules:
90
- - resources:
91
- - name: foo
92
- kind: Service
93
- methods: ["*"]
94
- paths: ["*"]
38
+ resources :
39
+ - kind : Service
40
+ name : foo
41
+ package : foo.v1
42
+ service : SearchService
43
+ rpc :
44
+ - name : Search
95
45
` ` `
96
46
97
- As roles are additive, policies that can allow all traffic are helpful for
98
- testing environments or super users. To grant access to anything in a namespace,
99
- ` *` can be used in combination with `kind`. The other keys are optional in this
100
- example.
47
+ ### TCPService
101
48
102
49
` ` ` yaml
103
- kind: TrafficRole
50
+ kind : TCPService
104
51
apiVersion : v1beta1
105
52
metadata :
106
- name: service-specific
53
+ name : foo
107
54
namespace : default
108
- rules:
109
- - resources:
110
- - name: "*"
111
- kind: Pod
112
- methods: ["*"]
113
- paths: ["*"]
55
+ resources :
56
+ - kind : Service
57
+ name : foo
114
58
` ` `
115
59
116
- # ## TrafficRoleBinding
117
-
118
- A `TrafficRoleBinding` grants the permissions defined in a `TrafficRole` to a
119
- specified identity. It holds a list of subjects (service accounts, deployments)
120
- and a reference to the role being granted.
121
-
122
- The following binding grants the `path-specific` role to pods contained within
123
- the deployment `bar` in the `default` namespace. Assuming the `path-specific`
124
- definition from above, these pods will be authorized to issue `GET` requests to
125
- the `foo` deployment with paths matching the `/authors/\d+` regex.
60
+ ### TrafficRole
126
61
127
62
` ` ` yaml
128
- kind: TrafficRoleBinding
63
+ kind : TrafficRole
129
64
apiVersion : v1beta1
130
65
metadata :
131
- name: account -specific
66
+ name : path -specific
132
67
namespace : default
68
+ resource :
69
+ name : foo
70
+ kind : Deployment
133
71
subjects :
134
- - kind: Deployment
135
- name: bar
136
- namespace: default
137
- roleRef:
138
- kind: TrafficRole
139
- name: path-specific
72
+ - kind : HTTPService
73
+ name : admin
140
74
` ` `
141
75
142
- Note : this specification defines that policy is *always* enforced on the
143
- *server* side of a connection. It is up to implementations to decide whether
144
- they would also like to enforce this policy on the *client* side of the
145
- connection as well.
146
-
147
- Bindings reference subjects that can be defined based on identity. This allows
148
- for references to be more than just groups of pods. In this example, a binding
149
- is against a service account.
76
+ ### TrafficRoleBinding
150
77
151
78
` ` ` yaml
152
79
kind : TrafficRoleBinding
@@ -156,131 +83,42 @@ metadata:
156
83
namespace : default
157
84
subjects :
158
85
- kind : ServiceAccount
159
- name: foo-account
86
+ name : bar
160
87
namespace : default
161
88
roleRef :
162
89
kind : TrafficRole
163
90
name : path-specific
164
91
` ` `
165
92
166
- Implementations and cluster administrators can provide some default policy as
167
- [ClusterTrafficRole](#clustertrafficrole). These can be bound to specific
168
- namespaces and will only be valid for that specific namespace. In this example,
169
- a `ClusterTrafficRole` that grants access to `/health` is bound only inside the
170
- ` default` namespace for the pod `foobar`.
171
-
172
- ` ` ` yaml
173
- kind: TrafficRoleBinding
174
- apiVersion: v1beta1
175
- metadata:
176
- name: health-check
177
- namespace: default
178
- subjects:
179
- - kind: Pod
180
- name: foobar
181
- roleRef:
182
- kind: ClusterTrafficRole
183
- name: health-check
184
- ` ` `
185
-
186
- # ## ClusterTrafficRole
187
-
188
- Roles can be defined cluster-wide with `ClusterTrafficRole`. These roles can
189
- grant access to applications in specific namespaces or across all namespaces and
190
- are particularly useful for providing sane default policy.
191
-
192
- The following `ClusterTrafficRole` can be used to grant access to `/health`
193
- endpoints.
194
-
195
- ` ` ` yaml
196
- kind: ClusterTrafficRole
197
- apiVersion: v1beta1
198
- metadata:
199
- name: health-check
200
- rules:
201
- - resources:
202
- - name: "*"
203
- kind: Pod
204
- methods:
205
- - GET
206
- paths:
207
- - '/health'
208
- ` ` `
209
-
210
- A `ClusterTrafficRole` can also be used as a default allow policy.
211
-
212
- ` ` ` yaml
213
- kind: ClusterTrafficRole
214
- apiVersion: v1beta1
215
- metadata:
216
- name: default-allow
217
- rules:
218
- - resources:
219
- - name: "*"
220
- kind: Pod
221
- methods: ["*"]
222
- paths: ["*"]
223
- ` ` `
224
-
225
- # ## ClusterTrafficRoleBinding
226
-
227
- The following `ClusterTrafficRoleBinding` will grant access every node in the
228
- cluster to request the `/health` endpoint served by pods in any namespace.
229
-
230
- ` ` ` yaml
231
- kind: ClusterTrafficRoleBinding
232
- apiVersion: v1beta1
233
- metadata:
234
- name: default-allow
235
- subjects:
236
- - name: *
237
- kind: Node
238
- roleRef:
239
- kind: ClusterTrafficRole
240
- name: health-check
241
- ` ` `
242
-
243
- To grant the pod `root` running in any namespace access to every pod serving any
244
- endpoint in any namespace, it would be possible to do :
93
+ Note: this specification defines that policy is *always* enforced on the
94
+ *server* side of a connection. It is up to implementations to decide whether
95
+ they would also like to enforce this policy on the *client* side of the
96
+ connection as well.
245
97
246
- ` ` ` yaml
247
- kind: ClusterTrafficRoleBinding
248
- apiVersion: v1beta1
249
- metadata:
250
- name: default-allow
251
- subjects:
252
- - name: root
253
- kind: Pod
254
- roleRef:
255
- kind: ClusterTrafficRole
256
- name: default-allow
257
- ` ` `
98
+ ## Use Cases
258
99
259
- # # Workflow
100
+ ## Admission Control
260
101
261
- # # Use Cases {#policy-use-cases}
102
+ TODO ...
262
103
263
- # ## OpenAPI/Swagger
104
+ ## RBAC
264
105
265
- Many REST applications provide OpenAPI definitions for their endpoints,
266
- operations and authentication methods. Consuming these definitions and
267
- generating policy automatically allows developers and organizations keep the
268
- definition of their policy in a single location. A given specification can be
269
- used to create `TrafficRole` and `TrafficRoleBinding` objects as part of a CI/CD
270
- workflow.
106
+ TODO ...
271
107
272
- TODO - specification mapping
108
+ ## Example Implementation
273
109
274
110
## Tradeoffs {#policy-tradeoffs}
275
111
276
112
* Additive policy - policy that denies instead of only allows is valuable
277
113
sometimes. Unfortunately, it makes it extremely difficult to reason about what
278
114
is allowed or denied in a configuration.
115
+
279
116
* It would be possible to support ` kind: Namespace`. This ends up having some
280
117
special casing as to references and doesn't cover all cases. Instead, there
281
118
has been a conscious decision to allow `*` kinds instead of supporting
282
119
non-namespaced resources (for example, namespaces). This solves the same user
283
120
goal and is slightly more flexible.
121
+
284
122
* Namespaces are explicitly left out of the resource reference (`namespace:
285
123
foobar`). This is because the reference could be used to point to a resource
286
124
in a different namespace that a user might not have permissions to access or
@@ -291,16 +129,18 @@ TODO - specification mapping
291
129
292
130
* Egress policy - while this specification allows for the possibility of
293
131
defining egress configuration, this functionality is currently out of scope.
132
+
294
133
* Non-HTTP traffic - this specification will need to be expanded to support
295
134
traffic such as Kafka or MySQL.
296
135
297
136
# # Open Questions
298
137
299
138
* Why include namespace in the reference *and* role? Is there any reason a user
300
139
would create a role in one namespace that references another?
140
+
301
141
* Namespaces should *not* be possible to define on `TrafficRole` for resource
302
142
references but are required for `ClusterTrafficRole`. Is it okay only allow
303
143
this key in `ClusterTrafficRole` references?
144
+
304
145
* I'm not sure `kind: pod` and `name: *` is the best solution for generic allow
305
146
policies. Is there a better way to do it? `kind : *` feels wrong as well.
306
-
0 commit comments