-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrbac.yaml
More file actions
265 lines (246 loc) · 8.48 KB
/
Copy pathrbac.yaml
File metadata and controls
265 lines (246 loc) · 8.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# Minimum RBAC for the ORB Kubernetes provider running in-cluster.
#
# Apply with:
# kubectl apply -f docs/root/providers/k8s/rbac.yaml
#
# Scope:
# - Single-namespace mode. For multi-namespace mode duplicate the Role +
# RoleBinding per namespace, or upgrade to ClusterRole + ClusterRoleBinding
# for cluster-scoped watches (`namespaces: ["*"]`).
#
# Adjust:
# - `metadata.namespace` to match where ORB runs.
# - The verbs list to drop any handler you do not use (e.g. drop
# `apps` / `deployments` if you only use the Pod handler).
#
# Opt-in sections:
# - events_watch_enabled — events rule in the Role below
# - node_watch_enabled — nodes rule in the ClusterRole section below
# (always requires ClusterRole, even in single-namespace mode)
# - inbound_auth_enabled — TokenReview ClusterRoleBinding at the end
#
# References:
# - docs/root/providers/k8s/auth.md
# - docs/root/providers/k8s/configuration.md
apiVersion: v1
kind: Namespace
metadata:
name: orb
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: orb
namespace: orb
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: orb
namespace: orb
rules:
# Core — required for the Pod handler and for the watch task.
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch", "create", "patch", "delete"]
- apiGroups: [""]
resources: ["pods/status"]
verbs: ["get"]
# Pod logs — optional; useful for diagnosing handler creation failures.
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
# Events — required when `events_watch_enabled: true` (default: false).
# The events watcher streams CoreV1Api.list_event_for_all_namespaces
# filtered to involvedObject.kind=Node and caches Karpenter
# node-disruption events. A namespace-scoped Role suffices for
# single-namespace mode; upgrade to ClusterRole when namespaces=["*"].
# Omit this rule when events_watch_enabled is False.
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "list", "watch"]
# apps/v1 — required for the Deployment and StatefulSet handlers.
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets"]
verbs: ["get", "list", "watch", "create", "patch", "delete"]
- apiGroups: ["apps"]
resources: ["deployments/status", "statefulsets/status"]
verbs: ["get"]
# Scale subresource — required for Deployment/StatefulSet handlers and
# for START_INSTANCES / STOP_INSTANCES (scale to 0 / restore replicas).
- apiGroups: ["apps"]
resources: ["deployments/scale", "statefulsets/scale"]
verbs: ["get", "patch"]
# batch/v1 — required for the Job handler.
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list", "watch", "create", "patch", "delete"]
- apiGroups: ["batch"]
resources: ["jobs/status"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: orb
namespace: orb
subjects:
- kind: ServiceAccount
name: orb
namespace: orb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: orb
# ---------------------------------------------------------------------------
# Cluster-scoped variant
# ---------------------------------------------------------------------------
# Use this section INSTEAD of the Role + RoleBinding above when you set
# `namespaces: ["*"]` in K8sProviderConfig (cluster-scoped watch mode).
# The watcher must be able to list/watch the target resource types across all
# namespaces; a namespaced Role cannot grant that.
#
# Apply with:
# kubectl apply -f docs/root/providers/k8s/rbac-cluster-scoped.yaml
# or inline by replacing the Role + RoleBinding section above.
#
# NOTE: ClusterRole + ClusterRoleBinding grant permissions cluster-wide.
# Review with your security team before applying in shared clusters.
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: orb
labels:
app.kubernetes.io/name: orb
app.kubernetes.io/component: cluster-scoped-watch
rules:
# Core — required for the Pod handler and for the cluster-scoped watch task.
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch", "create", "patch", "delete"]
- apiGroups: [""]
resources: ["pods/status"]
verbs: ["get"]
# Pod logs — optional; useful for diagnosing handler creation failures.
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
# Events — required when `events_watch_enabled: true` (default: false).
# See events_watch_enabled note in the Role section above.
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "list", "watch"]
# Nodes — required when `node_watch_enabled: true` (default: false).
# The node watcher streams CoreV1Api.list_node to cache per-node metadata
# (instance type, availability zone, capacity type, CPU/memory capacity)
# and enriches per-instance provider_data in get_status responses.
# Nodes are cluster-scoped; a namespaced Role cannot grant this permission.
# This rule is always placed here (not in the namespaced Role) because
# node access is inherently cluster-scoped regardless of provider mode.
# Omit this rule when node_watch_enabled is False (the default).
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
# apps/v1 — required for the Deployment and StatefulSet handlers.
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets"]
verbs: ["get", "list", "watch", "create", "patch", "delete"]
- apiGroups: ["apps"]
resources: ["deployments/status", "statefulsets/status"]
verbs: ["get"]
# Scale subresource — required for Deployment/StatefulSet handlers and
# for START_INSTANCES / STOP_INSTANCES.
- apiGroups: ["apps"]
resources: ["deployments/scale", "statefulsets/scale"]
verbs: ["get", "patch"]
# batch/v1 — required for the Job handler.
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list", "watch", "create", "patch", "delete"]
- apiGroups: ["batch"]
resources: ["jobs/status"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: orb
labels:
app.kubernetes.io/name: orb
app.kubernetes.io/component: cluster-scoped-watch
subjects:
- kind: ServiceAccount
name: orb
namespace: orb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: orb
# ---------------------------------------------------------------------------
# Inbound TokenReview auth (opt-in via inbound_auth_enabled: true)
# ---------------------------------------------------------------------------
# Required when `inbound_auth_enabled: true` in K8sProviderConfig.
#
# The KubeAuthStrategy validates caller Bearer tokens by submitting them
# to the `authentication.k8s.io/v1 TokenReview` API. The ORB pod's
# ServiceAccount must be able to create TokenReview objects.
#
# Option A (recommended): bind the standard system:auth-delegator ClusterRole,
# which grants exactly `tokenreviews: create` on authentication.k8s.io.
#
# Option B: create a targeted ClusterRole granting only tokenreviews: create
# (shown below, commented out).
#
# Uncomment ONE of the two options below when inbound_auth_enabled=true.
# Leave both commented out (the default) when inbound_auth_enabled=false.
#
# See docs/root/providers/k8s/auth.md for role-mapping configuration.
# --- Option A: bind system:auth-delegator (recommended) ---
#
# apiVersion: rbac.authorization.k8s.io/v1
# kind: ClusterRoleBinding
# metadata:
# name: orb-auth-delegator
# labels:
# app.kubernetes.io/name: orb
# app.kubernetes.io/component: inbound-auth
# subjects:
# - kind: ServiceAccount
# name: orb
# namespace: orb
# roleRef:
# apiGroup: rbac.authorization.k8s.io
# kind: ClusterRole
# name: system:auth-delegator
# --- Option B: targeted ClusterRole + ClusterRoleBinding ---
#
# apiVersion: rbac.authorization.k8s.io/v1
# kind: ClusterRole
# metadata:
# name: orb-tokenreview
# labels:
# app.kubernetes.io/name: orb
# app.kubernetes.io/component: inbound-auth
# rules:
# - apiGroups: ["authentication.k8s.io"]
# resources: ["tokenreviews"]
# verbs: ["create"]
#
# ---
#
# apiVersion: rbac.authorization.k8s.io/v1
# kind: ClusterRoleBinding
# metadata:
# name: orb-tokenreview
# labels:
# app.kubernetes.io/name: orb
# app.kubernetes.io/component: inbound-auth
# subjects:
# - kind: ServiceAccount
# name: orb
# namespace: orb
# roleRef:
# apiGroup: rbac.authorization.k8s.io
# kind: ClusterRole
# name: orb-tokenreview