@tangle-network/cli-agent-registry 0.15.31 → 0.15.33
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/{backend-types-BZoSzUzQ.d.mts → backend-types-DRmLR1e0.d.mts} +1 -1
- package/dist/backend-types.d.mts +1 -1
- package/dist/{cli-auth-bundle-DcxhAW23.mjs → cli-auth-bundle-B4SGUcYM.mjs} +26 -27
- package/dist/cli-auth-bundle.d.mts +240 -2
- package/dist/cli-auth-bundle.mjs +2 -2
- package/dist/cli-auth-placeholder.d.mts +138 -6
- package/dist/cli-auth-placeholder.mjs +202 -44
- package/dist/cli-backend-auth-env.mjs +12 -202
- package/dist/default-backend.d.mts +1 -1
- package/dist/default-backend.mjs +1 -1
- package/dist/harness-Dn0LC8Pe.mjs +346 -0
- package/dist/host-contracts.d.mts +2 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/local-cli-auth.d.mts +1 -1
- package/dist/local-cli-auth.mjs +1 -1
- package/dist/native-session-contracts.d.mts +1 -1
- package/dist/public-profile-request-BwBfLgGv.d.mts +17 -0
- package/dist/servable-models.mjs +1 -1
- package/dist/{session-contract-IJy6T_nD.d.mts → session-contract-Cx8ziXIJ.d.mts} +1 -1
- package/dist/session-contract.d.mts +1 -1
- package/dist/{spec-BJnoebFr.d.mts → spec-Br00Ybw5.d.mts} +2 -2
- package/dist/specs-CStHlNhB.d.mts +84 -0
- package/dist/{specs-D_iuiC3T.mjs → specs-CZ6eAF6G.mjs} +47 -9
- package/dist/specs.d.mts +4 -72
- package/dist/specs.mjs +2 -2
- package/package.json +6 -5
- package/dist/cli-auth-bundle-BIABHp5D.d.mts +0 -51
|
@@ -1,6 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as cliAuthFilesSchema, c as materializeCliAuthBundle, d as resolveCliAuthReference, f as cliAuthReferenceSchema, o as cliAuthObjectSchema, r as assertCliAuthReferenceSupported, t as AUTH_BUNDLE_PATHS, u as parseCliAuthJson } from "./cli-auth-bundle-B4SGUcYM.mjs";
|
|
2
|
+
import { r as proxySecretMaterializationsSchema } from "./harness-Dn0LC8Pe.mjs";
|
|
2
3
|
import { z } from "zod";
|
|
4
|
+
import { decodeJwt } from "jose";
|
|
5
|
+
//#region src/native-cli-auth-metadata.ts
|
|
6
|
+
const nativeAnnotation = z.strictObject({
|
|
7
|
+
harness: z.enum(["codex", "claude-code"]),
|
|
8
|
+
cliAuth: cliAuthReferenceSchema,
|
|
9
|
+
component: z.enum(["access", "account"])
|
|
10
|
+
}).refine(({ harness, component }) => harness === "codex" || component === "access");
|
|
11
|
+
function invalidMaterial() {
|
|
12
|
+
throw new Error("Unsupported or invalid native credential material");
|
|
13
|
+
}
|
|
14
|
+
function read(schema, raw) {
|
|
15
|
+
const parsed = schema.safeParse(raw);
|
|
16
|
+
return parsed.success ? parsed.data : invalidMaterial();
|
|
17
|
+
}
|
|
18
|
+
/** Sole decoder of the private annotation; it grants no source or scope authority. */
|
|
19
|
+
function decodeNativeCliAuthAnnotation(raw) {
|
|
20
|
+
if (raw === void 0) return void 0;
|
|
21
|
+
return read(nativeAnnotation, raw);
|
|
22
|
+
}
|
|
23
|
+
function selectedComponents(materials) {
|
|
24
|
+
const components = read(proxySecretMaterializationsSchema, materials);
|
|
25
|
+
const access = components.find((entry) => entry.grant.presentation.type === "bearer");
|
|
26
|
+
const account = components.find((entry) => entry.grant.presentation.type === "header" && entry.grant.presentation.name.toLowerCase() === "chatgpt-account-id");
|
|
27
|
+
const annotation = decodeNativeCliAuthAnnotation(access?.native);
|
|
28
|
+
if (!access || !annotation || components.length !== (account ? 2 : 1) || annotation.harness === "codex" && (!account || access.grant.placeholderFormat !== "jwt")) return invalidMaterial();
|
|
29
|
+
const context = (entry) => {
|
|
30
|
+
const native = decodeNativeCliAuthAnnotation(entry.native);
|
|
31
|
+
if (!native || native.component !== (entry === access ? "access" : "account")) return invalidMaterial();
|
|
32
|
+
const { grant } = entry;
|
|
33
|
+
return JSON.stringify([
|
|
34
|
+
native.harness,
|
|
35
|
+
native.cliAuth,
|
|
36
|
+
entry.issuerExpiresAt,
|
|
37
|
+
entry.executionExpiresAt,
|
|
38
|
+
grant.identity,
|
|
39
|
+
grant.scope,
|
|
40
|
+
grant.issuedAt,
|
|
41
|
+
grant.expiresAt
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
const authority = context(access);
|
|
45
|
+
if (components.some((entry) => context(entry) !== authority)) return invalidMaterial();
|
|
46
|
+
return {
|
|
47
|
+
access,
|
|
48
|
+
account,
|
|
49
|
+
annotation
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
3
53
|
//#region src/cli-auth-placeholder.ts
|
|
54
|
+
const MAX_NATIVE_CLI_AUTH_MATERIAL_BYTES = 1024 * 1024;
|
|
4
55
|
const token = z.string().min(8).max(64 * 1024).regex(/^[^\s\0]+$/);
|
|
5
56
|
const codexBundle = z.object({ tokens: z.object({
|
|
6
57
|
access_token: token,
|
|
@@ -12,9 +63,6 @@ const jwtHeader = btoa(JSON.stringify({
|
|
|
12
63
|
typ: "JWT"
|
|
13
64
|
}));
|
|
14
65
|
const placeholderPattern = new RegExp(`^(?:proxy-declared-\\d+-token-|${jwtHeader}\\.[\\w-]+\\.)[\\w-]{43}$`);
|
|
15
|
-
function invalidMaterial() {
|
|
16
|
-
throw new Error("Unsupported or invalid native credential material");
|
|
17
|
-
}
|
|
18
66
|
const ACCOUNT_HEADER = "ChatGPT-Account-Id";
|
|
19
67
|
const isAccountHeader = (presentation) => presentation.type === "header" && presentation.name.toLowerCase() === ACCOUNT_HEADER.toLowerCase();
|
|
20
68
|
/** The box env name that holds a Codex seat's account-id placeholder. */
|
|
@@ -84,53 +132,163 @@ function nativeProxyValue(raw, presentation) {
|
|
|
84
132
|
if (!bundle) return isAccountHeader(presentation) ? void 0 : raw;
|
|
85
133
|
return presentation.type === "bearer" ? bundle.access : presentation.type === "header" ? bundle.account : void 0;
|
|
86
134
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
const identity = z.string().min(1).max(256);
|
|
136
|
+
const expiry = z.number().int().positive().max(864e13);
|
|
137
|
+
const scopes = z.array(z.string().regex(/^[\x21\x23-\x5b\x5d-\x7e]+$/));
|
|
138
|
+
const rotationSchema = z.strictObject({
|
|
139
|
+
accessToken: token,
|
|
140
|
+
refreshToken: token.optional(),
|
|
141
|
+
idToken: token.optional(),
|
|
142
|
+
expiresAt: expiry.optional(),
|
|
143
|
+
scopes: scopes.optional()
|
|
144
|
+
});
|
|
145
|
+
const fieldsSchema = rotationSchema.extend({
|
|
146
|
+
refreshToken: z.union([
|
|
147
|
+
token,
|
|
148
|
+
z.literal(""),
|
|
149
|
+
z.null()
|
|
150
|
+
]).optional(),
|
|
151
|
+
expiresAt: expiry.nullable().optional(),
|
|
152
|
+
accountId: identity.nullable().optional(),
|
|
153
|
+
clientId: identity.regex(/^[\x21-\x7e]+$/).optional(),
|
|
154
|
+
oauthProvenance: z.object({
|
|
155
|
+
issuer: z.url(),
|
|
156
|
+
client_id: identity.regex(/^[\x21-\x7e]+$/)
|
|
157
|
+
}).nullish()
|
|
158
|
+
});
|
|
159
|
+
const providers = {
|
|
160
|
+
codex: {
|
|
161
|
+
accessToken: "access_token",
|
|
162
|
+
refreshToken: "refresh_token",
|
|
163
|
+
idToken: "id_token",
|
|
164
|
+
accountId: "account_id",
|
|
165
|
+
oauthProvenance: "oauth_provenance"
|
|
166
|
+
},
|
|
167
|
+
"claude-code": {
|
|
168
|
+
accessToken: "accessToken",
|
|
169
|
+
refreshToken: "refreshToken",
|
|
170
|
+
expiresAt: "expiresAt",
|
|
171
|
+
scopes: "scopes",
|
|
172
|
+
clientId: "clientId"
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function jwtClaims(raw) {
|
|
176
|
+
try {
|
|
177
|
+
if (raw.split(".").some((part) => !part)) return invalidMaterial();
|
|
178
|
+
return decodeJwt(raw);
|
|
179
|
+
} catch {
|
|
180
|
+
return invalidMaterial();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function credentials(harness, fields, names) {
|
|
184
|
+
const value = read(fieldsSchema, Object.fromEntries(Object.entries(names).map(([name, key]) => [name, fields[key]])));
|
|
185
|
+
let accountId = value.accountId ?? void 0;
|
|
186
|
+
let expiresAt = value.expiresAt ?? void 0;
|
|
187
|
+
if (harness === "codex") {
|
|
188
|
+
const claims = read(z.object({ chatgpt_account_id: identity.optional() }), jwtClaims(value.idToken ?? invalidMaterial())["https://api.openai.com/auth"] ?? {});
|
|
189
|
+
if (accountId && claims.chatgpt_account_id && accountId !== claims.chatgpt_account_id) return invalidMaterial();
|
|
190
|
+
accountId ??= claims.chatgpt_account_id;
|
|
191
|
+
const exp = value.accessToken.split(".").length === 3 ? jwtClaims(value.accessToken).exp : void 0;
|
|
192
|
+
if (exp !== void 0) expiresAt = read(expiry, read(expiry, exp) * 1e3);
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
accessToken: value.accessToken,
|
|
196
|
+
accountId,
|
|
197
|
+
refreshToken: value.refreshToken || void 0,
|
|
198
|
+
expiresAt,
|
|
199
|
+
refreshParameters: {
|
|
200
|
+
scopes: value.scopes,
|
|
201
|
+
clientId: value.oauthProvenance?.client_id ?? value.clientId,
|
|
202
|
+
issuer: value.oauthProvenance?.issuer
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/** TRUSTED HOLDER ONLY. All returned values, including rotatedBundle, stay outside the Box. */
|
|
207
|
+
function parseNativeCliAuthMaterial(input) {
|
|
208
|
+
if (input.secretValue.length > 1048576) return invalidMaterial();
|
|
209
|
+
const material = resolveCliAuthReference(input.harness, { cliAuth: input.cliAuth }, { [input.cliAuth.secretEnv]: input.secretValue });
|
|
210
|
+
if (!material) return invalidMaterial();
|
|
211
|
+
const rotation = input.rotation === void 0 ? void 0 : read(rotationSchema, input.rotation);
|
|
212
|
+
const tokenOnly = material.reference.format === "token";
|
|
213
|
+
const files = material.authFiles.filter((file) => file.path === AUTH_BUNDLE_PATHS[input.harness]);
|
|
214
|
+
const file = files.length === 1 ? files[0] : void 0;
|
|
215
|
+
const bundle = tokenOnly ? {} : parseCliAuthJson(file?.content ?? invalidMaterial(), "Unsupported or invalid native credential material", cliAuthObjectSchema);
|
|
216
|
+
const root = input.harness === "codex" ? "tokens" : "claudeAiOauth";
|
|
217
|
+
const names = tokenOnly ? { accessToken: "accessToken" } : providers[input.harness];
|
|
218
|
+
const value = tokenOnly ? { accessToken: Object.values(material.tokenEnvironment)[0] } : read(cliAuthObjectSchema, bundle[root]);
|
|
219
|
+
bundle[root] = value;
|
|
220
|
+
const original = credentials(input.harness, value, names);
|
|
221
|
+
if (!rotation) return {
|
|
222
|
+
...original,
|
|
223
|
+
rotatedBundle: input.secretValue
|
|
224
|
+
};
|
|
225
|
+
for (const [key, replacement] of Object.entries(rotation)) {
|
|
226
|
+
if (replacement === void 0) continue;
|
|
227
|
+
if (input.harness === "codex" && key === "expiresAt") continue;
|
|
228
|
+
const name = names[key];
|
|
229
|
+
if (!name) return invalidMaterial();
|
|
230
|
+
value[name] = key === "scopes" ? original.refreshParameters.scopes?.filter((scope) => rotation.scopes?.includes(scope)) ?? [] : replacement;
|
|
231
|
+
}
|
|
232
|
+
const next = credentials(input.harness, value, names);
|
|
233
|
+
if (next.accountId !== original.accountId) return invalidMaterial();
|
|
234
|
+
if (rotation.expiresAt !== void 0) next.expiresAt = Math.min(rotation.expiresAt, next.expiresAt ?? rotation.expiresAt);
|
|
235
|
+
if (file) file.content = JSON.stringify(bundle);
|
|
236
|
+
return {
|
|
237
|
+
...next,
|
|
238
|
+
rotatedBundle: tokenOnly ? next.accessToken : input.cliAuth.format === "bundle" ? file?.content ?? invalidMaterial() : JSON.stringify(material.authFiles)
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function placeholderFiles(harness, access, account, issuedAt, expiresAt, idToken = access) {
|
|
242
|
+
if (harness !== "codex" && harness !== "claude-code") return invalidMaterial();
|
|
243
|
+
const content = harness === "codex" ? {
|
|
244
|
+
auth_mode: "chatgpt",
|
|
245
|
+
OPENAI_API_KEY: null,
|
|
246
|
+
tokens: {
|
|
247
|
+
id_token: idToken,
|
|
248
|
+
access_token: access,
|
|
249
|
+
refresh_token: "",
|
|
250
|
+
...account ? { account_id: account } : {}
|
|
251
|
+
},
|
|
252
|
+
last_refresh: issuedAt
|
|
253
|
+
} : { claudeAiOauth: {
|
|
115
254
|
accessToken: access,
|
|
116
255
|
refreshToken: null,
|
|
117
|
-
expiresAt
|
|
256
|
+
expiresAt,
|
|
118
257
|
scopes: ["user:inference"],
|
|
119
258
|
subscriptionType: null,
|
|
120
259
|
rateLimitTier: null
|
|
121
260
|
} };
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
261
|
+
return materializeCliAuthBundle(harness, JSON.stringify(content));
|
|
262
|
+
}
|
|
263
|
+
/** One fake-file renderer serves the existing PH bootstrap and protected full snapshot. */
|
|
264
|
+
function buildCliAuthPlaceholderMaterial(input) {
|
|
265
|
+
if ("backendType" in input) {
|
|
266
|
+
const reference = assertCliAuthReferenceSupported(input.backendType, { cliAuth: input.reference });
|
|
267
|
+
const { access, account } = input.placeholders;
|
|
268
|
+
if (!reference || !isCliAuthPlaceholder(access) || account !== void 0 && !isCliAuthPlaceholder(account) || !Number.isFinite(input.now.getTime())) return invalidMaterial();
|
|
269
|
+
if (input.backendType === "claude-code" && reference.format === "token") return resolveCliAuthReference(input.backendType, { cliAuth: reference }, { [reference.secretEnv]: access }) ?? invalidMaterial();
|
|
270
|
+
let idToken = access;
|
|
271
|
+
if (input.backendType === "codex") {
|
|
272
|
+
const payload = access.split(".")[1];
|
|
273
|
+
if (!payload) return invalidMaterial();
|
|
274
|
+
const base64 = payload.replaceAll("-", "+").replaceAll("_", "/");
|
|
275
|
+
const { exp } = read(z.object({ exp: z.number().int().positive() }), JSON.parse(atob(base64)));
|
|
276
|
+
idToken = `e30.${btoa(JSON.stringify({
|
|
277
|
+
sub: "sandbox-placeholder",
|
|
278
|
+
aud: "tangle-sandbox",
|
|
279
|
+
exp
|
|
280
|
+
})).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "")}.tangle-placeholder`;
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
reference,
|
|
284
|
+
authFiles: placeholderFiles(input.backendType, access, account, input.now.toISOString(), null, idToken),
|
|
285
|
+
tokenEnvironment: {}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const { access, account, annotation } = selectedComponents(input);
|
|
289
|
+
return placeholderFiles(annotation.harness, access.placeholder, account?.placeholder, access.grant.issuedAt, Date.parse(access.grant.expiresAt));
|
|
132
290
|
}
|
|
133
291
|
//#endregion
|
|
134
|
-
export { buildCliAuthPlaceholderMaterial, isCliAuthPlaceholder, nativeAccountEnv, nativeProxyBindings, nativeProxyValue };
|
|
292
|
+
export { MAX_NATIVE_CLI_AUTH_MATERIAL_BYTES, buildCliAuthPlaceholderMaterial, decodeNativeCliAuthAnnotation, isCliAuthPlaceholder, nativeAccountEnv, nativeProxyBindings, nativeProxyValue, parseNativeCliAuthMaterial };
|
|
135
293
|
|
|
136
294
|
//# sourceMappingURL=cli-auth-placeholder.mjs.map
|
|
@@ -1,219 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ProxySecretBindingSchema, ProxySecretGrantSchema, ProxySecretReceiptSchema, ProxySecretUpdateControlsSchema, ProxySecretsSchema, isProxySecretScopeAttenuation, ownPropertyRecordSchema, proxySecretPresentationsEqual } from "@tangle-network/agent-interface";
|
|
1
|
+
import { l as getSpec } from "./specs-CZ6eAF6G.mjs";
|
|
2
|
+
import { a as cliAuthFilesSchema, d as resolveCliAuthReference, f as cliAuthReferenceSchema, n as CLI_AUTH_REFERENCE_ENV_VAR, u as parseCliAuthJson } from "./cli-auth-bundle-B4SGUcYM.mjs";
|
|
3
|
+
import { n as isSafeEnvVarName, t as isForbiddenEnvVarName } from "./harness-Dn0LC8Pe.mjs";
|
|
5
4
|
import { z } from "zod";
|
|
6
|
-
//#region ../runtime-contracts/dist/model-key-proxy.js
|
|
7
|
-
const MODEL_PROXY_TOKENS = {
|
|
8
|
-
OPENCODE_MODEL_API_KEY: "proxy-model-token",
|
|
9
|
-
OPENAI_API_KEY: "proxy-openai-token",
|
|
10
|
-
ANTHROPIC_API_KEY: "proxy-anthropic-token",
|
|
11
|
-
OPENROUTER_API_KEY: "proxy-openrouter-token",
|
|
12
|
-
TANGLE_INFERENCE_KEY: "proxy-openai-token",
|
|
13
|
-
ZAI_API_KEY: "proxy-zai-token",
|
|
14
|
-
ZHIPU_API_KEY: "proxy-zai-token"
|
|
15
|
-
};
|
|
16
|
-
new Set(Object.values(MODEL_PROXY_TOKENS));
|
|
17
|
-
new Set([
|
|
18
|
-
...Object.keys(MODEL_PROXY_TOKENS),
|
|
19
|
-
"TANGLE_API_KEY",
|
|
20
|
-
"GITHUB_TOKEN",
|
|
21
|
-
"GH_TOKEN"
|
|
22
|
-
]);
|
|
23
|
-
/** True for a slot name, which exists at the proxy and never in a box env. */
|
|
24
|
-
function isDeclaredSecretSlotEnvVar(name) {
|
|
25
|
-
return /^TANGLE_DECLARED_SLOT_\d+$/.test(name);
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region ../runtime-contracts/dist/proxy-secret-materialization.js
|
|
29
|
-
const syntheticHeader = {
|
|
30
|
-
alg: "HS256",
|
|
31
|
-
typ: "JWT"
|
|
32
|
-
};
|
|
33
|
-
const encode = (value) => btoa(value instanceof Uint8Array ? String.fromCharCode(...value) : JSON.stringify(value)).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
34
|
-
function placeholderPrefix(slot, format, expiresAt) {
|
|
35
|
-
return format === "jwt" ? `${encode(syntheticHeader)}.${encode({
|
|
36
|
-
sub: "sandbox-placeholder",
|
|
37
|
-
aud: "proxy-secret-placeholder",
|
|
38
|
-
exp: Math.floor(Date.parse(expiresAt) / 1e3)
|
|
39
|
-
})}.` : `proxy-declared-${slot.slice(21)}-token-`;
|
|
40
|
-
}
|
|
41
|
-
function isSyntheticPlaceholder(material) {
|
|
42
|
-
const prefix = placeholderPrefix(material.slot, material.grant.placeholderFormat, material.issuerExpiresAt);
|
|
43
|
-
return material.placeholder.startsWith(prefix) && /^[A-Za-z0-9_-]{43}$/.test(material.placeholder.slice(prefix.length));
|
|
44
|
-
}
|
|
45
|
-
z.array(z.strictObject({
|
|
46
|
-
binding: ProxySecretBindingSchema,
|
|
47
|
-
grant: ProxySecretGrantSchema,
|
|
48
|
-
placeholder: z.string().min(1),
|
|
49
|
-
slot: z.string().refine(isDeclaredSecretSlotEnvVar),
|
|
50
|
-
issuerExpiresAt: z.iso.datetime()
|
|
51
|
-
})).superRefine((materials, ctx) => {
|
|
52
|
-
const bindings = ProxySecretsSchema.safeParse(materials.map((m) => m.binding));
|
|
53
|
-
const unique = (values) => new Set(values).size === values.length;
|
|
54
|
-
if (!bindings.success || !unique(materials.map((m) => m.slot)) || !unique(materials.map((m) => m.placeholder)) || !unique(materials.map((m) => m.grant.grantId)) || new Set(materials.map((m) => m.grant.epoch)).size > 1 || new Set(materials.map((m) => m.grant.sandboxId)).size > 1 || materials.some((material) => !isSyntheticPlaceholder(material)) || materials.some(({ binding, grant, issuerExpiresAt }) => !isProxySecretScopeAttenuation(binding, grant.scope) || !proxySecretPresentationsEqual(binding.presentation, grant.presentation) || (binding.placeholderFormat ?? "opaque") !== grant.placeholderFormat || Date.parse(grant.expiresAt) > Date.parse(issuerExpiresAt))) ctx.addIssue({
|
|
55
|
-
code: "custom",
|
|
56
|
-
message: "Invalid proxy secret materialization"
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
ProxySecretUpdateControlsSchema.extend({
|
|
60
|
-
resolvedSecrets: ownPropertyRecordSchema(z.string().min(1), { maxEntries: Number.MAX_SAFE_INTEGER }).default({}),
|
|
61
|
-
proxySecretGrants: ProxySecretReceiptSchema.options[0].shape.bindings,
|
|
62
|
-
expectedProxySecretGeneration: ProxySecretUpdateControlsSchema.shape.expectedProxySecretGeneration.unwrap()
|
|
63
|
-
}).strict().refine((body) => new Set(body.proxySecretGrants.map((b) => b.envName)).size === body.proxySecretGrants.length);
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region ../runtime-contracts/dist/runtime-environment.js
|
|
66
|
-
const SAFE_ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
67
|
-
function isSafeEnvVarName(name) {
|
|
68
|
-
if (typeof name !== "string") return false;
|
|
69
|
-
if (name.length === 0 || name.length > 256) return false;
|
|
70
|
-
return SAFE_ENV_VAR_NAME_RE.test(name);
|
|
71
|
-
}
|
|
72
|
-
/** Client proxy URLs first, then bypass names. */
|
|
73
|
-
const EGRESS_PROXY_ENV_NAMES = [
|
|
74
|
-
"HTTPS_PROXY",
|
|
75
|
-
"https_proxy",
|
|
76
|
-
"HTTP_PROXY",
|
|
77
|
-
"http_proxy",
|
|
78
|
-
"NO_PROXY",
|
|
79
|
-
"no_proxy"
|
|
80
|
-
];
|
|
81
|
-
const CA_TRUST_ENV_NAMES = [
|
|
82
|
-
"NODE_EXTRA_CA_CERTS",
|
|
83
|
-
"SSL_CERT_FILE",
|
|
84
|
-
"CURL_CA_BUNDLE",
|
|
85
|
-
"GIT_SSL_CAINFO",
|
|
86
|
-
"NIX_SSL_CERT_FILE"
|
|
87
|
-
];
|
|
88
|
-
[...EGRESS_PROXY_ENV_NAMES, ...CA_TRUST_ENV_NAMES];
|
|
89
|
-
const FORBIDDEN_ENV_VAR_NAMES = new Set([
|
|
90
|
-
"LD_PRELOAD",
|
|
91
|
-
"LD_LIBRARY_PATH",
|
|
92
|
-
"LD_AUDIT",
|
|
93
|
-
"DYLD_INSERT_LIBRARIES",
|
|
94
|
-
"DYLD_LIBRARY_PATH",
|
|
95
|
-
"DYLD_FALLBACK_LIBRARY_PATH",
|
|
96
|
-
"NODE_OPTIONS",
|
|
97
|
-
"NODE_PATH",
|
|
98
|
-
"NODE_TLS_REJECT_UNAUTHORIZED",
|
|
99
|
-
"PYTHONPATH",
|
|
100
|
-
"PYTHONSTARTUP",
|
|
101
|
-
"PERL5OPT",
|
|
102
|
-
"PERL5LIB",
|
|
103
|
-
"RUBYOPT",
|
|
104
|
-
"RUBYLIB",
|
|
105
|
-
"PATH",
|
|
106
|
-
"NIX_BIN_PATH",
|
|
107
|
-
"EGRESS_EDGE_POOL_ENABLED",
|
|
108
|
-
"EDGE_BIND_ID",
|
|
109
|
-
"PRIVACY_EGRESS",
|
|
110
|
-
"LOG_REDACT",
|
|
111
|
-
"IFS",
|
|
112
|
-
"BASH_ENV",
|
|
113
|
-
"ENV",
|
|
114
|
-
"SHELL",
|
|
115
|
-
"SHELLOPTS",
|
|
116
|
-
"PROMPT_COMMAND",
|
|
117
|
-
"HOME",
|
|
118
|
-
"XDG_CONFIG_HOME",
|
|
119
|
-
"XDG_DATA_HOME",
|
|
120
|
-
"XDG_CACHE_HOME",
|
|
121
|
-
"XDG_STATE_HOME",
|
|
122
|
-
"XDG_RUNTIME_DIR",
|
|
123
|
-
"HTTPS_PROXY",
|
|
124
|
-
"HTTP_PROXY",
|
|
125
|
-
"ALL_PROXY",
|
|
126
|
-
"NO_PROXY",
|
|
127
|
-
"https_proxy",
|
|
128
|
-
"http_proxy",
|
|
129
|
-
"all_proxy",
|
|
130
|
-
"no_proxy",
|
|
131
|
-
"SSL_CERT_FILE",
|
|
132
|
-
"SSL_CERT_DIR",
|
|
133
|
-
"REQUESTS_CA_BUNDLE",
|
|
134
|
-
"CURL_CA_BUNDLE",
|
|
135
|
-
"NODE_EXTRA_CA_CERTS",
|
|
136
|
-
"HOSTNAME",
|
|
137
|
-
"CONTAINER_ID",
|
|
138
|
-
"AGENT_WORKSPACE_ROOT",
|
|
139
|
-
"WORKSPACE_PATH",
|
|
140
|
-
"STORAGE_PATH",
|
|
141
|
-
"WORKSPACE_FILE_API_ROOT_ONLY",
|
|
142
|
-
"WORKSPACE_ALLOWED_ABSOLUTE_PATHS",
|
|
143
|
-
"TANGLE_PLAN_CALLBACK_ALLOWED_ORIGINS"
|
|
144
|
-
]);
|
|
145
|
-
const FORBIDDEN_ENV_VAR_PREFIXES = [
|
|
146
|
-
"SIDECAR_",
|
|
147
|
-
"ORCHESTRATOR_",
|
|
148
|
-
"AGENT_INTERNAL_",
|
|
149
|
-
"SANDBOX_DEV_",
|
|
150
|
-
"AGENT_SUBPROCESS_",
|
|
151
|
-
"TEE_ATTESTATION_"
|
|
152
|
-
];
|
|
153
|
-
const RUNTIME_CALLER_ALLOWED_ENV_NAMES = new Set(["SIDECAR_CAPABILITIES", "SIDECAR_PLATFORM_CONTROL_RUNTIME"]);
|
|
154
|
-
new Set(Object.values(HARNESS_WARM_TRANSPORT_ENV).flatMap(({ warmServer, prewarm }) => [warmServer, prewarm]));
|
|
155
|
-
function isForbiddenEnvVarName(name) {
|
|
156
|
-
if (RUNTIME_CALLER_ALLOWED_ENV_NAMES.has(name)) return false;
|
|
157
|
-
if (FORBIDDEN_ENV_VAR_NAMES.has(name)) return true;
|
|
158
|
-
for (const prefix of FORBIDDEN_ENV_VAR_PREFIXES) if (name.startsWith(prefix)) return true;
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* POSIX names for caller-owned container env. Runtime process.env merges must additionally enforce
|
|
163
|
-
* isForbiddenEnvVarName, including project provisioning and Sidecar config.
|
|
164
|
-
*/
|
|
165
|
-
const safeEnvRecordSchema = ownPropertyRecordSchema(z.string(), { maxEntries: Number.MAX_SAFE_INTEGER }).refine((value) => Object.keys(value).every(isSafeEnvVarName), { message: "invalid env var name" });
|
|
166
|
-
/** Names only: the caller must keep a separate source and pass values to resume({ env }). */
|
|
167
|
-
const sandboxEnvRecoverySchema = z.object({ callerResupplies: z.array(z.string().max(256).refine(isSafeEnvVarName, { message: "invalid env var name" })).max(128).refine((keys) => new Set(keys).size === keys.length, { message: "callerResupplies must contain unique keys" }) }).strict();
|
|
168
|
-
z.object({
|
|
169
|
-
envRecovery: sandboxEnvRecoverySchema,
|
|
170
|
-
dryRun: z.boolean().optional()
|
|
171
|
-
}).strict();
|
|
172
|
-
z.object({
|
|
173
|
-
envRecovery: sandboxEnvRecoverySchema,
|
|
174
|
-
eligibleCallerResupplyKeys: z.array(z.string()),
|
|
175
|
-
requiredOnColdResumeKeys: z.array(z.string()),
|
|
176
|
-
automaticCredentialRecovery: z.literal(false),
|
|
177
|
-
dryRun: z.boolean()
|
|
178
|
-
}).strict();
|
|
179
|
-
safeEnvRecordSchema.refine((value) => Object.keys(value).every((key) => !isForbiddenEnvVarName(key) && !key.startsWith("SIDECAR_")), { message: "runtime-owned env var name cannot be set by callers" });
|
|
180
|
-
//#endregion
|
|
181
5
|
//#region src/cli-backend-auth-env.ts
|
|
182
6
|
/** The narrow credential leg shared by the host and sidecar rebind boundary. */
|
|
183
7
|
function assertCliBackendAuthEnv(backendType, authEnv) {
|
|
184
8
|
if (Object.keys(authEnv).length === 0) return;
|
|
185
9
|
const spec = backendType ? getSpec(backendType) : void 0;
|
|
186
10
|
if (!spec) throw new Error("Credential delivery requires a registered backend");
|
|
187
|
-
const allowed =
|
|
11
|
+
const allowed = [
|
|
188
12
|
spec.envVars.apiKey,
|
|
189
13
|
spec.envVars.oauthToken,
|
|
190
14
|
spec.envVars.authFiles
|
|
191
|
-
]
|
|
15
|
+
];
|
|
192
16
|
const rawReference = authEnv[CLI_AUTH_REFERENCE_ENV_VAR];
|
|
193
17
|
if (rawReference !== void 0) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
const result = cliAuthReferenceSchema.safeParse(parsed);
|
|
201
|
-
if (!result.success || !isSafeEnvVarName(result.data.secretEnv) || isForbiddenEnvVarName(result.data.secretEnv)) throw new Error("Invalid native credential reference");
|
|
202
|
-
allowed.add(CLI_AUTH_REFERENCE_ENV_VAR);
|
|
203
|
-
allowed.add(result.data.secretEnv);
|
|
204
|
-
resolveCliAuthReference(spec.name, { cliAuth: result.data }, authEnv);
|
|
18
|
+
const reference = parseCliAuthJson(rawReference, "Invalid native credential reference", cliAuthReferenceSchema);
|
|
19
|
+
if (!isSafeEnvVarName(reference.secretEnv) || isForbiddenEnvVarName(reference.secretEnv)) throw new Error("Invalid native credential reference");
|
|
20
|
+
allowed.push(CLI_AUTH_REFERENCE_ENV_VAR);
|
|
21
|
+
allowed.push(reference.secretEnv);
|
|
22
|
+
resolveCliAuthReference(spec.name, { cliAuth: reference }, authEnv);
|
|
205
23
|
}
|
|
206
|
-
for (const [name, value] of Object.entries(authEnv)) if (!allowed.
|
|
24
|
+
for (const [name, value] of Object.entries(authEnv)) if (!allowed.includes(name) || value.includes("\0")) throw new Error("Invalid backend credential environment");
|
|
207
25
|
const files = spec.envVars.authFiles && authEnv[spec.envVars.authFiles];
|
|
208
|
-
if (files !== void 0 && files !== "")
|
|
209
|
-
let parsed;
|
|
210
|
-
try {
|
|
211
|
-
parsed = JSON.parse(files);
|
|
212
|
-
} catch {
|
|
213
|
-
throw new Error("Invalid backend auth files");
|
|
214
|
-
}
|
|
215
|
-
if (!(Array.isArray(parsed) && parsed.length === 0) && !cliAuthFilesSchema.safeParse(parsed).success) throw new Error("Invalid backend auth files");
|
|
216
|
-
}
|
|
26
|
+
if (files !== void 0 && files !== "") parseCliAuthJson(files, "Invalid backend auth files", cliAuthFilesSchema.or(z.tuple([])));
|
|
217
27
|
}
|
|
218
28
|
//#endregion
|
|
219
29
|
export { assertCliBackendAuthEnv };
|
package/dist/default-backend.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as isBackendType, t as ALL_BACKEND_TYPES } from "./backend-types-CNo_Zj_K.mjs";
|
|
2
|
-
import "./specs-
|
|
2
|
+
import "./specs-CZ6eAF6G.mjs";
|
|
3
3
|
//#region src/default-backend.ts
|
|
4
4
|
/**
|
|
5
5
|
* Platform-wide default agent backend, read from `DEFAULT_AGENT_BACKEND`.
|