@kwirthmagnify/kwirth-plugin-magnify 0.1.1 → 0.3.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/README.md +20 -0
- package/back.js +329 -34
- package/front.js +66 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,26 @@ It needs three other extensions, which the marketplace asks for when you install
|
|
|
34
34
|
The two providers come already installed in the images that carry channels (`-readonly`, `-full`) and in the
|
|
35
35
|
desktop app.
|
|
36
36
|
|
|
37
|
+
## Permissions
|
|
38
|
+
|
|
39
|
+
Since **0.2.0** Magnify checks who is asking. It declares three scopes, each granting everything below it:
|
|
40
|
+
|
|
41
|
+
- **`magnify$user`** — open it and see the cluster's health: its metrics and its events. It does **not**
|
|
42
|
+
list resources.
|
|
43
|
+
- **`magnify$read`** — also see the **workloads and configuration**, with their contents. It can be
|
|
44
|
+
narrowed from the security editor to **hide kinds** — typically ConfigMap and Secret.
|
|
45
|
+
- **`magnify$write`** — also change those: apply, delete, evict, scale, restart.
|
|
46
|
+
|
|
47
|
+
`cluster` and `admin` sit above all three, and the `Namespaces` of the key limit where it all applies.
|
|
48
|
+
|
|
49
|
+
🔴 **The infrastructure is behind `cluster`, not behind these.** Nodes, CRDs, PersistentVolumes,
|
|
50
|
+
ClusterRoles, StorageClasses — seeing them *or touching them* asks for `cluster`. That is the line
|
|
51
|
+
between a developer and an administrator: somebody with `magnify$write` deletes a pod and cannot drain a
|
|
52
|
+
node.
|
|
53
|
+
|
|
54
|
+
> ⚠️ **Before 0.2.0 it checked nothing**: any key that reached the channel saw the whole cluster. If
|
|
55
|
+
> somebody loses access after upgrading, that is why — grant them `magnify$user` or above.
|
|
56
|
+
|
|
37
57
|
## Development
|
|
38
58
|
|
|
39
59
|
```
|
package/back.js
CHANGED
|
@@ -3094,7 +3094,182 @@ __export(index_exports, {
|
|
|
3094
3094
|
MagnifyChannel: () => MagnifyChannel
|
|
3095
3095
|
});
|
|
3096
3096
|
module.exports = __toCommonJS(index_exports);
|
|
3097
|
+
var import_kwirth_common2 = __toESM(require_kwirth_common(), 1);
|
|
3098
|
+
|
|
3099
|
+
// src/common/MagnifyScopes.ts
|
|
3100
|
+
var MAGNIFY_KINDS = [
|
|
3101
|
+
"CSIDriver",
|
|
3102
|
+
"CSINode",
|
|
3103
|
+
"CSIStorageCapacity",
|
|
3104
|
+
"ClusterRole",
|
|
3105
|
+
"ClusterRoleBinding",
|
|
3106
|
+
"ComponentStatus",
|
|
3107
|
+
"ConfigMap",
|
|
3108
|
+
"CronJob",
|
|
3109
|
+
"CustomResourceDefinition",
|
|
3110
|
+
"DaemonSet",
|
|
3111
|
+
"Deployment",
|
|
3112
|
+
"Endpoints",
|
|
3113
|
+
"HorizontalPodAutoscaler",
|
|
3114
|
+
"Ingress",
|
|
3115
|
+
"IngressClass",
|
|
3116
|
+
"Job",
|
|
3117
|
+
"Lease",
|
|
3118
|
+
"LimitRange",
|
|
3119
|
+
"MutatingWebhookConfiguration",
|
|
3120
|
+
"Namespace",
|
|
3121
|
+
"NetworkPolicy",
|
|
3122
|
+
"Node",
|
|
3123
|
+
"NodeMetrics",
|
|
3124
|
+
"PersistentVolume",
|
|
3125
|
+
"PersistentVolumeClaim",
|
|
3126
|
+
"Pod",
|
|
3127
|
+
"PodDisruptionBudget",
|
|
3128
|
+
"PodMetrics",
|
|
3129
|
+
"PriorityClass",
|
|
3130
|
+
"ReplicaSet",
|
|
3131
|
+
"ReplicationController",
|
|
3132
|
+
"ResourceQuota",
|
|
3133
|
+
"Role",
|
|
3134
|
+
"RoleBinding",
|
|
3135
|
+
"RuntimeClass",
|
|
3136
|
+
"Secret",
|
|
3137
|
+
"Service",
|
|
3138
|
+
"ServiceAccount",
|
|
3139
|
+
"StatefulSet",
|
|
3140
|
+
"StorageClass",
|
|
3141
|
+
"ValidatingWebhookConfiguration",
|
|
3142
|
+
"VolumeAttachment"
|
|
3143
|
+
];
|
|
3144
|
+
var MAGNIFY_HIDE_KINDS = "hideKinds";
|
|
3145
|
+
var MAGNIFY_SCOPES = [
|
|
3146
|
+
{
|
|
3147
|
+
scope: "magnify$user" /* USER */,
|
|
3148
|
+
label: "Magnify \xB7 User",
|
|
3149
|
+
description: "Open Magnify and see the cluster health: its metrics and its events. It does NOT list resources"
|
|
3150
|
+
},
|
|
3151
|
+
{
|
|
3152
|
+
scope: "magnify$read" /* READ */,
|
|
3153
|
+
label: "Magnify \xB7 Read",
|
|
3154
|
+
description: "Also see the cluster's workloads and configuration, with their contents. NOT its infrastructure (nodes, CRDs, cluster roles\u2026), which needs 'cluster'",
|
|
3155
|
+
/*
|
|
3156
|
+
Narrowing READ by KIND, because that is what Magnify knows how to describe and the core does
|
|
3157
|
+
not. 'Everything except ConfigMaps and Secrets' is the case this exists for: the two kinds
|
|
3158
|
+
that carry credentials in a cluster where everything else is harmless to look at.
|
|
3159
|
+
|
|
3160
|
+
⚠️ It hides, it does not allow — so a kind that appears LATER (a new CRD) is visible unless
|
|
3161
|
+
somebody adds it. The opposite, listing what may be seen, fails closed but is 43 entries that
|
|
3162
|
+
rot. The guide says which way it fails.
|
|
3163
|
+
*/
|
|
3164
|
+
config: [{
|
|
3165
|
+
name: MAGNIFY_HIDE_KINDS,
|
|
3166
|
+
label: "Hidden kinds",
|
|
3167
|
+
type: "multiselect",
|
|
3168
|
+
options: MAGNIFY_KINDS
|
|
3169
|
+
}]
|
|
3170
|
+
},
|
|
3171
|
+
{
|
|
3172
|
+
scope: "magnify$write" /* WRITE */,
|
|
3173
|
+
label: "Magnify \xB7 Write",
|
|
3174
|
+
description: "Also change those workloads: apply, delete, evict, scale and restart. NOT the infrastructure \u2014 draining or cordoning a node needs 'cluster'"
|
|
3175
|
+
}
|
|
3176
|
+
];
|
|
3177
|
+
var MAGNIFY_CLUSTER_SCOPE = "cluster";
|
|
3178
|
+
var MAGNIFY_ADMIN_SCOPE = "admin";
|
|
3179
|
+
var MAGNIFY_SCOPE_LADDER = [
|
|
3180
|
+
"",
|
|
3181
|
+
"magnify$user" /* USER */,
|
|
3182
|
+
"magnify$read" /* READ */,
|
|
3183
|
+
"magnify$write" /* WRITE */,
|
|
3184
|
+
MAGNIFY_CLUSTER_SCOPE,
|
|
3185
|
+
MAGNIFY_ADMIN_SCOPE
|
|
3186
|
+
];
|
|
3187
|
+
|
|
3188
|
+
// src/common/MagnifyAuth.ts
|
|
3097
3189
|
var import_kwirth_common = __toESM(require_kwirth_common(), 1);
|
|
3190
|
+
var levelOf = (scope) => MAGNIFY_SCOPE_LADDER.indexOf(scope);
|
|
3191
|
+
var CLUSTER_SCOPED = /* @__PURE__ */ new Set([
|
|
3192
|
+
"CSIDriver",
|
|
3193
|
+
"CSINode",
|
|
3194
|
+
"ClusterRole",
|
|
3195
|
+
"ClusterRoleBinding",
|
|
3196
|
+
"ComponentStatus",
|
|
3197
|
+
"CustomResourceDefinition",
|
|
3198
|
+
"IngressClass",
|
|
3199
|
+
"MutatingWebhookConfiguration",
|
|
3200
|
+
"Namespace",
|
|
3201
|
+
"Node",
|
|
3202
|
+
"NodeMetrics",
|
|
3203
|
+
"PersistentVolume",
|
|
3204
|
+
"PriorityClass",
|
|
3205
|
+
"RuntimeClass",
|
|
3206
|
+
"StorageClass",
|
|
3207
|
+
"ValidatingWebhookConfiguration",
|
|
3208
|
+
"VolumeAttachment"
|
|
3209
|
+
]);
|
|
3210
|
+
var grantsOf = (accessKey) => {
|
|
3211
|
+
if (!accessKey) return [];
|
|
3212
|
+
try {
|
|
3213
|
+
return (0, import_kwirth_common.parseResources)(accessKey.resources).map((r) => {
|
|
3214
|
+
const namespaces = (r.namespaces || "").split(",").map((n) => n.trim()).filter(Boolean);
|
|
3215
|
+
let level = -1;
|
|
3216
|
+
let hidden;
|
|
3217
|
+
for (const token of (r.scopes || "").split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
3218
|
+
const thin = (0, import_kwirth_common.parseThinScope)(token);
|
|
3219
|
+
const tokenLevel = levelOf(thin ? thin.wide : token);
|
|
3220
|
+
if (tokenLevel < 0) continue;
|
|
3221
|
+
if (tokenLevel > level) {
|
|
3222
|
+
level = tokenLevel;
|
|
3223
|
+
hidden = void 0;
|
|
3224
|
+
}
|
|
3225
|
+
if (tokenLevel !== level) continue;
|
|
3226
|
+
const tokenHides = thin ? kindsHiddenBy(thin.config) : /* @__PURE__ */ new Set();
|
|
3227
|
+
hidden = hidden === void 0 ? tokenHides : intersect(hidden, tokenHides);
|
|
3228
|
+
}
|
|
3229
|
+
return { level, hidden: hidden ?? /* @__PURE__ */ new Set(), namespaces };
|
|
3230
|
+
});
|
|
3231
|
+
} catch (err) {
|
|
3232
|
+
return [];
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
var intersect = (a, b) => new Set([...a].filter((k) => b.has(k)));
|
|
3236
|
+
var kindsHiddenBy = (config) => {
|
|
3237
|
+
if (!config || typeof config !== "object") return /* @__PURE__ */ new Set();
|
|
3238
|
+
const raw = config[MAGNIFY_HIDE_KINDS];
|
|
3239
|
+
const kinds = Array.isArray(raw) ? raw.map(String) : typeof raw === "string" ? raw.split(",") : [];
|
|
3240
|
+
return new Set(kinds.map((k) => k.trim()).filter(Boolean));
|
|
3241
|
+
};
|
|
3242
|
+
var reaches = (grant, namespace) => {
|
|
3243
|
+
if (grant.namespaces.length === 0) return true;
|
|
3244
|
+
if (!namespace) return false;
|
|
3245
|
+
return grant.namespaces.some((pattern) => {
|
|
3246
|
+
try {
|
|
3247
|
+
return new RegExp(`^${pattern}$`).test(namespace);
|
|
3248
|
+
} catch (err) {
|
|
3249
|
+
return false;
|
|
3250
|
+
}
|
|
3251
|
+
});
|
|
3252
|
+
};
|
|
3253
|
+
var allows = (accessKey, required) => {
|
|
3254
|
+
const requiredLevel = levelOf(required);
|
|
3255
|
+
return grantsOf(accessKey).some((g) => g.level >= requiredLevel);
|
|
3256
|
+
};
|
|
3257
|
+
var canSee = (accessKey, kind, namespace) => grantsOf(accessKey).some((g) => {
|
|
3258
|
+
if (g.level < levelFor(kind, "magnify$read" /* READ */)) return false;
|
|
3259
|
+
if (g.hidden.has(kind)) return false;
|
|
3260
|
+
return CLUSTER_SCOPED.has(kind) || reaches(g, namespace ?? "");
|
|
3261
|
+
});
|
|
3262
|
+
var canSeeAnyOf = (accessKey, kind) => grantsOf(accessKey).some((g) => g.level >= levelFor(kind, "magnify$read" /* READ */) && !g.hidden.has(kind));
|
|
3263
|
+
var canChange = (accessKey, kind, namespace) => grantsOf(accessKey).some((g) => {
|
|
3264
|
+
if (g.level < levelFor(kind, "magnify$write" /* WRITE */)) return false;
|
|
3265
|
+
if (g.hidden.has(kind)) return false;
|
|
3266
|
+
return CLUSTER_SCOPED.has(kind) || reaches(g, namespace ?? "");
|
|
3267
|
+
});
|
|
3268
|
+
var levelFor = (kind, asked) => levelOf(CLUSTER_SCOPED.has(kind) ? MAGNIFY_CLUSTER_SCOPE : asked);
|
|
3269
|
+
var needsFiltering = (accessKey) => grantsOf(accessKey).some((g) => g.namespaces.length > 0 || g.hidden.size > 0);
|
|
3270
|
+
var filterItems = (accessKey, kind, items) => items.filter((item) => canSee(accessKey, kind, item.metadata?.namespace));
|
|
3271
|
+
|
|
3272
|
+
// src/back/index.ts
|
|
3098
3273
|
var import_kwirth_common_back = __toESM(require_kwirth_common_back(), 1);
|
|
3099
3274
|
var yaml = require_js_yaml();
|
|
3100
3275
|
var EMagnifyCommand = /* @__PURE__ */ ((EMagnifyCommand2) => {
|
|
@@ -3119,6 +3294,22 @@ var EMagnifyCommand = /* @__PURE__ */ ((EMagnifyCommand2) => {
|
|
|
3119
3294
|
EMagnifyCommand2["LOGSEARCH_STOP"] = "logsearchstop";
|
|
3120
3295
|
return EMagnifyCommand2;
|
|
3121
3296
|
})(EMagnifyCommand || {});
|
|
3297
|
+
var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
|
|
3298
|
+
"create" /* CREATE */,
|
|
3299
|
+
"apply" /* APPLY */,
|
|
3300
|
+
"delete" /* DELETE */,
|
|
3301
|
+
"Pod" /* POD */,
|
|
3302
|
+
"Node" /* NODE */,
|
|
3303
|
+
"Controller" /* CONTROLLER */,
|
|
3304
|
+
"Image" /* IMAGE */,
|
|
3305
|
+
"CronJob" /* CRONJOB */,
|
|
3306
|
+
"IngressClass" /* INGRESSCLASS */
|
|
3307
|
+
]);
|
|
3308
|
+
var INFRA_COMMANDS = /* @__PURE__ */ new Set([
|
|
3309
|
+
"Node" /* NODE */,
|
|
3310
|
+
"Image" /* IMAGE */,
|
|
3311
|
+
"IngressClass" /* INGRESSCLASS */
|
|
3312
|
+
]);
|
|
3122
3313
|
var MagnifyChannel = class {
|
|
3123
3314
|
// +++ add dispose/destroy (conterpart of initChannel) to IChannel (and implement in this channel a remove from "events subscription")
|
|
3124
3315
|
constructor(clusterInfo, backChannelObject) {
|
|
@@ -3157,16 +3348,20 @@ var MagnifyChannel = class {
|
|
|
3157
3348
|
modifiable: false,
|
|
3158
3349
|
reconnectable: true,
|
|
3159
3350
|
metrics: true,
|
|
3160
|
-
sources: [
|
|
3351
|
+
sources: [import_kwirth_common2.EClusterType.KUBERNETES],
|
|
3161
3352
|
endpoints: [],
|
|
3162
3353
|
websocket: false,
|
|
3163
3354
|
cluster: true,
|
|
3164
3355
|
resourced: false
|
|
3165
3356
|
};
|
|
3166
3357
|
};
|
|
3167
|
-
this.getChannelScopeLevel = (scope) =>
|
|
3168
|
-
|
|
3169
|
-
|
|
3358
|
+
this.getChannelScopeLevel = (scope) => MAGNIFY_SCOPE_LADDER.indexOf(scope);
|
|
3359
|
+
/*
|
|
3360
|
+
What the security editor offers for Magnify. Until this existed the editor showed nothing of this
|
|
3361
|
+
channel, so the only way to grant it was `cluster` — admin-level over the whole product — and
|
|
3362
|
+
there was no way to say 'look but do not touch' or 'only this namespace'.
|
|
3363
|
+
*/
|
|
3364
|
+
this.getScopeCatalog = () => MAGNIFY_SCOPES;
|
|
3170
3365
|
this.startChannel = async () => {
|
|
3171
3366
|
this.clusterInfo.addSubscriber("metrics", this, {});
|
|
3172
3367
|
};
|
|
@@ -3183,7 +3378,7 @@ var MagnifyChannel = class {
|
|
|
3183
3378
|
};
|
|
3184
3379
|
this.processCommand = async (webSocket, instanceMessage) => {
|
|
3185
3380
|
try {
|
|
3186
|
-
if (instanceMessage.flow ===
|
|
3381
|
+
if (instanceMessage.flow === import_kwirth_common2.EInstanceMessageFlow.IMMEDIATE) {
|
|
3187
3382
|
return false;
|
|
3188
3383
|
} else {
|
|
3189
3384
|
let socket = this.webSockets.find((s) => s.ws === webSocket);
|
|
@@ -3194,7 +3389,7 @@ var MagnifyChannel = class {
|
|
|
3194
3389
|
let instances = socket.instances;
|
|
3195
3390
|
let instance = instances.find((i) => i.instanceId === instanceMessage.instance);
|
|
3196
3391
|
if (!instance) {
|
|
3197
|
-
this.sendSignalMessage(webSocket, instanceMessage.action,
|
|
3392
|
+
this.sendSignalMessage(webSocket, instanceMessage.action, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instanceMessage.instance, `Instance not found`);
|
|
3198
3393
|
this.log.info(`Instance ${instanceMessage.instance} not found`);
|
|
3199
3394
|
return false;
|
|
3200
3395
|
}
|
|
@@ -3210,6 +3405,19 @@ var MagnifyChannel = class {
|
|
|
3210
3405
|
};
|
|
3211
3406
|
this.addObject = async (webSocket, instanceConfig, podNamespace, podName, containerName) => {
|
|
3212
3407
|
this.log.info(`Start instance ${instanceConfig.instance} ${podNamespace}/${podName}/${containerName} (view: ${instanceConfig.view})`);
|
|
3408
|
+
const accessKey = (0, import_kwirth_common2.accessKeyDeserialize)(instanceConfig.accessKey);
|
|
3409
|
+
if (!allows(accessKey, "magnify$user" /* USER */)) {
|
|
3410
|
+
this.log.warning(`Denied instance ${instanceConfig.instance} to key ${accessKey?.id}: '${"magnify$user" /* USER */}' required`);
|
|
3411
|
+
this.sendSignalMessage(
|
|
3412
|
+
webSocket,
|
|
3413
|
+
import_kwirth_common2.EInstanceMessageAction.START,
|
|
3414
|
+
import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3415
|
+
import_kwirth_common2.ESignalMessageLevel.ERROR,
|
|
3416
|
+
instanceConfig.instance,
|
|
3417
|
+
`You don't have permission to use Magnify. Opening it requires the '${"magnify$user" /* USER */}' scope \u2014 ask an administrator.`
|
|
3418
|
+
);
|
|
3419
|
+
return false;
|
|
3420
|
+
}
|
|
3213
3421
|
let socket = this.webSockets.find((s) => s.ws === webSocket);
|
|
3214
3422
|
if (!socket) {
|
|
3215
3423
|
let len = this.webSockets.push({ ws: webSocket, lastRefresh: Date.now(), instances: [] });
|
|
@@ -3219,7 +3427,8 @@ var MagnifyChannel = class {
|
|
|
3219
3427
|
let instance = instances.find((i) => i.instanceId === instanceConfig.instance);
|
|
3220
3428
|
if (!instance) {
|
|
3221
3429
|
instance = {
|
|
3222
|
-
instanceId: instanceConfig.instance
|
|
3430
|
+
instanceId: instanceConfig.instance,
|
|
3431
|
+
accessKey
|
|
3223
3432
|
};
|
|
3224
3433
|
instances.push(instance);
|
|
3225
3434
|
}
|
|
@@ -3238,9 +3447,9 @@ var MagnifyChannel = class {
|
|
|
3238
3447
|
let instance = this.getInstance(webSocket, instanceConfig.instance);
|
|
3239
3448
|
if (instance) {
|
|
3240
3449
|
this.removeInstance(webSocket, instanceConfig.instance);
|
|
3241
|
-
this.sendSignalMessage(webSocket,
|
|
3450
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.STOP, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.INFO, instanceConfig.instance, "Magnify instance stopped");
|
|
3242
3451
|
} else {
|
|
3243
|
-
this.sendSignalMessage(webSocket,
|
|
3452
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.STOP, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instanceConfig.instance, `Magnify instance not found`);
|
|
3244
3453
|
}
|
|
3245
3454
|
};
|
|
3246
3455
|
this.removeInstance = (webSocket, instanceId) => {
|
|
@@ -3300,13 +3509,75 @@ var MagnifyChannel = class {
|
|
|
3300
3509
|
// *************************************************************************************
|
|
3301
3510
|
// PRIVATE
|
|
3302
3511
|
// *************************************************************************************
|
|
3512
|
+
/*
|
|
3513
|
+
🔴 Where a listing is cut down to what the key may see, and the ONLY place it happens.
|
|
3514
|
+
|
|
3515
|
+
It is done here, on the serialised body, and not in each of the forty-odd branches of
|
|
3516
|
+
`executeList`: a filter that has to be remembered in forty places is a filter that will be
|
|
3517
|
+
missing from one of them, and the one it is missing from is a kind somebody can read and should
|
|
3518
|
+
not. Everything Magnify lists leaves through this method.
|
|
3519
|
+
|
|
3520
|
+
A key that narrows nothing does no work at all.
|
|
3521
|
+
*/
|
|
3522
|
+
this.filterListPayload = (accessKey, data) => {
|
|
3523
|
+
if (typeof data !== "string") return data;
|
|
3524
|
+
try {
|
|
3525
|
+
const body = JSON.parse(data);
|
|
3526
|
+
if (!Array.isArray(body?.items)) return data;
|
|
3527
|
+
const kind = typeof body.kind === "string" && body.kind.endsWith("List") ? body.kind.slice(0, -4) : void 0;
|
|
3528
|
+
if (!kind) {
|
|
3529
|
+
this.log.warning(`A listing with no kind reached a limited key: nothing is sent (${String(data).slice(0, 80)})`);
|
|
3530
|
+
return JSON.stringify({ ...body, items: [] });
|
|
3531
|
+
}
|
|
3532
|
+
return JSON.stringify({ ...body, items: filterItems(accessKey, kind, body.items) });
|
|
3533
|
+
} catch (err) {
|
|
3534
|
+
this.log.warning(`A listing could not be read to be filtered, so nothing is sent: ${err}`);
|
|
3535
|
+
return JSON.stringify({ items: [] });
|
|
3536
|
+
}
|
|
3537
|
+
};
|
|
3538
|
+
/*
|
|
3539
|
+
🔴 May this key change THIS object? Asked per object, because the command does not say enough:
|
|
3540
|
+
'delete' on a Pod is a developer's business and 'delete' on a ClusterRole is the installation's.
|
|
3541
|
+
The kind travels inside the YAML, which is what makes the question answerable here.
|
|
3542
|
+
|
|
3543
|
+
It refuses one object and carries on with the rest rather than failing the whole batch: a
|
|
3544
|
+
selection of twelve pods and one node should apply to the twelve.
|
|
3545
|
+
*/
|
|
3546
|
+
this.mayChange = (webSocket, instance, obj, what) => {
|
|
3547
|
+
const kind = typeof obj?.kind === "string" ? obj.kind : void 0;
|
|
3548
|
+
if (!kind) {
|
|
3549
|
+
this.log.warning(`Refused to ${what} an object with no kind: there is no way to tell what it is`);
|
|
3550
|
+
this.sendSignalMessage(
|
|
3551
|
+
webSocket,
|
|
3552
|
+
import_kwirth_common2.EInstanceMessageAction.COMMAND,
|
|
3553
|
+
import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3554
|
+
import_kwirth_common2.ESignalMessageLevel.ERROR,
|
|
3555
|
+
instance.instanceId,
|
|
3556
|
+
`Could not ${what} an object: it does not say what kind it is.`
|
|
3557
|
+
);
|
|
3558
|
+
return false;
|
|
3559
|
+
}
|
|
3560
|
+
if (canChange(instance.accessKey, kind, obj?.metadata?.namespace)) return true;
|
|
3561
|
+
const name = obj?.metadata?.name ?? "(unnamed)";
|
|
3562
|
+
this.log.warning(`Denied ${what} of ${kind}/${name} to key ${instance.accessKey?.id}`);
|
|
3563
|
+
this.sendSignalMessage(
|
|
3564
|
+
webSocket,
|
|
3565
|
+
import_kwirth_common2.EInstanceMessageAction.COMMAND,
|
|
3566
|
+
import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3567
|
+
import_kwirth_common2.ESignalMessageLevel.ERROR,
|
|
3568
|
+
instance.instanceId,
|
|
3569
|
+
`You don't have permission to ${what} the ${kind} '${name}'.`
|
|
3570
|
+
);
|
|
3571
|
+
return false;
|
|
3572
|
+
};
|
|
3303
3573
|
this.sendDataMessage = (webSocket, instance, id, command, data) => {
|
|
3574
|
+
if (command === "list" /* LIST */ && needsFiltering(instance.accessKey)) data = this.filterListPayload(instance.accessKey, data);
|
|
3304
3575
|
let resp = {
|
|
3305
|
-
action:
|
|
3306
|
-
flow:
|
|
3576
|
+
action: import_kwirth_common2.EInstanceMessageAction.COMMAND,
|
|
3577
|
+
flow: import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3307
3578
|
channel: "magnify",
|
|
3308
3579
|
instance: instance.instanceId,
|
|
3309
|
-
type:
|
|
3580
|
+
type: import_kwirth_common2.EInstanceMessageType.DATA,
|
|
3310
3581
|
id,
|
|
3311
3582
|
command,
|
|
3312
3583
|
namespace: "",
|
|
@@ -3324,7 +3595,7 @@ var MagnifyChannel = class {
|
|
|
3324
3595
|
flow,
|
|
3325
3596
|
channel: "magnify",
|
|
3326
3597
|
instance: instanceId,
|
|
3327
|
-
type:
|
|
3598
|
+
type: import_kwirth_common2.EInstanceMessageType.SIGNAL,
|
|
3328
3599
|
text,
|
|
3329
3600
|
level
|
|
3330
3601
|
};
|
|
@@ -3424,6 +3695,7 @@ var MagnifyChannel = class {
|
|
|
3424
3695
|
case "events":
|
|
3425
3696
|
for (let socket of this.webSockets) {
|
|
3426
3697
|
for (let instance of socket.instances) {
|
|
3698
|
+
if (!canSee(instance.accessKey, obj.obj?.kind, obj.obj?.metadata?.namespace)) continue;
|
|
3427
3699
|
let magnifyMessage = {
|
|
3428
3700
|
msgtype: "magnifymessageresponse",
|
|
3429
3701
|
id: "1",
|
|
@@ -3432,9 +3704,9 @@ var MagnifyChannel = class {
|
|
|
3432
3704
|
group: "",
|
|
3433
3705
|
pod: "",
|
|
3434
3706
|
container: "",
|
|
3435
|
-
action:
|
|
3436
|
-
flow:
|
|
3437
|
-
type:
|
|
3707
|
+
action: import_kwirth_common2.EInstanceMessageAction.COMMAND,
|
|
3708
|
+
flow: import_kwirth_common2.EInstanceMessageFlow.UNSOLICITED,
|
|
3709
|
+
type: import_kwirth_common2.EInstanceMessageType.DATA,
|
|
3438
3710
|
channel: "magnify",
|
|
3439
3711
|
instance: instance.instanceId,
|
|
3440
3712
|
event: obj.type,
|
|
@@ -3471,8 +3743,8 @@ var MagnifyChannel = class {
|
|
|
3471
3743
|
async executeCommand(webSocket, instance, magnifyMessage) {
|
|
3472
3744
|
let execResponse = {
|
|
3473
3745
|
action: magnifyMessage.action,
|
|
3474
|
-
flow:
|
|
3475
|
-
type:
|
|
3746
|
+
flow: import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3747
|
+
type: import_kwirth_common2.EInstanceMessageType.SIGNAL,
|
|
3476
3748
|
channel: magnifyMessage.channel,
|
|
3477
3749
|
instance: magnifyMessage.instance,
|
|
3478
3750
|
command: magnifyMessage.command,
|
|
@@ -3488,6 +3760,21 @@ var MagnifyChannel = class {
|
|
|
3488
3760
|
execResponse.data = "No command received in data";
|
|
3489
3761
|
return execResponse;
|
|
3490
3762
|
}
|
|
3763
|
+
if (MUTATING_COMMANDS.has(magnifyMessage.command)) {
|
|
3764
|
+
const required = INFRA_COMMANDS.has(magnifyMessage.command) ? MAGNIFY_CLUSTER_SCOPE : "magnify$write" /* WRITE */;
|
|
3765
|
+
if (!allows(instance.accessKey, required)) {
|
|
3766
|
+
this.log.warning(`Denied '${magnifyMessage.command}' to key ${instance.accessKey?.id}: '${required}' required`);
|
|
3767
|
+
this.sendSignalMessage(
|
|
3768
|
+
webSocket,
|
|
3769
|
+
magnifyMessage.action,
|
|
3770
|
+
import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3771
|
+
import_kwirth_common2.ESignalMessageLevel.ERROR,
|
|
3772
|
+
instance.instanceId,
|
|
3773
|
+
INFRA_COMMANDS.has(magnifyMessage.command) ? `That acts on the cluster's infrastructure, which requires the '${MAGNIFY_CLUSTER_SCOPE}' scope.` : `You don't have permission to change the cluster from Magnify \u2014 that requires the '${"magnify$write" /* WRITE */}' scope.`
|
|
3774
|
+
);
|
|
3775
|
+
return void 0;
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3491
3778
|
switch (magnifyMessage.command) {
|
|
3492
3779
|
case "list" /* LIST */: {
|
|
3493
3780
|
this.log.info(`Get LIST`);
|
|
@@ -3513,14 +3800,14 @@ var MagnifyChannel = class {
|
|
|
3513
3800
|
switch (magnifyMessage.params[0]) {
|
|
3514
3801
|
case "evict":
|
|
3515
3802
|
await (0, import_kwirth_common_back.podEvict)(this.clusterInfo.coreApi, magnifyMessage.params[1], magnifyMessage.params[2]);
|
|
3516
|
-
this.sendSignalMessage(webSocket,
|
|
3803
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.INFO, instance.instanceId, `Pod '${magnifyMessage.params[1]}/${magnifyMessage.params[2]}' successfully evicted`);
|
|
3517
3804
|
return;
|
|
3518
3805
|
case "work":
|
|
3519
3806
|
let podName = await (0, import_kwirth_common_back.podWork)(this.clusterInfo.coreApi, magnifyMessage.params[1]);
|
|
3520
3807
|
this.sendDataMessage(webSocket, instance, "1", "Pod" /* POD */, JSON.stringify(["work", podName]));
|
|
3521
3808
|
return;
|
|
3522
3809
|
default:
|
|
3523
|
-
this.sendSignalMessage(webSocket,
|
|
3810
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid POD command");
|
|
3524
3811
|
console.error("Invalid POD command");
|
|
3525
3812
|
return;
|
|
3526
3813
|
}
|
|
@@ -3528,10 +3815,10 @@ var MagnifyChannel = class {
|
|
|
3528
3815
|
switch (magnifyMessage.params[0]) {
|
|
3529
3816
|
case "default":
|
|
3530
3817
|
await (0, import_kwirth_common_back.setIngressClassAsDefault)(this.clusterInfo.networkApi, magnifyMessage.params[1]);
|
|
3531
|
-
this.sendSignalMessage(webSocket,
|
|
3818
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.INFO, instance.instanceId, `Ingress class '${magnifyMessage.params[1]}}' successfully set`);
|
|
3532
3819
|
return;
|
|
3533
3820
|
default:
|
|
3534
|
-
this.sendSignalMessage(webSocket,
|
|
3821
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid IngressClass command");
|
|
3535
3822
|
console.error("Invalid IngressClass command");
|
|
3536
3823
|
return;
|
|
3537
3824
|
}
|
|
@@ -3547,7 +3834,7 @@ var MagnifyChannel = class {
|
|
|
3547
3834
|
});
|
|
3548
3835
|
return;
|
|
3549
3836
|
default:
|
|
3550
|
-
this.sendSignalMessage(webSocket,
|
|
3837
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid Image command");
|
|
3551
3838
|
console.error("Invalid Image command");
|
|
3552
3839
|
return;
|
|
3553
3840
|
}
|
|
@@ -3566,7 +3853,7 @@ var MagnifyChannel = class {
|
|
|
3566
3853
|
await (0, import_kwirth_common_back.nodeDrain)(this.clusterInfo.coreApi, magnifyMessage.params[1]);
|
|
3567
3854
|
break;
|
|
3568
3855
|
default:
|
|
3569
|
-
this.sendSignalMessage(webSocket,
|
|
3856
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid node command");
|
|
3570
3857
|
console.error("Invalid node command");
|
|
3571
3858
|
return;
|
|
3572
3859
|
}
|
|
@@ -3611,7 +3898,7 @@ var MagnifyChannel = class {
|
|
|
3611
3898
|
(0, import_kwirth_common_back.scaleController)(magnifyMessage.params[1], magnifyMessage.params[2], magnifyMessage.params[3], +magnifyMessage.params[4], this.clusterInfo);
|
|
3612
3899
|
break;
|
|
3613
3900
|
default:
|
|
3614
|
-
this.sendSignalMessage(webSocket,
|
|
3901
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid controller command");
|
|
3615
3902
|
console.error("Invalid node command");
|
|
3616
3903
|
return;
|
|
3617
3904
|
}
|
|
@@ -3630,7 +3917,7 @@ var MagnifyChannel = class {
|
|
|
3630
3917
|
await (0, import_kwirth_common_back.cronJobStatus)(magnifyMessage.params[1], magnifyMessage.params[2], false, this.clusterInfo.batchApi);
|
|
3631
3918
|
break;
|
|
3632
3919
|
default:
|
|
3633
|
-
this.sendSignalMessage(webSocket,
|
|
3920
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid cronjon command");
|
|
3634
3921
|
console.error("Invalid node command");
|
|
3635
3922
|
return;
|
|
3636
3923
|
}
|
|
@@ -3700,7 +3987,7 @@ var MagnifyChannel = class {
|
|
|
3700
3987
|
}
|
|
3701
3988
|
default:
|
|
3702
3989
|
let text = `Invalid command '${magnifyMessage.command}'. Valid commands are: ${Object.keys(EMagnifyCommand)}`;
|
|
3703
|
-
this.sendSignalMessage(webSocket,
|
|
3990
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, text);
|
|
3704
3991
|
break;
|
|
3705
3992
|
}
|
|
3706
3993
|
return execResponse;
|
|
@@ -3712,6 +3999,10 @@ var MagnifyChannel = class {
|
|
|
3712
3999
|
}
|
|
3713
4000
|
async executeList(webSocket, instance, magnifyMessage) {
|
|
3714
4001
|
for (let param of magnifyMessage.params) {
|
|
4002
|
+
if (!canSeeAnyOf(instance.accessKey, param)) {
|
|
4003
|
+
this.log.info(`Not listing '${param}' for key ${instance.accessKey?.id}: not granted`);
|
|
4004
|
+
continue;
|
|
4005
|
+
}
|
|
3715
4006
|
switch (param) {
|
|
3716
4007
|
case "ComponentStatus":
|
|
3717
4008
|
(0, import_kwirth_common_back.throttleExcute)(param, async () => {
|
|
@@ -3933,7 +4224,7 @@ var MagnifyChannel = class {
|
|
|
3933
4224
|
break;
|
|
3934
4225
|
default:
|
|
3935
4226
|
this.log.warning("Invalid class received: " + param);
|
|
3936
|
-
this.sendSignalMessage(webSocket,
|
|
4227
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid class: " + param);
|
|
3937
4228
|
break;
|
|
3938
4229
|
}
|
|
3939
4230
|
}
|
|
@@ -3951,17 +4242,18 @@ var MagnifyChannel = class {
|
|
|
3951
4242
|
});
|
|
3952
4243
|
} catch (err) {
|
|
3953
4244
|
this.log.info(err);
|
|
3954
|
-
this.sendSignalMessage(webSocket,
|
|
4245
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err.body));
|
|
3955
4246
|
}
|
|
3956
4247
|
}
|
|
3957
4248
|
async executeDelete(webSocket, instance, params) {
|
|
3958
4249
|
try {
|
|
3959
4250
|
for (let obj of params) {
|
|
3960
4251
|
try {
|
|
4252
|
+
if (!this.mayChange(webSocket, instance, yaml.load(obj), "delete")) continue;
|
|
3961
4253
|
await this.clusterInfo.objectsApi.delete(yaml.load(obj));
|
|
3962
4254
|
} catch (err) {
|
|
3963
4255
|
this.log.info(err);
|
|
3964
|
-
this.sendSignalMessage(webSocket,
|
|
4256
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err.body));
|
|
3965
4257
|
}
|
|
3966
4258
|
}
|
|
3967
4259
|
} catch (err) {
|
|
@@ -3973,9 +4265,11 @@ var MagnifyChannel = class {
|
|
|
3973
4265
|
try {
|
|
3974
4266
|
for (let param of params) {
|
|
3975
4267
|
try {
|
|
3976
|
-
|
|
4268
|
+
const res = yaml.load(param);
|
|
4269
|
+
if (!this.mayChange(webSocket, instance, res, "create")) continue;
|
|
4270
|
+
this.clusterInfo.objectsApi.create(res);
|
|
3977
4271
|
} catch (err) {
|
|
3978
|
-
this.sendSignalMessage(webSocket,
|
|
4272
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err));
|
|
3979
4273
|
}
|
|
3980
4274
|
}
|
|
3981
4275
|
} catch (err) {
|
|
@@ -3988,10 +4282,11 @@ var MagnifyChannel = class {
|
|
|
3988
4282
|
for (let param of params) {
|
|
3989
4283
|
try {
|
|
3990
4284
|
const res = yaml.load(param);
|
|
4285
|
+
if (!this.mayChange(webSocket, instance, res, "apply")) continue;
|
|
3991
4286
|
let result = await (0, import_kwirth_common_back.applyResource)(res, this.clusterInfo);
|
|
3992
|
-
this.sendSignalMessage(webSocket,
|
|
4287
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.INFO, instance.instanceId, result);
|
|
3993
4288
|
} catch (err) {
|
|
3994
|
-
this.sendSignalMessage(webSocket,
|
|
4289
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err));
|
|
3995
4290
|
}
|
|
3996
4291
|
}
|
|
3997
4292
|
} catch (err) {
|