@intentius/behold 0.31.0 → 0.33.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.
Files changed (50) hide show
  1. package/AGENTS.md +64 -2787
  2. package/README.md +78 -13
  3. package/THIRD_PARTY.md +6 -5
  4. package/dist/chant-KLLNQOCK.js +117 -0
  5. package/dist/choudoufu-chant-read-MJ6DK23L.js +36 -0
  6. package/dist/chunk-26K6QLVB.js +157 -0
  7. package/dist/chunk-4IETG5U7.js +267 -0
  8. package/dist/chunk-7DQDWJI5.js +46 -0
  9. package/dist/chunk-ANJ33KX4.js +78 -0
  10. package/dist/chunk-C7OMVDI5.js +124 -0
  11. package/dist/chunk-GG3SLEYM.js +30297 -0
  12. package/dist/chunk-GMCRBXPQ.js +15578 -0
  13. package/dist/chunk-IMX6PXXA.js +1019 -0
  14. package/dist/chunk-JHLNY324.js +232 -0
  15. package/dist/chunk-JJPU2DXX.js +54 -0
  16. package/dist/chunk-KUHU6T4P.js +2820 -0
  17. package/dist/chunk-OY4EF7ZO.js +5651 -0
  18. package/dist/chunk-XKWCGNT2.js +8139 -0
  19. package/dist/chunk-YO233FHU.js +136 -0
  20. package/dist/cli.js +491 -72879
  21. package/dist/config-XKQQ4ORG.js +69 -0
  22. package/dist/config-run-4IMSAYPX.js +418 -0
  23. package/dist/declaration-5NE7H5UD.js +6867 -0
  24. package/dist/index.js +99 -0
  25. package/dist/main-4PGA5RJS.js +2509 -0
  26. package/dist/mcp-W2CHVEPI.js +753 -0
  27. package/dist/object-store-H77QSRIZ.js +1033 -0
  28. package/dist/src-54PT4UC5.js +1189 -0
  29. package/dist/tree-W23HE2EZ.js +17 -0
  30. package/example-choudoufu-estate/chant.workspace.json +1 -1
  31. package/example-terraform-estate/README.md +2 -2
  32. package/example-terraform-estate/chant.workspace.json +1 -1
  33. package/example-three-cloud/chant.workspace.json +2 -2
  34. package/example-three-cloud/package-lock.json +32 -515
  35. package/example-three-cloud/package.json +5 -5
  36. package/package.json +26 -13
  37. package/schemas/graph/v1/graph.schema.json +140 -0
  38. package/web/app.js +9 -4
  39. package/web/boot-motion.js +6 -0
  40. package/web/cut-around.d.ts +30 -0
  41. package/web/cut-around.js +138 -0
  42. package/web/edge-weight.d.ts +8 -2
  43. package/web/edge-weight.js +34 -4
  44. package/web/edge-weight.test.js +36 -1
  45. package/web/index.html +8 -20
  46. package/web/neighbourhood.js +105 -0
  47. package/web/neighbourhood.test.js +131 -0
  48. package/web/outside-refs.js +515 -0
  49. package/web/outside-refs.test.js +249 -0
  50. package/web/theme-paint.js +14 -0
