@kwirthmagnify/kwirth-plugin-magnify 0.1.1 → 0.2.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 +16 -0
- package/back.js +286 -33
- package/front.js +66 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,22 @@ 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 what the cluster has: the resources, with their contents. It can be
|
|
44
|
+
narrowed from the security editor to **hide kinds** — typically ConfigMap and Secret.
|
|
45
|
+
- **`magnify$write`** — also change the cluster: apply, delete, evict, drain, scale, restart.
|
|
46
|
+
|
|
47
|
+
`cluster` and `admin` sit above all three. The `Namespaces` of the key limit it too, and a key limited to
|
|
48
|
+
namespaces does not see what lives in none of them (Nodes, PersistentVolumes, ClusterRoles…).
|
|
49
|
+
|
|
50
|
+
> ⚠️ **Before 0.2.0 it checked nothing**: any key that reached the channel saw the whole cluster. If
|
|
51
|
+
> somebody loses access after upgrading, that is why — grant them `magnify$user` or above.
|
|
52
|
+
|
|
37
53
|
## Development
|
|
38
54
|
|
|
39
55
|
```
|
package/back.js
CHANGED
|
@@ -3094,7 +3094,187 @@ __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 what the cluster has: its resources, with their contents",
|
|
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 the cluster: apply, delete, evict, drain, scale and restart"
|
|
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) => {
|
|
3258
|
+
const requiredLevel = levelOf("magnify$read" /* READ */);
|
|
3259
|
+
return grantsOf(accessKey).some((g) => {
|
|
3260
|
+
if (g.level < requiredLevel) return false;
|
|
3261
|
+
if (g.hidden.has(kind)) return false;
|
|
3262
|
+
if (CLUSTER_SCOPED.has(kind)) return g.namespaces.length === 0;
|
|
3263
|
+
return reaches(g, namespace ?? "");
|
|
3264
|
+
});
|
|
3265
|
+
};
|
|
3266
|
+
var canSeeAnyOf = (accessKey, kind) => {
|
|
3267
|
+
const requiredLevel = levelOf("magnify$read" /* READ */);
|
|
3268
|
+
return grantsOf(accessKey).some((g) => {
|
|
3269
|
+
if (g.level < requiredLevel) return false;
|
|
3270
|
+
if (g.hidden.has(kind)) return false;
|
|
3271
|
+
return !CLUSTER_SCOPED.has(kind) || g.namespaces.length === 0;
|
|
3272
|
+
});
|
|
3273
|
+
};
|
|
3274
|
+
var needsFiltering = (accessKey) => grantsOf(accessKey).some((g) => g.namespaces.length > 0 || g.hidden.size > 0);
|
|
3275
|
+
var filterItems = (accessKey, kind, items) => items.filter((item) => canSee(accessKey, kind, item.metadata?.namespace));
|
|
3276
|
+
|
|
3277
|
+
// src/back/index.ts
|
|
3098
3278
|
var import_kwirth_common_back = __toESM(require_kwirth_common_back(), 1);
|
|
3099
3279
|
var yaml = require_js_yaml();
|
|
3100
3280
|
var EMagnifyCommand = /* @__PURE__ */ ((EMagnifyCommand2) => {
|
|
@@ -3119,6 +3299,17 @@ var EMagnifyCommand = /* @__PURE__ */ ((EMagnifyCommand2) => {
|
|
|
3119
3299
|
EMagnifyCommand2["LOGSEARCH_STOP"] = "logsearchstop";
|
|
3120
3300
|
return EMagnifyCommand2;
|
|
3121
3301
|
})(EMagnifyCommand || {});
|
|
3302
|
+
var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
|
|
3303
|
+
"create" /* CREATE */,
|
|
3304
|
+
"apply" /* APPLY */,
|
|
3305
|
+
"delete" /* DELETE */,
|
|
3306
|
+
"Pod" /* POD */,
|
|
3307
|
+
"Node" /* NODE */,
|
|
3308
|
+
"Controller" /* CONTROLLER */,
|
|
3309
|
+
"Image" /* IMAGE */,
|
|
3310
|
+
"CronJob" /* CRONJOB */,
|
|
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,40 @@ 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
|
+
};
|
|
3303
3538
|
this.sendDataMessage = (webSocket, instance, id, command, data) => {
|
|
3539
|
+
if (command === "list" /* LIST */ && needsFiltering(instance.accessKey)) data = this.filterListPayload(instance.accessKey, data);
|
|
3304
3540
|
let resp = {
|
|
3305
|
-
action:
|
|
3306
|
-
flow:
|
|
3541
|
+
action: import_kwirth_common2.EInstanceMessageAction.COMMAND,
|
|
3542
|
+
flow: import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3307
3543
|
channel: "magnify",
|
|
3308
3544
|
instance: instance.instanceId,
|
|
3309
|
-
type:
|
|
3545
|
+
type: import_kwirth_common2.EInstanceMessageType.DATA,
|
|
3310
3546
|
id,
|
|
3311
3547
|
command,
|
|
3312
3548
|
namespace: "",
|
|
@@ -3324,7 +3560,7 @@ var MagnifyChannel = class {
|
|
|
3324
3560
|
flow,
|
|
3325
3561
|
channel: "magnify",
|
|
3326
3562
|
instance: instanceId,
|
|
3327
|
-
type:
|
|
3563
|
+
type: import_kwirth_common2.EInstanceMessageType.SIGNAL,
|
|
3328
3564
|
text,
|
|
3329
3565
|
level
|
|
3330
3566
|
};
|
|
@@ -3424,6 +3660,7 @@ var MagnifyChannel = class {
|
|
|
3424
3660
|
case "events":
|
|
3425
3661
|
for (let socket of this.webSockets) {
|
|
3426
3662
|
for (let instance of socket.instances) {
|
|
3663
|
+
if (!canSee(instance.accessKey, obj.obj?.kind, obj.obj?.metadata?.namespace)) continue;
|
|
3427
3664
|
let magnifyMessage = {
|
|
3428
3665
|
msgtype: "magnifymessageresponse",
|
|
3429
3666
|
id: "1",
|
|
@@ -3432,9 +3669,9 @@ var MagnifyChannel = class {
|
|
|
3432
3669
|
group: "",
|
|
3433
3670
|
pod: "",
|
|
3434
3671
|
container: "",
|
|
3435
|
-
action:
|
|
3436
|
-
flow:
|
|
3437
|
-
type:
|
|
3672
|
+
action: import_kwirth_common2.EInstanceMessageAction.COMMAND,
|
|
3673
|
+
flow: import_kwirth_common2.EInstanceMessageFlow.UNSOLICITED,
|
|
3674
|
+
type: import_kwirth_common2.EInstanceMessageType.DATA,
|
|
3438
3675
|
channel: "magnify",
|
|
3439
3676
|
instance: instance.instanceId,
|
|
3440
3677
|
event: obj.type,
|
|
@@ -3471,8 +3708,8 @@ var MagnifyChannel = class {
|
|
|
3471
3708
|
async executeCommand(webSocket, instance, magnifyMessage) {
|
|
3472
3709
|
let execResponse = {
|
|
3473
3710
|
action: magnifyMessage.action,
|
|
3474
|
-
flow:
|
|
3475
|
-
type:
|
|
3711
|
+
flow: import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3712
|
+
type: import_kwirth_common2.EInstanceMessageType.SIGNAL,
|
|
3476
3713
|
channel: magnifyMessage.channel,
|
|
3477
3714
|
instance: magnifyMessage.instance,
|
|
3478
3715
|
command: magnifyMessage.command,
|
|
@@ -3488,6 +3725,18 @@ var MagnifyChannel = class {
|
|
|
3488
3725
|
execResponse.data = "No command received in data";
|
|
3489
3726
|
return execResponse;
|
|
3490
3727
|
}
|
|
3728
|
+
if (MUTATING_COMMANDS.has(magnifyMessage.command) && !allows(instance.accessKey, "magnify$write" /* WRITE */)) {
|
|
3729
|
+
this.log.warning(`Denied '${magnifyMessage.command}' to key ${instance.accessKey?.id}: '${"magnify$write" /* WRITE */}' required`);
|
|
3730
|
+
this.sendSignalMessage(
|
|
3731
|
+
webSocket,
|
|
3732
|
+
magnifyMessage.action,
|
|
3733
|
+
import_kwirth_common2.EInstanceMessageFlow.RESPONSE,
|
|
3734
|
+
import_kwirth_common2.ESignalMessageLevel.ERROR,
|
|
3735
|
+
instance.instanceId,
|
|
3736
|
+
`You don't have permission to change the cluster from Magnify \u2014 that requires the '${"magnify$write" /* WRITE */}' scope.`
|
|
3737
|
+
);
|
|
3738
|
+
return void 0;
|
|
3739
|
+
}
|
|
3491
3740
|
switch (magnifyMessage.command) {
|
|
3492
3741
|
case "list" /* LIST */: {
|
|
3493
3742
|
this.log.info(`Get LIST`);
|
|
@@ -3513,14 +3762,14 @@ var MagnifyChannel = class {
|
|
|
3513
3762
|
switch (magnifyMessage.params[0]) {
|
|
3514
3763
|
case "evict":
|
|
3515
3764
|
await (0, import_kwirth_common_back.podEvict)(this.clusterInfo.coreApi, magnifyMessage.params[1], magnifyMessage.params[2]);
|
|
3516
|
-
this.sendSignalMessage(webSocket,
|
|
3765
|
+
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
3766
|
return;
|
|
3518
3767
|
case "work":
|
|
3519
3768
|
let podName = await (0, import_kwirth_common_back.podWork)(this.clusterInfo.coreApi, magnifyMessage.params[1]);
|
|
3520
3769
|
this.sendDataMessage(webSocket, instance, "1", "Pod" /* POD */, JSON.stringify(["work", podName]));
|
|
3521
3770
|
return;
|
|
3522
3771
|
default:
|
|
3523
|
-
this.sendSignalMessage(webSocket,
|
|
3772
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid POD command");
|
|
3524
3773
|
console.error("Invalid POD command");
|
|
3525
3774
|
return;
|
|
3526
3775
|
}
|
|
@@ -3528,10 +3777,10 @@ var MagnifyChannel = class {
|
|
|
3528
3777
|
switch (magnifyMessage.params[0]) {
|
|
3529
3778
|
case "default":
|
|
3530
3779
|
await (0, import_kwirth_common_back.setIngressClassAsDefault)(this.clusterInfo.networkApi, magnifyMessage.params[1]);
|
|
3531
|
-
this.sendSignalMessage(webSocket,
|
|
3780
|
+
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
3781
|
return;
|
|
3533
3782
|
default:
|
|
3534
|
-
this.sendSignalMessage(webSocket,
|
|
3783
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid IngressClass command");
|
|
3535
3784
|
console.error("Invalid IngressClass command");
|
|
3536
3785
|
return;
|
|
3537
3786
|
}
|
|
@@ -3547,7 +3796,7 @@ var MagnifyChannel = class {
|
|
|
3547
3796
|
});
|
|
3548
3797
|
return;
|
|
3549
3798
|
default:
|
|
3550
|
-
this.sendSignalMessage(webSocket,
|
|
3799
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid Image command");
|
|
3551
3800
|
console.error("Invalid Image command");
|
|
3552
3801
|
return;
|
|
3553
3802
|
}
|
|
@@ -3566,7 +3815,7 @@ var MagnifyChannel = class {
|
|
|
3566
3815
|
await (0, import_kwirth_common_back.nodeDrain)(this.clusterInfo.coreApi, magnifyMessage.params[1]);
|
|
3567
3816
|
break;
|
|
3568
3817
|
default:
|
|
3569
|
-
this.sendSignalMessage(webSocket,
|
|
3818
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid node command");
|
|
3570
3819
|
console.error("Invalid node command");
|
|
3571
3820
|
return;
|
|
3572
3821
|
}
|
|
@@ -3611,7 +3860,7 @@ var MagnifyChannel = class {
|
|
|
3611
3860
|
(0, import_kwirth_common_back.scaleController)(magnifyMessage.params[1], magnifyMessage.params[2], magnifyMessage.params[3], +magnifyMessage.params[4], this.clusterInfo);
|
|
3612
3861
|
break;
|
|
3613
3862
|
default:
|
|
3614
|
-
this.sendSignalMessage(webSocket,
|
|
3863
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid controller command");
|
|
3615
3864
|
console.error("Invalid node command");
|
|
3616
3865
|
return;
|
|
3617
3866
|
}
|
|
@@ -3630,7 +3879,7 @@ var MagnifyChannel = class {
|
|
|
3630
3879
|
await (0, import_kwirth_common_back.cronJobStatus)(magnifyMessage.params[1], magnifyMessage.params[2], false, this.clusterInfo.batchApi);
|
|
3631
3880
|
break;
|
|
3632
3881
|
default:
|
|
3633
|
-
this.sendSignalMessage(webSocket,
|
|
3882
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid cronjon command");
|
|
3634
3883
|
console.error("Invalid node command");
|
|
3635
3884
|
return;
|
|
3636
3885
|
}
|
|
@@ -3700,7 +3949,7 @@ var MagnifyChannel = class {
|
|
|
3700
3949
|
}
|
|
3701
3950
|
default:
|
|
3702
3951
|
let text = `Invalid command '${magnifyMessage.command}'. Valid commands are: ${Object.keys(EMagnifyCommand)}`;
|
|
3703
|
-
this.sendSignalMessage(webSocket,
|
|
3952
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, text);
|
|
3704
3953
|
break;
|
|
3705
3954
|
}
|
|
3706
3955
|
return execResponse;
|
|
@@ -3712,6 +3961,10 @@ var MagnifyChannel = class {
|
|
|
3712
3961
|
}
|
|
3713
3962
|
async executeList(webSocket, instance, magnifyMessage) {
|
|
3714
3963
|
for (let param of magnifyMessage.params) {
|
|
3964
|
+
if (!canSeeAnyOf(instance.accessKey, param)) {
|
|
3965
|
+
this.log.info(`Not listing '${param}' for key ${instance.accessKey?.id}: not granted`);
|
|
3966
|
+
continue;
|
|
3967
|
+
}
|
|
3715
3968
|
switch (param) {
|
|
3716
3969
|
case "ComponentStatus":
|
|
3717
3970
|
(0, import_kwirth_common_back.throttleExcute)(param, async () => {
|
|
@@ -3933,7 +4186,7 @@ var MagnifyChannel = class {
|
|
|
3933
4186
|
break;
|
|
3934
4187
|
default:
|
|
3935
4188
|
this.log.warning("Invalid class received: " + param);
|
|
3936
|
-
this.sendSignalMessage(webSocket,
|
|
4189
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, "Invalid class: " + param);
|
|
3937
4190
|
break;
|
|
3938
4191
|
}
|
|
3939
4192
|
}
|
|
@@ -3951,7 +4204,7 @@ var MagnifyChannel = class {
|
|
|
3951
4204
|
});
|
|
3952
4205
|
} catch (err) {
|
|
3953
4206
|
this.log.info(err);
|
|
3954
|
-
this.sendSignalMessage(webSocket,
|
|
4207
|
+
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
4208
|
}
|
|
3956
4209
|
}
|
|
3957
4210
|
async executeDelete(webSocket, instance, params) {
|
|
@@ -3961,7 +4214,7 @@ var MagnifyChannel = class {
|
|
|
3961
4214
|
await this.clusterInfo.objectsApi.delete(yaml.load(obj));
|
|
3962
4215
|
} catch (err) {
|
|
3963
4216
|
this.log.info(err);
|
|
3964
|
-
this.sendSignalMessage(webSocket,
|
|
4217
|
+
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
4218
|
}
|
|
3966
4219
|
}
|
|
3967
4220
|
} catch (err) {
|
|
@@ -3975,7 +4228,7 @@ var MagnifyChannel = class {
|
|
|
3975
4228
|
try {
|
|
3976
4229
|
this.clusterInfo.objectsApi.create(yaml.load(param));
|
|
3977
4230
|
} catch (err) {
|
|
3978
|
-
this.sendSignalMessage(webSocket,
|
|
4231
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err));
|
|
3979
4232
|
}
|
|
3980
4233
|
}
|
|
3981
4234
|
} catch (err) {
|
|
@@ -3989,9 +4242,9 @@ var MagnifyChannel = class {
|
|
|
3989
4242
|
try {
|
|
3990
4243
|
const res = yaml.load(param);
|
|
3991
4244
|
let result = await (0, import_kwirth_common_back.applyResource)(res, this.clusterInfo);
|
|
3992
|
-
this.sendSignalMessage(webSocket,
|
|
4245
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.INFO, instance.instanceId, result);
|
|
3993
4246
|
} catch (err) {
|
|
3994
|
-
this.sendSignalMessage(webSocket,
|
|
4247
|
+
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err));
|
|
3995
4248
|
}
|
|
3996
4249
|
}
|
|
3997
4250
|
} catch (err) {
|