passport-bridge 0.48.2 → 0.50.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 (129) hide show
  1. package/dist/cliHook.js +13 -0
  2. package/dist/cliHookAfter.js +10 -1
  3. package/dist/cliHookDecide.d.ts +9 -3
  4. package/dist/cliHookDecide.js +185 -28
  5. package/dist/cliHookDeliver.d.ts +2 -2
  6. package/dist/cliHookDeliver.js +8 -4
  7. package/dist/cliHookSessionState.d.ts +4 -1
  8. package/dist/cliHookSessionState.js +1 -1
  9. package/dist/connectorKit/callEffects.generated.d.ts +36 -0
  10. package/dist/connectorKit/callEffects.generated.js +73 -0
  11. package/dist/connectorKit/cli.generated.js +5 -2
  12. package/dist/connectorKit/engine.generated.d.ts +1 -1
  13. package/dist/connectorKit/engine.generated.js +32 -13
  14. package/dist/connectorKit/githubIds.generated.d.ts +1 -1
  15. package/dist/connectorKit/githubIds.generated.js +3 -2
  16. package/dist/connectorKit/manifest.generated.d.ts +34 -14
  17. package/dist/connectorKit/manifests/cloudflare.generated.d.ts +2 -0
  18. package/dist/connectorKit/manifests/cloudflare.generated.js +186 -0
  19. package/dist/connectorKit/manifests/cloudflareApi.generated.d.ts +4 -0
  20. package/dist/connectorKit/manifests/cloudflareApi.generated.js +207 -0
  21. package/dist/connectorKit/manifests/cloudflareCatalog.generated.d.ts +18 -0
  22. package/dist/connectorKit/manifests/cloudflareCatalog.generated.js +83 -0
  23. package/dist/connectorKit/manifests/cloudflareCli.generated.d.ts +2 -0
  24. package/dist/connectorKit/manifests/cloudflareCli.generated.js +441 -0
  25. package/dist/connectorKit/manifests/githubCapture.generated.js +19 -1
  26. package/dist/connectorKit/manifests/githubReads.generated.js +0 -3
  27. package/dist/connectorKit/manifests/kubernetes.generated.d.ts +76 -0
  28. package/dist/connectorKit/manifests/kubernetes.generated.js +210 -0
  29. package/dist/connectorKit/manifests/kubernetesArgs.generated.d.ts +21 -0
  30. package/dist/connectorKit/manifests/kubernetesArgs.generated.js +82 -0
  31. package/dist/connectorKit/manifests/kubernetesCli.generated.d.ts +30 -0
  32. package/dist/connectorKit/manifests/kubernetesCli.generated.js +530 -0
  33. package/dist/connectorKit/manifests/kubernetesEffects.generated.d.ts +15 -0
  34. package/dist/connectorKit/manifests/kubernetesEffects.generated.js +111 -0
  35. package/dist/connectorKit/manifests/kubernetesObjects.generated.d.ts +24 -0
  36. package/dist/connectorKit/manifests/kubernetesObjects.generated.js +154 -0
  37. package/dist/connectorKit/manifests/railwayHooks.generated.js +11 -5
  38. package/dist/connectorKit/manifests/sentry.generated.d.ts +6 -0
  39. package/dist/connectorKit/manifests/sentry.generated.js +27 -0
  40. package/dist/connectorKit/manifests/sentryApi.generated.d.ts +6 -0
  41. package/dist/connectorKit/manifests/sentryApi.generated.js +282 -0
  42. package/dist/connectorKit/manifests/sentryCapture.generated.d.ts +2 -0
  43. package/dist/connectorKit/manifests/sentryCapture.generated.js +165 -0
  44. package/dist/connectorKit/manifests/sentryCatalog.generated.d.ts +5 -0
  45. package/dist/connectorKit/manifests/sentryCatalog.generated.js +70 -0
  46. package/dist/connectorKit/manifests/sentryCli.generated.d.ts +2 -0
  47. package/dist/connectorKit/manifests/sentryCli.generated.js +230 -0
  48. package/dist/connectorKit/manifests/sentryIssues.generated.d.ts +20 -0
  49. package/dist/connectorKit/manifests/sentryIssues.generated.js +204 -0
  50. package/dist/connectorKit/manifests/supabase.generated.js +3 -2
  51. package/dist/connectorKit/manifests/supabaseApi.generated.js +52 -52
  52. package/dist/connectorKit/manifests/supabaseCapture.generated.js +22 -21
  53. package/dist/connectorKit/manifests/supabaseCatalog.generated.d.ts +2 -2
  54. package/dist/connectorKit/manifests/supabaseCatalog.generated.js +8 -7
  55. package/dist/connectorKit/manifests/supabaseCli.generated.js +32 -32
  56. package/dist/connectorKit/manifests/supabaseProbes.generated.js +29 -29
  57. package/dist/connectorKit/manifests/terraform.generated.d.ts +5 -0
  58. package/dist/connectorKit/manifests/terraform.generated.js +214 -0
  59. package/dist/connectorKit/manifests/terraformLink.generated.d.ts +30 -0
  60. package/dist/connectorKit/manifests/terraformLink.generated.js +73 -0
  61. package/dist/connectorKit/manifests/terraformPlan.generated.d.ts +48 -0
  62. package/dist/connectorKit/manifests/terraformPlan.generated.js +192 -0
  63. package/dist/connectorKit/params.generated.js +2 -0
  64. package/dist/connectorKit/shell.generated.d.ts +5 -1
  65. package/dist/connectorKit/shell.generated.js +121 -20
  66. package/dist/connectorKit/sources/cloudflare/api-operations.generated.d.ts +37 -0
  67. package/dist/connectorKit/sources/cloudflare/api-operations.generated.js +2 -0
  68. package/dist/connectorKit/sources/cloudflare/cli-flags.generated.d.ts +617 -0
  69. package/dist/connectorKit/sources/cloudflare/cli-flags.generated.js +2 -0
  70. package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.d.ts +16 -0
  71. package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.js +2 -0
  72. package/dist/connectorKit/sources/sentry/api-operations.generated.d.ts +121 -0
  73. package/dist/connectorKit/sources/sentry/api-operations.generated.js +2 -0
  74. package/dist/connectorKit/sources/sentry/cli-commands.generated.d.ts +530 -0
  75. package/dist/connectorKit/sources/sentry/cli-commands.generated.js +2 -0
  76. package/dist/connectorKit/sources/sentry/mcp-tools.generated.d.ts +32 -0
  77. package/dist/connectorKit/sources/sentry/mcp-tools.generated.js +2 -0
  78. package/dist/connectorKit/template.generated.d.ts +8 -4
  79. package/dist/connectorKit/template.generated.js +19 -6
  80. package/dist/controlPlane.generated.d.ts +11 -2
  81. package/dist/controlPlaneActions.generated.d.ts +52 -12
  82. package/dist/controlPlaneActions.generated.js +40 -11
  83. package/dist/controlPlaneAnswer.d.ts +35 -0
  84. package/dist/controlPlaneAnswer.js +23 -0
  85. package/dist/controlPlaneCli.d.ts +1 -1
  86. package/dist/controlPlaneCloudflare.d.ts +70 -0
  87. package/dist/controlPlaneCloudflare.js +188 -0
  88. package/dist/controlPlaneGuard.d.ts +6 -31
  89. package/dist/controlPlaneGuard.js +17 -24
  90. package/dist/controlPlaneKubernetes.d.ts +72 -0
  91. package/dist/controlPlaneKubernetes.js +260 -0
  92. package/dist/controlPlaneModel.generated.d.ts +6 -0
  93. package/dist/controlPlaneNpm.generated.d.ts +83 -0
  94. package/dist/controlPlaneNpm.generated.js +307 -0
  95. package/dist/controlPlaneNpmCommands.generated.d.ts +35 -0
  96. package/dist/controlPlaneNpmCommands.generated.js +567 -0
  97. package/dist/controlPlaneNpmGuard.d.ts +44 -0
  98. package/dist/controlPlaneNpmGuard.js +210 -0
  99. package/dist/controlPlaneOffline.d.ts +1 -1
  100. package/dist/controlPlaneRailway.generated.js +2 -2
  101. package/dist/controlPlaneRailwayCli.generated.js +13 -2
  102. package/dist/controlPlaneRailwayGuard.d.ts +1 -1
  103. package/dist/controlPlaneRailwayGuard.js +1 -1
  104. package/dist/controlPlaneRailwayModel.generated.d.ts +5 -0
  105. package/dist/controlPlaneRailwayModel.generated.js +15 -1
  106. package/dist/controlPlaneSentry.d.ts +68 -0
  107. package/dist/controlPlaneSentry.js +205 -0
  108. package/dist/controlPlaneSupabase.d.ts +1 -1
  109. package/dist/controlPlaneSupabase.js +1 -1
  110. package/dist/controlPlaneTerraform.d.ts +86 -0
  111. package/dist/controlPlaneTerraform.js +273 -0
  112. package/dist/controlPlaneUnnamed.generated.d.ts +41 -2
  113. package/dist/controlPlaneUnnamed.generated.js +148 -2
  114. package/dist/cpCli.d.ts +1 -1
  115. package/dist/cpCli.js +1 -1
  116. package/dist/gitPush.d.ts +8 -3
  117. package/dist/gitPush.js +37 -12
  118. package/dist/githubMergeHold.d.ts +42 -0
  119. package/dist/githubMergeHold.js +134 -0
  120. package/dist/githubMergeIds.d.ts +18 -0
  121. package/dist/githubMergeIds.js +51 -0
  122. package/dist/pluginPin.d.ts +1 -1
  123. package/dist/pluginPin.js +1 -1
  124. package/dist/terraformPlans.d.ts +45 -0
  125. package/dist/terraformPlans.js +96 -0
  126. package/dist/version.d.ts +1 -1
  127. package/dist/version.js +1 -1
  128. package/npm-shrinkwrap.json +2 -2
  129. package/package.json +1 -1
