@intentius/behold 0.31.0 → 0.32.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.
- package/AGENTS.md +347 -1
- package/README.md +64 -10
- package/THIRD_PARTY.md +6 -5
- package/dist/cli.js +32432 -28180
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/README.md +2 -2
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-three-cloud/chant.workspace.json +2 -2
- package/example-three-cloud/package-lock.json +24 -24
- package/example-three-cloud/package.json +5 -5
- package/package.json +20 -9
- package/schemas/graph/v1/graph.schema.json +140 -0
- package/web/app.js +9 -4
- package/web/boot-motion.js +6 -0
- package/web/cut-around.d.ts +30 -0
- package/web/cut-around.js +138 -0
- package/web/edge-weight.d.ts +8 -2
- package/web/edge-weight.js +34 -4
- package/web/edge-weight.test.js +36 -1
- package/web/index.html +8 -20
- package/web/neighbourhood.js +105 -0
- package/web/neighbourhood.test.js +131 -0
- package/web/outside-refs.js +515 -0
- package/web/outside-refs.test.js +249 -0
- package/web/theme-paint.js +14 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { outsideRefs, normalizeUrl } from "./outside-refs.js";
|
|
4
|
+
|
|
5
|
+
const sa = (name, annotations, namespace = "ci") => ({ apiVersion: "v1", kind: "ServiceAccount", metadata: { name, namespace, annotations } });
|
|
6
|
+
const clusterStore = (name, provider) => ({ apiVersion: "external-secrets.io/v1", kind: "ClusterSecretStore", metadata: { name }, spec: { provider } });
|
|
7
|
+
const store = (name, namespace, provider) => ({ apiVersion: "external-secrets.io/v1", kind: "SecretStore", metadata: { name, namespace }, spec: { provider } });
|
|
8
|
+
const externalSecret = (name, namespace, storeRef, keys, extra = {}) => ({
|
|
9
|
+
apiVersion: "external-secrets.io/v1",
|
|
10
|
+
kind: "ExternalSecret",
|
|
11
|
+
metadata: { name, namespace },
|
|
12
|
+
spec: { secretStoreRef: storeRef, data: keys.map((key) => ({ secretKey: "v", remoteRef: { key } })), ...extra },
|
|
13
|
+
});
|
|
14
|
+
const tf = (id, kind, body) => ({ id, kind, lexicon: "terraform", attrs: { address: id, body } });
|
|
15
|
+
|
|
16
|
+
const ARN = "arn:aws:iam::111122223333:role/ci-runner";
|
|
17
|
+
const GCP_STORE = clusterStore("gcp", { gcpsm: { projectID: "demo-proj" } });
|
|
18
|
+
|
|
19
|
+
describe("ServiceAccount annotations", () => {
|
|
20
|
+
it("gives an IRSA role one card labelled with the role and an edge from the account", () => {
|
|
21
|
+
const out = outsideRefs([sa("runner", { "eks.amazonaws.com/role-arn": ARN })]);
|
|
22
|
+
expect(out.cards).toEqual([
|
|
23
|
+
{ id: `outside:identity:aws:${ARN}`, kind: "CloudIdentity", label: ARN, placeholder: true, attrs: { cloud: "aws", arn: ARN, account: "111122223333", role: "ci-runner" } },
|
|
24
|
+
]);
|
|
25
|
+
expect(out.edges).toEqual([
|
|
26
|
+
{
|
|
27
|
+
from: "/ServiceAccount/ci/runner",
|
|
28
|
+
fromRef: { group: "", kind: "ServiceAccount", namespace: "ci", name: "runner" },
|
|
29
|
+
to: `outside:identity:aws:${ARN}`,
|
|
30
|
+
kind: "ref",
|
|
31
|
+
viaAttr: "metadata.annotations[eks.amazonaws.com/role-arn]",
|
|
32
|
+
inferred: true,
|
|
33
|
+
placeholder: true,
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
expect(out.notes).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("shares one card between two accounts with the same annotation", () => {
|
|
40
|
+
const out = outsideRefs([sa("a", { "eks.amazonaws.com/role-arn": ARN }), sa("b", { "eks.amazonaws.com/role-arn": ARN }, "other")]);
|
|
41
|
+
expect(out.cards).toHaveLength(1);
|
|
42
|
+
expect(out.edges.map((e) => e.from)).toEqual(["/ServiceAccount/ci/a", "/ServiceAccount/other/b"]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("reads the GKE and Azure annotations", () => {
|
|
46
|
+
const out = outsideRefs([
|
|
47
|
+
sa("g", { "iam.gke.io/gcp-service-account": "runner@demo-proj.iam.gserviceaccount.com" }),
|
|
48
|
+
sa("z", { "azure.workload.identity/client-id": "AAAA-BBBB" }),
|
|
49
|
+
]);
|
|
50
|
+
expect(out.cards.map((c) => c.id)).toEqual(["outside:identity:azure:aaaa-bbbb", "outside:identity:gcp:runner@demo-proj.iam.gserviceaccount.com"]);
|
|
51
|
+
expect(out.cards[1].attrs).toEqual({ cloud: "gcp", email: "runner@demo-proj.iam.gserviceaccount.com", project: "demo-proj" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("returns no card for a role the graph already holds", () => {
|
|
55
|
+
const graph = { nodes: [tf("tf/aws_iam_role.ci", "aws_iam_role", { name: "ci-runner" })] };
|
|
56
|
+
expect(outsideRefs([sa("runner", { "eks.amazonaws.com/role-arn": ARN })], { graph })).toEqual({ cards: [], edges: [], notes: [] });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("holds a role by an address in the node id and a service account by account_id and project", () => {
|
|
60
|
+
const graph = {
|
|
61
|
+
nodes: [
|
|
62
|
+
{ id: "tf/module.x.aws_iam_role.ci[0]", kind: "Terraform::Resource", lexicon: "terraform", attrs: { arn: ARN } },
|
|
63
|
+
tf("tf/google_service_account.r", "google_service_account", { account_id: "runner", project: "demo-proj" }),
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
const out = outsideRefs([sa("a", { "eks.amazonaws.com/role-arn": ARN }), sa("b", { "iam.gke.io/gcp-service-account": "runner@demo-proj.iam.gserviceaccount.com" })], { graph });
|
|
67
|
+
expect(out.cards).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("does not take a service account in another project as the held one", () => {
|
|
71
|
+
const graph = { nodes: [tf("tf/google_service_account.r", "google_service_account", { account_id: "runner", project: "other-proj" })] };
|
|
72
|
+
const out = outsideRefs([sa("b", { "iam.gke.io/gcp-service-account": "runner@demo-proj.iam.gserviceaccount.com" })], { graph });
|
|
73
|
+
expect(out.cards).toHaveLength(1);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("puts an annotation it cannot read in notes", () => {
|
|
77
|
+
const out = outsideRefs([sa("a", { "eks.amazonaws.com/role-arn": "not-an-arn" }), sa("b", { "iam.gke.io/gcp-service-account": "<masked>" })]);
|
|
78
|
+
expect(out.cards).toEqual([]);
|
|
79
|
+
expect(out.notes.map((n) => [n.code, n.path])).toEqual([
|
|
80
|
+
["unrecognised", "metadata.annotations[eks.amazonaws.com/role-arn]"],
|
|
81
|
+
["masked", "metadata.annotations[iam.gke.io/gcp-service-account]"],
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("ExternalSecret and its store", () => {
|
|
87
|
+
const es = externalSecret("app-creds", "app", { name: "gcp", kind: "ClusterSecretStore" }, ["app-token"]);
|
|
88
|
+
|
|
89
|
+
it("gives a store card and a provider card naming the project and the key", () => {
|
|
90
|
+
const out = outsideRefs([GCP_STORE, es]);
|
|
91
|
+
expect(out.cards).toEqual([
|
|
92
|
+
{
|
|
93
|
+
id: "outside:provider:gcpsm:demo-proj",
|
|
94
|
+
kind: "SecretProvider",
|
|
95
|
+
label: "GCP Secret Manager demo-proj",
|
|
96
|
+
placeholder: true,
|
|
97
|
+
attrs: { provider: "gcpsm", projectID: "demo-proj", keys: ["app-token"] },
|
|
98
|
+
},
|
|
99
|
+
{ id: "outside:store:ClusterSecretStore/gcp", kind: "SecretStore", label: "ClusterSecretStore gcp", placeholder: true, attrs: { storeKind: "ClusterSecretStore", name: "gcp", read: true } },
|
|
100
|
+
]);
|
|
101
|
+
expect(out.edges.map((e) => [e.from, e.to, e.viaAttr])).toEqual([
|
|
102
|
+
["external-secrets.io/ClusterSecretStore//gcp", "outside:provider:gcpsm:demo-proj", "spec.provider.gcpsm"],
|
|
103
|
+
["external-secrets.io/ExternalSecret/app/app-creds", "outside:store:ClusterSecretStore/gcp", "spec.secretStoreRef"],
|
|
104
|
+
]);
|
|
105
|
+
expect(out.notes).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("collects the keys of every secret that uses the store, and dataFrom extract keys", () => {
|
|
109
|
+
const more = externalSecret("db", "app", { name: "gcp", kind: "ClusterSecretStore" }, ["db-pass"], { dataFrom: [{ extract: { key: "bulk" } }] });
|
|
110
|
+
const out = outsideRefs([GCP_STORE, es, more]);
|
|
111
|
+
expect(out.cards.find((c) => c.kind === "SecretProvider").attrs.keys).toEqual(["app-token", "bulk", "db-pass"]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("looks a SecretStore up in the secret's own namespace", () => {
|
|
115
|
+
const other = store("gcp", "elsewhere", { gcpsm: { projectID: "other-proj" } });
|
|
116
|
+
const ns = externalSecret("app-creds", "app", { name: "gcp" }, ["k"]);
|
|
117
|
+
const out = outsideRefs([other, ns]);
|
|
118
|
+
expect(out.cards.map((c) => c.id)).toEqual(["outside:provider:gcpsm:other-proj", "outside:store:SecretStore/app/gcp"]);
|
|
119
|
+
// the store in "elsewhere" is not the one "app" uses: its card says it was not read, and a note says why
|
|
120
|
+
expect(out.cards[1].attrs.read).toBe(false);
|
|
121
|
+
expect(out.notes.map((n) => n.code)).toEqual(["unresolved"]);
|
|
122
|
+
// and the key went nowhere
|
|
123
|
+
expect(out.cards[0].attrs.keys).toEqual([]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("reads AWS and Vault providers", () => {
|
|
127
|
+
const out = outsideRefs([
|
|
128
|
+
clusterStore("aws", { aws: { service: "SecretsManager", region: "eu-west-1" } }),
|
|
129
|
+
clusterStore("vault", { vault: { server: "https://vault.example.com", path: "secret" } }),
|
|
130
|
+
externalSecret("a", "app", { name: "aws", kind: "ClusterSecretStore" }, ["prod/db"]),
|
|
131
|
+
]);
|
|
132
|
+
expect(out.cards.map((c) => [c.id, c.label])).toEqual([
|
|
133
|
+
["outside:provider:aws:SecretsManager:eu-west-1", "AWS Secrets Manager eu-west-1"],
|
|
134
|
+
["outside:provider:vault:https://vault.example.com/secret", "Vault https://vault.example.com/secret"],
|
|
135
|
+
["outside:store:ClusterSecretStore/aws", "ClusterSecretStore aws"],
|
|
136
|
+
]);
|
|
137
|
+
expect(out.cards[0].attrs.keys).toEqual(["prod/db"]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("drops a key the graph holds from the provider card, and the store card when the graph holds the store", () => {
|
|
141
|
+
const graph = {
|
|
142
|
+
nodes: [
|
|
143
|
+
tf("tf/google_secret_manager_secret.t", "google_secret_manager_secret", { secret_id: "app-token", project: "demo-proj" }),
|
|
144
|
+
{ id: "k/gcp", kind: "K8s::Core::ClusterSecretStore", lexicon: "k8s", attrs: { kind: "ClusterSecretStore", metadata: { name: "gcp" } } },
|
|
145
|
+
],
|
|
146
|
+
};
|
|
147
|
+
const out = outsideRefs([GCP_STORE, es, externalSecret("b", "app", { name: "gcp", kind: "ClusterSecretStore" }, ["other-token"])], { graph });
|
|
148
|
+
expect(out.cards.map((c) => c.id)).toEqual(["outside:provider:gcpsm:demo-proj"]);
|
|
149
|
+
expect(out.cards[0].attrs.keys).toEqual(["other-token"]);
|
|
150
|
+
expect(out.edges.map((e) => e.to)).toEqual(["outside:provider:gcpsm:demo-proj"]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("puts a provider with no rule and a dataFrom with no key in notes", () => {
|
|
154
|
+
const out = outsideRefs([
|
|
155
|
+
clusterStore("ibm", { ibm: { serviceUrl: "https://x" } }),
|
|
156
|
+
externalSecret("a", "app", { name: "ibm", kind: "ClusterSecretStore" }, [], { dataFrom: [{ find: { name: { regexp: "x" } } }] }),
|
|
157
|
+
]);
|
|
158
|
+
expect(out.cards.map((c) => c.id)).toEqual(["outside:store:ClusterSecretStore/ibm"]);
|
|
159
|
+
expect(out.notes.map((n) => n.path).sort()).toEqual(["spec.dataFrom[0]", "spec.provider.ibm"]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("notes a masked secretStoreRef and names the ruling it waits on, joining nothing", () => {
|
|
163
|
+
// what chant's live read hands back: any key matching /secret/i is masked whole
|
|
164
|
+
const live = { ...externalSecret("app-creds", "app", "<masked>", ["app-token"]) };
|
|
165
|
+
live.spec.secretStoreRef = "<masked>";
|
|
166
|
+
const out = outsideRefs([GCP_STORE, live]);
|
|
167
|
+
expect(out.notes).toEqual([
|
|
168
|
+
{
|
|
169
|
+
code: "masked",
|
|
170
|
+
from: "external-secrets.io/ExternalSecret/app/app-creds",
|
|
171
|
+
path: "spec.secretStoreRef",
|
|
172
|
+
message: "the live read masked secretStoreRef, so the store and the keys cannot be joined",
|
|
173
|
+
waitsOn: "INTENTIUS/chant#5116",
|
|
174
|
+
},
|
|
175
|
+
]);
|
|
176
|
+
// the store object still gives its provider card, with no keys
|
|
177
|
+
expect(out.cards.map((c) => [c.id, c.attrs.keys])).toEqual([["outside:provider:gcpsm:demo-proj", []]]);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("sources", () => {
|
|
182
|
+
const app = (name, spec) => ({ apiVersion: "argoproj.io/v1alpha1", kind: "Application", metadata: { name, namespace: "argocd" }, spec });
|
|
183
|
+
|
|
184
|
+
it("gives an Application source a card for the repo and path, and one per entry of sources", () => {
|
|
185
|
+
const out = outsideRefs([
|
|
186
|
+
app("one", { source: { repoURL: "https://GitHub.com/acme/infra.git", path: "./apps/web", targetRevision: "main" } }),
|
|
187
|
+
app("two", { sources: [{ repoURL: "https://charts.example.com", chart: "nginx" }, { repoURL: "https://github.com/acme/infra/", path: "apps/web" }] }),
|
|
188
|
+
]);
|
|
189
|
+
expect(out.cards.map((c) => c.id)).toEqual(["outside:source:https://charts.example.com#chart=nginx", "outside:source:https://github.com/acme/infra#apps/web"]);
|
|
190
|
+
expect(out.cards[1].attrs).toEqual({ repoURL: "https://github.com/acme/infra", path: "apps/web" });
|
|
191
|
+
expect(out.edges.map((e) => [e.from, e.viaAttr, e.revision])).toEqual([
|
|
192
|
+
["argoproj.io/Application/argocd/one", "spec.source", "main"],
|
|
193
|
+
["argoproj.io/Application/argocd/two", "spec.sources[0]", undefined],
|
|
194
|
+
["argoproj.io/Application/argocd/two", "spec.sources[1]", undefined],
|
|
195
|
+
]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("notes an Application source with no repoURL", () => {
|
|
199
|
+
const out = outsideRefs([app("x", { source: { path: "a" } })]);
|
|
200
|
+
expect(out.cards).toEqual([]);
|
|
201
|
+
expect(out.notes[0]).toMatchObject({ code: "unrecognised", path: "spec.source.repoURL" });
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("takes a Kustomization's repo from its source object and its path from spec.path", () => {
|
|
205
|
+
const git = { apiVersion: "source.toolkit.fluxcd.io/v1", kind: "GitRepository", metadata: { name: "fleet", namespace: "flux-system" }, spec: { url: "ssh://git@github.com/acme/fleet.git" } };
|
|
206
|
+
const ks = { apiVersion: "kustomize.toolkit.fluxcd.io/v1", kind: "Kustomization", metadata: { name: "apps", namespace: "flux-system" }, spec: { path: "./clusters/prod", sourceRef: { kind: "GitRepository", name: "fleet" } } };
|
|
207
|
+
const out = outsideRefs([git, ks]);
|
|
208
|
+
expect(out.cards.map((c) => [c.id, c.attrs.sourceKind])).toEqual([["outside:source:ssh://git@github.com/acme/fleet#clusters/prod", "GitRepository"]]);
|
|
209
|
+
expect(out.edges[0]).toMatchObject({ from: "kustomize.toolkit.fluxcd.io/Kustomization/flux-system/apps", viaAttr: "spec.sourceRef" });
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("notes a Kustomization whose source object was not read", () => {
|
|
213
|
+
const ks = { apiVersion: "kustomize.toolkit.fluxcd.io/v1", kind: "Kustomization", metadata: { name: "apps", namespace: "flux-system" }, spec: { sourceRef: { kind: "GitRepository", name: "fleet" } } };
|
|
214
|
+
expect(outsideRefs([ks]).notes[0]).toMatchObject({ code: "unresolved", path: "spec.sourceRef" });
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("returns no card for a repo the graph holds", () => {
|
|
218
|
+
const graph = { nodes: [{ id: "g", kind: "github_repository", attrs: { clone_url: "https://github.com/acme/infra.git" } }] };
|
|
219
|
+
expect(outsideRefs([app("one", { source: { repoURL: "https://github.com/acme/infra", path: "x" } })], { graph }).cards).toEqual([]);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("normalizes a URL the same whichever way it is written", () => {
|
|
223
|
+
expect(normalizeUrl("https://GitHub.com/acme/infra.git/")).toBe("https://github.com/acme/infra");
|
|
224
|
+
expect(normalizeUrl("git@github.com:acme/infra.git")).toBe("git@github.com:acme/infra");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("input shapes", () => {
|
|
229
|
+
it("opens a List and skips what it has no rule for", () => {
|
|
230
|
+
const list = { apiVersion: "v1", kind: "List", items: [sa("r", { "eks.amazonaws.com/role-arn": ARN }), { apiVersion: "apps/v1", kind: "Deployment", metadata: { name: "web" } }] };
|
|
231
|
+
expect(outsideRefs([list, null, "x"]).cards).toHaveLength(1);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("gives the same answer whatever order the objects arrive in", () => {
|
|
235
|
+
const objs = [GCP_STORE, externalSecret("a", "app", { name: "gcp", kind: "ClusterSecretStore" }, ["k"]), sa("r", { "eks.amazonaws.com/role-arn": ARN })];
|
|
236
|
+
expect(outsideRefs([...objs].reverse())).toEqual(outsideRefs(objs));
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("browser safety", () => {
|
|
241
|
+
it("imports nothing", () => {
|
|
242
|
+
const text = readFileSync(new URL("./outside-refs.js", import.meta.url), "utf8")
|
|
243
|
+
.split("\n")
|
|
244
|
+
.filter((l) => !l.trimStart().startsWith("//"))
|
|
245
|
+
.join("\n");
|
|
246
|
+
expect(text).not.toMatch(/(^|\n)\s*import\b/);
|
|
247
|
+
expect(text).not.toMatch(/\brequire\s*\(|\bnode:|\bprocess\./);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// behold#1068: the pre-paint theme, a classic script so it runs in <head> before the first frame.
|
|
2
|
+
// Loaded by <script src> (index.html), because a webview's content security policy blocks an inline one.
|
|
3
|
+
// The kiosk's frame (?bare=1) paints nothing until its theme is applied, so the kiosk's own ground shows through:
|
|
4
|
+
// the stylesheet's default --bg is white, and a first load with no stored paint flashed it over a dark pane.
|
|
5
|
+
try { if (/[?&]bare=1(&|$)/.test(location.search)) document.documentElement.style.setProperty("--bg", "transparent"); } catch (e) { /* the default paints */ }
|
|
6
|
+
try {
|
|
7
|
+
var beholdTheme = localStorage.getItem("behold.theme");
|
|
8
|
+
var beholdPaint = beholdTheme && JSON.parse(localStorage.getItem("behold.theme.paint") || "null");
|
|
9
|
+
if (beholdPaint && beholdPaint.name === beholdTheme && beholdPaint.vars) {
|
|
10
|
+
var beholdRoot = document.documentElement;
|
|
11
|
+
for (var k in beholdPaint.vars) if (k.slice(0, 2) === "--") beholdRoot.style.setProperty(k, beholdPaint.vars[k]);
|
|
12
|
+
if (beholdPaint.scheme) beholdRoot.style.setProperty("color-scheme", beholdPaint.scheme);
|
|
13
|
+
}
|
|
14
|
+
} catch (e) { /* private mode or a bad record: the default paints */ }
|