@geekmidas/edge 10.0.0-alpha.185 → 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.
@@ -0,0 +1,427 @@
1
+ //#region src/proxy/traefik.d.ts
2
+ /**
3
+ * The image, pinned: the edge is every stack's way in, so a new version is a
4
+ * change to this line, not whatever `latest` is on the day a server starts.
5
+ */
6
+ declare const TRAEFIK_IMAGE = "traefik:v3.7.13";
7
+ /** The edge's name when nothing renames it: one per server. */
8
+ declare const DEFAULT_EDGE_PROJECT = "gkm-edge";
9
+ /**
10
+ * The variable that renames the edge — its compose project, and with it its
11
+ * network and its volumes (`<project>_acme`, `_certs`, `_dynamic`). A testing
12
+ * and advanced knob: an end-to-end suite runs an edge of its own beside a
13
+ * developer's, and never touches theirs. Every command that registers with
14
+ * one edge must be run with the same value.
15
+ */
16
+ declare const EDGE_PROJECT_ENV = "GKM_EDGE_PROJECT";
17
+ /** The edge's compose project: `GKM_EDGE_PROJECT`, else `gkm-edge`. */
18
+ declare function edgeProject(env?: NodeJS.ProcessEnv): string;
19
+ /**
20
+ * The edge's compose project, one per server — read once, when gkm starts,
21
+ * so every step of a run names the same edge.
22
+ */
23
+ declare const EDGE_PROJECT: string;
24
+ /**
25
+ * The external network the edge and every stack's public services share:
26
+ * named after the edge, so a renamed edge has a network of its own.
27
+ */
28
+ declare const EDGE_NETWORK: string;
29
+ /** The edge's compose service. */
30
+ declare const EDGE_SERVICE = "traefik";
31
+ /** Inside the edge's container: what it watches, and where certificates are. */
32
+ declare const EDGE_DYNAMIC_DIR = "/etc/gkm-edge/dynamic";
33
+ declare const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
34
+ /** The certificate resolver every deployed route without its own certificate uses. */
35
+ declare const ACME_RESOLVER = "letsencrypt";
36
+ /**
37
+ * The key the edge writes Route 53's challenge records with, inside its
38
+ * container: written by the deploy of a stage with a wildcard site, and
39
+ * allowed nothing but each such stage's `_acme-challenge` record (see
40
+ * `acmeDns.ts`).
41
+ */
42
+ declare const EDGE_AWS_CREDENTIALS = "/etc/gkm-edge/certs/aws-credentials";
43
+ /**
44
+ * How the edge answers Let's Encrypt's DNS challenge through one DNS
45
+ * provider: Traefik's (lego's) name for it, and what it reads.
46
+ */
47
+ interface AcmeDnsChallenge {
48
+ /** The provider's code in Traefik's `dnsChallenge.provider`. */
49
+ provider: string;
50
+ /**
51
+ * The stage secrets the provider reads, by the variable lego reads each
52
+ * from. The deploy writes each into its own file in the edge's container
53
+ * (`0600`, see {@link edgeDnsSecretPath}), and the edge is handed only
54
+ * the file's path, as `<KEY>_FILE` — which lego reads in place of `<KEY>`.
55
+ * Never a value in the compose file or the static configuration.
56
+ */
57
+ secrets: readonly string[];
58
+ /** What else the edge's environment says for it — never a secret. */
59
+ environment?: Readonly<Record<string, string>>;
60
+ }
61
+ /**
62
+ * Every DNS provider the edge can get a wildcard certificate through, by the
63
+ * name a workspace's `dns` entry gives it. Another provider is one entry
64
+ * here — lego's code for it and the variables it reads — and nothing else:
65
+ * its resolver, its ACME storage and its edge environment follow from it.
66
+ *
67
+ * Route 53's key is the one exception to "from the stage's secrets": the
68
+ * deploy issues it through IAM, scoped to the stage's challenge record
69
+ * alone, and writes it into the edge itself (`acmeDns.ts`).
70
+ */
71
+ declare const ACME_DNS_CHALLENGES: {
72
+ readonly route53: {
73
+ readonly provider: 'route53';
74
+ readonly secrets: readonly [];
75
+ readonly environment: {
76
+ readonly AWS_SHARED_CREDENTIALS_FILE: "/etc/gkm-edge/certs/aws-credentials";
77
+ readonly AWS_REGION: 'us-east-1';
78
+ };
79
+ };
80
+ readonly godaddy: {
81
+ readonly provider: 'godaddy';
82
+ readonly secrets: readonly ["GODADDY_API_KEY", "GODADDY_API_SECRET"];
83
+ };
84
+ };
85
+ /** A DNS provider the edge answers the DNS challenge through. */
86
+ type AcmeDnsProvider = keyof typeof ACME_DNS_CHALLENGES;
87
+ /** Whether the edge can answer the DNS challenge through `provider`. */
88
+ declare function isAcmeDnsProvider(provider: unknown): provider is AcmeDnsProvider;
89
+ /** Route 53's DNS-challenge resolver — see {@link acmeDnsResolver}. */
90
+ declare const ACME_DNS_RESOLVER = "letsencrypt-dns";
91
+ /**
92
+ * The resolver a wildcard site's `*.<domain>` certificate comes from, for
93
+ * the DNS provider that holds the domain: Let's Encrypt issues a wildcard
94
+ * only over the DNS challenge, which the edge answers by writing an
95
+ * `_acme-challenge` TXT record through that provider. Route 53's keeps the
96
+ * name it had before there were others, so its certificates stay where they
97
+ * are.
98
+ */
99
+ declare function acmeDnsResolver(provider: AcmeDnsProvider): string;
100
+ /**
101
+ * A DNS provider's secret, inside the edge's container: one file per key,
102
+ * beside the certificates, readable by the edge alone.
103
+ */
104
+ declare function edgeDnsSecretPath(key: string): string;
105
+ /** Every stage secret the edge's DNS challenge reads, for any provider. */
106
+ declare const ACME_DNS_SECRET_KEYS: readonly string[];
107
+ /** A stack's service, as the edge — and the stack itself — reach it. */
108
+ declare function edgeAlias(project: string, service: string): string;
109
+ /** A stack's certificate, as the edge's container reads it. */
110
+ declare function edgeCertificatePaths(project: string): {
111
+ certFile: string;
112
+ keyFile: string;
113
+ };
114
+ /** The edge's ports on the host. */
115
+ interface EdgePorts {
116
+ https: number;
117
+ http: number;
118
+ }
119
+ /**
120
+ * The edge's static configuration: the entrypoints, the redirect, ACME, and
121
+ * the directory it watches. No API and no dashboard — nothing about the edge
122
+ * is reachable but the routes stacks register.
123
+ */
124
+ declare function traefikStatic(ports: EdgePorts): Record<string, unknown>;
125
+ /** The edge's compose document. */
126
+ declare function edgeCompose(options: {
127
+ ports: EdgePorts;
128
+ /**
129
+ * The static configuration, as written: handed to the container inline
130
+ * (`configs.content`), so nothing is read from a path on whichever machine
131
+ * runs the deploy — and its hash recreates the edge when it changes.
132
+ */
133
+ staticConfig: string;
134
+ logging: {
135
+ driver: string;
136
+ options: Record<string, string>;
137
+ };
138
+ }): Record<string, unknown>;
139
+ /** What a stack registers with the edge — its routes, and its certificate. */
140
+ interface TraefikStackOptions {
141
+ project: string;
142
+ /** ACME, or the stage's own certificate. */
143
+ tls: EdgeTls;
144
+ /**
145
+ * The stack's token, on which a service of the stack keeps gkm's client
146
+ * address through the edge — see `clientIpRule`.
147
+ */
148
+ edgeToken?: string;
149
+ }
150
+ /** A stack's dynamic configuration, as an object. */
151
+ declare function traefikDynamic(routes: readonly EdgeRoute[], options: TraefikStackOptions): Record<string, unknown>;
152
+ /**
153
+ * A host a stack routes on the shared edge: one name, or — for a wildcard
154
+ * site — every one label under a domain but the ones it never takes.
155
+ */
156
+ type EdgeClaim = {
157
+ host: string;
158
+ } | {
159
+ wildcard: string;
160
+ except: readonly string[];
161
+ };
162
+ /**
163
+ * What a stack's routes claim on the edge, from the route model: one claim
164
+ * per host, each route's aliases and redirects included.
165
+ */
166
+ declare function edgeClaims(routes: readonly EdgeRoute[]): EdgeClaim[];
167
+ /**
168
+ * The hosts a stack's file on the edge claims: from its claims line, or — a
169
+ * file written before gkm wrote one — from its routers' rules, in the shapes
170
+ * `traefikDynamic` renders them.
171
+ */
172
+ declare function readEdgeClaims(file: string): EdgeClaim[];
173
+ /**
174
+ * Where two claims meet, as a host to name — or undefined where they never
175
+ * do. A wildcard takes one label under its domain, so it meets a name one
176
+ * label under it that it does not leave out, and another wildcard on the
177
+ * same domain.
178
+ */
179
+ declare function claimsOverlap(a: EdgeClaim, b: EdgeClaim): string | undefined;
180
+ /** A stack's dynamic configuration file, as written to the edge's directory. */
181
+ declare function traefikDynamicFile(routes: readonly EdgeRoute[], options: TraefikStackOptions): string;
182
+ /** The edge's static configuration file. */
183
+ declare function traefikStaticFile(ports: EdgePorts): string;
184
+ /** The edge's compose file. */
185
+ declare function edgeComposeFile(options: Parameters<typeof edgeCompose>[0]): string;
186
+ //#endregion
187
+ //#region src/routes/index.d.ts
188
+ /** Where a route sends its requests. */
189
+ type Upstream = ServiceUpstream | HostUpstream;
190
+ /** A service of the stack that a route sends to. */
191
+ interface ServiceUpstream {
192
+ /** Its compose service name — `api`, `minio`. */
193
+ service: string;
194
+ /** The port it listens on, inside the network. */
195
+ port: number;
196
+ }
197
+ /**
198
+ * A process on the Docker host itself, outside every stack — an app `gkm dev`
199
+ * runs, or a port a container publishes there — reached from the proxy's
200
+ * container through the host's gateway ({@link HOST_GATEWAY}).
201
+ */
202
+ interface HostUpstream {
203
+ onHost: true;
204
+ /** The port it listens on, on the host. */
205
+ port: number;
206
+ }
207
+ /**
208
+ * The host's own address, from inside a container. Docker Desktop resolves
209
+ * it already; on Linux the proxy's compose definition maps it to the host
210
+ * gateway (`extra_hosts`).
211
+ */
212
+ declare const HOST_GATEWAY = "host.docker.internal";
213
+ /** An upstream's `host:port`, as a proxy on the stack's network dials it. */
214
+ declare function upstreamAddress(upstream: Upstream,
215
+ /** How a service of the stack is named where the proxy runs. */
216
+ service?: (name: string) => string): string;
217
+ /** One public host and what answers it. */
218
+ interface EdgeRoute {
219
+ /**
220
+ * Its name within the stack — unique there, and what a renderer names
221
+ * its routers and middlewares after: `api`, `files-uploads`.
222
+ */
223
+ name: string;
224
+ /** e.g. `api.example.com` — the canonical host, its `<ID>_URL`'s. */
225
+ host: string;
226
+ /**
227
+ * More hosts answered exactly as `host` is — a construct's `aliases`:
228
+ * every check, handler and upstream of the route holds on each of them.
229
+ */
230
+ aliases?: readonly string[];
231
+ /**
232
+ * Hosts answered with a permanent redirect to `to`, the canonical origin
233
+ * (`https://example.com`, with the edge's port where it is not 443), path
234
+ * and query kept — a site's `redirects`. Nothing is proxied for them.
235
+ */
236
+ redirects?: {
237
+ hosts: readonly string[];
238
+ to: string;
239
+ };
240
+ /**
241
+ * Where requests go. One today; a release that swaps containers without
242
+ * downtime routes to the old and the new while it does.
243
+ */
244
+ upstreams: readonly Upstream[];
245
+ /**
246
+ * Never buffer the response: a streamed one — server-sent events, a
247
+ * Next.js RSC payload — reaches the client as each chunk is written.
248
+ */
249
+ streaming: boolean;
250
+ /**
251
+ * A path prefix added before the request is sent, with the upstream's own
252
+ * address as `Host`: a bucket, served at a host of its own, is a prefix
253
+ * on MinIO, which routes and signs on the Host header.
254
+ */
255
+ prefix?: string;
256
+ /**
257
+ * The client addresses (IPs or CIDRs) it answers; every other is refused
258
+ * with 403, before the request reaches the upstream. Absent, it answers
259
+ * everyone. Matched against the peer the proxy sees, never a header a
260
+ * client could set.
261
+ */
262
+ allow?: readonly string[];
263
+ /**
264
+ * The only paths it answers, matched exactly; every other is refused at
265
+ * the edge, before the request reaches the upstream. Absent, it answers
266
+ * every path. A worker is reached only on the routes SNS pushes to.
267
+ */
268
+ paths?: readonly string[];
269
+ /**
270
+ * Path prefixes it answers besides `paths` — `/i/` admits everything
271
+ * under it. Together they are the whole allowlist; absent both, it
272
+ * answers every path. A processor unit's own host is reached only on its
273
+ * processors' prefixes.
274
+ */
275
+ prefixes?: readonly string[];
276
+ /**
277
+ * A header every request must carry, with exactly this value; any other
278
+ * is refused at the edge. What a CDN adds to reach its origin, so the
279
+ * origin's public host cannot be called around the CDN.
280
+ */
281
+ requireHeader?: {
282
+ name: string;
283
+ value: string;
284
+ };
285
+ /**
286
+ * Path prefixes on this host sent to another upstream, ahead of the
287
+ * route's own: a file server's processor patterns, to its processor unit,
288
+ * while every other path is the bucket. Served at the path asked for —
289
+ * no `prefix` — and never combined with `allow`, `paths`, `prefixes` or
290
+ * `requireHeader`, which would have to hold for every handler too.
291
+ */
292
+ handlers?: readonly EdgeHandler[];
293
+ /**
294
+ * The login every request must carry — HTTP basic auth, asked for by the
295
+ * edge before anything reaches the upstream. Absent, it asks for none.
296
+ * The password's bcrypt hash, never the password.
297
+ */
298
+ auth?: {
299
+ user: string;
300
+ hash: string;
301
+ };
302
+ /**
303
+ * What one client address may ask of it — a WebSocket surface's
304
+ * handshakes a minute and open sockets — refused with 429 at the edge.
305
+ * Rendered for Traefik (`rateLimit`, `inFlightReq`); Caddy ships no rate
306
+ * limiter, so behind it the surface's own count is what holds.
307
+ */
308
+ limits?: {
309
+ handshakesPerMinute?: number;
310
+ connectionsPerIp?: number;
311
+ };
312
+ /** The path the upstream answers its health on — `/health`, `/`. */
313
+ health?: string;
314
+ /**
315
+ * For a wildcard site's route, whose `host` is `*.<domain>`: every one
316
+ * label under the domain that no other route answers, and how its
317
+ * certificate is had. Named hosts always win over it.
318
+ */
319
+ wildcard?: EdgeWildcard;
320
+ }
321
+ /**
322
+ * Every host a route answers on — its own, its aliases and its redirects —
323
+ * in that order: what DNS, certificates and the edge's claims cover.
324
+ */
325
+ declare function routeHosts(route: EdgeRoute): string[];
326
+ /** How a `*.<domain>` route is matched and certified. */
327
+ interface EdgeWildcard {
328
+ /** The domain under the `*` — `example.com`. */
329
+ domain: string;
330
+ /**
331
+ * Labels under the domain that never reach it, although no route of this
332
+ * stack answers them: the protected subdomains (`www`, `mail`), and a
333
+ * stage whose domain sits under this one's (`staging`).
334
+ */
335
+ except: readonly string[];
336
+ /**
337
+ * Where its certificate comes from:
338
+ * - `stage`: the stage's own (`deploy.compose.tls`), a wildcard one;
339
+ * - `dns`: one `*.<domain>` certificate from Let's Encrypt over the DNS
340
+ * challenge, which the shared Traefik edge answers through `provider`
341
+ * — the DNS provider holding the domain;
342
+ * - `on-demand`: one per host, as Caddy is first asked for it, once the
343
+ * site's `hosts` route — `ask`, on the stack's network — answers 200.
344
+ */
345
+ tls: {
346
+ kind: 'stage';
347
+ } | {
348
+ kind: 'dns';
349
+ provider: AcmeDnsProvider;
350
+ } | {
351
+ kind: 'on-demand';
352
+ ask: string;
353
+ };
354
+ /**
355
+ * The site's `hosts` route, asked before each request a label makes —
356
+ * `GET <path>?domain=<host>` on `upstream` — where a certificate already
357
+ * covers every label (gkm's local one): a 2xx serves the label, and any
358
+ * other answer is what the client gets. Rendered by Caddy (`forward_auth`);
359
+ * Traefik's `forwardAuth` cannot hand the host as `domain`, so behind it
360
+ * every label but `except` reaches the site, as a deployed Traefik stage's
361
+ * do.
362
+ */
363
+ hosts?: {
364
+ upstream: Upstream;
365
+ path: string;
366
+ };
367
+ }
368
+ /** Some of a route's paths, answered by another upstream. */
369
+ interface EdgeHandler {
370
+ /** Unique within the route: what a renderer names its router after. */
371
+ name: string;
372
+ /** e.g. `/i/` — everything under it. */
373
+ prefixes: readonly string[];
374
+ upstreams: readonly Upstream[];
375
+ /**
376
+ * A path prefix added before the request is sent — where the upstream
377
+ * mounts what it answers: a dev server holding a file server's
378
+ * processors, under `/__gkm/processors/<id>`.
379
+ */
380
+ under?: string;
381
+ }
382
+ /** A route with handlers and a check that would have to hold for each of them. */
383
+ declare class EdgeRouteConflict extends Error {
384
+ readonly route: string;
385
+ constructor(route: string);
386
+ }
387
+ /** @throws {EdgeRouteConflict} */
388
+ declare function assertRouteRenderable(route: EdgeRoute): void;
389
+ /** Where a stack's certificates come from. */
390
+ type EdgeTls =
391
+ /** A deployed stage: Let's Encrypt, over HTTP-01, on first request. */
392
+ {
393
+ kind: 'acme';
394
+ } |
395
+ /**
396
+ * A certificate and key, as the proxy's container reads them: a deployed
397
+ * stage's own (`deploy.compose.tls`), or — on the local stage — the one
398
+ * gkm's local authority issued (`trust/authority.ts`).
399
+ */
400
+ {
401
+ kind: 'files';
402
+ certFile: string;
403
+ keyFile: string;
404
+ };
405
+ /** File descriptors a process holding sockets may open. */
406
+ declare const NOFILE: {
407
+ soft: number;
408
+ hard: number;
409
+ };
410
+ /**
411
+ * What the edge runs with: a descriptor per socket, twice — the client's and
412
+ * the upstream's — and every local port for those upstream connections. One
413
+ * edge address to one upstream has only the ephemeral range to open
414
+ * connections from, ~28k by Linux's default; widened, ~64k per replica.
415
+ */
416
+ declare const EDGE_LIMITS: {
417
+ sysctls: Record<string, string>;
418
+ ulimits: Record<string, {
419
+ soft: number;
420
+ hard: number;
421
+ }>;
422
+ };
423
+ /** The proxies a stack can be served by — `deploy.compose.proxy`. */
424
+ type ComposeProxy = 'caddy' | 'traefik';
425
+ //#endregion
426
+ export { EdgeClaim as A, edgeComposeFile as B, EDGE_AWS_CREDENTIALS as C, EDGE_PROJECT as D, EDGE_NETWORK as E, claimsOverlap as F, traefikDynamic as G, edgeProject as H, edgeAlias as I, traefikStaticFile as J, traefikDynamicFile as K, edgeCertificatePaths as L, TRAEFIK_IMAGE as M, TraefikStackOptions as N, EDGE_PROJECT_ENV as O, acmeDnsResolver as P, edgeClaims as R, DEFAULT_EDGE_PROJECT as S, EDGE_DYNAMIC_DIR as T, isAcmeDnsProvider as U, edgeDnsSecretPath as V, readEdgeClaims as W, ACME_DNS_RESOLVER as _, EdgeRouteConflict as a, AcmeDnsChallenge as b, HOST_GATEWAY as c, ServiceUpstream as d, Upstream as f, ACME_DNS_CHALLENGES as g, upstreamAddress as h, EdgeRoute as i, EdgePorts as j, EDGE_SERVICE as k, HostUpstream as l, routeHosts as m, EDGE_LIMITS as n, EdgeTls as o, assertRouteRenderable as p, traefikStatic as q, EdgeHandler as r, EdgeWildcard as s, ComposeProxy as t, NOFILE as u, ACME_DNS_SECRET_KEYS as v, EDGE_CERTS_DIR as w, AcmeDnsProvider as x, ACME_RESOLVER as y, edgeCompose as z };
427
+ //# sourceMappingURL=index-BVE0VFku.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BVE0VFku.d.mts","names":[],"sources":["../src/proxy/traefik.ts","../src/routes/index.ts"],"mappings":";;;;;cAwCa;;cAGA;;;;;;;;cASA;;iBAGG,YAAY,MAAK,OAAO;;;;;cAQ3B;;;;;cAMA;;cAGA;;cAGA;cACA;;cAGA;;;;;;;cAQA;;;;;UAMI;;EAEhB;;;;;;;;EAQA;;EAEA,cAAc,SAAS;;;;;;;;;;;;cAaX;;aAEX;aACA;aACA;eACC;eACA;;;;aAID;aACA;;;;KAKU,+BAA+B;;iBAG3B,kBACf,oBACE,YAAY;;cAOF;;;;;;;;;iBAUG,gBAAgB,UAAU;;;;;iBAiB1B,kBAAkB;;cAKrB;;iBAyBG,UAAU,iBAAiB;;iBAK3B,qBAAqB;EACpC;EACA;;;UASgB;EAChB;EACA;;;;;;;iBAQe,cAAc,OAAO,YAAY;;iBA4DjC,YAAY;EAC3B,OAAO;;;;;;EAMP;EACA;IAAW;IAAgB,SAAS;;IACjC;;UAsDa;EAChB;;EAEA,KAAK;;;;;EAKL;;;iBAIe,eACf,iBAAiB,aACjB,SAAS,sBACP;;;;;KA0PS;EACP;;EACA;EAAkB;;;;;;iBAMP,WAAW,iBAAiB,cAAc;;;;;;iBAyB1C,eAAe,eAAe;;;;;;;iBAqE9B,cAAc,GAAG,WAAW,GAAG;;iBAqB/B,mBACf,iBAAiB,aACjB,SAAS;;iBAWM,kBAAkB,OAAO;;iBAMzB,gBACf,SAAS,kBAAkB;;;;KC5uBhB,WAAW,kBAAkB;;UAGxB;;EAEhB;;EAEA;;;;;;;UAQgB;EAChB;;EAEA;;;;;;;cAQY;;iBAGG,gBACf,UAAU,UAEV;;AAAA,WAAU;;UAQM;;;;;EAKhB;;EAEA;;;;;EAKA;;;;;;EAMA;IAAc;IAA0B;;;;;;EAKxC,oBAAoB;;;;;EAKpB;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;IAAkB;IAAc;;;;;;;;;EAQhC,oBAAoB;;;;;;EAMpB;IAAS;IAAc;;;;;;;;EAOvB;IAAW;IAA8B;;;EAEzC;;;;;;EAMA,WAAW;;;;;;iBAOI,WAAW,OAAO;;UASjB;;EAEhB;;;;;;EAMA;;;;;;;;;;EAUA;IACK;;IACA;IAAa,UAAU;;IACvB;IAAmB;;;;;;;;;;;EAUxB;IAAU,UAAU;IAAU;;;;UAId;;EAEhB;;EAEA;EACA,oBAAoB;;;;;;EAMpB;;;cAIY,0BAA0B;WACjB;EAArB,YAAqB;;;iBAWN,sBAAsB,OAAO;;KAUjC;;;EAEP;;;;;;;;EAMA;EAAe;EAAkB;;;cAGzB;EAAW;EAAiB;;;;;;;;cAQ5B;EACZ,SAAS;EACT,SAAS;IAAiB;IAAc;;;;KAO7B"}
@@ -1,4 +1,4 @@
1
- import { EdgeRoute, EdgeTls } from "../routes/index.cjs";
1
+ import { i as EdgeRoute, o as EdgeTls } from "../index-BVE0VFku.cjs";
2
2
  //#region src/proxy/caddy.d.ts
