@impz/testing 7.11.0 → 7.13.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.
Files changed (2) hide show
  1. package/dist/index.js +156 -43
  2. 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
- var DomainSchema = 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, "IMP_DOMAIN must be a domain name such as imp.example.com"));
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",
@@ -21766,6 +21782,29 @@ function toWholeBlocks(mib) {
21766
21782
 
21767
21783
  // packages/daemon/src/config.ts
21768
21784
  var PortSchema3 = z54.coerce.number().pipe(z54.int().min(1).max(65535));
21785
+ var HostTcpPortsSchema = z54.string().default("").transform((value, ctx) => {
21786
+ const ports = [];
21787
+ const entries = value.trim() === "" ? [] : splitList(value);
21788
+ for (const entry of entries) {
21789
+ const port = /^\d+$/u.test(entry) ? Number(entry) : Number.NaN;
21790
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
21791
+ ctx.addIssue({
21792
+ code: "custom",
21793
+ message: `IMP_HOST_TCP_PORTS must list TCP ports from 1 to 65535, got ${JSON.stringify(entry)}`
21794
+ });
21795
+ return z54.NEVER;
21796
+ }
21797
+ if (ports.includes(port)) {
21798
+ ctx.addIssue({
21799
+ code: "custom",
21800
+ message: `IMP_HOST_TCP_PORTS lists port ${String(port)} twice`
21801
+ });
21802
+ return z54.NEVER;
21803
+ }
21804
+ ports.push(port);
21805
+ }
21806
+ return ports;
21807
+ });
21769
21808
  var CountSchema3 = z54.coerce.number().pipe(z54.int().positive());
21770
21809
  var DnsServersSchema = z54.array(z54.ipv4()).min(1);
21771
21810
  var PercentSchema = z54.coerce.number().pipe(z54.int().min(0).max(100));
