@spechtlabs/backstage-plugin-tailscale-common 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,462 @@
1
+ import { Entity, CompoundEntityRef } from '@backstage/catalog-model';
2
+ import { JsonObject } from '@backstage/types';
3
+
4
+ /**
5
+ * kind: Tailscale. One entity per piece of a tailnet policy file, and one
6
+ * for the policy itself. Every piece names the policy it belongs to in
7
+ * spec.target; the plugin renders each policy from its pieces.
8
+ *
9
+ * apiVersion: specht-labs.de/v1alpha1
10
+ * kind: Tailscale
11
+ * metadata:
12
+ * name: grant-metrics
13
+ * title: Agents push metrics
14
+ * spec:
15
+ * type: grant
16
+ * target: tailscale:my-tailnet
17
+ * owner: group:platform
18
+ * src: [tag:monitoring-agent]
19
+ * dst: [svc:metrics]
20
+ * ip: [tcp:443]
21
+ *
22
+ * spec.type what it is, and which section of the policy it renders to:
23
+ * policy the policy: hosts, settings, the catalog's grants, and
24
+ * where its file is published (spec.publish)
25
+ * grant one entry of "grants"
26
+ * ssh one entry of "ssh"
27
+ * tag one tag of "tagOwners"
28
+ * nodeAttr one entry of "nodeAttrs" (its target is spec.nodes)
29
+ * autoApprovers part of "autoApprovers": routes, services, exitNode
30
+ * test entries of "tests" and "sshTests"
31
+ *
32
+ * Users and groups are not Tailscale entities: a group:<name> is the
33
+ * Backstage Group whose specht-labs.de/tailnet-group annotation names it,
34
+ * and its members are that Group's Users (specht-labs.de/tailnet-login).
35
+ *
36
+ * Every other field is the Tailscale field of the same name, written as in
37
+ * a policy file.
38
+ */
39
+ declare const TAILSCALE_API_VERSION = "specht-labs.de/v1alpha1";
40
+ declare const TAILSCALE_KIND = "Tailscale";
41
+ declare const TAILSCALE_TYPES: readonly ["policy", "grant", "ssh", "tag", "nodeAttr", "autoApprovers", "test"];
42
+ type TailscaleType = (typeof TAILSCALE_TYPES)[number];
43
+ /** A piece -> its policy, and back. */
44
+ declare const RELATION_PART_OF_POLICY = "partOfPolicy";
45
+ declare const RELATION_HAS_POLICY_PART = "hasPolicyPart";
46
+ /** A piece -> the catalog entities it is about (spec.appliesTo), and back. */
47
+ declare const RELATION_APPLIES_TO = "appliesTo";
48
+ declare const RELATION_APPLIED_BY = "tailscaleAppliedBy";
49
+ /** On a Group: the tailnet group it is (group:admins). */
50
+ declare const ANNOTATION_TAILNET_GROUP = "specht-labs.de/tailnet-group";
51
+ /** On a User: their Tailscale login (alice@github). */
52
+ declare const ANNOTATION_TAILNET_LOGIN = "specht-labs.de/tailnet-login";
53
+ /**
54
+ * On a Tailscale tag entity: why traffic is addressed to devices carrying
55
+ * the tag rather than to a Tailscale Service, when that isn't evident (a
56
+ * peer mesh or a capability target is).
57
+ */
58
+ declare const ANNOTATION_DEVICE_REASON = "specht-labs.de/tailnet-device-reason";
59
+ type Common = {
60
+ type: TailscaleType;
61
+ /** The policy this belongs to: a Tailscale entity of type policy. */
62
+ target?: string;
63
+ owner: string;
64
+ system?: string;
65
+ /** Catalog entities this is about: they list it on their pages. */
66
+ appliesTo?: string[];
67
+ };
68
+ type PolicySpec = Common & {
69
+ type: 'policy';
70
+ /** The tailnet's name, for display: example.ts.net. */
71
+ tailnet?: string;
72
+ hosts?: {
73
+ [alias: string]: string;
74
+ };
75
+ /**
76
+ * Render a grant for every Component that consumes an API across the
77
+ * tailnet (the specht-labs.de/tailnet-* annotations).
78
+ */
79
+ catalogGrants?: boolean;
80
+ /** Other top-level policy keys, rendered as they are. */
81
+ settings?: JsonObject;
82
+ /** Where the rendered file goes, and how. */
83
+ publish?: PublishSpec;
84
+ };
85
+ /**
86
+ * spec.publish: the repository and path the policy file is written to.
87
+ * flow pullRequest keeps one pull request open from pullRequestBranch into
88
+ * branch; push commits to branch directly. branch defaults to the
89
+ * repository's default branch. The repository must be one Backstage's
90
+ * tailscale.allowedRepos lists.
91
+ */
92
+ type PublishSpec = {
93
+ repo: string;
94
+ path: string;
95
+ flow?: 'pullRequest' | 'push';
96
+ branch?: string;
97
+ pullRequestBranch?: string;
98
+ };
99
+ type GrantSpec = Common & {
100
+ type: 'grant';
101
+ src: string[];
102
+ dst: string[];
103
+ ip?: string[];
104
+ app?: {
105
+ [capability: string]: JsonObject[];
106
+ };
107
+ via?: string[];
108
+ srcPosture?: string[];
109
+ };
110
+ type SshSpec = Common & {
111
+ type: 'ssh';
112
+ action: 'accept' | 'check';
113
+ src: string[];
114
+ dst: string[];
115
+ users: string[];
116
+ checkPeriod?: string;
117
+ acceptEnv?: string[];
118
+ recorder?: string[];
119
+ enforceRecorder?: boolean;
120
+ };
121
+ type TagSpec = Common & {
122
+ type: 'tag';
123
+ tag: string;
124
+ owners: string[];
125
+ };
126
+ type NodeAttrSpec = Common & {
127
+ type: 'nodeAttr';
128
+ /** The nodeAttr's "target" (spec.target is the policy). */
129
+ nodes: string[];
130
+ attr?: string[];
131
+ app?: JsonObject;
132
+ ipPool?: string[];
133
+ };
134
+ type AutoApproversSpec = Common & {
135
+ type: 'autoApprovers';
136
+ routes?: {
137
+ [cidr: string]: string[];
138
+ };
139
+ services?: {
140
+ [service: string]: string[];
141
+ };
142
+ exitNode?: string[];
143
+ };
144
+ type AclTest = {
145
+ src: string;
146
+ proto?: string;
147
+ srcPostureAttrs?: JsonObject;
148
+ accept?: string[];
149
+ deny?: string[];
150
+ };
151
+ type SshTest = {
152
+ src: string;
153
+ dst: string[];
154
+ accept?: string[];
155
+ check?: string[];
156
+ deny?: string[];
157
+ };
158
+ type TestSpec = Common & {
159
+ type: 'test';
160
+ /** One test or a list of them. */
161
+ tests?: AclTest | AclTest[];
162
+ sshTests?: SshTest | SshTest[];
163
+ };
164
+ type TailscaleSpec = PolicySpec | GrantSpec | SshSpec | TagSpec | NodeAttrSpec | AutoApproversSpec | TestSpec;
165
+ type TailscaleEntity<S extends TailscaleSpec = TailscaleSpec> = Entity & {
166
+ spec: S & JsonObject;
167
+ };
168
+ declare function isTailscale(entity: Entity): entity is TailscaleEntity;
169
+ declare function isTailscaleOfType<T extends TailscaleType>(entity: Entity, type: T): entity is TailscaleEntity<Extract<TailscaleSpec, {
170
+ type: T;
171
+ }>>;
172
+ /** tests / sshTests: one or many. */
173
+ declare function asList<T>(value: T | T[] | undefined): T[];
174
+ /** What is wrong with a Tailscale entity's spec, as messages. */
175
+ declare function validateTailscaleSpec(spec: unknown): string[];
176
+
177
+ /**
178
+ * The `ip` entries of a Tailscale grant: `*`, `443`, `1000-2000`,
179
+ * `tcp:443`, `udp:*`. A bare port (or `*`) means every protocol.
180
+ */
181
+ interface PortRange {
182
+ proto: string;
183
+ from: number;
184
+ to: number;
185
+ }
186
+ declare function parsePort(entry: string): PortRange | undefined;
187
+ declare function isWildcardPort(range: PortRange): boolean;
188
+ /** Whether `outer` allows everything `inner` does. */
189
+ declare function portCovers(outer: PortRange, inner: PortRange): boolean;
190
+ declare function formatPort(range: PortRange): string;
191
+
192
+ /** A relation between two entities, as the catalog stores it. */
193
+ interface TailscaleRelation {
194
+ source: CompoundEntityRef;
195
+ type: string;
196
+ target: CompoundEntityRef;
197
+ }
198
+ /**
199
+ * The relations a Tailscale entity has, both ways: to its owner, its
200
+ * system, its policy (partOfPolicy / hasPolicyPart) and the entities it
201
+ * applies to (appliesTo / tailscaleAppliedBy). The catalog module emits
202
+ * these; tooling that reads entities from files can add them itself.
203
+ */
204
+ declare function tailscaleRelations(entity: TailscaleEntity): TailscaleRelation[];
205
+
206
+ interface LocalEdge {
207
+ consumer: string;
208
+ api: string;
209
+ providers: string[];
210
+ cluster: string;
211
+ }
212
+ interface Finding {
213
+ entity: string;
214
+ message: string;
215
+ }
216
+ type PrincipalKind = 'any' | 'group' | 'user' | 'tag' | 'service' | 'autogroup' | 'host' | 'address' | 'ipset';
217
+ /** A source, destination, owner or approver. */
218
+ interface Principal {
219
+ /** As the entity writes it. */
220
+ value: string;
221
+ /** As the policy file has it. */
222
+ name: string;
223
+ kind: PrincipalKind;
224
+ /** The catalog entity behind it: a Group, a User, a tag's entity. */
225
+ entityRef?: string;
226
+ title?: string;
227
+ }
228
+ /** Lines in the rendered file, 1-based and inclusive. */
229
+ type Lines = [number, number];
230
+ interface Rule {
231
+ id: string;
232
+ /** The Tailscale entity it comes from; none for catalog grants. */
233
+ entityRef?: string;
234
+ title?: string;
235
+ description?: string;
236
+ lines?: Lines;
237
+ }
238
+ interface CatalogEdge {
239
+ /** The consuming Component; for tailnet-allow, the API. */
240
+ consumer: string;
241
+ api: string;
242
+ providers: string[];
243
+ via: 'consumesApi' | 'tailnet-allow';
244
+ src: string[];
245
+ dst: string[];
246
+ ports: string[];
247
+ }
248
+ interface GrantRule extends Rule {
249
+ origin: 'entity' | 'catalog';
250
+ src: Principal[];
251
+ dst: Principal[];
252
+ ip: string[];
253
+ app?: Record<string, JsonObject[]>;
254
+ via?: Principal[];
255
+ srcPosture?: string[];
256
+ /** For catalog grants: the API consumptions it is made of. */
257
+ edges?: CatalogEdge[];
258
+ }
259
+ interface SshRule extends Rule {
260
+ action: 'accept' | 'check';
261
+ src: Principal[];
262
+ dst: Principal[];
263
+ users: string[];
264
+ checkPeriod?: string;
265
+ acceptEnv?: string[];
266
+ recorder?: Principal[];
267
+ enforceRecorder?: boolean;
268
+ }
269
+ interface TagRule extends Rule {
270
+ tag: string;
271
+ owners: Principal[];
272
+ appliesTo: string[];
273
+ /** How many rules name it. */
274
+ usage: number;
275
+ }
276
+ interface NodeAttrRule extends Rule {
277
+ nodes: Principal[];
278
+ attr: string[];
279
+ app?: JsonObject;
280
+ ipPool?: string[];
281
+ }
282
+ interface ApproverRule extends Rule {
283
+ kind: 'service' | 'route' | 'exitNode';
284
+ /** svc:<name>, a CIDR, or "exit node". */
285
+ target: string;
286
+ approvers: Principal[];
287
+ }
288
+ interface Member {
289
+ login?: string;
290
+ entityRef: string;
291
+ title?: string;
292
+ }
293
+ interface GroupView {
294
+ name: string;
295
+ entityRef: string;
296
+ title?: string;
297
+ description?: string;
298
+ members: Member[];
299
+ usage: number;
300
+ lines?: Lines;
301
+ }
302
+ interface HostView {
303
+ name: string;
304
+ address: string;
305
+ lines?: Lines;
306
+ }
307
+ interface TestRule extends Rule {
308
+ kind: 'acl' | 'ssh';
309
+ src: Principal;
310
+ proto?: string;
311
+ /** sshTests: the machines it connects to. */
312
+ dst?: Principal[];
313
+ accept: string[];
314
+ deny: string[];
315
+ /** sshTests: users that need check mode. */
316
+ check: string[];
317
+ }
318
+ /**
319
+ * What a grant destination is. A Service is what a destination should be;
320
+ * the rest are devices, for a reason: a peer mesh (a tag that reaches
321
+ * itself: every member is reached at its own address), a capability target
322
+ * (an app reading capabilities matched on its own address), autogroups,
323
+ * everything (a break-glass grant), or a reason declared on the tag entity.
324
+ */
325
+ type DestinationClass = 'service' | 'mesh' | 'capability' | 'autogroup' | 'any' | 'device';
326
+ interface DestinationView {
327
+ name: string;
328
+ class: DestinationClass;
329
+ /** Declared on the tag entity (specht-labs.de/tailnet-device-reason). */
330
+ reason?: string;
331
+ /** The tag's entity, for tags. */
332
+ entityRef?: string;
333
+ /** The grants that reach it. */
334
+ grants: string[];
335
+ /** The Services a tag may serve (auto approvers). */
336
+ serves: string[];
337
+ }
338
+ interface Diagnostic {
339
+ severity: 'error' | 'warning';
340
+ message: string;
341
+ entityRef?: string;
342
+ }
343
+ interface PartSummary {
344
+ entityRef: string;
345
+ type: TailscaleType;
346
+ name: string;
347
+ title?: string;
348
+ description?: string;
349
+ lines: Lines[];
350
+ }
351
+ interface Span {
352
+ entityRef: string;
353
+ section: string;
354
+ lines: Lines;
355
+ }
356
+ interface CoveredEdge extends CatalogEdge {
357
+ coveredBy: string[];
358
+ }
359
+ interface PolicyView {
360
+ entityRef: string;
361
+ name: string;
362
+ title?: string;
363
+ description?: string;
364
+ tailnet?: string;
365
+ owner?: string;
366
+ /** Where its file is published: the policy's spec.publish. */
367
+ publish?: PublishSpec;
368
+ renderedAt: string;
369
+ /** The policy file. */
370
+ text: string;
371
+ spans: Span[];
372
+ parts: PartSummary[];
373
+ groups: GroupView[];
374
+ hosts: HostView[];
375
+ tags: TagRule[];
376
+ grants: GrantRule[];
377
+ ssh: SshRule[];
378
+ nodeAttrs: NodeAttrRule[];
379
+ autoApprovers: ApproverRule[];
380
+ tests: TestRule[];
381
+ settings: string[];
382
+ catalog: {
383
+ enabled: boolean;
384
+ /** Consumptions another grant already allows: no grant of their own. */
385
+ covered: CoveredEdge[];
386
+ /** Consumer and provider share a cluster: not on the tailnet. */
387
+ local: LocalEdge[];
388
+ missingSource: Finding[];
389
+ invalid: Finding[];
390
+ };
391
+ destinations: DestinationView[];
392
+ diagnostics: Diagnostic[];
393
+ }
394
+ interface CompiledOverview {
395
+ renderedAt: string;
396
+ policies: PolicyView[];
397
+ /** Tailscale entities whose policy isn't in the catalog. */
398
+ orphans: Diagnostic[];
399
+ }
400
+ /** How an entity shows up on the tailnet, and why. */
401
+ interface Identity {
402
+ name: string;
403
+ /** Traffic it sends carries it (a tag, a group, a login)... */
404
+ source: boolean;
405
+ /** ...or traffic to it is addressed to it (a tag, a Service). */
406
+ destination: boolean;
407
+ /** Where that comes from: an annotation, a tag entity, an API. */
408
+ via: string;
409
+ }
410
+ /** One policy, as far as one entity is concerned. */
411
+ interface EntityAccess {
412
+ policy: {
413
+ entityRef: string;
414
+ name: string;
415
+ title?: string;
416
+ tailnet?: string;
417
+ };
418
+ identities: Identity[];
419
+ /** Grants it is a source of: what it can reach. */
420
+ outbound: GrantRule[];
421
+ /** Grants it is a destination of: who can reach it. */
422
+ inbound: GrantRule[];
423
+ /** SSH rules into it, and from it. */
424
+ sshInto: SshRule[];
425
+ sshFrom: SshRule[];
426
+ /** Tags it carries. */
427
+ tags: TagRule[];
428
+ /** Tags it may give devices. */
429
+ owns: TagRule[];
430
+ nodeAttrs: NodeAttrRule[];
431
+ /** What it may advertise without approval. */
432
+ approvals: ApproverRule[];
433
+ tests: TestRule[];
434
+ /** Rules that name it in spec.appliesTo, of any type. */
435
+ appliesTo: string[];
436
+ }
437
+ /** Where a policy's file is published, and how the last run went. */
438
+ interface PublishStatus {
439
+ repo: string;
440
+ path: string;
441
+ flow: 'pullRequest' | 'push';
442
+ /** The branch the file lands on; the repository's default if unset. */
443
+ branch?: string;
444
+ /** pullRequest: the branch Backstage owns and force-pushes. */
445
+ pullRequestBranch: string;
446
+ /** Why it isn't published, if it isn't. */
447
+ problem?: string;
448
+ last?: {
449
+ at: string;
450
+ outcome: string;
451
+ url?: string;
452
+ error?: string;
453
+ };
454
+ }
455
+ /** GET /api/tailscale/overview */
456
+ type Overview = CompiledOverview & {
457
+ /** By policy entity ref. */
458
+ publish: Record<string, PublishStatus>;
459
+ };
460
+
461
+ export { ANNOTATION_DEVICE_REASON, ANNOTATION_TAILNET_GROUP, ANNOTATION_TAILNET_LOGIN, RELATION_APPLIED_BY, RELATION_APPLIES_TO, RELATION_HAS_POLICY_PART, RELATION_PART_OF_POLICY, TAILSCALE_API_VERSION, TAILSCALE_KIND, TAILSCALE_TYPES, asList, formatPort, isTailscale, isTailscaleOfType, isWildcardPort, parsePort, portCovers, tailscaleRelations, validateTailscaleSpec };
462
+ export type { AclTest, ApproverRule, AutoApproversSpec, CatalogEdge, CompiledOverview, CoveredEdge, DestinationClass, DestinationView, Diagnostic, EntityAccess, Finding, GrantRule, GrantSpec, GroupView, HostView, Identity, Lines, LocalEdge, Member, NodeAttrRule, NodeAttrSpec, Overview, PartSummary, PolicySpec, PolicyView, PortRange, Principal, PrincipalKind, PublishSpec, PublishStatus, Rule, Span, SshRule, SshSpec, SshTest, TagRule, TagSpec, TailscaleEntity, TailscaleRelation, TailscaleSpec, TailscaleType, TestRule, TestSpec };
@@ -0,0 +1,4 @@
1
+ export { ANNOTATION_DEVICE_REASON, ANNOTATION_TAILNET_GROUP, ANNOTATION_TAILNET_LOGIN, RELATION_APPLIED_BY, RELATION_APPLIES_TO, RELATION_HAS_POLICY_PART, RELATION_PART_OF_POLICY, TAILSCALE_API_VERSION, TAILSCALE_KIND, TAILSCALE_TYPES, asList, isTailscale, isTailscaleOfType, validateTailscaleSpec } from './model.esm.js';
2
+ export { formatPort, isWildcardPort, parsePort, portCovers } from './ports.esm.js';
3
+ export { tailscaleRelations } from './relations.esm.js';
4
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}