3
3
  /** Where Caddy reads a stage's own certificate, inside its container. */
4
4
  export declare const CADDY_TLS_DIR = "/etc/caddy/tls";
@@ -1,4 +1,4 @@
1
- import { EdgeRoute, EdgeTls } from "../routes/index.mjs";
1
+ import { i as EdgeRoute, o as EdgeTls } from "../index-BVE0VFku.mjs";
2
2
  //#region src/proxy/caddy.d.ts
3
3
  /** Where Caddy reads a stage's own certificate, inside its container. */
4
4
  export declare const CADDY_TLS_DIR = "/etc/caddy/tls";
@@ -62,17 +62,79 @@ const EDGE_CERTS_DIR = "/etc/gkm-edge/certs";
62
62
  /** The certificate resolver every deployed route without its own certificate uses. */
63
63
  const ACME_RESOLVER = "letsencrypt";
64
64
  /**
65
- * The resolver a wildcard site's `*.<domain>` certificate comes from: Let's
66
- * Encrypt issues a wildcard only over the DNS challenge, which the edge
67
- * answers by writing an `_acme-challenge` TXT record through Route 53.
65
+ * The key the edge writes Route 53's challenge records with, inside its
66
+ * container: written by the deploy of a stage with a wildcard site, and
67
+ * allowed nothing but each such stage's `_acme-challenge` record (see
68
+ * `acmeDns.ts`).
68
69
  */
