Repository navigation
Expand file tree
/
Copy pathconfig_rbac.go.html
More file actions
453 lines (444 loc) · 24.8 KB
/
Copy pathconfig_rbac.go.html
File metadata and controls
453 lines (444 loc) · 24.8 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
{{/* Copyright (c) ClaceIO, LLC */}}
{{/* SPDX-License-Identifier: Apache-2.0 */}}
{{/* RBAC configuration sub page (/config/rbac): staged-changes banner with
publish and discard, RBAC groups/roles/grants tables (staged view when a
draft exists). Changes are staged and go live on publish, unlike the
other config sections. HTMX partial: block rbac_content
*/}}
{{ template "page_open" (dict "Ctx" . "Main" "max-w-6xl") }}
<div id="rbac-content" class="space-y-4">
{{ block "rbac_content" . }}
<!-- Header -->
<div
class="page-header flex items-center gap-2 flex-wrap mb-2 md:mb-6">
{{ template "hamburger" . }}
<div>
{{ template "page_title" (dict "Title" "Configuration" "Help" .Data.HelpUrl) }}
<nav
aria-label="Breadcrumb"
class="breadcrumbs text-xs text-base-content/70 p-0">
<ul>
<li>
<a href="{{ .AppPath }}/config">Configuration</a>
</li>
<li>RBAC</li>
</ul>
</nav>
<h2 class="text-xl font-semibold">RBAC</h2>
<p class="page-desc text-sm text-base-content/70">
Role based access control - staged changes go live on
publish
</p>
</div>
</div>
{{ template "page_progress" }}
{{ if .Data.Error }}
{{ template "error_alert" .Data.Error }}
{{ else }}
{{ template "flash_alerts" .Data }}
{{ $view := .Data.View }}
{{ $viewLive := .Data.ViewLive }}
{{ $canEdit := and (index .Data.Perms "config:update") (not $viewLive) }}
{{ $editTitle := "requires config:update" }}
{{ if $viewLive }}
{{ $editTitle = "read-only live view - switch to the staged draft to edit" }}
{{ end }}
{{ if .Data.HasStaged }}
<!-- Staged changes banner. The alert is a GRID (flex-wrap
does nothing): without alert-vertical the message column
gets crushed to a sliver on mobile and the buttons
overflow the right edge. alert-vertical stacks
icon/text/buttons below sm; the justify-items-start +
text-start utilities undo its centering (long sentences
read left-aligned) -->
<div
role="alert"
class="alert alert-vertical sm:alert-horizontal alert-info alert-soft py-2 text-sm justify-items-start text-start">
<span aria-hidden="true">⧗</span>
<span>
Staged changes by
<b>{{ .Data.Draft.created_by }}</b>
({{ template "time_ago" .Data.Draft.create_time }}{{ if ne .Data.Draft.updated_by .Data.Draft.created_by }}
, last edit by
<b>{{ .Data.Draft.updated_by }}</b>
{{ template "time_ago" .Data.Draft.update_time }}
{{ end }})
-
{{ if .Data.Diff.groups }}
groups:
{{ range $i, $n := .Data.Diff.groups }}
{{ if $i }},{{ end }}<span
class="font-mono text-xs break-all"
>{{ $n }}</span
>
{{- end }},
{{ end }}
{{ if .Data.Diff.roles }}
roles:
{{ range $i, $n := .Data.Diff.roles }}
{{ if $i }},{{ end }}<span
class="font-mono text-xs break-all"
>{{ $n }}</span
>
{{- end }},
{{ end }}
{{ if .Data.Diff.grants }}
grants changed,
{{ end }}
enforcement still uses the live config
</span>
<div class="ml-auto flex flex-wrap items-center justify-end gap-2">
{{ if $viewLive }}
<button
class="btn btn-xs btn-ghost tooltip tooltip-top"
data-tip="Show the staged draft in the tables below"
hx-get="{{ .AppPath }}/config/rbac"
hx-push-url="true"
hx-target="#rbac-content"
hx-swap="innerHTML"
hx-indicator="#page-progress">
View staged draft
</button>
{{ else }}
<button
class="btn btn-xs btn-ghost tooltip tooltip-top"
data-tip="Show the live config (what enforcement uses) in the tables below"
hx-get="{{ .AppPath }}/config/rbac?view=live"
hx-push-url="true"
hx-target="#rbac-content"
hx-swap="innerHTML"
hx-indicator="#page-progress">
View live config
</button>
{{ end }}
<button
class="btn btn-xs btn-ghost {{ if not (index .Data.Perms "config:update") }}tooltip{{ end }}"
{{ if index .Data.Perms "config:update" }}
hx-post="{{ .AppPath }}/config/rbac/action"
hx-vals='{"action": "discard", "draft_version":
"{{ .Data.DraftVersion }}"}' hx-confirm="Discard the
staged changes started by
{{ .Data.Draft.created_by }}
(last edit by {{ .Data.Draft.updated_by }})? This
cannot be undone." hx-target="#rbac-content"
hx-swap="innerHTML"
hx-disable="this" hx-indicator="#page-progress"
{{ else }}
disabled data-tip="requires config:update"
{{ end }}>
Discard
</button>
<button
class="btn btn-xs btn-primary {{ if not (index .Data.Perms "config:update") }}tooltip{{ end }}"
{{ if index .Data.Perms "config:update" }}
hx-post="{{ .AppPath }}/config/rbac/action"
hx-vals='{"action": "publish", "draft_version":
"{{ .Data.DraftVersion }}"}' hx-confirm="Publish the
staged RBAC configuration? It is validated and becomes
live immediately." hx-target="#rbac-content"
hx-swap="innerHTML"
hx-disable="this" hx-indicator="#page-progress"
{{ else }}
disabled data-tip="requires config:update"
{{ end }}>
Publish
</button>
{{ if and .Data.FlashError (contains "force" .Data.FlashError) (index .Data.Perms "config:update") }}
<button
class="btn btn-xs btn-warning"
hx-post="{{ .AppPath }}/config/rbac/action"
hx-vals='{"action": "publish", "draft_version": "{{ .Data.DraftVersion }}", "force": "true"}'
hx-confirm="Force publish, overriding the failed safety check? Make sure you reviewed the warning."
hx-target="#rbac-content"
hx-swap="innerHTML"
hx-disable="this"
hx-indicator="#page-progress">
Force publish
</button>
{{ end }}
</div>
</div>
{{ end }}
<!-- RBAC status card; the groups/roles/grants tables render
as their own cards below (the bindings-page per-group card
pattern) so the sections read as distinct tables -->
{{/* Rendered only when it has a state to show; the page
heading already describes RBAC */}}
{{ if or (not .AppRBACEnabled) .Data.HasStaged }}
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 flex items-center gap-2 flex-wrap">
<h2 class="text-sm font-medium">RBAC status</h2>
{{ if not .AppRBACEnabled }}
<span
class="badge badge-warning badge-sm badge-soft tooltip tooltip-top"
data-tip="security.unsafe_disable_rbac is set on this server: grants are not enforced"
>not enforced</span
>
{{ end }}
{{ if .Data.HasStaged }}
{{ if $viewLive }}
<span
class="badge badge-info badge-sm badge-soft tooltip tooltip-top"
data-tip="the tables below show the live config, which enforcement uses; a staged draft is pending"
>live view</span
>
{{ else }}
<span
class="badge badge-warning badge-sm badge-soft tooltip tooltip-top"
data-tip="the tables below show the staged draft"
>pending</span
>
{{ end }}
{{ end }}
</div>
</div>
{{ end }}
<!-- Groups card -->
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<h3 class="text-sm font-medium">Groups</h3>
<span class="text-xs text-base-content/70"
>{{ template "count" (dict "N" (len $view.groups) "One" "group") }} - user id lists, usable
in grants</span
>
{{ if not $viewLive }}
{{ template "perm_link" (dict "Allowed" $canEdit "Href" (print .AppPath "/config/rbac/group") "Label" "+ Add group" "Class" "btn-xs btn-outline ml-auto" "DeniedTip" $editTitle "Pos" "tooltip-left") }}
{{ end }}
</div>
{{ if $view.groups }}
<div class="overflow-x-auto">
<table class="table table-sm">
<tbody>
{{ range $view.groups }}
<tr class="group hover:bg-base-200/60">
<td
class="font-mono text-xs font-medium w-48">
{{ .name }}
</td>
<td>
{{ range .users }}
<span
class="badge badge-ghost badge-xs font-mono"
>{{ . }}</span
>
{{ end }}
</td>
{{ if not $viewLive }}
<td
class="text-right whitespace-nowrap w-32">
<div
class="inline-flex items-center gap-0.5">
{{ template "perm_link" (dict "Allowed" $canEdit "Href" (print $.AppPath "/config/rbac/group") "QueryKey" "name" "QueryValue" .name "Label" "edit" "Class" "btn-xs btn-ghost" "DeniedTip" $editTitle "Pos" "tooltip-left" "AriaLabel" (print "Edit group " .name)) }}
<button
class="btn btn-xs btn-ghost text-error {{ if not ($canEdit) }}tooltip tooltip-left{{ end }}"
{{ if $canEdit }}
hx-post="{{ $.AppPath }}/config/rbac/action"
aria-label="Delete group {{ .name }}" hx-vals='{"action":
"delete_group", "name":
"{{ .name }}", "draft_version":
"{{ $.Data.DraftVersion }}"}'
hx-confirm="Delete group
{{ .name }}
from the staged config?"
hx-target="#rbac-content"
hx-swap="innerHTML"
hx-disable="this"
hx-indicator="#page-progress"
{{ else }}
disabled data-tip="{{ $editTitle }}"
{{ end }}>
delete
</button>
</div>
</td>
{{ end }}
</tr>
{{ end }}
</tbody>
</table>
</div>
{{ else }}
<p class="px-4 py-3 text-xs text-base-content/70">
No groups defined
</p>
{{ end }}
</div>
<!-- Roles card -->
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<h3 class="text-sm font-medium">Roles</h3>
<span class="text-xs text-base-content/70"
>{{ template "count" (dict "N" (len $view.roles) "One" "role") }} - permission sets; the
built-in <span class="font-mono">admin</span> role
always exists</span
>
{{ if not $viewLive }}
{{ template "perm_link" (dict "Allowed" $canEdit "Href" (print .AppPath "/config/rbac/role") "Label" "+ Add role" "Class" "btn-xs btn-outline ml-auto" "DeniedTip" $editTitle "Pos" "tooltip-left") }}
{{ end }}
</div>
{{ if $view.roles }}
<div class="overflow-x-auto">
<table class="table table-sm">
<tbody>
{{ range $view.roles }}
<tr class="group hover:bg-base-200/60">
<td
class="font-mono text-xs font-medium w-48">
{{ .name }}
</td>
<td>
{{ range .permissions }}
<span
class="badge badge-soft badge-primary badge-xs font-mono"
>{{ . }}</span
>
{{ end }}
</td>
{{ if not $viewLive }}
<td
class="text-right whitespace-nowrap w-32">
<div
class="inline-flex items-center gap-0.5">
{{ template "perm_link" (dict "Allowed" $canEdit "Href" (print $.AppPath "/config/rbac/role") "QueryKey" "name" "QueryValue" .name "Label" "edit" "Class" "btn-xs btn-ghost" "DeniedTip" $editTitle "Pos" "tooltip-left" "AriaLabel" (print "Edit role " .name)) }}
<button
class="btn btn-xs btn-ghost text-error {{ if not ($canEdit) }}tooltip tooltip-left{{ end }}"
{{ if $canEdit }}
hx-post="{{ $.AppPath }}/config/rbac/action"
aria-label="Delete role {{ .name }}"
hx-vals='{"action": "delete_role",
"name": "{{ .name }}",
"draft_version":
"{{ $.Data.DraftVersion }}"}'
hx-confirm="Delete role
{{ .name }}
from the staged config? Publish
fails while grants still reference
it." hx-target="#rbac-content"
hx-swap="innerHTML"
hx-disable="this"
hx-indicator="#page-progress"
{{ else }}
disabled data-tip="{{ $editTitle }}"
{{ end }}>
delete
</button>
</div>
</td>
{{ end }}
</tr>
{{ end }}
</tbody>
</table>
</div>
{{ else }}
<p class="px-4 py-3 text-xs text-base-content/70">
No roles defined
</p>
{{ end }}
</div>
<!-- Grants card -->
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<h3 class="text-sm font-medium">Grants</h3>
<span class="text-xs text-base-content/70"
>{{ template "count" (dict "N" (len $view.grants) "One" "grant") }} - who gets which roles
on which apps, services and bindings</span
>
{{ if not $viewLive }}
{{ template "perm_link" (dict "Allowed" $canEdit "Href" (print .AppPath "/config/rbac/grant") "Label" "+ Add grant" "Class" "btn-xs btn-outline ml-auto" "DeniedTip" $editTitle "Pos" "tooltip-left") }}
{{ end }}
</div>
{{ if $view.grants }}
<div class="overflow-x-auto">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">Description</th>
<th scope="col">Users / groups</th>
<th scope="col">Roles</th>
<th scope="col">Targets</th>
{{ if not $viewLive }}
<th scope="col" class="text-right">
Actions
</th>
{{ end }}
</tr>
</thead>
<tbody>
{{ range $view.grants }}
<tr class="group hover:bg-base-200/60">
<td class="text-xs">{{ .description }}</td>
<td>
{{ range .users }}
<span
class="badge badge-ghost badge-xs font-mono"
>{{ . }}</span
>
{{ end }}
</td>
<td>
{{ range .roles }}
<span
class="badge badge-soft badge-secondary badge-xs font-mono"
>{{ . }}</span
>
{{ end }}
</td>
<td>
{{ range .targets }}
<span class="font-mono text-xs break-all"
>{{ . }}</span
>
{{ end }}
</td>
{{ if not $viewLive }}
<td
class="text-right whitespace-nowrap w-32">
<div
class="inline-flex items-center gap-0.5">
{{ template "perm_link" (dict "Allowed" $canEdit "Href" (print $.AppPath "/config/rbac/grant") "QueryKey" "index" "QueryValue" .index "Label" "edit" "Class" "btn-xs btn-ghost" "DeniedTip" $editTitle "Pos" "tooltip-left" "AriaLabel" (print "Edit grant " .description)) }}
<button
class="btn btn-xs btn-ghost text-error {{ if not ($canEdit) }}tooltip tooltip-left{{ end }}"
{{ if $canEdit }}
hx-post="{{ $.AppPath }}/config/rbac/action"
aria-label="Delete grant {{ .description }}"
hx-vals='{"action": "delete_grant",
"index": "{{ .index }}",
"draft_version":
"{{ $.Data.DraftVersion }}"}'
hx-confirm="Delete this grant from
the staged config?"
hx-target="#rbac-content"
hx-swap="innerHTML"
hx-disable="this"
hx-indicator="#page-progress"
{{ else }}
disabled data-tip="{{ $editTitle }}"
{{ end }}>
delete
</button>
</div>
</td>
{{ end }}
</tr>
{{ end }}
</tbody>
</table>
</div>
{{ else }}
<p class="px-4 py-3 text-xs text-base-content/70">
No grants defined - only admins could access apps or
use the management APIs; publishing requires at
least one grant
</p>
{{ end }}
</div>
{{ end }}
{{ end }}
<!-- End of "rbac_content" block -->
</div>
{{ template "page_close" . }}