@amalgm/core 0.1.0
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/PURPOSE.md +94 -0
- package/README.md +30 -0
- package/dist/adapters/index.d.ts +13 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +11 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/identity/auth-records.d.ts +147 -0
- package/dist/identity/auth-records.d.ts.map +1 -0
- package/dist/identity/auth-records.js +354 -0
- package/dist/identity/auth-records.js.map +1 -0
- package/dist/identity/ids.d.ts +57 -0
- package/dist/identity/ids.d.ts.map +1 -0
- package/dist/identity/ids.js +80 -0
- package/dist/identity/ids.js.map +1 -0
- package/dist/identity/index.d.ts +14 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +14 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/labels.d.ts +115 -0
- package/dist/identity/labels.d.ts.map +1 -0
- package/dist/identity/labels.js +154 -0
- package/dist/identity/labels.js.map +1 -0
- package/dist/identity/layout.d.ts +188 -0
- package/dist/identity/layout.d.ts.map +1 -0
- package/dist/identity/layout.js +233 -0
- package/dist/identity/layout.js.map +1 -0
- package/dist/identity/ports.d.ts +31 -0
- package/dist/identity/ports.d.ts.map +1 -0
- package/dist/identity/ports.js +9 -0
- package/dist/identity/ports.js.map +1 -0
- package/dist/identity/product-state.d.ts +49 -0
- package/dist/identity/product-state.d.ts.map +1 -0
- package/dist/identity/product-state.js +55 -0
- package/dist/identity/product-state.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/supervision/app-health.d.ts +148 -0
- package/dist/supervision/app-health.d.ts.map +1 -0
- package/dist/supervision/app-health.js +165 -0
- package/dist/supervision/app-health.js.map +1 -0
- package/dist/supervision/app-restart.d.ts +105 -0
- package/dist/supervision/app-restart.d.ts.map +1 -0
- package/dist/supervision/app-restart.js +97 -0
- package/dist/supervision/app-restart.js.map +1 -0
- package/dist/supervision/health.d.ts +218 -0
- package/dist/supervision/health.d.ts.map +1 -0
- package/dist/supervision/health.js +227 -0
- package/dist/supervision/health.js.map +1 -0
- package/dist/supervision/index.d.ts +17 -0
- package/dist/supervision/index.d.ts.map +1 -0
- package/dist/supervision/index.js +17 -0
- package/dist/supervision/index.js.map +1 -0
- package/dist/supervision/service-registration.d.ts +343 -0
- package/dist/supervision/service-registration.d.ts.map +1 -0
- package/dist/supervision/service-registration.js +543 -0
- package/dist/supervision/service-registration.js.map +1 -0
- package/dist/supervision/update.d.ts +231 -0
- package/dist/supervision/update.d.ts.map +1 -0
- package/dist/supervision/update.js +336 -0
- package/dist/supervision/update.js.map +1 -0
- package/dist/transport/admission.d.ts +235 -0
- package/dist/transport/admission.d.ts.map +1 -0
- package/dist/transport/admission.js +313 -0
- package/dist/transport/admission.js.map +1 -0
- package/dist/transport/auth.d.ts +232 -0
- package/dist/transport/auth.d.ts.map +1 -0
- package/dist/transport/auth.js +266 -0
- package/dist/transport/auth.js.map +1 -0
- package/dist/transport/index.d.ts +21 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +21 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/ingress.d.ts +94 -0
- package/dist/transport/ingress.d.ts.map +1 -0
- package/dist/transport/ingress.js +171 -0
- package/dist/transport/ingress.js.map +1 -0
- package/dist/transport/routing.d.ts +235 -0
- package/dist/transport/routing.d.ts.map +1 -0
- package/dist/transport/routing.js +288 -0
- package/dist/transport/routing.js.map +1 -0
- package/dist/transport/shipped-routes.d.ts +21 -0
- package/dist/transport/shipped-routes.d.ts.map +1 -0
- package/dist/transport/shipped-routes.js +53 -0
- package/dist/transport/shipped-routes.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App and preview admission — who gets routed to at all. Two distinct
|
|
3
|
+
* laws live side by side and must not be merged:
|
|
4
|
+
*
|
|
5
|
+
* - isAppRoutable is the SERVING gate (may this request reach the
|
|
6
|
+
* app right now), lenient by construction: unknown states default
|
|
7
|
+
* to routable, because the reader may be looking at rows written
|
|
8
|
+
* by an older engine.
|
|
9
|
+
* - isAdvertisableApp is the ADVERTISING breaker (should the public
|
|
10
|
+
* gateway be told this route exists), strict by construction: it
|
|
11
|
+
* assumes normalized rows and refuses 'degraded' and
|
|
12
|
+
* 'unresponsive' — routing traffic to a zombie is worse than
|
|
13
|
+
* routing none.
|
|
14
|
+
*
|
|
15
|
+
* Everything here is pure over injected sets and records; reading
|
|
16
|
+
* apps.json, port-monitor state, and env is the host's (axiom 6).
|
|
17
|
+
*/
|
|
18
|
+
import type { HeadersLike } from './auth.js';
|
|
19
|
+
/**
|
|
20
|
+
* THE app-ref shape: 8-24 lowercase alphanumerics. The engine spells
|
|
21
|
+
* this regex in three places — local-gateway.js:198, :657 (inside the
|
|
22
|
+
* app URL matcher), tunnel-events.js:240 — one constant here.
|
|
23
|
+
* App refs become DNS labels (`<ref>.<domain>`), hence the charset.
|
|
24
|
+
*/
|
|
25
|
+
export declare const APP_REF_PATTERN: RegExp;
|
|
26
|
+
/** An apps.json row as any engine version may have written it. */
|
|
27
|
+
export interface AppRecordLike {
|
|
28
|
+
readonly appRef?: unknown;
|
|
29
|
+
readonly app_ref?: unknown;
|
|
30
|
+
readonly artifactRef?: unknown;
|
|
31
|
+
readonly artifact_ref?: unknown;
|
|
32
|
+
readonly port?: unknown;
|
|
33
|
+
readonly name?: unknown;
|
|
34
|
+
readonly status?: unknown;
|
|
35
|
+
readonly desiredState?: unknown;
|
|
36
|
+
readonly dnsConnected?: unknown;
|
|
37
|
+
readonly connected?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The alias chain — local-gateway.js:188-190: appRef → app_ref →
|
|
41
|
+
* artifactRef → artifact_ref, first truthy wins, stringified and
|
|
42
|
+
* trimmed. The artifact* names are the pre-rename era and are LIVE
|
|
43
|
+
* WIRE CONTRACT (old rows on disk, old peers over the wire), not
|
|
44
|
+
* dead code; they are deprecated for writers, mandatory for readers
|
|
45
|
+
* (axiom 7: missing fields mean "the other end is older").
|
|
46
|
+
*/
|
|
47
|
+
export declare function normalizeAppRef(app: AppRecordLike | null | undefined): string;
|
|
48
|
+
/**
|
|
49
|
+
* The liveness triad + the serving gate — local-gateway.js:192-206,
|
|
50
|
+
* the same clauses tunnel-events.js:228-244 applies as filter + map.
|
|
51
|
+
* Each triad clause fails OPEN for absent fields:
|
|
52
|
+
* - connected: dnsConnected !== false && connected !== false — only
|
|
53
|
+
* an explicit false disconnects (connected is the legacy spelling);
|
|
54
|
+
* - desiredRunning: (desiredState || 'running') === 'running' — no
|
|
55
|
+
* recorded desire means running;
|
|
56
|
+
* - active: status !== 'stopped' && status !== 'error' — any other
|
|
57
|
+
* status, including undefined and 'degraded', still serves.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isAppRoutable(app: AppRecordLike | null | undefined): boolean;
|
|
60
|
+
/** A normalized apps.json row (post store normalizeApp) — what the advertising breaker reads. */
|
|
61
|
+
export interface AdvertisableAppLike {
|
|
62
|
+
readonly appRef?: string | null;
|
|
63
|
+
readonly dnsConnected?: boolean;
|
|
64
|
+
readonly desiredState?: string;
|
|
65
|
+
readonly status?: string;
|
|
66
|
+
readonly port?: number | null;
|
|
67
|
+
readonly name?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The route-advertisement breaker — the 8-clause predicate of
|
|
71
|
+
* getConnectedRoutes (amalgm-mcp/apps/store.js:159-178). Strict where
|
|
72
|
+
* isAppRoutable is lenient, because it runs over rows the store just
|
|
73
|
+
* normalized (dnsConnected always boolean, desiredState always set):
|
|
74
|
+
* 1. dnsConnected truthy — absent means NOT advertised here;
|
|
75
|
+
* 2. desiredState strictly 'running' — no default;
|
|
76
|
+
* 3. status not 'stopped';
|
|
77
|
+
* 4. status not 'error';
|
|
78
|
+
* 5. status not 'degraded';
|
|
79
|
+
* 6. status not 'unresponsive' — declared a heartbeat and stopped
|
|
80
|
+
* sending it: alive but hung; routing traffic to a zombie is
|
|
81
|
+
* worse than routing none;
|
|
82
|
+
* 7. port truthy;
|
|
83
|
+
* 8. appRef truthy.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isAdvertisableApp(app: AdvertisableAppLike): boolean;
|
|
86
|
+
/** The advertised shape — store.js:173-177: snake_case app_ref, raw port and name. */
|
|
87
|
+
export interface AppRoute {
|
|
88
|
+
readonly app_ref: string;
|
|
89
|
+
readonly port: number;
|
|
90
|
+
readonly name: string | undefined;
|
|
91
|
+
}
|
|
92
|
+
/** getConnectedRoutes minus the loadApps read: rows in, advertised routes out. */
|
|
93
|
+
export declare function connectedRoutesFrom(apps: readonly AdvertisableAppLike[]): AppRoute[];
|
|
94
|
+
/** The pre-rename projection — apps/advertise.js:76-80 (same shape in tunnel-events.js:247-253): sent when the gateway 404s the app-routes endpoint. */
|
|
95
|
+
export declare function legacyArtifactRoutes(routes: readonly AppRoute[]): Array<{
|
|
96
|
+
artifact_ref: string;
|
|
97
|
+
port: number;
|
|
98
|
+
name: string | undefined;
|
|
99
|
+
}>;
|
|
100
|
+
/** The ports the runtime itself listens on, as the host resolved them. */
|
|
101
|
+
export interface InternalRuntimePorts {
|
|
102
|
+
/** parseOptionalPort(env.AMALGM_LOCAL_APP_PORT) — null when unset. */
|
|
103
|
+
readonly localAgentAppPort: number | null;
|
|
104
|
+
/** The gateway/portMonitor/mcp/chat listen ports (SERVICE_PORTS values). */
|
|
105
|
+
readonly servicePorts: Iterable<number>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* local-gateway.js:218-223 — a preview may never target the runtime's
|
|
109
|
+
* own ports: proxying a browser at the gateway back into the gateway
|
|
110
|
+
* (or into mcp) would launder the preview path into an auth bypass.
|
|
111
|
+
*/
|
|
112
|
+
export declare function isInternalRuntimePort(port: number, internal: InternalRuntimePorts): boolean;
|
|
113
|
+
export interface PreviewAdmission {
|
|
114
|
+
readonly internal: InternalRuntimePorts;
|
|
115
|
+
/** Ports of currently routable apps — activeAppPorts() at local-gateway.js:214-216. */
|
|
116
|
+
readonly activeAppPorts: ReadonlySet<number>;
|
|
117
|
+
/** Ports the port monitor observed listening — the gateway's polled cache. */
|
|
118
|
+
readonly monitoredPreviewPorts: ReadonlySet<number>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* local-gateway.js:225-233 — a preview port must be a valid port,
|
|
122
|
+
* not internal, and POSITIVELY known: either an active app's port or
|
|
123
|
+
* one the port monitor saw listening. Unknown ports are denied, not
|
|
124
|
+
* probed — the preview path is reachable from outside the machine.
|
|
125
|
+
*/
|
|
126
|
+
export declare function isAllowedPreviewPort(port: number, admission: PreviewAdmission): boolean;
|
|
127
|
+
/** The external proxy URL matchers — local-gateway.js:657 and :671, byte-exact ('artifacts' is the legacy spelling, still served). */
|
|
128
|
+
export declare const APP_PROXY_PATH_PATTERN: RegExp;
|
|
129
|
+
export declare const PREVIEW_PROXY_PATH_PATTERN: RegExp;
|
|
130
|
+
/** What the proxy decision needs from the world; the host wires apps.json and the monitor cache in. */
|
|
131
|
+
export interface ExternalProxyPorts {
|
|
132
|
+
/** findAppByRef reduced to its answer: the routable app's port, or null. */
|
|
133
|
+
appPortForRef(appRef: string): number | null;
|
|
134
|
+
isAllowedPreviewPort(port: number): boolean;
|
|
135
|
+
}
|
|
136
|
+
export type ExternalProxyTarget = {
|
|
137
|
+
readonly port: number;
|
|
138
|
+
readonly prefix: string;
|
|
139
|
+
readonly kind: 'app' | 'preview';
|
|
140
|
+
} | {
|
|
141
|
+
readonly error: {
|
|
142
|
+
readonly status: 403 | 404;
|
|
143
|
+
readonly message: string;
|
|
144
|
+
};
|
|
145
|
+
} | null;
|
|
146
|
+
/**
|
|
147
|
+
* externalProxyTargetForPath — local-gateway.js:656-685: app paths
|
|
148
|
+
* first (an unknown or unroutable ref is the byte-exact 404), then
|
|
149
|
+
* preview ports (a disallowed port is the byte-exact 403), else null
|
|
150
|
+
* (not an external proxy path at all). `prefix` is what the proxy
|
|
151
|
+
* strips before forwarding: the matched span without its trailing
|
|
152
|
+
* slash.
|
|
153
|
+
*/
|
|
154
|
+
export declare function externalProxyTargetForPath(pathname: string, ports: ExternalProxyPorts): ExternalProxyTarget;
|
|
155
|
+
/** apps/store.js:31-33 — an app's public address is its ref as a DNS label under the apps domain, trailing slash included. */
|
|
156
|
+
export declare function publicUrlForRef(appRef: string, domain: string): string;
|
|
157
|
+
/** The ref alphabet — apps/store.js:36. 36 symbols; see genAppRef for the modulo law. */
|
|
158
|
+
export declare const APP_REF_CHARSET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
159
|
+
/**
|
|
160
|
+
* The ref-generation law — apps/store.js:35-43: 12 characters, each
|
|
161
|
+
* `byte % 36` into the charset. The modulo bias (256 % 36 !== 0) is
|
|
162
|
+
* part of the shipped law and is preserved, not fixed: refs generated
|
|
163
|
+
* here must be indistinguishable from engine-generated ones.
|
|
164
|
+
* Randomness is a host effect; the port must yield at least 12 bytes
|
|
165
|
+
* (node's crypto.randomBytes always does — a short read is a broken
|
|
166
|
+
* adapter, and throwing beats emitting a low-entropy ref).
|
|
167
|
+
*/
|
|
168
|
+
export declare function genAppRef(randomBytes: (size: number) => Uint8Array): string;
|
|
169
|
+
/**
|
|
170
|
+
* The engine's default allocation window — config.js:102-103
|
|
171
|
+
* (AMALGM_APP_PORT_MIN/MAX, defaults 9100..9199). Injected
|
|
172
|
+
* configuration; exported so hosts without an opinion inherit the
|
|
173
|
+
* shipped one.
|
|
174
|
+
*/
|
|
175
|
+
export declare const DEFAULT_APP_PORT_RANGE: {
|
|
176
|
+
readonly min: 9100;
|
|
177
|
+
readonly max: 9199;
|
|
178
|
+
};
|
|
179
|
+
export interface AllocatePortOptions {
|
|
180
|
+
/** Ports already claimed by apps — Number(app.port) over the store. */
|
|
181
|
+
readonly usedPorts: ReadonlySet<number>;
|
|
182
|
+
readonly range: {
|
|
183
|
+
readonly min: number;
|
|
184
|
+
readonly max: number;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The allocation law — apps/store.js:135-147: an explicitly
|
|
189
|
+
* preferred port is honored if it is a valid port AT ALL — even one
|
|
190
|
+
* already in use (the caller asked; collision is their bug to see) —
|
|
191
|
+
* and null if invalid, never "fall through to scanning". Only when no
|
|
192
|
+
* preference is given does the scan hand out the first free port in
|
|
193
|
+
* the range, or null when the range is exhausted.
|
|
194
|
+
*/
|
|
195
|
+
export declare function allocatePort(preferredPort: unknown, options: AllocatePortOptions): number | null;
|
|
196
|
+
/**
|
|
197
|
+
* RFC 7230's connection-scoped headers plus host and content-length —
|
|
198
|
+
* tunnel-events.js:90-102 (same 11-entry list in tunnel-chat.js:65-77
|
|
199
|
+
* and local-gateway.js:108-120). Stripped from every proxied request:
|
|
200
|
+
* they describe THIS hop, and the proxy re-derives its own.
|
|
201
|
+
*/
|
|
202
|
+
export declare const HOP_BY_HOP_HEADERS: ReadonlySet<string>;
|
|
203
|
+
/**
|
|
204
|
+
* The 8 headers the WebSocket handshake owns — tunnel-events.js:103-112
|
|
205
|
+
* (same list in local-gateway.js:122-131). Forwarding a client's
|
|
206
|
+
* Sec-WebSocket-Key to an upstream socket the proxy is opening itself
|
|
207
|
+
* corrupts the upstream handshake; the ws library mints fresh ones.
|
|
208
|
+
*/
|
|
209
|
+
export declare const WS_HANDSHAKE_HEADERS: ReadonlySet<string>;
|
|
210
|
+
/**
|
|
211
|
+
* The one strip-and-flatten helper behind the engine's normalizeHeaders /
|
|
212
|
+
* normalizeWsHeaders family (tunnel-events.js:163-173, local-gateway.js:
|
|
213
|
+
* 570-580 and :593-603): drop every header whose lowercased name is in
|
|
214
|
+
* `drop` (original casing otherwise preserved), join repeated values
|
|
215
|
+
* with ', ', stringify stray numbers, and silently drop nulls. Callers
|
|
216
|
+
* pass HOP_BY_HOP_HEADERS, or its union with WS_HANDSHAKE_HEADERS for
|
|
217
|
+
* upgrade legs.
|
|
218
|
+
*/
|
|
219
|
+
export declare function stripHeaders(headers: HeadersLike | null | undefined, drop: ReadonlySet<string>): Record<string, string>;
|
|
220
|
+
/**
|
|
221
|
+
* The log-redaction laws — local-gateway.js:450-459, the four
|
|
222
|
+
* replaces verbatim and IN ORDER (the order is load-bearing: the
|
|
223
|
+
* authorization-line rule must consume its Bearer token before the
|
|
224
|
+
* bare-Bearer rule sees it):
|
|
225
|
+
* 1. `authorization: <anything token-shaped>` → keep the label,
|
|
226
|
+
* redact the value;
|
|
227
|
+
* 2. bare `Bearer <20+ chars>` anywhere → 'Bearer [REDACTED]';
|
|
228
|
+
* 3. known token prefixes (sk|pk|rk|ghp|github_pat|glpat|xox[baprs]
|
|
229
|
+
* + separator + 16+ token chars) → '[REDACTED_TOKEN]';
|
|
230
|
+
* 4. `api_key/token/secret/password/cookie`-labeled assignments →
|
|
231
|
+
* keep the label, redact the value.
|
|
232
|
+
* Applied to diagnostic log tails before they leave the machine.
|
|
233
|
+
*/
|
|
234
|
+
export declare function redactSecrets(text: string): string;
|
|
235
|
+
//# sourceMappingURL=admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../../src/transport/admission.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAqB,CAAC;AAElD,kEAAkE;AAClE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,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;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EACvC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUxB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASlD"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App and preview admission — who gets routed to at all. Two distinct
|
|
3
|
+
* laws live side by side and must not be merged:
|
|
4
|
+
*
|
|
5
|
+
* - isAppRoutable is the SERVING gate (may this request reach the
|
|
6
|
+
* app right now), lenient by construction: unknown states default
|
|
7
|
+
* to routable, because the reader may be looking at rows written
|
|
8
|
+
* by an older engine.
|
|
9
|
+
* - isAdvertisableApp is the ADVERTISING breaker (should the public
|
|
10
|
+
* gateway be told this route exists), strict by construction: it
|
|
11
|
+
* assumes normalized rows and refuses 'degraded' and
|
|
12
|
+
* 'unresponsive' — routing traffic to a zombie is worse than
|
|
13
|
+
* routing none.
|
|
14
|
+
*
|
|
15
|
+
* Everything here is pure over injected sets and records; reading
|
|
16
|
+
* apps.json, port-monitor state, and env is the host's (axiom 6).
|
|
17
|
+
*/
|
|
18
|
+
import { appNotRoutableError, previewPortDeniedError } from './routing.js';
|
|
19
|
+
/**
|
|
20
|
+
* THE app-ref shape: 8-24 lowercase alphanumerics. The engine spells
|
|
21
|
+
* this regex in three places — local-gateway.js:198, :657 (inside the
|
|
22
|
+
* app URL matcher), tunnel-events.js:240 — one constant here.
|
|
23
|
+
* App refs become DNS labels (`<ref>.<domain>`), hence the charset.
|
|
24
|
+
*/
|
|
25
|
+
export const APP_REF_PATTERN = /^[a-z0-9]{8,24}$/;
|
|
26
|
+
/**
|
|
27
|
+
* The alias chain — local-gateway.js:188-190: appRef → app_ref →
|
|
28
|
+
* artifactRef → artifact_ref, first truthy wins, stringified and
|
|
29
|
+
* trimmed. The artifact* names are the pre-rename era and are LIVE
|
|
30
|
+
* WIRE CONTRACT (old rows on disk, old peers over the wire), not
|
|
31
|
+
* dead code; they are deprecated for writers, mandatory for readers
|
|
32
|
+
* (axiom 7: missing fields mean "the other end is older").
|
|
33
|
+
*/
|
|
34
|
+
export function normalizeAppRef(app) {
|
|
35
|
+
return String(app?.appRef || app?.app_ref || app?.artifactRef || app?.artifact_ref || '').trim();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The liveness triad + the serving gate — local-gateway.js:192-206,
|
|
39
|
+
* the same clauses tunnel-events.js:228-244 applies as filter + map.
|
|
40
|
+
* Each triad clause fails OPEN for absent fields:
|
|
41
|
+
* - connected: dnsConnected !== false && connected !== false — only
|
|
42
|
+
* an explicit false disconnects (connected is the legacy spelling);
|
|
43
|
+
* - desiredRunning: (desiredState || 'running') === 'running' — no
|
|
44
|
+
* recorded desire means running;
|
|
45
|
+
* - active: status !== 'stopped' && status !== 'error' — any other
|
|
46
|
+
* status, including undefined and 'degraded', still serves.
|
|
47
|
+
*/
|
|
48
|
+
export function isAppRoutable(app) {
|
|
49
|
+
const port = Number(app?.port);
|
|
50
|
+
const connected = app?.dnsConnected !== false && app?.connected !== false;
|
|
51
|
+
const desiredRunning = (app?.desiredState || 'running') === 'running';
|
|
52
|
+
const active = app?.status !== 'stopped' && app?.status !== 'error';
|
|
53
|
+
return (APP_REF_PATTERN.test(normalizeAppRef(app))
|
|
54
|
+
&& Number.isInteger(port)
|
|
55
|
+
&& port > 0
|
|
56
|
+
&& port <= 65535
|
|
57
|
+
&& connected
|
|
58
|
+
&& desiredRunning
|
|
59
|
+
&& active);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The route-advertisement breaker — the 8-clause predicate of
|
|
63
|
+
* getConnectedRoutes (amalgm-mcp/apps/store.js:159-178). Strict where
|
|
64
|
+
* isAppRoutable is lenient, because it runs over rows the store just
|
|
65
|
+
* normalized (dnsConnected always boolean, desiredState always set):
|
|
66
|
+
* 1. dnsConnected truthy — absent means NOT advertised here;
|
|
67
|
+
* 2. desiredState strictly 'running' — no default;
|
|
68
|
+
* 3. status not 'stopped';
|
|
69
|
+
* 4. status not 'error';
|
|
70
|
+
* 5. status not 'degraded';
|
|
71
|
+
* 6. status not 'unresponsive' — declared a heartbeat and stopped
|
|
72
|
+
* sending it: alive but hung; routing traffic to a zombie is
|
|
73
|
+
* worse than routing none;
|
|
74
|
+
* 7. port truthy;
|
|
75
|
+
* 8. appRef truthy.
|
|
76
|
+
*/
|
|
77
|
+
export function isAdvertisableApp(app) {
|
|
78
|
+
return Boolean(app.dnsConnected
|
|
79
|
+
&& app.desiredState === 'running'
|
|
80
|
+
&& app.status !== 'stopped'
|
|
81
|
+
&& app.status !== 'error'
|
|
82
|
+
&& app.status !== 'degraded'
|
|
83
|
+
&& app.status !== 'unresponsive'
|
|
84
|
+
&& app.port
|
|
85
|
+
&& app.appRef);
|
|
86
|
+
}
|
|
87
|
+
/** getConnectedRoutes minus the loadApps read: rows in, advertised routes out. */
|
|
88
|
+
export function connectedRoutesFrom(apps) {
|
|
89
|
+
const routes = [];
|
|
90
|
+
for (const app of apps) {
|
|
91
|
+
const { appRef, port } = app;
|
|
92
|
+
if (appRef == null || port == null || !isAdvertisableApp(app))
|
|
93
|
+
continue;
|
|
94
|
+
routes.push({ app_ref: appRef, port, name: app.name });
|
|
95
|
+
}
|
|
96
|
+
return routes;
|
|
97
|
+
}
|
|
98
|
+
/** The pre-rename projection — apps/advertise.js:76-80 (same shape in tunnel-events.js:247-253): sent when the gateway 404s the app-routes endpoint. */
|
|
99
|
+
export function legacyArtifactRoutes(routes) {
|
|
100
|
+
return routes.map((route) => ({
|
|
101
|
+
artifact_ref: route.app_ref,
|
|
102
|
+
port: route.port,
|
|
103
|
+
name: route.name,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* local-gateway.js:218-223 — a preview may never target the runtime's
|
|
108
|
+
* own ports: proxying a browser at the gateway back into the gateway
|
|
109
|
+
* (or into mcp) would launder the preview path into an auth bypass.
|
|
110
|
+
*/
|
|
111
|
+
export function isInternalRuntimePort(port, internal) {
|
|
112
|
+
if (internal.localAgentAppPort !== null && port === internal.localAgentAppPort)
|
|
113
|
+
return true;
|
|
114
|
+
for (const value of internal.servicePorts) {
|
|
115
|
+
if (Number(value) === port)
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* local-gateway.js:225-233 — a preview port must be a valid port,
|
|
122
|
+
* not internal, and POSITIVELY known: either an active app's port or
|
|
123
|
+
* one the port monitor saw listening. Unknown ports are denied, not
|
|
124
|
+
* probed — the preview path is reachable from outside the machine.
|
|
125
|
+
*/
|
|
126
|
+
export function isAllowedPreviewPort(port, admission) {
|
|
127
|
+
return (Number.isInteger(port)
|
|
128
|
+
&& port > 0
|
|
129
|
+
&& port <= 65535
|
|
130
|
+
&& !isInternalRuntimePort(port, admission.internal)
|
|
131
|
+
&& (admission.activeAppPorts.has(port) || admission.monitoredPreviewPorts.has(port)));
|
|
132
|
+
}
|
|
133
|
+
/** The external proxy URL matchers — local-gateway.js:657 and :671, byte-exact ('artifacts' is the legacy spelling, still served). */
|
|
134
|
+
export const APP_PROXY_PATH_PATTERN = /^\/__amalgm\/(?:apps|artifacts)\/([a-z0-9]{8,24})(?:\/|$)/;
|
|
135
|
+
export const PREVIEW_PROXY_PATH_PATTERN = /^\/__amalgm\/preview\/(\d{1,5})(?:\/|$)/;
|
|
136
|
+
/**
|
|
137
|
+
* externalProxyTargetForPath — local-gateway.js:656-685: app paths
|
|
138
|
+
* first (an unknown or unroutable ref is the byte-exact 404), then
|
|
139
|
+
* preview ports (a disallowed port is the byte-exact 403), else null
|
|
140
|
+
* (not an external proxy path at all). `prefix` is what the proxy
|
|
141
|
+
* strips before forwarding: the matched span without its trailing
|
|
142
|
+
* slash.
|
|
143
|
+
*/
|
|
144
|
+
export function externalProxyTargetForPath(pathname, ports) {
|
|
145
|
+
const appMatch = pathname.match(APP_PROXY_PATH_PATTERN);
|
|
146
|
+
if (appMatch) {
|
|
147
|
+
const appRef = appMatch[1] ?? '';
|
|
148
|
+
const matched = appMatch[0] ?? '';
|
|
149
|
+
const port = ports.appPortForRef(appRef);
|
|
150
|
+
if (port === null) {
|
|
151
|
+
return { error: appNotRoutableError(appRef) };
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
port,
|
|
155
|
+
prefix: matched.endsWith('/') ? matched.slice(0, -1) : matched,
|
|
156
|
+
kind: 'app',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const previewMatch = pathname.match(PREVIEW_PROXY_PATH_PATTERN);
|
|
160
|
+
if (previewMatch) {
|
|
161
|
+
const port = Number(previewMatch[1]);
|
|
162
|
+
if (!ports.isAllowedPreviewPort(port)) {
|
|
163
|
+
return { error: previewPortDeniedError(port) };
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
port,
|
|
167
|
+
prefix: `/__amalgm/preview/${port}`,
|
|
168
|
+
kind: 'preview',
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
// App identity and port allocation
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
/** apps/store.js:31-33 — an app's public address is its ref as a DNS label under the apps domain, trailing slash included. */
|
|
177
|
+
export function publicUrlForRef(appRef, domain) {
|
|
178
|
+
return `https://${appRef}.${domain}/`;
|
|
179
|
+
}
|
|
180
|
+
/** The ref alphabet — apps/store.js:36. 36 symbols; see genAppRef for the modulo law. */
|
|
181
|
+
export const APP_REF_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
182
|
+
/**
|
|
183
|
+
* The ref-generation law — apps/store.js:35-43: 12 characters, each
|
|
184
|
+
* `byte % 36` into the charset. The modulo bias (256 % 36 !== 0) is
|
|
185
|
+
* part of the shipped law and is preserved, not fixed: refs generated
|
|
186
|
+
* here must be indistinguishable from engine-generated ones.
|
|
187
|
+
* Randomness is a host effect; the port must yield at least 12 bytes
|
|
188
|
+
* (node's crypto.randomBytes always does — a short read is a broken
|
|
189
|
+
* adapter, and throwing beats emitting a low-entropy ref).
|
|
190
|
+
*/
|
|
191
|
+
export function genAppRef(randomBytes) {
|
|
192
|
+
const bytes = randomBytes(12);
|
|
193
|
+
let out = '';
|
|
194
|
+
for (let i = 0; i < 12; i += 1) {
|
|
195
|
+
const byte = bytes[i];
|
|
196
|
+
if (byte === undefined)
|
|
197
|
+
throw new Error('randomBytes port returned fewer than 12 bytes');
|
|
198
|
+
out += APP_REF_CHARSET.charAt(byte % APP_REF_CHARSET.length);
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The engine's default allocation window — config.js:102-103
|
|
204
|
+
* (AMALGM_APP_PORT_MIN/MAX, defaults 9100..9199). Injected
|
|
205
|
+
* configuration; exported so hosts without an opinion inherit the
|
|
206
|
+
* shipped one.
|
|
207
|
+
*/
|
|
208
|
+
export const DEFAULT_APP_PORT_RANGE = { min: 9100, max: 9199 };
|
|
209
|
+
/**
|
|
210
|
+
* The allocation law — apps/store.js:135-147: an explicitly
|
|
211
|
+
* preferred port is honored if it is a valid port AT ALL — even one
|
|
212
|
+
* already in use (the caller asked; collision is their bug to see) —
|
|
213
|
+
* and null if invalid, never "fall through to scanning". Only when no
|
|
214
|
+
* preference is given does the scan hand out the first free port in
|
|
215
|
+
* the range, or null when the range is exhausted.
|
|
216
|
+
*/
|
|
217
|
+
export function allocatePort(preferredPort, options) {
|
|
218
|
+
if (preferredPort !== undefined && preferredPort !== null) {
|
|
219
|
+
const parsed = Number(preferredPort);
|
|
220
|
+
if (Number.isInteger(parsed) && parsed > 0 && parsed <= 65535)
|
|
221
|
+
return parsed;
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
for (let port = options.range.min; port <= options.range.max; port += 1) {
|
|
225
|
+
if (!options.usedPorts.has(port))
|
|
226
|
+
return port;
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
// ---------------------------------------------------------------------------
|
|
231
|
+
// Header hygiene
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
/**
|
|
234
|
+
* RFC 7230's connection-scoped headers plus host and content-length —
|
|
235
|
+
* tunnel-events.js:90-102 (same 11-entry list in tunnel-chat.js:65-77
|
|
236
|
+
* and local-gateway.js:108-120). Stripped from every proxied request:
|
|
237
|
+
* they describe THIS hop, and the proxy re-derives its own.
|
|
238
|
+
*/
|
|
239
|
+
export const HOP_BY_HOP_HEADERS = new Set([
|
|
240
|
+
'connection',
|
|
241
|
+
'keep-alive',
|
|
242
|
+
'proxy-authenticate',
|
|
243
|
+
'proxy-authorization',
|
|
244
|
+
'te',
|
|
245
|
+
'trailer',
|
|
246
|
+
'trailers',
|
|
247
|
+
'transfer-encoding',
|
|
248
|
+
'upgrade',
|
|
249
|
+
'host',
|
|
250
|
+
'content-length',
|
|
251
|
+
]);
|
|
252
|
+
/**
|
|
253
|
+
* The 8 headers the WebSocket handshake owns — tunnel-events.js:103-112
|
|
254
|
+
* (same list in local-gateway.js:122-131). Forwarding a client's
|
|
255
|
+
* Sec-WebSocket-Key to an upstream socket the proxy is opening itself
|
|
256
|
+
* corrupts the upstream handshake; the ws library mints fresh ones.
|
|
257
|
+
*/
|
|
258
|
+
export const WS_HANDSHAKE_HEADERS = new Set([
|
|
259
|
+
'connection',
|
|
260
|
+
'upgrade',
|
|
261
|
+
'host',
|
|
262
|
+
'sec-websocket-key',
|
|
263
|
+
'sec-websocket-version',
|
|
264
|
+
'sec-websocket-extensions',
|
|
265
|
+
'sec-websocket-accept',
|
|
266
|
+
'sec-websocket-protocol',
|
|
267
|
+
]);
|
|
268
|
+
/**
|
|
269
|
+
* The one strip-and-flatten helper behind the engine's normalizeHeaders /
|
|
270
|
+
* normalizeWsHeaders family (tunnel-events.js:163-173, local-gateway.js:
|
|
271
|
+
* 570-580 and :593-603): drop every header whose lowercased name is in
|
|
272
|
+
* `drop` (original casing otherwise preserved), join repeated values
|
|
273
|
+
* with ', ', stringify stray numbers, and silently drop nulls. Callers
|
|
274
|
+
* pass HOP_BY_HOP_HEADERS, or its union with WS_HANDSHAKE_HEADERS for
|
|
275
|
+
* upgrade legs.
|
|
276
|
+
*/
|
|
277
|
+
export function stripHeaders(headers, drop) {
|
|
278
|
+
const out = {};
|
|
279
|
+
for (const [key, value] of Object.entries(headers || {})) {
|
|
280
|
+
const lower = key.toLowerCase();
|
|
281
|
+
if (drop.has(lower))
|
|
282
|
+
continue;
|
|
283
|
+
if (Array.isArray(value))
|
|
284
|
+
out[key] = value.join(', ');
|
|
285
|
+
else if (typeof value === 'string')
|
|
286
|
+
out[key] = value;
|
|
287
|
+
else if (value != null)
|
|
288
|
+
out[key] = String(value);
|
|
289
|
+
}
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The log-redaction laws — local-gateway.js:450-459, the four
|
|
294
|
+
* replaces verbatim and IN ORDER (the order is load-bearing: the
|
|
295
|
+
* authorization-line rule must consume its Bearer token before the
|
|
296
|
+
* bare-Bearer rule sees it):
|
|
297
|
+
* 1. `authorization: <anything token-shaped>` → keep the label,
|
|
298
|
+
* redact the value;
|
|
299
|
+
* 2. bare `Bearer <20+ chars>` anywhere → 'Bearer [REDACTED]';
|
|
300
|
+
* 3. known token prefixes (sk|pk|rk|ghp|github_pat|glpat|xox[baprs]
|
|
301
|
+
* + separator + 16+ token chars) → '[REDACTED_TOKEN]';
|
|
302
|
+
* 4. `api_key/token/secret/password/cookie`-labeled assignments →
|
|
303
|
+
* keep the label, redact the value.
|
|
304
|
+
* Applied to diagnostic log tails before they leave the machine.
|
|
305
|
+
*/
|
|
306
|
+
export function redactSecrets(text) {
|
|
307
|
+
return String(text)
|
|
308
|
+
.replace(/(authorization\s*[:=]\s*)(?:Bearer\s+)?[A-Za-z0-9._~+/=-]{8,}/gi, '$1[REDACTED]')
|
|
309
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]{20,}\b/gi, 'Bearer [REDACTED]')
|
|
310
|
+
.replace(/\b(?:sk|pk|rk|ghp|github_pat|glpat|xox[baprs])[-_][A-Za-z0-9_./+=-]{16,}\b/g, '[REDACTED_TOKEN]')
|
|
311
|
+
.replace(/((?:api[_-]?key|apikey|token|secret|password|cookie|set-cookie)[^:=\n]{0,32}[:=]\s*["']?)[^\s"',;}]+/gi, '$1[REDACTED]');
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.js","sourceRoot":"","sources":["../../src/transport/admission.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAgBlD;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,GAAqC;IACnE,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,IAAI,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACnG,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,GAAqC;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,GAAG,EAAE,YAAY,KAAK,KAAK,IAAI,GAAG,EAAE,SAAS,KAAK,KAAK,CAAC;IAC1E,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,YAAY,IAAI,SAAS,CAAC,KAAK,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