@geekmidas/edge 0.0.0-stage → 10.0.0-alpha.182
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 +14 -2
- package/dist/certificates/local.cjs +393 -0
- package/dist/certificates/local.cjs.map +1 -0
- package/dist/certificates/local.d.cts +92 -0
- package/dist/certificates/local.d.cts.map +1 -0
- package/dist/certificates/local.d.mts +92 -0
- package/dist/certificates/local.d.mts.map +1 -0
- package/dist/certificates/local.mjs +361 -0
- package/dist/certificates/local.mjs.map +1 -0
- package/dist/compose-BHWyQvsD.cjs +22 -0
- package/dist/compose-BHWyQvsD.cjs.map +1 -0
- package/dist/compose-CcNlj65h.mjs +17 -0
- package/dist/compose-CcNlj65h.mjs.map +1 -0
- package/dist/dns/godaddy/index.cjs +448 -0
- package/dist/dns/godaddy/index.cjs.map +1 -0
- package/dist/dns/godaddy/index.d.cts +164 -0
- package/dist/dns/godaddy/index.d.cts.map +1 -0
- package/dist/dns/godaddy/index.d.mts +164 -0
- package/dist/dns/godaddy/index.d.mts.map +1 -0
- package/dist/dns/godaddy/index.mjs +435 -0
- package/dist/dns/godaddy/index.mjs.map +1 -0
- package/dist/dns/hostinger/index.cjs +252 -0
- package/dist/dns/hostinger/index.cjs.map +1 -0
- package/dist/dns/hostinger/index.d.cts +143 -0
- package/dist/dns/hostinger/index.d.cts.map +1 -0
- package/dist/dns/hostinger/index.d.mts +143 -0
- package/dist/dns/hostinger/index.d.mts.map +1 -0
- package/dist/dns/hostinger/index.mjs +249 -0
- package/dist/dns/hostinger/index.mjs.map +1 -0
- package/dist/dns/index.cjs +76 -0
- package/dist/dns/index.cjs.map +1 -0
- package/dist/dns/index.d.cts +144 -0
- package/dist/dns/index.d.cts.map +1 -0
- package/dist/dns/index.d.mts +144 -0
- package/dist/dns/index.d.mts.map +1 -0
- package/dist/dns/index.mjs +71 -0
- package/dist/dns/index.mjs.map +1 -0
- package/dist/dns/route53.cjs +210 -0
- package/dist/dns/route53.cjs.map +1 -0
- package/dist/dns/route53.d.cts +45 -0
- package/dist/dns/route53.d.cts.map +1 -0
- package/dist/dns/route53.d.mts +45 -0
- package/dist/dns/route53.d.mts.map +1 -0
- package/dist/dns/route53.mjs +209 -0
- package/dist/dns/route53.mjs.map +1 -0
- package/dist/errors-CO33_TDV.mjs +16 -0
- package/dist/errors-CO33_TDV.mjs.map +1 -0
- package/dist/errors-DBZfelEN.d.cts +13 -0
- package/dist/errors-DBZfelEN.d.cts.map +1 -0
- package/dist/errors-DBZfelEN.d.mts +13 -0
- package/dist/errors-DBZfelEN.d.mts.map +1 -0
- package/dist/errors-DlRLQOyZ.cjs +27 -0
- package/dist/errors-DlRLQOyZ.cjs.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/proxy/caddy.cjs +167 -0
- package/dist/proxy/caddy.cjs.map +1 -0
- package/dist/proxy/caddy.d.cts +35 -0
- package/dist/proxy/caddy.d.cts.map +1 -0
- package/dist/proxy/caddy.d.mts +35 -0
- package/dist/proxy/caddy.d.mts.map +1 -0
- package/dist/proxy/caddy.mjs +164 -0
- package/dist/proxy/caddy.mjs.map +1 -0
- package/dist/proxy/traefik.cjs +460 -0
- package/dist/proxy/traefik.cjs.map +1 -0
- package/dist/proxy/traefik.d.cts +129 -0
- package/dist/proxy/traefik.d.cts.map +1 -0
- package/dist/proxy/traefik.d.mts +129 -0
- package/dist/proxy/traefik.d.mts.map +1 -0
- package/dist/proxy/traefik.mjs +437 -0
- package/dist/proxy/traefik.mjs.map +1 -0
- package/dist/routes/index.cjs +49 -0
- package/dist/routes/index.cjs.map +1 -0
- package/dist/routes/index.d.cts +205 -0
- package/dist/routes/index.d.cts.map +1 -0
- package/dist/routes/index.d.mts +205 -0
- package/dist/routes/index.d.mts.map +1 -0
- package/dist/routes/index.mjs +44 -0
- package/dist/routes/index.mjs.map +1 -0
- package/package.json +131 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caddy.mjs","names":[],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network: its service name. */\nfunction address({ service, port }: Upstream): string {\n\treturn `${service}:${port}`;\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_header @gkm_outside -${CLIENT_IP_HEADER}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;;AAmB7B,SAAS,QAAQ,EAAE,SAAS,QAA0B;CACrD,OAAO,GAAG,QAAQ,GAAG;AACtB;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW,CAAC,EACzE,UAAU;CACb,MAAM,WACL,KAAK,SAAS,cACX;;QAEG,IAAI,IAAI;MAEX;CACJ,MAAM,WAAW,GAAG,QAAQ,QAAQ,aAAa,QAAQ,UAAU,KAClE,QAAQ,cAAc,QAAQ,oCAAqC,KACjE;CACH,MAAM,SAAS,WAAW,IAAI,SAAS,OAAO;CAE9C,MAAM,cACL,IAAI,SAAS,UACV;OACE,IAAI,SAAS,GAAG,IAAI,QAAQ;IAE9B;CAIJ,MAAM,SAAS,CACd,GAAG,OAAO,QAAQ,UAAU,CAAC,MAAM,QAAQ,GAC3C,GAAG,OAAO,QAAQ,UAAU,MAAM,QAAQ,CAC3C,CAAC,CAAC,KAAK,UACN,UACC,OACA,QAAQ,WACR,MAAM,UAAU,IAAI,SA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,IAAI;CAGX,MAAM,aAAa,MAAM,WAAW,SAAS,CAAC,EAAA,CAC5C,KACC,SAAS;;UAEH,KAAK,IAAI,YAAY;SACtB,MAAM,WAAW,GAAG;EAE3B,CAAC,CACA,KAAK,EAAE;CAET,OAAO,GAAG,MAAM,IAAI,cAAc,aAAa,SAAS,EAAE;EACzD,SAAS,KAAK;GACb;AACH;;AAGA,SAAS,WAAW,OAA0B;CAC7C,MAAM,EAAE,WAAW,QAAQ,cAAc;CACzC,MAAM,SAAS,YAAY,KAAK;CAChC,OAAO,SACJ;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,EAAE;YACtC,OAAO;sCACmB,OAAO;MAEzC;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,IAC9C,aAAa,SACV,KACA,YACG;;;uBAIA,KACD,OAAO;MAET;AAEL;;;;;;;;;AAUA,SAAS,YAAY,EAAE,UAA6B;CACnD,OAAO,SACJ;;;eAGW,OAAO;;uBAGlB;AACJ;AAEA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;AAqBf,SAAgB,aAAa,WAAuC;CACnE,IAAI,CAAC,WACJ,OAAO;;;mBAGU;CAElB,OAAO;;;;2BAImB,kBAAkB,GAAG,UAAU;gCAC1B;AAChC"}
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_compose = require("../compose-BHWyQvsD.cjs");
|
|
3
|
+
const require_routes_index = require("../routes/index.cjs");
|
|
4
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
5
|
+
let node_crypto = require("node:crypto");
|
|
6
|
+
let yaml = require("yaml");
|
|
7
|
+
//#region src/proxy/traefik.ts
|
|
8
|
+
/**
|
|
9
|
+
* The server's shared edge, rendered for Traefik: what the edge itself runs
|
|
10
|
+
* with, and what one stack registers with it.
|
|
11
|
+
*
|
|
12
|
+
* One Traefik per server owns 80 and 443, the ACME state and the redirect to
|
|
13
|
+
* HTTPS. It is configured through its file provider alone: each stack writes
|
|
14
|
+
* one file — its routers, services and middlewares, every name prefixed with
|
|
15
|
+
* its compose project — into a directory the edge watches, and removes it
|
|
16
|
+
* when it stops. There is no Docker socket: the edge never learns what runs
|
|
17
|
+
* on the server except from those files.
|
|
18
|
+
*
|
|
19
|
+
* The edge and the stacks meet on one external Docker network. Only a
|
|
20
|
+
* stack's public services join it, each under an alias prefixed with its
|
|
21
|
+
* project (`<project>-api`), because the network is shared: a bare service
|
|
22
|
+
* name there would be answered by every stack's `api`.
|
|
23
|
+
*
|
|
24
|
+
* Pure but for the edge's name, read from the environment once (see
|
|
25
|
+
* {@link EDGE_PROJECT_ENV}): the documents are data, and the edge's side
|
|
26
|
+
* effects are `edge.ts`'s.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* The image, pinned: the edge is every stack's way in, so a new version is a
|
|
30
|
+
* change to this line, not whatever `latest` is on the day a server starts.
|
|
31
|
+
*/
|
|
32
|
+
const TRAEFIK_IMAGE = "traefik:v3.7.13";
|
|
33
|
+
/** The edge's name when nothing renames it: one per server. */
|
|
34
|
+
const DEFAULT_EDGE_PROJECT = "gkm-edge";
|
|
35
|
+
/**
|
|
36
|
+
* The variable that renames the edge — its compose project, and with it its
|
|
37
|
+
* network and its volumes (`<project>_acme`, `_certs`, `_dynamic`). A testing
|
|
38
|
+
* and advanced knob: an end-to-end suite runs an edge of its own beside a
|
|
39
|
+
* developer's, and never touches theirs. Every command that registers with
|
|
40
|
+
* one edge must be run with the same value.
|
|
41
|
+
*/
|
|
42
|
+
const EDGE_PROJECT_ENV = "GKM_EDGE_PROJECT";
|
|
43
|
+
/** The edge's compose project: `GKM_EDGE_PROJECT`, else `gkm-edge`. */
|
|
44
|
+
function edgeProject(env = process.env) {
|
|
45
|
+
return env["GKM_EDGE_PROJECT"] || "gkm-edge";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The edge's compose project, one per server — read once, when gkm starts,
|
|
49
|
+
* so every step of a run names the same edge.
|
|
50
|
+
*/
|
|
51
|
+
const EDGE_PROJECT = edgeProject();
|
|
52
|
+
/**
|
|
53
|
+
* The external network the edge and every stack's public services share:
|
|
54
|
+
* named after the edge, so a renamed edge has a network of its own.
|
|
55
|
+
*/
|
|
56
|
+
const EDGE_NETWORK = EDGE_PROJECT;
|
|
57
|
+
/** The edge's compose service. */
|
|
58
|
+
const EDGE_SERVICE = "traefik";
|
|
59
|
+
/** Inside the edge's container: what it watches, and where certificates are. */
|
|
60
|
+
const EDGE_DYNAMIC_DIR = "/etc/gkm-edge/dynamic";
|
|
61
|
+
const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
|
|
62
|
+
/** The certificate resolver every deployed route without its own certificate uses. */
|
|
63
|
+
const ACME_RESOLVER = "letsencrypt";
|
|
64
|
+
/**
|
|
65
|
+
* The resolver a wildcard site's `*.<domain>` certificate comes from: Let's
|
|
66
|
+
* Encrypt issues a wildcard only over the DNS challenge, which the edge
|
|
67
|
+
* answers by writing an `_acme-challenge` TXT record through Route 53.
|
|
68
|
+
*/
|
|
69
|
+
const ACME_DNS_RESOLVER = "letsencrypt-dns";
|
|
70
|
+
/**
|
|
71
|
+
* The key the edge writes those records with, inside its container: written
|
|
72
|
+
* by the deploy of a stage with a wildcard site, and allowed nothing but
|
|
73
|
+
* each such stage's `_acme-challenge` record (see `acmeDns.ts`).
|
|
74
|
+
*/
|
|
75
|
+
const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;
|
|
76
|
+
/** The internal entrypoint the edge's health check asks; never published. */
|
|
77
|
+
const PING_PORT = 8082;
|
|
78
|
+
/** A stack's service, as the edge — and the stack itself — reach it. */
|
|
79
|
+
function edgeAlias(project, service) {
|
|
80
|
+
return `${project}-${service}`;
|
|
81
|
+
}
|
|
82
|
+
/** A stack's certificate, as the edge's container reads it. */
|
|
83
|
+
function edgeCertificatePaths(project) {
|
|
84
|
+
return {
|
|
85
|
+
certFile: `${EDGE_CERTS_DIR}/${project}.crt`,
|
|
86
|
+
keyFile: `${EDGE_CERTS_DIR}/${project}.key`
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The edge's static configuration: the entrypoints, the redirect, ACME, and
|
|
91
|
+
* the directory it watches. No API and no dashboard — nothing about the edge
|
|
92
|
+
* is reachable but the routes stacks register.
|
|
93
|
+
*/
|
|
94
|
+
function traefikStatic(ports) {
|
|
95
|
+
return {
|
|
96
|
+
global: {
|
|
97
|
+
checkNewVersion: false,
|
|
98
|
+
sendAnonymousUsage: false
|
|
99
|
+
},
|
|
100
|
+
entryPoints: {
|
|
101
|
+
web: {
|
|
102
|
+
address: ":80",
|
|
103
|
+
http: { redirections: { entryPoint: {
|
|
104
|
+
to: ports.https === 443 ? "websecure" : `:${ports.https}`,
|
|
105
|
+
scheme: "https",
|
|
106
|
+
permanent: true
|
|
107
|
+
} } }
|
|
108
|
+
},
|
|
109
|
+
websecure: { address: ":443" },
|
|
110
|
+
ping: { address: `:${PING_PORT}` }
|
|
111
|
+
},
|
|
112
|
+
ping: { entryPoint: "ping" },
|
|
113
|
+
providers: { file: {
|
|
114
|
+
directory: EDGE_DYNAMIC_DIR,
|
|
115
|
+
watch: true
|
|
116
|
+
} },
|
|
117
|
+
certificatesResolvers: {
|
|
118
|
+
[ACME_RESOLVER]: { acme: {
|
|
119
|
+
storage: "/acme/acme.json",
|
|
120
|
+
httpChallenge: { entryPoint: "web" }
|
|
121
|
+
} },
|
|
122
|
+
[ACME_DNS_RESOLVER]: { acme: {
|
|
123
|
+
storage: "/acme/acme-dns.json",
|
|
124
|
+
dnsChallenge: {
|
|
125
|
+
provider: "route53",
|
|
126
|
+
resolvers: ["1.1.1.1:53", "8.8.8.8:53"]
|
|
127
|
+
}
|
|
128
|
+
} }
|
|
129
|
+
},
|
|
130
|
+
log: { level: "INFO" }
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** The edge's compose document. */
|
|
134
|
+
function edgeCompose(options) {
|
|
135
|
+
const { ports } = options;
|
|
136
|
+
return {
|
|
137
|
+
name: EDGE_PROJECT,
|
|
138
|
+
services: { [EDGE_SERVICE]: {
|
|
139
|
+
image: TRAEFIK_IMAGE,
|
|
140
|
+
restart: "unless-stopped",
|
|
141
|
+
ports: [`${ports.https}:443`, `${ports.http}:80`],
|
|
142
|
+
configs: [{
|
|
143
|
+
source: "traefik",
|
|
144
|
+
target: "/etc/traefik/traefik.yml"
|
|
145
|
+
}],
|
|
146
|
+
volumes: [
|
|
147
|
+
`dynamic:${EDGE_DYNAMIC_DIR}`,
|
|
148
|
+
`certs:${EDGE_CERTS_DIR}`,
|
|
149
|
+
"acme:/acme"
|
|
150
|
+
],
|
|
151
|
+
labels: { "dev.geekmidas.edge.config": (0, node_crypto.createHash)("sha256").update(options.staticConfig).digest("hex").slice(0, 16) },
|
|
152
|
+
environment: {
|
|
153
|
+
AWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,
|
|
154
|
+
AWS_REGION: "us-east-1"
|
|
155
|
+
},
|
|
156
|
+
networks: ["edge"],
|
|
157
|
+
...require_routes_index.EDGE_LIMITS,
|
|
158
|
+
healthcheck: {
|
|
159
|
+
test: [
|
|
160
|
+
"CMD",
|
|
161
|
+
"traefik",
|
|
162
|
+
"healthcheck",
|
|
163
|
+
"--ping"
|
|
164
|
+
],
|
|
165
|
+
interval: "10s",
|
|
166
|
+
timeout: "5s",
|
|
167
|
+
retries: 5
|
|
168
|
+
},
|
|
169
|
+
logging: options.logging
|
|
170
|
+
} },
|
|
171
|
+
configs: { traefik: { content: require_compose.composeLiteral(options.staticConfig) } },
|
|
172
|
+
volumes: {
|
|
173
|
+
acme: {},
|
|
174
|
+
dynamic: {},
|
|
175
|
+
certs: {}
|
|
176
|
+
},
|
|
177
|
+
networks: { edge: {
|
|
178
|
+
name: EDGE_NETWORK,
|
|
179
|
+
external: true
|
|
180
|
+
} }
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** A stack's dynamic configuration, as an object. */
|
|
184
|
+
function traefikDynamic(routes, options) {
|
|
185
|
+
const { project, tls, edgeToken } = options;
|
|
186
|
+
const name = (route, suffix) => `${project}-${route.name}${suffix ? `-${suffix}` : ""}`;
|
|
187
|
+
const url = ({ service, port }) => `http://${edgeAlias(project, service)}:${port}`;
|
|
188
|
+
const routers = {};
|
|
189
|
+
const services = {};
|
|
190
|
+
const middlewares = {};
|
|
191
|
+
const strip = `${project}-strip-gkm-headers`;
|
|
192
|
+
if (routes.length > 0) middlewares[strip] = { headers: { customRequestHeaders: { [_geekmidas_manifest.CLIENT_IP_HEADER]: "" } } };
|
|
193
|
+
for (const route of routes) {
|
|
194
|
+
const chain = [strip];
|
|
195
|
+
const limited = /* @__PURE__ */ new Set();
|
|
196
|
+
if (route.allow) {
|
|
197
|
+
middlewares[name(route, "allow")] = { ipAllowList: { sourceRange: [...route.allow] } };
|
|
198
|
+
chain.push(name(route, "allow"));
|
|
199
|
+
}
|
|
200
|
+
if (route.auth) {
|
|
201
|
+
middlewares[name(route, "auth")] = { basicAuth: { users: [`${route.auth.user}:${route.auth.hash}`] } };
|
|
202
|
+
chain.push(name(route, "auth"));
|
|
203
|
+
}
|
|
204
|
+
if (route.limits?.handshakesPerMinute) {
|
|
205
|
+
const perMinute = route.limits.handshakesPerMinute;
|
|
206
|
+
middlewares[name(route, "rate")] = { rateLimit: {
|
|
207
|
+
average: perMinute,
|
|
208
|
+
period: "1m",
|
|
209
|
+
burst: perMinute
|
|
210
|
+
} };
|
|
211
|
+
chain.push(name(route, "rate"));
|
|
212
|
+
limited.add(name(route, "rate"));
|
|
213
|
+
}
|
|
214
|
+
if (route.limits?.connectionsPerIp) {
|
|
215
|
+
middlewares[name(route, "in-flight")] = { inFlightReq: { amount: route.limits.connectionsPerIp } };
|
|
216
|
+
chain.push(name(route, "in-flight"));
|
|
217
|
+
limited.add(name(route, "in-flight"));
|
|
218
|
+
}
|
|
219
|
+
if (route.prefix) {
|
|
220
|
+
middlewares[name(route, "prefix")] = { addPrefix: { prefix: route.prefix } };
|
|
221
|
+
chain.push(name(route, "prefix"));
|
|
222
|
+
}
|
|
223
|
+
require_routes_index.assertRouteRenderable(route);
|
|
224
|
+
const allowed = [...(route.paths ?? []).map((path) => `Path(\`${path}\`)`), ...(route.prefixes ?? []).map((prefix) => `PathPrefix(\`${prefix}\`)`)];
|
|
225
|
+
const paths = allowed.length ? ` && (${allowed.join(" || ")})` : "";
|
|
226
|
+
const header = route.requireHeader ? ` && Header(\`${route.requireHeader.name}\`, \`${route.requireHeader.value}\`)` : "";
|
|
227
|
+
const certificate = () => route.wildcard?.tls.kind === "dns" ? {
|
|
228
|
+
certResolver: ACME_DNS_RESOLVER,
|
|
229
|
+
domains: [{ main: `*.${route.wildcard.domain}` }]
|
|
230
|
+
} : tls.kind === "acme" ? { certResolver: ACME_RESOLVER } : {};
|
|
231
|
+
for (const handler of route.handlers ?? []) {
|
|
232
|
+
const handlerName = name(route, handler.name);
|
|
233
|
+
routers[handlerName] = {
|
|
234
|
+
rule: `${hostRule(route)} && (${handler.prefixes.map((prefix) => `PathPrefix(\`${prefix}\`)`).join(" || ")})`,
|
|
235
|
+
priority: 1e4,
|
|
236
|
+
entryPoints: ["websecure"],
|
|
237
|
+
service: handlerName,
|
|
238
|
+
middlewares: [strip],
|
|
239
|
+
tls: certificate()
|
|
240
|
+
};
|
|
241
|
+
services[handlerName] = { loadBalancer: { servers: handler.upstreams.map((upstream) => ({ url: url(upstream) })) } };
|
|
242
|
+
}
|
|
243
|
+
if (route.redirects?.hosts.length) {
|
|
244
|
+
const redirect = name(route, "redirect");
|
|
245
|
+
middlewares[redirect] = { redirectRegex: {
|
|
246
|
+
regex: "^https?://[^/]+(.*)$",
|
|
247
|
+
replacement: `${route.redirects.to}$\{1}`,
|
|
248
|
+
permanent: true
|
|
249
|
+
} };
|
|
250
|
+
route.redirects.hosts.forEach((host, index) => {
|
|
251
|
+
routers[name(route, `redirect-${index + 1}`)] = {
|
|
252
|
+
rule: `Host(\`${host}\`)`,
|
|
253
|
+
entryPoints: ["websecure"],
|
|
254
|
+
service: "noop@internal",
|
|
255
|
+
middlewares: [redirect],
|
|
256
|
+
tls: certificate()
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const rule = `${hostRule(route)}${paths}${header}`;
|
|
261
|
+
routers[name(route)] = {
|
|
262
|
+
rule,
|
|
263
|
+
...route.wildcard ? { priority: 1 } : {},
|
|
264
|
+
entryPoints: ["websecure"],
|
|
265
|
+
service: name(route),
|
|
266
|
+
middlewares: chain,
|
|
267
|
+
tls: certificate()
|
|
268
|
+
};
|
|
269
|
+
if (edgeToken && !route.prefix) {
|
|
270
|
+
const trusted = chain.slice(1).filter((m) => !limited.has(m));
|
|
271
|
+
routers[name(route, "stack")] = {
|
|
272
|
+
rule: `${rule} && Header(\`${_geekmidas_manifest.EDGE_TOKEN_HEADER}\`, \`${edgeToken}\`)`,
|
|
273
|
+
...route.wildcard ? { priority: 2 } : {},
|
|
274
|
+
entryPoints: ["websecure"],
|
|
275
|
+
service: name(route),
|
|
276
|
+
...trusted.length > 0 ? { middlewares: trusted } : {},
|
|
277
|
+
tls: certificate()
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
services[name(route)] = { loadBalancer: {
|
|
281
|
+
servers: route.upstreams.map((upstream) => ({ url: url(upstream) })),
|
|
282
|
+
...route.prefix ? { passHostHeader: false } : {},
|
|
283
|
+
...route.streaming ? { responseForwarding: { flushInterval: "-1ms" } } : {},
|
|
284
|
+
...route.health ? { healthCheck: {
|
|
285
|
+
path: route.health,
|
|
286
|
+
interval: "5s",
|
|
287
|
+
timeout: "3s"
|
|
288
|
+
} } : {}
|
|
289
|
+
} };
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
http: {
|
|
293
|
+
routers,
|
|
294
|
+
services,
|
|
295
|
+
...Object.keys(middlewares).length > 0 ? { middlewares } : {}
|
|
296
|
+
},
|
|
297
|
+
...tls.kind === "files" ? { tls: { certificates: [{
|
|
298
|
+
certFile: tls.certFile,
|
|
299
|
+
keyFile: tls.keyFile
|
|
300
|
+
}] } } : {}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* The hosts a route answers, as a Traefik rule: its own and its aliases', or
|
|
305
|
+
* — for a wildcard site — exactly one label under its domain, but the ones
|
|
306
|
+
* it never takes. One label, as a wildcard certificate covers: a stage at
|
|
307
|
+
* `staging.example.com` is never reached through `example.com`'s wildcard.
|
|
308
|
+
*
|
|
309
|
+
* Several hosts are parenthesised, `(Host(a) || Host(b))`, so whatever is
|
|
310
|
+
* joined to the rule with `&&` — the path allowlist, a required header, the
|
|
311
|
+
* stack's token — holds on every one of them. One router's hosts are one
|
|
312
|
+
* certificate's names under ACME.
|
|
313
|
+
*/
|
|
314
|
+
function hostRule(route) {
|
|
315
|
+
if (!route.wildcard) {
|
|
316
|
+
const hosts = [route.host, ...route.aliases ?? []].map((host) => `Host(\`${host}\`)`);
|
|
317
|
+
return hosts.length === 1 ? hosts[0] : `(${hosts.join(" || ")})`;
|
|
318
|
+
}
|
|
319
|
+
const { domain, except } = route.wildcard;
|
|
320
|
+
return [`HostRegexp(\`${`^[a-z0-9-]+\\.${domain.replace(/\./g, "\\.")}$`}\`)`, ...except.map((label) => `!Host(\`${label}.${domain}\`)`)].join(" && ");
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* What a stack's routes claim on the edge, from the route model: one claim
|
|
324
|
+
* per host, each route's aliases and redirects included.
|
|
325
|
+
*/
|
|
326
|
+
function edgeClaims(routes) {
|
|
327
|
+
return routes.flatMap((route) => route.wildcard ? [{
|
|
328
|
+
wildcard: route.wildcard.domain.toLowerCase(),
|
|
329
|
+
except: [...route.wildcard.except]
|
|
330
|
+
}] : require_routes_index.routeHosts(route).map((host) => ({ host: host.toLowerCase() })));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* The comment line a stack's file carries its claims on: a comment, because
|
|
334
|
+
* Traefik's file provider refuses a whole file over a key it does not know,
|
|
335
|
+
* and gkm reads it back rather than taking the routers' rules apart.
|
|
336
|
+
*/
|
|
337
|
+
const CLAIMS_PREFIX = "# gkm-claims: ";
|
|
338
|
+
/**
|
|
339
|
+
* The hosts a stack's file on the edge claims: from its claims line, or — a
|
|
340
|
+
* file written before gkm wrote one — from its routers' rules, in the shapes
|
|
341
|
+
* `traefikDynamic` renders them.
|
|
342
|
+
*/
|
|
343
|
+
function readEdgeClaims(file) {
|
|
344
|
+
for (const line of file.split("\n")) {
|
|
345
|
+
if (!line.startsWith(CLAIMS_PREFIX)) continue;
|
|
346
|
+
try {
|
|
347
|
+
const claims = JSON.parse(line.slice(14));
|
|
348
|
+
if (Array.isArray(claims)) return claims.filter(isClaim);
|
|
349
|
+
} catch {}
|
|
350
|
+
}
|
|
351
|
+
let document;
|
|
352
|
+
try {
|
|
353
|
+
document = (0, yaml.parse)(file);
|
|
354
|
+
} catch {
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
const routers = document?.http?.routers;
|
|
358
|
+
if (!routers || typeof routers !== "object") return [];
|
|
359
|
+
const claims = [];
|
|
360
|
+
for (const router of Object.values(routers)) {
|
|
361
|
+
const rule = router?.rule;
|
|
362
|
+
if (typeof rule === "string") claims.push(...ruleClaims(rule));
|
|
363
|
+
}
|
|
364
|
+
return claims;
|
|
365
|
+
}
|
|
366
|
+
function isClaim(value) {
|
|
367
|
+
if (!value || typeof value !== "object") return false;
|
|
368
|
+
const claim = value;
|
|
369
|
+
return typeof claim.host === "string" || typeof claim.wildcard === "string" && Array.isArray(claim.except);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The hosts a rule matches: each `Host(\`a\`)` not negated, and a
|
|
373
|
+
* `HostRegexp` of a wildcard site — one label under a domain — with the
|
|
374
|
+
* `!Host` labels it leaves out.
|
|
375
|
+
*/
|
|
376
|
+
function ruleClaims(rule) {
|
|
377
|
+
const negated = [...rule.matchAll(/!\s*Host\(`([^`]+)`\)/g)].map((match) => match[1].toLowerCase());
|
|
378
|
+
const wildcard = /HostRegexp\(`\^\[a-z0-9-\]\+\\\.(.+)\$`\)/.exec(rule);
|
|
379
|
+
if (wildcard) {
|
|
380
|
+
const domain = wildcard[1].replace(/\\\./g, ".").toLowerCase();
|
|
381
|
+
const suffix = `.${domain}`;
|
|
382
|
+
return [{
|
|
383
|
+
wildcard: domain,
|
|
384
|
+
except: negated.filter((host) => host.endsWith(suffix)).map((host) => host.slice(0, -suffix.length))
|
|
385
|
+
}];
|
|
386
|
+
}
|
|
387
|
+
return [...rule.matchAll(/(?<![!\w])Host\(`([^`]+)`\)/g)].map((match) => ({ host: match[1].toLowerCase() }));
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Where two claims meet, as a host to name — or undefined where they never
|
|
391
|
+
* do. A wildcard takes one label under its domain, so it meets a name one
|
|
392
|
+
* label under it that it does not leave out, and another wildcard on the
|
|
393
|
+
* same domain.
|
|
394
|
+
*/
|
|
395
|
+
function claimsOverlap(a, b) {
|
|
396
|
+
if ("host" in a && "host" in b) return a.host === b.host ? a.host : void 0;
|
|
397
|
+
if ("wildcard" in a && "wildcard" in b) return a.wildcard === b.wildcard ? `*.${a.wildcard}` : void 0;
|
|
398
|
+
const [name, wildcard] = "host" in a ? [a, b] : [b, a];
|
|
399
|
+
const suffix = `.${wildcard.wildcard}`;
|
|
400
|
+
if (!name.host.endsWith(suffix)) return void 0;
|
|
401
|
+
const label = name.host.slice(0, -suffix.length);
|
|
402
|
+
if (!/^[a-z0-9-]+$/.test(label) || wildcard.except.includes(label)) return;
|
|
403
|
+
return name.host;
|
|
404
|
+
}
|
|
405
|
+
/** A stack's dynamic configuration file, as written to the edge's directory. */
|
|
406
|
+
function traefikDynamicFile(routes, options) {
|
|
407
|
+
return `# Generated by gkm compose for ${options.project} — do not edit.
|
|
408
|
+
# The shared edge (${EDGE_PROJECT}) reads every file in this directory; this
|
|
409
|
+
# one is removed by gkm compose --down. The hosts it routes, which no other
|
|
410
|
+
# stack on the edge may route:
|
|
411
|
+
${CLAIMS_PREFIX}${JSON.stringify(edgeClaims(routes))}
|
|
412
|
+
${yaml$1(traefikDynamic(routes, options))}`;
|
|
413
|
+
}
|
|
414
|
+
/** The edge's static configuration file. */
|
|
415
|
+
function traefikStaticFile(ports) {
|
|
416
|
+
return `# Generated by gkm compose — the server's shared edge. Do not edit.
|
|
417
|
+
${yaml$1(traefikStatic(ports))}`;
|
|
418
|
+
}
|
|
419
|
+
/** The edge's compose file. */
|
|
420
|
+
function edgeComposeFile(options) {
|
|
421
|
+
return `# Generated by gkm compose — the server's shared edge. Do not edit.
|
|
422
|
+
#
|
|
423
|
+
# Started by the first stack that runs with proxy: 'traefik', and left
|
|
424
|
+
# running by gkm compose --down. Stop it, once nothing uses it, with:
|
|
425
|
+
#
|
|
426
|
+
# docker compose -p ${EDGE_PROJECT} down
|
|
427
|
+
${yaml$1(edgeCompose(options))}`;
|
|
428
|
+
}
|
|
429
|
+
function yaml$1(value) {
|
|
430
|
+
return (0, yaml.stringify)(value, {
|
|
431
|
+
lineWidth: 0,
|
|
432
|
+
aliasDuplicateObjects: false
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
//#endregion
|
|
436
|
+
exports.ACME_DNS_RESOLVER = ACME_DNS_RESOLVER;
|
|
437
|
+
exports.ACME_RESOLVER = ACME_RESOLVER;
|
|
438
|
+
exports.DEFAULT_EDGE_PROJECT = DEFAULT_EDGE_PROJECT;
|
|
439
|
+
exports.EDGE_AWS_CREDENTIALS = EDGE_AWS_CREDENTIALS;
|
|
440
|
+
exports.EDGE_CERTS_DIR = EDGE_CERTS_DIR;
|
|
441
|
+
exports.EDGE_DYNAMIC_DIR = EDGE_DYNAMIC_DIR;
|
|
442
|
+
exports.EDGE_NETWORK = EDGE_NETWORK;
|
|
443
|
+
exports.EDGE_PROJECT = EDGE_PROJECT;
|
|
444
|
+
exports.EDGE_PROJECT_ENV = EDGE_PROJECT_ENV;
|
|
445
|
+
exports.EDGE_SERVICE = EDGE_SERVICE;
|
|
446
|
+
exports.TRAEFIK_IMAGE = TRAEFIK_IMAGE;
|
|
447
|
+
exports.claimsOverlap = claimsOverlap;
|
|
448
|
+
exports.edgeAlias = edgeAlias;
|
|
449
|
+
exports.edgeCertificatePaths = edgeCertificatePaths;
|
|
450
|
+
exports.edgeClaims = edgeClaims;
|
|
451
|
+
exports.edgeCompose = edgeCompose;
|
|
452
|
+
exports.edgeComposeFile = edgeComposeFile;
|
|
453
|
+
exports.edgeProject = edgeProject;
|
|
454
|
+
exports.readEdgeClaims = readEdgeClaims;
|
|
455
|
+
exports.traefikDynamic = traefikDynamic;
|
|
456
|
+
exports.traefikDynamicFile = traefikDynamicFile;
|
|
457
|
+
exports.traefikStatic = traefikStatic;
|
|
458
|
+
exports.traefikStaticFile = traefikStaticFile;
|
|
459
|
+
|
|
460
|
+
//# sourceMappingURL=traefik.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traefik.cjs","names":["createHash","EDGE_LIMITS","composeLiteral","CLIENT_IP_HEADER","EDGE_TOKEN_HEADER","routeHosts","parse","yaml","stringify"],"sources":["../../src/proxy/traefik.ts"],"sourcesContent":["/**\n * The server's shared edge, rendered for Traefik: what the edge itself runs\n * with, and what one stack registers with it.\n *\n * One Traefik per server owns 80 and 443, the ACME state and the redirect to\n * HTTPS. It is configured through its file provider alone: each stack writes\n * one file — its routers, services and middlewares, every name prefixed with\n * its compose project — into a directory the edge watches, and removes it\n * when it stops. There is no Docker socket: the edge never learns what runs\n * on the server except from those files.\n *\n * The edge and the stacks meet on one external Docker network. Only a\n * stack's public services join it, each under an alias prefixed with its\n * project (`<project>-api`), because the network is shared: a bare service\n * name there would be answered by every stack's `api`.\n *\n * Pure but for the edge's name, read from the environment once (see\n * {@link EDGE_PROJECT_ENV}): the documents are data, and the edge's side\n * effects are `edge.ts`'s.\n */\n\nimport { createHash } from 'node:crypto';\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport { parse, stringify } from 'yaml';\nimport { composeLiteral } from '../compose';\nimport {\n\tassertRouteRenderable,\n\tEDGE_LIMITS,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\trouteHosts,\n\ttype Upstream,\n} from '../routes';\n\n/**\n * The image, pinned: the edge is every stack's way in, so a new version is a\n * change to this line, not whatever `latest` is on the day a server starts.\n */\nexport const TRAEFIK_IMAGE = 'traefik:v3.7.13';\n\n/** The edge's name when nothing renames it: one per server. */\nexport const DEFAULT_EDGE_PROJECT = 'gkm-edge';\n\n/**\n * The variable that renames the edge — its compose project, and with it its\n * network and its volumes (`<project>_acme`, `_certs`, `_dynamic`). A testing\n * and advanced knob: an end-to-end suite runs an edge of its own beside a\n * developer's, and never touches theirs. Every command that registers with\n * one edge must be run with the same value.\n */\nexport const EDGE_PROJECT_ENV = 'GKM_EDGE_PROJECT';\n\n/** The edge's compose project: `GKM_EDGE_PROJECT`, else `gkm-edge`. */\nexport function edgeProject(env: NodeJS.ProcessEnv = process.env): string {\n\treturn env[EDGE_PROJECT_ENV] || DEFAULT_EDGE_PROJECT;\n}\n\n/**\n * The edge's compose project, one per server — read once, when gkm starts,\n * so every step of a run names the same edge.\n */\nexport const EDGE_PROJECT = edgeProject();\n\n/**\n * The external network the edge and every stack's public services share:\n * named after the edge, so a renamed edge has a network of its own.\n */\nexport const EDGE_NETWORK = EDGE_PROJECT;\n\n/** The edge's compose service. */\nexport const EDGE_SERVICE = 'traefik';\n\n/** Inside the edge's container: what it watches, and where certificates are. */\nexport const EDGE_DYNAMIC_DIR = '/etc/gkm-edge/dynamic';\nexport const EDGE_CERTS_DIR = '/etc/gkm-edge/certs';\n\n/** The certificate resolver every deployed route without its own certificate uses. */\nexport const ACME_RESOLVER = 'letsencrypt';\n\n/**\n * The resolver a wildcard site's `*.<domain>` certificate comes from: Let's\n * Encrypt issues a wildcard only over the DNS challenge, which the edge\n * answers by writing an `_acme-challenge` TXT record through Route 53.\n */\nexport const ACME_DNS_RESOLVER = 'letsencrypt-dns';\n\n/**\n * The key the edge writes those records with, inside its container: written\n * by the deploy of a stage with a wildcard site, and allowed nothing but\n * each such stage's `_acme-challenge` record (see `acmeDns.ts`).\n */\nexport const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;\n\n/** The internal entrypoint the edge's health check asks; never published. */\nconst PING_PORT = 8082;\n\n/** A stack's service, as the edge — and the stack itself — reach it. */\nexport function edgeAlias(project: string, service: string): string {\n\treturn `${project}-${service}`;\n}\n\n/** A stack's certificate, as the edge's container reads it. */\nexport function edgeCertificatePaths(project: string): {\n\tcertFile: string;\n\tkeyFile: string;\n} {\n\treturn {\n\t\tcertFile: `${EDGE_CERTS_DIR}/${project}.crt`,\n\t\tkeyFile: `${EDGE_CERTS_DIR}/${project}.key`,\n\t};\n}\n\n/** The edge's ports on the host. */\nexport interface EdgePorts {\n\thttps: number;\n\thttp: number;\n}\n\n/**\n * The edge's static configuration: the entrypoints, the redirect, ACME, and\n * the directory it watches. No API and no dashboard — nothing about the edge\n * is reachable but the routes stacks register.\n */\nexport function traefikStatic(ports: EdgePorts): Record<string, unknown> {\n\treturn {\n\t\tglobal: { checkNewVersion: false, sendAnonymousUsage: false },\n\t\tentryPoints: {\n\t\t\tweb: {\n\t\t\t\taddress: ':80',\n\t\t\t\thttp: {\n\t\t\t\t\t// Every plain-HTTP request is sent to HTTPS — but an ACME\n\t\t\t\t\t// HTTP-01 challenge, which Traefik answers before the redirect.\n\t\t\t\t\tredirections: {\n\t\t\t\t\t\tentryPoint: {\n\t\t\t\t\t\t\t// The published port when it is not 443, so the redirect\n\t\t\t\t\t\t\t// lands where the edge actually listens.\n\t\t\t\t\t\t\tto: ports.https === 443 ? 'websecure' : `:${ports.https}`,\n\t\t\t\t\t\t\tscheme: 'https',\n\t\t\t\t\t\t\tpermanent: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\twebsecure: { address: ':443' },\n\t\t\tping: { address: `:${PING_PORT}` },\n\t\t},\n\t\tping: { entryPoint: 'ping' },\n\t\tproviders: {\n\t\t\tfile: { directory: EDGE_DYNAMIC_DIR, watch: true },\n\t\t},\n\t\tcertificatesResolvers: {\n\t\t\t[ACME_RESOLVER]: {\n\t\t\t\tacme: {\n\t\t\t\t\tstorage: '/acme/acme.json',\n\t\t\t\t\thttpChallenge: { entryPoint: 'web' },\n\t\t\t\t},\n\t\t\t},\n\t\t\t[ACME_DNS_RESOLVER]: {\n\t\t\t\tacme: {\n\t\t\t\t\tstorage: '/acme/acme-dns.json',\n\t\t\t\t\tdnsChallenge: {\n\t\t\t\t\t\tprovider: 'route53',\n\t\t\t\t\t\t// Asked directly, so the record is seen as soon as Route 53\n\t\t\t\t\t\t// serves it rather than when a cache on the server expires.\n\t\t\t\t\t\tresolvers: ['1.1.1.1:53', '8.8.8.8:53'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tlog: { level: 'INFO' },\n\t};\n}\n\n/** The edge's compose document. */\nexport function edgeCompose(options: {\n\tports: EdgePorts;\n\t/**\n\t * The static configuration, as written: handed to the container inline\n\t * (`configs.content`), so nothing is read from a path on whichever machine\n\t * runs the deploy — and its hash recreates the edge when it changes.\n\t */\n\tstaticConfig: string;\n\tlogging: { driver: string; options: Record<string, string> };\n}): Record<string, unknown> {\n\tconst { ports } = options;\n\treturn {\n\t\tname: EDGE_PROJECT,\n\t\tservices: {\n\t\t\t[EDGE_SERVICE]: {\n\t\t\t\timage: TRAEFIK_IMAGE,\n\t\t\t\trestart: 'unless-stopped',\n\t\t\t\tports: [`${ports.https}:443`, `${ports.http}:80`],\n\t\t\t\tconfigs: [{ source: 'traefik', target: '/etc/traefik/traefik.yml' }],\n\t\t\t\tvolumes: [\n\t\t\t\t\t// Volumes on the server, written through the engine (`docker\n\t\t\t\t\t// exec`): each stack's routes and certificate, replaced by a\n\t\t\t\t\t// rename the file provider sees whole.\n\t\t\t\t\t`dynamic:${EDGE_DYNAMIC_DIR}`,\n\t\t\t\t\t`certs:${EDGE_CERTS_DIR}`,\n\t\t\t\t\t'acme:/acme',\n\t\t\t\t],\n\t\t\t\t// Static configuration is read at start: a change to it is a\n\t\t\t\t// change to the service, so `up` recreates the edge.\n\t\t\t\tlabels: {\n\t\t\t\t\t'dev.geekmidas.edge.config': createHash('sha256')\n\t\t\t\t\t\t.update(options.staticConfig)\n\t\t\t\t\t\t.digest('hex')\n\t\t\t\t\t\t.slice(0, 16),\n\t\t\t\t},\n\t\t\t\t// What the DNS challenge writes with: read from the file a stage\n\t\t\t\t// with a wildcard site puts there, and never needed otherwise.\n\t\t\t\tenvironment: {\n\t\t\t\t\tAWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,\n\t\t\t\t\tAWS_REGION: 'us-east-1',\n\t\t\t\t},\n\t\t\t\tnetworks: ['edge'],\n\t\t\t\t// Every stack on the server shares it, so it is sized for the one\n\t\t\t\t// that holds the most sockets — see `EDGE_LIMITS`.\n\t\t\t\t...EDGE_LIMITS,\n\t\t\t\thealthcheck: {\n\t\t\t\t\ttest: ['CMD', 'traefik', 'healthcheck', '--ping'],\n\t\t\t\t\tinterval: '10s',\n\t\t\t\t\ttimeout: '5s',\n\t\t\t\t\tretries: 5,\n\t\t\t\t},\n\t\t\t\tlogging: options.logging,\n\t\t\t},\n\t\t},\n\t\tconfigs: { traefik: { content: composeLiteral(options.staticConfig) } },\n\t\tvolumes: { acme: {}, dynamic: {}, certs: {} },\n\t\tnetworks: { edge: { name: EDGE_NETWORK, external: true } },\n\t};\n}\n\n/** What a stack registers with the edge — its routes, and its certificate. */\nexport interface TraefikStackOptions {\n\tproject: string;\n\t/** ACME, or the stage's own certificate. */\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n}\n\n/** A stack's dynamic configuration, as an object. */\nexport function traefikDynamic(\n\troutes: readonly EdgeRoute[],\n\toptions: TraefikStackOptions,\n): Record<string, unknown> {\n\tconst { project, tls, edgeToken } = options;\n\tconst name = (route: EdgeRoute, suffix?: string) =>\n\t\t`${project}-${route.name}${suffix ? `-${suffix}` : ''}`;\n\tconst url = ({ service, port }: Upstream) =>\n\t\t`http://${edgeAlias(project, service)}:${port}`;\n\n\tconst routers: Record<string, unknown> = {};\n\tconst services: Record<string, unknown> = {};\n\tconst middlewares: Record<string, unknown> = {};\n\n\t// gkm's own header, which only a service of this stack may send — the\n\t// auth server rate-limits by the client address it carries — removed from\n\t// every request that arrives from outside. An empty value is Traefik's\n\t// way of removing a request header. A request carrying the stack's token\n\t// is one of its own services calling a sibling through the edge: it is\n\t// matched by a router of its own, below, whose chain keeps the header.\n\tconst strip = `${project}-strip-gkm-headers`;\n\tif (routes.length > 0) {\n\t\tmiddlewares[strip] = {\n\t\t\theaders: { customRequestHeaders: { [CLIENT_IP_HEADER]: '' } },\n\t\t};\n\t}\n\n\tfor (const route of routes) {\n\t\tconst chain: string[] = [strip];\n\t\t// The client-address limits, which the stack's own services — all\n\t\t// behind one address — are not counted against.\n\t\tconst limited = new Set<string>();\n\t\tif (route.allow) {\n\t\t\t// The peer Traefik sees — never X-Forwarded-For, which a client\n\t\t\t// could set. Everything else gets 403.\n\t\t\tmiddlewares[name(route, 'allow')] = {\n\t\t\t\tipAllowList: { sourceRange: [...route.allow] },\n\t\t\t};\n\t\t\tchain.push(name(route, 'allow'));\n\t\t}\n\t\tif (route.auth) {\n\t\t\t// The stage's login, asked for before anything reaches the\n\t\t\t// upstream. The service's health check goes to the upstream\n\t\t\t// directly, so it is never asked.\n\t\t\tmiddlewares[name(route, 'auth')] = {\n\t\t\t\tbasicAuth: { users: [`${route.auth.user}:${route.auth.hash}`] },\n\t\t\t};\n\t\t\tchain.push(name(route, 'auth'));\n\t\t}\n\t\t// Per client address, as the edge — the first hop — sees it: an\n\t\t// upgrade past either is answered 429 before it reaches a replica.\n\t\t// An upgraded request stays in flight while its socket is open, so\n\t\t// `inFlightReq` counts open sockets.\n\t\tif (route.limits?.handshakesPerMinute) {\n\t\t\tconst perMinute = route.limits.handshakesPerMinute;\n\t\t\tmiddlewares[name(route, 'rate')] = {\n\t\t\t\trateLimit: { average: perMinute, period: '1m', burst: perMinute },\n\t\t\t};\n\t\t\tchain.push(name(route, 'rate'));\n\t\t\tlimited.add(name(route, 'rate'));\n\t\t}\n\t\tif (route.limits?.connectionsPerIp) {\n\t\t\tmiddlewares[name(route, 'in-flight')] = {\n\t\t\t\tinFlightReq: { amount: route.limits.connectionsPerIp },\n\t\t\t};\n\t\t\tchain.push(name(route, 'in-flight'));\n\t\t\tlimited.add(name(route, 'in-flight'));\n\t\t}\n\t\tif (route.prefix) {\n\t\t\tmiddlewares[name(route, 'prefix')] = {\n\t\t\t\taddPrefix: { prefix: route.prefix },\n\t\t\t};\n\t\t\tchain.push(name(route, 'prefix'));\n\t\t}\n\n\t\tassertRouteRenderable(route);\n\t\t// Only the paths it names, where it names some: a request for any\n\t\t// other matches no router, and the edge answers it 404 itself. So\n\t\t// does one without the header a CDN sends, where it requires one.\n\t\tconst allowed = [\n\t\t\t...(route.paths ?? []).map((path) => `Path(\\`${path}\\`)`),\n\t\t\t...(route.prefixes ?? []).map((prefix) => `PathPrefix(\\`${prefix}\\`)`),\n\t\t];\n\t\tconst paths = allowed.length ? ` && (${allowed.join(' || ')})` : '';\n\t\tconst header = route.requireHeader\n\t\t\t? ` && Header(\\`${route.requireHeader.name}\\`, \\`${route.requireHeader.value}\\`)`\n\t\t\t: '';\n\n\t\tconst certificate = (): Record<string, unknown> =>\n\t\t\troute.wildcard?.tls.kind === 'dns'\n\t\t\t\t? {\n\t\t\t\t\t\tcertResolver: ACME_DNS_RESOLVER,\n\t\t\t\t\t\tdomains: [{ main: `*.${route.wildcard.domain}` }],\n\t\t\t\t\t}\n\t\t\t\t: tls.kind === 'acme'\n\t\t\t\t\t? { certResolver: ACME_RESOLVER }\n\t\t\t\t\t: {};\n\n\t\t// Each handler: a router of its own on the same host, ahead of the\n\t\t// route's, to a service of its own.\n\t\tfor (const handler of route.handlers ?? []) {\n\t\t\tconst handlerName = name(route, handler.name);\n\t\t\trouters[handlerName] = {\n\t\t\t\t// Every host of the route, as its own router's rule has them.\n\t\t\t\trule: `${hostRule(route)} && (${handler.prefixes\n\t\t\t\t\t.map((prefix) => `PathPrefix(\\`${prefix}\\`)`)\n\t\t\t\t\t.join(' || ')})`,\n\t\t\t\t// Above the route's own router, whatever the rules' lengths.\n\t\t\t\tpriority: 10_000,\n\t\t\t\tentryPoints: ['websecure'],\n\t\t\t\tservice: handlerName,\n\t\t\t\tmiddlewares: [strip],\n\t\t\t\ttls: certificate(),\n\t\t\t};\n\t\t\tservices[handlerName] = {\n\t\t\t\tloadBalancer: {\n\t\t\t\t\tservers: handler.upstreams.map((upstream) => ({\n\t\t\t\t\t\turl: url(upstream),\n\t\t\t\t\t})),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Each redirect host: a router of its own, answering a permanent\n\t\t// redirect to the canonical host with the path and query it was asked\n\t\t// for. Nothing is behind it — Traefik's `noop` service never answers,\n\t\t// because the middleware always does first.\n\t\tif (route.redirects?.hosts.length) {\n\t\t\tconst redirect = name(route, 'redirect');\n\t\t\tmiddlewares[redirect] = {\n\t\t\t\tredirectRegex: {\n\t\t\t\t\tregex: '^https?://[^/]+(.*)$',\n\t\t\t\t\treplacement: `${route.redirects.to}$\\{1}`,\n\t\t\t\t\tpermanent: true,\n\t\t\t\t},\n\t\t\t};\n\t\t\troute.redirects.hosts.forEach((host, index) => {\n\t\t\t\trouters[name(route, `redirect-${index + 1}`)] = {\n\t\t\t\t\trule: `Host(\\`${host}\\`)`,\n\t\t\t\t\tentryPoints: ['websecure'],\n\t\t\t\t\tservice: 'noop@internal',\n\t\t\t\t\tmiddlewares: [redirect],\n\t\t\t\t\ttls: certificate(),\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\n\t\tconst rule = `${hostRule(route)}${paths}${header}`;\n\t\trouters[name(route)] = {\n\t\t\trule,\n\t\t\t// Below every named host's router, whatever the rules' lengths: a\n\t\t\t// wildcard site gets only the labels nothing else answers.\n\t\t\t...(route.wildcard ? { priority: 1 } : {}),\n\t\t\tentryPoints: ['websecure'],\n\t\t\tservice: name(route),\n\t\t\tmiddlewares: chain,\n\t\t\ttls: certificate(),\n\t\t};\n\t\t// The stack's own services, proven by its token: the same route, to\n\t\t// the same service, keeping gkm's header. Its longer rule puts it ahead\n\t\t// of the route's own; a wildcard's, just above that one's.\n\t\tif (edgeToken && !route.prefix) {\n\t\t\tconst trusted = chain.slice(1).filter((m) => !limited.has(m));\n\t\t\trouters[name(route, 'stack')] = {\n\t\t\t\trule: `${rule} && Header(\\`${EDGE_TOKEN_HEADER}\\`, \\`${edgeToken}\\`)`,\n\t\t\t\t...(route.wildcard ? { priority: 2 } : {}),\n\t\t\t\tentryPoints: ['websecure'],\n\t\t\t\tservice: name(route),\n\t\t\t\t...(trusted.length > 0 ? { middlewares: trusted } : {}),\n\t\t\t\ttls: certificate(),\n\t\t\t};\n\t\t}\n\n\t\tservices[name(route)] = {\n\t\t\tloadBalancer: {\n\t\t\t\tservers: route.upstreams.map((upstream) => ({ url: url(upstream) })),\n\t\t\t\t// A bucket is routed and signed on the Host header, so MinIO is\n\t\t\t\t// sent its own; an app is sent the one the caller used, which is\n\t\t\t\t// what it builds redirects, cookies and links on.\n\t\t\t\t...(route.prefix ? { passHostHeader: false } : {}),\n\t\t\t\t...(route.streaming\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t// Never buffer: each chunk of a streamed response is\n\t\t\t\t\t\t\t// flushed to the client as it is written.\n\t\t\t\t\t\t\tresponseForwarding: { flushInterval: '-1ms' },\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(route.health\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thealthCheck: {\n\t\t\t\t\t\t\t\tpath: route.health,\n\t\t\t\t\t\t\t\tinterval: '5s',\n\t\t\t\t\t\t\t\ttimeout: '3s',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\thttp: {\n\t\t\trouters,\n\t\t\tservices,\n\t\t\t...(Object.keys(middlewares).length > 0 ? { middlewares } : {}),\n\t\t},\n\t\t...(tls.kind === 'files'\n\t\t\t? {\n\t\t\t\t\ttls: {\n\t\t\t\t\t\tcertificates: [{ certFile: tls.certFile, keyFile: tls.keyFile }],\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n\n/**\n * The hosts a route answers, as a Traefik rule: its own and its aliases', or\n * — for a wildcard site — exactly one label under its domain, but the ones\n * it never takes. One label, as a wildcard certificate covers: a stage at\n * `staging.example.com` is never reached through `example.com`'s wildcard.\n *\n * Several hosts are parenthesised, `(Host(a) || Host(b))`, so whatever is\n * joined to the rule with `&&` — the path allowlist, a required header, the\n * stack's token — holds on every one of them. One router's hosts are one\n * certificate's names under ACME.\n */\nfunction hostRule(route: EdgeRoute): string {\n\tif (!route.wildcard) {\n\t\tconst hosts = [route.host, ...(route.aliases ?? [])].map(\n\t\t\t(host) => `Host(\\`${host}\\`)`,\n\t\t);\n\t\treturn hosts.length === 1 ? hosts[0]! : `(${hosts.join(' || ')})`;\n\t}\n\tconst { domain, except } = route.wildcard;\n\tconst pattern = `^[a-z0-9-]+\\\\.${domain.replace(/\\./g, '\\\\.')}$`;\n\treturn [\n\t\t`HostRegexp(\\`${pattern}\\`)`,\n\t\t...except.map((label) => `!Host(\\`${label}.${domain}\\`)`),\n\t].join(' && ');\n}\n\n/**\n * A host a stack routes on the shared edge: one name, or — for a wildcard\n * site — every one label under a domain but the ones it never takes.\n */\nexport type EdgeClaim =\n\t| { host: string }\n\t| { wildcard: string; except: readonly string[] };\n\n/**\n * What a stack's routes claim on the edge, from the route model: one claim\n * per host, each route's aliases and redirects included.\n */\nexport function edgeClaims(routes: readonly EdgeRoute[]): EdgeClaim[] {\n\treturn routes.flatMap((route): EdgeClaim[] =>\n\t\troute.wildcard\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\twildcard: route.wildcard.domain.toLowerCase(),\n\t\t\t\t\t\texcept: [...route.wildcard.except],\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: routeHosts(route).map((host) => ({ host: host.toLowerCase() })),\n\t);\n}\n\n/**\n * The comment line a stack's file carries its claims on: a comment, because\n * Traefik's file provider refuses a whole file over a key it does not know,\n * and gkm reads it back rather than taking the routers' rules apart.\n */\nconst CLAIMS_PREFIX = '# gkm-claims: ';\n\n/**\n * The hosts a stack's file on the edge claims: from its claims line, or — a\n * file written before gkm wrote one — from its routers' rules, in the shapes\n * `traefikDynamic` renders them.\n */\nexport function readEdgeClaims(file: string): EdgeClaim[] {\n\tfor (const line of file.split('\\n')) {\n\t\tif (!line.startsWith(CLAIMS_PREFIX)) continue;\n\t\ttry {\n\t\t\tconst claims = JSON.parse(line.slice(CLAIMS_PREFIX.length));\n\t\t\tif (Array.isArray(claims)) return claims.filter(isClaim);\n\t\t} catch {\n\t\t\t// A line that is not gkm's: the rules below still say.\n\t\t}\n\t}\n\tlet document: unknown;\n\ttry {\n\t\tdocument = parse(file);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst routers = (document as { http?: { routers?: unknown } } | null)?.http\n\t\t?.routers;\n\tif (!routers || typeof routers !== 'object') return [];\n\tconst claims: EdgeClaim[] = [];\n\tfor (const router of Object.values(routers)) {\n\t\tconst rule = (router as { rule?: unknown } | null)?.rule;\n\t\tif (typeof rule === 'string') claims.push(...ruleClaims(rule));\n\t}\n\treturn claims;\n}\n\nfunction isClaim(value: unknown): value is EdgeClaim {\n\tif (!value || typeof value !== 'object') return false;\n\tconst claim = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof claim.host === 'string' ||\n\t\t(typeof claim.wildcard === 'string' && Array.isArray(claim.except))\n\t);\n}\n\n/**\n * The hosts a rule matches: each `Host(\\`a\\`)` not negated, and a\n * `HostRegexp` of a wildcard site — one label under a domain — with the\n * `!Host` labels it leaves out.\n */\nfunction ruleClaims(rule: string): EdgeClaim[] {\n\tconst negated = [...rule.matchAll(/!\\s*Host\\(`([^`]+)`\\)/g)].map((match) =>\n\t\tmatch[1]!.toLowerCase(),\n\t);\n\tconst wildcard = /HostRegexp\\(`\\^\\[a-z0-9-\\]\\+\\\\\\.(.+)\\$`\\)/.exec(rule);\n\tif (wildcard) {\n\t\tconst domain = wildcard[1]!.replace(/\\\\\\./g, '.').toLowerCase();\n\t\tconst suffix = `.${domain}`;\n\t\treturn [\n\t\t\t{\n\t\t\t\twildcard: domain,\n\t\t\t\texcept: negated\n\t\t\t\t\t.filter((host) => host.endsWith(suffix))\n\t\t\t\t\t.map((host) => host.slice(0, -suffix.length)),\n\t\t\t},\n\t\t];\n\t}\n\treturn [...rule.matchAll(/(?<![!\\w])Host\\(`([^`]+)`\\)/g)].map((match) => ({\n\t\thost: match[1]!.toLowerCase(),\n\t}));\n}\n\n/**\n * Where two claims meet, as a host to name — or undefined where they never\n * do. A wildcard takes one label under its domain, so it meets a name one\n * label under it that it does not leave out, and another wildcard on the\n * same domain.\n */\nexport function claimsOverlap(a: EdgeClaim, b: EdgeClaim): string | undefined {\n\tif ('host' in a && 'host' in b) {\n\t\treturn a.host === b.host ? a.host : undefined;\n\t}\n\tif ('wildcard' in a && 'wildcard' in b) {\n\t\treturn a.wildcard === b.wildcard ? `*.${a.wildcard}` : undefined;\n\t}\n\tconst [name, wildcard] = ('host' in a ? [a, b] : [b, a]) as [\n\t\t{ host: string },\n\t\t{ wildcard: string; except: readonly string[] },\n\t];\n\tconst suffix = `.${wildcard.wildcard}`;\n\tif (!name.host.endsWith(suffix)) return undefined;\n\tconst label = name.host.slice(0, -suffix.length);\n\tif (!/^[a-z0-9-]+$/.test(label) || wildcard.except.includes(label)) {\n\t\treturn undefined;\n\t}\n\treturn name.host;\n}\n\n/** A stack's dynamic configuration file, as written to the edge's directory. */\nexport function traefikDynamicFile(\n\troutes: readonly EdgeRoute[],\n\toptions: TraefikStackOptions,\n): string {\n\treturn `# Generated by gkm compose for ${options.project} — do not edit.\n# The shared edge (${EDGE_PROJECT}) reads every file in this directory; this\n# one is removed by gkm compose --down. The hosts it routes, which no other\n# stack on the edge may route:\n${CLAIMS_PREFIX}${JSON.stringify(edgeClaims(routes))}\n${yaml(traefikDynamic(routes, options))}`;\n}\n\n/** The edge's static configuration file. */\nexport function traefikStaticFile(ports: EdgePorts): string {\n\treturn `# Generated by gkm compose — the server's shared edge. Do not edit.\n${yaml(traefikStatic(ports))}`;\n}\n\n/** The edge's compose file. */\nexport function edgeComposeFile(\n\toptions: Parameters<typeof edgeCompose>[0],\n): string {\n\treturn `# Generated by gkm compose — the server's shared edge. Do not edit.\n#\n# Started by the first stack that runs with proxy: 'traefik', and left\n# running by gkm compose --down. Stop it, once nothing uses it, with:\n#\n# docker compose -p ${EDGE_PROJECT} down\n${yaml(edgeCompose(options))}`;\n}\n\nfunction yaml(value: unknown): string {\n\treturn stringify(value, { lineWidth: 0, aliasDuplicateObjects: false });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,gBAAgB;;AAG7B,MAAa,uBAAuB;;;;;;;;AASpC,MAAa,mBAAmB;;AAGhC,SAAgB,YAAY,MAAyB,QAAQ,KAAa;CACzE,OAAO,IAAA,uBAAA;AACR;;;;;AAMA,MAAa,eAAe,YAAY;;;;;AAMxC,MAAa,eAAe;;AAG5B,MAAa,eAAe;;AAG5B,MAAa,mBAAmB;AAChC,MAAa,iBAAiB;;AAG9B,MAAa,gBAAgB;;;;;;AAO7B,MAAa,oBAAoB;;;;;;AAOjC,MAAa,uBAAuB,GAAG,eAAe;;AAGtD,MAAM,YAAY;;AAGlB,SA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