@geekmidas/edge 10.0.0-alpha.184 → 10.0.0-alpha.186
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-BVE0VFku.d.cts +427 -0
- package/dist/index-BVE0VFku.d.cts.map +1 -0
- package/dist/index-BVE0VFku.d.mts +427 -0
- package/dist/index-BVE0VFku.d.mts.map +1 -0
- package/dist/proxy/caddy.cjs +6 -4
- package/dist/proxy/caddy.cjs.map +1 -1
- package/dist/proxy/caddy.d.cts +1 -1
- package/dist/proxy/caddy.d.cts.map +1 -1
- package/dist/proxy/caddy.d.mts +1 -1
- package/dist/proxy/caddy.d.mts.map +1 -1
- package/dist/proxy/caddy.mjs +7 -5
- package/dist/proxy/caddy.mjs.map +1 -1
- package/dist/proxy/traefik.cjs +85 -18
- package/dist/proxy/traefik.cjs.map +1 -1
- package/dist/proxy/traefik.d.cts +2 -129
- package/dist/proxy/traefik.d.mts +2 -129
- package/dist/proxy/traefik.mjs +82 -20
- package/dist/proxy/traefik.mjs.map +1 -1
- package/dist/routes/index.cjs +12 -0
- package/dist/routes/index.cjs.map +1 -1
- package/dist/routes/index.d.cts +2 -205
- package/dist/routes/index.d.mts +2 -205
- package/dist/routes/index.mjs +11 -1
- package/dist/routes/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/proxy/traefik.d.cts.map +0 -1
- package/dist/proxy/traefik.d.mts.map +0 -1
- package/dist/routes/index.d.cts.map +0 -1
- package/dist/routes/index.d.mts.map +0 -1
package/dist/proxy/traefik.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as composeLiteral } from "../compose-CcNlj65h.mjs";
|
|
2
|
-
import { EDGE_LIMITS, assertRouteRenderable, routeHosts } from "../routes/index.mjs";
|
|
2
|
+
import { EDGE_LIMITS, HOST_GATEWAY, assertRouteRenderable, routeHosts, upstreamAddress } from "../routes/index.mjs";
|
|
3
3
|
import { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from "@geekmidas/manifest";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { parse, stringify } from "yaml";
|
|
@@ -61,17 +61,79 @@ const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
|
|
|
61
61
|
/** The certificate resolver every deployed route without its own certificate uses. */
|
|
62
62
|
const ACME_RESOLVER = "letsencrypt";
|
|
63
63
|
/**
|
|
64
|
-
* The
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* The key the edge writes Route 53's challenge records with, inside its
|
|
65
|
+
* container: written by the deploy of a stage with a wildcard site, and
|
|
66
|
+
* allowed nothing but each such stage's `_acme-challenge` record (see
|
|
67
|
+
* `acmeDns.ts`).
|
|
67
68
|
*/
|
|
69
|
+
const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;
|
|
70
|
+
/**
|
|
71
|
+
* Every DNS provider the edge can get a wildcard certificate through, by the
|
|
72
|
+
* name a workspace's `dns` entry gives it. Another provider is one entry
|
|
73
|
+
* here — lego's code for it and the variables it reads — and nothing else:
|
|
74
|
+
* its resolver, its ACME storage and its edge environment follow from it.
|
|
75
|
+
*
|
|
76
|
+
* Route 53's key is the one exception to "from the stage's secrets": the
|
|
77
|
+
* deploy issues it through IAM, scoped to the stage's challenge record
|
|
78
|
+
* alone, and writes it into the edge itself (`acmeDns.ts`).
|
|
79
|
+
*/
|
|
80
|
+
const ACME_DNS_CHALLENGES = {
|
|
81
|
+
route53: {
|
|
82
|
+
provider: "route53",
|
|
83
|
+
secrets: [],
|
|
84
|
+
environment: {
|
|
85
|
+
AWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,
|
|
86
|
+
AWS_REGION: "us-east-1"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
godaddy: {
|
|
90
|
+
provider: "godaddy",
|
|
91
|
+
secrets: ["GODADDY_API_KEY", "GODADDY_API_SECRET"]
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/** Whether the edge can answer the DNS challenge through `provider`. */
|
|
95
|
+
function isAcmeDnsProvider(provider) {
|
|
96
|
+
return typeof provider === "string" && Object.hasOwn(ACME_DNS_CHALLENGES, provider);
|
|
97
|
+
}
|
|
98
|
+
/** Route 53's DNS-challenge resolver — see {@link acmeDnsResolver}. */
|
|
68
99
|
const ACME_DNS_RESOLVER = "letsencrypt-dns";
|
|
69
100
|
/**
|
|
70
|
-
* The
|
|
71
|
-
*
|
|
72
|
-
*
|
|
101
|
+
* The resolver a wildcard site's `*.<domain>` certificate comes from, for
|
|
102
|
+
* the DNS provider that holds the domain: Let's Encrypt issues a wildcard
|
|
103
|
+
* only over the DNS challenge, which the edge answers by writing an
|
|
104
|
+
* `_acme-challenge` TXT record through that provider. Route 53's keeps the
|
|
105
|
+
* name it had before there were others, so its certificates stay where they
|
|
106
|
+
* are.
|
|
73
107
|
*/
|
|
74
|
-
|
|
108
|
+
function acmeDnsResolver(provider) {
|
|
109
|
+
return provider === "route53" ? ACME_DNS_RESOLVER : `${ACME_DNS_RESOLVER}-${provider}`;
|
|
110
|
+
}
|
|
111
|
+
/** Where a DNS-challenge resolver keeps its account and certificates. */
|
|
112
|
+
function acmeDnsStorage(provider) {
|
|
113
|
+
return provider === "route53" ? "/acme/acme-dns.json" : `/acme/acme-dns-${provider}.json`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A DNS provider's secret, inside the edge's container: one file per key,
|
|
117
|
+
* beside the certificates, readable by the edge alone.
|
|
118
|
+
*/
|
|
119
|
+
function edgeDnsSecretPath(key) {
|
|
120
|
+
return `${EDGE_CERTS_DIR}/acme-dns-${key}`;
|
|
121
|
+
}
|
|
122
|
+
/** Every stage secret the edge's DNS challenge reads, for any provider. */
|
|
123
|
+
const ACME_DNS_SECRET_KEYS = Object.values(ACME_DNS_CHALLENGES).flatMap((challenge) => [...challenge.secrets]);
|
|
124
|
+
/**
|
|
125
|
+
* What the edge's environment says for the DNS challenge, every provider's:
|
|
126
|
+
* where each key is read from, never a key.
|
|
127
|
+
*/
|
|
128
|
+
function acmeDnsEnvironment() {
|
|
129
|
+
const environment = {};
|
|
130
|
+
const challenges = Object.values(ACME_DNS_CHALLENGES);
|
|
131
|
+
for (const challenge of challenges) {
|
|
132
|
+
Object.assign(environment, challenge.environment);
|
|
133
|
+
for (const key of challenge.secrets) environment[`${key}_FILE`] = edgeDnsSecretPath(key);
|
|
134
|
+
}
|
|
135
|
+
return environment;
|
|
136
|
+
}
|
|
75
137
|
/** The internal entrypoint the edge's health check asks; never published. */
|
|
76
138
|
const PING_PORT = 8082;
|
|
77
139
|
/** A stack's service, as the edge — and the stack itself — reach it. */
|
|
@@ -118,13 +180,13 @@ function traefikStatic(ports) {
|
|
|
118
180
|
storage: "/acme/acme.json",
|
|
119
181
|
httpChallenge: { entryPoint: "web" }
|
|
120
182
|
} },
|
|
121
|
-
[
|
|
122
|
-
storage:
|
|
183
|
+
...Object.fromEntries(Object.entries(ACME_DNS_CHALLENGES).map(([name, challenge]) => [acmeDnsResolver(name), { acme: {
|
|
184
|
+
storage: acmeDnsStorage(name),
|
|
123
185
|
dnsChallenge: {
|
|
124
|
-
provider:
|
|
186
|
+
provider: challenge.provider,
|
|
125
187
|
resolvers: ["1.1.1.1:53", "8.8.8.8:53"]
|
|
126
188
|
}
|
|
127
|
-
} }
|
|
189
|
+
} }]))
|
|
128
190
|
},
|
|
129
191
|
log: { level: "INFO" }
|
|
130
192
|
};
|
|
@@ -148,11 +210,9 @@ function edgeCompose(options) {
|
|
|
148
210
|
"acme:/acme"
|
|
149
211
|
],
|
|
150
212
|
labels: { "dev.geekmidas.edge.config": createHash("sha256").update(options.staticConfig).digest("hex").slice(0, 16) },
|
|
151
|
-
environment:
|
|
152
|
-
AWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,
|
|
153
|
-
AWS_REGION: "us-east-1"
|
|
154
|
-
},
|
|
213
|
+
environment: acmeDnsEnvironment(),
|
|
155
214
|
networks: ["edge"],
|
|
215
|
+
extra_hosts: [`${HOST_GATEWAY}:host-gateway`],
|
|
156
216
|
...EDGE_LIMITS,
|
|
157
217
|
healthcheck: {
|
|
158
218
|
test: [
|
|
@@ -183,7 +243,7 @@ function edgeCompose(options) {
|
|
|
183
243
|
function traefikDynamic(routes, options) {
|
|
184
244
|
const { project, tls, edgeToken } = options;
|
|
185
245
|
const name = (route, suffix) => `${project}-${route.name}${suffix ? `-${suffix}` : ""}`;
|
|
186
|
-
const url = (
|
|
246
|
+
const url = (upstream) => `http://${upstreamAddress(upstream, (service) => edgeAlias(project, service))}`;
|
|
187
247
|
const routers = {};
|
|
188
248
|
const services = {};
|
|
189
249
|
const middlewares = {};
|
|
@@ -224,17 +284,19 @@ function traefikDynamic(routes, options) {
|
|
|
224
284
|
const paths = allowed.length ? ` && (${allowed.join(" || ")})` : "";
|
|
225
285
|
const header = route.requireHeader ? ` && Header(\`${route.requireHeader.name}\`, \`${route.requireHeader.value}\`)` : "";
|
|
226
286
|
const certificate = () => route.wildcard?.tls.kind === "dns" ? {
|
|
227
|
-
certResolver:
|
|
287
|
+
certResolver: acmeDnsResolver(route.wildcard.tls.provider),
|
|
228
288
|
domains: [{ main: `*.${route.wildcard.domain}` }]
|
|
229
289
|
} : tls.kind === "acme" ? { certResolver: ACME_RESOLVER } : {};
|
|
230
290
|
for (const handler of route.handlers ?? []) {
|
|
231
291
|
const handlerName = name(route, handler.name);
|
|
292
|
+
const under = name(route, `${handler.name}-under`);
|
|
293
|
+
if (handler.under) middlewares[under] = { addPrefix: { prefix: handler.under } };
|
|
232
294
|
routers[handlerName] = {
|
|
233
295
|
rule: `${hostRule(route)} && (${handler.prefixes.map((prefix) => `PathPrefix(\`${prefix}\`)`).join(" || ")})`,
|
|
234
296
|
priority: 1e4,
|
|
235
297
|
entryPoints: ["websecure"],
|
|
236
298
|
service: handlerName,
|
|
237
|
-
middlewares: [strip],
|
|
299
|
+
middlewares: handler.under ? [strip, under] : [strip],
|
|
238
300
|
tls: certificate()
|
|
239
301
|
};
|
|
240
302
|
services[handlerName] = { loadBalancer: { servers: handler.upstreams.map((upstream) => ({ url: url(upstream) })) } };
|
|
@@ -432,6 +494,6 @@ function yaml(value) {
|
|
|
432
494
|
});
|
|
433
495
|
}
|
|
434
496
|
//#endregion
|
|
435
|
-
export { ACME_DNS_RESOLVER, ACME_RESOLVER, DEFAULT_EDGE_PROJECT, EDGE_AWS_CREDENTIALS, EDGE_CERTS_DIR, EDGE_DYNAMIC_DIR, EDGE_NETWORK, EDGE_PROJECT, EDGE_PROJECT_ENV, EDGE_SERVICE, TRAEFIK_IMAGE, claimsOverlap, edgeAlias, edgeCertificatePaths, edgeClaims, edgeCompose, edgeComposeFile, edgeProject, readEdgeClaims, traefikDynamic, traefikDynamicFile, traefikStatic, traefikStaticFile };
|
|
497
|
+
export { ACME_DNS_CHALLENGES, ACME_DNS_RESOLVER, ACME_DNS_SECRET_KEYS, ACME_RESOLVER, DEFAULT_EDGE_PROJECT, EDGE_AWS_CREDENTIALS, EDGE_CERTS_DIR, EDGE_DYNAMIC_DIR, EDGE_NETWORK, EDGE_PROJECT, EDGE_PROJECT_ENV, EDGE_SERVICE, TRAEFIK_IMAGE, acmeDnsResolver, claimsOverlap, edgeAlias, edgeCertificatePaths, edgeClaims, edgeCompose, edgeComposeFile, edgeDnsSecretPath, edgeProject, isAcmeDnsProvider, readEdgeClaims, traefikDynamic, traefikDynamicFile, traefikStatic, traefikStaticFile };
|
|
436
498
|
|
|
437
499
|
//# sourceMappingURL=traefik.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traefik.mjs","names":[],"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;;;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G,CAAC,OAAO,MAAM;CAC/C,IAAI,CAAC,eAAe,KAAK,KAAK,KAAK,SAAS,OAAO,SAAS,KAAK,GAChE;CAED,OAAO,KAAK;AACb;;AAGA,SAAgB,mBACf,QACA,SACS;CACT,OAAO,kCAAkC,QAAQ,QAAQ;qBACrC,aAAa;;;EAGhC,gBAAgB,KAAK,UAAU,WAAW,MAAM,CAAC,EAAE;EACnD,KAAK,eAAe,QAAQ,OAAO,CAAC;AACtC;;AAGA,SAAgB,kBAAkB,OAA0B;CAC3D,OAAO;EACN,KAAK,cAAc,KAAK,CAAC;AAC3B;;AAGA,SAAgB,gBACf,SACS;CACT,OAAO;;;;;wBAKgB,aAAa;EACnC,KAAK,YAAY,OAAO,CAAC;AAC3B;AAEA,SAAS,KAAK,OAAwB;CACrC,OAAO,UAAU,OAAO;EAAE,WAAW;EAAG,uBAAuB;CAAM,CAAC;AACvE"}
|
|
1
|
+
{"version":3,"file":"traefik.mjs","names":[],"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\tHOST_GATEWAY,\n\trouteHosts,\n\ttype Upstream,\n\tupstreamAddress,\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 key the edge writes Route 53's challenge records with, inside its\n * container: written by the deploy of a stage with a wildcard site, and\n * allowed nothing but each such stage's `_acme-challenge` record (see\n * `acmeDns.ts`).\n */\nexport const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;\n\n/**\n * How the edge answers Let's Encrypt's DNS challenge through one DNS\n * provider: Traefik's (lego's) name for it, and what it reads.\n */\nexport interface AcmeDnsChallenge {\n\t/** The provider's code in Traefik's `dnsChallenge.provider`. */\n\tprovider: string;\n\t/**\n\t * The stage secrets the provider reads, by the variable lego reads each\n\t * from. The deploy writes each into its own file in the edge's container\n\t * (`0600`, see {@link edgeDnsSecretPath}), and the edge is handed only\n\t * the file's path, as `<KEY>_FILE` — which lego reads in place of `<KEY>`.\n\t * Never a value in the compose file or the static configuration.\n\t */\n\tsecrets: readonly string[];\n\t/** What else the edge's environment says for it — never a secret. */\n\tenvironment?: Readonly<Record<string, string>>;\n}\n\n/**\n * Every DNS provider the edge can get a wildcard certificate through, by the\n * name a workspace's `dns` entry gives it. Another provider is one entry\n * here — lego's code for it and the variables it reads — and nothing else:\n * its resolver, its ACME storage and its edge environment follow from it.\n *\n * Route 53's key is the one exception to \"from the stage's secrets\": the\n * deploy issues it through IAM, scoped to the stage's challenge record\n * alone, and writes it into the edge itself (`acmeDns.ts`).\n */\nexport const ACME_DNS_CHALLENGES = {\n\troute53: {\n\t\tprovider: 'route53',\n\t\tsecrets: [],\n\t\tenvironment: {\n\t\t\tAWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,\n\t\t\tAWS_REGION: 'us-east-1',\n\t\t},\n\t},\n\tgodaddy: {\n\t\tprovider: 'godaddy',\n\t\tsecrets: ['GODADDY_API_KEY', 'GODADDY_API_SECRET'],\n\t},\n} as const satisfies Record<string, AcmeDnsChallenge>;\n\n/** A DNS provider the edge answers the DNS challenge through. */\nexport type AcmeDnsProvider = keyof typeof ACME_DNS_CHALLENGES;\n\n/** Whether the edge can answer the DNS challenge through `provider`. */\nexport function isAcmeDnsProvider(\n\tprovider: unknown,\n): provider is AcmeDnsProvider {\n\treturn (\n\t\ttypeof provider === 'string' && Object.hasOwn(ACME_DNS_CHALLENGES, provider)\n\t);\n}\n\n/** Route 53's DNS-challenge resolver — see {@link acmeDnsResolver}. */\nexport const ACME_DNS_RESOLVER = 'letsencrypt-dns';\n\n/**\n * The resolver a wildcard site's `*.<domain>` certificate comes from, for\n * the DNS provider that holds the domain: Let's Encrypt issues a wildcard\n * only over the DNS challenge, which the edge answers by writing an\n * `_acme-challenge` TXT record through that provider. Route 53's keeps the\n * name it had before there were others, so its certificates stay where they\n * are.\n */\nexport function acmeDnsResolver(provider: AcmeDnsProvider): string {\n\treturn provider === 'route53'\n\t\t? ACME_DNS_RESOLVER\n\t\t: `${ACME_DNS_RESOLVER}-${provider}`;\n}\n\n/** Where a DNS-challenge resolver keeps its account and certificates. */\nfunction acmeDnsStorage(provider: AcmeDnsProvider): string {\n\treturn provider === 'route53'\n\t\t? '/acme/acme-dns.json'\n\t\t: `/acme/acme-dns-${provider}.json`;\n}\n\n/**\n * A DNS provider's secret, inside the edge's container: one file per key,\n * beside the certificates, readable by the edge alone.\n */\nexport function edgeDnsSecretPath(key: string): string {\n\treturn `${EDGE_CERTS_DIR}/acme-dns-${key}`;\n}\n\n/** Every stage secret the edge's DNS challenge reads, for any provider. */\nexport const ACME_DNS_SECRET_KEYS: readonly string[] = Object.values(\n\tACME_DNS_CHALLENGES,\n).flatMap((challenge) => [...challenge.secrets]);\n\n/**\n * What the edge's environment says for the DNS challenge, every provider's:\n * where each key is read from, never a key.\n */\nfunction acmeDnsEnvironment(): Record<string, string> {\n\tconst environment: Record<string, string> = {};\n\tconst challenges: readonly AcmeDnsChallenge[] =\n\t\tObject.values(ACME_DNS_CHALLENGES);\n\tfor (const challenge of challenges) {\n\t\tObject.assign(environment, challenge.environment);\n\t\tfor (const key of challenge.secrets) {\n\t\t\tenvironment[`${key}_FILE`] = edgeDnsSecretPath(key);\n\t\t}\n\t}\n\treturn environment;\n}\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// One per DNS provider, whichever the stacks on the server use: the\n\t\t\t// edge is shared, and a stage on another provider must not take\n\t\t\t// this one's resolver away.\n\t\t\t...Object.fromEntries(\n\t\t\t\tObject.entries(ACME_DNS_CHALLENGES).map(([name, challenge]) => [\n\t\t\t\t\tacmeDnsResolver(name as AcmeDnsProvider),\n\t\t\t\t\t{\n\t\t\t\t\t\tacme: {\n\t\t\t\t\t\t\tstorage: acmeDnsStorage(name as AcmeDnsProvider),\n\t\t\t\t\t\t\tdnsChallenge: {\n\t\t\t\t\t\t\t\tprovider: challenge.provider,\n\t\t\t\t\t\t\t\t// Asked directly, so the record is seen as soon as the\n\t\t\t\t\t\t\t\t// provider serves it rather than when a cache on the\n\t\t\t\t\t\t\t\t// server expires.\n\t\t\t\t\t\t\t\tresolvers: ['1.1.1.1:53', '8.8.8.8:53'],\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\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 files a stage\n\t\t\t\t// with a wildcard site puts there, and never needed otherwise.\n\t\t\t\t// Paths only — never a key.\n\t\t\t\tenvironment: acmeDnsEnvironment(),\n\t\t\t\tnetworks: ['edge'],\n\t\t\t\t// A process on the host — an app `gkm dev` runs — is reached\n\t\t\t\t// through the host's gateway. Docker Desktop resolves the name\n\t\t\t\t// already; on Linux it needs saying.\n\t\t\t\textra_hosts: [`${HOST_GATEWAY}:host-gateway`],\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\t// A service of the stack by its alias on the shared network; a process on\n\t// the host — an app `gkm dev` runs — through the host's gateway.\n\tconst url = (upstream: Upstream) =>\n\t\t`http://${upstreamAddress(upstream, (service) => edgeAlias(project, service))}`;\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: acmeDnsResolver(route.wildcard.tls.provider),\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\t// Sent under the path the upstream mounts it on, where it names one.\n\t\t\tconst under = name(route, `${handler.name}-under`);\n\t\t\tif (handler.under) {\n\t\t\t\tmiddlewares[under] = { addPrefix: { prefix: handler.under } };\n\t\t\t}\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: handler.under ? [strip, under] : [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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,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;;AAG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,KAAK,KAAK,SAAS,OAAO,SAAS,KAAK,GAChE;CAED,OAAO,KAAK;AACb;;AAGA,SAAgB,mBACf,QACA,SACS;CACT,OAAO,kCAAkC,QAAQ,QAAQ;qBACrC,aAAa;;;EAGhC,gBAAgB,KAAK,UAAU,WAAW,MAAM,CAAC,EAAE;EACnD,KAAK,eAAe,QAAQ,OAAO,CAAC;AACtC;;AAGA,SAAgB,kBAAkB,OAA0B;CAC3D,OAAO;EACN,KAAK,cAAc,KAAK,CAAC;AAC3B;;AAGA,SAAgB,gBACf,SACS;CACT,OAAO;;;;;wBAKgB,aAAa;EACnC,KAAK,YAAY,OAAO,CAAC;AAC3B;AAEA,SAAS,KAAK,OAAwB;CACrC,OAAO,UAAU,OAAO;EAAE,WAAW;EAAG,uBAAuB;CAAM,CAAC;AACvE"}
|
package/dist/routes/index.cjs
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/routes/index.ts
|
|
3
3
|
/**
|
|
4
|
+
* The host's own address, from inside a container. Docker Desktop resolves
|
|
5
|
+
* it already; on Linux the proxy's compose definition maps it to the host
|
|
6
|
+
* gateway (`extra_hosts`).
|
|
7
|
+
*/
|
|
8
|
+
const HOST_GATEWAY = "host.docker.internal";
|
|
9
|
+
/** An upstream's `host:port`, as a proxy on the stack's network dials it. */
|
|
10
|
+
function upstreamAddress(upstream, service = (name) => name) {
|
|
11
|
+
return "onHost" in upstream ? `${HOST_GATEWAY}:${upstream.port}` : `${service(upstream.service)}:${upstream.port}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
4
14
|
* Every host a route answers on — its own, its aliases and its redirects —
|
|
5
15
|
* in that order: what DNS, certificates and the edge's claims cover.
|
|
6
16
|
*/
|
|
@@ -42,8 +52,10 @@ const EDGE_LIMITS = {
|
|
|
42
52
|
//#endregion
|
|
43
53
|
exports.EDGE_LIMITS = EDGE_LIMITS;
|
|
44
54
|
exports.EdgeRouteConflict = EdgeRouteConflict;
|
|
55
|
+
exports.HOST_GATEWAY = HOST_GATEWAY;
|
|
45
56
|
exports.NOFILE = NOFILE;
|
|
46
57
|
exports.assertRouteRenderable = assertRouteRenderable;
|
|
47
58
|
exports.routeHosts = routeHosts;
|
|
59
|
+
exports.upstreamAddress = upstreamAddress;
|
|
48
60
|
|
|
49
61
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/routes/index.ts"],"sourcesContent":["/**\n * What a stack's edge serves, as data: one route per public host, and the\n * service behind it. Computed once by the stack, then rendered by whichever\n * proxy the stage runs — a Caddyfile for the stack's own Caddy, or a dynamic\n * config file for the server's shared Traefik — so the two never drift.\n *\n * Pure.\n */\n\n/** A service of the stack that a route sends to. */\nexport interface Upstream {\n\t/** Its compose service name — `api`, `minio`. */\n\tservice: string;\n\t/** The port it listens on, inside the network. */\n\tport: number;\n}\n\n/** One public host and what answers it. */\nexport interface EdgeRoute {\n\t/**\n\t * Its name within the stack — unique there, and what a renderer names\n\t * its routers and middlewares after: `api`, `files-uploads`.\n\t */\n\tname: string;\n\t/** e.g. `api.example.com` — the canonical host, its `<ID>_URL`'s. */\n\thost: string;\n\t/**\n\t * More hosts answered exactly as `host` is — a construct's `aliases`:\n\t * every check, handler and upstream of the route holds on each of them.\n\t */\n\taliases?: readonly string[];\n\t/**\n\t * Hosts answered with a permanent redirect to `to`, the canonical origin\n\t * (`https://example.com`, with the edge's port where it is not 443), path\n\t * and query kept — a site's `redirects`. Nothing is proxied for them.\n\t */\n\tredirects?: { hosts: readonly string[]; to: string };\n\t/**\n\t * Where requests go. One today; a release that swaps containers without\n\t * downtime routes to the old and the new while it does.\n\t */\n\tupstreams: readonly Upstream[];\n\t/**\n\t * Never buffer the response: a streamed one — server-sent events, a\n\t * Next.js RSC payload — reaches the client as each chunk is written.\n\t */\n\tstreaming: boolean;\n\t/**\n\t * A path prefix added before the request is sent, with the upstream's own\n\t * address as `Host`: a bucket, served at a host of its own, is a prefix\n\t * on MinIO, which routes and signs on the Host header.\n\t */\n\tprefix?: string;\n\t/**\n\t * The client addresses (IPs or CIDRs) it answers; every other is refused\n\t * with 403, before the request reaches the upstream. Absent, it answers\n\t * everyone. Matched against the peer the proxy sees, never a header a\n\t * client could set.\n\t */\n\tallow?: readonly string[];\n\t/**\n\t * The only paths it answers, matched exactly; every other is refused at\n\t * the edge, before the request reaches the upstream. Absent, it answers\n\t * every path. A worker is reached only on the routes SNS pushes to.\n\t */\n\tpaths?: readonly string[];\n\t/**\n\t * Path prefixes it answers besides `paths` — `/i/` admits everything\n\t * under it. Together they are the whole allowlist; absent both, it\n\t * answers every path. A processor unit's own host is reached only on its\n\t * processors' prefixes.\n\t */\n\tprefixes?: readonly string[];\n\t/**\n\t * A header every request must carry, with exactly this value; any other\n\t * is refused at the edge. What a CDN adds to reach its origin, so the\n\t * origin's public host cannot be called around the CDN.\n\t */\n\trequireHeader?: { name: string; value: string };\n\t/**\n\t * Path prefixes on this host sent to another upstream, ahead of the\n\t * route's own: a file server's processor patterns, to its processor unit,\n\t * while every other path is the bucket. Served at the path asked for —\n\t * no `prefix` — and never combined with `allow`, `paths`, `prefixes` or\n\t * `requireHeader`, which would have to hold for every handler too.\n\t */\n\thandlers?: readonly EdgeHandler[];\n\t/**\n\t * The login every request must carry — HTTP basic auth, asked for by the\n\t * edge before anything reaches the upstream. Absent, it asks for none.\n\t * The password's bcrypt hash, never the password.\n\t */\n\tauth?: { user: string; hash: string };\n\t/**\n\t * What one client address may ask of it — a WebSocket surface's\n\t * handshakes a minute and open sockets — refused with 429 at the edge.\n\t * Rendered for Traefik (`rateLimit`, `inFlightReq`); Caddy ships no rate\n\t * limiter, so behind it the surface's own count is what holds.\n\t */\n\tlimits?: { handshakesPerMinute?: number; connectionsPerIp?: number };\n\t/** The path the upstream answers its health on — `/health`, `/`. */\n\thealth?: string;\n\t/**\n\t * For a wildcard site's route, whose `host` is `*.<domain>`: every one\n\t * label under the domain that no other route answers, and how its\n\t * certificate is had. Named hosts always win over it.\n\t */\n\twildcard?: EdgeWildcard;\n}\n\n/**\n * Every host a route answers on — its own, its aliases and its redirects —\n * in that order: what DNS, certificates and the edge's claims cover.\n */\nexport function routeHosts(route: EdgeRoute): string[] {\n\treturn [\n\t\troute.host,\n\t\t...(route.aliases ?? []),\n\t\t...(route.redirects?.hosts ?? []),\n\t];\n}\n\n/** How a `*.<domain>` route is matched and certified. */\nexport interface EdgeWildcard {\n\t/** The domain under the `*` — `example.com`. */\n\tdomain: string;\n\t/**\n\t * Labels under the domain that never reach it, although no route of this\n\t * stack answers them: the protected subdomains (`www`, `mail`), and a\n\t * stage whose domain sits under this one's (`staging`).\n\t */\n\texcept: readonly string[];\n\t/**\n\t * Where its certificate comes from:\n\t * - `stage`: the stage's own (`deploy.compose.tls`), a wildcard one;\n\t * - `dns`: one `*.<domain>` certificate from Let's Encrypt over the DNS\n\t * challenge, which the shared Traefik edge answers through Route 53;\n\t * - `on-demand`: one per host, as Caddy is first asked for it, once the\n\t * site's `hosts` route — `ask`, on the stack's network — answers 200.\n\t */\n\ttls: { kind: 'stage' } | { kind: 'dns' } | { kind: 'on-demand'; ask: string };\n}\n\n/** Some of a route's paths, answered by another upstream. */\nexport interface EdgeHandler {\n\t/** Unique within the route: what a renderer names its router after. */\n\tname: string;\n\t/** e.g. `/i/` — everything under it. */\n\tprefixes: readonly string[];\n\tupstreams: readonly Upstream[];\n}\n\n/** A route with handlers and a check that would have to hold for each of them. */\nexport class EdgeRouteConflict extends Error {\n\tconstructor(readonly route: string) {\n\t\tsuper(\n\t\t\t`The edge route '${route}' sends some paths to other upstreams and also ` +\n\t\t\t\t`restricts who or what it answers. The two are not combined: give the ` +\n\t\t\t\t`restricted paths a host of their own.`,\n\t\t);\n\t\tthis.name = 'EdgeRouteConflict';\n\t}\n}\n\n/** @throws {EdgeRouteConflict} */\nexport function assertRouteRenderable(route: EdgeRoute): void {\n\tif (\n\t\troute.handlers?.length &&\n\t\t(route.allow || route.paths || route.prefixes || route.requireHeader)\n\t) {\n\t\tthrow new EdgeRouteConflict(route.name);\n\t}\n}\n\n/** Where a stack's certificates come from. */\nexport type EdgeTls =\n\t/** A deployed stage: Let's Encrypt, over HTTP-01, on first request. */\n\t| { kind: 'acme' }\n\t/**\n\t * A certificate and key, as the proxy's container reads them: a deployed\n\t * stage's own (`deploy.compose.tls`), or — on the local stage — the one\n\t * gkm's local authority issued (`trust/authority.ts`).\n\t */\n\t| { kind: 'files'; certFile: string; keyFile: string };\n\n/** File descriptors a process holding sockets may open. */\nexport const NOFILE = { soft: 1_048_576, hard: 1_048_576 };\n\n/**\n * What the edge runs with: a descriptor per socket, twice — the client's and\n * the upstream's — and every local port for those upstream connections. One\n * edge address to one upstream has only the ephemeral range to open\n * connections from, ~28k by Linux's default; widened, ~64k per replica.\n */\nexport const EDGE_LIMITS: {\n\tsysctls: Record<string, string>;\n\tulimits: Record<string, { soft: number; hard: number }>;\n} = {\n\tsysctls: { 'net.ipv4.ip_local_port_range': '1024 65535' },\n\tulimits: { nofile: NOFILE },\n};\n\n/** The proxies a stack can be served by — `deploy.compose.proxy`. */\nexport type ComposeProxy = 'caddy' | 'traefik';\n"],"mappings":";;;;;;AAkHA,SAAgB,WAAW,OAA4B;CACtD,OAAO;EACN,MAAM;EACN,GAAI,MAAM,WAAW,CAAC;EACtB,GAAI,MAAM,WAAW,SAAS,CAAC;CAChC;AACD;;AAiCA,IAAa,oBAAb,cAAuC,MAAM;CACvB;CAArB,YAAY,OAAwB;EACnC,MACC,mBAAmB,MAAM,0JAG1B;EALoB,KAAA,QAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,SAAgB,sBAAsB,OAAwB;CAC7D,IACC,MAAM,UAAU,WACf,MAAM,SAAS,MAAM,SAAS,MAAM,YAAY,MAAM,gBAEvD,MAAM,IAAI,kBAAkB,MAAM,IAAI;AAExC;;AAcA,MAAa,SAAS;CAAE,MAAM;CAAW,MAAM;AAAU;;;;;;;AAQzD,MAAa,cAGT;CACH,SAAS,EAAE,gCAAgC,aAAa;CACxD,SAAS,EAAE,QAAQ,OAAO;AAC3B"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/routes/index.ts"],"sourcesContent":["/**\n * What a stack's edge serves, as data: one route per public host, and the\n * service behind it. Computed once by the stack, then rendered by whichever\n * proxy the stage runs — a Caddyfile for the stack's own Caddy, or a dynamic\n * config file for the server's shared Traefik — so the two never drift.\n *\n * Pure.\n */\n\nimport type { AcmeDnsProvider } from '../proxy/traefik';\n\n/** Where a route sends its requests. */\nexport type Upstream = ServiceUpstream | HostUpstream;\n\n/** A service of the stack that a route sends to. */\nexport interface ServiceUpstream {\n\t/** Its compose service name — `api`, `minio`. */\n\tservice: string;\n\t/** The port it listens on, inside the network. */\n\tport: number;\n}\n\n/**\n * A process on the Docker host itself, outside every stack — an app `gkm dev`\n * runs, or a port a container publishes there — reached from the proxy's\n * container through the host's gateway ({@link HOST_GATEWAY}).\n */\nexport interface HostUpstream {\n\tonHost: true;\n\t/** The port it listens on, on the host. */\n\tport: number;\n}\n\n/**\n * The host's own address, from inside a container. Docker Desktop resolves\n * it already; on Linux the proxy's compose definition maps it to the host\n * gateway (`extra_hosts`).\n */\nexport const HOST_GATEWAY = 'host.docker.internal';\n\n/** An upstream's `host:port`, as a proxy on the stack's network dials it. */\nexport function upstreamAddress(\n\tupstream: Upstream,\n\t/** How a service of the stack is named where the proxy runs. */\n\tservice: (name: string) => string = (name) => name,\n): string {\n\treturn 'onHost' in upstream\n\t\t? `${HOST_GATEWAY}:${upstream.port}`\n\t\t: `${service(upstream.service)}:${upstream.port}`;\n}\n\n/** One public host and what answers it. */\nexport interface EdgeRoute {\n\t/**\n\t * Its name within the stack — unique there, and what a renderer names\n\t * its routers and middlewares after: `api`, `files-uploads`.\n\t */\n\tname: string;\n\t/** e.g. `api.example.com` — the canonical host, its `<ID>_URL`'s. */\n\thost: string;\n\t/**\n\t * More hosts answered exactly as `host` is — a construct's `aliases`:\n\t * every check, handler and upstream of the route holds on each of them.\n\t */\n\taliases?: readonly string[];\n\t/**\n\t * Hosts answered with a permanent redirect to `to`, the canonical origin\n\t * (`https://example.com`, with the edge's port where it is not 443), path\n\t * and query kept — a site's `redirects`. Nothing is proxied for them.\n\t */\n\tredirects?: { hosts: readonly string[]; to: string };\n\t/**\n\t * Where requests go. One today; a release that swaps containers without\n\t * downtime routes to the old and the new while it does.\n\t */\n\tupstreams: readonly Upstream[];\n\t/**\n\t * Never buffer the response: a streamed one — server-sent events, a\n\t * Next.js RSC payload — reaches the client as each chunk is written.\n\t */\n\tstreaming: boolean;\n\t/**\n\t * A path prefix added before the request is sent, with the upstream's own\n\t * address as `Host`: a bucket, served at a host of its own, is a prefix\n\t * on MinIO, which routes and signs on the Host header.\n\t */\n\tprefix?: string;\n\t/**\n\t * The client addresses (IPs or CIDRs) it answers; every other is refused\n\t * with 403, before the request reaches the upstream. Absent, it answers\n\t * everyone. Matched against the peer the proxy sees, never a header a\n\t * client could set.\n\t */\n\tallow?: readonly string[];\n\t/**\n\t * The only paths it answers, matched exactly; every other is refused at\n\t * the edge, before the request reaches the upstream. Absent, it answers\n\t * every path. A worker is reached only on the routes SNS pushes to.\n\t */\n\tpaths?: readonly string[];\n\t/**\n\t * Path prefixes it answers besides `paths` — `/i/` admits everything\n\t * under it. Together they are the whole allowlist; absent both, it\n\t * answers every path. A processor unit's own host is reached only on its\n\t * processors' prefixes.\n\t */\n\tprefixes?: readonly string[];\n\t/**\n\t * A header every request must carry, with exactly this value; any other\n\t * is refused at the edge. What a CDN adds to reach its origin, so the\n\t * origin's public host cannot be called around the CDN.\n\t */\n\trequireHeader?: { name: string; value: string };\n\t/**\n\t * Path prefixes on this host sent to another upstream, ahead of the\n\t * route's own: a file server's processor patterns, to its processor unit,\n\t * while every other path is the bucket. Served at the path asked for —\n\t * no `prefix` — and never combined with `allow`, `paths`, `prefixes` or\n\t * `requireHeader`, which would have to hold for every handler too.\n\t */\n\thandlers?: readonly EdgeHandler[];\n\t/**\n\t * The login every request must carry — HTTP basic auth, asked for by the\n\t * edge before anything reaches the upstream. Absent, it asks for none.\n\t * The password's bcrypt hash, never the password.\n\t */\n\tauth?: { user: string; hash: string };\n\t/**\n\t * What one client address may ask of it — a WebSocket surface's\n\t * handshakes a minute and open sockets — refused with 429 at the edge.\n\t * Rendered for Traefik (`rateLimit`, `inFlightReq`); Caddy ships no rate\n\t * limiter, so behind it the surface's own count is what holds.\n\t */\n\tlimits?: { handshakesPerMinute?: number; connectionsPerIp?: number };\n\t/** The path the upstream answers its health on — `/health`, `/`. */\n\thealth?: string;\n\t/**\n\t * For a wildcard site's route, whose `host` is `*.<domain>`: every one\n\t * label under the domain that no other route answers, and how its\n\t * certificate is had. Named hosts always win over it.\n\t */\n\twildcard?: EdgeWildcard;\n}\n\n/**\n * Every host a route answers on — its own, its aliases and its redirects —\n * in that order: what DNS, certificates and the edge's claims cover.\n */\nexport function routeHosts(route: EdgeRoute): string[] {\n\treturn [\n\t\troute.host,\n\t\t...(route.aliases ?? []),\n\t\t...(route.redirects?.hosts ?? []),\n\t];\n}\n\n/** How a `*.<domain>` route is matched and certified. */\nexport interface EdgeWildcard {\n\t/** The domain under the `*` — `example.com`. */\n\tdomain: string;\n\t/**\n\t * Labels under the domain that never reach it, although no route of this\n\t * stack answers them: the protected subdomains (`www`, `mail`), and a\n\t * stage whose domain sits under this one's (`staging`).\n\t */\n\texcept: readonly string[];\n\t/**\n\t * Where its certificate comes from:\n\t * - `stage`: the stage's own (`deploy.compose.tls`), a wildcard one;\n\t * - `dns`: one `*.<domain>` certificate from Let's Encrypt over the DNS\n\t * challenge, which the shared Traefik edge answers through `provider`\n\t * — the DNS provider holding the domain;\n\t * - `on-demand`: one per host, as Caddy is first asked for it, once the\n\t * site's `hosts` route — `ask`, on the stack's network — answers 200.\n\t */\n\ttls:\n\t\t| { kind: 'stage' }\n\t\t| { kind: 'dns'; provider: AcmeDnsProvider }\n\t\t| { kind: 'on-demand'; ask: string };\n\t/**\n\t * The site's `hosts` route, asked before each request a label makes —\n\t * `GET <path>?domain=<host>` on `upstream` — where a certificate already\n\t * covers every label (gkm's local one): a 2xx serves the label, and any\n\t * other answer is what the client gets. Rendered by Caddy (`forward_auth`);\n\t * Traefik's `forwardAuth` cannot hand the host as `domain`, so behind it\n\t * every label but `except` reaches the site, as a deployed Traefik stage's\n\t * do.\n\t */\n\thosts?: { upstream: Upstream; path: string };\n}\n\n/** Some of a route's paths, answered by another upstream. */\nexport interface EdgeHandler {\n\t/** Unique within the route: what a renderer names its router after. */\n\tname: string;\n\t/** e.g. `/i/` — everything under it. */\n\tprefixes: readonly string[];\n\tupstreams: readonly Upstream[];\n\t/**\n\t * A path prefix added before the request is sent — where the upstream\n\t * mounts what it answers: a dev server holding a file server's\n\t * processors, under `/__gkm/processors/<id>`.\n\t */\n\tunder?: string;\n}\n\n/** A route with handlers and a check that would have to hold for each of them. */\nexport class EdgeRouteConflict extends Error {\n\tconstructor(readonly route: string) {\n\t\tsuper(\n\t\t\t`The edge route '${route}' sends some paths to other upstreams and also ` +\n\t\t\t\t`restricts who or what it answers. The two are not combined: give the ` +\n\t\t\t\t`restricted paths a host of their own.`,\n\t\t);\n\t\tthis.name = 'EdgeRouteConflict';\n\t}\n}\n\n/** @throws {EdgeRouteConflict} */\nexport function assertRouteRenderable(route: EdgeRoute): void {\n\tif (\n\t\troute.handlers?.length &&\n\t\t(route.allow || route.paths || route.prefixes || route.requireHeader)\n\t) {\n\t\tthrow new EdgeRouteConflict(route.name);\n\t}\n}\n\n/** Where a stack's certificates come from. */\nexport type EdgeTls =\n\t/** A deployed stage: Let's Encrypt, over HTTP-01, on first request. */\n\t| { kind: 'acme' }\n\t/**\n\t * A certificate and key, as the proxy's container reads them: a deployed\n\t * stage's own (`deploy.compose.tls`), or — on the local stage — the one\n\t * gkm's local authority issued (`trust/authority.ts`).\n\t */\n\t| { kind: 'files'; certFile: string; keyFile: string };\n\n/** File descriptors a process holding sockets may open. */\nexport const NOFILE = { soft: 1_048_576, hard: 1_048_576 };\n\n/**\n * What the edge runs with: a descriptor per socket, twice — the client's and\n * the upstream's — and every local port for those upstream connections. One\n * edge address to one upstream has only the ephemeral range to open\n * connections from, ~28k by Linux's default; widened, ~64k per replica.\n */\nexport const EDGE_LIMITS: {\n\tsysctls: Record<string, string>;\n\tulimits: Record<string, { soft: number; hard: number }>;\n} = {\n\tsysctls: { 'net.ipv4.ip_local_port_range': '1024 65535' },\n\tulimits: { nofile: NOFILE },\n};\n\n/** The proxies a stack can be served by — `deploy.compose.proxy`. */\nexport type ComposeProxy = 'caddy' | 'traefik';\n"],"mappings":";;;;;;;AAsCA,MAAa,eAAe;;AAG5B,SAAgB,gBACf,UAEA,WAAqC,SAAS,MACrC;CACT,OAAO,YAAY,WAChB,GAAG,aAAa,GAAG,SAAS,SAC5B,GAAG,QAAQ,SAAS,OAAO,EAAE,GAAG,SAAS;AAC7C;;;;;AAmGA,SAAgB,WAAW,OAA4B;CACtD,OAAO;EACN,MAAM;EACN,GAAI,MAAM,WAAW,CAAC;EACtB,GAAI,MAAM,WAAW,SAAS,CAAC;CAChC;AACD;;AAqDA,IAAa,oBAAb,cAAuC,MAAM;CACvB;CAArB,YAAY,OAAwB;EACnC,MACC,mBAAmB,MAAM,0JAG1B;EALoB,KAAA,QAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,SAAgB,sBAAsB,OAAwB;CAC7D,IACC,MAAM,UAAU,WACf,MAAM,SAAS,MAAM,SAAS,MAAM,YAAY,MAAM,gBAEvD,MAAM,IAAI,kBAAkB,MAAM,IAAI;AAExC;;AAcA,MAAa,SAAS;CAAE,MAAM;CAAW,MAAM;AAAU;;;;;;;AAQzD,MAAa,cAGT;CACH,SAAS,EAAE,gCAAgC,aAAa;CACxD,SAAS,EAAE,QAAQ,OAAO;AAC3B"}
|
package/dist/routes/index.d.cts
CHANGED
|
@@ -1,205 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* What a stack's edge serves, as data: one route per public host, and the
|
|
4
|
-
* service behind it. Computed once by the stack, then rendered by whichever
|
|
5
|
-
* proxy the stage runs — a Caddyfile for the stack's own Caddy, or a dynamic
|
|
6
|
-
* config file for the server's shared Traefik — so the two never drift.
|
|
7
|
-
*
|
|
8
|
-
* Pure.
|
|
9
|
-
*/
|
|
10
|
-
/** A service of the stack that a route sends to. */
|
|
11
|
-
export interface Upstream {
|
|
12
|
-
/** Its compose service name — `api`, `minio`. */
|
|
13
|
-
service: string;
|
|
14
|
-
/** The port it listens on, inside the network. */
|
|
15
|
-
port: number;
|
|
16
|
-
}
|
|
17
|
-
/** One public host and what answers it. */
|
|
18
|
-
export interface EdgeRoute {
|
|
19
|
-
/**
|
|
20
|
-
* Its name within the stack — unique there, and what a renderer names
|
|
21
|
-
* its routers and middlewares after: `api`, `files-uploads`.
|
|
22
|
-
*/
|
|
23
|
-
name: string;
|
|
24
|
-
/** e.g. `api.example.com` — the canonical host, its `<ID>_URL`'s. */
|
|
25
|
-
host: string;
|
|
26
|
-
/**
|
|
27
|
-
* More hosts answered exactly as `host` is — a construct's `aliases`:
|
|
28
|
-
* every check, handler and upstream of the route holds on each of them.
|
|
29
|
-
*/
|
|
30
|
-
aliases?: readonly string[];
|
|
31
|
-
/**
|
|
32
|
-
* Hosts answered with a permanent redirect to `to`, the canonical origin
|
|
33
|
-
* (`https://example.com`, with the edge's port where it is not 443), path
|
|
34
|
-
* and query kept — a site's `redirects`. Nothing is proxied for them.
|
|
35
|
-
*/
|
|
36
|
-
redirects?: {
|
|
37
|
-
hosts: readonly string[];
|
|
38
|
-
to: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Where requests go. One today; a release that swaps containers without
|
|
42
|
-
* downtime routes to the old and the new while it does.
|
|
43
|
-
*/
|
|
44
|
-
upstreams: readonly Upstream[];
|
|
45
|
-
/**
|
|
46
|
-
* Never buffer the response: a streamed one — server-sent events, a
|
|
47
|
-
* Next.js RSC payload — reaches the client as each chunk is written.
|
|
48
|
-
*/
|
|
49
|
-
streaming: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* A path prefix added before the request is sent, with the upstream's own
|
|
52
|
-
* address as `Host`: a bucket, served at a host of its own, is a prefix
|
|
53
|
-
* on MinIO, which routes and signs on the Host header.
|
|
54
|
-
*/
|
|
55
|
-
prefix?: string;
|
|
56
|
-
/**
|
|
57
|
-
* The client addresses (IPs or CIDRs) it answers; every other is refused
|
|
58
|
-
* with 403, before the request reaches the upstream. Absent, it answers
|
|
59
|
-
* everyone. Matched against the peer the proxy sees, never a header a
|
|
60
|
-
* client could set.
|
|
61
|
-
*/
|
|
62
|
-
allow?: readonly string[];
|
|
63
|
-
/**
|
|
64
|
-
* The only paths it answers, matched exactly; every other is refused at
|
|
65
|
-
* the edge, before the request reaches the upstream. Absent, it answers
|
|
66
|
-
* every path. A worker is reached only on the routes SNS pushes to.
|
|
67
|
-
*/
|
|
68
|
-
paths?: readonly string[];
|
|
69
|
-
/**
|
|
70
|
-
* Path prefixes it answers besides `paths` — `/i/` admits everything
|
|
71
|
-
* under it. Together they are the whole allowlist; absent both, it
|
|
72
|
-
* answers every path. A processor unit's own host is reached only on its
|
|
73
|
-
* processors' prefixes.
|
|
74
|
-
*/
|
|
75
|
-
prefixes?: readonly string[];
|
|
76
|
-
/**
|
|
77
|
-
* A header every request must carry, with exactly this value; any other
|
|
78
|
-
* is refused at the edge. What a CDN adds to reach its origin, so the
|
|
79
|
-
* origin's public host cannot be called around the CDN.
|
|
80
|
-
*/
|
|
81
|
-
requireHeader?: {
|
|
82
|
-
name: string;
|
|
83
|
-
value: string;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Path prefixes on this host sent to another upstream, ahead of the
|
|
87
|
-
* route's own: a file server's processor patterns, to its processor unit,
|
|
88
|
-
* while every other path is the bucket. Served at the path asked for —
|
|
89
|
-
* no `prefix` — and never combined with `allow`, `paths`, `prefixes` or
|
|
90
|
-
* `requireHeader`, which would have to hold for every handler too.
|
|
91
|
-
*/
|
|
92
|
-
handlers?: readonly EdgeHandler[];
|
|
93
|
-
/**
|
|
94
|
-
* The login every request must carry — HTTP basic auth, asked for by the
|
|
95
|
-
* edge before anything reaches the upstream. Absent, it asks for none.
|
|
96
|
-
* The password's bcrypt hash, never the password.
|
|
97
|
-
*/
|
|
98
|
-
auth?: {
|
|
99
|
-
user: string;
|
|
100
|
-
hash: string;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* What one client address may ask of it — a WebSocket surface's
|
|
104
|
-
* handshakes a minute and open sockets — refused with 429 at the edge.
|
|
105
|
-
* Rendered for Traefik (`rateLimit`, `inFlightReq`); Caddy ships no rate
|
|
106
|
-
* limiter, so behind it the surface's own count is what holds.
|
|
107
|
-
*/
|
|
108
|
-
limits?: {
|
|
109
|
-
handshakesPerMinute?: number;
|
|
110
|
-
connectionsPerIp?: number;
|
|
111
|
-
};
|
|
112
|
-
/** The path the upstream answers its health on — `/health`, `/`. */
|
|
113
|
-
health?: string;
|
|
114
|
-
/**
|
|
115
|
-
* For a wildcard site's route, whose `host` is `*.<domain>`: every one
|
|
116
|
-
* label under the domain that no other route answers, and how its
|
|
117
|
-
* certificate is had. Named hosts always win over it.
|
|
118
|
-
*/
|
|
119
|
-
wildcard?: EdgeWildcard;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Every host a route answers on — its own, its aliases and its redirects —
|
|
123
|
-
* in that order: what DNS, certificates and the edge's claims cover.
|
|
124
|
-
*/
|
|
125
|
-
export declare function routeHosts(route: EdgeRoute): string[];
|
|
126
|
-
/** How a `*.<domain>` route is matched and certified. */
|
|
127
|
-
export interface EdgeWildcard {
|
|
128
|
-
/** The domain under the `*` — `example.com`. */
|
|
129
|
-
domain: string;
|
|
130
|
-
/**
|
|
131
|
-
* Labels under the domain that never reach it, although no route of this
|
|
132
|
-
* stack answers them: the protected subdomains (`www`, `mail`), and a
|
|
133
|
-
* stage whose domain sits under this one's (`staging`).
|
|
134
|
-
*/
|
|
135
|
-
except: readonly string[];
|
|
136
|
-
/**
|
|
137
|
-
* Where its certificate comes from:
|
|
138
|
-
* - `stage`: the stage's own (`deploy.compose.tls`), a wildcard one;
|
|
139
|
-
* - `dns`: one `*.<domain>` certificate from Let's Encrypt over the DNS
|
|
140
|
-
* challenge, which the shared Traefik edge answers through Route 53;
|
|
141
|
-
* - `on-demand`: one per host, as Caddy is first asked for it, once the
|
|
142
|
-
* site's `hosts` route — `ask`, on the stack's network — answers 200.
|
|
143
|
-
*/
|
|
144
|
-
tls: {
|
|
145
|
-
kind: 'stage';
|
|
146
|
-
} | {
|
|
147
|
-
kind: 'dns';
|
|
148
|
-
} | {
|
|
149
|
-
kind: 'on-demand';
|
|
150
|
-
ask: string;
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
/** Some of a route's paths, answered by another upstream. */
|
|
154
|
-
export interface EdgeHandler {
|
|
155
|
-
/** Unique within the route: what a renderer names its router after. */
|
|
156
|
-
name: string;
|
|
157
|
-
/** e.g. `/i/` — everything under it. */
|
|
158
|
-
prefixes: readonly string[];
|
|
159
|
-
upstreams: readonly Upstream[];
|
|
160
|
-
}
|
|
161
|
-
/** A route with handlers and a check that would have to hold for each of them. */
|
|
162
|
-
export declare class EdgeRouteConflict extends Error {
|
|
163
|
-
readonly route: string;
|
|
164
|
-
constructor(route: string);
|
|
165
|
-
}
|
|
166
|
-
/** @throws {EdgeRouteConflict} */
|
|
167
|
-
export declare function assertRouteRenderable(route: EdgeRoute): void;
|
|
168
|
-
/** Where a stack's certificates come from. */
|
|
169
|
-
export type EdgeTls =
|
|
170
|
-
/** A deployed stage: Let's Encrypt, over HTTP-01, on first request. */
|
|
171
|
-
{
|
|
172
|
-
kind: 'acme';
|
|
173
|
-
} |
|
|
174
|
-
/**
|
|
175
|
-
* A certificate and key, as the proxy's container reads them: a deployed
|
|
176
|
-
* stage's own (`deploy.compose.tls`), or — on the local stage — the one
|
|
177
|
-
* gkm's local authority issued (`trust/authority.ts`).
|
|
178
|
-
*/
|
|
179
|
-
{
|
|
180
|
-
kind: 'files';
|
|
181
|
-
certFile: string;
|
|
182
|
-
keyFile: string;
|
|
183
|
-
};
|
|
184
|
-
/** File descriptors a process holding sockets may open. */
|
|
185
|
-
export declare const NOFILE: {
|
|
186
|
-
soft: number;
|
|
187
|
-
hard: number;
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* What the edge runs with: a descriptor per socket, twice — the client's and
|
|
191
|
-
* the upstream's — and every local port for those upstream connections. One
|
|
192
|
-
* edge address to one upstream has only the ephemeral range to open
|
|
193
|
-
* connections from, ~28k by Linux's default; widened, ~64k per replica.
|
|
194
|
-
*/
|
|
195
|
-
export declare const EDGE_LIMITS: {
|
|
196
|
-
sysctls: Record<string, string>;
|
|
197
|
-
ulimits: Record<string, {
|
|
198
|
-
soft: number;
|
|
199
|
-
hard: number;
|
|
200
|
-
}>;
|
|
201
|
-
};
|
|
202
|
-
/** The proxies a stack can be served by — `deploy.compose.proxy`. */
|
|
203
|
-
export type ComposeProxy = 'caddy' | 'traefik';
|
|
204
|
-
//#endregion
|
|
205
|
-
//# sourceMappingURL=index.d.cts.map
|
|
1
|
+
import { a as EdgeRouteConflict, c as HOST_GATEWAY, d as ServiceUpstream, f as Upstream, h as upstreamAddress, i as EdgeRoute, l as HostUpstream, m as routeHosts, n as EDGE_LIMITS, o as EdgeTls, p as assertRouteRenderable, r as EdgeHandler, s as EdgeWildcard, t as ComposeProxy, u as NOFILE } from "../index-BVE0VFku.cjs";
|
|
2
|
+
export { ComposeProxy, EDGE_LIMITS, EdgeHandler, EdgeRoute, EdgeRouteConflict, EdgeTls, EdgeWildcard, HOST_GATEWAY, HostUpstream, NOFILE, ServiceUpstream, Upstream, assertRouteRenderable, routeHosts, upstreamAddress };
|