@impz/testing 7.10.0 → 7.12.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/dist/index.js +160 -72
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -20136,6 +20136,7 @@ var PassStatusSchema = z34.object({
|
|
|
20136
20136
|
});
|
|
20137
20137
|
var HttpsInfoSchema = z34.object({
|
|
20138
20138
|
domain: z34.string(),
|
|
20139
|
+
apiHost: z34.string().optional(),
|
|
20139
20140
|
dnsToken: PassStatusSchema.nullable()
|
|
20140
20141
|
});
|
|
20141
20142
|
var PublicInfoSchema = z34.object({
|
|
@@ -21564,11 +21565,16 @@ function checkPublicPorts(ports, others, slotPorts) {
|
|
|
21564
21565
|
import { existsSync as existsSync2 } from "fs";
|
|
21565
21566
|
import * as z52 from "zod";
|
|
21566
21567
|
var LETS_ENCRYPT_DIRECTORY = "https://acme-v02.api.letsencrypt.org/directory";
|
|
21567
|
-
|
|
21568
|
+
function buildDomainSchema(setting, example) {
|
|
21569
|
+
return z52.string().transform((value) => value.toLowerCase().replace(/\.$/u, "")).pipe(z52.string().regex(/^(?:[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?\.)+[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/u, `${setting} must be a domain name such as ${example}`));
|
|
21570
|
+
}
|
|
21571
|
+
var DomainSchema = buildDomainSchema("IMP_DOMAIN", "imp.example.com");
|
|
21572
|
+
var ApiHostSchema = buildDomainSchema("IMP_API_HOST", "dash.imp.example.com");
|
|
21568
21573
|
var PortSchema2 = z52.coerce.number().pipe(z52.int().min(1).max(65535));
|
|
21569
21574
|
var DNS_PROVIDERS = ["cloudflare", "challtestsrv"];
|
|
21570
21575
|
var HttpsEnvSchema = z52.object({
|
|
21571
21576
|
IMP_DOMAIN: DomainSchema.optional(),
|
|
21577
|
+
IMP_API_HOST: ApiHostSchema.optional(),
|
|
21572
21578
|
IMP_HTTPS_PORT: PortSchema2.default(443),
|
|
21573
21579
|
IMP_HTTP_PORT: PortSchema2.default(80),
|
|
21574
21580
|
IMP_DNS_PROVIDER: z52.enum(DNS_PROVIDERS).optional(),
|
|
@@ -21588,6 +21594,9 @@ function readHttpsConfig(env) {
|
|
|
21588
21594
|
throw new Error("set IMP_DNS_API_TOKEN or IMP_DNS_API_TOKEN_FILE, not both");
|
|
21589
21595
|
}
|
|
21590
21596
|
if (env.IMP_DOMAIN === undefined) {
|
|
21597
|
+
if (env.IMP_API_HOST !== undefined) {
|
|
21598
|
+
throw new Error("IMP_API_HOST needs IMP_DOMAIN: it is one label below it");
|
|
21599
|
+
}
|
|
21591
21600
|
if (env.IMP_PUBLIC_IP !== undefined) {
|
|
21592
21601
|
throw new Error("IMP_PUBLIC_IP needs IMP_DOMAIN: public imps are served on it");
|
|
21593
21602
|
}
|
|
@@ -21596,6 +21605,9 @@ function readHttpsConfig(env) {
|
|
|
21596
21605
|
if (env.IMP_DNS_PROVIDER === undefined) {
|
|
21597
21606
|
throw new Error(`IMP_DOMAIN needs IMP_DNS_PROVIDER (${DNS_PROVIDERS.join(" or ")}) for its certificate`);
|
|
21598
21607
|
}
|
|
21608
|
+
if (env.IMP_API_HOST !== undefined && !isOneLabelBelow(env.IMP_API_HOST, env.IMP_DOMAIN)) {
|
|
21609
|
+
throw new Error(`IMP_API_HOST ${env.IMP_API_HOST} must be one label below IMP_DOMAIN, such as dash.${env.IMP_DOMAIN}, so the wildcard certificate covers it`);
|
|
21610
|
+
}
|
|
21599
21611
|
const token = findTokenSource(env);
|
|
21600
21612
|
if (env.IMP_DNS_PROVIDER === "cloudflare" && token === null) {
|
|
21601
21613
|
throw new Error("IMP_DNS_PROVIDER=cloudflare needs IMP_DNS_API_TOKEN or IMP_DNS_API_TOKEN_FILE");
|
|
@@ -21614,6 +21626,7 @@ function readHttpsConfig(env) {
|
|
|
21614
21626
|
}
|
|
21615
21627
|
return {
|
|
21616
21628
|
domain: env.IMP_DOMAIN,
|
|
21629
|
+
apiHost: env.IMP_API_HOST ?? env.IMP_DOMAIN,
|
|
21617
21630
|
httpsPort: env.IMP_HTTPS_PORT,
|
|
21618
21631
|
httpPort: env.IMP_HTTP_PORT,
|
|
21619
21632
|
dns: {
|
|
@@ -21631,6 +21644,9 @@ function readHttpsConfig(env) {
|
|
|
21631
21644
|
}
|
|
21632
21645
|
};
|
|
21633
21646
|
}
|
|
21647
|
+
function isOneLabelBelow(host, domain) {
|
|
21648
|
+
return host.endsWith(`.${domain}`) && !host.slice(0, -(domain.length + 1)).includes(".");
|
|
21649
|
+
}
|
|
21634
21650
|
var isUnreachable = buildRangeMatcher([
|
|
21635
21651
|
"10.0.0.0/8",
|
|
21636
21652
|
"100.64.0.0/10",
|
|
@@ -22161,7 +22177,7 @@ import { join as join49 } from "path";
|
|
|
22161
22177
|
// packages/daemon/package.json
|
|
22162
22178
|
var package_default = {
|
|
22163
22179
|
name: "@impz/daemon",
|
|
22164
|
-
version: "7.
|
|
22180
|
+
version: "7.12.0",
|
|
22165
22181
|
private: true,
|
|
22166
22182
|
description: "impd: the imp host daemon",
|
|
22167
22183
|
type: "module",
|
|
@@ -28422,6 +28438,7 @@ async function runRestore(deps, input) {
|
|
|
28422
28438
|
}
|
|
28423
28439
|
for (const imp of chosen) {
|
|
28424
28440
|
const name = input.as ?? imp.name;
|
|
28441
|
+
deps.imps.requireFreeName(name);
|
|
28425
28442
|
if (presentNames.has(name)) {
|
|
28426
28443
|
throw buildConflictError("imp", name, `an imp named ${name} exists; restore it --as another name`);
|
|
28427
28444
|
}
|
|
@@ -29579,6 +29596,31 @@ async function listDrivesInUse(db, findPaths) {
|
|
|
29579
29596
|
return drives;
|
|
29580
29597
|
}
|
|
29581
29598
|
|
|
29599
|
+
// packages/daemon/src/imps/imps/require-free-name.ts
|
|
29600
|
+
function readReservedName(https) {
|
|
29601
|
+
if (https === null || https.apiHost === https.domain) {
|
|
29602
|
+
return null;
|
|
29603
|
+
}
|
|
29604
|
+
return https.apiHost.slice(0, -(https.domain.length + 1));
|
|
29605
|
+
}
|
|
29606
|
+
function requireFreeName(https, name) {
|
|
29607
|
+
const reserved = readReservedName(https);
|
|
29608
|
+
if (reserved === null || https === null || name !== reserved) {
|
|
29609
|
+
return;
|
|
29610
|
+
}
|
|
29611
|
+
throw new ImpdError("BAD_REQUEST", {
|
|
29612
|
+
message: `imp name ${name} is taken: ${https.apiHost} serves impd's API and dashboard (IMP_API_HOST), so an imp named ${name} would share its host`
|
|
29613
|
+
});
|
|
29614
|
+
}
|
|
29615
|
+
async function requireNoImpNamedLikeApiHost(db, https) {
|
|
29616
|
+
const reserved = readReservedName(https);
|
|
29617
|
+
const holder = reserved === null ? undefined : await readImpByName(db, reserved);
|
|
29618
|
+
if (reserved === null || https === null || holder === undefined || holder.moveState === "receiving") {
|
|
29619
|
+
return;
|
|
29620
|
+
}
|
|
29621
|
+
throw new Error(`IMP_API_HOST ${https.apiHost} is the hostname of the imp ${reserved}; destroy that imp, or choose another host`);
|
|
29622
|
+
}
|
|
29623
|
+
|
|
29582
29624
|
// packages/daemon/src/imps/ssh/authorized-keys.ts
|
|
29583
29625
|
var import_ssh2 = __toESM(require_lib2(), 1);
|
|
29584
29626
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -32877,7 +32919,13 @@ function createKnownHosts(deps) {
|
|
|
32877
32919
|
read: async () => {
|
|
32878
32920
|
const status = await deps.readTailscale();
|
|
32879
32921
|
const addresses = status.ips.map(readAddressHost);
|
|
32880
|
-
const names = [
|
|
32922
|
+
const names = [
|
|
32923
|
+
...LOOPBACK_HOSTS2,
|
|
32924
|
+
status.hostname,
|
|
32925
|
+
status.dnsName,
|
|
32926
|
+
...addresses,
|
|
32927
|
+
deps.apiHost
|
|
32928
|
+
];
|
|
32881
32929
|
return new Set(names.filter((name) => name !== null).map((name) => name.toLowerCase()));
|
|
32882
32930
|
}
|
|
32883
32931
|
};
|
|
@@ -36049,13 +36097,14 @@ function readPublicInfo(config, imps, records) {
|
|
|
36049
36097
|
};
|
|
36050
36098
|
}
|
|
36051
36099
|
async function readHttpsInfo(deps) {
|
|
36052
|
-
const
|
|
36053
|
-
if (
|
|
36100
|
+
const https = deps.config.https;
|
|
36101
|
+
if (https === null) {
|
|
36054
36102
|
return null;
|
|
36055
36103
|
}
|
|
36056
36104
|
const token = deps.checkDnsToken === null ? null : await deps.checkDnsToken();
|
|
36057
36105
|
return {
|
|
36058
|
-
domain,
|
|
36106
|
+
domain: https.domain,
|
|
36107
|
+
apiHost: https.apiHost,
|
|
36059
36108
|
dnsToken: token === null ? null : { isOk: token.isOk, error: token.error, at: new Date(token.at) }
|
|
36060
36109
|
};
|
|
36061
36110
|
}
|
|
@@ -44049,6 +44098,23 @@ function resolveCpuSettings(input, current, hostCpus) {
|
|
|
44049
44098
|
return { limit, weight };
|
|
44050
44099
|
}
|
|
44051
44100
|
|
|
44101
|
+
// packages/daemon/src/imps/imps/resolve-imp-name.ts
|
|
44102
|
+
var NAME_ALPHABET2 = "abcdefghijkmnpqrstuvwxyz23456789";
|
|
44103
|
+
async function resolveImpName(context, requested, random = Math.random) {
|
|
44104
|
+
if (requested !== undefined) {
|
|
44105
|
+
return requested;
|
|
44106
|
+
}
|
|
44107
|
+
for (;; ) {
|
|
44108
|
+
const picks = Array.from({ length: 4 }, () => random() * NAME_ALPHABET2.length);
|
|
44109
|
+
const suffix = picks.map((pick) => NAME_ALPHABET2[Math.floor(pick)]).join("");
|
|
44110
|
+
const name = `imp-${suffix}`;
|
|
44111
|
+
const taken = await readImpByName(context.db, name);
|
|
44112
|
+
if (taken === undefined && name !== readReservedName(context.config.https)) {
|
|
44113
|
+
return name;
|
|
44114
|
+
}
|
|
44115
|
+
}
|
|
44116
|
+
}
|
|
44117
|
+
|
|
44052
44118
|
// packages/daemon/src/imps/imps/create-imp-record.ts
|
|
44053
44119
|
var CREATE_TRIES = 3;
|
|
44054
44120
|
async function createImpRecord(context, id, input, image) {
|
|
@@ -44092,21 +44158,6 @@ async function createImpRecord(context, id, input, image) {
|
|
|
44092
44158
|
}
|
|
44093
44159
|
}
|
|
44094
44160
|
}
|
|
44095
|
-
var NAME_ALPHABET2 = "abcdefghijkmnpqrstuvwxyz23456789";
|
|
44096
|
-
async function resolveImpName(context, requested) {
|
|
44097
|
-
if (requested !== undefined) {
|
|
44098
|
-
return requested;
|
|
44099
|
-
}
|
|
44100
|
-
for (;; ) {
|
|
44101
|
-
const picks = Array.from({ length: 4 }, () => Math.random() * NAME_ALPHABET2.length);
|
|
44102
|
-
const suffix = picks.map((pick) => NAME_ALPHABET2[Math.floor(pick)]).join("");
|
|
44103
|
-
const name = `imp-${suffix}`;
|
|
44104
|
-
const taken = await readImpByName(context.db, name);
|
|
44105
|
-
if (taken === undefined) {
|
|
44106
|
-
return name;
|
|
44107
|
-
}
|
|
44108
|
-
}
|
|
44109
|
-
}
|
|
44110
44161
|
|
|
44111
44162
|
// packages/daemon/src/imps/imps/imp-commands.ts
|
|
44112
44163
|
function createImpCommands(parts) {
|
|
@@ -44132,9 +44183,13 @@ function createImpCommands(parts) {
|
|
|
44132
44183
|
await removeImp(context.db, imp.id);
|
|
44133
44184
|
};
|
|
44134
44185
|
return {
|
|
44186
|
+
requireFreeName: (name) => {
|
|
44187
|
+
requireFreeName(context.config.https, name);
|
|
44188
|
+
},
|
|
44135
44189
|
createImp: async (input) => {
|
|
44136
44190
|
const received = performance.now();
|
|
44137
44191
|
const image = input.image;
|
|
44192
|
+
requireFreeName(context.config.https, input.name);
|
|
44138
44193
|
if (input.policy !== undefined) {
|
|
44139
44194
|
context.egress.requirePolicy(input.policy);
|
|
44140
44195
|
}
|
|
@@ -45180,43 +45235,59 @@ function createMemoryWarm(deps) {
|
|
|
45180
45235
|
const running = new Map;
|
|
45181
45236
|
const lifetime = { isStopped: false };
|
|
45182
45237
|
const slots = createSemaphore(WARM_CONCURRENCY);
|
|
45238
|
+
const budgetBlocks = Math.floor(deps.capMib / BLOCK_MIB2);
|
|
45183
45239
|
const readBlocks = async (mode, target, signal) => {
|
|
45184
45240
|
signal.throwIfAborted();
|
|
45185
|
-
const argv =
|
|
45241
|
+
const argv = match23(mode).with("--warm-blocks", () => [
|
|
45242
|
+
deps.handlerBin,
|
|
45243
|
+
mode,
|
|
45244
|
+
target.blockList,
|
|
45245
|
+
target.memFile,
|
|
45246
|
+
String(budgetBlocks)
|
|
45247
|
+
]).with("--count-blocks", () => [deps.handlerBin, mode, target.blockList, target.memFile]).with("--count-data", "--warm", () => [deps.handlerBin, mode, target.memFile]).exhaustive();
|
|
45186
45248
|
const stdout = await runChecked(argv, { signal }, deps.run);
|
|
45187
45249
|
return WarmReportSchema.parse(JSON.parse(stdout)).blocks;
|
|
45188
45250
|
};
|
|
45189
|
-
const
|
|
45190
|
-
|
|
45191
|
-
|
|
45192
|
-
|
|
45193
|
-
scope: "recorded",
|
|
45194
|
-
blocks: await readBlocks(RECORDED_MODES.count, target, signal)
|
|
45195
|
-
};
|
|
45196
|
-
} catch (error) {
|
|
45197
|
-
signal.throwIfAborted();
|
|
45198
|
-
getImpdLogger("imps").with({ imp: target.name }).warning("the recorded blocks of the memory file cannot be counted, so the whole file is: {error}", {
|
|
45199
|
-
error: getErrorMessage(error)
|
|
45200
|
-
});
|
|
45201
|
-
}
|
|
45251
|
+
const warmRecorded = async (target, signal, startedMs) => {
|
|
45252
|
+
const recorded = await readBlocks(RECORDED_MODES.count, target, signal);
|
|
45253
|
+
if (recorded > 0 && budgetBlocks === 0) {
|
|
45254
|
+
return { kind: "overCap", scope: "recorded", blocks: recorded };
|
|
45202
45255
|
}
|
|
45203
|
-
|
|
45256
|
+
const read = recorded === 0 ? 0 : await readBlocks(RECORDED_MODES.warm, target, signal);
|
|
45257
|
+
return {
|
|
45258
|
+
kind: "warmed",
|
|
45259
|
+
scope: "recorded",
|
|
45260
|
+
blocks: read,
|
|
45261
|
+
scopeBlocks: recorded,
|
|
45262
|
+
warmMs: Math.round(performance.now() - startedMs)
|
|
45263
|
+
};
|
|
45264
|
+
};
|
|
45265
|
+
const warmWhole = async (target, signal, startedMs) => {
|
|
45266
|
+
const counted = await readBlocks(WHOLE_MODES.count, target, signal);
|
|
45267
|
+
if (counted * BLOCK_MIB2 > deps.capMib) {
|
|
45268
|
+
return { kind: "overCap", scope: "whole", blocks: counted };
|
|
45269
|
+
}
|
|
45270
|
+
const read = await readBlocks(WHOLE_MODES.warm, target, signal);
|
|
45271
|
+
return {
|
|
45272
|
+
kind: "warmed",
|
|
45273
|
+
scope: "whole",
|
|
45274
|
+
blocks: read,
|
|
45275
|
+
scopeBlocks: counted,
|
|
45276
|
+
warmMs: Math.round(performance.now() - startedMs)
|
|
45277
|
+
};
|
|
45204
45278
|
};
|
|
45205
45279
|
const runWarm = async (target, signal) => {
|
|
45206
45280
|
const startedMs = performance.now();
|
|
45207
45281
|
try {
|
|
45208
|
-
|
|
45209
|
-
|
|
45210
|
-
|
|
45282
|
+
if (existsSync21(target.blockList)) {
|
|
45283
|
+
try {
|
|
45284
|
+
return await warmRecorded(target, signal, startedMs);
|
|
45285
|
+
} catch (error) {
|
|
45286
|
+
signal.throwIfAborted();
|
|
45287
|
+
getImpdLogger("imps").with({ imp: target.name }).warning("the recorded blocks of the memory file cannot be read, so the whole file is: {error}", { error: getErrorMessage(error) });
|
|
45288
|
+
}
|
|
45211
45289
|
}
|
|
45212
|
-
|
|
45213
|
-
const read = await readBlocks(modes.warm, target, signal);
|
|
45214
|
-
return {
|
|
45215
|
-
kind: "warmed",
|
|
45216
|
-
scope: counted.scope,
|
|
45217
|
-
blocks: read,
|
|
45218
|
-
warmMs: Math.round(performance.now() - startedMs)
|
|
45219
|
-
};
|
|
45290
|
+
return await warmWhole(target, signal, startedMs);
|
|
45220
45291
|
} catch (error) {
|
|
45221
45292
|
return { kind: "failed", error: getErrorMessage(error) };
|
|
45222
45293
|
}
|
|
@@ -45274,15 +45345,15 @@ function createMemoryWarm(deps) {
|
|
|
45274
45345
|
}
|
|
45275
45346
|
};
|
|
45276
45347
|
}
|
|
45277
|
-
function isBlockListMode(mode) {
|
|
45278
|
-
return mode === "--count-blocks" || mode === "--warm-blocks";
|
|
45279
|
-
}
|
|
45280
45348
|
function logWarm(target, outcome, capMib) {
|
|
45281
45349
|
const logger = getImpdLogger("imps").with({ imp: target.name });
|
|
45282
45350
|
match23(outcome).with({ kind: "warmed", scope: "recorded" }, (warmed) => {
|
|
45283
|
-
logger.info("warmed {blocks} recorded blocks of
|
|
45351
|
+
logger.info("warmed {blocks} of {recordedBlocks} recorded blocks ({blocksMib} of {recordedMib} MiB) in {warmMs}ms", {
|
|
45284
45352
|
warmMs: String(warmed.warmMs),
|
|
45285
|
-
blocks: String(warmed.blocks)
|
|
45353
|
+
blocks: String(warmed.blocks),
|
|
45354
|
+
recordedBlocks: String(warmed.scopeBlocks),
|
|
45355
|
+
blocksMib: String(warmed.blocks * BLOCK_MIB2),
|
|
45356
|
+
recordedMib: String(warmed.scopeBlocks * BLOCK_MIB2)
|
|
45286
45357
|
});
|
|
45287
45358
|
}).with({ kind: "warmed", scope: "whole" }, (warmed) => {
|
|
45288
45359
|
logger.info("warmed the whole memory file in {warmMs}ms: {blocks} blocks of 2 MiB", {
|
|
@@ -45290,7 +45361,7 @@ function logWarm(target, outcome, capMib) {
|
|
|
45290
45361
|
blocks: String(warmed.blocks)
|
|
45291
45362
|
});
|
|
45292
45363
|
}).with({ kind: "overCap", scope: "recorded" }, (over) => {
|
|
45293
|
-
logger.info("left the memory file cold: its {
|
|
45364
|
+
logger.info("left the memory file cold: not one of its {blocks} recorded blocks of {blockMib} MiB fits the warm cap of {capMib} MiB", { blocks: String(over.blocks), blockMib: String(BLOCK_MIB2), capMib: String(capMib) });
|
|
45294
45365
|
}).with({ kind: "overCap", scope: "whole" }, (over) => {
|
|
45295
45366
|
logger.info("left the memory file cold: its {dataMib} MiB of data pass the warm cap of {capMib} MiB", { dataMib: String(over.blocks * BLOCK_MIB2), capMib: String(capMib) });
|
|
45296
45367
|
}).with({ kind: "ended" }, (ended) => {
|
|
@@ -52339,6 +52410,7 @@ async function readMoveStream(deps, options) {
|
|
|
52339
52410
|
const header = MoveHeaderSchema.parse(readJsonPayload(first.payload));
|
|
52340
52411
|
const headerAt = deps.now();
|
|
52341
52412
|
requireTicketedName(row.name, header.imp.name);
|
|
52413
|
+
deps.imps.requireFreeName(header.imp.name);
|
|
52342
52414
|
if (await readImpById(deps.db, header.imp.id) !== undefined) {
|
|
52343
52415
|
throw new MoveRequestError("CONFLICT", `this host has an imp with id ${header.imp.id}`);
|
|
52344
52416
|
}
|
|
@@ -52624,6 +52696,7 @@ function createMoveReceiver(deps) {
|
|
|
52624
52696
|
if (deps.now() > row.stream_by) {
|
|
52625
52697
|
throw new MoveRequestError("GONE", "the move ticket expired before its stream started");
|
|
52626
52698
|
}
|
|
52699
|
+
deps.imps.requireFreeName(row.name);
|
|
52627
52700
|
const isClaimed = await claimMoveTicketStream(deps.db, row.id, deps.now());
|
|
52628
52701
|
if (!isClaimed) {
|
|
52629
52702
|
throw new MoveRequestError("CONFLICT", "the move ticket was used for a stream already");
|
|
@@ -52700,6 +52773,7 @@ function createMoveReceiver(deps) {
|
|
|
52700
52773
|
if (row.commit_until !== null && deps.now() > row.commit_until) {
|
|
52701
52774
|
throw new MoveRequestError("GONE", "the commit window ended; reissue the ticket");
|
|
52702
52775
|
}
|
|
52776
|
+
deps.imps.requireFreeName(row.name);
|
|
52703
52777
|
await writeCommit(imp, row);
|
|
52704
52778
|
return { isCommitted: true };
|
|
52705
52779
|
});
|
|
@@ -52729,6 +52803,7 @@ function createMoveReceiver(deps) {
|
|
|
52729
52803
|
};
|
|
52730
52804
|
return {
|
|
52731
52805
|
issueTicket: async (name, bytes, warm) => {
|
|
52806
|
+
deps.imps.requireFreeName(name);
|
|
52732
52807
|
const taken = await readImpByName(deps.db, name);
|
|
52733
52808
|
if (taken !== undefined) {
|
|
52734
52809
|
throw new ImpdError("CONFLICT", {
|
|
@@ -57066,7 +57141,7 @@ function createTailnetAccess(config, deps, readStatus) {
|
|
|
57066
57141
|
}),
|
|
57067
57142
|
knownHosts: createKnownHosts({
|
|
57068
57143
|
readTailscale,
|
|
57069
|
-
|
|
57144
|
+
apiHost: config.https?.apiHost ?? null
|
|
57070
57145
|
})
|
|
57071
57146
|
};
|
|
57072
57147
|
}
|
|
@@ -57951,7 +58026,7 @@ function createCloudflareProvider(options) {
|
|
|
57951
58026
|
const existing = RecordListSchema.parse(result).filter((item) => ADDRESS_TYPES.has(item.type ?? ""));
|
|
57952
58027
|
const foreign = existing.find((item) => item.comment !== owner);
|
|
57953
58028
|
if (foreign !== undefined) {
|
|
57954
|
-
throw new Error(`Cloudflare: ${fqdn} already has a record impd did not make (${foreign.type ?? ""} ${foreign.content}); remove it,
|
|
58029
|
+
throw new Error(`Cloudflare: ${fqdn} already has a record impd did not make (${foreign.type ?? ""} ${foreign.content}); remove it; when it is the bare IMP_DOMAIN, set IMP_API_HOST to put the API on a name of its own`);
|
|
57955
58030
|
}
|
|
57956
58031
|
if (existing.length > 1) {
|
|
57957
58032
|
getImpdLogger("https").warning("{fqdn} has {length} A records impd made; it updates only the first", { fqdn, length: String(existing.length) });
|
|
@@ -58206,18 +58281,21 @@ function normalizeHost(host) {
|
|
|
58206
58281
|
}
|
|
58207
58282
|
|
|
58208
58283
|
// packages/daemon/src/network/https/parse-domain-host.ts
|
|
58209
|
-
function parseDomainHost(host,
|
|
58284
|
+
function parseDomainHost(host, names) {
|
|
58210
58285
|
const hostname = normalizeHost(host);
|
|
58211
58286
|
if (hostname === null) {
|
|
58212
58287
|
return null;
|
|
58213
58288
|
}
|
|
58214
|
-
if (hostname ===
|
|
58215
|
-
return { kind: "
|
|
58289
|
+
if (hostname === names.apiHost) {
|
|
58290
|
+
return { kind: "api" };
|
|
58216
58291
|
}
|
|
58217
|
-
if (
|
|
58292
|
+
if (hostname === names.domain) {
|
|
58218
58293
|
return null;
|
|
58219
58294
|
}
|
|
58220
|
-
|
|
58295
|
+
if (!hostname.endsWith(`.${names.domain}`)) {
|
|
58296
|
+
return null;
|
|
58297
|
+
}
|
|
58298
|
+
const label = hostname.slice(0, -(names.domain.length + 1));
|
|
58221
58299
|
const parsed = NameSchema.safeParse(label);
|
|
58222
58300
|
return parsed.success && !label.includes(".") ? { kind: "imp", name: parsed.data } : null;
|
|
58223
58301
|
}
|
|
@@ -58225,6 +58303,7 @@ function parseDomainHost(host, domain) {
|
|
|
58225
58303
|
// packages/daemon/src/network/https/https-listeners.ts
|
|
58226
58304
|
function createHttpsListeners(options) {
|
|
58227
58305
|
const domain = options.domain;
|
|
58306
|
+
const names = { domain, apiHost: options.apiHost };
|
|
58228
58307
|
const ports = { https: options.httpsPort, http: options.httpPort };
|
|
58229
58308
|
const byAddress = new Map;
|
|
58230
58309
|
const failed = new Set;
|
|
@@ -58233,18 +58312,18 @@ function createHttpsListeners(options) {
|
|
|
58233
58312
|
const readRedirectPort = () => scope.kind === "public" ? 443 : ports.https;
|
|
58234
58313
|
const hint = scope.kind === "public" ? "No public imp here." : `Use https://<imp>.${domain}/.`;
|
|
58235
58314
|
const resolveRoute = async (request) => {
|
|
58236
|
-
const parsed = parseDomainHost(request.headers.get("host"),
|
|
58315
|
+
const parsed = parseDomainHost(request.headers.get("host"), names);
|
|
58237
58316
|
if (parsed === null) {
|
|
58238
58317
|
return { kind: "none", hint };
|
|
58239
58318
|
}
|
|
58240
58319
|
if (scope.kind === "tailnet") {
|
|
58241
|
-
return parsed.kind === "
|
|
58320
|
+
return parsed.kind === "api" ? { kind: "api" } : parsed;
|
|
58242
58321
|
}
|
|
58243
58322
|
const route = parsed.kind === "imp" ? await scope.routeImp(parsed.name, request) : null;
|
|
58244
58323
|
return route ?? { kind: "none", hint };
|
|
58245
58324
|
};
|
|
58246
58325
|
const checkRedirect = (request) => {
|
|
58247
|
-
const parsed = parseDomainHost(request.headers.get("host"),
|
|
58326
|
+
const parsed = parseDomainHost(request.headers.get("host"), names);
|
|
58248
58327
|
if (parsed === null || scope.kind === "tailnet") {
|
|
58249
58328
|
return Promise.resolve(parsed !== null);
|
|
58250
58329
|
}
|
|
@@ -58279,7 +58358,7 @@ function createHttpsListeners(options) {
|
|
|
58279
58358
|
}));
|
|
58280
58359
|
const handleRedirectRequest = async (request) => {
|
|
58281
58360
|
const isRedirected = await checkRedirect(request);
|
|
58282
|
-
return isRedirected ? buildRedirect(request,
|
|
58361
|
+
return isRedirected ? buildRedirect(request, names, readRedirectPort(), hint) : buildErrorPage(404, hint);
|
|
58283
58362
|
};
|
|
58284
58363
|
const startRedirect = (address) => tryBind(address, "http", () => Bun.serve({
|
|
58285
58364
|
hostname: address,
|
|
@@ -58339,8 +58418,8 @@ function createHttpsListeners(options) {
|
|
|
58339
58418
|
}
|
|
58340
58419
|
};
|
|
58341
58420
|
}
|
|
58342
|
-
function buildRedirect(request,
|
|
58343
|
-
const parsed = parseDomainHost(request.headers.get("host"),
|
|
58421
|
+
function buildRedirect(request, names, httpsPort, hint) {
|
|
58422
|
+
const parsed = parseDomainHost(request.headers.get("host"), names);
|
|
58344
58423
|
if (parsed === null) {
|
|
58345
58424
|
return buildErrorPage(404, hint);
|
|
58346
58425
|
}
|
|
@@ -58349,12 +58428,12 @@ function buildRedirect(request, domain, httpsPort, hint) {
|
|
|
58349
58428
|
return new Response(null, {
|
|
58350
58429
|
status: 308,
|
|
58351
58430
|
headers: {
|
|
58352
|
-
location: `https://${buildHostname(parsed,
|
|
58431
|
+
location: `https://${buildHostname(parsed, names)}${port}${url.pathname}${url.search}`
|
|
58353
58432
|
}
|
|
58354
58433
|
});
|
|
58355
58434
|
}
|
|
58356
|
-
function buildHostname(route,
|
|
58357
|
-
return route.kind === "
|
|
58435
|
+
function buildHostname(route, names) {
|
|
58436
|
+
return route.kind === "api" ? names.apiHost : `${route.name}.${names.domain}`;
|
|
58358
58437
|
}
|
|
58359
58438
|
|
|
58360
58439
|
// packages/daemon/src/network/https/public-limits.ts
|
|
@@ -58379,6 +58458,7 @@ var ADDRESS_INTERVAL_MS = 30000;
|
|
|
58379
58458
|
function createHttpsService(deps) {
|
|
58380
58459
|
const config = deps.config;
|
|
58381
58460
|
const domain = config.domain;
|
|
58461
|
+
const apiHost = config.apiHost;
|
|
58382
58462
|
const certs = createCertManager({
|
|
58383
58463
|
domain,
|
|
58384
58464
|
store: deps.store,
|
|
@@ -58388,6 +58468,7 @@ function createHttpsService(deps) {
|
|
|
58388
58468
|
const listeners = createHttpsListeners({
|
|
58389
58469
|
proxy: deps.proxy,
|
|
58390
58470
|
domain,
|
|
58471
|
+
apiHost,
|
|
58391
58472
|
httpsPort: config.httpsPort,
|
|
58392
58473
|
httpPort: config.httpPort,
|
|
58393
58474
|
scope: { kind: "tailnet" }
|
|
@@ -58396,6 +58477,7 @@ function createHttpsService(deps) {
|
|
|
58396
58477
|
const publicListeners = publicConfig === null ? null : createHttpsListeners({
|
|
58397
58478
|
proxy: deps.proxy,
|
|
58398
58479
|
domain,
|
|
58480
|
+
apiHost,
|
|
58399
58481
|
httpsPort: publicConfig.httpsPort,
|
|
58400
58482
|
httpPort: publicConfig.httpPort,
|
|
58401
58483
|
scope: createPublicScope(deps.readPublicImpByName, createPublicLimits(deps.now))
|
|
@@ -58421,13 +58503,17 @@ function createHttpsService(deps) {
|
|
|
58421
58503
|
};
|
|
58422
58504
|
const setRecords = async (ip) => {
|
|
58423
58505
|
try {
|
|
58424
|
-
await deps.dns.setA(
|
|
58506
|
+
await deps.dns.setA(apiHost, ip);
|
|
58425
58507
|
await deps.dns.setA(`*.${domain}`, ip);
|
|
58426
58508
|
state.recordsIp = ip;
|
|
58427
58509
|
state.recordsError = null;
|
|
58428
|
-
getImpdLogger("https").info("{
|
|
58510
|
+
getImpdLogger("https").info("{apiHost} and *.{domain} point at {ip}", {
|
|
58511
|
+
apiHost,
|
|
58512
|
+
domain,
|
|
58513
|
+
ip
|
|
58514
|
+
});
|
|
58429
58515
|
} catch (error) {
|
|
58430
|
-
const message = `cannot point ${
|
|
58516
|
+
const message = `cannot point ${apiHost} at ${ip}: ${getErrorMessage(error)}`;
|
|
58431
58517
|
if (message !== state.recordsError) {
|
|
58432
58518
|
state.recordsError = message;
|
|
58433
58519
|
getImpdLogger("https").warning("{message}", { message });
|
|
@@ -60427,6 +60513,7 @@ async function startImpdParts(config, boundaries, plan) {
|
|
|
60427
60513
|
});
|
|
60428
60514
|
const db = await runStep("database", () => boundaries.db ?? openDatabase(join49(config.dataDir, "db", "imp.sqlite"), now));
|
|
60429
60515
|
plan.db = boundaries.db === undefined ? db : null;
|
|
60516
|
+
await requireNoImpNamedLikeApiHost(db, config.https);
|
|
60430
60517
|
const kernelOops = boundaries.imps?.kernelOops ?? createKernelOopsWatch();
|
|
60431
60518
|
const storage = boundaries.storage ?? createStorageBackend(config, { zfs: { isKernelOopsed: kernelOops.isOopsed } });
|
|
60432
60519
|
const deps = {
|
|
@@ -61247,6 +61334,7 @@ var WarmRunSchema = z105.object({
|
|
|
61247
61334
|
mode: z105.enum(["--count-data", "--warm", "--count-blocks", "--warm-blocks"]),
|
|
61248
61335
|
memFile: z105.string(),
|
|
61249
61336
|
blockList: z105.string().optional(),
|
|
61337
|
+
limit: z105.int().optional(),
|
|
61250
61338
|
pid: z105.int()
|
|
61251
61339
|
});
|
|
61252
61340
|
function createStubUffdHandler(directory, mode = "serve") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@impz/testing",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.12.0",
|
|
4
4
|
"description": "A real impd on stand-ins, for Bun tests of code that drives impd through @impz/client",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"ts-pattern": "^5.9.2",
|
|
48
48
|
"xstate": "^5.33.3",
|
|
49
49
|
"zod": "^4.6.7",
|
|
50
|
-
"@impz/client": "7.
|
|
50
|
+
"@impz/client": "7.12.0"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"bun": ">=1.4.3"
|