70
+ const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;
71
+ /**
72
+ * Every DNS provider the edge can get a wildcard certificate through, by the
73
+ * name a workspace's `dns` entry gives it. Another provider is one entry
74
+ * here — lego's code for it and the variables it reads — and nothing else:
75
+ * its resolver, its ACME storage and its edge environment follow from it.
76
+ *
77
+ * Route 53's key is the one exception to "from the stage's secrets": the
78
+ * deploy issues it through IAM, scoped to the stage's challenge record
79
+ * alone, and writes it into the edge itself (`acmeDns.ts`).
80
+ */
81
+ const ACME_DNS_CHALLENGES = {
82
+ route53: {
83
+ provider: "route53",
84
+ secrets: [],
85
+ environment: {
86
+ AWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,
87
+ AWS_REGION: "us-east-1"
88
+ }
89
+ },
90
+ godaddy: {
91
+ provider: "godaddy",
92
+ secrets: ["GODADDY_API_KEY", "GODADDY_API_SECRET"]
93
+ }
94
+ };
95
+ /** Whether the edge can answer the DNS challenge through `provider`. */
96
+ function isAcmeDnsProvider(provider) {
97
+ return typeof provider === "string" && Object.hasOwn(ACME_DNS_CHALLENGES, provider);
98
+ }
99
+ /** Route 53's DNS-challenge resolver — see {@link acmeDnsResolver}. */
69
100
  const ACME_DNS_RESOLVER = "letsencrypt-dns";