@@ -21781,6 +21820,7 @@ var EnvSchema = z54.object({
21781
21820
  IMP_BROKER_TEST_UPSTREAMS: z54.string().optional(),
21782
21821
  IMP_IDENTITY_ISSUER: IdentityIssuerSchema.optional(),
21783
21822
  IMP_EGRESS_DNS_PORT: PortSchema3.default(7053),
21823
+ IMP_HOST_TCP_PORTS: HostTcpPortsSchema,
21784
21824
  IMP_EGRESS_DENY: z54.string().default(""),
21785
21825
  IMP_HOST_ADDRESSES: z54.string().default(""),
21786
21826
  IMP_RAM_BUDGET_MIB: CountSchema3.default(16384),
@@ -21845,11 +21885,26 @@ var EnvSchema = z54.object({
21845
21885
  ...TailnetNamesEnvSchema.shape,
21846
21886
  ...PublicMcpEnvSchema.shape
21847
21887
  });
21888
+ function refineHostTcpPorts(parsed, ctx) {
21889
+ for (const [name, port] of [
21890
+ ["IMP_BROKER_PORT", parsed.IMP_BROKER_PORT],
21891
+ ["IMP_EGRESS_DNS_PORT", parsed.IMP_EGRESS_DNS_PORT]
21892
+ ]) {
21893
+ if (parsed.IMP_HOST_TCP_PORTS.includes(port)) {
21894
+ ctx.addIssue({
21895
+ code: "custom",
21896
+ message: `IMP_HOST_TCP_PORTS lists port ${String(port)}, which is ${name}`
21897
+ });
21898
+ }
21899
+ }
21900
+ }
21901
+ var CheckedEnvSchema = EnvSchema.superRefine(refineHostTcpPorts);
21848
21902
  var NetworkEnvSchema = EnvSchema.pick({
21849
21903
  IMP_SUBNET: true,
21850
21904
  IMP_BROKER_PORT: true,
21851
- IMP_EGRESS_DNS_PORT: true
21852
- });
21905
+ IMP_EGRESS_DNS_PORT: true,
21906
+ IMP_HOST_TCP_PORTS: true
21907
+ }).superRefine(refineHostTcpPorts);
21853
21908
  function parseCidrList(value) {
21854
21909
  return splitList(value).filter((entry) => entry !== "").map((entry) => {
21855
21910
  const cidr = formatCidr4(entry) ?? formatCidr6(entry);
@@ -21886,7 +21941,7 @@ function checkMoveSettings(testCidr, peerUrl, isE2e) {
21886
21941
  }
21887
21942
  function loadConfig(env) {
21888
21943
  const present = Object.fromEntries(Object.entries(env).filter(([, value]) => value !== ""));
21889
- const parsed = EnvSchema.parse(present);
21944
+ const parsed = CheckedEnvSchema.parse(present);
21890
21945
  const subnet = parseSubnet(parsed.IMP_SUBNET);
21891
21946
  const lastPort = parsed.IMP_PORT_BASE + countSlots(subnet) - 1;
21892
21947
  if (lastPort > 65535) {
@@ -21944,6 +21999,7 @@ function loadConfig(env) {
21944
21999
  sshAuthorizedKeys: parsed.IMP_SSH_AUTHORIZED_KEYS === "true",
21945
22000
  brokerPort: parsed.IMP_BROKER_PORT,
21946
22001
  egressDnsPort: parsed.IMP_EGRESS_DNS_PORT,
22002
+ hostTcpPorts: parsed.IMP_HOST_TCP_PORTS,
21947
22003
  egressDeny: [
21948
22004
  ...new Set([
21949
22005
  ...parseCidrList(parsed.IMP_EGRESS_DENY),
@@ -22161,7 +22217,7 @@ import { join as join49 } from "path";
22161
22217
  // packages/daemon/package.json
22162
22218
  var package_default = {
22163
22219
  name: "@impz/daemon",
22164
- version: "7.11.0",
22220
+ version: "7.13.0",
22165
22221
  private: true,
22166
22222
  description: "impd: the imp host daemon",
22167
22223
  type: "module",
@@ -28422,6 +28478,7 @@ async function runRestore(deps, input) {
28422
28478
  }
28423
28479
  for (const imp of chosen) {
28424
28480
  const name = input.as ?? imp.name;
28481
+ deps.imps.requireFreeName(name);
28425
28482
  if (presentNames.has(name)) {
28426
28483
  throw buildConflictError("imp", name, `an imp named ${name} exists; restore it --as another name`);
28427
28484
  }
@@ -29579,6 +29636,31 @@ async function listDrivesInUse(db, findPaths) {
29579
29636
  return drives;
29580
29637
  }
29581
29638
 
29639
+ // packages/daemon/src/imps/imps/require-free-name.ts
29640
+ function readReservedName(https) {
29641
+ if (https === null || https.apiHost === https.domain) {
29642
+ return null;
29643
+ }
29644
+ return https.apiHost.slice(0, -(https.domain.length + 1));
29645
+ }
29646
+ function requireFreeName(https, name) {
29647
+ const reserved = readReservedName(https);
29648
+ if (reserved === null || https === null || name !== reserved) {
29649
+ return;
29650
+ }
29651
+ throw new ImpdError("BAD_REQUEST", {
29652
+ 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`
29653
+ });
29654
+ }
29655
+ async function requireNoImpNamedLikeApiHost(db, https) {
29656
+ const reserved = readReservedName(https);
29657
+ const holder = reserved === null ? undefined : await readImpByName(db, reserved);
29658
+ if (reserved === null || https === null || holder === undefined || holder.moveState === "receiving") {
29659
+ return;
29660
+ }
29661
+ throw new Error(`IMP_API_HOST ${https.apiHost} is the hostname of the imp ${reserved}; destroy that imp, or choose another host`);
29662
+ }
29663
+
29582
29664
  // packages/daemon/src/imps/ssh/authorized-keys.ts
29583
29665
  var import_ssh2 = __toESM(require_lib2(), 1);
29584
29666
  import { createHash as createHash2 } from "crypto";
@@ -32877,7 +32959,13 @@ function createKnownHosts(deps) {
32877
32959
  read: async () => {
32878
32960
  const status = await deps.readTailscale();
32879
32961
  const addresses = status.ips.map(readAddressHost);
32880
- const names = [...LOOPBACK_HOSTS2, status.hostname, status.dnsName, ...addresses, deps.domain];
32962
+ const names = [
32963
+ ...LOOPBACK_HOSTS2,
32964
+ status.hostname,
32965
+ status.dnsName,
32966
+ ...addresses,
32967
+ deps.apiHost
32968
+ ];
32881
32969
  return new Set(names.filter((name) => name !== null).map((name) => name.toLowerCase()));
32882
32970
  }
32883
32971
  };
@@ -36049,13 +36137,14 @@ function readPublicInfo(config, imps, records) {
36049
36137
  };
36050
36138
  }
36051
36139
  async function readHttpsInfo(deps) {
36052
- const domain = deps.config.https?.domain;
36053
- if (domain === undefined) {
36140
+ const https = deps.config.https;
36141
+ if (https === null) {
36054
36142
  return null;
36055
36143
  }
36056
36144
  const token = deps.checkDnsToken === null ? null : await deps.checkDnsToken();
36057
36145
  return {
36058
- domain,
36146
+ domain: https.domain,
36147
+ apiHost: https.apiHost,
36059
36148
  dnsToken: token === null ? null : { isOk: token.isOk, error: token.error, at: new Date(token.at) }
36060
36149
  };
36061
36150
  }
@@ -41883,6 +41972,7 @@ function buildRuleset(input) {
41883
41972
  ' iifname != "imp*" accept',
41884
41973
  " meta nfproto ipv4 accept",
41885
41974
  " icmpv6 type { nd-router-solicit, nd-neighbor-solicit, nd-neighbor-advert } ip6 hoplimit 255 accept",
41975
+ ...input.hostTcpPorts.length === 0 ? [] : [` tcp dport { ${input.hostTcpPorts.join(", ")} } accept`],
41886
41976
  " drop",
41887
41977
  " }",
41888
41978
  " chain dns {",
@@ -42837,6 +42927,7 @@ function createEgressService(deps) {
42837
42927
  uplinks4: host.uplinks.ipv4,
42838
42928
  uplinks6: host.uplinks.ipv6,
42839
42929
  dnsPort: deps.config.egressDnsPort,
42930
+ hostTcpPorts: deps.config.hostTcpPorts,
42840
42931
  setSize: SET_SIZE,
42841
42932
  slots: [...views.values()].map((view) => ({
42842
42933
  slot: view.entry.slot,
@@ -44049,6 +44140,23 @@ function resolveCpuSettings(input, current, hostCpus) {
44049
44140
  return { limit, weight };
44050
44141
  }
44051
44142
 
44143
+ // packages/daemon/src/imps/imps/resolve-imp-name.ts
44144
+ var NAME_ALPHABET2 = "abcdefghijkmnpqrstuvwxyz23456789";
44145
+ async function resolveImpName(context, requested, random = Math.random) {
44146
+ if (requested !== undefined) {
44147
+ return requested;
44148
+ }
44149
+ for (;; ) {
44150
+ const picks = Array.from({ length: 4 }, () => random() * NAME_ALPHABET2.length);
44151
+ const suffix = picks.map((pick) => NAME_ALPHABET2[Math.floor(pick)]).join("");
44152
+ const name = `imp-${suffix}`;
44153
+ const taken = await readImpByName(context.db, name);
44154
+ if (taken === undefined && name !== readReservedName(context.config.https)) {
44155
+ return name;
44156
+ }
44157
+ }
44158
+ }
44159
+
44052
44160
  // packages/daemon/src/imps/imps/create-imp-record.ts
44053
44161
  var CREATE_TRIES = 3;
44054
44162
  async function createImpRecord(context, id, input, image) {
@@ -44092,21 +44200,6 @@ async function createImpRecord(context, id, input, image) {
44092
44200
  }
44093
44201
  }
44094
44202
  }
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
44203
 
44111
44204
  // packages/daemon/src/imps/imps/imp-commands.ts
44112
44205
  function createImpCommands(parts) {
@@ -44132,9 +44225,13 @@ function createImpCommands(parts) {
44132
44225
  await removeImp(context.db, imp.id);
44133
44226
  };
44134
44227
  return {
44228
+ requireFreeName: (name) => {
44229
+ requireFreeName(context.config.https, name);
44230
+ },
44135
44231
  createImp: async (input) => {
44136
44232
  const received = performance.now();
44137
44233
  const image = input.image;
44234
+ requireFreeName(context.config.https, input.name);
44138
44235
  if (input.policy !== undefined) {
44139
44236
  context.egress.requirePolicy(input.policy);
44140
44237
  }
@@ -52355,6 +52452,7 @@ async function readMoveStream(deps, options) {
52355
52452
  const header = MoveHeaderSchema.parse(readJsonPayload(first.payload));
52356
52453
  const headerAt = deps.now();
52357
52454
  requireTicketedName(row.name, header.imp.name);
52455
+ deps.imps.requireFreeName(header.imp.name);
52358
52456
  if (await readImpById(deps.db, header.imp.id) !== undefined) {
52359
52457
  throw new MoveRequestError("CONFLICT", `this host has an imp with id ${header.imp.id}`);
52360
52458
  }
@@ -52640,6 +52738,7 @@ function createMoveReceiver(deps) {
52640
52738
  if (deps.now() > row.stream_by) {
52641
52739
  throw new MoveRequestError("GONE", "the move ticket expired before its stream started");
52642
52740
  }
52741
+ deps.imps.requireFreeName(row.name);
52643
52742
  const isClaimed = await claimMoveTicketStream(deps.db, row.id, deps.now());
52644
52743
  if (!isClaimed) {
52645
52744
  throw new MoveRequestError("CONFLICT", "the move ticket was used for a stream already");
@@ -52716,6 +52815,7 @@ function createMoveReceiver(deps) {
52716
52815
  if (row.commit_until !== null && deps.now() > row.commit_until) {
52717
52816
  throw new MoveRequestError("GONE", "the commit window ended; reissue the ticket");
52718
52817
  }
52818
+ deps.imps.requireFreeName(row.name);
52719
52819
  await writeCommit(imp, row);
52720
52820
  return { isCommitted: true };
52721
52821
  });
@@ -52745,6 +52845,7 @@ function createMoveReceiver(deps) {
52745
52845
  };
52746
52846
  return {
52747
52847
  issueTicket: async (name, bytes, warm) => {
52848
+ deps.imps.requireFreeName(name);
52748
52849
  const taken = await readImpByName(deps.db, name);
52749
52850
  if (taken !== undefined) {
52750
52851
  throw new ImpdError("CONFLICT", {
@@ -57082,7 +57183,7 @@ function createTailnetAccess(config, deps, readStatus) {
57082
57183
  }),
57083
57184
  knownHosts: createKnownHosts({
57084
57185
  readTailscale,
57085
- domain: config.https?.domain ?? null
57186
+ apiHost: config.https?.apiHost ?? null
57086
57187
  })
57087
57188
  };
57088
57189
  }
@@ -57967,7 +58068,7 @@ function createCloudflareProvider(options) {
57967
58068
  const existing = RecordListSchema.parse(result).filter((item) => ADDRESS_TYPES.has(item.type ?? ""));
57968
58069
  const foreign = existing.find((item) => item.comment !== owner);
57969
58070
  if (foreign !== undefined) {
57970
- throw new Error(`Cloudflare: ${fqdn} already has a record impd did not make (${foreign.type ?? ""} ${foreign.content}); remove it, or give impd a name of its own in IMP_DOMAIN`);
58071
+ 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`);
57971
58072
  }
57972
58073
  if (existing.length > 1) {
57973
58074
  getImpdLogger("https").warning("{fqdn} has {length} A records impd made; it updates only the first", { fqdn, length: String(existing.length) });
@@ -58222,18 +58323,21 @@ function normalizeHost(host) {
58222
58323
  }
58223
58324
 
58224
58325
  // packages/daemon/src/network/https/parse-domain-host.ts
58225
- function parseDomainHost(host, domain) {
58326
+ function parseDomainHost(host, names) {
58226
58327
  const hostname = normalizeHost(host);
58227
58328
  if (hostname === null) {
58228
58329
  return null;
58229
58330
  }
58230
- if (hostname === domain) {
58231
- return { kind: "apex" };
58331
+ if (hostname === names.apiHost) {
58332
+ return { kind: "api" };
58232
58333
  }
58233
- if (!hostname.endsWith(`.${domain}`)) {
58334
+ if (hostname === names.domain) {
58234
58335
  return null;
58235
58336
  }
58236
- const label = hostname.slice(0, -(domain.length + 1));
58337
+ if (!hostname.endsWith(`.${names.domain}`)) {
58338
+ return null;
58339
+ }
58340
+ const label = hostname.slice(0, -(names.domain.length + 1));
58237
58341
  const parsed = NameSchema.safeParse(label);
58238
58342
  return parsed.success && !label.includes(".") ? { kind: "imp", name: parsed.data } : null;
58239
58343
  }
@@ -58241,6 +58345,7 @@ function parseDomainHost(host, domain) {
58241
58345
  // packages/daemon/src/network/https/https-listeners.ts
58242
58346
  function createHttpsListeners(options) {
58243
58347
  const domain = options.domain;
58348
+ const names = { domain, apiHost: options.apiHost };
58244
58349
  const ports = { https: options.httpsPort, http: options.httpPort };
58245
58350
  const byAddress = new Map;
58246
58351
  const failed = new Set;
@@ -58249,18 +58354,18 @@ function createHttpsListeners(options) {
58249
58354
  const readRedirectPort = () => scope.kind === "public" ? 443 : ports.https;
58250
58355
  const hint = scope.kind === "public" ? "No public imp here." : `Use https://<imp>.${domain}/.`;
58251
58356
  const resolveRoute = async (request) => {
58252
- const parsed = parseDomainHost(request.headers.get("host"), domain);
58357
+ const parsed = parseDomainHost(request.headers.get("host"), names);
58253
58358
  if (parsed === null) {
58254
58359
  return { kind: "none", hint };
58255
58360
  }
58256
58361
  if (scope.kind === "tailnet") {
58257
- return parsed.kind === "apex" ? { kind: "api" } : parsed;
58362
+ return parsed.kind === "api" ? { kind: "api" } : parsed;
58258
58363
  }
58259
58364
  const route = parsed.kind === "imp" ? await scope.routeImp(parsed.name, request) : null;
58260
58365
  return route ?? { kind: "none", hint };
58261
58366
  };
58262
58367
  const checkRedirect = (request) => {
58263
- const parsed = parseDomainHost(request.headers.get("host"), domain);
58368
+ const parsed = parseDomainHost(request.headers.get("host"), names);
58264
58369
  if (parsed === null || scope.kind === "tailnet") {
58265
58370
  return Promise.resolve(parsed !== null);
58266
58371
  }
@@ -58295,7 +58400,7 @@ function createHttpsListeners(options) {
58295
58400
  }));
58296
58401
  const handleRedirectRequest = async (request) => {
58297
58402
  const isRedirected = await checkRedirect(request);
58298
- return isRedirected ? buildRedirect(request, domain, readRedirectPort(), hint) : buildErrorPage(404, hint);
58403
+ return isRedirected ? buildRedirect(request, names, readRedirectPort(), hint) : buildErrorPage(404, hint);
58299
58404
  };
58300
58405
  const startRedirect = (address) => tryBind(address, "http", () => Bun.serve({
58301
58406
  hostname: address,
@@ -58355,8 +58460,8 @@ function createHttpsListeners(options) {
58355
58460
  }
58356
58461
  };
58357
58462
  }
58358
- function buildRedirect(request, domain, httpsPort, hint) {
58359
- const parsed = parseDomainHost(request.headers.get("host"), domain);
58463
+ function buildRedirect(request, names, httpsPort, hint) {
58464
+ const parsed = parseDomainHost(request.headers.get("host"), names);
58360
58465
  if (parsed === null) {
58361
58466
  return buildErrorPage(404, hint);
58362
58467
  }
@@ -58365,12 +58470,12 @@ function buildRedirect(request, domain, httpsPort, hint) {
58365
58470
  return new Response(null, {
58366
58471
  status: 308,
58367
58472
  headers: {
58368
- location: `https://${buildHostname(parsed, domain)}${port}${url.pathname}${url.search}`
58473
+ location: `https://${buildHostname(parsed, names)}${port}${url.pathname}${url.search}`
58369
58474
  }
58370
58475
  });
58371
58476
  }
58372
- function buildHostname(route, domain) {
58373
- return route.kind === "apex" ? domain : `${route.name}.${domain}`;
58477
+ function buildHostname(route, names) {
58478
+ return route.kind === "api" ? names.apiHost : `${route.name}.${names.domain}`;
58374
58479
  }
58375
58480
 
58376
58481
  // packages/daemon/src/network/https/public-limits.ts
@@ -58395,6 +58500,7 @@ var ADDRESS_INTERVAL_MS = 30000;
58395
58500
  function createHttpsService(deps) {
58396
58501
  const config = deps.config;
58397
58502
  const domain = config.domain;
58503
+ const apiHost = config.apiHost;
58398
58504
  const certs = createCertManager({
58399
58505
  domain,
58400
58506
  store: deps.store,
@@ -58404,6 +58510,7 @@ function createHttpsService(deps) {
58404
58510
  const listeners = createHttpsListeners({
58405
58511
  proxy: deps.proxy,
58406
58512
  domain,
58513
+ apiHost,
58407
58514
  httpsPort: config.httpsPort,
58408
58515
  httpPort: config.httpPort,
58409
58516
  scope: { kind: "tailnet" }
@@ -58412,6 +58519,7 @@ function createHttpsService(deps) {
58412
58519
  const publicListeners = publicConfig === null ? null : createHttpsListeners({
58413
58520
  proxy: deps.proxy,
58414
58521
  domain,
58522
+ apiHost,
58415
58523
  httpsPort: publicConfig.httpsPort,
58416
58524
  httpPort: publicConfig.httpPort,
58417
58525
  scope: createPublicScope(deps.readPublicImpByName, createPublicLimits(deps.now))
@@ -58437,13 +58545,17 @@ function createHttpsService(deps) {
58437
58545
  };
58438
58546
  const setRecords = async (ip) => {
58439
58547
  try {
58440
- await deps.dns.setA(domain, ip);
58548
+ await deps.dns.setA(apiHost, ip);
58441
58549
  await deps.dns.setA(`*.${domain}`, ip);
58442
58550
  state.recordsIp = ip;
58443
58551
  state.recordsError = null;
58444
- getImpdLogger("https").info("{domain} and *.{domain} point at {ip}", { domain, ip });
58552
+ getImpdLogger("https").info("{apiHost} and *.{domain} point at {ip}", {
58553
+ apiHost,
58554
+ domain,
58555
+ ip
58556
+ });
58445
58557
  } catch (error) {
58446
- const message = `cannot point ${domain} at ${ip}: ${getErrorMessage(error)}`;
58558
+ const message = `cannot point ${apiHost} at ${ip}: ${getErrorMessage(error)}`;
58447
58559
  if (message !== state.recordsError) {
58448
58560
  state.recordsError = message;
58449
58561
  getImpdLogger("https").warning("{message}", { message });
@@ -60443,6 +60555,7 @@ async function startImpdParts(config, boundaries, plan) {
60443
60555
  });
60444
60556
  const db = await runStep("database", () => boundaries.db ?? openDatabase(join49(config.dataDir, "db", "imp.sqlite"), now));
60445
60557
  plan.db = boundaries.db === undefined ? db : null;
60558
+ await requireNoImpNamedLikeApiHost(db, config.https);
60446
60559
  const kernelOops = boundaries.imps?.kernelOops ?? createKernelOopsWatch();
60447
60560
  const storage = boundaries.storage ?? createStorageBackend(config, { zfs: { isKernelOopsed: kernelOops.isOopsed } });
60448
60561
  const deps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impz/testing",
3
- "version": "7.11.0",
3
+ "version": "7.13.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.11.0"
50
+ "@impz/client": "7.13.0"
51
51
  },
52
52
  "engines": {
53
53
  "bun": ">=1.4.3"