@@ -0,0 +1,210 @@
1
+ import { PRODUCTION_NAME } from "../../controlPlaneActions.generated.js";
2
+ import { kubernetesEffectsOf } from "./kubernetesEffects.generated.js";
3
+ /**
4
+ * Kubernetes (`kubectl` and `helm`), decided only through the CLI guard: Passport reads no cluster, so there is
5
+ * nothing to connect, and the guard decides every consequential command it sees. The tree is cluster › namespace ›
6
+ * kind/name, named from the kubeconfig context on the computer (its name only, never a credential) and the command's
7
+ * own words. Nodes are created the first time a decision lands on them.
8
+ *
9
+ * Production (docs/design/control-plane.md, "Production"): a context or kubeconfig cluster named prod or production,
10
+ * or a namespace named so, is production; a cluster that runs on the computer itself (minikube, kind, Docker Desktop)
11
+ * isn't (the app's rule); anything else is unknown, which counts as production.
12
+ */
13
+ export const KUBERNETES = "kubernetes";
14
+ export const KUBERNETES_SERVICE = "kubernetes/clusters";
15
+ const def = (kind, category, names, clusterScoped) => names.split(" ").map((name) => [name, { kind, category, ...(clusterScoped ? { clusterScoped } : {}) }]);
16
+ /** kubectl's resource names, short names and kinds (lowercase), as `kubectl api-resources` lists them. */
17
+ const KINDS = new Map([
18
+ ...def("pod", "pod", "pod pods po"),
19
+ ...def("deployment", "workload", "deployment deployments deploy"),
20
+ ...def("statefulset", "workload", "statefulset statefulsets sts"),
21
+ ...def("daemonset", "workload", "daemonset daemonsets ds"),
22
+ ...def("replicaset", "workload", "replicaset replicasets rs"),
23
+ ...def("replicationcontroller", "workload", "replicationcontroller replicationcontrollers rc"),
24
+ ...def("job", "workload", "job jobs"),
25
+ ...def("cronjob", "workload", "cronjob cronjobs cj"),
26
+ ...def("service", "network", "service services svc"),
27
+ ...def("ingress", "network", "ingress ingresses ing"),
28
+ ...def("configmap", "config", "configmap configmaps cm"),
29
+ ...def("secret", "secret", "secret secrets"),
30
+ ...def("persistentvolumeclaim", "storage", "persistentvolumeclaim persistentvolumeclaims pvc"),
31
+ ...def("persistentvolume", "storage", "persistentvolume persistentvolumes pv", true),
32
+ ...def("storageclass", "storage", "storageclass storageclasses sc", true),
33
+ ...def("role", "access", "role roles"),
34
+ ...def("rolebinding", "access", "rolebinding rolebindings"),
35
+ ...def("serviceaccount", "access", "serviceaccount serviceaccounts sa"),
36
+ ...def("networkpolicy", "access", "networkpolicy networkpolicies netpol"),
37
+ ...def("clusterrole", "access", "clusterrole clusterroles", true),
38
+ ...def("clusterrolebinding", "access", "clusterrolebinding clusterrolebindings", true),
39
+ ...def("certificatesigningrequest", "access", "certificatesigningrequest certificatesigningrequests csr", true),
40
+ ...def("node", "machine", "node nodes no", true),
41
+ ...def("namespace", "namespace", "namespace namespaces ns", true),
42
+ ...def("horizontalpodautoscaler", "object", "horizontalpodautoscaler horizontalpodautoscalers hpa"),
43
+ ...def("poddisruptionbudget", "object", "poddisruptionbudget poddisruptionbudgets pdb"),
44
+ ...def("resourcequota", "object", "resourcequota resourcequotas quota"),
45
+ ...def("limitrange", "object", "limitrange limitranges limits"),
46
+ ...def("endpoints", "object", "endpoints ep"),
47
+ ...def("customresourcedefinition", "object", "customresourcedefinition customresourcedefinitions crd crds", true),
48
+ ...def("priorityclass", "object", "priorityclass priorityclasses pc", true),
49
+ ...def("mutatingwebhookconfiguration", "access", "mutatingwebhookconfiguration mutatingwebhookconfigurations", true),
50
+ ...def("validatingwebhookconfiguration", "access", "validatingwebhookconfiguration validatingwebhookconfigurations", true)
51
+ ]);
52
+ const KIND_WORD = /^[a-z][a-z0-9-]{0,62}$/;
53
+ /** A resource type as kubectl or a manifest names it ("deploy", "deployments.apps", "Deployment"); an unknown one
54
+ * (a custom resource) is an object of its own name, namespaced. Null when it isn't a type's shape. */
55
+ export function kubeKind(raw) {
56
+ const word = raw.toLowerCase().split(".")[0];
57
+ if (!KIND_WORD.test(word))
58
+ return null;
59
+ return KINDS.get(word) ?? { kind: word.replace(/s$/, ""), category: "object" };
60
+ }
61
+ /* ------------------------------------------------------------------ */
62
+ /* Catalog */
63
+ /* ------------------------------------------------------------------ */
64
+ const node = (type, label) => ({ type, label, service: "clusters", depth: "node" });
65
+ /** Node types, by category; a cluster, a namespace, and a Helm release are their own. */
66
+ export const KUBERNETES_TYPES = [
67
+ node("cluster", "Cluster"),
68
+ node("namespace", "Namespace"),
69
+ node("workload", "Workload"),
70
+ node("pod", "Pod"),
71
+ node("network", "Service or Ingress"),
72
+ node("config", "ConfigMap"),
73
+ node("secret", "Secret"),
74
+ node("storage", "Volume"),
75
+ node("access", "Role or account"),
76
+ node("machine", "Node"),
77
+ node("release", "Helm release"),
78
+ node("object", "Resource")
79
+ ];
80
+ const action = (key, kind, appliesTo, label, icon) => ({
81
+ key: `kubernetes.${key}`,
82
+ kind,
83
+ appliesTo,
84
+ label,
85
+ icon,
86
+ effects: kubernetesEffectsOf(`kubernetes.${key}`, label)
87
+ });
88
+ export const KUBERNETES_CATALOG = Object.freeze({
89
+ platform: "kubernetes",
90
+ label: "Kubernetes",
91
+ version: 1,
92
+ services: [{ key: "clusters", label: "Clusters" }],
93
+ types: [...KUBERNETES_TYPES],
94
+ actions: [
95
+ action("workload.change", "change", "workload", "Change a workload", "Rocket"),
96
+ action("rollout.restart", "change", "workload", "Restart a workload", "RotateCcw"),
97
+ action("rollout.undo", "change", "workload", "Roll back a workload", "Undo2"),
98
+ action("scale", "change", "workload", "Scale a workload", "Gauge"),
99
+ action("pod.exec", "create", "pod", "Run code in a pod", "SquareTerminal"),
100
+ action("pod.delete", "delete", "pod", "Delete pods", "Trash2"),
101
+ action("access.change", "change", "access", "Change roles, accounts or secrets", "KeyRound"),
102
+ action("network.expose", "change", "network", "Expose a service publicly", "Globe"),
103
+ // A read: allowed by default, decided only when a Block on Read is on its path.
104
+ action("secret.read", "read", "secret", "Read secret values", "Eye"),
105
+ action("node.drain", "change", "machine", "Drain, cordon or taint a node", "ServerOff"),
106
+ action("storage.delete", "delete", "storage", "Delete a volume and its data", "HardDrive"),
107
+ action("namespace.delete", "delete", "namespace", "Delete a namespace", "Trash2"),
108
+ action("object.delete", "delete", "namespace", "Delete resources", "Trash2"),
109
+ action("prune", "delete", "namespace", "Delete what a manifest no longer lists", "Eraser"),
110
+ action("helm.install", "change", "release", "Install or upgrade a release", "Package"),
111
+ action("helm.rollback", "change", "release", "Roll back a release", "Undo2"),
112
+ action("helm.uninstall", "delete", "release", "Uninstall a release", "PackageX"),
113
+ action("object.change", "change", "namespace", "Other change", "Pencil"),
114
+ action("unclassified", "unclassified", "cluster", "Unclassified action", "CircleHelp")
115
+ ]
116
+ });
117
+ /** A cluster that runs on the computer itself: never production. */
118
+ const LOCAL_CLUSTER = /^(?:minikube|docker-desktop|docker-for-desktop|rancher-desktop|orbstack|colima|microk8s)$|^(?:kind|k3d)-/i;
119
+ const SAFE_NAME = /^[^\s\u0000-\u001f\u007f]{1,253}$/;
120
+ /** A name the guard may send: one line, bounded, no control characters. */
121
+ export const safeKubeName = (name) => Boolean(name && SAFE_NAME.test(name));
122
+ /** Production by name (`PRODUCTION_NAME`), else the app's rule for local clusters, else unknown. */
123
+ export function kubeProduction(context, namespace) {
124
+ if (!context)
125
+ return undefined;
126
+ const names = [context.name, context.cluster ?? "", namespace ?? ""];
127
+ if (names.some((name) => PRODUCTION_NAME.test(name)))
128
+ return true;
129
+ if (LOCAL_CLUSTER.test(context.name) || LOCAL_CLUSTER.test(context.cluster ?? ""))
130
+ return false;
131
+ return undefined;
132
+ }
133
+ export const kubeIds = {
134
+ platform: KUBERNETES,
135
+ service: KUBERNETES_SERVICE,
136
+ cluster: (context) => `${KUBERNETES_SERVICE}/cluster:${context}`,
137
+ namespace: (context, namespace) => `${KUBERNETES_SERVICE}/namespace:${context}/${namespace}`,
138
+ object: (type, key) => `${KUBERNETES_SERVICE}/${type}:${key}`
139
+ };
140
+ const withProduction = (entry, production) => production === undefined ? entry : { ...entry, production };
141
+ /** The chain from the cluster down to the namespace (when there is one), cluster first. */
142
+ function placeChain(place) {
143
+ const context = place.context;
144
+ const cluster = withProduction({
145
+ id: kubeIds.cluster(context.name),
146
+ parentId: KUBERNETES_SERVICE,
147
+ type: "cluster",
148
+ name: context.name,
149
+ externalKey: context.name
150
+ }, kubeProduction(context));
151
+ if (!place.namespace)
152
+ return [cluster];
153
+ const namespace = withProduction({
154
+ id: kubeIds.namespace(context.name, place.namespace),
155
+ parentId: cluster.id,
156
+ type: "namespace",
157
+ name: place.namespace,
158
+ externalKey: `${context.name}/${place.namespace}`
159
+ }, kubeProduction(context, place.namespace));
160
+ return [cluster, namespace];
161
+ }
162
+ /** The node of a place: its namespace, else its cluster, else every cluster (the guard couldn't tell which). */
163
+ export function placeNode(place) {
164
+ if (!place.context)
165
+ return { nodeId: KUBERNETES_SERVICE, nodes: [] };
166
+ const nodes = placeChain(place);
167
+ return { nodeId: nodes[nodes.length - 1].id, nodes };
168
+ }
169
+ /** A namespace's own node, when the command names one as its object (`delete namespace shop`). */
170
+ export function namespaceNode(context, namespace) {
171
+ return placeNode({ context, namespace });
172
+ }
173
+ const CATEGORY_TYPE = {
174
+ workload: "workload",
175
+ pod: "pod",
176
+ network: "network",
177
+ config: "config",
178
+ secret: "secret",
179
+ storage: "storage",
180
+ access: "access",
181
+ machine: "machine",
182
+ namespace: "namespace",
183
+ object: "object"
184
+ };
185
+ /** One named resource's node (`deployment/web` in shop), with the chain above it. A namespace is its own node; a
186
+ * cluster-scoped resource hangs off the cluster. Without a context: the place's node, nothing created. */
187
+ export function objectNode(place, kind, name) {
188
+ const label = `${kind.kind}/${name}`;
189
+ if (kind.category === "namespace")
190
+ return { ...namespaceNode(place.context, name), label };
191
+ const scoped = kind.clusterScoped ? { context: place.context } : place;
192
+ if (!place.context || (!kind.clusterScoped && !place.namespace))
193
+ return { ...placeNode(scoped), label };
194
+ const above = placeChain(scoped);
195
+ const parent = above[above.length - 1];
196
+ const type = CATEGORY_TYPE[kind.category];
197
+ const externalKey = `${parent.externalKey}/${kind.kind}/${name}`;
198
+ const own = withProduction({ id: kubeIds.object(type, externalKey), parentId: parent.id, type, name: label, externalKey }, kubeProduction(place.context, kind.clusterScoped ? undefined : place.namespace));
199
+ return { nodeId: own.id, nodes: [...above, own], label };
200
+ }
201
+ /** A Helm release's node. */
202
+ export function releaseNode(place, name) {
203
+ if (!place.context || !place.namespace)
204
+ return placeNode(place);
205
+ const above = placeChain(place);
206
+ const parent = above[above.length - 1];
207
+ const externalKey = `${parent.externalKey}/${name}`;
208
+ const own = withProduction({ id: kubeIds.object("release", externalKey), parentId: parent.id, type: "release", name, externalKey }, kubeProduction(place.context, place.namespace));
209
+ return { nodeId: own.id, nodes: [...above, own] };
210
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * How `kubectl` and `helm` read their command lines, for the classifier (`kubernetesCli.ts`): which flags take a
3
+ * value (from each CLI's own help), positional words, and what follows `--`. Pure.
4
+ */
5
+ export type Flags = Map<string, string[]>;
6
+ export type Parsed = {
7
+ words: string[];
8
+ flags: Flags;
9
+ afterDash: string[];
10
+ };
11
+ /** kubectl's flags that take a value (global, then per command), from `kubectl options` and each command's help. */
12
+ export declare const KUBECTL_VALUES: Set<string>;
13
+ /** Helm's flags that take a value, from `helm --help` and each command's help. */
14
+ export declare const HELM_VALUES: Set<string>;
15
+ export declare function parse(args: readonly string[], values: ReadonlySet<string>): Parsed;
16
+ export declare const flag: (flags: Flags, ...names: string[]) => string | undefined;
17
+ export declare const all: (flags: Flags, ...names: string[]) => string[];
18
+ export declare const on: (flags: Flags, ...names: string[]) => boolean;
19
+ /** A dry run changes nothing: any value but `none` (a bare `--dry-run` is `client`). */
20
+ export declare const dryRun: (flags: Flags) => boolean;
21
+ export declare const programOf: (argv0: string) => string;
@@ -0,0 +1,82 @@
1
+ // Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
2
+ /**
3
+ * How `kubectl` and `helm` read their command lines, for the classifier (`kubernetesCli.ts`): which flags take a
4
+ * value (from each CLI's own help), positional words, and what follows `--`. Pure.
5
+ */
6
+ /* ------------------------------------------------------------------ */
7
+ /* Parsing */
8
+ /* ------------------------------------------------------------------ */
9
+ /** kubectl's flags that take a value (global, then per command), from `kubectl options` and each command's help. */
10
+ export const KUBECTL_VALUES = new Set(("-n --namespace --context --cluster --user --kubeconfig -s --server --token --as --as-group --as-uid " +
11
+ "--certificate-authority --client-certificate --client-key --password --username --request-timeout " +
12
+ "--tls-server-name --cache-dir -v --v --vmodule --log-file --log-dir --log-file-max-size --profile " +
13
+ "--profile-output --warnings-as-errors -o --output -l --selector -f --filename -k --kustomize -c --container " +
14
+ "--field-selector -p --patch --patch-file --type --replicas --current-replicas --resource-version --image " +
15
+ "--port --target-port --protocol --name --external-ip --load-balancer-ip --timeout --grace-period " +
16
+ "--from-literal --from-file --from-env-file --env --overrides --field-manager --prune-allowlist " +
17
+ "--prune-whitelist --labels --limits --requests --sort-by --template --chunk-size -L --label-columns " +
18
+ "--to-revision --pod-running-timeout --restart --serviceaccount --hostport --image-pull-policy " +
19
+ "--session-affinity --cluster-ip --class --rule --annotation --default-backend --resource --verb " +
20
+ "--resource-name --role --clusterrole --group --schedule --from --docker-server --docker-username " +
21
+ "--docker-password --docker-email --cert --key --duration --audience --bound-object-kind " +
22
+ "--bound-object-name --bound-object-uid --target --copy-to --set-image --address --min --max --cpu-percent " +
23
+ "--cpu --raw --for --subresource --output-watch-events --since --since-time --tail --max-log-requests " +
24
+ "--selector --filename --container-name --custom-profile --attach-timeout --request --contains --env-file").split(" "));
25
+ /** Flags whose value is optional (`--dry-run`, `--dry-run=server`): a value only after `=`. */
26
+ const OPTIONAL = new Set(["--dry-run", "--cascade", "--validate", "--wait", "--prune", "--record"]);
27
+ /** Helm's flags that take a value, from `helm --help` and each command's help. */
28
+ export const HELM_VALUES = new Set(("-n --namespace --kube-context --kubeconfig --kube-apiserver --kube-as-user --kube-as-group --kube-ca-file " +
29
+ "--kube-token --kube-tls-server-name --burst-limit --qps --registry-config --repository-cache " +
30
+ "--repository-config -f --values --set --set-string --set-file --set-json --set-literal --version --repo " +
31
+ "--timeout -o --output --post-renderer --post-renderer-args --description --history-max --max --revision " +
32
+ "--username --password --cert-file --key-file --ca-file --name-template --labels -l --selector --cascade " +
33
+ "--keyring --filter --offset --time-format --template --deletion-propagation").split(" "));
34
+ export function parse(args, values) {
35
+ const words = [];
36
+ const flags = new Map();
37
+ const add = (flag, value) => flags.set(flag, [...(flags.get(flag) ?? []), value]);
38
+ for (let index = 0; index < args.length; index++) {
39
+ const word = args[index];
40
+ if (word === "--")
41
+ return { words, flags, afterDash: args.slice(index + 1) };
42
+ if (word.startsWith("--")) {
43
+ const eq = word.indexOf("=");
44
+ const flag = eq > 0 ? word.slice(0, eq) : word;
45
+ if (eq > 0)
46
+ add(flag, word.slice(eq + 1));
47
+ else if (values.has(flag) && !OPTIONAL.has(flag))
48
+ add(flag, args[++index] ?? "");
49
+ else
50
+ add(flag, "true");
51
+ continue;
52
+ }
53
+ if (/^-[A-Za-z]/.test(word)) {
54
+ const flag = word.slice(0, 2);
55
+ if (word.length > 2 && values.has(flag))
56
+ add(flag, word.slice(2).replace(/^=/, ""));
57
+ else if (values.has(flag))
58
+ add(flag, args[++index] ?? "");
59
+ else
60
+ for (const letter of word.slice(1))
61
+ add(`-${letter}`, "true");
62
+ continue;
63
+ }
64
+ words.push(word);
65
+ }
66
+ return { words, flags, afterDash: [] };
67
+ }
68
+ export const flag = (flags, ...names) => names.flatMap((name) => flags.get(name) ?? []).at(-1);
69
+ export const all = (flags, ...names) => names.flatMap((name) => flags.get(name) ?? []);
70
+ export const on = (flags, ...names) => {
71
+ const value = flag(flags, ...names);
72
+ return value !== undefined && !/^(?:false|0|f)$/i.test(value);
73
+ };
74
+ /** A dry run changes nothing: any value but `none` (a bare `--dry-run` is `client`). */
75
+ export const dryRun = (flags) => {
76
+ const value = flag(flags, "--dry-run");
77
+ return value !== undefined && value !== "none" && value !== "false";
78
+ };
79
+ export const programOf = (argv0) => argv0
80
+ .replace(/^.*[\\/]/, "")
81
+ .replace(/\.exe$/i, "")
82
+ .toLowerCase();
@@ -0,0 +1,30 @@
1
+ import type { Classification } from "../../controlPlane.generated.js";
2
+ import { type KubeContextName } from "./kubernetes.generated.js";
3
+ import type { ManifestRead } from "./kubernetesObjects.generated.js";
4
+ /**
5
+ * `kubectl` and `helm` commands as Passport's actions (`kubernetes.ts`), on the guard's computer. Reads (`get`,
6
+ * `describe`, `logs`, `top`, `diff`, `port-forward`, `helm list` …) and local commands (`config use-context`, `helm
7
+ * template`, `--dry-run`) find nothing; `get secret -o yaml` is its own read, so a rule can block it. A write lands on
8
+ * the object it names (`deployment/web` in its namespace), on its namespace when it names several or none, on its
9
+ * cluster with `--all-namespaces`, and on every cluster when the guard can't tell which (`--server`, no kubeconfig).
10
+ * A subcommand Passport doesn't know is its Unclassified action, with the command words it hit.
11
+ *
12
+ * What leaves the computer is the classification: nodes named from the context and the command's resource names, the
13
+ * catalog action, and a fixed summary. Never a flag's value (a token, a literal, a patch), a manifest's contents, or
14
+ * anything after `--`.
15
+ */
16
+ export type KubeResolver = {
17
+ /** The context a command runs against: the one `--context` names, else the kubeconfig's current one (from the
18
+ * `--kubeconfig` file when given); null when it can't be read. */
19
+ context: (name: string | undefined, kubeconfig: string | undefined) => KubeContextName | null;
20
+ /** The objects the `-f` paths declare (files, directories, `-R`); a URL, `-` (standard input) or anything it can't
21
+ * read is unread. */
22
+ manifests: (paths: readonly string[], recursive: boolean) => ManifestRead;
23
+ /** `HELM_NAMESPACE`, `HELM_KUBECONTEXT`, `HELM_KUBECONFIG`: Helm reads its place from them. */
24
+ env?: Readonly<Record<string, string | undefined>>;
25
+ };
26
+ export declare const KUBE_PROGRAMS: Set<string>;
27
+ /** Whether a command's program is one this classifier reads. */
28
+ export declare const isKubeProgram: (argv0: string | undefined) => boolean;
29
+ /** One `kubectl` or `helm` command's actions, in the order it does them; empty for a read or another program. */
30
+ export declare function classifyKube(argv: readonly string[], resolver: KubeResolver): Classification[];