deepline 0.3.544 → 0.3.546
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/bundling-sources/sdk/src/client-core.ts +5 -0
- package/dist/bundling-sources/sdk/src/errors.ts +1 -1
- package/dist/bundling-sources/sdk/src/http-core.ts +41 -12
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/fleets/errors.ts +5 -0
- package/dist/bundling-sources/shared_libs/monitors/fleets/issues.ts +5 -1
- package/dist/bundling-sources/shared_libs/monitors/fleets/limits.ts +6 -0
- package/dist/bundling-sources/shared_libs/monitors/fleets/plan.ts +35 -3
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +2 -2
- package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +27 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +8 -0
- package/dist/bundling-sources/shared_libs/play-runtime/fleet-sandbox-sweep.ts +40 -3
- package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +19 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +18 -4
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +441 -103
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +322 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +200 -64
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +65 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -3
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +32 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +206 -12
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +30 -2
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +30 -1
- package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +35 -2
- package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +35 -1
- package/dist/bundling-sources/shared_libs/security/email-domain.ts +19 -0
- package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +2 -0
- package/dist/cli/{auth-IMWJAHPU.mjs → auth-KFWG72AZ.mjs} +6 -6
- package/dist/cli/auth-W32GMYND.js +43 -0
- package/dist/cli/{billing-YQMW3QJI.mjs → billing-MMZ336HO.mjs} +10 -10
- package/dist/cli/{billing-Y55PR2PV.js → billing-OQVOAZ4S.js} +98 -98
- package/dist/cli/{chunk-RJPDCSTD.mjs → chunk-3DUNNZB6.mjs} +4 -4
- package/dist/cli/{chunk-G26VJCNT.js → chunk-4AZLGNXV.js} +36 -26
- package/dist/cli/{chunk-Y3T5GWYK.mjs → chunk-5OEFXAKP.mjs} +5 -1
- package/dist/cli/{chunk-RG34YBDE.js → chunk-5V7NZKGG.js} +2 -2
- package/dist/cli/{chunk-UHIAQPVA.js → chunk-5VNQMVCU.js} +26 -26
- package/dist/cli/{chunk-PDJ4UDCO.js → chunk-5W4ENHWM.js} +12 -12
- package/dist/cli/{chunk-3JDA23NN.mjs → chunk-6FBDTYR2.mjs} +2 -2
- package/dist/cli/{chunk-KE6CSCUF.js → chunk-6LG7MLJ2.js} +44 -44
- package/dist/cli/{chunk-HXM2JUGD.mjs → chunk-6Y5TU3R7.mjs} +2 -2
- package/dist/cli/{chunk-PFGOCUH3.mjs → chunk-7MY7KWJS.mjs} +1 -1
- package/dist/cli/{chunk-57G4NYOL.mjs → chunk-7ZW67ME6.mjs} +1 -1
- package/dist/cli/{chunk-JBWOE6AP.js → chunk-BTFUAGHC.js} +16 -16
- package/dist/cli/{chunk-5PR4VLLL.mjs → chunk-EEG46QZY.mjs} +2 -2
- package/dist/cli/{chunk-3I26HMJ7.js → chunk-EEJHB76U.js} +9 -9
- package/dist/cli/{chunk-2GJZLIKW.js → chunk-EITMD3A5.js} +1 -1
- package/dist/cli/{chunk-Z44YTSTA.js → chunk-F2VEFMU5.js} +13 -13
- package/dist/cli/{chunk-4JQEAYN3.js → chunk-F5YQXCP3.js} +5 -1
- package/dist/cli/{chunk-BEQ7RQLT.mjs → chunk-GOOF7E2B.mjs} +5 -5
- package/dist/cli/{chunk-PMW5YP72.mjs → chunk-GYTSDSQD.mjs} +11 -11
- package/dist/cli/{chunk-ZY6FL4O4.js → chunk-H7Q5IDO3.js} +19 -19
- package/dist/cli/{chunk-GV45TTI6.mjs → chunk-HJR2DDJS.mjs} +2 -2
- package/dist/cli/{chunk-7HMMTSDA.js → chunk-IVWU7SJC.js} +5 -5
- package/dist/cli/{chunk-WBSGPLH5.mjs → chunk-J65HJCJO.mjs} +2 -2
- package/dist/cli/{chunk-REEOMNCO.mjs → chunk-JA633HRV.mjs} +3 -3
- package/dist/cli/{chunk-HVJQF5BI.mjs → chunk-JARZ47OP.mjs} +2 -2
- package/dist/cli/{chunk-IFIJ4DBJ.js → chunk-JCH4UNNS.js} +2 -2
- package/dist/cli/{chunk-COJHT2KF.js → chunk-JCWNF44W.js} +22 -22
- package/dist/cli/{chunk-3KGMM4KS.js → chunk-JVOUQFHT.js} +1 -1
- package/dist/cli/{chunk-W7X4KH45.js → chunk-JYG4XZLT.js} +99 -99
- package/dist/cli/{chunk-HBSWATOU.mjs → chunk-K2XELBPF.mjs} +5 -5
- package/dist/cli/{chunk-HAQRF6DJ.mjs → chunk-KUK7ARXA.mjs} +2 -2
- package/dist/cli/{chunk-WUEORIOY.mjs → chunk-LHE2TSV6.mjs} +1 -1
- package/dist/cli/{chunk-7GNZEOTH.js → chunk-LIJKRDDG.js} +6 -6
- package/dist/cli/{chunk-SKS53WM6.mjs → chunk-LX2TC3HO.mjs} +4 -4
- package/dist/cli/{chunk-GQHRGBHV.js → chunk-MEGHIX4M.js} +5 -5
- package/dist/cli/{chunk-H4SAHB3Q.mjs → chunk-MI7X6V6V.mjs} +3 -3
- package/dist/cli/{chunk-ON56ISO6.js → chunk-MXQP7CXZ.js} +8 -8
- package/dist/cli/{chunk-PKRW76XG.js → chunk-ND7SFRQL.js} +2 -2
- package/dist/cli/{chunk-CQBIO6HW.mjs → chunk-NURW5XH4.mjs} +1 -1
- package/dist/cli/{chunk-Q7ZOWNKR.mjs → chunk-OAKWSLKS.mjs} +2 -2
- package/dist/cli/{chunk-SK3HPU2J.mjs → chunk-P7A3H6G5.mjs} +1 -1
- package/dist/cli/{chunk-UNMNGRPB.js → chunk-PMDHY2YK.js} +7 -7
- package/dist/cli/{chunk-LW274RO7.mjs → chunk-PU3ZAG6V.mjs} +1 -1
- package/dist/cli/{chunk-ZHY4T5M6.mjs → chunk-RO66FPTS.mjs} +22 -12
- package/dist/cli/{chunk-DYDHLBSK.js → chunk-SH32HL7I.js} +53 -53
- package/dist/cli/{chunk-DF2X7GJG.js → chunk-SYTWWVIQ.js} +5 -5
- package/dist/cli/{chunk-JWVG7ZPX.js → chunk-TBWYZOSV.js} +3 -3
- package/dist/cli/{chunk-RUFR4PUO.js → chunk-UQJBV5PM.js} +10 -10
- package/dist/cli/{chunk-LPUBBUKX.mjs → chunk-UREAIHUU.mjs} +2 -2
- package/dist/cli/{chunk-22OBDYHP.js → chunk-VAT2SXFF.js} +12 -12
- package/dist/cli/{chunk-LQ6RRYXN.mjs → chunk-VPERQ3U6.mjs} +5 -5
- package/dist/cli/{chunk-456RRXAP.mjs → chunk-VTK3HGMN.mjs} +5 -5
- package/dist/cli/{chunk-DVDWAC2M.mjs → chunk-VXTTAYOT.mjs} +2 -2
- package/dist/cli/{chunk-4PKHFW56.js → chunk-WKHPLBJK.js} +15 -15
- package/dist/cli/{chunk-YIRVKMON.mjs → chunk-X5KOHDJN.mjs} +1 -1
- package/dist/cli/{chunk-C4P2KLWT.js → chunk-Z3UEBFIN.js} +41 -41
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +21 -0
- package/dist/cli/{concurrent-runs-help-KBWPKSTP.mjs → concurrent-runs-help-C2O5YKQA.mjs} +7 -7
- package/dist/cli/{csv-XGGDZTQI.js → csv-MJDNOIQJ.js} +14 -14
- package/dist/cli/{csv-M5EBEMZH.mjs → csv-Z4DNGR54.mjs} +5 -5
- package/dist/cli/{db-M6FJ6J6E.mjs → db-4RL2BNOF.mjs} +7 -7
- package/dist/cli/{db-CVPR54XK.js → db-S5QVPK5E.js} +32 -32
- package/dist/cli/{describe-X6QA2U3C.mjs → describe-L4P5SZLQ.mjs} +19 -19
- package/dist/cli/describe-VLU2LUDJ.js +50 -0
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/describe-core.js +1 -1
- package/dist/cli/describe-core.mjs +1 -1
- package/dist/cli/{executions-VJEEWN22.js → executions-MFZ2Z36O.js} +9 -9
- package/dist/cli/{executions-EHTS2XJX.mjs → executions-RR6O3XK5.mjs} +7 -7
- package/dist/cli/{feedback-76VGY4GP.mjs → feedback-EQBQ3ABB.mjs} +7 -7
- package/dist/cli/{feedback-DQPUCUXO.js → feedback-YDAG7VH2.js} +15 -15
- package/dist/cli/git-E6W44F5M.js +25 -0
- package/dist/cli/{git-IY6DKKLR.mjs → git-YGLCCU35.mjs} +6 -6
- package/dist/cli/index.js +150 -150
- package/dist/cli/index.mjs +46 -46
- package/dist/cli/{integrations-242LE3TQ.mjs → integrations-FWYXSBHK.mjs} +8 -8
- package/dist/cli/{integrations-CQSTIKFY.js → integrations-IQXYMRMW.js} +16 -16
- package/dist/cli/{legacy-noops-SWTSTMRY.mjs → legacy-noops-I4YRIX5F.mjs} +7 -7
- package/dist/cli/{legacy-noops-U72DO6ZF.js → legacy-noops-U7LI7UXC.js} +10 -10
- package/dist/cli/{mcp-L473BKLJ.js → mcp-GX2UKKWU.js} +25 -25
- package/dist/cli/{mcp-JJH6JR52.mjs → mcp-QJBMB6VS.mjs} +5 -5
- package/dist/cli/{monitors-3TF2DOFD.js → monitors-WCJYINGX.js} +164 -106
- package/dist/cli/{monitors-VSYHUBKC.mjs → monitors-Z6EGKYJP.mjs} +70 -12
- package/dist/cli/{org-YKVI2ZTI.js → org-7SKG423N.js} +89 -89
- package/dist/cli/{org-S5VIKU2E.mjs → org-NNHICBR2.mjs} +7 -7
- package/dist/cli/{play-DOWEG45Y.js → play-4P4DTG3Q.js} +318 -318
- package/dist/cli/{play-C7T5A3QM.mjs → play-CXDFPJ7Z.mjs} +18 -18
- package/dist/cli/{providers-TAZPPFTB.js → providers-EE4TUE3O.js} +10 -10
- package/dist/cli/{providers-BMVVX3VD.mjs → providers-VQLQ7DTR.mjs} +7 -7
- package/dist/cli/{quickstart-A3WKMKTW.mjs → quickstart-IYNJRB5G.mjs} +5 -5
- package/dist/cli/{quickstart-HD6FQXGR.js → quickstart-RVXHK4WA.js} +7 -7
- package/dist/cli/{run-BVVV2UX7.js → run-R3F34KU3.js} +44 -44
- package/dist/cli/{run-FV7TWNOC.mjs → run-VBQPPMEX.mjs} +24 -24
- package/dist/cli/{search-MGK6WIKS.mjs → search-B7R62HX5.mjs} +8 -8
- package/dist/cli/search-UUVFXZRA.js +32 -0
- package/dist/cli/{search-output-GM7LDZKE.mjs → search-output-LNQQXIGZ.mjs} +5 -5
- package/dist/cli/{search-output-6Y7KEPIE.js → search-output-LWHWEPOT.js} +7 -7
- package/dist/cli/{secrets-4RFAR7YI.mjs → secrets-NM3VAJLO.mjs} +7 -7
- package/dist/cli/{secrets-SISXIXSZ.js → secrets-QBOZ7WTD.js} +16 -16
- package/dist/cli/sessions-K3PD73Q2.js +22 -0
- package/dist/cli/{sessions-CE3OMEG7.mjs → sessions-R5BSIJ4I.mjs} +7 -7
- package/dist/cli/{settings-4HPM3K4A.js → settings-POYWKNRD.js} +86 -86
- package/dist/cli/{settings-E22IDSX2.mjs → settings-S4PN7WLY.mjs} +13 -13
- package/dist/cli/{setup-BK65MDZ6.mjs → setup-PFLXVBTL.mjs} +10 -10
- package/dist/cli/{setup-BDRSNLKX.js → setup-VHB4Z654.js} +50 -50
- package/dist/cli/skills-QNE2EYT3.js +36 -0
- package/dist/cli/{skills-FI2GZMR4.mjs → skills-W2TELEU7.mjs} +8 -8
- package/dist/cli/tools-3RLI4HGF.js +57 -0
- package/dist/cli/{tools-HMMWYUNW.mjs → tools-M4FA6N3Y.mjs} +18 -18
- package/dist/cli/update-UT6KIW2W.js +34 -0
- package/dist/cli/{update-WDKBSXV5.mjs → update-W7LIHEA7.mjs} +10 -10
- package/dist/cli/{views-775AUDWQ.js → views-DJXAGD7V.js} +22 -22
- package/dist/cli/{views-JYIJCO23.mjs → views-KTVPV6UP.mjs} +7 -7
- package/dist/cli/{workflow-FKKHE3IU.mjs → workflow-LGKCRODX.mjs} +8 -8
- package/dist/cli/{workflow-4H6KQRFQ.js → workflow-NVZDJKH2.js} +18 -18
- package/dist/{client-DD_FyJVd.d.ts → client-CCyWJqAI.d.ts} +1 -1
- package/dist/{client-ANT3pyoa.d.mts → client-Tp1LSULB.d.mts} +1 -1
- package/dist/{client-core-QHmo73k1.d.ts → client-core-BpYiYEfu.d.ts} +10 -1
- package/dist/{client-core-Dg9tKhdB.d.mts → client-core-D8eCZz3O.d.mts} +10 -1
- package/dist/{compiler-manifest-BWFtsQIC.d.ts → compiler-manifest-EBWEUj0b.d.mts} +35 -0
- package/dist/{compiler-manifest-BWFtsQIC.d.mts → compiler-manifest-EBWEUj0b.d.ts} +35 -0
- package/dist/{errors-Lm9_vJHZ.d.ts → errors-CParKUQR.d.mts} +2 -2
- package/dist/{errors-CwKXXtuu.d.mts → errors-Qt0OTA7_.d.ts} +2 -2
- package/dist/{index-DjwsAt82.d.mts → index-BMUVCNp7.d.mts} +1 -1
- package/dist/{index-3vJ-V9yw.d.ts → index-CoqDkIw0.d.ts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +10 -10
- package/dist/index.mjs +7 -7
- package/dist/install-integrity.json +126 -124
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- package/dist/plays/bundle-play-file.mjs +20 -1
- package/dist/plays/play-description.d.mts +2 -2
- package/dist/plays/play-description.d.ts +2 -2
- package/dist/plays/run-request.d.mts +2 -2
- package/dist/plays/run-request.d.ts +2 -2
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +10 -10
- package/dist/server.mjs +4 -4
- package/package.json +1 -1
- package/dist/cli/auth-ENBXAKQS.js +0 -43
- package/dist/cli/concurrent-runs-help-TOMLCMV7.js +0 -21
- package/dist/cli/describe-RUODIS6M.js +0 -50
- package/dist/cli/git-RLHTSYRY.js +0 -25
- package/dist/cli/search-VJFCWUZN.js +0 -32
- package/dist/cli/sessions-OWWZJZXH.js +0 -22
- package/dist/cli/skills-ZLBFUAFR.js +0 -36
- package/dist/cli/tools-3K72VE33.js +0 -57
- package/dist/cli/update-QZV6DH5V.js +0 -34
package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { Resolver } from 'node:dns/promises';
|
|
3
|
+
import { isIPv4 } from 'node:net';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Egress identity and the fail-closed egress gate for an early sandbox
|
|
7
|
+
* started without the supervisor sidecar.
|
|
8
|
+
*
|
|
9
|
+
* A provider fixes a sandbox's network policy at create, and adoption keeps
|
|
10
|
+
* it. Modal's SDK (0.9, `sandboxes.create`) turns any `outboundCidrAllowlist`
|
|
11
|
+
* array, including `[]`, into an ALLOWLIST policy, and an absent one into
|
|
12
|
+
* OPEN egress. So the early create must carry the same non-empty allowlist as
|
|
13
|
+
* the launch that adopts it, and adoption must refuse a sandbox created with
|
|
14
|
+
* any other policy (`egressKey`) or in another deployment environment: Preview
|
|
15
|
+
* and Production share one Modal workspace and app name.
|
|
16
|
+
*
|
|
17
|
+
* The gate refuses an early start (the launch then creates its own sandbox,
|
|
18
|
+
* as today) unless the allowlist is non-empty, every entry is a valid IPv4
|
|
19
|
+
* CIDR no wider than /24, and every IPv4 address the receipt and execution
|
|
20
|
+
* gateways resolve to is covered. Ordinary launches are unchanged.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** Deployment environment an early sandbox belongs to. */
|
|
24
|
+
export type EarlySandboxEnvironment = 'preview' | 'production';
|
|
25
|
+
|
|
26
|
+
/** What, besides org and workflow, an early sandbox's key names. */
|
|
27
|
+
export type EarlySandboxScope = Readonly<{
|
|
28
|
+
environment: EarlySandboxEnvironment;
|
|
29
|
+
/** `earlySandboxEgressKey` of the create's outbound allowlist. */
|
|
30
|
+
egressKey: string;
|
|
31
|
+
}>;
|
|
32
|
+
|
|
33
|
+
export class EarlySandboxEnvironmentError extends Error {
|
|
34
|
+
constructor(value: string) {
|
|
35
|
+
super(
|
|
36
|
+
`DEEPLINE_RUNTIME_ENVIRONMENT must be preview or production, got ${value}.`,
|
|
37
|
+
);
|
|
38
|
+
this.name = 'EarlySandboxEnvironmentError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The early sandbox's deployment environment: `preview` or `production`
|
|
44
|
+
* (unset or empty). Any other value, including a padded one, throws: an
|
|
45
|
+
* unknown environment must never be tagged, adopted or swept as Production.
|
|
46
|
+
* Only early-sandbox paths call this. Whenever it returns, it equals the
|
|
47
|
+
* ordinary launch's mapping (exactly `preview` is Preview, anything else
|
|
48
|
+
* Production), which never throws.
|
|
49
|
+
*/
|
|
50
|
+
export function earlySandboxEnvironment(
|
|
51
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
52
|
+
): EarlySandboxEnvironment {
|
|
53
|
+
const value = env.DEEPLINE_RUNTIME_ENVIRONMENT || 'production';
|
|
54
|
+
if (value === 'preview' || value === 'production') return value;
|
|
55
|
+
throw new EarlySandboxEnvironmentError(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* sha256 of the sorted allowlist, or of `open` when the create carries none
|
|
60
|
+
* (OPEN egress). `[]` (no egress) and OPEN never share a key.
|
|
61
|
+
*/
|
|
62
|
+
export function earlySandboxEgressKey(
|
|
63
|
+
outboundCidrAllowlist: readonly string[] | null | undefined,
|
|
64
|
+
): string {
|
|
65
|
+
const policy = outboundCidrAllowlist
|
|
66
|
+
? JSON.stringify(['allowlist', [...outboundCidrAllowlist].sort()])
|
|
67
|
+
: JSON.stringify(['open']);
|
|
68
|
+
return createHash('sha256').update(policy).digest('hex').slice(0, 40);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The widest allowlist entry an early sandbox may carry. */
|
|
72
|
+
export const EARLY_SANDBOX_EGRESS_MIN_PREFIX = 24;
|
|
73
|
+
/** The gateway address refresh interval. */
|
|
74
|
+
export const EARLY_SANDBOX_GATEWAY_DNS_REFRESH_MS = 5 * 60_000;
|
|
75
|
+
/** Addresses older than this (two missed refreshes) are refused. */
|
|
76
|
+
export const EARLY_SANDBOX_GATEWAY_DNS_MAX_AGE_MS =
|
|
77
|
+
2 * EARLY_SANDBOX_GATEWAY_DNS_REFRESH_MS + 30_000;
|
|
78
|
+
|
|
79
|
+
export type EarlySandboxEgressRefusal =
|
|
80
|
+
| 'environment_unknown'
|
|
81
|
+
| 'egress_allowlist_missing'
|
|
82
|
+
| 'egress_allowlist_empty'
|
|
83
|
+
| 'egress_allowlist_invalid'
|
|
84
|
+
| 'egress_allowlist_too_wide'
|
|
85
|
+
| 'egress_gateway_unconfigured'
|
|
86
|
+
| 'egress_gateway_dns_pending'
|
|
87
|
+
| 'egress_gateway_dns_failed'
|
|
88
|
+
| 'egress_gateway_dns_stale'
|
|
89
|
+
| 'egress_gateway_uncovered';
|
|
90
|
+
|
|
91
|
+
type Ipv4Cidr = { network: number; prefix: number };
|
|
92
|
+
|
|
93
|
+
function ipv4ToInt(address: string): number | null {
|
|
94
|
+
if (!isIPv4(address)) return null;
|
|
95
|
+
return (
|
|
96
|
+
address
|
|
97
|
+
.split('.')
|
|
98
|
+
.reduce((value, octet) => value * 256 + Number(octet), 0) >>> 0
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseIpv4Cidr(entry: string): Ipv4Cidr | null {
|
|
103
|
+
const [address, prefixText, ...rest] = entry.trim().split('/');
|
|
104
|
+
if (rest.length > 0 || !address) return null;
|
|
105
|
+
const base = ipv4ToInt(address);
|
|
106
|
+
if (base === null) return null;
|
|
107
|
+
const prefix = prefixText === undefined ? 32 : Number(prefixText);
|
|
108
|
+
if (!/^\d+$/.test(prefixText ?? '32') || prefix < 0 || prefix > 32)
|
|
109
|
+
return null;
|
|
110
|
+
return { network: base, prefix };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function cidrCovers(cidr: Ipv4Cidr, address: number): boolean {
|
|
114
|
+
if (cidr.prefix === 0) return true;
|
|
115
|
+
const mask = (0xffffffff << (32 - cidr.prefix)) >>> 0;
|
|
116
|
+
return ((cidr.network & mask) >>> 0) === ((address & mask) >>> 0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Gateway hostnames (or literal IPv4s) whose addresses the gate checks. */
|
|
120
|
+
export function earlySandboxGatewayHosts(
|
|
121
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
122
|
+
): string[] | null {
|
|
123
|
+
const receipt = env.DEEPLINE_RUNTIME_RECEIPT_GATEWAY_URL?.trim();
|
|
124
|
+
if (!receipt) return null;
|
|
125
|
+
// The runner's execution origin falls back to the receipt gateway.
|
|
126
|
+
const execution =
|
|
127
|
+
env.DEEPLINE_RUNTIME_EXECUTION_GATEWAY_URL?.trim() || receipt;
|
|
128
|
+
const hosts = new Set<string>();
|
|
129
|
+
for (const url of [receipt, execution]) {
|
|
130
|
+
try {
|
|
131
|
+
const host = new URL(url).hostname;
|
|
132
|
+
if (!host) return null;
|
|
133
|
+
hosts.add(host);
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return [...hosts].sort();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type EarlySandboxGatewayAddresses =
|
|
142
|
+
| { status: 'pending' }
|
|
143
|
+
| { status: 'failed'; error: string; atMs: number }
|
|
144
|
+
| {
|
|
145
|
+
status: 'resolved';
|
|
146
|
+
hosts: readonly string[];
|
|
147
|
+
/** Every IPv4 address of every host. */
|
|
148
|
+
addresses: readonly string[];
|
|
149
|
+
atMs: number;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Why an early sandbox may not start with this allowlist and these gateway
|
|
154
|
+
* addresses, or null. Pure.
|
|
155
|
+
*/
|
|
156
|
+
export function earlySandboxEgressRefusal(input: {
|
|
157
|
+
outboundCidrAllowlist: readonly string[] | null | undefined;
|
|
158
|
+
gatewayHosts: readonly string[] | null;
|
|
159
|
+
gateway: EarlySandboxGatewayAddresses;
|
|
160
|
+
nowMs: number;
|
|
161
|
+
}): EarlySandboxEgressRefusal | null {
|
|
162
|
+
const allowlist = input.outboundCidrAllowlist;
|
|
163
|
+
if (!allowlist) return 'egress_allowlist_missing';
|
|
164
|
+
if (allowlist.length === 0) return 'egress_allowlist_empty';
|
|
165
|
+
const cidrs: Ipv4Cidr[] = [];
|
|
166
|
+
for (const entry of allowlist) {
|
|
167
|
+
const cidr = parseIpv4Cidr(entry);
|
|
168
|
+
if (!cidr) return 'egress_allowlist_invalid';
|
|
169
|
+
if (cidr.prefix < EARLY_SANDBOX_EGRESS_MIN_PREFIX)
|
|
170
|
+
return 'egress_allowlist_too_wide';
|
|
171
|
+
cidrs.push(cidr);
|
|
172
|
+
}
|
|
173
|
+
if (!input.gatewayHosts || input.gatewayHosts.length === 0)
|
|
174
|
+
return 'egress_gateway_unconfigured';
|
|
175
|
+
const gateway = input.gateway;
|
|
176
|
+
if (gateway.status === 'pending') return 'egress_gateway_dns_pending';
|
|
177
|
+
if (gateway.status === 'failed') return 'egress_gateway_dns_failed';
|
|
178
|
+
// Resolved for other hosts (the env changed): not yet resolved for these.
|
|
179
|
+
if (
|
|
180
|
+
gateway.hosts.length !== input.gatewayHosts.length ||
|
|
181
|
+
gateway.hosts.some((host, index) => host !== input.gatewayHosts![index])
|
|
182
|
+
)
|
|
183
|
+
return 'egress_gateway_dns_pending';
|
|
184
|
+
if (input.nowMs - gateway.atMs > EARLY_SANDBOX_GATEWAY_DNS_MAX_AGE_MS)
|
|
185
|
+
return 'egress_gateway_dns_stale';
|
|
186
|
+
if (gateway.addresses.length === 0) return 'egress_gateway_dns_failed';
|
|
187
|
+
for (const address of gateway.addresses) {
|
|
188
|
+
const value = ipv4ToInt(address);
|
|
189
|
+
if (value === null || !cidrs.some((cidr) => cidrCovers(cidr, value)))
|
|
190
|
+
return 'egress_gateway_uncovered';
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export type ResolveIpv4 = (host: string) => Promise<string[]>;
|
|
196
|
+
|
|
197
|
+
const DNS_TIMEOUT_MS = 5_000;
|
|
198
|
+
|
|
199
|
+
function defaultResolveIpv4(): ResolveIpv4 {
|
|
200
|
+
const resolver = new Resolver({ timeout: DNS_TIMEOUT_MS, tries: 2 });
|
|
201
|
+
return (host) => resolver.resolve4(host);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The gateways' IPv4 addresses, resolved at start and every
|
|
206
|
+
* EARLY_SANDBOX_GATEWAY_DNS_REFRESH_MS. A failed refresh replaces the last
|
|
207
|
+
* good answer with `failed`, so the gate refuses until the next success.
|
|
208
|
+
*/
|
|
209
|
+
export class EarlySandboxGatewayAddressWatch {
|
|
210
|
+
#state: EarlySandboxGatewayAddresses = { status: 'pending' };
|
|
211
|
+
#timer: ReturnType<typeof setInterval> | null = null;
|
|
212
|
+
#inFlight: Promise<void> | null = null;
|
|
213
|
+
readonly #hosts: () => string[] | null;
|
|
214
|
+
readonly #resolve4: ResolveIpv4;
|
|
215
|
+
readonly #nowMs: () => number;
|
|
216
|
+
|
|
217
|
+
constructor(
|
|
218
|
+
input: {
|
|
219
|
+
hosts?: () => string[] | null;
|
|
220
|
+
resolve4?: ResolveIpv4;
|
|
221
|
+
nowMs?: () => number;
|
|
222
|
+
} = {},
|
|
223
|
+
) {
|
|
224
|
+
this.#hosts = input.hosts ?? (() => earlySandboxGatewayHosts());
|
|
225
|
+
this.#resolve4 = input.resolve4 ?? defaultResolveIpv4();
|
|
226
|
+
this.#nowMs = input.nowMs ?? Date.now;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
state(): EarlySandboxGatewayAddresses {
|
|
230
|
+
return this.#state;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Idempotent: the first call resolves now and schedules refreshes. */
|
|
234
|
+
start(): void {
|
|
235
|
+
if (this.#timer) return;
|
|
236
|
+
void this.refresh();
|
|
237
|
+
this.#timer = setInterval(() => {
|
|
238
|
+
void this.refresh();
|
|
239
|
+
}, EARLY_SANDBOX_GATEWAY_DNS_REFRESH_MS);
|
|
240
|
+
this.#timer.unref?.();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
stop(): void {
|
|
244
|
+
if (this.#timer) clearInterval(this.#timer);
|
|
245
|
+
this.#timer = null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** One resolution of every gateway host; never throws. */
|
|
249
|
+
refresh(): Promise<void> {
|
|
250
|
+
if (this.#inFlight) return this.#inFlight;
|
|
251
|
+
const run = (async () => {
|
|
252
|
+
const hosts = this.#hosts();
|
|
253
|
+
if (!hosts || hosts.length === 0) {
|
|
254
|
+
this.#state = {
|
|
255
|
+
status: 'failed',
|
|
256
|
+
error: 'gateway_unconfigured',
|
|
257
|
+
atMs: this.#nowMs(),
|
|
258
|
+
};
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
const addresses = new Set<string>();
|
|
263
|
+
for (const host of hosts) {
|
|
264
|
+
const resolved = isIPv4(host) ? [host] : await this.#resolve4(host);
|
|
265
|
+
if (resolved.length === 0)
|
|
266
|
+
throw new Error(`no IPv4 address for ${host}`);
|
|
267
|
+
for (const address of resolved) addresses.add(address);
|
|
268
|
+
}
|
|
269
|
+
this.#state = {
|
|
270
|
+
status: 'resolved',
|
|
271
|
+
hosts,
|
|
272
|
+
addresses: [...addresses].sort(),
|
|
273
|
+
atMs: this.#nowMs(),
|
|
274
|
+
};
|
|
275
|
+
} catch (error) {
|
|
276
|
+
this.#state = {
|
|
277
|
+
status: 'failed',
|
|
278
|
+
error: error instanceof Error ? error.message : String(error),
|
|
279
|
+
atMs: this.#nowMs(),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
})().finally(() => {
|
|
283
|
+
this.#inFlight = null;
|
|
284
|
+
});
|
|
285
|
+
this.#inFlight = run;
|
|
286
|
+
return run;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The gate, logged: a refusal is one loud structured line; the caller then
|
|
292
|
+
* starts no early sandbox and the launch creates its own.
|
|
293
|
+
*/
|
|
294
|
+
export function assertEarlySandboxEgress(input: {
|
|
295
|
+
logScope: string;
|
|
296
|
+
outboundCidrAllowlist: readonly string[] | null | undefined;
|
|
297
|
+
/** Why the allowlist could not be read, when it was not simply unset. */
|
|
298
|
+
allowlistError?: string | null;
|
|
299
|
+
gatewayHosts: readonly string[] | null;
|
|
300
|
+
gateway: EarlySandboxGatewayAddresses;
|
|
301
|
+
nowMs: number;
|
|
302
|
+
}): EarlySandboxEgressRefusal | null {
|
|
303
|
+
const refusal = earlySandboxEgressRefusal(input);
|
|
304
|
+
if (refusal) {
|
|
305
|
+
console.error(
|
|
306
|
+
JSON.stringify({
|
|
307
|
+
event: `${input.logScope}.egress_refused`,
|
|
308
|
+
reason: refusal,
|
|
309
|
+
allowlistEntries: input.outboundCidrAllowlist?.length ?? null,
|
|
310
|
+
...(input.allowlistError
|
|
311
|
+
? { allowlistError: input.allowlistError }
|
|
312
|
+
: {}),
|
|
313
|
+
gatewayHosts: input.gatewayHosts,
|
|
314
|
+
gatewayStatus: input.gateway.status,
|
|
315
|
+
...(input.gateway.status === 'failed'
|
|
316
|
+
? { gatewayError: input.gateway.error }
|
|
317
|
+
: {}),
|
|
318
|
+
}),
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
return refusal;
|
|
322
|
+
}
|