70
101
  /**
71
- * The key the edge writes those records with, inside its container: written
72
- * by the deploy of a stage with a wildcard site, and allowed nothing but
73
- * each such stage's `_acme-challenge` record (see `acmeDns.ts`).
102
+ * The resolver a wildcard site's `*.<domain>` certificate comes from, for
103
+ * the DNS provider that holds the domain: Let's Encrypt issues a wildcard
104
+ * only over the DNS challenge, which the edge answers by writing an
105
+ * `_acme-challenge` TXT record through that provider. Route 53's keeps the
106
+ * name it had before there were others, so its certificates stay where they
107
+ * are.
74
108
  */
75
- const EDGE_AWS_CREDENTIALS = `${EDGE_CERTS_DIR}/aws-credentials`;
109
+ function acmeDnsResolver(provider) {
110
+ return provider === "route53" ? ACME_DNS_RESOLVER : `${ACME_DNS_RESOLVER}-${provider}`;
111
+ }
112
+ /** Where a DNS-challenge resolver keeps its account and certificates. */
113
+ function acmeDnsStorage(provider) {
114
+ return provider === "route53" ? "/acme/acme-dns.json" : `/acme/acme-dns-${provider}.json`;
115
+ }
116
+ /**
117
+ * A DNS provider's secret, inside the edge's container: one file per key,
118
+ * beside the certificates, readable by the edge alone.
119
+ */
120
+ function edgeDnsSecretPath(key) {
121
+ return `${EDGE_CERTS_DIR}/acme-dns-${key}`;
122
+ }
123
+ /** Every stage secret the edge's DNS challenge reads, for any provider. */
124
+ const ACME_DNS_SECRET_KEYS = Object.values(ACME_DNS_CHALLENGES).flatMap((challenge) => [...challenge.secrets]);
125
+ /**
126
+ * What the edge's environment says for the DNS challenge, every provider's:
127
+ * where each key is read from, never a key.
128
+ */
129
+ function acmeDnsEnvironment() {
130
+ const environment = {};
131
+ const challenges = Object.values(ACME_DNS_CHALLENGES);
132
+ for (const challenge of challenges) {
133
+ Object.assign(environment, challenge.environment);
134
+ for (const key of challenge.secrets) environment[`${key}_FILE`] = edgeDnsSecretPath(key);
135
+ }
136
+ return environment;
137
+ }
76
138
  /** The internal entrypoint the edge's health check asks; never published. */
