@kwirthmagnify/kwirth-plugin-magnify 0.2.0 → 0.3.1
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 +8 -4
- package/back.js +102 -34
- package/front.js +66 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,12 +40,16 @@ Since **0.2.0** Magnify checks who is asking. It declares three scopes, each gra
|
|
|
40
40
|
|
|
41
41
|
- **`magnify$user`** — open it and see the cluster's health: its metrics and its events. It does **not**
|
|
42
42
|
list resources.
|
|
43
|
-
- **`magnify$read`** — also see
|
|
43
|
+
- **`magnify$read`** — also see the **workloads and configuration**, with their contents. It can be
|
|
44
44
|
narrowed from the security editor to **hide kinds** — typically ConfigMap and Secret.
|
|
45
|
-
- **`magnify$write`** — also change
|
|
45
|
+
- **`magnify$write`** — also change those: apply, delete, evict, scale, restart.
|
|
46
46
|
|
|
47
|
-
`cluster` and `admin` sit above all three
|
|
48
|
-
|
|
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.
|
|
49
53
|
|
|
50
54
|
> ⚠️ **Before 0.2.0 it checked nothing**: any key that reached the channel saw the whole cluster. If
|
|
51
55
|
> somebody loses access after upgrading, that is why — grant them `magnify$user` or above.
|
package/back.js
CHANGED
|
@@ -3151,7 +3151,7 @@ var MAGNIFY_SCOPES = [
|
|
|
3151
3151
|
{
|
|
3152
3152
|
scope: "magnify$read" /* READ */,
|
|
3153
3153
|
label: "Magnify \xB7 Read",
|
|
3154
|
-
description: "Also see
|
|
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
3155
|
/*
|
|
3156
3156
|
Narrowing READ by KIND, because that is what Magnify knows how to describe and the core does
|
|
3157
3157
|
not. 'Everything except ConfigMaps and Secrets' is the case this exists for: the two kinds
|
|
@@ -3171,7 +3171,7 @@ var MAGNIFY_SCOPES = [
|
|
|
3171
3171
|
{
|
|
3172
3172
|
scope: "magnify$write" /* WRITE */,
|
|
3173
3173
|
label: "Magnify \xB7 Write",
|
|
3174
|
-
description: "Also change
|
|
3174
|
+
description: "Also change those workloads: apply, delete, evict, scale and restart. NOT the infrastructure \u2014 draining or cordoning a node needs 'cluster'"
|
|
3175
3175
|
}
|
|
3176
3176
|
];
|
|
3177
3177
|
var MAGNIFY_CLUSTER_SCOPE = "cluster";
|
|
@@ -3244,7 +3244,7 @@ var reaches = (grant, namespace) => {
|
|
|
3244
3244
|
if (!namespace) return false;
|
|
3245
3245
|
return grant.namespaces.some((pattern) => {
|
|
3246
3246
|
try {
|
|
3247
|
-
return new RegExp(
|
|
3247
|
+
return new RegExp(pattern).test(namespace);
|
|
3248
3248
|
} catch (err) {
|
|
3249
3249
|
return false;
|
|
3250
3250
|
}
|
|
@@ -3254,23 +3254,18 @@ var allows = (accessKey, required) => {
|
|
|
3254
3254
|
const requiredLevel = levelOf(required);
|
|
3255
3255
|
return grantsOf(accessKey).some((g) => g.level >= requiredLevel);
|
|
3256
3256
|
};
|
|
3257
|
-
var canSee = (accessKey, kind, namespace) => {
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
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
|
-
};
|
|
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);
|
|
3274
3269
|
var needsFiltering = (accessKey) => grantsOf(accessKey).some((g) => g.namespaces.length > 0 || g.hidden.size > 0);
|
|
3275
3270
|
var filterItems = (accessKey, kind, items) => items.filter((item) => canSee(accessKey, kind, item.metadata?.namespace));
|
|
3276
3271
|
|
|
@@ -3310,6 +3305,11 @@ var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
3310
3305
|
"CronJob" /* CRONJOB */,
|
|
3311
3306
|
"IngressClass" /* INGRESSCLASS */
|
|
3312
3307
|
]);
|
|
3308
|
+
var INFRA_COMMANDS = /* @__PURE__ */ new Set([
|
|
3309
|
+
"Node" /* NODE */,
|
|
3310
|
+
"Image" /* IMAGE */,
|
|
3311
|
+
"IngressClass" /* INGRESSCLASS */
|
|
3312
|
+
]);
|
|
3313
3313
|
var MagnifyChannel = class {
|
|
3314
3314
|
// +++ add dispose/destroy (conterpart of initChannel) to IChannel (and implement in this channel a remove from "events subscription")
|
|
3315
3315
|
constructor(clusterInfo, backChannelObject) {
|
|
@@ -3535,6 +3535,41 @@ var MagnifyChannel = class {
|
|
|
3535
3535
|
return JSON.stringify({ items: [] });
|
|
3536
3536
|
}
|
|
3537
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
|
+
};
|
|
3538
3573
|
this.sendDataMessage = (webSocket, instance, id, command, data) => {
|
|
3539
3574
|
if (command === "list" /* LIST */ && needsFiltering(instance.accessKey)) data = this.filterListPayload(instance.accessKey, data);
|
|
3540
3575
|
let resp = {
|
|
@@ -3725,17 +3760,20 @@ var MagnifyChannel = class {
|
|
|
3725
3760
|
execResponse.data = "No command received in data";
|
|
3726
3761
|
return execResponse;
|
|
3727
3762
|
}
|
|
3728
|
-
if (MUTATING_COMMANDS.has(magnifyMessage.command)
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
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
|
+
}
|
|
3739
3777
|
}
|
|
3740
3778
|
switch (magnifyMessage.command) {
|
|
3741
3779
|
case "list" /* LIST */: {
|
|
@@ -4207,11 +4245,38 @@ var MagnifyChannel = class {
|
|
|
4207
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));
|
|
4208
4246
|
}
|
|
4209
4247
|
}
|
|
4248
|
+
/*
|
|
4249
|
+
The objects to delete, and 'force' appended as the LAST parameter when the delete must not wait.
|
|
4250
|
+
|
|
4251
|
+
At the end and not at the front on purpose: a list with no flag is exactly what it always was —
|
|
4252
|
+
every entry an object— so nothing has to be sent for the normal case and an older front end goes
|
|
4253
|
+
on working unchanged. 'force' is not valid YAML for an object, so it cannot be confused with one.
|
|
4254
|
+
|
|
4255
|
+
It is Kubernetes' `--force`: a grace period of ZERO, which is the only thing that flag does. The
|
|
4256
|
+
object leaves the API immediately instead of being asked to stop first.
|
|
4257
|
+
|
|
4258
|
+
⚠️ On a Pod that means the container may still be running on its node. It is what you want when
|
|
4259
|
+
the node is unreachable and the pod will never confirm it died; it is NOT a faster delete. The
|
|
4260
|
+
dialog that offers it says so, which is why it is offered and never applied by default.
|
|
4261
|
+
*/
|
|
4210
4262
|
async executeDelete(webSocket, instance, params) {
|
|
4263
|
+
const force = params[params.length - 1] === "force";
|
|
4264
|
+
const objects = force ? params.slice(0, -1) : params;
|
|
4265
|
+
this.log.info(`DELETE of ${objects.length} object(s)${force ? " FORCED (gracePeriodSeconds=0)" : ""}`);
|
|
4211
4266
|
try {
|
|
4212
|
-
for (let obj of
|
|
4267
|
+
for (let obj of objects) {
|
|
4213
4268
|
try {
|
|
4214
|
-
|
|
4269
|
+
const res = yaml.load(obj);
|
|
4270
|
+
if (!this.mayChange(webSocket, instance, res, "delete")) continue;
|
|
4271
|
+
await this.clusterInfo.objectsApi.delete(
|
|
4272
|
+
res,
|
|
4273
|
+
void 0,
|
|
4274
|
+
void 0,
|
|
4275
|
+
force ? 0 : void 0,
|
|
4276
|
+
void 0,
|
|
4277
|
+
void 0,
|
|
4278
|
+
force ? { gracePeriodSeconds: 0 } : void 0
|
|
4279
|
+
);
|
|
4215
4280
|
} catch (err) {
|
|
4216
4281
|
this.log.info(err);
|
|
4217
4282
|
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err.body));
|
|
@@ -4226,7 +4291,9 @@ var MagnifyChannel = class {
|
|
|
4226
4291
|
try {
|
|
4227
4292
|
for (let param of params) {
|
|
4228
4293
|
try {
|
|
4229
|
-
|
|
4294
|
+
const res = yaml.load(param);
|
|
4295
|
+
if (!this.mayChange(webSocket, instance, res, "create")) continue;
|
|
4296
|
+
this.clusterInfo.objectsApi.create(res);
|
|
4230
4297
|
} catch (err) {
|
|
4231
4298
|
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.ERROR, instance.instanceId, JSON.stringify(err));
|
|
4232
4299
|
}
|
|
@@ -4241,6 +4308,7 @@ var MagnifyChannel = class {
|
|
|
4241
4308
|
for (let param of params) {
|
|
4242
4309
|
try {
|
|
4243
4310
|
const res = yaml.load(param);
|
|
4311
|
+
if (!this.mayChange(webSocket, instance, res, "apply")) continue;
|
|
4244
4312
|
let result = await (0, import_kwirth_common_back.applyResource)(res, this.clusterInfo);
|
|
4245
4313
|
this.sendSignalMessage(webSocket, import_kwirth_common2.EInstanceMessageAction.COMMAND, import_kwirth_common2.EInstanceMessageFlow.RESPONSE, import_kwirth_common2.ESignalMessageLevel.INFO, instance.instanceId, result);
|
|
4246
4314
|
} catch (err) {
|