@@ -0,0 +1,515 @@
1
+ // What live Kubernetes objects name outside the cluster, as placeholder cards
2
+ // (#1082, part of #1049 phase 4). A ServiceAccount's annotation names a cloud
3
+ // identity, an ExternalSecret names a store and through it a secret in a cloud
4
+ // secret manager, an Argo CD Application and a Flux Kustomization name a repo
5
+ // and a path. A cluster surface can draw those with no configuration and no
6
+ // Terraform read: this turns the objects into labelled cards and edges.
7
+ //
8
+ // Pure and browser-safe: it imports nothing, no `node:*` and nothing from
9
+ // src/. `esbuild web/outside-refs.js --bundle --platform=browser` takes it
10
+ // whole, and web/outside-refs.test.js checks the module graph.
11
+ //
12
+ // outsideRefs(objects, { graph? }) -> { cards, edges, notes }
13
+ //
14
+ // `objects` are Kubernetes manifests as the API serves them (apiVersion, kind,
15
+ // metadata, spec), or `List` documents of them. `graph` is the graph the
16
+ // surface already holds, `{ nodes }`; a target it holds gets no card and no
17
+ // edge, because the derived edge (chant#5098, chant#5099) already draws it.
18
+ // What counts as holding a target:
19
+ //
20
+ // cloud identity a node of type aws_iam_role (name or arn), google_service_account
21
+ // (email, or account_id and project) or an Azure identity (client_id)
22
+ // a secret key aws_secretsmanager_secret (name), aws_ssm_parameter (name) or
23
+ // google_secret_manager_secret (secret_id and project): the key
24
+ // leaves the provider card's `keys`
25
+ // a store a Kubernetes node with the store's kind, namespace and name
26
+ // a source a node carrying the same URL in `repoURL`, `url` or `clone_url`
27
+ //
28
+ // A node's type is its `kind` when that reads like a Terraform type, else the
29
+ // type in its address, else the chant AWS name for the same resource. Its
30
+ // arguments are read from `attrs`, `attrs.body`, `attrs.values` and
31
+ // `attrs.properties`.
32
+ //
33
+ // The field paths are the ones chant#5098 (ExternalSecret and its store) and
34
+ // chant#5099 (ServiceAccount annotations) read, so a placeholder and a derived
35
+ // edge cannot disagree:
36
+ //
37
+ // ServiceAccount metadata.annotations["iam.gke.io/gcp-service-account"]
38
+ // metadata.annotations["eks.amazonaws.com/role-arn"]
39
+ // metadata.annotations["azure.workload.identity/client-id"]
40
+ // ExternalSecret spec.secretStoreRef.{name,kind}, spec.data[].remoteRef.key,
41
+ // spec.dataFrom[].extract.key
42
+ // (Cluster)SecretStore spec.provider.gcpsm.projectID, spec.provider.aws.{service,region},
43
+ // spec.provider.vault.{server,path}
44
+ // Application spec.source and spec.sources[]: repoURL, path, chart
45
+ // Kustomization spec.sourceRef, spec.path (the URL comes from the source object)
46
+ //
47
+ // Ids are made from what a card names, so two objects naming the same thing
48
+ // share one card:
49
+ //
50
+ // outside:identity:aws:<arn> outside:identity:gcp:<email> outside:identity:azure:<client id>
51
+ // outside:store:ClusterSecretStore/<name> outside:store:SecretStore/<namespace>/<name>
52
+ // outside:provider:gcpsm:<project> outside:provider:aws:<service>:<region>
53
+ // outside:provider:vault:<server>/<path>
54
+ // outside:source:<repo url>#<path> outside:source:<repo url>#chart=<chart>
55
+ //
56
+ // Edges name their origin twice: `from` is the object's id in the form
57
+ // "<group>/<Kind>/<namespace>/<name>" (group empty for core, namespace empty
58
+ // for a cluster-scoped kind) and `fromRef` is the same as an object, for a
59
+ // surface that keys on Kubernetes identity. A store's edge to its provider
60
+ // card starts at the store object the same way. An edge to a source card also
61
+ // carries the `targetRevision` as `revision`.
62
+ //
63
+ // A field the rules do not understand, or cannot read, goes in `notes`. The
64
+ // live read masks any key matching /secret/i, which takes the whole
65
+ // `spec.secretStoreRef` of an ExternalSecret (chant#5116). That ExternalSecret
66
+ // cannot be joined to its store, so it gives a note with `waitsOn` set, and
67
+ // its remoteRef keys stay off the provider card until the read allows it.
68
+
69
+ /** What chant's live read writes over a masked value. */
70
+ const MASKED = "<masked>";
71
+ const WAITS_ON_MASK = "INTENTIUS/chant#5116";
72
+
73
+ const ANNOTATION_GCP = "iam.gke.io/gcp-service-account";
74
+ const ANNOTATION_AWS = "eks.amazonaws.com/role-arn";
75
+ const ANNOTATION_AZURE = "azure.workload.identity/client-id";
76
+
77
+ const ESO_GROUP = "external-secrets.io";
78
+ const FLUX_SOURCE_GROUP = "source.toolkit.fluxcd.io";
79
+ const FLUX_KUSTOMIZE_GROUP = "kustomize.toolkit.fluxcd.io";
80
+ const ARGO_GROUP = "argoproj.io";
81
+
82
+ const CLUSTER_SCOPED = new Set(["ClusterSecretStore"]);
83
+
84
+ const isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
85
+ const str = (v) => (typeof v === "string" && v.length > 0 ? v : undefined);
86
+ const arr = (v) => (Array.isArray(v) ? v : []);
87
+
88
+ /** `{ group, kind, namespace, name }` of a manifest. */
89
+ function refOf(obj) {
90
+ const apiVersion = str(obj.apiVersion) || "";
91
+ const group = apiVersion.includes("/") ? apiVersion.slice(0, apiVersion.indexOf("/")) : "";
92
+ const meta = isObject(obj.metadata) ? obj.metadata : {};
93
+ const kind = str(obj.kind);
94
+ const name = str(meta.name);
95
+ const namespace = CLUSTER_SCOPED.has(kind) ? "" : str(meta.namespace) || "default";
96
+ return { group, kind, namespace, name };
97
+ }
98
+
99
+ const idOf = (r) => `${r.group}/${r.kind}/${r.namespace}/${r.name}`;
100
+
101
+ /** Every manifest in `objects`, with `List` documents opened up. */
102
+ function flatten(objects) {
103
+ const out = [];
104
+ for (const o of arr(objects)) {
105
+ if (!isObject(o)) continue;
106
+ if (Array.isArray(o.items) && typeof o.kind === "string" && o.kind.endsWith("List")) out.push(...flatten(o.items));
107
+ else out.push(o);
108
+ }
109
+ return out;
110
+ }
111
+
112
+ // --- the graph the surface already holds ---------------------------------
113
+
114
+ const CHANT_AWS_TYPES = {
115
+ "AWS::IAM::Role": "aws_iam_role",
116
+ "AWS::SecretsManager::Secret": "aws_secretsmanager_secret",
117
+ "AWS::SSM::Parameter": "aws_ssm_parameter",
118
+ };
119
+
120
+ /** The Terraform type a graph node stands for, or undefined. */
121
+ function typeOfNode(node) {
122
+ const kind = str(node && node.kind);
123
+ if (kind && CHANT_AWS_TYPES[kind]) return CHANT_AWS_TYPES[kind];
124
+ if (kind && /^[a-z][a-z0-9]*_[a-z0-9_]+$/.test(kind)) return kind;
125
+ const attrs = (node && node.attrs) || {};
126
+ const address = str(attrs.address) || str(node && node.id);
127
+ if (!address) return undefined;
128
+ const parts = address.replace(/\[[^\]]*\]/g, "").split(".");
129
+ if (parts[0] === "data" || parts.length < 2) return undefined;
130
+ const type = parts[parts.length - 2];
131
+ return /^[a-z][a-z0-9]*_[a-z0-9_]+$/.test(type) ? type : undefined;
132
+ }
133
+
134
+ /** A literal argument of a graph node, by any of `names`. */
135
+ function argOf(node, ...names) {
136
+ const attrs = (node && node.attrs) || {};
137
+ const layers = [attrs, attrs.body, attrs.values, attrs.properties, attrs.Properties].filter(isObject);
138
+ for (const layer of layers) {
139
+ for (const n of names) if (str(layer[n])) return layer[n];
140
+ }
141
+ return undefined;
142
+ }
143
+
144
+ function nodesOfType(graph, ...types) {
145
+ return arr(graph && graph.nodes).filter((n) => types.includes(typeOfNode(n)));
146
+ }
147
+
148
+ function holdsIdentity(graph, identity) {
149
+ if (identity.cloud === "aws") {
150
+ return nodesOfType(graph, "aws_iam_role").some((n) => argOf(n, "arn") === identity.arn || argOf(n, "name", "RoleName", "role_name") === identity.role);
151
+ }
152
+ if (identity.cloud === "gcp") {
153
+ return nodesOfType(graph, "google_service_account").some((n) => {
154
+ if (argOf(n, "email") === identity.email) return true;
155
+ const id = argOf(n, "account_id");
156
+ const project = argOf(n, "project");
157
+ return !!id && !!project && `${id}@${project}.iam.gserviceaccount.com` === identity.email;
158
+ });
159
+ }
160
+ return nodesOfType(graph, "azuread_application", "azuread_application_registration", "azuread_service_principal", "azurerm_user_assigned_identity").some(
161
+ (n) => String(argOf(n, "client_id", "application_id") || "").toLowerCase() === identity.clientId,
162
+ );
163
+ }
164
+
165
+ function holdsSecret(graph, provider, key) {
166
+ if (provider.provider === "gcpsm") {
167
+ return nodesOfType(graph, "google_secret_manager_secret").some((n) => argOf(n, "secret_id") === key && argOf(n, "project") === provider.projectID);
168
+ }
169
+ if (provider.provider === "aws") {
170
+ const types = provider.service === "ParameterStore" ? ["aws_ssm_parameter"] : ["aws_secretsmanager_secret"];
171
+ return nodesOfType(graph, ...types).some((n) => argOf(n, "name", "Name") === key);
172
+ }
173
+ return false;
174
+ }
175
+
176
+ function holdsK8s(graph, ref) {
177
+ return arr(graph && graph.nodes).some((n) => {
178
+ const attrs = (n && n.attrs) || {};
179
+ const meta = isObject(attrs.metadata) ? attrs.metadata : {};
180
+ const parts = typeof n.kind === "string" ? n.kind.split("::") : [];
181
+ const kind = str(attrs.kind) || (parts[0] === "K8s" ? parts[parts.length - 1] : undefined);
182
+ if (kind !== ref.kind || str(meta.name) !== ref.name) return false;
183
+ return CLUSTER_SCOPED.has(ref.kind) || (str(meta.namespace) || "default") === ref.namespace;
184
+ });
185
+ }
186
+
187
+ function holdsSource(graph, url) {
188
+ return arr(graph && graph.nodes).some((n) => {
189
+ const v = argOf(n, "repoURL", "url", "clone_url");
190
+ return !!v && normalizeUrl(v) === url;
191
+ });
192
+ }
193
+
194
+ // --- naming ---------------------------------------------------------------
195
+
196
+ /** A repo URL as one key: host lower-cased, no trailing slash, no `.git`. */
197
+ export function normalizeUrl(raw) {
198
+ let s = String(raw).trim().replace(/\/+$/, "").replace(/\.git$/, "");
199
+ const m = /^([a-z][a-z0-9+.-]*:\/\/)([^/]+)(.*)$/i.exec(s);
200
+ if (m) s = m[1].toLowerCase() + m[2].toLowerCase() + m[3];
201
+ return s;
202
+ }
203
+
204
+ const cleanPath = (p) => String(p).trim().replace(/^\.\//, "").replace(/^\/+/, "").replace(/\/+$/, "");
205
+
206
+ const PROVIDER_LABEL = {
207
+ gcpsm: "GCP Secret Manager",
208
+ aws: "AWS Secrets Manager",
209
+ awsParameterStore: "AWS Parameter Store",
210
+ vault: "Vault",
211
+ };
212
+
213
+ // --- the result under construction ---------------------------------------
214
+
215
+ function builder(graph) {
216
+ const cards = new Map();
217
+ const edges = new Map();
218
+ const notes = [];
219
+ return {
220
+ graph,
221
+ cards,
222
+ notes,
223
+ card(c) {
224
+ const have = cards.get(c.id);
225
+ if (!have) cards.set(c.id, { ...c, placeholder: true });
226
+ return cards.get(c.id);
227
+ },
228
+ edge(from, fromRef, to, viaAttr, extra) {
229
+ const e = { from, to, kind: "ref", viaAttr, inferred: true, placeholder: true, ...(extra || {}) };
230
+ if (fromRef) e.fromRef = fromRef;
231
+ edges.set(`${from}>${to}>${viaAttr}`, e);
232
+ },
233
+ note(from, path, code, message, extra) {
234
+ notes.push({ code, from, path, message, ...(extra || {}) });
235
+ },
236
+ result() {
237
+ const byId = (a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
238
+ return {
239
+ cards: [...cards.values()].sort(byId),
240
+ edges: [...edges.values()].sort((a, b) => `${a.from}>${a.to}>${a.viaAttr}`.localeCompare(`${b.from}>${b.to}>${b.viaAttr}`)),
241
+ notes,
242
+ };
243
+ },
244
+ };
245
+ }
246
+
247
+ const isMasked = (v) => v === MASKED;
248
+
249
+ // --- ServiceAccount: cloud identity --------------------------------------
250
+
251
+ function identityFor(annotation, value) {
252
+ if (annotation === ANNOTATION_GCP) {
253
+ const m = /^[^@\s]+@([^@\s]+)\.iam\.gserviceaccount\.com$/.exec(value);
254
+ return {
255
+ id: `outside:identity:gcp:${value}`,
256
+ identity: { cloud: "gcp", email: value, ...(m ? { project: m[1] } : {}) },
257
+ label: value,
258
+ ok: true,
259
+ };
260
+ }
261
+ if (annotation === ANNOTATION_AWS) {
262
+ const m = /^arn:aws[a-z-]*:iam::(\d{12}):role\/(.+)$/.exec(value);
263
+ if (!m) return { ok: false, why: "not an IAM role ARN" };
264
+ const role = m[2].slice(m[2].lastIndexOf("/") + 1);
265
+ return { id: `outside:identity:aws:${value}`, identity: { cloud: "aws", arn: value, account: m[1], role }, label: value, ok: true };
266
+ }
267
+ const clientId = value.toLowerCase();
268
+ return { id: `outside:identity:azure:${clientId}`, identity: { cloud: "azure", clientId }, label: `Azure identity ${clientId}`, ok: true };
269
+ }
270
+
271
+ function serviceAccount(b, obj, ref) {
272
+ const annotations = isObject(obj.metadata) && isObject(obj.metadata.annotations) ? obj.metadata.annotations : {};
273
+ for (const annotation of [ANNOTATION_GCP, ANNOTATION_AWS, ANNOTATION_AZURE]) {
274
+ if (!(annotation in annotations)) continue;
275
+ const path = `metadata.annotations[${annotation}]`;
276
+ const value = annotations[annotation];
277
+ if (isMasked(value)) {
278
+ b.note(idOf(ref), path, "masked", "the live read masked this annotation", { waitsOn: WAITS_ON_MASK });
279
+ continue;
280
+ }
281
+ if (!str(value)) {
282
+ b.note(idOf(ref), path, "unrecognised", "the annotation is empty or not a string");
283
+ continue;
284
+ }
285
+ const found = identityFor(annotation, value.trim());
286
+ if (!found.ok) {
287
+ b.note(idOf(ref), path, "unrecognised", `${found.why}: ${value}`);
288
+ continue;
289
+ }
290
+ if (holdsIdentity(b.graph, found.identity)) continue;
291
+ const cardAttrs = { ...found.identity };
292
+ b.card({ id: found.id, kind: "CloudIdentity", label: found.label, attrs: cardAttrs });
293
+ b.edge(idOf(ref), ref, found.id, path);
294
+ }
295
+ }
296
+
297
+ // --- ExternalSecret and its store ----------------------------------------
298
+
299
+ function providerOf(store, ref, b) {
300
+ const provider = isObject(store.spec) && isObject(store.spec.provider) ? store.spec.provider : undefined;
301
+ if (!provider) {
302
+ b.note(idOf(ref), "spec.provider", "unrecognised", "the store has no provider");
303
+ return undefined;
304
+ }
305
+ const kinds = Object.keys(provider);
306
+ const known = kinds.filter((k) => k === "gcpsm" || k === "aws" || k === "vault");
307
+ for (const k of kinds) {
308
+ if (!known.includes(k)) b.note(idOf(ref), `spec.provider.${k}`, "unrecognised", `no placeholder rule for the ${k} provider`);
309
+ }
310
+ if (known.length === 0) return undefined;
311
+ const k = known[0];
312
+ const spec = isObject(provider[k]) ? provider[k] : {};
313
+ if (k === "gcpsm") {
314
+ const projectID = str(spec.projectID);
315
+ if (!projectID || isMasked(projectID)) {
316
+ b.note(idOf(ref), "spec.provider.gcpsm.projectID", "unrecognised", "no readable projectID");
317
+ return undefined;
318
+ }
319
+ return { provider: "gcpsm", projectID, id: `outside:provider:gcpsm:${projectID}`, label: `${PROVIDER_LABEL.gcpsm} ${projectID}`, path: "spec.provider.gcpsm" };
320
+ }
321
+ if (k === "aws") {
322
+ const region = str(spec.region);
323
+ const service = str(spec.service) || "SecretsManager";
324
+ if (!region || isMasked(region)) {
325
+ b.note(idOf(ref), "spec.provider.aws.region", "unrecognised", "no readable region");
326
+ return undefined;
327
+ }
328
+ const label = service === "ParameterStore" ? PROVIDER_LABEL.awsParameterStore : PROVIDER_LABEL.aws;
329
+ return { provider: "aws", service, region, id: `outside:provider:aws:${service}:${region}`, label: `${label} ${region}`, path: "spec.provider.aws" };
330
+ }
331
+ const server = str(spec.server);
332
+ if (!server || isMasked(server)) {
333
+ b.note(idOf(ref), "spec.provider.vault.server", "unrecognised", "no readable server");
334
+ return undefined;
335
+ }
336
+ const path = str(spec.path) || "";
337
+ return {
338
+ provider: "vault",
339
+ server,
340
+ ...(path ? { path } : {}),
341
+ id: `outside:provider:vault:${server}/${path}`,
342
+ label: `${PROVIDER_LABEL.vault} ${server}${path ? `/${path}` : ""}`,
343
+ path: "spec.provider.vault",
344
+ };
345
+ }
346
+
347
+ /** The remoteRef keys an ExternalSecret reads, and a note for each shape that gives none. */
348
+ function keysOf(obj, ref, b) {
349
+ const spec = isObject(obj.spec) ? obj.spec : {};
350
+ const keys = [];
351
+ arr(spec.data).forEach((d, i) => {
352
+ const key = isObject(d) && isObject(d.remoteRef) ? d.remoteRef.key : undefined;
353
+ if (str(key) && !isMasked(key)) keys.push(key);
354
+ else b.note(idOf(ref), `spec.data[${i}].remoteRef.key`, "unrecognised", "no readable key");
355
+ });
356
+ arr(spec.dataFrom).forEach((d, i) => {
357
+ const key = isObject(d) && isObject(d.extract) ? d.extract.key : undefined;
358
+ if (str(key) && !isMasked(key)) keys.push(key);
359
+ else b.note(idOf(ref), `spec.dataFrom[${i}]`, "unrecognised", "only extract.key is read; find, sourceRef and the rest name no single secret");
360
+ });
361
+ return keys;
362
+ }
363
+
364
+ function externalSecrets(b, all) {
365
+ const stores = new Map();
366
+ for (const o of all) {
367
+ const r = refOf(o);
368
+ if (r.group === ESO_GROUP && (r.kind === "SecretStore" || r.kind === "ClusterSecretStore") && r.name) stores.set(idOf(r), { obj: o, ref: r });
369
+ }
370
+ // provider id -> { provider, keys:Set } so stores and secrets that name one scope share a card
371
+ const providers = new Map();
372
+ const touch = (storeKey) => {
373
+ const s = stores.get(storeKey);
374
+ if (!s || s.provider !== undefined) return s;
375
+ s.provider = providerOf(s.obj, s.ref, b) || null;
376
+ if (s.provider && !providers.has(s.provider.id)) providers.set(s.provider.id, { provider: s.provider, keys: new Set(), stores: [] });
377
+ if (s.provider) providers.get(s.provider.id).stores.push(s);
378
+ return s;
379
+ };
380
+ for (const key of stores.keys()) touch(key);
381
+
382
+ for (const o of all) {
383
+ const ref = refOf(o);
384
+ if (ref.group !== ESO_GROUP || ref.kind !== "ExternalSecret" || !ref.name) continue;
385
+ const from = idOf(ref);
386
+ const spec = isObject(o.spec) ? o.spec : {};
387
+ const sref = spec.secretStoreRef;
388
+ if (isMasked(sref) || (isObject(sref) && (isMasked(sref.name) || isMasked(sref.kind)))) {
389
+ b.note(from, "spec.secretStoreRef", "masked", "the live read masked secretStoreRef, so the store and the keys cannot be joined", { waitsOn: WAITS_ON_MASK });
390
+ continue;
391
+ }
392
+ if (!isObject(sref) || !str(sref.name)) {
393
+ b.note(from, "spec.secretStoreRef", "unrecognised", "no store named");
394
+ continue;
395
+ }
396
+ const storeKind = str(sref.kind) || "SecretStore";
397
+ if (storeKind !== "SecretStore" && storeKind !== "ClusterSecretStore") {
398
+ b.note(from, "spec.secretStoreRef.kind", "unrecognised", `no placeholder rule for a ${storeKind} store`);
399
+ continue;
400
+ }
401
+ const storeRef = { group: ESO_GROUP, kind: storeKind, namespace: storeKind === "ClusterSecretStore" ? "" : ref.namespace, name: sref.name };
402
+ const keys = keysOf(o, ref, b);
403
+ const held = holdsK8s(b.graph, storeRef);
404
+ const found = touch(idOf(storeRef));
405
+ if (!held) {
406
+ const id = `outside:store:${storeKind}/${storeKind === "SecretStore" ? `${storeRef.namespace}/` : ""}${storeRef.name}`;
407
+ b.card({
408
+ id,
409
+ kind: "SecretStore",
410
+ label: storeKind === "SecretStore" ? `SecretStore ${storeRef.namespace}/${storeRef.name}` : `ClusterSecretStore ${storeRef.name}`,
411
+ attrs: { storeKind, name: storeRef.name, ...(storeRef.namespace ? { namespace: storeRef.namespace } : {}), read: !!found },
412
+ });
413
+ b.edge(from, ref, id, "spec.secretStoreRef");
414
+ }
415
+ if (!found) {
416
+ b.note(from, "spec.secretStoreRef", "unresolved", `${storeKind} ${storeRef.name} is not among the objects read, so its provider is not known`);
417
+ continue;
418
+ }
419
+ if (found.provider) for (const k of keys) providers.get(found.provider.id).keys.add(k);
420
+ }
421
+
422
+ for (const { provider, keys, stores: viaStores } of providers.values()) {
423
+ const kept = [...keys].filter((k) => !holdsSecret(b.graph, provider, k)).sort();
424
+ const { id, label, path, ...attrs } = provider;
425
+ b.card({ id, kind: "SecretProvider", label, attrs: { ...attrs, keys: kept } });
426
+ for (const s of viaStores) b.edge(idOf(s.ref), s.ref, id, path);
427
+ }
428
+ }
429
+
430
+ // --- Argo CD Application and Flux Kustomization --------------------------
431
+
432
+ function sourceCard(b, ref, from, via, { url, path, chart, revision, kindOfSource }) {
433
+ const repo = normalizeUrl(url);
434
+ if (holdsSource(b.graph, repo)) return;
435
+ const where = chart ? `chart=${chart}` : path ? cleanPath(path) : "";
436
+ const id = `outside:source:${repo}#${where}`;
437
+ const label = chart ? `${repo} chart ${chart}` : where ? `${repo} ${where}` : repo;
438
+ b.card({
439
+ id,
440
+ kind: "Source",
441
+ label,
442
+ attrs: { repoURL: repo, ...(path ? { path: cleanPath(path) } : {}), ...(chart ? { chart } : {}), ...(kindOfSource ? { sourceKind: kindOfSource } : {}) },
443
+ });
444
+ b.edge(from, ref, id, via, revision ? { revision } : undefined);
445
+ }
446
+
447
+ function application(b, obj, ref) {
448
+ const from = idOf(ref);
449
+ const spec = isObject(obj.spec) ? obj.spec : {};
450
+ const entries = [];
451
+ if (isObject(spec.source)) entries.push([spec.source, "spec.source"]);
452
+ arr(spec.sources).forEach((s, i) => entries.push([s, `spec.sources[${i}]`]));
453
+ for (const [s, via] of entries) {
454
+ if (!isObject(s)) continue;
455
+ const url = str(s.repoURL);
456
+ if (!url || isMasked(url)) {
457
+ b.note(from, `${via}.repoURL`, "unrecognised", "no readable repoURL");
458
+ continue;
459
+ }
460
+ sourceCard(b, ref, from, via, { url, path: str(s.path), chart: str(s.chart), revision: str(s.targetRevision) });
461
+ }
462
+ }
463
+
464
+ const FLUX_SOURCE_KINDS = new Set(["GitRepository", "OCIRepository", "Bucket"]);
465
+
466
+ function kustomization(b, obj, ref, all) {
467
+ const from = idOf(ref);
468
+ const spec = isObject(obj.spec) ? obj.spec : {};
469
+ const sref = spec.sourceRef;
470
+ if (!isObject(sref) || !str(sref.name)) {
471
+ b.note(from, "spec.sourceRef", "unrecognised", "no source named");
472
+ return;
473
+ }
474
+ const kind = str(sref.kind) || "GitRepository";
475
+ if (!FLUX_SOURCE_KINDS.has(kind)) {
476
+ b.note(from, "spec.sourceRef.kind", "unrecognised", `no placeholder rule for a ${kind} source`);
477
+ return;
478
+ }
479
+ const namespace = str(sref.namespace) || ref.namespace;
480
+ const source = all.find((o) => {
481
+ const r = refOf(o);
482
+ return r.group === FLUX_SOURCE_GROUP && r.kind === kind && r.name === sref.name && r.namespace === namespace;
483
+ });
484
+ if (!source) {
485
+ b.note(from, "spec.sourceRef", "unresolved", `${kind} ${namespace}/${sref.name} is not among the objects read, so the repo is not known`);
486
+ return;
487
+ }
488
+ const sspec = isObject(source.spec) ? source.spec : {};
489
+ const url = kind === "Bucket" ? (str(sspec.endpoint) && str(sspec.bucketName) ? `${sspec.endpoint}/${sspec.bucketName}` : undefined) : str(sspec.url);
490
+ if (!url || isMasked(url)) {
491
+ b.note(from, "spec.sourceRef", "unrecognised", `${kind} ${namespace}/${sref.name} has no readable url`);
492
+ return;
493
+ }
494
+ sourceCard(b, ref, from, "spec.sourceRef", { url, path: str(spec.path), kindOfSource: kind });
495
+ }
496
+
497
+ // --- the function ----------------------------------------------------------
498
+
499
+ /**
500
+ * Placeholder cards, edges and notes for what `objects` name outside the cluster.
501
+ * `opts.graph` is the graph already on the surface, `{ nodes }`.
502
+ */
503
+ export function outsideRefs(objects, opts = {}) {
504
+ const all = flatten(objects);
505
+ const b = builder(opts.graph);
506
+ for (const o of all) {
507
+ const ref = refOf(o);
508
+ if (!ref.kind || !ref.name) continue;
509
+ if (ref.group === "" && ref.kind === "ServiceAccount") serviceAccount(b, o, ref);
510
+ else if (ref.group === ARGO_GROUP && ref.kind === "Application") application(b, o, ref);
511
+ else if (ref.group === FLUX_KUSTOMIZE_GROUP && ref.kind === "Kustomization") kustomization(b, o, ref, all);
512
+ }
513
+ externalSecrets(b, all);
514
+ return b.result();
515
+ }