@geekmidas/edge 10.0.0-alpha.184 → 10.0.0-alpha.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-BVE0VFku.d.cts +427 -0
- package/dist/index-BVE0VFku.d.cts.map +1 -0
- package/dist/index-BVE0VFku.d.mts +427 -0
- package/dist/index-BVE0VFku.d.mts.map +1 -0
- package/dist/proxy/caddy.cjs +6 -4
- package/dist/proxy/caddy.cjs.map +1 -1
- package/dist/proxy/caddy.d.cts +1 -1
- package/dist/proxy/caddy.d.cts.map +1 -1
- package/dist/proxy/caddy.d.mts +1 -1
- package/dist/proxy/caddy.d.mts.map +1 -1
- package/dist/proxy/caddy.mjs +7 -5
- package/dist/proxy/caddy.mjs.map +1 -1
- package/dist/proxy/traefik.cjs +85 -18
- package/dist/proxy/traefik.cjs.map +1 -1
- package/dist/proxy/traefik.d.cts +2 -129
- package/dist/proxy/traefik.d.mts +2 -129
- package/dist/proxy/traefik.mjs +82 -20
- package/dist/proxy/traefik.mjs.map +1 -1
- package/dist/routes/index.cjs +12 -0
- package/dist/routes/index.cjs.map +1 -1
- package/dist/routes/index.d.cts +2 -205
- package/dist/routes/index.d.mts +2 -205
- package/dist/routes/index.mjs +11 -1
- package/dist/routes/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/proxy/traefik.d.cts.map +0 -1
- package/dist/proxy/traefik.d.mts.map +0 -1
- package/dist/routes/index.d.cts.map +0 -1
- package/dist/routes/index.d.mts.map +0 -1
|
@@ -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;;;;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ACA,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"}
|
package/dist/proxy/caddy.cjs
CHANGED
|
@@ -17,9 +17,9 @@ let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
|
17
17
|
*/
|
|
18
18
|
/** Where Caddy reads a stage's own certificate, inside its container. */
|
|
19
19
|
const CADDY_TLS_DIR = "/etc/caddy/tls";
|
|
20
|
-
/** An upstream on the stack's own network
|
|
21
|
-
function address(
|
|
22
|
-
return
|
|
20
|
+
/** An upstream on the stack's own network — its service name — or on the host. */
|
|
21
|
+
function address(upstream) {
|
|
22
|
+
return require_routes_index.upstreamAddress(upstream);
|
|
23
23
|
}
|
|
24
24
|
/** The Caddyfile for a stack's edge. */
|
|
25
25
|
function edgeCaddyfile(routes, options) {
|
|
@@ -77,7 +77,9 @@ function siteBlock(route, edgeToken, certificate) {
|
|
|
77
77
|
# Answered by another service: ${handler.name}.
|
|
78
78
|
@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(" ")}
|
|
79
79
|
handle @handler${index} {
|
|
80
|
-
reverse_proxy ${handler.upstreams.map(address).join(" ")}
|
|
80
|
+
reverse_proxy ${handler.upstreams.map(address).join(" ")}${handler.under ? ` {
|
|
81
|
+
rewrite ${handler.under}{uri}
|
|
82
|
+
}` : ""}
|
|
81
83
|
}
|
|
82
84
|
`).join("")}
|
|
83
85
|
handle {${proxy.replace(/\n/g, "\n ")}
|
package/dist/proxy/caddy.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caddy.cjs","names":["CLIENT_IP_HEADER","EDGE_TOKEN_HEADER"],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network: its service name. */\nfunction address({ service, port }: Upstream): string {\n\treturn `${service}:${port}`;\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_header @gkm_outside -${CLIENT_IP_HEADER}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;;AAmB7B,SAAS,QAAQ,EAAE,SAAS,QAA0B;CACrD,OAAO,GAAG,QAAQ,GAAG;AACtB;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW,CAAC,EACzE,UAAU;CACb,MAAM,WACL,KAAK,SAAS,cACX;;QAEG,IAAI,IAAI;MAEX;CACJ,MAAM,WAAW,GAAG,QAAQ,QAAQ,aAAa,QAAQ,UAAU,KAClE,QAAQ,cAAc,QAAQ,oCAAqC,KACjE;CACH,MAAM,SAAS,WAAW,IAAI,SAAS,OAAO;CAE9C,MAAM,cACL,IAAI,SAAS,UACV;OACE,IAAI,SAAS,GAAG,IAAI,QAAQ;IAE9B;CAIJ,MAAM,SAAS,CACd,GAAG,OAAO,QAAQ,UAAU,CAAC,MAAM,QAAQ,GAC3C,GAAG,OAAO,QAAQ,UAAU,MAAM,QAAQ,CAC3C,CAAC,CAAC,KAAK,UACN,UACC,OACA,QAAQ,WACR,MAAM,UAAU,IAAI,SAAS,cAC1B;;;;IAKA,WACJ,CACD;CAGA,OAAO,GAAG,SAAS,SAAS,GAAG,OAAO,QAAQ,KAAK,OAAO,KAAK,MAAM,EAAE;AACxE;;AAGA,SAAS,UACR,OACA,WACA,aACS;CACT,qBAAA,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AET,OAAO,GAAG,MAAM,IAAI,cAAc,aAAa,SAAS,EAAE;EACzD,SAAS,KAAK;GACb;AACH;;AAGA,SAAS,WAAW,OAA0B;CAC7C,MAAM,EAAE,WAAW,QAAQ,cAAc;CACzC,MAAM,SAAS,YAAY,KAAK;CAChC,OAAO,SACJ;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,EAAE;YACtC,OAAO;sCACmB,OAAO;MAEzC;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,IAC9C,aAAa,SACV,KACA,YACG;;;uBAIA,KACD,OAAO;MAET;AAEL;;;;;;;;;AAUA,SAAS,YAAY,EAAE,UAA6B;CACnD,OAAO,SACJ;;;eAGW,OAAO;;uBAGlB;AACJ;AAEA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;AAqBf,SAAgB,aAAa,WAAuC;CACnE,IAAI,CAAC,WACJ,OAAO;;;mBAGUA,oBAAAA;CAElB,OAAO;;;;2BAImBC,oBAAAA,kBAAkB,GAAG,UAAU;gCAC1BD,oBAAAA;AAChC"}
|
|
1
|
+
{"version":3,"file":"caddy.cjs","names":["upstreamAddress","CLIENT_IP_HEADER","EDGE_TOKEN_HEADER"],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n\tupstreamAddress,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network — its service name — or on the host. */\nfunction address(upstream: Upstream): string {\n\treturn upstreamAddress(upstream);\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}${\n\t\t\thandler.under\n\t\t\t\t? ` {\n\t\t\trewrite ${handler.under}{uri}\n\t\t}`\n\t\t\t\t: ''\n\t\t}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_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B,OAAO;MAEzC;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,IAC9C,aAAa,SACV,KACA,YACG;;;uBAIA,KACD,OAAO;MAET;AAEL;;;;;;;;;AAUA,SAAS,YAAY,EAAE,UAA6B;CACnD,OAAO,SACJ;;;eAGW,OAAO;;uBAGlB;AACJ;AAEA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;AAqBf,SAAgB,aAAa,WAAuC;CACnE,IAAI,CAAC,WACJ,OAAO;;;mBAGUC,oBAAAA;CAElB,OAAO;;;;2BAImBC,oBAAAA,kBAAkB,GAAG,UAAU;gCAC1BD,oBAAAA;AAChC"}
|
package/dist/proxy/caddy.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EdgeRoute, EdgeTls } from "../
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caddy.d.cts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"caddy.d.cts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAwBa;iBAEI;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBAgOM,aAAa"}
|
package/dist/proxy/caddy.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EdgeRoute, EdgeTls } from "../
|
|
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";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caddy.d.mts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"caddy.d.mts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAwBa;iBAEI;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBAgOM,aAAa"}
|
package/dist/proxy/caddy.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertRouteRenderable } from "../routes/index.mjs";
|
|
1
|
+
import { assertRouteRenderable, upstreamAddress } from "../routes/index.mjs";
|
|
2
2
|
import { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from "@geekmidas/manifest";
|
|
3
3
|
//#region src/proxy/caddy.ts
|
|
4
4
|
/**
|
|
@@ -16,9 +16,9 @@ import { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from "@geekmidas/manifest";
|
|
|
16
16
|
*/
|
|
17
17
|
/** Where Caddy reads a stage's own certificate, inside its container. */
|
|
18
18
|
const CADDY_TLS_DIR = "/etc/caddy/tls";
|
|
19
|
-
/** An upstream on the stack's own network
|
|
20
|
-
function address(
|
|
21
|
-
return
|
|
19
|
+
/** An upstream on the stack's own network — its service name — or on the host. */
|
|
20
|
+
function address(upstream) {
|
|
21
|
+
return upstreamAddress(upstream);
|
|
22
22
|
}
|
|
23
23
|
/** The Caddyfile for a stack's edge. */
|
|
24
24
|
function edgeCaddyfile(routes, options) {
|
|
@@ -76,7 +76,9 @@ function siteBlock(route, edgeToken, certificate) {
|
|
|
76
76
|
# Answered by another service: ${handler.name}.
|
|
77
77
|
@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(" ")}
|
|
78
78
|
handle @handler${index} {
|
|
79
|
-
reverse_proxy ${handler.upstreams.map(address).join(" ")}
|
|
79
|
+
reverse_proxy ${handler.upstreams.map(address).join(" ")}${handler.under ? ` {
|
|
80
|
+
rewrite ${handler.under}{uri}
|
|
81
|
+
}` : ""}
|
|
80
82
|
}
|
|
81
83
|
`).join("")}
|
|
82
84
|
handle {${proxy.replace(/\n/g, "\n ")}
|
package/dist/proxy/caddy.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caddy.mjs","names":[],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network: its service name. */\nfunction address({ service, port }: Upstream): string {\n\treturn `${service}:${port}`;\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_header @gkm_outside -${CLIENT_IP_HEADER}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;;AAmB7B,SAAS,QAAQ,EAAE,SAAS,QAA0B;CACrD,OAAO,GAAG,QAAQ,GAAG;AACtB;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW,CAAC,EACzE,UAAU;CACb,MAAM,WACL,KAAK,SAAS,cACX;;QAEG,IAAI,IAAI;MAEX;CACJ,MAAM,WAAW,GAAG,QAAQ,QAAQ,aAAa,QAAQ,UAAU,KAClE,QAAQ,cAAc,QAAQ,oCAAqC,KACjE;CACH,MAAM,SAAS,WAAW,IAAI,SAAS,OAAO;CAE9C,MAAM,cACL,IAAI,SAAS,UACV;OACE,IAAI,SAAS,GAAG,IAAI,QAAQ;IAE9B;CAIJ,MAAM,SAAS,CACd,GAAG,OAAO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AM,QAAQ,OAAO,KAAM,EAAE;MAEpC;CAGH,MAAM,QAAQ,CAAC,MAAM,GAAI,MAAM,WAAW,CAAC,CAAE,CAAC,CAC5C,KAAK,SAAS,WAAW,MAAM,CAAC,CAChC,KAAK,IAAI;CAGX,MAAM,aAAa,MAAM,WAAW,SAAS,CAAC,EAAA,CAC5C,KACC,SAAS;;UAEH,KAAK,IAAI,YAAY;SACtB,MAAM,WAAW,GAAG;EAE3B,CAAC,CACA,KAAK,EAAE;CAET,OAAO,GAAG,MAAM,IAAI,cAAc,aAAa,SAAS,EAAE;EACzD,SAAS,KAAK;GACb;AACH;;AAGA,SAAS,WAAW,OAA0B;CAC7C,MAAM,EAAE,WAAW,QAAQ,cAAc;CACzC,MAAM,SAAS,YAAY,KAAK;CAChC,OAAO,SACJ;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,EAAE;YACtC,OAAO;sCACmB,OAAO;MAEzC;;;iBAGa,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,IAC9C,aAAa,SACV,KACA,YACG;;;uBAIA,KACD,OAAO;MAET;AAEL;;;;;;;;;AAUA,SAAS,YAAY,EAAE,UAA6B;CACnD,OAAO,SACJ;;;eAGW,OAAO;;uBAGlB;AACJ;AAEA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;AAqBf,SAAgB,aAAa,WAAuC;CACnE,IAAI,CAAC,WACJ,OAAO;;;mBAGU;CAElB,OAAO;;;;2BAImB,kBAAkB,GAAG,UAAU;gCAC1B;AAChC"}
|
|
1
|
+
{"version":3,"file":"caddy.mjs","names":[],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n\tupstreamAddress,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network — its service name — or on the host. */\nfunction address(upstream: Upstream): string {\n\treturn upstreamAddress(upstream);\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}${\n\t\t\thandler.under\n\t\t\t\t? ` {\n\t\t\trewrite ${handler.under}{uri}\n\t\t}`\n\t\t\t\t: ''\n\t\t}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_header @gkm_outside -${CLIENT_IP_HEADER}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,MAAa,gBAAgB;;AAmB7B,SAAS,QAAQ,UAA4B;CAC5C,OAAO,gBAAgB,QAAQ;AAChC;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW,CAAC,EACzE,UAAU;CACb,MAAM,WACL,KAAK,SAAS,cACX;;QAEG,IAAI,IAAI;MAEX;CACJ,MAAM,WAAW,GAAG,QAAQ,QAAQ,aAAa,QAAQ,UAAU,KAClE,QAAQ,cAAc,QAAQ,oCAAqC,KACjE;CACH,MAAM,SAAS,WAAW,IAAI,SAAS,OAAO;CAE9C,MAAM,cACL,IAAI,SAAS,UACV;OACE,IAAI,SAAS,GAAG,IAAI,QAAQ;IAE9B;CAIJ,MAAM,SAAS,CACd,GAAG,OAAO,QAAQ,UAAU,CAAC,MAAM,QAAQ,GAC3C,GAAG,OAAO,QAAQ,UAAU,MAAM,QAAQ,CAC3C,CAAC,CAAC,KAAK,UACN,UACC,OACA,QAAQ,WACR,MAAM,UAAU,IAAI,SAAS,cAC1B;;;;IAKA,WACJ,CACD;CAGA,OAAO,GAAG,SAAS,SAAS,GAAG,OAAO,QAAQ,KAAK,OAAO,KAAK,MAAM,EAAE;AACxE;;AAGA,SAAS,UACR,OACA,WACA,aACS;CACT,sBAAsB,KAAK;CAC3B,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,UAAU,eAAe,aAAa;CACxE,MAAM,UAAU,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