deepline 0.3.497 → 0.3.499
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/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/billing/policy-builders.ts +2 -0
- package/dist/bundling-sources/shared_libs/monitors/billing/state.ts +8 -1
- package/dist/bundling-sources/shared_libs/monitors/billing/tamradar.ts +23 -5
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-upstream-identity.ts +4 -3
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +1 -1
- package/dist/bundling-sources/shared_libs/observability/scheduled-work-control.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-admission-outcome.ts +8 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-oidc.ts +470 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-profile.ts +318 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +7 -4
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +4 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +19 -5
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +138 -0
- package/dist/cli/auth-32FRISRT.js +43 -0
- package/dist/cli/{auth-OAKBFUQD.mjs → auth-TECJ27G3.mjs} +5 -5
- package/dist/cli/{billing-AM6D2KN5.mjs → billing-PMKO73VG.mjs} +6 -6
- package/dist/cli/{billing-FUB6HQZ5.js → billing-ULZGAED6.js} +79 -79
- package/dist/cli/{chunk-V2EVSEUD.js → chunk-2PKZ3RUU.js} +16 -16
- package/dist/cli/{chunk-SLS3HUVC.js → chunk-2RZHMCDL.js} +4 -4
- package/dist/cli/{chunk-3IVAGF4P.mjs → chunk-3GP52OHV.mjs} +10 -10
- package/dist/cli/{chunk-KFJV3BZX.mjs → chunk-43ZERPGR.mjs} +1 -1
- package/dist/cli/{chunk-FISH2MI2.mjs → chunk-56JE475N.mjs} +9 -5
- package/dist/cli/{chunk-6TA2H7CY.js → chunk-57LW4TGY.js} +26 -26
- package/dist/cli/{chunk-MBOAXLWC.mjs → chunk-5IDORX4E.mjs} +4 -4
- package/dist/cli/{chunk-XLYJ7MJX.js → chunk-7OQZZHZ4.js} +15 -11
- package/dist/cli/{chunk-EWQ3KY5U.mjs → chunk-7UC2UZYW.mjs} +6 -6
- package/dist/cli/{chunk-JDFYCHNV.js → chunk-7WUMIRBV.js} +5 -5
- package/dist/cli/{chunk-5GXYXU45.mjs → chunk-A2VCFBZN.mjs} +1 -1
- package/dist/cli/{chunk-7RBIOOCQ.js → chunk-AGZRRHSB.js} +3 -3
- package/dist/cli/{chunk-SJM7MKOE.js → chunk-AKLI4XSG.js} +2 -2
- package/dist/cli/{chunk-4MR7LZXF.mjs → chunk-BBFWIYAF.mjs} +2 -2
- package/dist/cli/{chunk-XNLXHU6L.mjs → chunk-C2V5U6HO.mjs} +5 -5
- package/dist/cli/{chunk-OWDK2PVH.js → chunk-FG5OZ5FB.js} +8 -8
- package/dist/cli/{chunk-BRUDMG56.js → chunk-G7BB2VOC.js} +41 -41
- package/dist/cli/{chunk-IURXJPGH.mjs → chunk-IGCSKXGK.mjs} +3 -3
- package/dist/cli/{chunk-WKCMARFR.js → chunk-JIZHGOZ5.js} +94 -94
- package/dist/cli/{chunk-WZ3A35ZD.mjs → chunk-JM52ATUS.mjs} +1 -1
- package/dist/cli/{chunk-KUX3HYJI.mjs → chunk-JQHJKARU.mjs} +28 -22
- package/dist/cli/{chunk-5IBHSACU.mjs → chunk-JUQESEJX.mjs} +2 -2
- package/dist/cli/{chunk-ZLYKN4AJ.js → chunk-K54BUQSK.js} +7 -7
- package/dist/cli/{chunk-FVS5MJQ5.js → chunk-KLQ5CR77.js} +30 -24
- package/dist/cli/{chunk-VMOVB2FN.mjs → chunk-KOD45UP5.mjs} +5 -5
- package/dist/cli/{chunk-SJID5WMV.mjs → chunk-KZJKRU24.mjs} +4 -4
- package/dist/cli/{chunk-BBHGJE73.js → chunk-L6C7C7IJ.js} +1 -1
- package/dist/cli/{chunk-DKSTMQ3F.js → chunk-L7O7AFSF.js} +21 -21
- package/dist/cli/{chunk-YUEFDOME.js → chunk-LUNXREUI.js} +6 -6
- package/dist/cli/{chunk-3DHPKENA.mjs → chunk-MQ5YPD7K.mjs} +1 -1
- package/dist/cli/{chunk-LPCK5KK5.mjs → chunk-OWHQ4OG5.mjs} +2 -2
- package/dist/cli/{chunk-YQ66NC4J.mjs → chunk-P3MGNLZF.mjs} +2 -2
- package/dist/cli/{chunk-B4Q3EBQX.js → chunk-PE3UHMMZ.js} +5 -5
- package/dist/cli/{chunk-M2WIEW2E.mjs → chunk-PSYGSXDS.mjs} +1 -1
- package/dist/cli/{chunk-THD6KA67.mjs → chunk-QXI2W7YY.mjs} +4 -4
- package/dist/cli/{chunk-OEI6HXMK.js → chunk-SLWCXGKP.js} +16 -16
- package/dist/cli/{chunk-2HCZHIMT.mjs → chunk-TFFJ2PRN.mjs} +5 -3
- package/dist/cli/{chunk-7FFNSYMJ.js → chunk-TUDYBF4Y.js} +9 -9
- package/dist/cli/{chunk-UETGYJYH.mjs → chunk-UMPCQ4EE.mjs} +2 -2
- package/dist/cli/{chunk-A66Y2LCW.js → chunk-UOQUCFAK.js} +53 -53
- package/dist/cli/{chunk-TGAYN34A.mjs → chunk-WEVIUQGZ.mjs} +2 -2
- package/dist/cli/{chunk-77IAUCTB.js → chunk-WSOM3TY6.js} +3 -3
- package/dist/cli/{chunk-3KG2FUU4.js → chunk-XSUQAUG4.js} +7 -7
- package/dist/cli/{chunk-HRODQDTB.mjs → chunk-YAW7ET4P.mjs} +1 -1
- package/dist/cli/{chunk-N3T3L3WW.js → chunk-YPTZJ7LO.js} +5 -3
- package/dist/cli/{chunk-UV7AT2D4.js → chunk-YRQWGWRJ.js} +2 -2
- package/dist/cli/{chunk-WXW7YJDO.js → chunk-Z2MO7FZG.js} +53 -53
- package/dist/cli/{chunk-XX7WLKOQ.mjs → chunk-ZVAD65CF.mjs} +1 -1
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-U2GOFP3M.mjs → csv-ACO5YC46.mjs} +4 -4
- package/dist/cli/{csv-PMBYKVUU.js → csv-VGSQ3JYE.js} +13 -13
- package/dist/cli/{db-DKFOTZGZ.mjs → db-CXNZOXGM.mjs} +6 -6
- package/dist/cli/{db-GREVTMIR.js → db-QOUPHFFN.js} +27 -27
- package/dist/cli/describe-DEXYQMBO.js +50 -0
- package/dist/cli/{describe-SWXA6L62.mjs → describe-J4O5GCJS.mjs} +17 -17
- package/dist/cli/{executions-EBRFC5JR.mjs → executions-SJETRLXW.mjs} +6 -6
- package/dist/cli/{executions-2RRAESQK.js → executions-YIECH2CL.js} +8 -8
- package/dist/cli/{feedback-N6ML7IRH.js → feedback-5BRCNERV.js} +8 -8
- package/dist/cli/{feedback-4A57QLX2.mjs → feedback-GSAFFMF6.mjs} +4 -4
- package/dist/cli/git-RDKLITUC.js +25 -0
- package/dist/cli/{git-6D2WQPOS.mjs → git-SF5XIGLU.mjs} +5 -5
- package/dist/cli/index.js +141 -141
- package/dist/cli/index.mjs +41 -41
- package/dist/cli/{legacy-noops-DXRJARNC.js → legacy-noops-5TBT4XC6.js} +8 -8
- package/dist/cli/{legacy-noops-CL5QWXGH.mjs → legacy-noops-TZA3CALE.mjs} +5 -5
- package/dist/cli/{monitors-SGMEGGJO.mjs → monitors-XAYWJNSV.mjs} +7 -7
- package/dist/cli/{monitors-XWKDVHYL.js → monitors-XNB5YNC3.js} +95 -95
- package/dist/cli/{org-QKQ57PDN.js → org-2UYWJXG7.js} +72 -72
- package/dist/cli/{org-55BI5RQF.mjs → org-S5VZL5KZ.mjs} +6 -6
- package/dist/cli/{pages-LM4QACOM.mjs → pages-NGVJO7PA.mjs} +6 -6
- package/dist/cli/{pages-FOIR5UH4.js → pages-ZQRRTZIT.js} +18 -18
- package/dist/cli/{play-7VA26O6E.mjs → play-3JNERHSC.mjs} +37 -27
- package/dist/cli/{play-S44FXGD7.js → play-P3OYQ7JV.js} +406 -396
- package/dist/cli/{providers-QAVIR5E2.mjs → providers-27O6BOAP.mjs} +6 -6
- package/dist/cli/{providers-RDSHID7C.js → providers-2FFGAPUR.js} +9 -9
- package/dist/cli/{quickstart-EREQPM3G.js → quickstart-5G2UPKJV.js} +6 -6
- package/dist/cli/{quickstart-IL4HQYE4.mjs → quickstart-B2EXIAU6.mjs} +4 -4
- package/dist/cli/{run-TBUUV5EG.js → run-2TGD7FAL.js} +82 -43
- package/dist/cli/{run-4XZNJR7N.mjs → run-3QFXYV3Z.mjs} +69 -30
- package/dist/cli/{search-SYT5UT5G.mjs → search-GXEEOMVD.mjs} +7 -7
- package/dist/cli/search-YKTYDBCN.js +32 -0
- package/dist/cli/{search-output-Y3IKZ3TX.mjs → search-output-DMIJQTAA.mjs} +4 -4
- package/dist/cli/{search-output-5F3EEQ34.js → search-output-I4RZPHU6.js} +6 -6
- package/dist/cli/{secrets-AKAU2N3K.mjs → secrets-DQI5YCS6.mjs} +6 -6
- package/dist/cli/{secrets-PZWJ2ES5.js → secrets-MJMNRXZX.js} +15 -15
- package/dist/cli/{sessions-Z5C26IS7.mjs → sessions-HAUN3VYE.mjs} +5 -5
- package/dist/cli/{sessions-UMHA7K23.js → sessions-QS74ZTRH.js} +6 -6
- package/dist/cli/{settings-S5BM3SVI.mjs → settings-E64HIUXW.mjs} +11 -11
- package/dist/cli/{settings-WGJYWTJZ.js → settings-VQBOS6VU.js} +78 -78
- package/dist/cli/{setup-6K6ERKOH.js → setup-KRW3JCJE.js} +49 -49
- package/dist/cli/{setup-E4HRXP2X.mjs → setup-NRUG42F2.mjs} +9 -9
- package/dist/cli/{skills-HIZA7YAN.mjs → skills-AHLZRTKZ.mjs} +7 -7
- package/dist/cli/skills-PGVIJK6Q.js +36 -0
- package/dist/cli/{tools-FS5S6BT7.mjs → tools-INRRIWOU.mjs} +16 -16
- package/dist/cli/tools-IXXN2RE4.js +57 -0
- package/dist/cli/{update-4CJPTG3L.mjs → update-ETOWEJ7D.mjs} +9 -9
- package/dist/cli/update-QW4RV2UX.js +34 -0
- package/dist/cli/{workflow-UMSXOIOS.mjs → workflow-JT2DOSCJ.mjs} +7 -7
- package/dist/cli/{workflow-TYSZ5JWS.js → workflow-RUAYQK4D.js} +17 -17
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +102 -100
- 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.js +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-553ZBCPJ.js +0 -43
- package/dist/cli/describe-BL5NNHV5.js +0 -50
- package/dist/cli/git-7TSX5V57.js +0 -25
- package/dist/cli/search-GCANFVVZ.js +0 -32
- package/dist/cli/skills-J3GQHHHL.js +0 -36
- package/dist/cli/tools-RZYKMOUX.js +0 -57
- package/dist/cli/update-CATZW7GA.js +0 -34
|
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
|
|
|
205
205
|
// getters keep their established compatibility behavior.
|
|
206
206
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
207
207
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
208
|
-
version: '0.3.
|
|
208
|
+
version: '0.3.499',
|
|
209
209
|
updateSummary: {
|
|
210
210
|
introducedIn: '0.3.90',
|
|
211
211
|
summary:
|
|
@@ -593,6 +593,8 @@ export function defineTamradarMonitorBillingPolicy(
|
|
|
593
593
|
'No Deepline base reactivate charge',
|
|
594
594
|
);
|
|
595
595
|
const customerUsageCharges: MonitorRetailCharge[] = [];
|
|
596
|
+
// Not currently used: no TamRadar radar type is priced as a subscription
|
|
597
|
+
// since job changes moved to per-finding pricing (2026-11-10).
|
|
596
598
|
if (subscriptionEntries.length > 0) {
|
|
597
599
|
customerUsageCharges.push(
|
|
598
600
|
retailCharge({
|
|
@@ -191,7 +191,8 @@ export function monitorBillingRequiresExplicitReactivation(
|
|
|
191
191
|
* Whether a monthly-billed monitor is still inside the period it has already
|
|
192
192
|
* paid for (KAR-43 decision 8).
|
|
193
193
|
*
|
|
194
|
-
* A subscription monitor (TamRadar `contact_job_changes`
|
|
194
|
+
* A subscription monitor (TamRadar `contact_job_changes` until it moved to
|
|
195
|
+
* per-finding pricing on 2026-11-10; no radar type today) is billed per month,
|
|
195
196
|
* not per finding: the first month at create, then renewed by the
|
|
196
197
|
* `charge-reconcile` cron 24 hours before the provider's `next_charge_at`.
|
|
197
198
|
* That renewal is its funding gate. Until the paid period ends, a negative
|
|
@@ -199,6 +200,12 @@ export function monitorBillingRequiresExplicitReactivation(
|
|
|
199
200
|
* charges, the customer keeps the month they paid for, and a recreate would
|
|
200
201
|
* charge Deepline again (TamRadar has no reactivate endpoint).
|
|
201
202
|
*
|
|
203
|
+
* Since 2026-11-10 that premise no longer holds for a job-change monitor
|
|
204
|
+
* bought monthly and not yet converted: its findings DO charge per finding,
|
|
205
|
+
* so finding admission, not this exemption, is what stops it at a zero
|
|
206
|
+
* balance. The renewal pass or `monitors billing resync-period` clears the
|
|
207
|
+
* period, after which this returns false for it.
|
|
208
|
+
*
|
|
202
209
|
* `provider_next_charge_at` is the provider-owned period end; `next_renewal_at`
|
|
203
210
|
* is Deepline's own periodic renewal. Either one in the future proves a paid
|
|
204
211
|
* period. An unparseable anchor proves nothing.
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
MonitorCommercialModel,
|
|
4
4
|
MonitorPayloadPricingEntry,
|
|
5
5
|
MonitorPayloadPricingMap,
|
|
6
|
+
MonitorPayloadPricingMode,
|
|
6
7
|
} from '@deepline/monitors/billing/types';
|
|
7
8
|
import { publicMonitorPricingEntry } from '@deepline/monitors/billing/public-pricing';
|
|
8
9
|
|
|
@@ -64,13 +65,17 @@ export const TAMRADAR_RADAR_TYPE_PRICING = {
|
|
|
64
65
|
providerCostUsd: 0.025,
|
|
65
66
|
unitLabel: 'finding',
|
|
66
67
|
},
|
|
68
|
+
// Source: TAMRadar per-update pricing (confidential/internal). TAMRadar
|
|
69
|
+
// moved job changes from $0.07/month to $0.13 per delivered change, with no
|
|
70
|
+
// monthly renewal, on 2026-11-10. Monitors created as subscriptions convert
|
|
71
|
+
// through the renewal pass (`reconcile.ts`).
|
|
72
|
+
// https://tamradar.mintlify.app/api-reference/create-contact-radar (job_changes).
|
|
67
73
|
contact_job_changes: {
|
|
68
74
|
capability: 'contact_radar',
|
|
69
75
|
label: 'Contact job changes',
|
|
70
|
-
mode: '
|
|
71
|
-
providerCostUsd: 0.
|
|
72
|
-
unitLabel: '
|
|
73
|
-
periodDays: 30,
|
|
76
|
+
mode: 'monitor_usage',
|
|
77
|
+
providerCostUsd: 0.13,
|
|
78
|
+
unitLabel: 'finding',
|
|
74
79
|
},
|
|
75
80
|
// Source: TAMRadar per-update pricing (confidential/internal),
|
|
76
81
|
// https://tamradar.mintlify.app/api-reference/create-contact-radar (social_posts).
|
|
@@ -181,10 +186,23 @@ export function tamradarProviderCostKey(input: {
|
|
|
181
186
|
return `deepline_native.${input.capability}.${input.radarType}`;
|
|
182
187
|
}
|
|
183
188
|
|
|
189
|
+
// Every mode a registry entry may take. Read through this rather than the
|
|
190
|
+
// registry's literal type: no entry is a subscription today, so the literal
|
|
191
|
+
// type would reject the subscription branch below.
|
|
192
|
+
type TamradarRadarTypePricingConfig = {
|
|
193
|
+
capability: string;
|
|
194
|
+
label: string;
|
|
195
|
+
mode: MonitorPayloadPricingMode;
|
|
196
|
+
providerCostUsd: number;
|
|
197
|
+
unitLabel: string;
|
|
198
|
+
periodDays?: number;
|
|
199
|
+
};
|
|
200
|
+
|
|
184
201
|
function entryForRadarType(
|
|
185
202
|
radarType: TamradarRadarType,
|
|
186
203
|
): MonitorPayloadPricingEntry {
|
|
187
|
-
const config =
|
|
204
|
+
const config: TamradarRadarTypePricingConfig =
|
|
205
|
+
TAMRADAR_RADAR_TYPE_PRICING[radarType];
|
|
188
206
|
return {
|
|
189
207
|
label: config.label,
|
|
190
208
|
mode: config.mode,
|
|
@@ -46,9 +46,10 @@ type ProviderMonitorUpstreamIdentityDefinition = {
|
|
|
46
46
|
* Payload fields that never change which findings the provider resource
|
|
47
47
|
* delivers. `updates_since` only sets how far back the first delivery
|
|
48
48
|
* replays, so two monitors that differ only there watch the same feed.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* readers
|
|
49
|
+
* Claim keys omit them; the `normalizeProviderMonitorIdentityClaimKeys`
|
|
50
|
+
* migration rewrote every key stored before that. An older app build can
|
|
51
|
+
* still send a key that carries them, so readers pass incoming keys through
|
|
52
|
+
* `canonicalProviderMonitorIdentityClaimKey`.
|
|
52
53
|
*/
|
|
53
54
|
nonConfigurationFields?: readonly string[];
|
|
54
55
|
};
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"id": "github.ci-health-analytics",
|
|
94
94
|
"name": "CI Health Analytics",
|
|
95
95
|
"scheduler": "github_actions",
|
|
96
|
-
"cadence": "
|
|
96
|
+
"cadence": "20 * * * *",
|
|
97
97
|
"timezone": "UTC",
|
|
98
98
|
"source": ".github/workflows/ci-health-analytics.yml",
|
|
99
99
|
"locator": "schedule:",
|
|
@@ -61,6 +61,8 @@ export type ScheduledWorkControlContext = {
|
|
|
61
61
|
*/
|
|
62
62
|
readonly orgScope?: readonly string[];
|
|
63
63
|
readonly historicalSettlementManifest?: HistoricalSettlementManifest;
|
|
64
|
+
/** Maximum settlement batch width for `settlement-batch-width` activate. */
|
|
65
|
+
readonly settlementBatchWidth?: number;
|
|
64
66
|
readonly requestedByUserId: string;
|
|
65
67
|
readonly requestedByEmail: string;
|
|
66
68
|
readonly reason: string;
|
|
@@ -47,7 +47,10 @@ export const PLAY_RUNTIME_CALLBACK_UNCONFIGURED =
|
|
|
47
47
|
*/
|
|
48
48
|
export const PLAY_RUN_RATE_LIMITED = 'PLAY_RUN_RATE_LIMITED' as const;
|
|
49
49
|
|
|
50
|
-
export
|
|
50
|
+
export const WORKSPACE_TRIGGER_RETIRED = 'WORKSPACE_TRIGGER_RETIRED' as const;
|
|
51
|
+
export type PlayAdmissionSkippedCode =
|
|
52
|
+
| typeof PLAY_RUN_RATE_LIMITED
|
|
53
|
+
| typeof WORKSPACE_TRIGGER_RETIRED;
|
|
51
54
|
|
|
52
55
|
export type PlayAdmissionBlockedCode =
|
|
53
56
|
| typeof PLAY_ADMISSION_PAYLOAD_UNREADABLE
|
|
@@ -112,6 +115,8 @@ const PLAY_RUN_RATE_LIMITED_MESSAGE =
|
|
|
112
115
|
* code alone, so the reason must be derivable from the stable code.
|
|
113
116
|
*/
|
|
114
117
|
export function playAdmissionBlockedMessage(code: string): string {
|
|
118
|
+
if (code === WORKSPACE_TRIGGER_RETIRED)
|
|
119
|
+
return 'Workspace was archived after this delivery was queued.';
|
|
115
120
|
return code === PLAY_RUN_RATE_LIMITED
|
|
116
121
|
? PLAY_RUN_RATE_LIMITED_MESSAGE
|
|
117
122
|
: code === PLAY_SECRET_UNAVAILABLE
|
|
@@ -159,11 +164,11 @@ export function classifyPlayAdmissionFailure(
|
|
|
159
164
|
return blocked(PLAY_SECRET_UNAVAILABLE);
|
|
160
165
|
}
|
|
161
166
|
const code = stableErrorCode(error);
|
|
162
|
-
if (code === PLAY_RUN_RATE_LIMITED) {
|
|
167
|
+
if (code === PLAY_RUN_RATE_LIMITED || code === WORKSPACE_TRIGGER_RETIRED) {
|
|
163
168
|
return {
|
|
164
169
|
disposition: 'skipped',
|
|
165
170
|
code,
|
|
166
|
-
message:
|
|
171
|
+
message: playAdmissionBlockedMessage(code),
|
|
167
172
|
};
|
|
168
173
|
}
|
|
169
174
|
if (
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPrivateKey,
|
|
3
|
+
createPublicKey,
|
|
4
|
+
sign,
|
|
5
|
+
verify,
|
|
6
|
+
type JsonWebKey,
|
|
7
|
+
type KeyObject,
|
|
8
|
+
} from 'node:crypto';
|
|
9
|
+
import { isRuntimeGatewayDeploymentId } from './runtime-gateway-profile';
|
|
10
|
+
import { isTestOnlyRuntime } from './runtime-env';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Edge credential for sandbox -> pinned app-deployment gateway traffic.
|
|
14
|
+
*
|
|
15
|
+
* One durable, code-owned issuer signs short-lived RS256 tokens scoped to one
|
|
16
|
+
* deployment, run and attempt. Vercel Trusted Sources admits the request at
|
|
17
|
+
* the edge from `x-vercel-trusted-oidc-idp-token`; the gateway handler checks
|
|
18
|
+
* the same token from `x-deepline-runtime-oidc` against the exact run and
|
|
19
|
+
* deployment. The executor token remains the request's authorization.
|
|
20
|
+
*
|
|
21
|
+
* Preview and Production never accept each other's tokens. Every token
|
|
22
|
+
* carries `deepline_env`; each environment signs with and trusts only its
|
|
23
|
+
* own kids, and verification requires the deployment's own environment in
|
|
24
|
+
* both the kid and the claim. The published JWKS is the union of both
|
|
25
|
+
* environments' keys, so one issuer serves both.
|
|
26
|
+
*/
|
|
27
|
+
export const RUNTIME_GATEWAY_OIDC_ISSUER =
|
|
28
|
+
'https://code.deepline.com/runtime-gateway-oidc';
|
|
29
|
+
export const RUNTIME_GATEWAY_OIDC_SUBJECT = 'deepline:runtime-gateway:daytona';
|
|
30
|
+
export const RUNTIME_GATEWAY_OIDC_AUDIENCE = 'deepline:runtime-gateway';
|
|
31
|
+
export const RUNTIME_GATEWAY_OIDC_MAX_AGE_SECONDS = 15 * 60;
|
|
32
|
+
export const RUNTIME_GATEWAY_OIDC_RENEW_AFTER_SECONDS = 2 * 60;
|
|
33
|
+
/** Appended to the pinned receipt gateway base URL. */
|
|
34
|
+
export const RUNTIME_GATEWAY_OIDC_RENEW_PATH = '/renew-oidc';
|
|
35
|
+
/** Header Vercel Trusted Sources reads at the edge. */
|
|
36
|
+
export const RUNTIME_GATEWAY_OIDC_EDGE_HEADER =
|
|
37
|
+
'x-vercel-trusted-oidc-idp-token';
|
|
38
|
+
/** Header the app verifies, independent of edge header handling. */
|
|
39
|
+
export const RUNTIME_GATEWAY_OIDC_APP_HEADER = 'x-deepline-runtime-oidc';
|
|
40
|
+
export const RUNTIME_GATEWAY_OIDC_DISCOVERY_PATH =
|
|
41
|
+
'/.well-known/openid-configuration';
|
|
42
|
+
export const RUNTIME_GATEWAY_OIDC_JWKS_PATH = '/.well-known/jwks.json';
|
|
43
|
+
/** Secret env (base64 DER PKCS#8 RSA key) and its key id. */
|
|
44
|
+
export const RUNTIME_GATEWAY_OIDC_PRIVATE_KEY_ENV =
|
|
45
|
+
'DEEPLINE_RUNTIME_GATEWAY_OIDC_PRIVATE_KEY';
|
|
46
|
+
export const RUNTIME_GATEWAY_OIDC_KID_ENV = 'DEEPLINE_RUNTIME_GATEWAY_OIDC_KID';
|
|
47
|
+
/** Sandbox-local file the watchdog rewrites with each renewed token. */
|
|
48
|
+
export const RUNTIME_GATEWAY_OIDC_FILE_ENV =
|
|
49
|
+
'DEEPLINE_RUNTIME_GATEWAY_OIDC_FILE';
|
|
50
|
+
/** Renewal response body field. */
|
|
51
|
+
export const RUNTIME_GATEWAY_OIDC_RENEW_RESPONSE_FIELD = 'oidcToken';
|
|
52
|
+
const RUNTIME_GATEWAY_OIDC_MAX_TOKEN_LENGTH = 4_096;
|
|
53
|
+
const RUNTIME_GATEWAY_OIDC_CLOCK_SKEW_SECONDS = 30;
|
|
54
|
+
|
|
55
|
+
export type RuntimeGatewayOidcPublicJwk = JsonWebKey & {
|
|
56
|
+
kty: 'RSA';
|
|
57
|
+
kid: string;
|
|
58
|
+
alg: 'RS256';
|
|
59
|
+
use: 'sig';
|
|
60
|
+
n: string;
|
|
61
|
+
e: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Public keys trusted for verification. Rotation: add the new key first and
|
|
66
|
+
* keep the previous one until every token it signed has expired (15 min),
|
|
67
|
+
* then switch the signing secret, then remove the previous key.
|
|
68
|
+
*/
|
|
69
|
+
export const RUNTIME_GATEWAY_OIDC_PUBLIC_JWKS: Readonly<{
|
|
70
|
+
keys: readonly RuntimeGatewayOidcPublicJwk[];
|
|
71
|
+
}> = Object.freeze({
|
|
72
|
+
keys: Object.freeze([
|
|
73
|
+
Object.freeze({
|
|
74
|
+
kty: 'RSA',
|
|
75
|
+
kid: 'rgw-oidc-2026-11-10',
|
|
76
|
+
alg: 'RS256',
|
|
77
|
+
use: 'sig',
|
|
78
|
+
n: 'rx63Q0lYpf56t-9Ab1UZMdlvEHvA2HeaJP95XtXhD65C4CZexNgUBiC9TGmqBKyCIVJK2sd9nHzhikSiAch8Wwjuo_zqU_L5te1YbfuVDi-0klnCyKqjCai8V8Td0IQ4yJaTAyO0DQNsnMKxayyxWs3N-dQ12C51wx1BNGm_Xx8Y3T_KfLU2lyam0RhEyl5D7S4cdtdITVqQMPjWVhxNb_iIz1PYP6VH3AKATOo5g4TuWXpz3WJcuATlSLCg-oW07pfdDCi2BTSL0kcBoe4SdrWcBCb8ja3xn3L-bMwVOB3-6L0G6uHC68Qp4zK0RQK_esZWb9L9nlbvqNDysVqX2w',
|
|
79
|
+
e: 'AQAB',
|
|
80
|
+
}),
|
|
81
|
+
Object.freeze({
|
|
82
|
+
kty: 'RSA',
|
|
83
|
+
kid: 'rgw-oidc-preview-2026-11-10',
|
|
84
|
+
alg: 'RS256',
|
|
85
|
+
use: 'sig',
|
|
86
|
+
n: 'wnlW_8K4tn3KDmpl6CHhsHnlewnbxMORijZal1Ft8f94Z_hrKQxV7uzl6xv-iYzc1vGh7SSWsTcctO1Hig489U78BZzIz07D1oHtl7NbVsncip8jV5E-EIhi6X159kzPKsj1PTSwihvEpN0x91GGHQORZKuQEPPN923kWN8omkia3Fr4sRwV79qXKm_Bp_jMWwX_7YklVaviyCiT0nQbxt9x289HyS1lOUhtu4jsha19L2tqSt7on1lYizSq5BHCBqHMd7hjlfiC2QWXu74mqUQil88VUFySUFQXndXodwvquSdga6vGBmfggfffQrS-Oh2IBdQln96--XnJWlszKw',
|
|
87
|
+
e: 'AQAB',
|
|
88
|
+
}),
|
|
89
|
+
]),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/** Which deployment class signs or accepts a token. */
|
|
93
|
+
export type RuntimeGatewayOidcEnvironment = 'preview' | 'production';
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The published kids each environment may sign with and accept. Disjoint, so
|
|
97
|
+
* a Preview private key can never produce a token a Production deployment
|
|
98
|
+
* accepts, and the reverse. Rotation adds the new kid to its environment
|
|
99
|
+
* here and to the JWKS above in the same change.
|
|
100
|
+
*/
|
|
101
|
+
export const RUNTIME_GATEWAY_OIDC_ENVIRONMENT_KIDS: Readonly<
|
|
102
|
+
Record<RuntimeGatewayOidcEnvironment, readonly string[]>
|
|
103
|
+
> = Object.freeze({
|
|
104
|
+
production: Object.freeze(['rgw-oidc-2026-11-10']),
|
|
105
|
+
preview: Object.freeze(['rgw-oidc-preview-2026-11-10']),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* This process's environment, from the same canonical test the internal
|
|
110
|
+
* capabilities use (`isTestOnlyRuntime`): anything that is not Production is
|
|
111
|
+
* Preview for this credential.
|
|
112
|
+
*/
|
|
113
|
+
export function resolveRuntimeGatewayOidcEnvironment(): RuntimeGatewayOidcEnvironment {
|
|
114
|
+
return isTestOnlyRuntime() ? 'preview' : 'production';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Key material a caller trusts; defaults to the code-owned constants. */
|
|
118
|
+
export type RuntimeGatewayOidcTrust = Readonly<{
|
|
119
|
+
jwks: Readonly<{ keys: readonly RuntimeGatewayOidcPublicJwk[] }>;
|
|
120
|
+
environmentKids: Readonly<
|
|
121
|
+
Record<RuntimeGatewayOidcEnvironment, readonly string[]>
|
|
122
|
+
>;
|
|
123
|
+
}>;
|
|
124
|
+
|
|
125
|
+
export const RUNTIME_GATEWAY_OIDC_TRUST: RuntimeGatewayOidcTrust =
|
|
126
|
+
Object.freeze({
|
|
127
|
+
jwks: RUNTIME_GATEWAY_OIDC_PUBLIC_JWKS,
|
|
128
|
+
environmentKids: RUNTIME_GATEWAY_OIDC_ENVIRONMENT_KIDS,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
function environmentJwk(
|
|
132
|
+
trust: RuntimeGatewayOidcTrust,
|
|
133
|
+
environment: RuntimeGatewayOidcEnvironment,
|
|
134
|
+
kid: string,
|
|
135
|
+
): RuntimeGatewayOidcPublicJwk | null {
|
|
136
|
+
if (!trust.environmentKids[environment].includes(kid)) return null;
|
|
137
|
+
return trust.jwks.keys.find((candidate) => candidate.kid === kid) ?? null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type RuntimeGatewayOidcClaims = {
|
|
141
|
+
iss: string;
|
|
142
|
+
aud: string;
|
|
143
|
+
sub: string;
|
|
144
|
+
deployment_id: string;
|
|
145
|
+
run_id: string;
|
|
146
|
+
run_attempt: number;
|
|
147
|
+
deepline_env: RuntimeGatewayOidcEnvironment;
|
|
148
|
+
iat: number;
|
|
149
|
+
exp: number;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type RuntimeGatewayOidcSigningKey = Readonly<{
|
|
153
|
+
kid: string;
|
|
154
|
+
/** Base64 DER PKCS#8 RSA private key. */
|
|
155
|
+
privateKeyPkcs8Base64: string;
|
|
156
|
+
}>;
|
|
157
|
+
|
|
158
|
+
export class RuntimeGatewayOidcError extends Error {
|
|
159
|
+
constructor(
|
|
160
|
+
readonly code:
|
|
161
|
+
| 'signing_key_unavailable'
|
|
162
|
+
| 'signing_key_invalid'
|
|
163
|
+
| 'signing_key_not_published'
|
|
164
|
+
| 'claims_invalid',
|
|
165
|
+
message: string,
|
|
166
|
+
) {
|
|
167
|
+
super(message);
|
|
168
|
+
this.name = 'RuntimeGatewayOidcError';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Read the secret signing key. Missing or partial configuration is null. */
|
|
173
|
+
export function resolveRuntimeGatewayOidcSigningKey(
|
|
174
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
175
|
+
): RuntimeGatewayOidcSigningKey | null {
|
|
176
|
+
const privateKeyPkcs8Base64 =
|
|
177
|
+
env[RUNTIME_GATEWAY_OIDC_PRIVATE_KEY_ENV]?.trim();
|
|
178
|
+
const kid = env[RUNTIME_GATEWAY_OIDC_KID_ENV]?.trim();
|
|
179
|
+
if (!privateKeyPkcs8Base64 || !kid) return null;
|
|
180
|
+
return { kid, privateKeyPkcs8Base64 };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function rsaPrivateKey(signingKey: RuntimeGatewayOidcSigningKey): KeyObject {
|
|
184
|
+
let key: KeyObject;
|
|
185
|
+
try {
|
|
186
|
+
key = createPrivateKey({
|
|
187
|
+
key: Buffer.from(signingKey.privateKeyPkcs8Base64, 'base64'),
|
|
188
|
+
format: 'der',
|
|
189
|
+
type: 'pkcs8',
|
|
190
|
+
});
|
|
191
|
+
} catch {
|
|
192
|
+
throw new RuntimeGatewayOidcError(
|
|
193
|
+
'signing_key_invalid',
|
|
194
|
+
'Runtime gateway OIDC signing key is not a PKCS#8 private key.',
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (
|
|
198
|
+
key.asymmetricKeyType !== 'rsa' ||
|
|
199
|
+
(key.asymmetricKeyDetails?.modulusLength ?? 0) < 2048
|
|
200
|
+
) {
|
|
201
|
+
throw new RuntimeGatewayOidcError(
|
|
202
|
+
'signing_key_invalid',
|
|
203
|
+
'Runtime gateway OIDC signing key must be RSA with at least 2048 bits.',
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return key;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function encodeSegment(value: object): string {
|
|
210
|
+
return Buffer.from(JSON.stringify(value)).toString('base64url');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Refuse to sign unless `kid` is published for this environment and the
|
|
215
|
+
* private key's public half is exactly that published key. A wrong or
|
|
216
|
+
* stale secret fails here, loudly, instead of minting tokens every gateway
|
|
217
|
+
* rejects.
|
|
218
|
+
*/
|
|
219
|
+
function assertSigningKeyPublished(
|
|
220
|
+
signingKey: RuntimeGatewayOidcSigningKey,
|
|
221
|
+
key: KeyObject,
|
|
222
|
+
environment: RuntimeGatewayOidcEnvironment,
|
|
223
|
+
trust: RuntimeGatewayOidcTrust,
|
|
224
|
+
): void {
|
|
225
|
+
const published = environmentJwk(trust, environment, signingKey.kid);
|
|
226
|
+
if (!published) {
|
|
227
|
+
throw new RuntimeGatewayOidcError(
|
|
228
|
+
'signing_key_not_published',
|
|
229
|
+
`${RUNTIME_GATEWAY_OIDC_KID_ENV} "${signingKey.kid}" is not a published ${environment} Runtime gateway OIDC key id (published for ${environment}: ${trust.environmentKids[environment].join(', ') || 'none'}).`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
const derived = createPublicKey(key).export({ format: 'jwk' });
|
|
233
|
+
if (derived.n !== published.n || derived.e !== published.e) {
|
|
234
|
+
throw new RuntimeGatewayOidcError(
|
|
235
|
+
'signing_key_not_published',
|
|
236
|
+
`${RUNTIME_GATEWAY_OIDC_PRIVATE_KEY_ENV} does not match the published ${environment} key "${signingKey.kid}".`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function mintRuntimeGatewayOidcToken(input: {
|
|
242
|
+
signingKey: RuntimeGatewayOidcSigningKey;
|
|
243
|
+
deploymentId: string;
|
|
244
|
+
runId: string;
|
|
245
|
+
attempt: number;
|
|
246
|
+
nowMs: number;
|
|
247
|
+
/** Defaults to this process's environment. */
|
|
248
|
+
environment?: RuntimeGatewayOidcEnvironment;
|
|
249
|
+
/** Defaults to the code-owned keys. */
|
|
250
|
+
trust?: RuntimeGatewayOidcTrust;
|
|
251
|
+
}): string {
|
|
252
|
+
if (
|
|
253
|
+
!isRuntimeGatewayDeploymentId(input.deploymentId) ||
|
|
254
|
+
!input.runId.trim() ||
|
|
255
|
+
!Number.isSafeInteger(input.attempt) ||
|
|
256
|
+
input.attempt < 0 ||
|
|
257
|
+
!Number.isFinite(input.nowMs)
|
|
258
|
+
) {
|
|
259
|
+
throw new RuntimeGatewayOidcError(
|
|
260
|
+
'claims_invalid',
|
|
261
|
+
'Runtime gateway OIDC claims are invalid.',
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const environment =
|
|
265
|
+
input.environment ?? resolveRuntimeGatewayOidcEnvironment();
|
|
266
|
+
const key = rsaPrivateKey(input.signingKey);
|
|
267
|
+
assertSigningKeyPublished(
|
|
268
|
+
input.signingKey,
|
|
269
|
+
key,
|
|
270
|
+
environment,
|
|
271
|
+
input.trust ?? RUNTIME_GATEWAY_OIDC_TRUST,
|
|
272
|
+
);
|
|
273
|
+
const iat = Math.floor(input.nowMs / 1_000);
|
|
274
|
+
const claims: RuntimeGatewayOidcClaims = {
|
|
275
|
+
iss: RUNTIME_GATEWAY_OIDC_ISSUER,
|
|
276
|
+
aud: RUNTIME_GATEWAY_OIDC_AUDIENCE,
|
|
277
|
+
sub: RUNTIME_GATEWAY_OIDC_SUBJECT,
|
|
278
|
+
deployment_id: input.deploymentId,
|
|
279
|
+
run_id: input.runId,
|
|
280
|
+
run_attempt: input.attempt,
|
|
281
|
+
deepline_env: environment,
|
|
282
|
+
iat,
|
|
283
|
+
exp: iat + RUNTIME_GATEWAY_OIDC_MAX_AGE_SECONDS,
|
|
284
|
+
};
|
|
285
|
+
const signingInput = `${encodeSegment({
|
|
286
|
+
alg: 'RS256',
|
|
287
|
+
kid: input.signingKey.kid,
|
|
288
|
+
typ: 'JWT',
|
|
289
|
+
})}.${encodeSegment(claims)}`;
|
|
290
|
+
const signature = sign('RSA-SHA256', Buffer.from(signingInput), key);
|
|
291
|
+
return `${signingInput}.${signature.toString('base64url')}`;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function decodeSegment(segment: string): Record<string, unknown> | null {
|
|
295
|
+
try {
|
|
296
|
+
const value = JSON.parse(Buffer.from(segment, 'base64url').toString());
|
|
297
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
298
|
+
? (value as Record<string, unknown>)
|
|
299
|
+
: null;
|
|
300
|
+
} catch {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function isTokenShape(token: unknown): token is string {
|
|
306
|
+
return (
|
|
307
|
+
typeof token === 'string' &&
|
|
308
|
+
token.length <= RUNTIME_GATEWAY_OIDC_MAX_TOKEN_LENGTH &&
|
|
309
|
+
/^[\w-]+\.[\w-]+\.[\w-]+$/.test(token)
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Unverified claim read for schedulers deciding when to renew. */
|
|
314
|
+
export function readRuntimeGatewayOidcClaimsUnverified(
|
|
315
|
+
token: unknown,
|
|
316
|
+
): RuntimeGatewayOidcClaims | null {
|
|
317
|
+
if (!isTokenShape(token)) return null;
|
|
318
|
+
const claims = decodeSegment(token.split('.')[1]!);
|
|
319
|
+
return claims && isClaimsShape(claims) ? claims : null;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function isClaimsShape(
|
|
323
|
+
claims: Record<string, unknown>,
|
|
324
|
+
): claims is RuntimeGatewayOidcClaims {
|
|
325
|
+
return (
|
|
326
|
+
typeof claims.iss === 'string' &&
|
|
327
|
+
typeof claims.aud === 'string' &&
|
|
328
|
+
typeof claims.sub === 'string' &&
|
|
329
|
+
typeof claims.deployment_id === 'string' &&
|
|
330
|
+
typeof claims.run_id === 'string' &&
|
|
331
|
+
Number.isSafeInteger(claims.run_attempt) &&
|
|
332
|
+
(claims.deepline_env === 'preview' ||
|
|
333
|
+
claims.deepline_env === 'production') &&
|
|
334
|
+
Number.isSafeInteger(claims.iat) &&
|
|
335
|
+
Number.isSafeInteger(claims.exp)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export type RuntimeGatewayOidcVerification =
|
|
340
|
+
| { ok: true; claims: RuntimeGatewayOidcClaims }
|
|
341
|
+
| {
|
|
342
|
+
ok: false;
|
|
343
|
+
reason:
|
|
344
|
+
| 'malformed'
|
|
345
|
+
| 'unknown_key'
|
|
346
|
+
| 'bad_signature'
|
|
347
|
+
| 'wrong_issuer'
|
|
348
|
+
| 'wrong_audience'
|
|
349
|
+
| 'wrong_subject'
|
|
350
|
+
| 'wrong_scope'
|
|
351
|
+
| 'wrong_environment'
|
|
352
|
+
| 'expired'
|
|
353
|
+
| 'not_yet_valid'
|
|
354
|
+
| 'lifetime_too_long';
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Verify a token for one exact deployment, run and attempt, in this
|
|
359
|
+
* deployment's environment: the kid must be one this environment trusts and
|
|
360
|
+
* the `deepline_env` claim must name it. `environment` defaults to this
|
|
361
|
+
* process's; `trust` defaults to the code-owned keys.
|
|
362
|
+
*/
|
|
363
|
+
export function verifyRuntimeGatewayOidcToken(
|
|
364
|
+
token: unknown,
|
|
365
|
+
expected: { deploymentId: string; runId: string; attempt: number },
|
|
366
|
+
options: {
|
|
367
|
+
nowMs?: number;
|
|
368
|
+
environment?: RuntimeGatewayOidcEnvironment;
|
|
369
|
+
trust?: RuntimeGatewayOidcTrust;
|
|
370
|
+
} = {},
|
|
371
|
+
): RuntimeGatewayOidcVerification {
|
|
372
|
+
if (!isTokenShape(token)) return { ok: false, reason: 'malformed' };
|
|
373
|
+
const [headerPart, claimsPart, signaturePart] = token.split('.') as [
|
|
374
|
+
string,
|
|
375
|
+
string,
|
|
376
|
+
string,
|
|
377
|
+
];
|
|
378
|
+
const header = decodeSegment(headerPart);
|
|
379
|
+
const claims = decodeSegment(claimsPart);
|
|
380
|
+
if (
|
|
381
|
+
!header ||
|
|
382
|
+
!claims ||
|
|
383
|
+
header.alg !== 'RS256' ||
|
|
384
|
+
typeof header.kid !== 'string' ||
|
|
385
|
+
!isClaimsShape(claims)
|
|
386
|
+
) {
|
|
387
|
+
return { ok: false, reason: 'malformed' };
|
|
388
|
+
}
|
|
389
|
+
const environment =
|
|
390
|
+
options.environment ?? resolveRuntimeGatewayOidcEnvironment();
|
|
391
|
+
const jwk = environmentJwk(
|
|
392
|
+
options.trust ?? RUNTIME_GATEWAY_OIDC_TRUST,
|
|
393
|
+
environment,
|
|
394
|
+
header.kid,
|
|
395
|
+
);
|
|
396
|
+
if (!jwk) return { ok: false, reason: 'unknown_key' };
|
|
397
|
+
let signatureValid = false;
|
|
398
|
+
try {
|
|
399
|
+
signatureValid = verify(
|
|
400
|
+
'RSA-SHA256',
|
|
401
|
+
Buffer.from(`${headerPart}.${claimsPart}`),
|
|
402
|
+
createPublicKey({ key: jwk as JsonWebKey, format: 'jwk' }),
|
|
403
|
+
Buffer.from(signaturePart, 'base64url'),
|
|
404
|
+
);
|
|
405
|
+
} catch {
|
|
406
|
+
signatureValid = false;
|
|
407
|
+
}
|
|
408
|
+
if (!signatureValid) return { ok: false, reason: 'bad_signature' };
|
|
409
|
+
if (claims.iss !== RUNTIME_GATEWAY_OIDC_ISSUER)
|
|
410
|
+
return { ok: false, reason: 'wrong_issuer' };
|
|
411
|
+
if (claims.aud !== RUNTIME_GATEWAY_OIDC_AUDIENCE)
|
|
412
|
+
return { ok: false, reason: 'wrong_audience' };
|
|
413
|
+
if (claims.sub !== RUNTIME_GATEWAY_OIDC_SUBJECT)
|
|
414
|
+
return { ok: false, reason: 'wrong_subject' };
|
|
415
|
+
if (
|
|
416
|
+
claims.deployment_id !== expected.deploymentId ||
|
|
417
|
+
claims.run_id !== expected.runId ||
|
|
418
|
+
claims.run_attempt !== expected.attempt
|
|
419
|
+
) {
|
|
420
|
+
return { ok: false, reason: 'wrong_scope' };
|
|
421
|
+
}
|
|
422
|
+
if (claims.deepline_env !== environment)
|
|
423
|
+
return { ok: false, reason: 'wrong_environment' };
|
|
424
|
+
if (claims.exp - claims.iat > RUNTIME_GATEWAY_OIDC_MAX_AGE_SECONDS)
|
|
425
|
+
return { ok: false, reason: 'lifetime_too_long' };
|
|
426
|
+
const now = Math.floor((options.nowMs ?? Date.now()) / 1_000);
|
|
427
|
+
if (claims.iat > now + RUNTIME_GATEWAY_OIDC_CLOCK_SKEW_SECONDS)
|
|
428
|
+
return { ok: false, reason: 'not_yet_valid' };
|
|
429
|
+
if (claims.exp <= now) return { ok: false, reason: 'expired' };
|
|
430
|
+
return { ok: true, claims };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** Discovery document served at `${ISSUER}/.well-known/openid-configuration`. */
|
|
434
|
+
export function runtimeGatewayOidcDiscoveryDocument(): Readonly<{
|
|
435
|
+
issuer: string;
|
|
436
|
+
jwks_uri: string;
|
|
437
|
+
subject_types_supported: readonly string[];
|
|
438
|
+
id_token_signing_alg_values_supported: readonly string[];
|
|
439
|
+
response_types_supported: readonly string[];
|
|
440
|
+
claims_supported: readonly string[];
|
|
441
|
+
}> {
|
|
442
|
+
return {
|
|
443
|
+
issuer: RUNTIME_GATEWAY_OIDC_ISSUER,
|
|
444
|
+
jwks_uri: `${RUNTIME_GATEWAY_OIDC_ISSUER}${RUNTIME_GATEWAY_OIDC_JWKS_PATH}`,
|
|
445
|
+
subject_types_supported: ['public'],
|
|
446
|
+
id_token_signing_alg_values_supported: ['RS256'],
|
|
447
|
+
response_types_supported: ['id_token'],
|
|
448
|
+
claims_supported: [
|
|
449
|
+
'iss',
|
|
450
|
+
'aud',
|
|
451
|
+
'sub',
|
|
452
|
+
'iat',
|
|
453
|
+
'exp',
|
|
454
|
+
'deployment_id',
|
|
455
|
+
'run_id',
|
|
456
|
+
'run_attempt',
|
|
457
|
+
'deepline_env',
|
|
458
|
+
],
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** True once a token is old enough that the watchdog should renew it. */
|
|
463
|
+
export function shouldRenewRuntimeGatewayOidcToken(
|
|
464
|
+
token: unknown,
|
|
465
|
+
nowMs: number,
|
|
466
|
+
): boolean {
|
|
467
|
+
const claims = readRuntimeGatewayOidcClaimsUnverified(token);
|
|
468
|
+
if (!claims) return true;
|
|
469
|
+
return nowMs / 1_000 >= claims.iat + RUNTIME_GATEWAY_OIDC_RENEW_AFTER_SECONDS;
|
|
470
|
+
}
|