@spechtlabs/backstage-plugin-tailscale 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,831 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { useMemo, useState } from 'react';
3
+ import { useSearchParams } from 'react-router-dom';
4
+ import { Content, Progress, ResponseErrorPanel } from '@backstage/core-components';
5
+ import { stringifyEntityRef } from '@backstage/catalog-model';
6
+ import { useEntity } from '@backstage/plugin-catalog-react';
7
+ import PolicyIcon from '@material-ui/icons/Policy';
8
+ import OverviewIcon from '@material-ui/icons/Dashboard';
9
+ import GrantIcon from '@material-ui/icons/CallMerge';
10
+ import SshIcon from '@material-ui/icons/Lock';
11
+ import PreviewIcon from '@material-ui/icons/Visibility';
12
+ import GroupIcon from '@material-ui/icons/People';
13
+ import TagIcon from '@material-ui/icons/LocalOffer';
14
+ import HostIcon from '@material-ui/icons/Computer';
15
+ import AttrIcon from '@material-ui/icons/Tune';
16
+ import ApproveIcon from '@material-ui/icons/DoneAll';
17
+ import TestIcon from '@material-ui/icons/PlaylistAddCheck';
18
+ import FileIcon from '@material-ui/icons/Description';
19
+ import SearchIcon from '@material-ui/icons/Search';
20
+ import DownloadIcon from '@material-ui/icons/GetApp';
21
+ import CopyIcon from '@material-ui/icons/FileCopy';
22
+ import ErrorIcon from '@material-ui/icons/Error';
23
+ import WarningIcon from '@material-ui/icons/Warning';
24
+ import HealthyIcon from '@material-ui/icons/VerifiedUser';
25
+ import CatalogIcon from '@material-ui/icons/AccountTree';
26
+ import PullRequestIcon from '@material-ui/icons/CallSplit';
27
+ import OwnerIcon from '@material-ui/icons/Group';
28
+ import CheckIcon from '@material-ui/icons/Schedule';
29
+ import PushIcon from '@material-ui/icons/Publish';
30
+ import { AccessMap } from './AccessMap.esm.js';
31
+ import { CodeView } from './CodeView.esm.js';
32
+ import { Preview } from './Preview.esm.js';
33
+ import { useOverview, Empty, LineLink, matches, EntityLink, plural, since, entityName } from './primitives.esm.js';
34
+ import { TestGroup, ApproverRow, NodeAttrRow, TagRow, GroupCard, SshRow, GrantRow, FlowHeader } from './rules.esm.js';
35
+ import '../tailscale.css.esm.js';
36
+
37
+ const SECTIONS = [
38
+ {
39
+ id: "overview",
40
+ label: "Overview",
41
+ icon: /* @__PURE__ */ jsx(OverviewIcon, { fontSize: "inherit" })
42
+ },
43
+ {
44
+ heading: "Access",
45
+ id: "grants",
46
+ label: "Grants",
47
+ icon: /* @__PURE__ */ jsx(GrantIcon, { fontSize: "inherit" }),
48
+ count: (p) => p.grants.length
49
+ },
50
+ {
51
+ id: "ssh",
52
+ label: "Tailscale SSH",
53
+ icon: /* @__PURE__ */ jsx(SshIcon, { fontSize: "inherit" }),
54
+ count: (p) => p.ssh.length
55
+ },
56
+ {
57
+ id: "preview",
58
+ label: "Preview access",
59
+ icon: /* @__PURE__ */ jsx(PreviewIcon, { fontSize: "inherit" })
60
+ },
61
+ {
62
+ heading: "Identity",
63
+ id: "groups",
64
+ label: "Groups",
65
+ icon: /* @__PURE__ */ jsx(GroupIcon, { fontSize: "inherit" }),
66
+ count: (p) => p.groups.length
67
+ },
68
+ {
69
+ id: "tags",
70
+ label: "Tags",
71
+ icon: /* @__PURE__ */ jsx(TagIcon, { fontSize: "inherit" }),
72
+ count: (p) => p.tags.length
73
+ },
74
+ {
75
+ id: "hosts",
76
+ label: "Hosts",
77
+ icon: /* @__PURE__ */ jsx(HostIcon, { fontSize: "inherit" }),
78
+ count: (p) => p.hosts.length
79
+ },
80
+ {
81
+ heading: "Devices",
82
+ id: "nodeAttrs",
83
+ label: "Node attributes",
84
+ icon: /* @__PURE__ */ jsx(AttrIcon, { fontSize: "inherit" }),
85
+ count: (p) => p.nodeAttrs.length
86
+ },
87
+ {
88
+ id: "autoApprovers",
89
+ label: "Auto approvers",
90
+ icon: /* @__PURE__ */ jsx(ApproveIcon, { fontSize: "inherit" }),
91
+ count: (p) => p.autoApprovers.length
92
+ },
93
+ {
94
+ heading: "Verify",
95
+ id: "tests",
96
+ label: "Tests",
97
+ icon: /* @__PURE__ */ jsx(TestIcon, { fontSize: "inherit" }),
98
+ count: (p) => p.tests.length
99
+ },
100
+ { id: "file", label: "Policy file", icon: /* @__PURE__ */ jsx(FileIcon, { fontSize: "inherit" }) }
101
+ ];
102
+ const TYPE_LABEL = {
103
+ policy: "Policy",
104
+ grant: "Grants",
105
+ ssh: "SSH rules",
106
+ tag: "Tags",
107
+ nodeAttr: "Node attributes",
108
+ autoApprovers: "Auto approvers",
109
+ test: "Tests"
110
+ };
111
+ function download(policy) {
112
+ const url = URL.createObjectURL(
113
+ new Blob([policy.text], { type: "application/json" })
114
+ );
115
+ const a = document.createElement("a");
116
+ a.href = url;
117
+ a.download = `${policy.name}.hujson`;
118
+ a.click();
119
+ URL.revokeObjectURL(url);
120
+ }
121
+ function PublishMeta(props) {
122
+ const p = props.publish;
123
+ const where = `${p.repo}: ${p.path}${p.branch ? ` on ${p.branch}` : ""}`;
124
+ const verb = p.flow === "push" ? "Pushes to" : "Pull request in";
125
+ if (p.problem) {
126
+ return /* @__PURE__ */ jsxs("span", { title: where, className: "ts-warning", children: [
127
+ /* @__PURE__ */ jsx(WarningIcon, { fontSize: "inherit" }),
128
+ "Not published: ",
129
+ p.problem
130
+ ] });
131
+ }
132
+ return /* @__PURE__ */ jsxs(
133
+ "span",
134
+ {
135
+ title: `${where}${p.last ? ` \xB7 last run ${since(p.last.at)}: ${p.last.outcome}` : ""}${p.last?.error ? ` (${p.last.error})` : ""}`,
136
+ children: [
137
+ p.flow === "push" ? /* @__PURE__ */ jsx(PushIcon, { fontSize: "inherit" }) : /* @__PURE__ */ jsx(PullRequestIcon, { fontSize: "inherit" }),
138
+ p.last?.url ? /* @__PURE__ */ jsxs("a", { href: p.last.url, target: "_blank", rel: "noreferrer", children: [
139
+ verb,
140
+ " ",
141
+ p.repo
142
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
143
+ verb,
144
+ " ",
145
+ p.repo,
146
+ p.last ? ` \xB7 ${p.last.outcome}` : ""
147
+ ] })
148
+ ]
149
+ }
150
+ );
151
+ }
152
+ function Hero(props) {
153
+ const { policy, overview } = props;
154
+ const publish = overview.publish[policy.entityRef];
155
+ const [copied, setCopied] = useState(false);
156
+ return /* @__PURE__ */ jsxs("div", { className: "ts-hero", children: [
157
+ /* @__PURE__ */ jsxs(
158
+ "div",
159
+ {
160
+ className: "ts-row",
161
+ style: { alignItems: "flex-start", gap: 14, flexWrap: "nowrap" },
162
+ children: [
163
+ /* @__PURE__ */ jsx("span", { className: "ts-hero-mark", "aria-hidden": true, children: /* @__PURE__ */ jsx(PolicyIcon, {}) }),
164
+ /* @__PURE__ */ jsxs("div", { children: [
165
+ /* @__PURE__ */ jsx("h1", { children: policy.title ?? policy.name }),
166
+ policy.tailnet ? /* @__PURE__ */ jsx("div", { className: "ts-mono ts-muted", children: policy.tailnet }) : null,
167
+ policy.description ? /* @__PURE__ */ jsx("p", { className: "ts-muted", children: policy.description }) : null,
168
+ /* @__PURE__ */ jsxs("div", { className: "ts-meta", children: [
169
+ policy.owner ? /* @__PURE__ */ jsxs("span", { children: [
170
+ /* @__PURE__ */ jsx(OwnerIcon, { fontSize: "inherit" }),
171
+ /* @__PURE__ */ jsx(
172
+ EntityLink,
173
+ {
174
+ entityRef: policy.owner.includes(":") ? policy.owner : `group:${policy.owner}`
175
+ }
176
+ )
177
+ ] }) : null,
178
+ /* @__PURE__ */ jsxs("span", { children: [
179
+ /* @__PURE__ */ jsx(CatalogIcon, { fontSize: "inherit" }),
180
+ /* @__PURE__ */ jsx(EntityLink, { entityRef: policy.entityRef, children: plural(policy.parts.length, "entity", "entities") })
181
+ ] }),
182
+ /* @__PURE__ */ jsxs("span", { title: new Date(policy.renderedAt).toLocaleString(), children: [
183
+ /* @__PURE__ */ jsx(CheckIcon, { fontSize: "inherit" }),
184
+ "Rendered ",
185
+ since(policy.renderedAt)
186
+ ] }),
187
+ publish ? /* @__PURE__ */ jsx(PublishMeta, { publish }) : null
188
+ ] })
189
+ ] })
190
+ ]
191
+ }
192
+ ),
193
+ /* @__PURE__ */ jsxs("div", { className: "ts-row", children: [
194
+ overview.policies.length > 1 ? /* @__PURE__ */ jsx(
195
+ "select",
196
+ {
197
+ className: "ts-select",
198
+ "aria-label": "Policy",
199
+ style: { minWidth: 0 },
200
+ value: policy.name,
201
+ onChange: (e) => props.onPolicy(e.target.value),
202
+ children: overview.policies.map((p) => /* @__PURE__ */ jsx("option", { value: p.name, children: p.title ?? p.name }, p.entityRef))
203
+ }
204
+ ) : null,
205
+ /* @__PURE__ */ jsxs(
206
+ "button",
207
+ {
208
+ type: "button",
209
+ className: "ts-button",
210
+ onClick: () => navigator.clipboard?.writeText(policy.text).then(() => {
211
+ setCopied(true);
212
+ setTimeout(() => setCopied(false), 1500);
213
+ }),
214
+ children: [
215
+ /* @__PURE__ */ jsx(CopyIcon, { fontSize: "inherit" }),
216
+ copied ? "Copied" : "Copy"
217
+ ]
218
+ }
219
+ ),
220
+ /* @__PURE__ */ jsxs(
221
+ "button",
222
+ {
223
+ type: "button",
224
+ className: "ts-button ts-button-primary",
225
+ onClick: () => download(policy),
226
+ children: [
227
+ /* @__PURE__ */ jsx(DownloadIcon, { fontSize: "inherit" }),
228
+ "Download policy"
229
+ ]
230
+ }
231
+ )
232
+ ] })
233
+ ] });
234
+ }
235
+ function SectionHeader(props) {
236
+ return /* @__PURE__ */ jsxs(
237
+ "div",
238
+ {
239
+ className: "ts-row",
240
+ style: { alignItems: "flex-end", marginBottom: 16 },
241
+ children: [
242
+ /* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 260 }, children: [
243
+ /* @__PURE__ */ jsx("h2", { className: "ts-section-title", children: props.title }),
244
+ props.lede ? /* @__PURE__ */ jsx("p", { className: "ts-section-lede", style: { margin: 0 }, children: props.lede }) : null
245
+ ] }),
246
+ props.children
247
+ ]
248
+ }
249
+ );
250
+ }
251
+ function Search(props) {
252
+ return /* @__PURE__ */ jsxs("label", { className: "ts-search", children: [
253
+ /* @__PURE__ */ jsx(SearchIcon, { fontSize: "inherit" }),
254
+ /* @__PURE__ */ jsx(
255
+ "input",
256
+ {
257
+ type: "search",
258
+ value: props.value,
259
+ placeholder: props.placeholder ?? "Filter: tag:ceph, group:admins, 443 \u2026",
260
+ onChange: (e) => props.onChange(e.target.value),
261
+ "aria-label": "Filter"
262
+ }
263
+ )
264
+ ] });
265
+ }
266
+ function Problems(props) {
267
+ if (!props.diagnostics.length) {
268
+ return /* @__PURE__ */ jsxs("div", { className: "ts-healthy", children: [
269
+ /* @__PURE__ */ jsx(HealthyIcon, { fontSize: "inherit" }),
270
+ "Every selector resolves: each group is a Backstage Group, each tag is declared, each host is known."
271
+ ] });
272
+ }
273
+ return /* @__PURE__ */ jsx("div", { children: props.diagnostics.map((d, i) => /* @__PURE__ */ jsxs("div", { className: `ts-problem ts-problem-${d.severity}`, children: [
274
+ d.severity === "error" ? /* @__PURE__ */ jsx(ErrorIcon, { fontSize: "inherit" }) : /* @__PURE__ */ jsx(WarningIcon, { fontSize: "inherit" }),
275
+ /* @__PURE__ */ jsxs("div", { children: [
276
+ d.entityRef ? /* @__PURE__ */ jsx("div", { className: "ts-small", children: /* @__PURE__ */ jsx(EntityLink, { entityRef: d.entityRef }) }) : null,
277
+ /* @__PURE__ */ jsx("div", { children: d.message })
278
+ ] })
279
+ ] }, i)) });
280
+ }
281
+ function OverviewSection(props) {
282
+ const { policy, go } = props;
283
+ const fromCatalog = policy.grants.filter((g) => g.origin === "catalog").length;
284
+ const catalogEdges = (via) => policy.grants.flatMap((g) => g.edges ?? []).filter((e) => e.via === via).length;
285
+ const stats = [
286
+ [
287
+ "grants",
288
+ policy.grants.length,
289
+ "Grants",
290
+ /* @__PURE__ */ jsx(GrantIcon, { fontSize: "inherit" })
291
+ ],
292
+ ["ssh", policy.ssh.length, "SSH rules", /* @__PURE__ */ jsx(SshIcon, { fontSize: "inherit" })],
293
+ [
294
+ "groups",
295
+ policy.groups.length,
296
+ "Groups",
297
+ /* @__PURE__ */ jsx(GroupIcon, { fontSize: "inherit" })
298
+ ],
299
+ ["tags", policy.tags.length, "Tags", /* @__PURE__ */ jsx(TagIcon, { fontSize: "inherit" })],
300
+ [
301
+ "autoApprovers",
302
+ policy.autoApprovers.length,
303
+ "Auto-approved",
304
+ /* @__PURE__ */ jsx(ApproveIcon, { fontSize: "inherit" })
305
+ ],
306
+ ["tests", policy.tests.length, "Tests", /* @__PURE__ */ jsx(TestIcon, { fontSize: "inherit" })]
307
+ ];
308
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
309
+ /* @__PURE__ */ jsx("div", { className: "ts-stats", children: stats.map(([section, value, label, icon]) => /* @__PURE__ */ jsxs(
310
+ "button",
311
+ {
312
+ type: "button",
313
+ className: "ts-stat",
314
+ onClick: () => go(section),
315
+ children: [
316
+ /* @__PURE__ */ jsx("div", { className: "ts-stat-value", children: value }),
317
+ /* @__PURE__ */ jsxs("div", { className: "ts-stat-label", children: [
318
+ icon,
319
+ label
320
+ ] })
321
+ ]
322
+ },
323
+ section
324
+ )) }),
325
+ /* @__PURE__ */ jsxs("div", { className: "ts-card", children: [
326
+ /* @__PURE__ */ jsx("div", { className: "ts-card-head", children: /* @__PURE__ */ jsxs("div", { children: [
327
+ /* @__PURE__ */ jsx("h3", { children: "Access map" }),
328
+ /* @__PURE__ */ jsx("p", { children: "Every grant: sources on the left, what they reach on the right, by what it is. Dashed lines are capability grants. Hover a selector to trace it, click it to see its grants." })
329
+ ] }) }),
330
+ /* @__PURE__ */ jsx("div", { className: "ts-card-body", children: /* @__PURE__ */ jsx(
331
+ AccessMap,
332
+ {
333
+ grants: policy.grants,
334
+ destinations: policy.destinations,
335
+ onSelect: (name) => go("grants", { q: name })
336
+ }
337
+ ) })
338
+ ] }),
339
+ /* @__PURE__ */ jsxs("div", { className: "ts-card", children: [
340
+ /* @__PURE__ */ jsxs("div", { className: "ts-card-head", children: [
341
+ /* @__PURE__ */ jsxs("div", { children: [
342
+ /* @__PURE__ */ jsx("h3", { children: "Health" }),
343
+ /* @__PURE__ */ jsx("p", { children: "What the catalog says that the policy can't use." })
344
+ ] }),
345
+ /* @__PURE__ */ jsx("span", { className: "ts-spacer" }),
346
+ props.problems.length ? /* @__PURE__ */ jsx("span", { className: "ts-badge ts-badge-error", children: plural(props.problems.length, "problem") }) : null
347
+ ] }),
348
+ /* @__PURE__ */ jsx(Problems, { diagnostics: props.problems })
349
+ ] }),
350
+ policy.catalog.enabled ? /* @__PURE__ */ jsxs("div", { className: "ts-card", children: [
351
+ /* @__PURE__ */ jsx("div", { className: "ts-card-head", children: /* @__PURE__ */ jsxs("div", { children: [
352
+ /* @__PURE__ */ jsx("h3", { children: "From the catalog" }),
353
+ /* @__PURE__ */ jsx("p", { children: "Grants made from the services' own annotations: an API's specht-labs.de/tailnet-dst and -ports say where it is reached; every Component that consumes it across the tailnet reaches it as its tailnet-src (or the API's tailnet-client-tag), and whoever its tailnet-allow names may use it too." })
354
+ ] }) }),
355
+ /* @__PURE__ */ jsx("div", { className: "ts-card-body", children: /* @__PURE__ */ jsxs("dl", { className: "ts-kv", children: [
356
+ /* @__PURE__ */ jsx("dt", { children: "Grants" }),
357
+ /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsxs(
358
+ "button",
359
+ {
360
+ type: "button",
361
+ className: "ts-button",
362
+ onClick: () => go("grants", { origin: "catalog" }),
363
+ children: [
364
+ plural(fromCatalog, "grant"),
365
+ " from",
366
+ " ",
367
+ plural(catalogEdges("consumesApi"), "API consumption"),
368
+ " and",
369
+ " ",
370
+ plural(catalogEdges("tailnet-allow"), "tailnet-allow")
371
+ ]
372
+ }
373
+ ) }),
374
+ /* @__PURE__ */ jsx("dt", { children: "Already allowed" }),
375
+ /* @__PURE__ */ jsx("dd", { children: policy.catalog.covered.length ? policy.catalog.covered.map((c) => /* @__PURE__ */ jsxs("div", { className: "ts-small", children: [
376
+ /* @__PURE__ */ jsx(EntityLink, { entityRef: c.consumer }),
377
+ " \u2192",
378
+ " ",
379
+ /* @__PURE__ */ jsx(EntityLink, { entityRef: c.api }),
380
+ " ",
381
+ /* @__PURE__ */ jsx("span", { className: "ts-muted", children: "by" }),
382
+ " ",
383
+ c.coveredBy.map(
384
+ (id) => id.startsWith("tailscale:") ? /* @__PURE__ */ jsx(EntityLink, { entityRef: id }, id) : id
385
+ )
386
+ ] }, `${c.consumer}${c.api}`)) : /* @__PURE__ */ jsx("span", { className: "ts-muted ts-small", children: "No consumption that a grant entity already allows." }) }),
387
+ /* @__PURE__ */ jsx("dt", { children: "Inside a cluster" }),
388
+ /* @__PURE__ */ jsx("dd", { className: "ts-small", children: policy.catalog.local.length ? /* @__PURE__ */ jsxs("details", { className: "ts-details", style: { marginTop: 0 }, children: [
389
+ /* @__PURE__ */ jsxs("summary", { children: [
390
+ plural(policy.catalog.local.length, "consumption"),
391
+ " on the pod network, not the tailnet"
392
+ ] }),
393
+ /* @__PURE__ */ jsx("ul", { style: { margin: "6px 0 0", paddingLeft: 18 }, children: policy.catalog.local.map((l) => /* @__PURE__ */ jsxs("li", { children: [
394
+ /* @__PURE__ */ jsx(EntityLink, { entityRef: l.consumer }),
395
+ " \u2192",
396
+ " ",
397
+ /* @__PURE__ */ jsx(EntityLink, { entityRef: l.api }),
398
+ " ",
399
+ /* @__PURE__ */ jsxs("span", { className: "ts-muted", children: [
400
+ "in ",
401
+ entityName(l.cluster)
402
+ ] })
403
+ ] }, `${l.consumer}${l.api}`)) })
404
+ ] }) : /* @__PURE__ */ jsx("span", { className: "ts-muted", children: "None" }) })
405
+ ] }) })
406
+ ] }) : null
407
+ ] });
408
+ }
409
+ function List(props) {
410
+ if (!props.count) {
411
+ return /* @__PURE__ */ jsx("div", { className: "ts-card", children: /* @__PURE__ */ jsx(Empty, { icon: props.icon, children: props.empty }) });
412
+ }
413
+ return /* @__PURE__ */ jsxs("div", { className: "ts-card", children: [
414
+ props.columns ? /* @__PURE__ */ jsx(FlowHeader, { ...props.columns }) : null,
415
+ /* @__PURE__ */ jsx("div", { className: `ts-rules${props.columns ? " ts-rules-headed" : ""}`, children: props.children })
416
+ ] });
417
+ }
418
+ function FileSection(props) {
419
+ const { policy } = props;
420
+ const highlight = useMemo(() => {
421
+ if (props.focus) {
422
+ return policy.spans.filter((s) => s.entityRef === props.focus).map((s) => s.lines);
423
+ }
424
+ const m = /^(\d+)(?:-(\d+))?$/.exec(props.lines ?? "");
425
+ return m ? [[Number(m[1]), Number(m[2] ?? m[1])]] : [];
426
+ }, [policy, props.focus, props.lines]);
427
+ const byType = useMemo(() => {
428
+ const out = /* @__PURE__ */ new Map();
429
+ for (const part of policy.parts) {
430
+ out.set(part.type, [...out.get(part.type) ?? [], part]);
431
+ }
432
+ return out;
433
+ }, [policy]);
434
+ const lineCount = policy.text.split("\n").length - 1;
435
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
436
+ /* @__PURE__ */ jsx(
437
+ SectionHeader,
438
+ {
439
+ title: "Policy file",
440
+ lede: `The tailnet policy file, ${lineCount} lines, exactly as Tailscale gets it. Pick an entity to see what it renders to.`
441
+ }
442
+ ),
443
+ /* @__PURE__ */ jsxs("div", { className: "ts-file", children: [
444
+ /* @__PURE__ */ jsxs("div", { className: "ts-card", children: [
445
+ /* @__PURE__ */ jsxs("div", { className: "ts-card-head", children: [
446
+ /* @__PURE__ */ jsx(FileIcon, { fontSize: "inherit" }),
447
+ /* @__PURE__ */ jsxs("span", { className: "ts-mono", children: [
448
+ policy.name,
449
+ ".hujson"
450
+ ] }),
451
+ /* @__PURE__ */ jsx("span", { className: "ts-spacer" }),
452
+ props.focus ? /* @__PURE__ */ jsx(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ className: "ts-button",
457
+ onClick: () => props.onFocus(void 0),
458
+ children: "Clear selection"
459
+ }
460
+ ) : null
461
+ ] }),
462
+ /* @__PURE__ */ jsx(
463
+ CodeView,
464
+ {
465
+ text: policy.text,
466
+ highlight,
467
+ scroll: true,
468
+ lineHref: (n) => `?section=file&policy=${policy.name}&lines=${n}`
469
+ }
470
+ )
471
+ ] }),
472
+ /* @__PURE__ */ jsx("div", { className: "ts-card ts-outline", "aria-label": "Entities", children: [...byType.entries()].map(([type, parts]) => /* @__PURE__ */ jsxs("div", { children: [
473
+ /* @__PURE__ */ jsx("h4", { children: TYPE_LABEL[type] }),
474
+ parts.map((part) => /* @__PURE__ */ jsxs(
475
+ "button",
476
+ {
477
+ type: "button",
478
+ "aria-pressed": props.focus === part.entityRef,
479
+ onClick: () => props.onFocus(part.entityRef),
480
+ title: part.title,
481
+ children: [
482
+ /* @__PURE__ */ jsx(
483
+ "span",
484
+ {
485
+ style: {
486
+ flex: 1,
487
+ minWidth: 0,
488
+ overflow: "hidden",
489
+ textOverflow: "ellipsis",
490
+ whiteSpace: "nowrap"
491
+ },
492
+ children: part.title ?? part.name
493
+ }
494
+ ),
495
+ /* @__PURE__ */ jsx("span", { className: "ts-mono ts-muted", style: { fontSize: 11 }, children: part.lines[0] ? `L${part.lines[0][0]}` : "" })
496
+ ]
497
+ },
498
+ part.entityRef
499
+ ))
500
+ ] }, type)) })
501
+ ] })
502
+ ] });
503
+ }
504
+ function groupTests(tests) {
505
+ const out = /* @__PURE__ */ new Map();
506
+ for (const t of tests) {
507
+ const key = t.entityRef ?? t.id;
508
+ out.set(key, [...out.get(key) ?? [], t]);
509
+ }
510
+ return [...out.values()];
511
+ }
512
+ function PolicyConsole(props) {
513
+ const [params, setParams] = useSearchParams();
514
+ const { overview } = props;
515
+ const policy = overview.policies.find((p) => p.entityRef === props.policyRef) ?? overview.policies.find((p) => p.name === params.get("policy")) ?? overview.policies[0];
516
+ const section = params.get("section") || "overview";
517
+ const q = params.get("q") ?? "";
518
+ const origin = params.get("origin");
519
+ const update = (next, replace = false) => {
520
+ const p = new URLSearchParams(params);
521
+ for (const [k, v] of Object.entries(next)) {
522
+ if (v === void 0 || v === "") p.delete(k);
523
+ else p.set(k, v);
524
+ }
525
+ setParams(p, { replace });
526
+ };
527
+ const go = (s, extra = {}) => update({
528
+ section: s,
529
+ q: void 0,
530
+ origin: void 0,
531
+ lines: void 0,
532
+ focus: void 0,
533
+ ...extra
534
+ });
535
+ if (!policy) {
536
+ return /* @__PURE__ */ jsx(Empty, { icon: /* @__PURE__ */ jsx(PolicyIcon, {}), children: "No Tailscale policy in the catalog yet. Add an entity of kind Tailscale with spec.type: policy." });
537
+ }
538
+ const problems = [...policy.diagnostics, ...overview.orphans];
539
+ const filtered = (list) => list.filter((item) => matches(q, item));
540
+ const name = policy.name;
541
+ const searchBox = /* @__PURE__ */ jsx(Search, { value: q, onChange: (value) => update({ q: value }, true) });
542
+ let body;
543
+ switch (section) {
544
+ case "grants": {
545
+ const grants = filtered(policy.grants).filter(
546
+ (g) => !origin || g.origin === origin
547
+ );
548
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
549
+ /* @__PURE__ */ jsxs(
550
+ SectionHeader,
551
+ {
552
+ title: "Grants",
553
+ lede: "Who may reach what, on which ports, with which capabilities. Grants only allow: what no grant names is denied.",
554
+ children: [
555
+ /* @__PURE__ */ jsxs(
556
+ "select",
557
+ {
558
+ className: "ts-select",
559
+ style: { minWidth: 0 },
560
+ "aria-label": "Origin",
561
+ value: origin ?? "",
562
+ onChange: (e) => update({ origin: e.target.value }, true),
563
+ children: [
564
+ /* @__PURE__ */ jsx("option", { value: "", children: "All grants" }),
565
+ /* @__PURE__ */ jsx("option", { value: "entity", children: "Declared" }),
566
+ /* @__PURE__ */ jsx("option", { value: "catalog", children: "From the catalog" })
567
+ ]
568
+ }
569
+ ),
570
+ searchBox
571
+ ]
572
+ }
573
+ ),
574
+ /* @__PURE__ */ jsx(
575
+ List,
576
+ {
577
+ count: grants.length,
578
+ icon: /* @__PURE__ */ jsx(GrantIcon, {}),
579
+ columns: {},
580
+ empty: "No grant matches.",
581
+ children: grants.map((g) => /* @__PURE__ */ jsx(GrantRow, { grant: g, policy: name }, g.id))
582
+ }
583
+ )
584
+ ] });
585
+ break;
586
+ }
587
+ case "ssh": {
588
+ const rules = filtered(policy.ssh);
589
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
590
+ /* @__PURE__ */ jsx(
591
+ SectionHeader,
592
+ {
593
+ title: "Tailscale SSH",
594
+ lede: "Who may open a shell where, as which local user. Check mode asks for a fresh sign-in first.",
595
+ children: searchBox
596
+ }
597
+ ),
598
+ /* @__PURE__ */ jsx(
599
+ List,
600
+ {
601
+ count: rules.length,
602
+ icon: /* @__PURE__ */ jsx(SshIcon, {}),
603
+ columns: { right: "As" },
604
+ empty: "No SSH rule matches.",
605
+ children: rules.map((s) => /* @__PURE__ */ jsx(SshRow, { rule: s, policy: name }, s.id))
606
+ }
607
+ )
608
+ ] });
609
+ break;
610
+ }
611
+ case "preview":
612
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
613
+ /* @__PURE__ */ jsx(
614
+ SectionHeader,
615
+ {
616
+ title: "Preview access",
617
+ lede: "What the policy lets someone reach, or who reaches something, rule by rule."
618
+ }
619
+ ),
620
+ /* @__PURE__ */ jsx(Preview, { policy })
621
+ ] });
622
+ break;
623
+ case "groups": {
624
+ const groups = filtered(policy.groups);
625
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
626
+ /* @__PURE__ */ jsx(
627
+ SectionHeader,
628
+ {
629
+ title: "Groups",
630
+ lede: "Backstage Groups with a specht-labs.de/tailnet-group annotation, and their Users' tailnet logins. Change membership in the catalog.",
631
+ children: searchBox
632
+ }
633
+ ),
634
+ groups.length ? groups.map((g) => /* @__PURE__ */ jsx(GroupCard, { group: g, policy: name }, g.entityRef)) : /* @__PURE__ */ jsx("div", { className: "ts-card", children: /* @__PURE__ */ jsx(Empty, { icon: /* @__PURE__ */ jsx(GroupIcon, {}), children: "No group matches." }) })
635
+ ] });
636
+ break;
637
+ }
638
+ case "tags": {
639
+ const tags = filtered(policy.tags);
640
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
641
+ /* @__PURE__ */ jsx(
642
+ SectionHeader,
643
+ {
644
+ title: "Tags",
645
+ lede: "What a device is or does, and who may give a device the tag.",
646
+ children: searchBox
647
+ }
648
+ ),
649
+ /* @__PURE__ */ jsx("div", { className: "ts-card", children: tags.length ? /* @__PURE__ */ jsxs("table", { className: "ts-table", children: [
650
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
651
+ /* @__PURE__ */ jsx("th", { children: "Tag" }),
652
+ /* @__PURE__ */ jsx("th", { children: "What it means" }),
653
+ /* @__PURE__ */ jsx("th", { children: "Owners" }),
654
+ /* @__PURE__ */ jsx("th", { children: "Used in" }),
655
+ /* @__PURE__ */ jsx("th", { "aria-label": "Line" })
656
+ ] }) }),
657
+ /* @__PURE__ */ jsx("tbody", { children: tags.map((t) => /* @__PURE__ */ jsx(
658
+ TagRow,
659
+ {
660
+ tag: t,
661
+ policy: name,
662
+ destination: policy.destinations.find(
663
+ (d) => d.name === t.tag
664
+ )
665
+ },
666
+ t.id
667
+ )) })
668
+ ] }) : /* @__PURE__ */ jsx(Empty, { icon: /* @__PURE__ */ jsx(TagIcon, {}), children: "No tag matches." }) })
669
+ ] });
670
+ break;
671
+ }
672
+ case "hosts":
673
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
674
+ /* @__PURE__ */ jsx(
675
+ SectionHeader,
676
+ {
677
+ title: "Hosts",
678
+ lede: "Names for addresses, from the policy entity. The tests use them to name devices."
679
+ }
680
+ ),
681
+ /* @__PURE__ */ jsx("div", { className: "ts-card", children: policy.hosts.length ? /* @__PURE__ */ jsxs("table", { className: "ts-table", children: [
682
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
683
+ /* @__PURE__ */ jsx("th", { children: "Name" }),
684
+ /* @__PURE__ */ jsx("th", { children: "Address" }),
685
+ /* @__PURE__ */ jsx("th", { "aria-label": "Line" })
686
+ ] }) }),
687
+ /* @__PURE__ */ jsx("tbody", { children: policy.hosts.map((h) => /* @__PURE__ */ jsxs("tr", { children: [
688
+ /* @__PURE__ */ jsx("td", { className: "ts-mono", children: h.name }),
689
+ /* @__PURE__ */ jsx("td", { className: "ts-mono ts-muted", children: h.address }),
690
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx(LineLink, { lines: h.lines, policy: name }) })
691
+ ] }, h.name)) })
692
+ ] }) : /* @__PURE__ */ jsx(Empty, { icon: /* @__PURE__ */ jsx(HostIcon, {}), children: "No hosts." }) })
693
+ ] });
694
+ break;
695
+ case "nodeAttrs": {
696
+ const rules = filtered(policy.nodeAttrs);
697
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
698
+ /* @__PURE__ */ jsx(
699
+ SectionHeader,
700
+ {
701
+ title: "Node attributes",
702
+ lede: "Features devices get by tag, or by the group of the user who owns them."
703
+ }
704
+ ),
705
+ /* @__PURE__ */ jsx(
706
+ List,
707
+ {
708
+ count: rules.length,
709
+ icon: /* @__PURE__ */ jsx(AttrIcon, {}),
710
+ columns: { from: "Devices", to: "Get", right: " " },
711
+ empty: "No node attributes.",
712
+ children: rules.map((n) => /* @__PURE__ */ jsx(NodeAttrRow, { rule: n, policy: name }, n.id))
713
+ }
714
+ )
715
+ ] });
716
+ break;
717
+ }
718
+ case "autoApprovers": {
719
+ const rules = filtered(policy.autoApprovers);
720
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
721
+ /* @__PURE__ */ jsx(
722
+ SectionHeader,
723
+ {
724
+ title: "Auto approvers",
725
+ lede: "The Tailscale Services, routes and exit nodes a device may advertise without approval in the admin console.",
726
+ children: searchBox
727
+ }
728
+ ),
729
+ /* @__PURE__ */ jsx(
730
+ List,
731
+ {
732
+ count: rules.length,
733
+ icon: /* @__PURE__ */ jsx(ApproveIcon, {}),
734
+ columns: { from: "Devices", to: "May serve", right: " " },
735
+ empty: "No auto approvers.",
736
+ children: rules.map((a) => /* @__PURE__ */ jsx(ApproverRow, { rule: a, policy: name }, a.id))
737
+ }
738
+ )
739
+ ] });
740
+ break;
741
+ }
742
+ case "tests": {
743
+ const groups = groupTests(filtered(policy.tests));
744
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
745
+ /* @__PURE__ */ jsx(
746
+ SectionHeader,
747
+ {
748
+ title: "Tests",
749
+ lede: "Tailscale runs these every time the policy is saved; one that fails rejects the save, and the previous policy stays live.",
750
+ children: searchBox
751
+ }
752
+ ),
753
+ /* @__PURE__ */ jsx(
754
+ List,
755
+ {
756
+ count: groups.length,
757
+ icon: /* @__PURE__ */ jsx(TestIcon, {}),
758
+ empty: "No test matches.",
759
+ children: groups.map((tests) => /* @__PURE__ */ jsx(TestGroup, { tests, policy: name }, tests[0].id))
760
+ }
761
+ )
762
+ ] });
763
+ break;
764
+ }
765
+ case "file":
766
+ body = /* @__PURE__ */ jsx(
767
+ FileSection,
768
+ {
769
+ policy,
770
+ lines: params.get("lines") ?? void 0,
771
+ focus: params.get("focus") ?? void 0,
772
+ onFocus: (ref) => update({ focus: ref, lines: void 0 }, true)
773
+ }
774
+ );
775
+ break;
776
+ default:
777
+ body = /* @__PURE__ */ jsx(OverviewSection, { policy, problems, go });
778
+ }
779
+ return /* @__PURE__ */ jsxs("div", { className: "ts", children: [
780
+ /* @__PURE__ */ jsx(
781
+ Hero,
782
+ {
783
+ overview,
784
+ policy,
785
+ onPolicy: (p) => update({ policy: p })
786
+ }
787
+ ),
788
+ /* @__PURE__ */ jsxs("div", { className: "ts-shell", children: [
789
+ /* @__PURE__ */ jsx("nav", { className: "ts-nav", "aria-label": "Policy sections", children: SECTIONS.map((s) => /* @__PURE__ */ jsxs("div", { style: { display: "contents" }, children: [
790
+ s.heading ? /* @__PURE__ */ jsx("div", { className: "ts-nav-heading", children: s.heading }) : null,
791
+ /* @__PURE__ */ jsxs(
792
+ "button",
793
+ {
794
+ type: "button",
795
+ className: "ts-nav-item",
796
+ "aria-current": section === s.id ? "page" : void 0,
797
+ onClick: () => go(s.id),
798
+ children: [
799
+ s.icon,
800
+ s.label,
801
+ s.id === "overview" && problems.length ? /* @__PURE__ */ jsx("span", { className: "ts-nav-count ts-nav-count-bad", children: problems.length }) : null,
802
+ s.count ? /* @__PURE__ */ jsx("span", { className: "ts-nav-count", children: s.count(policy) }) : null
803
+ ]
804
+ }
805
+ )
806
+ ] }, s.id)) }),
807
+ /* @__PURE__ */ jsx("main", { children: body })
808
+ ] })
809
+ ] });
810
+ }
811
+ function TailscalePage() {
812
+ const { value, error, loading } = useOverview();
813
+ return /* @__PURE__ */ jsxs(Content, { children: [
814
+ loading && !value ? /* @__PURE__ */ jsx(Progress, {}) : null,
815
+ error ? /* @__PURE__ */ jsx(ResponseErrorPanel, { error }) : null,
816
+ value ? /* @__PURE__ */ jsx(PolicyConsole, { overview: value }) : null
817
+ ] });
818
+ }
819
+ function PolicyTab() {
820
+ const { entity } = useEntity();
821
+ return /* @__PURE__ */ jsx(PolicyContent, { entityRef: stringifyEntityRef(entity) });
822
+ }
823
+ function PolicyContent(props) {
824
+ const { value, error, loading } = useOverview();
825
+ if (loading && !value) return /* @__PURE__ */ jsx(Progress, {});
826
+ if (error) return /* @__PURE__ */ jsx(ResponseErrorPanel, { error });
827
+ return value ? /* @__PURE__ */ jsx(PolicyConsole, { overview: value, policyRef: props.entityRef }) : null;
828
+ }
829
+
830
+ export { PolicyConsole, PolicyTab, TailscalePage };
831
+ //# sourceMappingURL=PolicyConsole.esm.js.map