passport-bridge 0.48.2 → 0.49.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/dist/cliHookAfter.js +10 -1
- package/dist/cliHookDecide.d.ts +9 -3
- package/dist/cliHookDecide.js +182 -28
- package/dist/cliHookSessionState.d.ts +4 -1
- package/dist/cliHookSessionState.js +1 -1
- package/dist/connectorKit/callEffects.generated.d.ts +36 -0
- package/dist/connectorKit/callEffects.generated.js +73 -0
- package/dist/connectorKit/cli.generated.js +5 -2
- package/dist/connectorKit/engine.generated.d.ts +1 -1
- package/dist/connectorKit/engine.generated.js +32 -13
- package/dist/connectorKit/githubIds.generated.d.ts +1 -1
- package/dist/connectorKit/githubIds.generated.js +3 -2
- package/dist/connectorKit/manifest.generated.d.ts +34 -14
- package/dist/connectorKit/manifests/cloudflare.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/cloudflare.generated.js +186 -0
- package/dist/connectorKit/manifests/cloudflareApi.generated.d.ts +4 -0
- package/dist/connectorKit/manifests/cloudflareApi.generated.js +207 -0
- package/dist/connectorKit/manifests/cloudflareCatalog.generated.d.ts +18 -0
- package/dist/connectorKit/manifests/cloudflareCatalog.generated.js +83 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.js +441 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +19 -1
- package/dist/connectorKit/manifests/githubReads.generated.js +0 -3
- package/dist/connectorKit/manifests/kubernetes.generated.d.ts +76 -0
- package/dist/connectorKit/manifests/kubernetes.generated.js +210 -0
- package/dist/connectorKit/manifests/kubernetesArgs.generated.d.ts +21 -0
- package/dist/connectorKit/manifests/kubernetesArgs.generated.js +82 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.js +530 -0
- package/dist/connectorKit/manifests/kubernetesEffects.generated.d.ts +15 -0
- package/dist/connectorKit/manifests/kubernetesEffects.generated.js +111 -0
- package/dist/connectorKit/manifests/kubernetesObjects.generated.d.ts +24 -0
- package/dist/connectorKit/manifests/kubernetesObjects.generated.js +154 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.js +11 -5
- package/dist/connectorKit/manifests/sentry.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/sentry.generated.js +27 -0
- package/dist/connectorKit/manifests/sentryApi.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/sentryApi.generated.js +282 -0
- package/dist/connectorKit/manifests/sentryCapture.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/sentryCapture.generated.js +165 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.js +70 -0
- package/dist/connectorKit/manifests/sentryCli.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/sentryCli.generated.js +230 -0
- package/dist/connectorKit/manifests/sentryIssues.generated.d.ts +20 -0
- package/dist/connectorKit/manifests/sentryIssues.generated.js +204 -0
- package/dist/connectorKit/manifests/supabase.generated.js +3 -2
- package/dist/connectorKit/manifests/supabaseApi.generated.js +52 -52
- package/dist/connectorKit/manifests/supabaseCapture.generated.js +22 -21
- package/dist/connectorKit/manifests/supabaseCatalog.generated.d.ts +2 -2
- package/dist/connectorKit/manifests/supabaseCatalog.generated.js +8 -7
- package/dist/connectorKit/manifests/supabaseCli.generated.js +32 -32
- package/dist/connectorKit/manifests/supabaseProbes.generated.js +29 -29
- package/dist/connectorKit/manifests/terraform.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/terraform.generated.js +214 -0
- package/dist/connectorKit/manifests/terraformLink.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/terraformLink.generated.js +73 -0
- package/dist/connectorKit/manifests/terraformPlan.generated.d.ts +48 -0
- package/dist/connectorKit/manifests/terraformPlan.generated.js +192 -0
- package/dist/connectorKit/params.generated.js +2 -0
- package/dist/connectorKit/shell.generated.d.ts +5 -1
- package/dist/connectorKit/shell.generated.js +121 -20
- package/dist/connectorKit/sources/cloudflare/api-operations.generated.d.ts +37 -0
- package/dist/connectorKit/sources/cloudflare/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/cli-flags.generated.d.ts +617 -0
- package/dist/connectorKit/sources/cloudflare/cli-flags.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.d.ts +16 -0
- package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/api-operations.generated.d.ts +121 -0
- package/dist/connectorKit/sources/sentry/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.d.ts +530 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/mcp-tools.generated.d.ts +32 -0
- package/dist/connectorKit/sources/sentry/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/template.generated.d.ts +8 -4
- package/dist/connectorKit/template.generated.js +19 -6
- package/dist/controlPlane.generated.d.ts +11 -2
- package/dist/controlPlaneActions.generated.d.ts +52 -12
- package/dist/controlPlaneActions.generated.js +40 -11
- package/dist/controlPlaneCloudflare.d.ts +70 -0
- package/dist/controlPlaneCloudflare.js +188 -0
- package/dist/controlPlaneKubernetes.d.ts +72 -0
- package/dist/controlPlaneKubernetes.js +260 -0
- package/dist/controlPlaneModel.generated.d.ts +6 -0
- package/dist/controlPlaneNpm.generated.d.ts +83 -0
- package/dist/controlPlaneNpm.generated.js +307 -0
- package/dist/controlPlaneNpmCommands.generated.d.ts +35 -0
- package/dist/controlPlaneNpmCommands.generated.js +567 -0
- package/dist/controlPlaneNpmGuard.d.ts +44 -0
- package/dist/controlPlaneNpmGuard.js +210 -0
- package/dist/controlPlaneOffline.d.ts +1 -1
- package/dist/controlPlaneRailway.generated.js +2 -2
- package/dist/controlPlaneRailwayCli.generated.js +13 -2
- package/dist/controlPlaneRailwayModel.generated.d.ts +5 -0
- package/dist/controlPlaneRailwayModel.generated.js +15 -1
- package/dist/controlPlaneSentry.d.ts +68 -0
- package/dist/controlPlaneSentry.js +205 -0
- package/dist/controlPlaneTerraform.d.ts +86 -0
- package/dist/controlPlaneTerraform.js +273 -0
- package/dist/controlPlaneUnnamed.generated.d.ts +41 -2
- package/dist/controlPlaneUnnamed.generated.js +148 -2
- package/dist/cpCli.d.ts +1 -1
- package/dist/cpCli.js +1 -1
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/terraformPlans.d.ts +45 -0
- package/dist/terraformPlans.js +96 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { unnamedCli } from "../../controlPlaneUnnamed.generated.js";
|
|
2
|
+
import { kubeKind, namespaceNode, objectNode, placeNode, releaseNode, safeKubeName } from "./kubernetes.generated.js";
|
|
3
|
+
import { KUBE_ASIDE, UNREAD_MANIFEST } from "./kubernetesEffects.generated.js";
|
|
4
|
+
import { all, dryRun, flag, HELM_VALUES, KUBECTL_VALUES, on, parse, programOf } from "./kubernetesArgs.generated.js";
|
|
5
|
+
/* ------------------------------------------------------------------ */
|
|
6
|
+
/* Places and objects */
|
|
7
|
+
/* ------------------------------------------------------------------ */
|
|
8
|
+
const NAMESPACE = /^[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?$/;
|
|
9
|
+
const OBJECT_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,252}$/;
|
|
10
|
+
const goodNamespace = (value) => Boolean(value && NAMESPACE.test(value));
|
|
11
|
+
function placeOf(flags, resolver, helm) {
|
|
12
|
+
const env = resolver.env ?? {};
|
|
13
|
+
const contextFlag = helm ? (flag(flags, "--kube-context") ?? env.HELM_KUBECONTEXT) : flag(flags, "--context");
|
|
14
|
+
const kubeconfig = flag(flags, "--kubeconfig") ?? (helm ? env.HELM_KUBECONFIG : undefined);
|
|
15
|
+
const elsewhere = helm ? flag(flags, "--kube-apiserver") : flag(flags, "-s", "--server");
|
|
16
|
+
const read = elsewhere ? null : resolver.context(contextFlag, kubeconfig);
|
|
17
|
+
const context = read && safeKubeName(read.name) ? read : null;
|
|
18
|
+
// `--cluster` points the context at another cluster of the kubeconfig: production by its name too.
|
|
19
|
+
const cluster = helm ? undefined : flag(flags, "--cluster");
|
|
20
|
+
const named = context && cluster && safeKubeName(cluster) ? { ...context, cluster } : context;
|
|
21
|
+
const given = flag(flags, "-n", "--namespace") ?? (helm ? env.HELM_NAMESPACE : undefined);
|
|
22
|
+
const namespace = goodNamespace(given) ? given : goodNamespace(context?.namespace) ? context.namespace : "default";
|
|
23
|
+
const allNamespaces = on(flags, "-A", "--all-namespaces");
|
|
24
|
+
return { place: { context: named, ...(allNamespaces ? {} : { namespace }) }, allNamespaces };
|
|
25
|
+
}
|
|
26
|
+
function namedObjects(args) {
|
|
27
|
+
if (!args.length)
|
|
28
|
+
return [];
|
|
29
|
+
if (args[0].includes("/")) {
|
|
30
|
+
const out = [];
|
|
31
|
+
// `key=value` words (a label, `container=image`) aren't objects.
|
|
32
|
+
for (const arg of args.filter((word) => !word.includes("="))) {
|
|
33
|
+
const slash = arg.indexOf("/");
|
|
34
|
+
const kind = slash > 0 ? kubeKind(arg.slice(0, slash)) : null;
|
|
35
|
+
const name = arg.slice(slash + 1);
|
|
36
|
+
if (!kind || !OBJECT_NAME.test(name))
|
|
37
|
+
return null;
|
|
38
|
+
const same = out.find((entry) => entry.kind.kind === kind.kind);
|
|
39
|
+
if (same)
|
|
40
|
+
same.names.push(name);
|
|
41
|
+
else
|
|
42
|
+
out.push({ kind, names: [name] });
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
const kinds = args[0].split(",").map(kubeKind);
|
|
47
|
+
if (kinds.some((kind) => !kind))
|
|
48
|
+
return null;
|
|
49
|
+
const names = args.slice(1).filter((name) => OBJECT_NAME.test(name));
|
|
50
|
+
return kinds.map((kind) => ({ kind: kind, names }));
|
|
51
|
+
}
|
|
52
|
+
const plural = (kind) => /(?:s|x|ch|sh)$/.test(kind) ? `${kind}es` : kind.endsWith("y") ? `${kind.slice(0, -1)}ies` : `${kind}s`;
|
|
53
|
+
/** " in shop", " across all namespaces", or nothing (a cluster-wide resource). */
|
|
54
|
+
function where(place, allNamespaces, clusterScoped) {
|
|
55
|
+
if (clusterScoped)
|
|
56
|
+
return "";
|
|
57
|
+
if (allNamespaces)
|
|
58
|
+
return " across all namespaces";
|
|
59
|
+
return place.namespace ? ` in ${place.namespace}` : "";
|
|
60
|
+
}
|
|
61
|
+
const found = (key, summary, at, extra = {}) => ({
|
|
62
|
+
nodeId: at.nodeId,
|
|
63
|
+
actionKey: `kubernetes.${key}`,
|
|
64
|
+
summary,
|
|
65
|
+
...(at.nodes.length ? { nodes: at.nodes } : {}),
|
|
66
|
+
...extra
|
|
67
|
+
});
|
|
68
|
+
/** One action over the names of one type: the object's own node for one name, the namespace (or cluster) for several
|
|
69
|
+
* or none, with the count in the words ("Delete 3 pods"). */
|
|
70
|
+
function onNames(key, verb, named, where_, opts = {}) {
|
|
71
|
+
const { kind, names } = named;
|
|
72
|
+
const scope = kind.kind === "namespace" || kind.clusterScoped ? { context: where_.place.context } : where_.place;
|
|
73
|
+
const place = where(where_.place, where_.allNamespaces, kind.clusterScoped || kind.kind === "namespace");
|
|
74
|
+
const tail = opts.tail ?? "";
|
|
75
|
+
const aside = opts.aside ? ` ${opts.aside}` : "";
|
|
76
|
+
if (names.length === 1 && !where_.allNamespaces) {
|
|
77
|
+
const own = objectNode(where_.place, kind, names[0]);
|
|
78
|
+
return found(key, `${verb} ${own.label}${tail}${place}${aside}`, own);
|
|
79
|
+
}
|
|
80
|
+
const at = where_.allNamespaces ? placeNode({ context: where_.place.context }) : placeNode(scope);
|
|
81
|
+
const what = names.length > 1 ? `${names.length} ${plural(kind.kind)}` : (opts.none ?? `all ${plural(kind.kind)}`);
|
|
82
|
+
return found(key, `${verb} ${what}${tail}${place}${aside}`, at);
|
|
83
|
+
}
|
|
84
|
+
/* ------------------------------------------------------------------ */
|
|
85
|
+
/* Which action */
|
|
86
|
+
/* ------------------------------------------------------------------ */
|
|
87
|
+
const WORKLOAD_DELETE = {
|
|
88
|
+
namespace: "namespace.delete",
|
|
89
|
+
storage: "storage.delete",
|
|
90
|
+
pod: "pod.delete"
|
|
91
|
+
};
|
|
92
|
+
/** The delete action of a kind. */
|
|
93
|
+
const deleteKey = (category) => WORKLOAD_DELETE[category] ?? "object.delete";
|
|
94
|
+
/** The change action of a kind, from what it is (and, from a manifest, whether it is public). */
|
|
95
|
+
function changeKey(category, exposed) {
|
|
96
|
+
if (exposed)
|
|
97
|
+
return "network.expose";
|
|
98
|
+
if (category === "workload" || category === "pod")
|
|
99
|
+
return "workload.change";
|
|
100
|
+
if (category === "access" || category === "secret")
|
|
101
|
+
return "access.change";
|
|
102
|
+
return "object.change";
|
|
103
|
+
}
|
|
104
|
+
/** A pod name a controller generated: a Deployment's (`web-7d9f8c6b5-x2k4p`), a StatefulSet's (`db-0`), a DaemonSet's
|
|
105
|
+
* or Job's (`agent-x2k4p`). */
|
|
106
|
+
const CONTROLLED_POD = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?-(?:[a-z0-9]{6,10}-[a-z0-9]{5}|[a-z0-9]{5}|\d{1,4})$/;
|
|
107
|
+
/* ------------------------------------------------------------------ */
|
|
108
|
+
/* Manifests */
|
|
109
|
+
/* ------------------------------------------------------------------ */
|
|
110
|
+
/** The objects of `-f` (and `-k`, which Passport doesn't render: unread), grouped into one action per action key and
|
|
111
|
+
* namespace: one object is its own node, several their namespace. */
|
|
112
|
+
function fromManifests(verb, parsed, where_, resolver, keyOf, aside) {
|
|
113
|
+
const paths = all(parsed.flags, "-f", "--filename");
|
|
114
|
+
const kustomize = all(parsed.flags, "-k", "--kustomize");
|
|
115
|
+
const read = paths.length
|
|
116
|
+
? resolver.manifests(paths, on(parsed.flags, "-R", "--recursive"))
|
|
117
|
+
: { objects: [], unread: false };
|
|
118
|
+
const out = [];
|
|
119
|
+
const groups = new Map();
|
|
120
|
+
for (const object of read.objects) {
|
|
121
|
+
const kind = kubeKind(object.kind);
|
|
122
|
+
if (!kind)
|
|
123
|
+
continue;
|
|
124
|
+
const key = keyOf(object, kind);
|
|
125
|
+
const namespace = kind.clusterScoped || kind.kind === "namespace" ? undefined : (object.namespace ?? "");
|
|
126
|
+
const id = `${key}\u0000${namespace ?? "\u0001"}`;
|
|
127
|
+
const group = groups.get(id) ?? { key, ...(namespace === undefined ? {} : { namespace }), objects: [] };
|
|
128
|
+
group.objects.push([object, kind]);
|
|
129
|
+
groups.set(id, group);
|
|
130
|
+
}
|
|
131
|
+
const tail = aside ? ` ${aside}` : "";
|
|
132
|
+
for (const group of groups.values()) {
|
|
133
|
+
const namespace = group.namespace || where_.place.namespace;
|
|
134
|
+
const place = { context: where_.place.context, ...(namespace ? { namespace } : {}) };
|
|
135
|
+
const scoped = group.namespace === undefined;
|
|
136
|
+
const in_ = scoped ? "" : namespace ? ` in ${namespace}` : "";
|
|
137
|
+
if (group.objects.length === 1) {
|
|
138
|
+
const [object, kind] = group.objects[0];
|
|
139
|
+
if (object.name) {
|
|
140
|
+
const own = objectNode(place, kind, object.name);
|
|
141
|
+
out.push(found(group.key, `${verb} ${own.label}${in_}${tail}`, own));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const at = placeNode(scoped ? { context: place.context } : place);
|
|
146
|
+
const what = group.objects.length === 1 ? `a ${group.objects[0][1].kind}` : `${group.objects.length} resources`;
|
|
147
|
+
out.push(found(group.key, `${verb} ${what}${in_}${tail}`, at));
|
|
148
|
+
}
|
|
149
|
+
if (read.unread || kustomize.length || (!paths.length && !kustomize.length)) {
|
|
150
|
+
const at = placeNode(where_.place);
|
|
151
|
+
out.push(found("object.change", `${verb} ${UNREAD_MANIFEST}${where(where_.place, where_.allNamespaces)}`, at));
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
const changeOf = (object, kind) => changeKey(kind.category, object.public);
|
|
156
|
+
const deleteOf = (object, kind) => kind.category === "pod" ? "pod.delete" : deleteKey(kind.category);
|
|
157
|
+
/* ------------------------------------------------------------------ */
|
|
158
|
+
/* kubectl */
|
|
159
|
+
/* ------------------------------------------------------------------ */
|
|
160
|
+
/** Commands that only read, or change only this computer. */
|
|
161
|
+
const KUBECTL_READS = new Set(("get describe logs log top explain diff wait events api-resources api-versions cluster-info version " +
|
|
162
|
+
"config completion kustomize port-forward proxy plugin options help alpha").split(" "));
|
|
163
|
+
const SHELLS = /^(?:\/(?:usr\/)?bin\/)?(?:sh|bash|zsh|ash|dash|fish|ksh)$/;
|
|
164
|
+
/** `-o` that prints a Secret's values. */
|
|
165
|
+
const VALUE_OUTPUT = /^(?:yaml|json|kyaml|jsonpath|go-template|template|custom-columns)/;
|
|
166
|
+
function secretRead(parsed, where_) {
|
|
167
|
+
const output = flag(parsed.flags, "-o", "--output") ?? (flag(parsed.flags, "--template") ? "go-template" : "");
|
|
168
|
+
if (!VALUE_OUTPUT.test(output))
|
|
169
|
+
return [];
|
|
170
|
+
const named = namedObjects(parsed.words.slice(1));
|
|
171
|
+
const secrets = named?.find((entry) => entry.kind.kind === "secret");
|
|
172
|
+
if (!secrets)
|
|
173
|
+
return [];
|
|
174
|
+
const { names } = secrets;
|
|
175
|
+
if (names.length === 1 && !where_.allNamespaces) {
|
|
176
|
+
const own = objectNode(where_.place, secrets.kind, names[0]);
|
|
177
|
+
return [found("secret.read", `Read secret values of ${own.label}${where(where_.place, false)}`, own)];
|
|
178
|
+
}
|
|
179
|
+
const at = where_.allNamespaces ? placeNode({ context: where_.place.context }) : placeNode(where_.place);
|
|
180
|
+
const what = names.length > 1 ? `values of ${names.length} secrets` : "all secret values";
|
|
181
|
+
return [found("secret.read", `Read ${what}${where(where_.place, where_.allNamespaces)}`, at)];
|
|
182
|
+
}
|
|
183
|
+
function unclassified(argv, where_, program) {
|
|
184
|
+
const at = where_.place.context ? placeNode({ context: where_.place.context }) : placeNode({ context: null });
|
|
185
|
+
const unnamed = unnamedCli(argv);
|
|
186
|
+
return [found("unclassified", `Run a ${program} command Passport can't name`, at, unnamed ? { unnamed } : {})];
|
|
187
|
+
}
|
|
188
|
+
const other = (cmd) => unclassified(cmd.argv, cmd.where_, "kubectl");
|
|
189
|
+
const withoutPairs = (entry) => ({ ...entry, names: entry.names.filter((name) => !name.includes("=")) });
|
|
190
|
+
const fromFiles = (cmd, ...flags) => all(cmd.parsed.flags, ...flags).length > 0;
|
|
191
|
+
function applyCommand(cmd) {
|
|
192
|
+
const { parsed, where_, resolver, sub, args } = cmd;
|
|
193
|
+
if (sub === "view-last-applied")
|
|
194
|
+
return [];
|
|
195
|
+
if (sub === "set-last-applied" || sub === "edit-last-applied") {
|
|
196
|
+
const named = namedObjects(args.slice(1));
|
|
197
|
+
return named?.[0]
|
|
198
|
+
? [onNames("object.change", "Change the last applied state of", named[0], where_)]
|
|
199
|
+
: fromManifests("Change the last applied state of", parsed, where_, resolver, () => "object.change");
|
|
200
|
+
}
|
|
201
|
+
const applied = fromManifests("Apply", parsed, where_, resolver, changeOf);
|
|
202
|
+
if (!on(parsed.flags, "--prune"))
|
|
203
|
+
return applied;
|
|
204
|
+
const at = placeNode(where_.allNamespaces ? { context: where_.place.context } : where_.place);
|
|
205
|
+
const pruned = `Delete what the manifest no longer lists${where(where_.place, where_.allNamespaces)}`;
|
|
206
|
+
return [...applied, found("prune", pruned, at)];
|
|
207
|
+
}
|
|
208
|
+
function deleteCommand(cmd) {
|
|
209
|
+
const { parsed, where_, resolver, args } = cmd;
|
|
210
|
+
if (fromFiles(cmd, "-f", "--filename", "-k", "--kustomize")) {
|
|
211
|
+
return fromManifests("Delete", parsed, where_, resolver, deleteOf);
|
|
212
|
+
}
|
|
213
|
+
const named = namedObjects(args);
|
|
214
|
+
if (!named?.length)
|
|
215
|
+
return other(cmd);
|
|
216
|
+
const selector = flag(parsed.flags, "-l", "--selector", "--field-selector") !== undefined;
|
|
217
|
+
return named.map((entry) => {
|
|
218
|
+
const none = selector ? `${plural(entry.kind.kind)} matching a selector` : undefined;
|
|
219
|
+
const controlled = entry.kind.category === "pod" && entry.names.length > 0 && entry.names.every((name) => CONTROLLED_POD.test(name));
|
|
220
|
+
return onNames(deleteKey(entry.kind.category), "Delete", entry, where_, {
|
|
221
|
+
...(none ? { none } : {}),
|
|
222
|
+
...(controlled ? { aside: KUBE_ASIDE.recreated } : {})
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const EDIT_WORDS = {
|
|
227
|
+
edit: "Edit",
|
|
228
|
+
patch: "Patch",
|
|
229
|
+
label: "Label",
|
|
230
|
+
annotate: "Annotate"
|
|
231
|
+
};
|
|
232
|
+
/** `edit`, `patch`, `label`, `annotate`: by what the object is; a patch that makes a Service public exposes it, and a
|
|
233
|
+
* Pod Security label on a namespace changes access. */
|
|
234
|
+
function editCommand(cmd) {
|
|
235
|
+
const { parsed, where_, resolver, verb, args } = cmd;
|
|
236
|
+
const named = namedObjects(args);
|
|
237
|
+
const words = EDIT_WORDS[verb];
|
|
238
|
+
if (!named?.length) {
|
|
239
|
+
return fromFiles(cmd, "-f", "--filename") ? fromManifests(words, parsed, where_, resolver, changeOf) : other(cmd);
|
|
240
|
+
}
|
|
241
|
+
const exposes = verb === "patch" && /LoadBalancer|NodePort/.test(all(parsed.flags, "-p", "--patch").join(" "));
|
|
242
|
+
const labels = verb === "label" || verb === "annotate";
|
|
243
|
+
const podSecurity = labels && args.some((arg) => arg.startsWith("pod-security.kubernetes.io/"));
|
|
244
|
+
return named.map((entry) => {
|
|
245
|
+
const key = podSecurity
|
|
246
|
+
? "access.change"
|
|
247
|
+
: labels
|
|
248
|
+
? "object.change"
|
|
249
|
+
: changeKey(entry.kind.category, exposes && entry.kind.kind === "service");
|
|
250
|
+
return onNames(key, words, withoutPairs(entry), where_);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
const SET_WORDS = {
|
|
254
|
+
image: ["workload.change", "Set the image of"],
|
|
255
|
+
env: ["workload.change", "Set the environment of"],
|
|
256
|
+
resources: ["workload.change", "Set the resources of"],
|
|
257
|
+
selector: ["object.change", "Set the selector of"],
|
|
258
|
+
serviceaccount: ["access.change", "Set the service account of"],
|
|
259
|
+
subject: ["access.change", "Set the subjects of"]
|
|
260
|
+
};
|
|
261
|
+
function setCommand(cmd) {
|
|
262
|
+
const named = namedObjects(cmd.args.slice(1));
|
|
263
|
+
const chosen = cmd.sub ? SET_WORDS[cmd.sub] : undefined;
|
|
264
|
+
if (!named?.length || !chosen)
|
|
265
|
+
return other(cmd);
|
|
266
|
+
return named.map((entry) => onNames(chosen[0], chosen[1], withoutPairs(entry), cmd.where_));
|
|
267
|
+
}
|
|
268
|
+
function scaleCommand(cmd) {
|
|
269
|
+
const named = namedObjects(cmd.args);
|
|
270
|
+
if (!named?.length)
|
|
271
|
+
return other(cmd);
|
|
272
|
+
const replicas = flag(cmd.parsed.flags, "--replicas");
|
|
273
|
+
const tail = replicas === "0" ? " to zero" : replicas && /^\d+$/.test(replicas) ? ` to ${replicas} replicas` : "";
|
|
274
|
+
return named.map((entry) => onNames("scale", "Scale", entry, cmd.where_, { tail }));
|
|
275
|
+
}
|
|
276
|
+
function autoscaleCommand(cmd) {
|
|
277
|
+
const named = namedObjects(cmd.args);
|
|
278
|
+
return named?.length ? named.map((entry) => onNames("object.change", "Autoscale", entry, cmd.where_)) : other(cmd);
|
|
279
|
+
}
|
|
280
|
+
const ROLLOUT_WORDS = {
|
|
281
|
+
restart: ["rollout.restart", "Restart"],
|
|
282
|
+
undo: ["rollout.undo", "Roll back"],
|
|
283
|
+
pause: ["workload.change", "Pause the rollout of"],
|
|
284
|
+
resume: ["workload.change", "Resume the rollout of"]
|
|
285
|
+
};
|
|
286
|
+
function rolloutCommand(cmd) {
|
|
287
|
+
if (cmd.sub === "status" || cmd.sub === "history")
|
|
288
|
+
return [];
|
|
289
|
+
const named = namedObjects(cmd.args.slice(1));
|
|
290
|
+
const chosen = cmd.sub ? ROLLOUT_WORDS[cmd.sub] : undefined;
|
|
291
|
+
if (!chosen || !named)
|
|
292
|
+
return other(cmd);
|
|
293
|
+
const list = named.length ? named : [{ kind: kubeKind("deployment"), names: [] }];
|
|
294
|
+
return list.map((entry) => onNames(chosen[0], chosen[1], entry, cmd.where_));
|
|
295
|
+
}
|
|
296
|
+
const NODE_WORDS = {
|
|
297
|
+
drain: "Drain",
|
|
298
|
+
cordon: "Cordon",
|
|
299
|
+
uncordon: "Uncordon",
|
|
300
|
+
taint: "Taint"
|
|
301
|
+
};
|
|
302
|
+
/** `drain`, `cordon`, `uncordon`, `taint`: on the node they name (`taint` takes one, then its taints). */
|
|
303
|
+
function nodeCommand(cmd) {
|
|
304
|
+
const { verb, args } = cmd;
|
|
305
|
+
const words = verb === "taint" ? args.slice(args[0]?.startsWith("node") ? 1 : 0, args[0]?.startsWith("node") ? 2 : 1) : args;
|
|
306
|
+
const names = words
|
|
307
|
+
.filter((name) => OBJECT_NAME.test(name) && !name.includes("=") && !name.includes(":"))
|
|
308
|
+
.map((name) => name.replace(/^nodes?\//, ""));
|
|
309
|
+
const node = { kind: kubeKind("node"), names };
|
|
310
|
+
return [onNames("node.drain", NODE_WORDS[verb], node, cmd.where_, { none: "nodes matching a selector" })];
|
|
311
|
+
}
|
|
312
|
+
/** `exec`, `attach`, `debug`: code runs in the pod (or a workload's pod, or on a node); `exec` with no command or a
|
|
313
|
+
* shell, and `attach`, open a shell. */
|
|
314
|
+
function execCommand(cmd) {
|
|
315
|
+
const { verb, args, where_, parsed } = cmd;
|
|
316
|
+
const target = args.find((arg) => OBJECT_NAME.test(arg) || arg.includes("/"));
|
|
317
|
+
const slash = target?.indexOf("/") ?? -1;
|
|
318
|
+
const kind = slash > 0 ? kubeKind(target.slice(0, slash)) : kubeKind("pod");
|
|
319
|
+
if (!target || !kind)
|
|
320
|
+
return other(cmd);
|
|
321
|
+
const own = objectNode(where_.place, kind, slash > 0 ? target.slice(slash + 1) : target);
|
|
322
|
+
const shell = verb === "attach" || (verb === "exec" && (!parsed.afterDash.length || SHELLS.test(parsed.afterDash[0])));
|
|
323
|
+
const words = verb === "debug" ? "Debug" : shell ? "Open a shell on" : "Run a command on";
|
|
324
|
+
return [found("pod.exec", `${words} ${own.label}${where(where_.place, false, kind.clusterScoped)}`, own)];
|
|
325
|
+
}
|
|
326
|
+
function runCommand(cmd) {
|
|
327
|
+
const name = cmd.args[0];
|
|
328
|
+
if (!name || !OBJECT_NAME.test(name))
|
|
329
|
+
return other(cmd);
|
|
330
|
+
const own = objectNode(cmd.where_.place, kubeKind("pod"), name);
|
|
331
|
+
return [found("pod.exec", `Start ${own.label} from an image${where(cmd.where_.place, false)}`, own)];
|
|
332
|
+
}
|
|
333
|
+
/** `cp` into a pod runs there (`[namespace/]pod:path`); out of a pod only reads. */
|
|
334
|
+
function cpCommand(cmd) {
|
|
335
|
+
const destination = cmd.args[1] ?? "";
|
|
336
|
+
const remote = /^(?:([a-z0-9-]+)\/)?([A-Za-z0-9][A-Za-z0-9._-]*):/.exec(destination);
|
|
337
|
+
if (!remote || /^[A-Za-z]:[\\/]/.test(destination))
|
|
338
|
+
return [];
|
|
339
|
+
const place = goodNamespace(remote[1]) ? { ...cmd.where_.place, namespace: remote[1] } : cmd.where_.place;
|
|
340
|
+
const own = objectNode(place, kubeKind("pod"), remote[2]);
|
|
341
|
+
return [found("pod.exec", `Copy files to ${own.label}${where(place, false)}`, own)];
|
|
342
|
+
}
|
|
343
|
+
function exposeCommand(cmd) {
|
|
344
|
+
const named = namedObjects(cmd.args);
|
|
345
|
+
if (!named?.length)
|
|
346
|
+
return other(cmd);
|
|
347
|
+
const exposed = /^(?:LoadBalancer|NodePort)$/i.test(flag(cmd.parsed.flags, "--type") ?? "");
|
|
348
|
+
return named.map((entry) => onNames(exposed ? "network.expose" : "object.change", "Expose", entry, cmd.where_, {
|
|
349
|
+
tail: exposed ? " publicly" : " inside the cluster"
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
function certificateCommand(cmd) {
|
|
353
|
+
if (cmd.sub !== "approve" && cmd.sub !== "deny")
|
|
354
|
+
return other(cmd);
|
|
355
|
+
const names = cmd.args.slice(1).filter((name) => OBJECT_NAME.test(name));
|
|
356
|
+
const csr = { kind: kubeKind("csr"), names };
|
|
357
|
+
const words = cmd.sub === "approve" ? "Approve" : "Deny";
|
|
358
|
+
return [onNames("access.change", words, csr, cmd.where_, { none: "certificate requests" })];
|
|
359
|
+
}
|
|
360
|
+
function authCommand(cmd) {
|
|
361
|
+
if (cmd.sub === "reconcile")
|
|
362
|
+
return fromManifests("Reconcile", cmd.parsed, cmd.where_, cmd.resolver, () => "access.change");
|
|
363
|
+
return cmd.sub === "can-i" || cmd.sub === "whoami" ? [] : other(cmd);
|
|
364
|
+
}
|
|
365
|
+
const KUBECTL = {
|
|
366
|
+
apply: applyCommand,
|
|
367
|
+
replace: (cmd) => fromManifests("Replace", cmd.parsed, cmd.where_, cmd.resolver, changeOf, on(cmd.parsed.flags, "--force") ? KUBE_ASIDE.recreates : undefined),
|
|
368
|
+
create: createCommand,
|
|
369
|
+
delete: deleteCommand,
|
|
370
|
+
edit: editCommand,
|
|
371
|
+
patch: editCommand,
|
|
372
|
+
label: editCommand,
|
|
373
|
+
annotate: editCommand,
|
|
374
|
+
set: setCommand,
|
|
375
|
+
scale: scaleCommand,
|
|
376
|
+
autoscale: autoscaleCommand,
|
|
377
|
+
rollout: rolloutCommand,
|
|
378
|
+
drain: nodeCommand,
|
|
379
|
+
cordon: nodeCommand,
|
|
380
|
+
uncordon: nodeCommand,
|
|
381
|
+
taint: nodeCommand,
|
|
382
|
+
exec: execCommand,
|
|
383
|
+
attach: execCommand,
|
|
384
|
+
debug: execCommand,
|
|
385
|
+
run: runCommand,
|
|
386
|
+
cp: cpCommand,
|
|
387
|
+
expose: exposeCommand,
|
|
388
|
+
certificate: certificateCommand
|
|
389
|
+
};
|
|
390
|
+
/** One `kubectl` command's actions; empty for a read. */
|
|
391
|
+
function classifyKubectl(argv, resolver) {
|
|
392
|
+
const parsed = parse(argv.slice(1), KUBECTL_VALUES);
|
|
393
|
+
const [verb, sub] = parsed.words;
|
|
394
|
+
if (!verb || on(parsed.flags, "-h", "--help"))
|
|
395
|
+
return [];
|
|
396
|
+
const where_ = placeOf(parsed.flags, resolver, false);
|
|
397
|
+
const cmd = { argv, parsed, where_, resolver, verb, sub, args: parsed.words.slice(1) };
|
|
398
|
+
if (verb === "get")
|
|
399
|
+
return secretRead(parsed, where_);
|
|
400
|
+
if (verb === "auth")
|
|
401
|
+
return authCommand(cmd);
|
|
402
|
+
if (KUBECTL_READS.has(verb) || dryRun(parsed.flags))
|
|
403
|
+
return [];
|
|
404
|
+
const handler = Object.hasOwn(KUBECTL, verb) ? KUBECTL[verb] : other;
|
|
405
|
+
return handler(cmd);
|
|
406
|
+
}
|
|
407
|
+
/** The resource kind each `kubectl create` generator makes, and the action it is. */
|
|
408
|
+
const CREATE_KINDS = {
|
|
409
|
+
deployment: ["workload.change", "deployment"],
|
|
410
|
+
deploy: ["workload.change", "deployment"],
|
|
411
|
+
job: ["workload.change", "job"],
|
|
412
|
+
cronjob: ["workload.change", "cronjob"],
|
|
413
|
+
cj: ["workload.change", "cronjob"],
|
|
414
|
+
secret: ["access.change", "secret"],
|
|
415
|
+
configmap: ["object.change", "configmap"],
|
|
416
|
+
cm: ["object.change", "configmap"],
|
|
417
|
+
ingress: ["network.expose", "ingress"],
|
|
418
|
+
ing: ["network.expose", "ingress"],
|
|
419
|
+
role: ["access.change", "role"],
|
|
420
|
+
clusterrole: ["access.change", "clusterrole"],
|
|
421
|
+
rolebinding: ["access.change", "rolebinding"],
|
|
422
|
+
clusterrolebinding: ["access.change", "clusterrolebinding"],
|
|
423
|
+
serviceaccount: ["access.change", "serviceaccount"],
|
|
424
|
+
sa: ["access.change", "serviceaccount"],
|
|
425
|
+
quota: ["object.change", "resourcequota"],
|
|
426
|
+
resourcequota: ["object.change", "resourcequota"],
|
|
427
|
+
priorityclass: ["object.change", "priorityclass"],
|
|
428
|
+
pc: ["object.change", "priorityclass"],
|
|
429
|
+
poddisruptionbudget: ["object.change", "poddisruptionbudget"],
|
|
430
|
+
pdb: ["object.change", "poddisruptionbudget"]
|
|
431
|
+
};
|
|
432
|
+
function createToken(cmd, account) {
|
|
433
|
+
const { place } = cmd.where_;
|
|
434
|
+
if (!account || !OBJECT_NAME.test(account)) {
|
|
435
|
+
return [found("access.change", `Create a token${where(place, false)}`, placeNode(place))];
|
|
436
|
+
}
|
|
437
|
+
const own = objectNode(place, kubeKind("serviceaccount"), account);
|
|
438
|
+
return [found("access.change", `Create a token for ${own.label}${where(place, false)}`, own)];
|
|
439
|
+
}
|
|
440
|
+
function createNamespace(cmd, name) {
|
|
441
|
+
const { context } = cmd.where_.place;
|
|
442
|
+
if (!name || !NAMESPACE.test(name))
|
|
443
|
+
return [found("object.change", "Create a namespace", placeNode({ context }))];
|
|
444
|
+
return [found("object.change", `Create namespace ${name}`, namespaceNode(context, name))];
|
|
445
|
+
}
|
|
446
|
+
/** `kubectl create …`: from a manifest, or one of its generators. */
|
|
447
|
+
function createCommand(cmd) {
|
|
448
|
+
const { parsed, where_, resolver, sub } = cmd;
|
|
449
|
+
if (!sub || fromFiles(cmd, "-f", "--filename", "-k", "--kustomize")) {
|
|
450
|
+
return fromManifests("Create", parsed, where_, resolver, changeOf);
|
|
451
|
+
}
|
|
452
|
+
const [, , third, fourth] = parsed.words;
|
|
453
|
+
if (sub === "token")
|
|
454
|
+
return createToken(cmd, third);
|
|
455
|
+
if (sub === "namespace" || sub === "ns")
|
|
456
|
+
return createNamespace(cmd, third);
|
|
457
|
+
// `create secret generic NAME`, `create service loadbalancer NAME`: the name comes after the second word.
|
|
458
|
+
const service = sub === "service" || sub === "svc";
|
|
459
|
+
const name = sub === "secret" || service ? fourth : third;
|
|
460
|
+
const exposed = service && (third === "loadbalancer" || third === "nodeport");
|
|
461
|
+
const chosen = service ? [exposed ? "network.expose" : "object.change", "service"] : CREATE_KINDS[sub];
|
|
462
|
+
if (!chosen)
|
|
463
|
+
return other(cmd);
|
|
464
|
+
const named = { kind: kubeKind(chosen[1]), names: name && OBJECT_NAME.test(name) ? [name] : [] };
|
|
465
|
+
return [
|
|
466
|
+
onNames(chosen[0], "Create", named, where_, { none: `a ${chosen[1]}`, ...(exposed ? { tail: " publicly" } : {}) })
|
|
467
|
+
];
|
|
468
|
+
}
|
|
469
|
+
/* ------------------------------------------------------------------ */
|
|
470
|
+
/* helm */
|
|
471
|
+
/* ------------------------------------------------------------------ */
|
|
472
|
+
const HELM_READS = new Set(("list ls status get history hist show inspect search repo template lint package pull fetch dependency dep " +
|
|
473
|
+
"dependencies env version verify plugin registry completion create help push").split(" "));
|
|
474
|
+
function classifyHelm(argv, resolver) {
|
|
475
|
+
const parsed = parse(argv.slice(1), HELM_VALUES);
|
|
476
|
+
const [verb, ...rest] = parsed.words;
|
|
477
|
+
if (!verb || on(parsed.flags, "-h", "--help"))
|
|
478
|
+
return [];
|
|
479
|
+
const where_ = placeOf(parsed.flags, resolver, true);
|
|
480
|
+
if (HELM_READS.has(verb) || dryRun(parsed.flags))
|
|
481
|
+
return [];
|
|
482
|
+
const release = (name) => (name && OBJECT_NAME.test(name) ? name : undefined);
|
|
483
|
+
const place = where(where_.place, false);
|
|
484
|
+
const on_ = (key, words, name) => {
|
|
485
|
+
if (!name)
|
|
486
|
+
return found(key, `${words} a release${place}`, placeNode(where_.place));
|
|
487
|
+
return found(key, `${words} release ${name}${place}`, releaseNode(where_.place, name));
|
|
488
|
+
};
|
|
489
|
+
switch (verb) {
|
|
490
|
+
case "install": {
|
|
491
|
+
// `install NAME CHART`, or `install CHART --generate-name`.
|
|
492
|
+
const generated = on(parsed.flags, "-g", "--generate-name");
|
|
493
|
+
return [on_("helm.install", "Install", generated ? undefined : release(rest[0]))];
|
|
494
|
+
}
|
|
495
|
+
case "upgrade":
|
|
496
|
+
return [on_("helm.install", "Upgrade", release(rest[0]))];
|
|
497
|
+
case "rollback":
|
|
498
|
+
return [on_("helm.rollback", "Roll back", release(rest[0]))];
|
|
499
|
+
case "uninstall":
|
|
500
|
+
case "delete":
|
|
501
|
+
case "del":
|
|
502
|
+
case "un": {
|
|
503
|
+
const names = rest.filter((name) => release(name));
|
|
504
|
+
if (names.length <= 1)
|
|
505
|
+
return [on_("helm.uninstall", "Uninstall", names[0])];
|
|
506
|
+
return [
|
|
507
|
+
found("helm.uninstall", `Uninstall ${names.length} ${names.length === 1 ? "release" : "releases"}${place}`, placeNode(where_.place))
|
|
508
|
+
];
|
|
509
|
+
}
|
|
510
|
+
case "test":
|
|
511
|
+
return [on_("pod.exec", "Run the tests of", release(rest[0]))];
|
|
512
|
+
default:
|
|
513
|
+
return unclassified(argv, where_, "helm");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/* ------------------------------------------------------------------ */
|
|
517
|
+
/* Entry */
|
|
518
|
+
/* ------------------------------------------------------------------ */
|
|
519
|
+
export const KUBE_PROGRAMS = new Set(["kubectl", "helm"]);
|
|
520
|
+
/** Whether a command's program is one this classifier reads. */
|
|
521
|
+
export const isKubeProgram = (argv0) => KUBE_PROGRAMS.has(programOf(argv0 ?? ""));
|
|
522
|
+
/** One `kubectl` or `helm` command's actions, in the order it does them; empty for a read or another program. */
|
|
523
|
+
export function classifyKube(argv, resolver) {
|
|
524
|
+
const program = programOf(argv[0] ?? "");
|
|
525
|
+
if (program === "kubectl")
|
|
526
|
+
return classifyKubectl(argv, resolver);
|
|
527
|
+
if (program === "helm")
|
|
528
|
+
return classifyHelm(argv, resolver);
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Effect } from "../../controlPlaneActions.generated.js";
|
|
2
|
+
export declare const KUBERNETES_EFFECTS: Readonly<Record<string, readonly Effect[]>>;
|
|
3
|
+
/** An action's default effects: the review, else the derivation from its label. */
|
|
4
|
+
export declare function kubernetesEffectsOf(key: string, label: string): readonly Effect[];
|
|
5
|
+
/** The asides the classifier writes after a summary, which the Activity row drops. */
|
|
6
|
+
export declare const KUBE_ASIDE: {
|
|
7
|
+
/** A pod a ReplicaSet, StatefulSet, DaemonSet or Job owns, by its generated name. */
|
|
8
|
+
readonly recreated: "(recreated by its controller)";
|
|
9
|
+
/** `replace --force` deletes the object, then creates it. */
|
|
10
|
+
readonly recreates: "(deletes and recreates it)";
|
|
11
|
+
};
|
|
12
|
+
/** The summary of an apply, create or replace whose manifest Passport couldn't read. */
|
|
13
|
+
export declare const UNREAD_MANIFEST = "manifests Passport couldn't read";
|
|
14
|
+
/** One Kubernetes call's own effects from its summary; undefined keeps the action's defaults. */
|
|
15
|
+
export declare function kubernetesCallEffects(keys: readonly string[], summary: string): Effect[] | undefined;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
|
|
2
|
+
import { UNRECOGNIZED_EFFECTS } from "../../controlPlaneActions.generated.js";
|
|
3
|
+
import { deriveEffects, MAY_OUTAGE, OUTAGE, PUBLIC_DATA, RUN } from "../callEffects.generated.js";
|
|
4
|
+
/**
|
|
5
|
+
* Kubernetes's effects (docs/design/control-plane.md, "Action model"): each catalog action's defaults, and what one
|
|
6
|
+
* call does from the summary the classifier wrote (`kubernetesCli.ts`), which the server reads for the guard's
|
|
7
|
+
* decisions: its size ("Delete 3 pods"), a scale to zero (an outage), a pod its controller recreates (restorable), a
|
|
8
|
+
* manifest Passport couldn't read (what it may do), a replace that deletes first, and a shell (it reads the pod's
|
|
9
|
+
* mounted secrets). No bridge release is needed for a new entry here.
|
|
10
|
+
*/
|
|
11
|
+
const change = (object) => ({ verb: "change", object });
|
|
12
|
+
const del = (object) => ({ verb: "delete", object });
|
|
13
|
+
/** A workload's pods roll: its new spec runs. */
|
|
14
|
+
const ROLLS = [change("service"), RUN];
|
|
15
|
+
export const KUBERNETES_EFFECTS = {
|
|
16
|
+
"kubernetes.workload.change": ROLLS,
|
|
17
|
+
"kubernetes.rollout.restart": [RUN, MAY_OUTAGE],
|
|
18
|
+
"kubernetes.rollout.undo": ROLLS,
|
|
19
|
+
"kubernetes.scale": [change("service")],
|
|
20
|
+
"kubernetes.pod.exec": [RUN],
|
|
21
|
+
// A pod no controller recreates is gone for good; one a controller owns comes back (the summary says which).
|
|
22
|
+
"kubernetes.pod.delete": [del("service")],
|
|
23
|
+
"kubernetes.access.change": [change("access")],
|
|
24
|
+
"kubernetes.network.expose": [change("service"), PUBLIC_DATA],
|
|
25
|
+
"kubernetes.secret.read": [{ verb: "read", object: "access" }],
|
|
26
|
+
"kubernetes.node.drain": [change("service"), MAY_OUTAGE],
|
|
27
|
+
"kubernetes.storage.delete": [del("data")],
|
|
28
|
+
"kubernetes.namespace.delete": [del("service"), del("data")],
|
|
29
|
+
"kubernetes.object.delete": [del("service")],
|
|
30
|
+
"kubernetes.prune": [del("service")],
|
|
31
|
+
"kubernetes.helm.install": ROLLS,
|
|
32
|
+
"kubernetes.helm.rollback": ROLLS,
|
|
33
|
+
"kubernetes.helm.uninstall": [del("service")],
|
|
34
|
+
"kubernetes.object.change": [change("service")],
|
|
35
|
+
"kubernetes.unclassified": UNRECOGNIZED_EFFECTS
|
|
36
|
+
};
|
|
37
|
+
/** An action's default effects: the review, else the derivation from its label. */
|
|
38
|
+
export function kubernetesEffectsOf(key, label) {
|
|
39
|
+
return KUBERNETES_EFFECTS[key] ?? deriveEffects(label);
|
|
40
|
+
}
|
|
41
|
+
/** The asides the classifier writes after a summary, which the Activity row drops. */
|
|
42
|
+
export const KUBE_ASIDE = {
|
|
43
|
+
/** A pod a ReplicaSet, StatefulSet, DaemonSet or Job owns, by its generated name. */
|
|
44
|
+
recreated: "(recreated by its controller)",
|
|
45
|
+
/** `replace --force` deletes the object, then creates it. */
|
|
46
|
+
recreates: "(deletes and recreates it)"
|
|
47
|
+
};
|
|
48
|
+
/** The summary of an apply, create or replace whose manifest Passport couldn't read. */
|
|
49
|
+
export const UNREAD_MANIFEST = "manifests Passport couldn't read";
|
|
50
|
+
/** "Delete 3 pods", "Read values of 4 secrets", "Apply 12 resources": the call's size. */
|
|
51
|
+
const COUNT = /^[A-Z][a-z]+(?: values of)? (\d{1,6}) /;
|
|
52
|
+
/** Every pod a selector or `--all` names: whether a controller owns each isn't known. */
|
|
53
|
+
const SOME_PODS = /^Delete (?:all pods|pods matching a selector)\b/;
|
|
54
|
+
/** A manifest Passport couldn't read may run code, change access, or make something public. */
|
|
55
|
+
const UNREAD = [
|
|
56
|
+
change("service"),
|
|
57
|
+
{ ...RUN, possible: true },
|
|
58
|
+
{ ...change("access"), possible: true },
|
|
59
|
+
{ ...PUBLIC_DATA, possible: true }
|
|
60
|
+
];
|
|
61
|
+
/** One Kubernetes call's own effects from its summary; undefined keeps the action's defaults. */
|
|
62
|
+
export function kubernetesCallEffects(keys, summary) {
|
|
63
|
+
const key = keys.find((entry) => entry in KUBERNETES_EFFECTS);
|
|
64
|
+
if (!key || key === "kubernetes.unclassified")
|
|
65
|
+
return undefined;
|
|
66
|
+
const text = summary.trim();
|
|
67
|
+
let effects = KUBERNETES_EFFECTS[key].map((effect) => ({ ...effect }));
|
|
68
|
+
let changed = false;
|
|
69
|
+
if (text.includes(UNREAD_MANIFEST)) {
|
|
70
|
+
effects = UNREAD.map((effect) => ({ ...effect }));
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
if (key === "kubernetes.pod.delete" && text.endsWith(KUBE_ASIDE.recreated)) {
|
|
74
|
+
effects = [{ ...del("service"), restorable: true }];
|
|
75
|
+
changed = true;
|
|
76
|
+
}
|
|
77
|
+
else if (key === "kubernetes.pod.delete" && SOME_PODS.test(text)) {
|
|
78
|
+
effects = [
|
|
79
|
+
{ ...del("service"), restorable: true },
|
|
80
|
+
{ ...del("service"), possible: true }
|
|
81
|
+
];
|
|
82
|
+
changed = true;
|
|
83
|
+
}
|
|
84
|
+
if (key === "kubernetes.scale" && / to zero\b/.test(text)) {
|
|
85
|
+
effects = [change("service"), OUTAGE];
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
if (text.endsWith(KUBE_ASIDE.recreates)) {
|
|
89
|
+
effects = [...effects, MAY_OUTAGE];
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
if (key === "kubernetes.pod.exec" && /^Open a shell\b/.test(text)) {
|
|
93
|
+
effects = [RUN, { verb: "read", object: "access" }];
|
|
94
|
+
changed = true;
|
|
95
|
+
}
|
|
96
|
+
if (key === "kubernetes.access.change" && /^Create a token\b/.test(text)) {
|
|
97
|
+
effects = [{ verb: "create", object: "access" }];
|
|
98
|
+
changed = true;
|
|
99
|
+
}
|
|
100
|
+
if (key === "kubernetes.node.drain" && /^Uncordon\b/.test(text)) {
|
|
101
|
+
effects = [change("service")];
|
|
102
|
+
changed = true;
|
|
103
|
+
}
|
|
104
|
+
const count = COUNT.exec(text);
|
|
105
|
+
const n = count ? Number(count[1]) : 0;
|
|
106
|
+
if (n > 1) {
|
|
107
|
+
effects = effects.map((effect, index) => (index === 0 ? { ...effect, count: { n, unit: "items" } } : effect));
|
|
108
|
+
changed = true;
|
|
109
|
+
}
|
|
110
|
+
return changed ? effects : undefined;
|
|
111
|
+
}
|