@geekmidas/edge 10.0.0-alpha.185 → 10.0.0-alpha.187
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.d.cts +1 -1
- package/dist/proxy/caddy.d.mts +1 -1
- package/dist/proxy/traefik.cjs +80 -16
- 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 +76 -17
- package/dist/proxy/traefik.mjs.map +1 -1
- package/dist/routes/index.cjs.map +1 -1
- package/dist/routes/index.d.cts +2 -246
- package/dist/routes/index.d.mts +2 -246
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traefik.cjs","names":["createHash","HOST_GATEWAY","EDGE_LIMITS","composeLiteral","upstreamAddress","CLIENT_IP_HEADER","EDGE_TOKEN_HEADER","routeHosts","parse","yaml","stringify"],"sources":["../../src/proxy/traefik.ts"],"sourcesContent":["/**\n * The server's shared edge, rendered for Traefik: what the edge itself runs\n * with, and what one stack registers with it.\n *\n * One Traefik per server owns 80 and 443, the ACME state and the redirect to\n * HTTPS. It is configured through its file provider alone: each stack writes\n * one file — its routers, services and middlewares, every name prefixed with\n * its compose project — into a directory the edge watches, and removes it\n * when it stops. There is no Docker socket: the edge never learns what runs\n * on the server except from those files.\n *\n * The edge and the stacks meet on one external Docker network. Only a\n * stack's public services join it, each under an alias prefixed with its\n * project (`<project>-api`), because the network is shared: a bare service\n * name there would be answered by every stack's `api`.\n *\n * Pure but for the edge's name, read from the environment once (see\n * {@link EDGE_PROJECT_ENV}): the documents are data, and the edge's side\n * effects are `edge.ts`'s.\n */\n\nimport { createHash } from 'node:crypto';\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport { parse, stringify } from 'yaml';\nimport { composeLiteral } from '../compose';\nimport {\n\tassertRouteRenderable,\n\tEDGE_LIMITS,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\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 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// 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: 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\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;;AAG5B,MAAa,eAAe;;AAG5B,MAAa,mBAAmB;AAChC,MAAa,iBAAiB;;AAG9B,MAAa,gBAAgB;;;;;;AAO7B,MAAa,oBAAoB;;;;;;AAOjC,MAAa,uBAAuB,GAAG,eAAe;;AAGtD,MAAM,YAAY;;AAGlB,SAAgB,UAAU,SAAiB,SAAyB;CACnE,OAAO,GAAG,QAAQ,GAAG;AACtB;;AAGA,SAAgB,qBAAqB,SAGnC;CACD,OAAO;EACN,UAAU,GAAG,eAAe,GAAG,QAAQ;EACvC,SAAS,GAAG,eAAe,GAAG,QAAQ;CACvC;AACD;;;;;;AAaA,SAAgB,cAAc,OAA2C;CACxE,OAAO;EACN,QAAQ;GAAE,iBAAiB;GAAO,oBAAoB;EAAM;EAC5D,aAAa;GACZ,KAAK;IACJ,SAAS;IACT,MAAM,EAGL,cAAc,EACb,YAAY;KAGX,IAAI,MAAM,UAAU,MAAM,cAAc,IAAI,MAAM;KAClD,QAAQ;KACR,WAAW;IACZ,EACD,EACD;GACD;GACA,WAAW,EAAE,SAAS,OAAO;GAC7B,MAAM,EAAE,SAAS,IAAI,YAAY;EAClC;EACA,MAAM,EAAE,YAAY,OAAO;EAC3B,WAAW,EACV,MAAM;GAAE,WAAW;GAAkB,OAAO;EAAK,EAClD;EACA,uBAAuB;IACrB,gBAAgB,EAChB,MAAM;IACL,SAAS;IACT,eAAe,EAAE,YAAY,MAAM;GACpC,EACD;IACC,oBAAoB,EACpB,M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names":["createHash","HOST_GATEWAY","EDGE_LIMITS","composeLiteral","upstreamAddress","CLIENT_IP_HEADER","EDGE_TOKEN_HEADER","routeHosts","parse","yaml","stringify"],"sources":["../../src/proxy/traefik.ts"],"sourcesContent":["/**\n * The server's shared edge, rendered for Traefik: what the edge itself runs\n * with, and what one stack registers with it.\n *\n * One Traefik per server owns 80 and 443, the ACME state and the redirect to\n * HTTPS. It is configured through its file provider alone: each stack writes\n * one file — its routers, services and middlewares, every name prefixed with\n * its compose project — into a directory the edge watches, and removes it\n * when it stops. There is no Docker socket: the edge never learns what runs\n * on the server except from those files.\n *\n * The edge and the stacks meet on one external Docker network. Only a\n * stack's public services join it, each under an alias prefixed with its\n * project (`<project>-api`), because the network is shared: a bare service\n * name there would be answered by every stack's `api`.\n *\n * Pure but for the edge's name, read from the environment once (see\n * {@link EDGE_PROJECT_ENV}): the documents are data, and the edge's side\n * effects are `edge.ts`'s.\n */\n\nimport { createHash } from 'node:crypto';\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport { parse, stringify } from 'yaml';\nimport { composeLiteral } from '../compose';\nimport {\n\tassertRouteRenderable,\n\tEDGE_LIMITS,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\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;;AAG5B,MAAa,eAAe;;AAG5B,MAAa,mBAAmB;AAChC,MAAa,iBAAiB;;AAG9B,MAAa,gBAAgB;;;;;;;AAQ7B,MAAa,uBAAuB,GAAG,eAAe;;;;;;;;;;;AA+BtD,MAAa,sBAAsB;CAClC,SAAS;EACR,UAAU;EACV,SAAS,CAAC;EACV,aAAa;GACZ,6BAA6B;GAC7B,YAAY;EACb;CACD;CACA,SAAS;EACR,UAAU;EACV,SAAS,CAAC,mBAAmB,oBAAoB;CAClD;AACD;;AAMA,SAAgB,kBACf,UAC8B;CAC9B,OACC,OAAO,aAAa,YAAY,OAAO,OAAO,qBAAqB,QAAQ;AAE7E;;AAGA,MAAa,oBAAoB;;;;;;;;;AAUjC,SAAgB,gBAAgB,UAAmC;CAClE,OAAO,aAAa,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B,aAAa;EACnCA,OAAK,YAAY,OAAO,CAAC;AAC3B;AAEA,SAASA,OAAK,OAAwB;CACrC,QAAA,GAAOC,KAAAA,UAAAA,CAAU,OAAO;EAAE,WAAW;EAAG,uBAAuB;CAAM,CAAC;AACvE"}
|
package/dist/proxy/traefik.d.cts
CHANGED
|
@@ -1,129 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The image, pinned: the edge is every stack's way in, so a new version is a
|
|
5
|
-
* change to this line, not whatever `latest` is on the day a server starts.
|
|
6
|
-
*/
|
|
7
|
-
export declare const TRAEFIK_IMAGE = "traefik:v3.7.13";
|
|
8
|
-
/** The edge's name when nothing renames it: one per server. */
|
|
9
|
-
export declare const DEFAULT_EDGE_PROJECT = "gkm-edge";
|
|
10
|
-
/**
|
|
11
|
-
* The variable that renames the edge — its compose project, and with it its
|
|
12
|
-
* network and its volumes (`<project>_acme`, `_certs`, `_dynamic`). A testing
|
|
13
|
-
* and advanced knob: an end-to-end suite runs an edge of its own beside a
|
|
14
|
-
* developer's, and never touches theirs. Every command that registers with
|
|
15
|
-
* one edge must be run with the same value.
|
|
16
|
-
*/
|
|
17
|
-
export declare const EDGE_PROJECT_ENV = "GKM_EDGE_PROJECT";
|
|
18
|
-
/** The edge's compose project: `GKM_EDGE_PROJECT`, else `gkm-edge`. */
|
|
19
|
-
export declare function edgeProject(env?: NodeJS.ProcessEnv): string;
|
|
20
|
-
/**
|
|
21
|
-
* The edge's compose project, one per server — read once, when gkm starts,
|
|
22
|
-
* so every step of a run names the same edge.
|
|
23
|
-
*/
|
|
24
|
-
export declare const EDGE_PROJECT: string;
|
|
25
|
-
/**
|
|
26
|
-
* The external network the edge and every stack's public services share:
|
|
27
|
-
* named after the edge, so a renamed edge has a network of its own.
|
|
28
|
-
*/
|
|
29
|
-
export declare const EDGE_NETWORK: string;
|
|
30
|
-
/** The edge's compose service. */
|
|
31
|
-
export declare const EDGE_SERVICE = "traefik";
|
|
32
|
-
/** Inside the edge's container: what it watches, and where certificates are. */
|
|
33
|
-
export declare const EDGE_DYNAMIC_DIR = "/etc/gkm-edge/dynamic";
|
|
34
|
-
export declare const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
|
|
35
|
-
/** The certificate resolver every deployed route without its own certificate uses. */
|
|
36
|
-
export declare const ACME_RESOLVER = "letsencrypt";
|
|
37
|
-
/**
|
|
38
|
-
* The resolver a wildcard site's `*.<domain>` certificate comes from: Let's
|
|
39
|
-
* Encrypt issues a wildcard only over the DNS challenge, which the edge
|
|
40
|
-
* answers by writing an `_acme-challenge` TXT record through Route 53.
|
|
41
|
-
*/
|
|
42
|
-
export declare const ACME_DNS_RESOLVER = "letsencrypt-dns";
|
|
43
|
-
/**
|
|
44
|
-
* The key the edge writes those records with, inside its container: written
|
|
45
|
-
* by the deploy of a stage with a wildcard site, and allowed nothing but
|
|
46
|
-
* each such stage's `_acme-challenge` record (see `acmeDns.ts`).
|
|
47
|
-
*/
|
|
48
|
-
export declare const EDGE_AWS_CREDENTIALS = "/etc/gkm-edge/certs/aws-credentials";
|
|
49
|
-
/** A stack's service, as the edge — and the stack itself — reach it. */
|
|
50
|
-
export declare function edgeAlias(project: string, service: string): string;
|
|
51
|
-
/** A stack's certificate, as the edge's container reads it. */
|
|
52
|
-
export declare function edgeCertificatePaths(project: string): {
|
|
53
|
-
certFile: string;
|
|
54
|
-
keyFile: string;
|
|
55
|
-
};
|
|
56
|
-
/** The edge's ports on the host. */
|
|
57
|
-
export interface EdgePorts {
|
|
58
|
-
https: number;
|
|
59
|
-
http: number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The edge's static configuration: the entrypoints, the redirect, ACME, and
|
|
63
|
-
* the directory it watches. No API and no dashboard — nothing about the edge
|
|
64
|
-
* is reachable but the routes stacks register.
|
|
65
|
-
*/
|
|
66
|
-
export declare function traefikStatic(ports: EdgePorts): Record<string, unknown>;
|
|
67
|
-
/** The edge's compose document. */
|
|
68
|
-
export declare function edgeCompose(options: {
|
|
69
|
-
ports: EdgePorts;
|
|
70
|
-
/**
|
|
71
|
-
* The static configuration, as written: handed to the container inline
|
|
72
|
-
* (`configs.content`), so nothing is read from a path on whichever machine
|
|
73
|
-
* runs the deploy — and its hash recreates the edge when it changes.
|
|
74
|
-
*/
|
|
75
|
-
staticConfig: string;
|
|
76
|
-
logging: {
|
|
77
|
-
driver: string;
|
|
78
|
-
options: Record<string, string>;
|
|
79
|
-
};
|
|
80
|
-
}): Record<string, unknown>;
|
|
81
|
-
/** What a stack registers with the edge — its routes, and its certificate. */
|
|
82
|
-
export interface TraefikStackOptions {
|
|
83
|
-
project: string;
|
|
84
|
-
/** ACME, or the stage's own certificate. */
|
|
85
|
-
tls: EdgeTls;
|
|
86
|
-
/**
|
|
87
|
-
* The stack's token, on which a service of the stack keeps gkm's client
|
|
88
|
-
* address through the edge — see `clientIpRule`.
|
|
89
|
-
*/
|
|
90
|
-
edgeToken?: string;
|
|
91
|
-
}
|
|
92
|
-
/** A stack's dynamic configuration, as an object. */
|
|
93
|
-
export declare function traefikDynamic(routes: readonly EdgeRoute[], options: TraefikStackOptions): Record<string, unknown>;
|
|
94
|
-
/**
|
|
95
|
-
* A host a stack routes on the shared edge: one name, or — for a wildcard
|
|
96
|
-
* site — every one label under a domain but the ones it never takes.
|
|
97
|
-
*/
|
|
98
|
-
export type EdgeClaim = {
|
|
99
|
-
host: string;
|
|
100
|
-
} | {
|
|
101
|
-
wildcard: string;
|
|
102
|
-
except: readonly string[];
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* What a stack's routes claim on the edge, from the route model: one claim
|
|
106
|
-
* per host, each route's aliases and redirects included.
|
|
107
|
-
*/
|
|
108
|
-
export declare function edgeClaims(routes: readonly EdgeRoute[]): EdgeClaim[];
|
|
109
|
-
/**
|
|
110
|
-
* The hosts a stack's file on the edge claims: from its claims line, or — a
|
|
111
|
-
* file written before gkm wrote one — from its routers' rules, in the shapes
|
|
112
|
-
* `traefikDynamic` renders them.
|
|
113
|
-
*/
|
|
114
|
-
export declare function readEdgeClaims(file: string): EdgeClaim[];
|
|
115
|
-
/**
|
|
116
|
-
* Where two claims meet, as a host to name — or undefined where they never
|
|
117
|
-
* do. A wildcard takes one label under its domain, so it meets a name one
|
|
118
|
-
* label under it that it does not leave out, and another wildcard on the
|
|
119
|
-
* same domain.
|
|
120
|
-
*/
|
|
121
|
-
export declare function claimsOverlap(a: EdgeClaim, b: EdgeClaim): string | undefined;
|
|
122
|
-
/** A stack's dynamic configuration file, as written to the edge's directory. */
|
|
123
|
-
export declare function traefikDynamicFile(routes: readonly EdgeRoute[], options: TraefikStackOptions): string;
|
|
124
|
-
/** The edge's static configuration file. */
|
|
125
|
-
export declare function traefikStaticFile(ports: EdgePorts): string;
|
|
126
|
-
/** The edge's compose file. */
|
|
127
|
-
export declare function edgeComposeFile(options: Parameters<typeof edgeCompose>[0]): string;
|
|
128
|
-
//#endregion
|
|
129
|
-
//# sourceMappingURL=traefik.d.cts.map
|
|
1
|
+
import { A as EdgeClaim, B as edgeComposeFile, C as EDGE_AWS_CREDENTIALS, D as EDGE_PROJECT, E as EDGE_NETWORK, F as claimsOverlap, G as traefikDynamic, H as edgeProject, I as edgeAlias, J as traefikStaticFile, K as traefikDynamicFile, L as edgeCertificatePaths, M as TRAEFIK_IMAGE, N as TraefikStackOptions, O as EDGE_PROJECT_ENV, P as acmeDnsResolver, R as edgeClaims, S as DEFAULT_EDGE_PROJECT, T as EDGE_DYNAMIC_DIR, U as isAcmeDnsProvider, V as edgeDnsSecretPath, W as readEdgeClaims, _ as ACME_DNS_RESOLVER, b as AcmeDnsChallenge, g as ACME_DNS_CHALLENGES, j as EdgePorts, k as EDGE_SERVICE, q as traefikStatic, v as ACME_DNS_SECRET_KEYS, w as EDGE_CERTS_DIR, x as AcmeDnsProvider, y as ACME_RESOLVER, z as edgeCompose } from "../index-BVE0VFku.cjs";
|
|
2
|
+
export { ACME_DNS_CHALLENGES, ACME_DNS_RESOLVER, ACME_DNS_SECRET_KEYS, ACME_RESOLVER, AcmeDnsChallenge, AcmeDnsProvider, DEFAULT_EDGE_PROJECT, EDGE_AWS_CREDENTIALS, EDGE_CERTS_DIR, EDGE_DYNAMIC_DIR, EDGE_NETWORK, EDGE_PROJECT, EDGE_PROJECT_ENV, EDGE_SERVICE, EdgeClaim, EdgePorts, TRAEFIK_IMAGE, TraefikStackOptions, acmeDnsResolver, claimsOverlap, edgeAlias, edgeCertificatePaths, edgeClaims, edgeCompose, edgeComposeFile, edgeDnsSecretPath, edgeProject, isAcmeDnsProvider, readEdgeClaims, traefikDynamic, traefikDynamicFile, traefikStatic, traefikStaticFile };
|
package/dist/proxy/traefik.d.mts
CHANGED
|
@@ -1,129 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The image, pinned: the edge is every stack's way in, so a new version is a
|
|
5
|
-
* change to this line, not whatever `latest` is on the day a server starts.
|
|
6
|
-
*/
|
|
7
|
-
export declare const TRAEFIK_IMAGE = "traefik:v3.7.13";
|
|
8
|
-
/** The edge's name when nothing renames it: one per server. */
|
|
9
|
-
export declare const DEFAULT_EDGE_PROJECT = "gkm-edge";
|
|
10
|
-
/**
|
|
11
|
-
* The variable that renames the edge — its compose project, and with it its
|
|
12
|
-
* network and its volumes (`<project>_acme`, `_certs`, `_dynamic`). A testing
|
|
13
|
-
* and advanced knob: an end-to-end suite runs an edge of its own beside a
|
|
14
|
-
* developer's, and never touches theirs. Every command that registers with
|
|
15
|
-
* one edge must be run with the same value.
|
|
16
|
-
*/
|
|
17
|
-
export declare const EDGE_PROJECT_ENV = "GKM_EDGE_PROJECT";
|
|
18
|
-
/** The edge's compose project: `GKM_EDGE_PROJECT`, else `gkm-edge`. */
|
|
19
|
-
export declare function edgeProject(env?: NodeJS.ProcessEnv): string;
|
|
20
|
-
/**
|
|
21
|
-
* The edge's compose project, one per server — read once, when gkm starts,
|
|
22
|
-
* so every step of a run names the same edge.
|
|
23
|
-
*/
|
|
24
|
-
export declare const EDGE_PROJECT: string;
|
|
25
|
-
/**
|
|
26
|
-
* The external network the edge and every stack's public services share:
|
|
27
|
-
* named after the edge, so a renamed edge has a network of its own.
|
|
28
|
-
*/
|
|
29
|
-
export declare const EDGE_NETWORK: string;
|
|
30
|
-
/** The edge's compose service. */
|
|
31
|
-
export declare const EDGE_SERVICE = "traefik";
|
|
32
|
-
/** Inside the edge's container: what it watches, and where certificates are. */
|
|
33
|
-
export declare const EDGE_DYNAMIC_DIR = "/etc/gkm-edge/dynamic";
|
|
34
|
-
export declare const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
|
|
35
|
-
/** The certificate resolver every deployed route without its own certificate uses. */
|
|
36
|
-
export declare const ACME_RESOLVER = "letsencrypt";
|
|
37
|
-
/**
|
|
38
|
-
* The resolver a wildcard site's `*.<domain>` certificate comes from: Let's
|
|
39
|
-
* Encrypt issues a wildcard only over the DNS challenge, which the edge
|
|
40
|
-
* answers by writing an `_acme-challenge` TXT record through Route 53.
|
|
41
|
-
*/
|
|
42
|
-
export declare const ACME_DNS_RESOLVER = "letsencrypt-dns";
|
|
43
|
-
/**
|
|
44
|
-
* The key the edge writes those records with, inside its container: written
|
|
45
|
-
* by the deploy of a stage with a wildcard site, and allowed nothing but
|
|
46
|
-
* each such stage's `_acme-challenge` record (see `acmeDns.ts`).
|
|
47
|
-
*/
|
|
48
|
-
export declare const EDGE_AWS_CREDENTIALS = "/etc/gkm-edge/certs/aws-credentials";
|
|
49
|
-
/** A stack's service, as the edge — and the stack itself — reach it. */
|
|
50
|
-
export declare function edgeAlias(project: string, service: string): string;
|
|
51
|
-
/** A stack's certificate, as the edge's container reads it. */
|
|
52
|
-
export declare function edgeCertificatePaths(project: string): {
|
|
53
|
-
certFile: string;
|
|
54
|
-
keyFile: string;
|
|
55
|
-
};
|
|
56
|
-
/** The edge's ports on the host. */
|
|
57
|
-
export interface EdgePorts {
|
|
58
|
-
https: number;
|
|
59
|
-
http: number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The edge's static configuration: the entrypoints, the redirect, ACME, and
|
|
63
|
-
* the directory it watches. No API and no dashboard — nothing about the edge
|
|
64
|
-
* is reachable but the routes stacks register.
|
|
65
|
-
*/
|
|
66
|
-
export declare function traefikStatic(ports: EdgePorts): Record<string, unknown>;
|
|
67
|
-
/** The edge's compose document. */
|
|
68
|
-
export declare function edgeCompose(options: {
|
|
69
|
-
ports: EdgePorts;
|
|
70
|
-
/**
|
|
71
|
-
* The static configuration, as written: handed to the container inline
|
|
72
|
-
* (`configs.content`), so nothing is read from a path on whichever machine
|
|
73
|
-
* runs the deploy — and its hash recreates the edge when it changes.
|
|
74
|
-
*/
|
|
75
|
-
staticConfig: string;
|
|
76
|
-
logging: {
|
|
77
|
-
driver: string;
|
|
78
|
-
options: Record<string, string>;
|
|
79
|
-
};
|
|
80
|
-
}): Record<string, unknown>;
|
|
81
|
-
/** What a stack registers with the edge — its routes, and its certificate. */
|
|
82
|
-
export interface TraefikStackOptions {
|
|
83
|
-
project: string;
|
|
84
|
-
/** ACME, or the stage's own certificate. */
|
|
85
|
-
tls: EdgeTls;
|
|
86
|
-
/**
|
|
87
|
-
* The stack's token, on which a service of the stack keeps gkm's client
|
|
88
|
-
* address through the edge — see `clientIpRule`.
|
|
89
|
-
*/
|
|
90
|
-
edgeToken?: string;
|
|
91
|
-
}
|
|
92
|
-
/** A stack's dynamic configuration, as an object. */
|
|
93
|
-
export declare function traefikDynamic(routes: readonly EdgeRoute[], options: TraefikStackOptions): Record<string, unknown>;
|
|
94
|
-
/**
|
|
95
|
-
* A host a stack routes on the shared edge: one name, or — for a wildcard
|
|
96
|
-
* site — every one label under a domain but the ones it never takes.
|
|
97
|
-
*/
|
|
98
|
-
export type EdgeClaim = {
|
|
99
|
-
host: string;
|
|
100
|
-
} | {
|
|
101
|
-
wildcard: string;
|
|
102
|
-
except: readonly string[];
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* What a stack's routes claim on the edge, from the route model: one claim
|
|
106
|
-
* per host, each route's aliases and redirects included.
|
|
107
|
-
*/
|
|
108
|
-
export declare function edgeClaims(routes: readonly EdgeRoute[]): EdgeClaim[];
|
|
109
|
-
/**
|
|
110
|
-
* The hosts a stack's file on the edge claims: from its claims line, or — a
|
|
111
|
-
* file written before gkm wrote one — from its routers' rules, in the shapes
|
|
112
|
-
* `traefikDynamic` renders them.
|
|
113
|
-
*/
|
|
114
|
-
export declare function readEdgeClaims(file: string): EdgeClaim[];
|
|
115
|
-
/**
|
|
116
|
-
* Where two claims meet, as a host to name — or undefined where they never
|
|
117
|
-
* do. A wildcard takes one label under its domain, so it meets a name one
|
|
118
|
-
* label under it that it does not leave out, and another wildcard on the
|
|
119
|
-
* same domain.
|
|
120
|
-
*/
|
|
121
|
-
export declare function claimsOverlap(a: EdgeClaim, b: EdgeClaim): string | undefined;
|
|
122
|
-
/** A stack's dynamic configuration file, as written to the edge's directory. */
|
|
123
|
-
export declare function traefikDynamicFile(routes: readonly EdgeRoute[], options: TraefikStackOptions): string;
|
|
124
|
-
/** The edge's static configuration file. */
|
|
125
|
-
export declare function traefikStaticFile(ports: EdgePorts): string;
|
|
126
|
-
/** The edge's compose file. */
|
|
127
|
-
export declare function edgeComposeFile(options: Parameters<typeof edgeCompose>[0]): string;
|
|
128
|
-
//#endregion
|
|
129
|
-
//# sourceMappingURL=traefik.d.mts.map
|
|
1
|
+
import { A as EdgeClaim, B as edgeComposeFile, C as EDGE_AWS_CREDENTIALS, D as EDGE_PROJECT, E as EDGE_NETWORK, F as claimsOverlap, G as traefikDynamic, H as edgeProject, I as edgeAlias, J as traefikStaticFile, K as traefikDynamicFile, L as edgeCertificatePaths, M as TRAEFIK_IMAGE, N as TraefikStackOptions, O as EDGE_PROJECT_ENV, P as acmeDnsResolver, R as edgeClaims, S as DEFAULT_EDGE_PROJECT, T as EDGE_DYNAMIC_DIR, U as isAcmeDnsProvider, V as edgeDnsSecretPath, W as readEdgeClaims, _ as ACME_DNS_RESOLVER, b as AcmeDnsChallenge, g as ACME_DNS_CHALLENGES, j as EdgePorts, k as EDGE_SERVICE, q as traefikStatic, v as ACME_DNS_SECRET_KEYS, w as EDGE_CERTS_DIR, x as AcmeDnsProvider, y as ACME_RESOLVER, z as edgeCompose } from "../index-BVE0VFku.mjs";
|
|
2
|
+
export { ACME_DNS_CHALLENGES, ACME_DNS_RESOLVER, ACME_DNS_SECRET_KEYS, ACME_RESOLVER, AcmeDnsChallenge, AcmeDnsProvider, DEFAULT_EDGE_PROJECT, EDGE_AWS_CREDENTIALS, EDGE_CERTS_DIR, EDGE_DYNAMIC_DIR, EDGE_NETWORK, EDGE_PROJECT, EDGE_PROJECT_ENV, EDGE_SERVICE, EdgeClaim, EdgePorts, TRAEFIK_IMAGE, TraefikStackOptions, acmeDnsResolver, claimsOverlap, edgeAlias, edgeCertificatePaths, edgeClaims, edgeCompose, edgeComposeFile, edgeDnsSecretPath, edgeProject, isAcmeDnsProvider, readEdgeClaims, traefikDynamic, traefikDynamicFile, traefikStatic, traefikStaticFile };
|
package/dist/proxy/traefik.mjs
CHANGED
|
@@ -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,10 +210,7 @@ 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"],
|
|
156
215
|
extra_hosts: [`${HOST_GATEWAY}:host-gateway`],
|
|
157
216
|
...EDGE_LIMITS,
|
|
@@ -225,7 +284,7 @@ function traefikDynamic(routes, options) {
|
|
|
225
284
|
const paths = allowed.length ? ` && (${allowed.join(" || ")})` : "";
|
|
226
285
|
const header = route.requireHeader ? ` && Header(\`${route.requireHeader.name}\`, \`${route.requireHeader.value}\`)` : "";
|
|
227
286
|
const certificate = () => route.wildcard?.tls.kind === "dns" ? {
|
|
228
|
-
certResolver:
|
|
287
|
+
certResolver: acmeDnsResolver(route.wildcard.tls.provider),
|
|
229
288
|
domains: [{ main: `*.${route.wildcard.domain}` }]
|
|
230
289
|
} : tls.kind === "acme" ? { certResolver: ACME_RESOLVER } : {};
|
|
231
290
|
for (const handler of route.handlers ?? []) {
|
|
@@ -435,6 +494,6 @@ function yaml(value) {
|
|
|
435
494
|
});
|
|
436
495
|
}
|
|
437
496
|
//#endregion
|
|
438
|
-
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 };
|
|
439
498
|
|
|
440
499
|
//# sourceMappingURL=traefik.mjs.map
|