77
139
  const PING_PORT = 8082;
78
140
  /** A stack's service, as the edge — and the stack itself — reach it. */
@@ -119,13 +181,13 @@ function traefikStatic(ports) {
119
181
  storage: "/acme/acme.json",
120
182
  httpChallenge: { entryPoint: "web" }
121
183
  } },
122
- [ACME_DNS_RESOLVER]: { acme: {
123
- storage: "/acme/acme-dns.json",
184
+ ...Object.fromEntries(Object.entries(ACME_DNS_CHALLENGES).map(([name, challenge]) => [acmeDnsResolver(name), { acme: {
185
+ storage: acmeDnsStorage(name),
124
186
  dnsChallenge: {
125
- provider: "route53",
187
+ provider: challenge.provider,
126
188
  resolvers: ["1.1.1.1:53", "8.8.8.8:53"]
127
189
  }
128
- } }
190
+ } }]))
129
191
  },
130
192
  log: { level: "INFO" }
131
193
  };
@@ -149,10 +211,7 @@ function edgeCompose(options) {
149
211
  "acme:/acme"
150
212
  ],
151
213
  labels: { "dev.geekmidas.edge.config": (0, node_crypto.createHash)("sha256").update(options.staticConfig).digest("hex").slice(0, 16) },
152
- environment: {
153
- AWS_SHARED_CREDENTIALS_FILE: EDGE_AWS_CREDENTIALS,
154
- AWS_REGION: "us-east-1"
155
- },
214
+ environment: acmeDnsEnvironment(),
156
215
  networks: ["edge"],
