@kvbox/server 0.6.20 → 0.6.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kvbox-server.js +138 -21
- package/dist/kvbox-server.js.map +1 -1
- package/package.json +1 -1
- package/scripts/net-setup.sh +99 -4
package/dist/kvbox-server.js
CHANGED
|
@@ -735,6 +735,22 @@ async function openFarLink(link4, cfg) {
|
|
|
735
735
|
async function closeFarLink(link4, cfg) {
|
|
736
736
|
await netRun(cfg, ["farlink", "rm", link4.box, link4.fromIp, link4.standIn, String(link4.port)]);
|
|
737
737
|
}
|
|
738
|
+
function carriesClusters() {
|
|
739
|
+
try {
|
|
740
|
+
return readFileSync(netSetupScript(), "utf8").includes("cluster add");
|
|
741
|
+
} catch {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
async function joinCluster(member, cfg) {
|
|
746
|
+
await netRun(cfg, ["cluster", "add", member.box, member.ip, member.cluster]).catch((err) => {
|
|
747
|
+
if (!err.message.includes("usage:")) throw err;
|
|
748
|
+
throw new KvboxError("this host's network setup is from before clusters; its operator finishes the update by running install-server.sh on it (the root step)");
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
async function leaveCluster(member, cfg) {
|
|
752
|
+
await netRun(cfg, ["cluster", "rm", member.box, member.ip]);
|
|
753
|
+
}
|
|
738
754
|
async function closeProxy(proxy, cfg) {
|
|
739
755
|
await netRun(cfg, ["proxy", "rm", ...proxyArgs(proxy)]);
|
|
740
756
|
}
|
|
@@ -1111,6 +1127,9 @@ var firecrackerDriver = {
|
|
|
1111
1127
|
farListenHost: (cfg) => cfg.gateway,
|
|
1112
1128
|
openFarLink,
|
|
1113
1129
|
closeFarLink,
|
|
1130
|
+
carriesClusters,
|
|
1131
|
+
joinCluster,
|
|
1132
|
+
leaveCluster,
|
|
1114
1133
|
relay: netSetup,
|
|
1115
1134
|
setupScript: netSetupScript
|
|
1116
1135
|
},
|
|
@@ -1410,7 +1429,13 @@ var MachineMetaSchema = z3.object({
|
|
|
1410
1429
|
* for one each time it needs it (core/machines/integrations.ts) and is answered only for a name in this
|
|
1411
1430
|
* list. Plain strings, so a name a newer server wrote still reads. Absent: none.
|
|
1412
1431
|
*/
|
|
1413
|
-
integrations: z3.array(z3.string()).optional()
|
|
1432
|
+
integrations: z3.array(z3.string()).optional(),
|
|
1433
|
+
/**
|
|
1434
|
+
* The cluster the box is a part of (kvbox k8s, #215), given at create by the control plane and never
|
|
1435
|
+
* changed: while it runs, it and the other boxes of its owner with the same id reach each other on any
|
|
1436
|
+
* port (core/machines/cluster.ts). A fork or a box from a snapshot never has it. Absent: none.
|
|
1437
|
+
*/
|
|
1438
|
+
cluster: z3.string().optional()
|
|
1414
1439
|
});
|
|
1415
1440
|
var VolumeMetaSchema = z3.object({
|
|
1416
1441
|
/** Host-unique like a box id (#91): the ledger's key, so a name removed and made again is two volumes. */
|
|
@@ -2478,6 +2503,7 @@ var HostEnvRequest = z6.object({
|
|
|
2478
2503
|
vars: z6.array(z6.object({ name: z6.string(), value: z6.string() }))
|
|
2479
2504
|
});
|
|
2480
2505
|
var HostEnvVersionsSchema = z6.array(z6.object({ owner: z6.string(), version: z6.number().int() }));
|
|
2506
|
+
var CLUSTER_ID_RE = /^[a-z0-9][a-z0-9_-]{0,39}$/;
|
|
2481
2507
|
var CreateMachineRequest = z6.object({
|
|
2482
2508
|
name: z6.string().optional(),
|
|
2483
2509
|
/** Ignored over the local socket (the caller is the host owner); the control plane sets it over HTTPS. */
|
|
@@ -2521,7 +2547,13 @@ var CreateMachineRequest = z6.object({
|
|
|
2521
2547
|
* The integrations turned on for the box (#205, `kvbox new --integration github`). Absent: none, or with
|
|
2522
2548
|
* `from` / `fromBackup` the list the snapshot or the backup was taken with.
|
|
2523
2549
|
*/
|
|
2524
|
-
integrations: IntegrationListSchema.optional()
|
|
2550
|
+
integrations: IntegrationListSchema.optional(),
|
|
2551
|
+
/**
|
|
2552
|
+
* The cluster the box is a part of (kvbox k8s, #215): on its host, the boxes of one owner with the same id
|
|
2553
|
+
* reach each other on any port. An id the control plane makes, never a user's: the control plane refuses
|
|
2554
|
+
* it from anyone it did not make it for, and a host takes it only from a control plane.
|
|
2555
|
+
*/
|
|
2556
|
+
cluster: z6.string().regex(CLUSTER_ID_RE).optional()
|
|
2525
2557
|
});
|
|
2526
2558
|
var HostFromBackupRequest = CreateMachineRequest.omit({ from: true, fromBackup: true, image: true, env: true }).extend({ backup: HostRestoreRequest });
|
|
2527
2559
|
var ForkMachineRequest = z6.object({
|
|
@@ -2618,6 +2650,8 @@ var CapacitySchema = z6.object({
|
|
|
2618
2650
|
integrations: z6.boolean().optional(),
|
|
2619
2651
|
/** True on a kvbox-server that carries a link to a box on another host (#207); the control plane links across hosts only between two such. */
|
|
2620
2652
|
farLinks: z6.boolean().optional(),
|
|
2653
|
+
/** True on a host whose network puts the boxes of one cluster in reach of each other (#215); the control plane places a cluster's box only on such a host. */
|
|
2654
|
+
clusters: z6.boolean().optional(),
|
|
2621
2655
|
/** The integrations this kvbox-server knows (`hostKnowsIntegrations`). Absent with `integrations`: the first one's, `github` alone. */
|
|
2622
2656
|
integrationIds: z6.array(z6.string()).optional()
|
|
2623
2657
|
});
|
|
@@ -3768,6 +3802,8 @@ async function capacity(p = paths()) {
|
|
|
3768
3802
|
// A link to a box on another host is carried here (#207): the control plane links across hosts only between two such.
|
|
3769
3803
|
// Only once the host's privileged network script knows them: an update without its root step does not.
|
|
3770
3804
|
farLinks: driver().net.carriesFarLinks(),
|
|
3805
|
+
// The boxes of a cluster reach each other here (#215), on the same condition: the control plane places a cluster's box only on such a host.
|
|
3806
|
+
clusters: driver().net.carriesClusters(),
|
|
3771
3807
|
// A box's integrations are kept here (#205): the control plane sends a list only to such a host.
|
|
3772
3808
|
integrations: true,
|
|
3773
3809
|
// ...and which (the control plane places a box with `claude` only on a host that names it).
|
|
@@ -4089,7 +4125,7 @@ import { setTimeout as sleep3 } from "node:timers/promises";
|
|
|
4089
4125
|
// src/core/agent.ts
|
|
4090
4126
|
import { connect } from "node:net";
|
|
4091
4127
|
var AGENT_PORT = 52;
|
|
4092
|
-
async function agentCall(udsPath, req, timeoutMs = 5e3) {
|
|
4128
|
+
async function agentCall(udsPath, req, timeoutMs = 5e3, connectMs = timeoutMs) {
|
|
4093
4129
|
const reply = await new Promise((resolve3, reject) => {
|
|
4094
4130
|
const sock = connect(udsPath);
|
|
4095
4131
|
let buf = "";
|
|
@@ -4098,7 +4134,7 @@ async function agentCall(udsPath, req, timeoutMs = 5e3) {
|
|
|
4098
4134
|
sock.destroy();
|
|
4099
4135
|
reject(err);
|
|
4100
4136
|
};
|
|
4101
|
-
sock.setTimeout(
|
|
4137
|
+
sock.setTimeout(connectMs, () => fail(new KvboxError(handshaken ? `kvbox-agent did not answer within ${timeoutMs} ms` : `the guest did not accept the vsock connection within ${connectMs} ms`)));
|
|
4102
4138
|
sock.once("error", (err) => fail(new KvboxError(`kvbox-agent unreachable: ${err.message}`)));
|
|
4103
4139
|
sock.once("connect", () => sock.write(`CONNECT ${AGENT_PORT}
|
|
4104
4140
|
`));
|
|
@@ -4111,6 +4147,7 @@ async function agentCall(udsPath, req, timeoutMs = 5e3) {
|
|
|
4111
4147
|
if (!handshaken) {
|
|
4112
4148
|
if (!line.startsWith("OK ")) return fail(new KvboxError(`vsock connect refused: ${line}`));
|
|
4113
4149
|
handshaken = true;
|
|
4150
|
+
sock.setTimeout(timeoutMs);
|
|
4114
4151
|
sock.write(JSON.stringify(req) + "\n");
|
|
4115
4152
|
} else {
|
|
4116
4153
|
sock.end();
|
|
@@ -4181,6 +4218,19 @@ async function runOutput(udsPath, id, stream, offset, limit, timeoutMs = 15e3) {
|
|
|
4181
4218
|
if (typeof size2 !== "number" || !Number.isInteger(size2) || size2 < 0 || typeof data !== "string") throw new KvboxError("kvbox-agent sent run output this server does not understand");
|
|
4182
4219
|
return { size: size2, offset, data };
|
|
4183
4220
|
}
|
|
4221
|
+
var FREEZE_BASE = "v0.19.0";
|
|
4222
|
+
var FREEZE_TIMEOUT_MS = 2e4;
|
|
4223
|
+
var FREEZE_CONNECT_MS = 3e3;
|
|
4224
|
+
var isAgentRefusal = (err) => /^kvbox-agent: /.test(err.message ?? "");
|
|
4225
|
+
async function freezeDisks(udsPath, disks, thawAfterSec, timeoutMs = FREEZE_TIMEOUT_MS) {
|
|
4226
|
+
const reply = await agentCall(udsPath, { op: "freeze", box: disks.box === true, volumes: [...disks.volumes ?? []], thawAfterSec }, timeoutMs, FREEZE_CONNECT_MS);
|
|
4227
|
+
const frozen = reply["frozen"];
|
|
4228
|
+
return Array.isArray(frozen) ? frozen.filter((m) => typeof m === "string") : [];
|
|
4229
|
+
}
|
|
4230
|
+
async function thawDisks(udsPath, timeoutMs) {
|
|
4231
|
+
const thawed = (await agentCall(udsPath, { op: "thaw" }, timeoutMs))["thawed"];
|
|
4232
|
+
return Array.isArray(thawed) ? thawed.filter((m) => typeof m === "string") : [];
|
|
4233
|
+
}
|
|
4184
4234
|
var isUnknownOp = (err) => /unknown op/.test(err.message ?? "");
|
|
4185
4235
|
var isGuestBooting = (err) => /did not accept the vsock connection/.test(err.message ?? "");
|
|
4186
4236
|
var isNoAgent = (err) => /vsock connect refused|vsock connection closed before the guest accepted|did not accept the vsock connection|kvbox-agent unreachable: connect (ENOENT|ECONNREFUSED)/.test(err.message ?? "");
|
|
@@ -4765,6 +4815,42 @@ function pickSshPort(taken) {
|
|
|
4765
4815
|
throw new KvboxError(`no free port left between ${SSH_PORT_MIN} and ${SSH_PORT_MAX} on this host`);
|
|
4766
4816
|
}
|
|
4767
4817
|
|
|
4818
|
+
// src/core/machines/cluster.ts
|
|
4819
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
4820
|
+
var clusterKey = (owner, cluster) => createHash3("sha256").update(`${owner}
|
|
4821
|
+
${cluster}`).digest("hex").slice(0, 16);
|
|
4822
|
+
function requestedCluster(req, owner, fromBackup = false) {
|
|
4823
|
+
if (req.cluster === void 0) return void 0;
|
|
4824
|
+
if (!isCloudBox(owner)) throw new KvboxError("a box is put in a cluster by a control plane; this host's own boxes have none");
|
|
4825
|
+
if (req.from !== void 0 || fromBackup) throw new KvboxError("a box of a cluster is made from its image, never from a snapshot or a backup");
|
|
4826
|
+
if (!driver().net.carriesClusters()) {
|
|
4827
|
+
throw new KvboxError("this host's network setup is from before clusters; its operator finishes the update by running install-server.sh on it (the root step)");
|
|
4828
|
+
}
|
|
4829
|
+
return req.cluster;
|
|
4830
|
+
}
|
|
4831
|
+
async function joinCluster2(meta, cfg) {
|
|
4832
|
+
if (meta.cluster === void 0 || meta.owner === void 0) return;
|
|
4833
|
+
await driver().net.joinCluster({ box: meta.id, ip: meta.ip, cluster: clusterKey(meta.owner, meta.cluster) }, cfg);
|
|
4834
|
+
}
|
|
4835
|
+
async function leaveCluster2(meta, cfg) {
|
|
4836
|
+
await leftCluster(meta, cfg).catch((err) => log.warn(`could not take box ${meta.id} out of its cluster: ${err.message}`));
|
|
4837
|
+
}
|
|
4838
|
+
async function leftCluster(meta, cfg) {
|
|
4839
|
+
if (meta.cluster === void 0) return;
|
|
4840
|
+
await driver().net.leaveCluster({ box: meta.id, ip: meta.ip }, cfg);
|
|
4841
|
+
}
|
|
4842
|
+
async function rejoinClusters(p = paths()) {
|
|
4843
|
+
const cfg = await loadConfig(p);
|
|
4844
|
+
for (const listed of await readAllMeta(p)) {
|
|
4845
|
+
if (!vmAlive(listed) || listed.cluster === void 0) continue;
|
|
4846
|
+
await withBoxLock(listed, async () => {
|
|
4847
|
+
const meta = await readMachineMeta(listed, p).catch(() => null);
|
|
4848
|
+
if (meta === null || !vmAlive(meta)) return;
|
|
4849
|
+
await joinCluster2(meta, cfg).catch((err) => log.warn(`box ${meta.name} is cut off from its cluster: ${err.message}`));
|
|
4850
|
+
});
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4768
4854
|
// src/core/farTunnel.ts
|
|
4769
4855
|
import { createServer as createServer2 } from "node:net";
|
|
4770
4856
|
import { connect as tlsConnect } from "node:tls";
|
|
@@ -5106,6 +5192,7 @@ async function openPorts(meta, cfg, p) {
|
|
|
5106
5192
|
}
|
|
5107
5193
|
const far = reaching(meta);
|
|
5108
5194
|
if (far) await openFarTargets(far, cfg, p);
|
|
5195
|
+
await joinCluster2(meta, cfg);
|
|
5109
5196
|
}
|
|
5110
5197
|
async function closePorts(meta, cfg) {
|
|
5111
5198
|
for (const proxy of boxProxies(meta)) {
|
|
@@ -5116,6 +5203,7 @@ async function closePorts(meta, cfg) {
|
|
|
5116
5203
|
}
|
|
5117
5204
|
const far = reaching(meta);
|
|
5118
5205
|
if (far) await closeFarTargets(far, cfg);
|
|
5206
|
+
await leaveCluster2(meta, cfg);
|
|
5119
5207
|
}
|
|
5120
5208
|
var reservedPorts = /* @__PURE__ */ new Set();
|
|
5121
5209
|
async function drawPorts(count, p) {
|
|
@@ -5272,7 +5360,7 @@ async function bootInto(box, prepare, origin, cfg, p) {
|
|
|
5272
5360
|
const spec = { ...box, sshPort };
|
|
5273
5361
|
const bootedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5274
5362
|
pid = await launch(spec, tap, cfg, keysB64, p);
|
|
5275
|
-
await openPorts(spec, cfg, p);
|
|
5363
|
+
await openPorts({ ...spec, cluster: origin.cluster }, cfg, p);
|
|
5276
5364
|
void pushEnvAfterBoot(spec, pid, m.vsock, p);
|
|
5277
5365
|
const meta = { ...spec, pid, bootId: currentBootId(), bootedAt, createdAt: (/* @__PURE__ */ new Date()).toISOString(), ...origin };
|
|
5278
5366
|
await writeMachineMeta(meta, p);
|
|
@@ -5282,7 +5370,7 @@ async function bootInto(box, prepare, origin, cfg, p) {
|
|
|
5282
5370
|
} catch (err) {
|
|
5283
5371
|
if (pid !== void 0) killQuietly(pid);
|
|
5284
5372
|
await stopListeningForGuest(box, p);
|
|
5285
|
-
await closePorts({ id, ip, sshPort }, cfg);
|
|
5373
|
+
await closePorts({ id, ip, sshPort, cluster: origin.cluster }, cfg);
|
|
5286
5374
|
if (tapCreated) await driver().net.remove(id, cfg).catch(() => void 0);
|
|
5287
5375
|
await rm6(m.dir, { recursive: true, force: true });
|
|
5288
5376
|
boxListChanged();
|
|
@@ -5342,7 +5430,7 @@ async function restoreInto(box, prepare, origin, cfg, p, keysOrFail) {
|
|
|
5342
5430
|
import { rm as rm7 } from "node:fs/promises";
|
|
5343
5431
|
|
|
5344
5432
|
// src/core/machines/links.ts
|
|
5345
|
-
import { createHash as
|
|
5433
|
+
import { createHash as createHash4, timingSafeEqual } from "node:crypto";
|
|
5346
5434
|
function linkSource(req, caller, target) {
|
|
5347
5435
|
if (req.fromOwner !== void 0) return { owner: ownerFor(req.fromOwner, caller), name: req.from, display: `${req.fromOwner}/${req.from}` };
|
|
5348
5436
|
const ref = parseRef(req.from, caller);
|
|
@@ -5375,7 +5463,7 @@ var addLink = locked(async function addLink2(ref, req, caller, p = paths()) {
|
|
|
5375
5463
|
}
|
|
5376
5464
|
return toMachine(next, p);
|
|
5377
5465
|
});
|
|
5378
|
-
var keyHash = (key) =>
|
|
5466
|
+
var keyHash = (key) => createHash4("sha256").update(key).digest("hex");
|
|
5379
5467
|
async function addFarLink(meta, from, port, key, p) {
|
|
5380
5468
|
if (realmOf(meta.owner) === null || realmOf(from.owner) !== realmOf(meta.owner)) {
|
|
5381
5469
|
throw new KvboxError(`a link from a box on another host joins two boxes of one control plane; box ${shown(from)} and box ${meta.name} are not`);
|
|
@@ -5521,7 +5609,10 @@ var destroyBox = locked(async function destroyBox2(ref, p = paths()) {
|
|
|
5521
5609
|
const meta = await readMeta(ref, p);
|
|
5522
5610
|
const cfg = await loadConfig(p);
|
|
5523
5611
|
await shutdown2(meta, cfg, p, 2e3);
|
|
5524
|
-
await
|
|
5612
|
+
await (async () => {
|
|
5613
|
+
await closeLinksFrom(meta, cfg, p);
|
|
5614
|
+
await leftCluster(meta, cfg);
|
|
5615
|
+
})().catch((err) => {
|
|
5525
5616
|
recordState(meta, "stopped", "stop", p);
|
|
5526
5617
|
throw err;
|
|
5527
5618
|
});
|
|
@@ -5611,7 +5702,10 @@ var replaceDisk = locked(async function replaceDisk2(ref, file, disk, p = paths(
|
|
|
5611
5702
|
var setMachine = locked(async function setMachine2(ref, req, p = paths()) {
|
|
5612
5703
|
const meta = await readMeta(ref, p);
|
|
5613
5704
|
const next = { ...meta };
|
|
5614
|
-
if (req.autoHibernateSec !== void 0)
|
|
5705
|
+
if (req.autoHibernateSec !== void 0) {
|
|
5706
|
+
if (req.autoHibernateSec > 0 && meta.cluster !== void 0) throw new KvboxError(`box ${shown(ref)} is part of a cluster, whose boxes stay up; it cannot hibernate by itself`);
|
|
5707
|
+
next.autoHibernateSec = req.autoHibernateSec || void 0;
|
|
5708
|
+
}
|
|
5615
5709
|
if (req.idleCheck !== void 0) next.idleCheck = req.idleCheck || void 0;
|
|
5616
5710
|
if (req.integrations !== void 0) {
|
|
5617
5711
|
next.integrations = requestedIntegrations(req.integrations);
|
|
@@ -5703,6 +5797,7 @@ async function checkNewBox(req, owner, diskBytes, p = paths()) {
|
|
|
5703
5797
|
}
|
|
5704
5798
|
async function createMachine(req, owner, p = paths(), from) {
|
|
5705
5799
|
const cfg = await loadConfig(p);
|
|
5800
|
+
const cluster = requestedCluster(req, owner, from !== void 0);
|
|
5706
5801
|
if (req.from !== void 0) return restoreMachine(req.from, owner, req, cfg, p);
|
|
5707
5802
|
const size2 = sizeOf(req, cfg.defaultSize, from ? (await stat3(from.disk)).size : void 0);
|
|
5708
5803
|
assertAssets(cfg);
|
|
@@ -5719,7 +5814,7 @@ async function createMachine(req, owner, p = paths(), from) {
|
|
|
5719
5814
|
const manifest = await imageManifest(base.file);
|
|
5720
5815
|
const env = from ? null : imageEnv(manifest, name, req.env ?? [], (await readOwnerEnv(owner, p).catch(() => null))?.vars ?? []);
|
|
5721
5816
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5722
|
-
const autoHibernateSec = autoHibernateFor(req, cfg, manifest);
|
|
5817
|
+
const autoHibernateSec = cluster === void 0 ? autoHibernateFor(req, cfg, manifest) : void 0;
|
|
5723
5818
|
const vars = env === null ? from?.vars ?? [] : env.vars.map((v) => ({ ...v, secret: env.secrets.includes(v.name), updatedAt: now }));
|
|
5724
5819
|
const machine = await bootInto(
|
|
5725
5820
|
{ id, name, owner, ip, mac, vcpu: size2.vcpu, memMib: size2.memMib, base: base.version, image, sshKeys },
|
|
@@ -5731,7 +5826,7 @@ async function createMachine(req, owner, p = paths(), from) {
|
|
|
5731
5826
|
} else await createOverlay(m.overlay, size2.diskGib);
|
|
5732
5827
|
if (vars.length > 0) await writeBoxEnv({ owner, name }, vars, p);
|
|
5733
5828
|
},
|
|
5734
|
-
{ source: from ? `backup:${from.id}` : "base", autoHibernateSec, idleCheck: manifest.idle, url: maskedUrl(manifest, vars), integrations: requestedIntegrations(req.integrations, { owner, name, base: base.version, image }) },
|
|
5829
|
+
{ source: from ? `backup:${from.id}` : "base", autoHibernateSec, idleCheck: manifest.idle, url: maskedUrl(manifest, vars), integrations: requestedIntegrations(req.integrations, { owner, name, base: base.version, image }), cluster },
|
|
5735
5830
|
cfg,
|
|
5736
5831
|
p
|
|
5737
5832
|
);
|
|
@@ -6407,7 +6502,7 @@ async function stageBackup(ref, req, p = paths()) {
|
|
|
6407
6502
|
const meta2 = await readBox2(ref, p);
|
|
6408
6503
|
const m = p.machine(meta2.owner, meta2.name);
|
|
6409
6504
|
await assertRoom(s.dir, 0, `a backup of box ${shown(ref)}`, p);
|
|
6410
|
-
await frozenClone(meta2, m.overlay, s.disk, p);
|
|
6505
|
+
await frozenClone(meta2, m.overlay, s.disk, { box: true }, p);
|
|
6411
6506
|
const envText2 = existsSync13(m.env) ? await readFile9(m.env, "utf8") : null;
|
|
6412
6507
|
return { meta: meta2, envText: envText2 };
|
|
6413
6508
|
});
|
|
@@ -6429,13 +6524,33 @@ async function stageBackup(ref, req, p = paths()) {
|
|
|
6429
6524
|
throw err;
|
|
6430
6525
|
}
|
|
6431
6526
|
}
|
|
6432
|
-
|
|
6527
|
+
var THAW_AFTER_SEC = 30;
|
|
6528
|
+
async function frozenClone(box, from, to, disks, p) {
|
|
6433
6529
|
if (!vmAlive(box) || box.paused) return driver().disk.clone(from, to);
|
|
6434
|
-
|
|
6530
|
+
const vsock = p.machine(box.owner, box.name).vsock;
|
|
6531
|
+
const freeze = await freezeForCopy(box, vsock, disks);
|
|
6435
6532
|
try {
|
|
6436
|
-
await driver().
|
|
6533
|
+
await driver().vm.pause(box, p);
|
|
6534
|
+
try {
|
|
6535
|
+
await driver().disk.clone(from, to);
|
|
6536
|
+
} finally {
|
|
6537
|
+
await resumeAfterCopy(box, p);
|
|
6538
|
+
}
|
|
6437
6539
|
} finally {
|
|
6438
|
-
await
|
|
6540
|
+
if (freeze !== "none") await thawDisks(vsock, freeze === "unsure" ? FREEZE_TIMEOUT_MS + 5e3 : void 0).catch((err) => log.warn(`box ${shown(box)}: thaw after a backup's copy failed (${err.message}); its guest thaws by itself within ${THAW_AFTER_SEC} s`));
|
|
6541
|
+
}
|
|
6542
|
+
}
|
|
6543
|
+
async function freezeForCopy(box, vsock, disks) {
|
|
6544
|
+
try {
|
|
6545
|
+
return (await freezeDisks(vsock, disks, THAW_AFTER_SEC)).length > 0 ? "frozen" : "none";
|
|
6546
|
+
} catch (err) {
|
|
6547
|
+
if (isUnknownOp(err)) {
|
|
6548
|
+
log.debug(`box ${shown(box)}: its image is from before base ${FREEZE_BASE}, which cannot freeze a disk; copied as it is`);
|
|
6549
|
+
return "none";
|
|
6550
|
+
}
|
|
6551
|
+
if (isNoAgent(err)) return "none";
|
|
6552
|
+
log.warn(`box ${shown(box)}: its disk was not frozen for a backup's copy (${err.message}); copied as it is`);
|
|
6553
|
+
return isAgentRefusal(err) ? "none" : "unsure";
|
|
6439
6554
|
}
|
|
6440
6555
|
}
|
|
6441
6556
|
async function stageVolumeBackup(ref, req, p = paths()) {
|
|
@@ -6460,7 +6575,7 @@ async function stageVolumeBackup(ref, req, p = paths()) {
|
|
|
6460
6575
|
await withBoxLock(box, async () => {
|
|
6461
6576
|
const meta = await readBox2(box, p);
|
|
6462
6577
|
if (!meta.volumes?.includes(ref.name)) throw new KvboxError(`volume ${shown(ref)} was just detached from box ${holder}; try again`);
|
|
6463
|
-
await frozenClone(meta, from, s.disk, p);
|
|
6578
|
+
await frozenClone(meta, from, s.disk, { volumes: [ref.name] }, p);
|
|
6464
6579
|
});
|
|
6465
6580
|
}
|
|
6466
6581
|
const { sizeBytes, chunks } = await chunkNames(s.disk, keys);
|
|
@@ -6631,6 +6746,7 @@ async function restoreOnce(ref, req, p) {
|
|
|
6631
6746
|
async function createFromBackup(req, owner, p = paths()) {
|
|
6632
6747
|
const { backup, ...create } = req;
|
|
6633
6748
|
checkId(backup.id);
|
|
6749
|
+
requestedCluster(create, owner, true);
|
|
6634
6750
|
const base = await baseFor(backup, p);
|
|
6635
6751
|
await checkNewBox(create, owner, backup.sizeBytes, p);
|
|
6636
6752
|
const keys = backupKeys(backup.key);
|
|
@@ -7775,10 +7891,10 @@ function versionOf(srcFileUrl, injected) {
|
|
|
7775
7891
|
}
|
|
7776
7892
|
|
|
7777
7893
|
// src/version.ts
|
|
7778
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
7894
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.22" : void 0);
|
|
7779
7895
|
|
|
7780
7896
|
// src/caller.ts
|
|
7781
|
-
import { createHash as
|
|
7897
|
+
import { createHash as createHash5, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
7782
7898
|
var OWNER_HEADER = "x-kvbox-owner";
|
|
7783
7899
|
function resolveCaller(opts = {}) {
|
|
7784
7900
|
const cp = opts.controlPlane;
|
|
@@ -7832,7 +7948,7 @@ function bearerCheck(token) {
|
|
|
7832
7948
|
};
|
|
7833
7949
|
}
|
|
7834
7950
|
function digest(secret) {
|
|
7835
|
-
return
|
|
7951
|
+
return createHash5("sha256").update(secret).digest();
|
|
7836
7952
|
}
|
|
7837
7953
|
|
|
7838
7954
|
// src/core/update.ts
|
|
@@ -8780,6 +8896,7 @@ var startCommand = new Command("start").description("run the daemon in the foreg
|
|
|
8780
8896
|
const state = await driver().net.prepare(cfg);
|
|
8781
8897
|
log.info(`host network: bridge ${cfg.bridge} ${state}`);
|
|
8782
8898
|
await pinRunningTaps(paths());
|
|
8899
|
+
await rejoinClusters(paths()).catch((err) => log.warn(`running boxes may be cut off from their clusters: ${err.message}`));
|
|
8783
8900
|
await reopenFarTargets(paths()).catch((err) => log.warn(`running boxes cannot reach the boxes they are linked to on other hosts: ${err.message}`));
|
|
8784
8901
|
} catch (err) {
|
|
8785
8902
|
log.warn(`host network not ready (${err.message}); run: kvbox-server net up`);
|