157
216
  extra_hosts: [`${require_routes_index.HOST_GATEWAY}:host-gateway`],
158
217
  ...require_routes_index.EDGE_LIMITS,
@@ -226,7 +285,7 @@ function traefikDynamic(routes, options) {
226
285
  const paths = allowed.length ? ` && (${allowed.join(" || ")})` : "";
227
286
  const header = route.requireHeader ? ` && Header(\`${route.requireHeader.name}\`, \`${route.requireHeader.value}\`)` : "";
228
287
  const certificate = () => route.wildcard?.tls.kind === "dns" ? {
229
- certResolver: ACME_DNS_RESOLVER,
288
+ certResolver: acmeDnsResolver(route.wildcard.tls.provider),
230
289
  domains: [{ main: `*.${route.wildcard.domain}` }]
231
290
  } : tls.kind === "acme" ? { certResolver: ACME_RESOLVER } : {};
232
291
  for (const handler of route.handlers ?? []) {
@@ -436,7 +495,9 @@ function yaml$1(value) {
436
495
  });
437
496
  }
438
497
  //#endregion
498
+ exports.ACME_DNS_CHALLENGES = ACME_DNS_CHALLENGES;
439
499
  exports.ACME_DNS_RESOLVER = ACME_DNS_RESOLVER;
500
+ exports.ACME_DNS_SECRET_KEYS = ACME_DNS_SECRET_KEYS;
440
501
  exports.ACME_RESOLVER = ACME_RESOLVER;
441
502
  exports.DEFAULT_EDGE_PROJECT = DEFAULT_EDGE_PROJECT;
442
503
  exports.EDGE_AWS_CREDENTIALS = EDGE_AWS_CREDENTIALS;
@@ -447,13 +508,16 @@ exports.EDGE_PROJECT = EDGE_PROJECT;
447
508
  exports.EDGE_PROJECT_ENV = EDGE_PROJECT_ENV;
448
509
  exports.EDGE_SERVICE = EDGE_SERVICE;
449
510
  exports.TRAEFIK_IMAGE = TRAEFIK_IMAGE;
511
+ exports.acmeDnsResolver = acmeDnsResolver;
450
512
  exports.claimsOverlap = claimsOverlap;
451
513
  exports.edgeAlias = edgeAlias;
452
514
  exports.edgeCertificatePaths = edgeCertificatePaths;
453
515
  exports.edgeClaims = edgeClaims;
454
516
  exports.edgeCompose = edgeCompose;
455
517
  exports.edgeComposeFile = edgeComposeFile;
518
+ exports.edgeDnsSecretPath = edgeDnsSecretPath;
456
519
  exports.edgeProject = edgeProject;
520
+ exports.isAcmeDnsProvider = isAcmeDnsProvider;
457
521
  exports.readEdgeClaims = readEdgeClaims;
458
522
  exports.traefikDynamic = traefikDynamic;
459
523
  exports.traefikDynamicFile = traefikDynamicFile;