@hivemagnus/embermend-integrations 0.0.0-stage → 0.6.1
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +11 -2
- package/dist/github.d.ts +155 -0
- package/dist/github.js +197 -0
- package/dist/github.js.map +1 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +245 -0
- package/dist/index.js.map +1 -0
- package/dist/inference/claude.d.ts +11 -0
- package/dist/inference/claude.js +34 -0
- package/dist/inference/claude.js.map +1 -0
- package/dist/inference/codex.d.ts +11 -0
- package/dist/inference/codex.js +162 -0
- package/dist/inference/codex.js.map +1 -0
- package/dist/inference/config.d.ts +177 -0
- package/dist/inference/config.js +35 -0
- package/dist/inference/config.js.map +1 -0
- package/dist/inference/http.d.ts +14 -0
- package/dist/inference/http.js +43 -0
- package/dist/inference/http.js.map +1 -0
- package/dist/inference/index.d.ts +7 -0
- package/dist/inference/index.js +15 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/inference/process.d.ts +3 -0
- package/dist/inference/process.js +43 -0
- package/dist/inference/process.js.map +1 -0
- package/dist/oathweave-roles.d.ts +76 -0
- package/dist/oathweave-roles.js +184 -0
- package/dist/oathweave-roles.js.map +1 -0
- package/dist/registry.d.ts +43 -0
- package/dist/registry.js +203 -0
- package/dist/registry.js.map +1 -0
- package/dist/threat-feeds.d.ts +6 -0
- package/dist/threat-feeds.js +41 -0
- package/dist/threat-feeds.js.map +1 -0
- package/package.json +41 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import type { JWTVerifyGetKey } from 'jose';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type AccountLookup, type RoleScopes } from './oathweave-roles.js';
|
|
4
|
+
import { capabilitySchema, jsonObject, type Actor, type OperationRequest, type Receipt } from '@hivemagnus/embermend-contracts';
|
|
5
|
+
export declare class IntegrationError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly uncertain: boolean;
|
|
8
|
+
constructor(code: string, uncertain: boolean);
|
|
9
|
+
}
|
|
10
|
+
export declare function endpoint(value: string, allowLoopback?: boolean): URL;
|
|
11
|
+
/** `value` without trailing `/` characters, in linear time. */
|
|
12
|
+
export declare function withoutTrailingSlashes(value: string): string;
|
|
13
|
+
export declare function responseJson(response: Response): Promise<unknown>;
|
|
14
|
+
export interface Magnus {
|
|
15
|
+
capabilities(signal?: AbortSignal): Promise<z.infer<typeof capabilitySchema>>;
|
|
16
|
+
dispatch(request: OperationRequest, signal?: AbortSignal): Promise<Receipt>;
|
|
17
|
+
receipt(operationId: string, signal?: AbortSignal): Promise<Receipt>;
|
|
18
|
+
}
|
|
19
|
+
export declare class MagnusClient implements Magnus {
|
|
20
|
+
private readonly token;
|
|
21
|
+
private readonly request;
|
|
22
|
+
private readonly base;
|
|
23
|
+
constructor(base: string, token: string, request?: typeof fetch, allowLoopback?: boolean);
|
|
24
|
+
private call;
|
|
25
|
+
capabilities(signal?: AbortSignal): Promise<{
|
|
26
|
+
protocol: 1;
|
|
27
|
+
installationId: string;
|
|
28
|
+
serviceVersion: string;
|
|
29
|
+
actions: string[];
|
|
30
|
+
targets: ({
|
|
31
|
+
kind: "management-agent";
|
|
32
|
+
magnusInstallationId: string;
|
|
33
|
+
magnusAgentId: string;
|
|
34
|
+
targetIds: string[];
|
|
35
|
+
capabilities: string[];
|
|
36
|
+
version: string | null;
|
|
37
|
+
lifecycle: "unknown" | "active" | "offline" | "retired";
|
|
38
|
+
id: string;
|
|
39
|
+
scope: {
|
|
40
|
+
installationId: string;
|
|
41
|
+
applicationIds: string[];
|
|
42
|
+
targetIds: string[];
|
|
43
|
+
};
|
|
44
|
+
label: string;
|
|
45
|
+
provenance: {
|
|
46
|
+
source: string;
|
|
47
|
+
assurance: "unknown" | "established" | "inferred";
|
|
48
|
+
evidenceIds: string[];
|
|
49
|
+
observedAt: string;
|
|
50
|
+
};
|
|
51
|
+
} | {
|
|
52
|
+
kind: "application";
|
|
53
|
+
owner: string | null;
|
|
54
|
+
importance: "low" | "high" | "critical" | "normal";
|
|
55
|
+
deploymentExpectation: "unknown" | "source-only" | "deployed";
|
|
56
|
+
environments: string[];
|
|
57
|
+
id: string;
|
|
58
|
+
scope: {
|
|
59
|
+
installationId: string;
|
|
60
|
+
applicationIds: string[];
|
|
61
|
+
targetIds: string[];
|
|
62
|
+
};
|
|
63
|
+
label: string;
|
|
64
|
+
provenance: {
|
|
65
|
+
source: string;
|
|
66
|
+
assurance: "unknown" | "established" | "inferred";
|
|
67
|
+
evidenceIds: string[];
|
|
68
|
+
observedAt: string;
|
|
69
|
+
};
|
|
70
|
+
} | {
|
|
71
|
+
kind: "repository";
|
|
72
|
+
provider: "github";
|
|
73
|
+
providerInstance: string;
|
|
74
|
+
providerId: string;
|
|
75
|
+
owner: string;
|
|
76
|
+
name: string;
|
|
77
|
+
accessRevision: number;
|
|
78
|
+
id: string;
|
|
79
|
+
scope: {
|
|
80
|
+
installationId: string;
|
|
81
|
+
applicationIds: string[];
|
|
82
|
+
targetIds: string[];
|
|
83
|
+
};
|
|
84
|
+
label: string;
|
|
85
|
+
provenance: {
|
|
86
|
+
source: string;
|
|
87
|
+
assurance: "unknown" | "established" | "inferred";
|
|
88
|
+
evidenceIds: string[];
|
|
89
|
+
observedAt: string;
|
|
90
|
+
};
|
|
91
|
+
environment?: string | undefined;
|
|
92
|
+
} | {
|
|
93
|
+
kind: "source-binding";
|
|
94
|
+
repositoryId: string;
|
|
95
|
+
applicationId: string;
|
|
96
|
+
includedPaths: string[];
|
|
97
|
+
excludedPaths: string[];
|
|
98
|
+
maintainedBranches: string[];
|
|
99
|
+
buildDefinitions: string[];
|
|
100
|
+
modelPolicy: {
|
|
101
|
+
providerRefs: string[];
|
|
102
|
+
allowRemote: boolean;
|
|
103
|
+
allowExecution: boolean;
|
|
104
|
+
};
|
|
105
|
+
id: string;
|
|
106
|
+
scope: {
|
|
107
|
+
installationId: string;
|
|
108
|
+
applicationIds: string[];
|
|
109
|
+
targetIds: string[];
|
|
110
|
+
};
|
|
111
|
+
label: string;
|
|
112
|
+
provenance: {
|
|
113
|
+
source: string;
|
|
114
|
+
assurance: "unknown" | "established" | "inferred";
|
|
115
|
+
evidenceIds: string[];
|
|
116
|
+
observedAt: string;
|
|
117
|
+
};
|
|
118
|
+
} | {
|
|
119
|
+
kind: "source-revision";
|
|
120
|
+
repositoryId: string;
|
|
121
|
+
commit: string;
|
|
122
|
+
branch: string | null;
|
|
123
|
+
id: string;
|
|
124
|
+
scope: {
|
|
125
|
+
installationId: string;
|
|
126
|
+
applicationIds: string[];
|
|
127
|
+
targetIds: string[];
|
|
128
|
+
};
|
|
129
|
+
label: string;
|
|
130
|
+
provenance: {
|
|
131
|
+
source: string;
|
|
132
|
+
assurance: "unknown" | "established" | "inferred";
|
|
133
|
+
evidenceIds: string[];
|
|
134
|
+
observedAt: string;
|
|
135
|
+
};
|
|
136
|
+
} | {
|
|
137
|
+
kind: "artifact";
|
|
138
|
+
digest: string;
|
|
139
|
+
sourceRevisionIds: string[];
|
|
140
|
+
buildRunId: string | null;
|
|
141
|
+
image: string | null;
|
|
142
|
+
id: string;
|
|
143
|
+
scope: {
|
|
144
|
+
installationId: string;
|
|
145
|
+
applicationIds: string[];
|
|
146
|
+
targetIds: string[];
|
|
147
|
+
};
|
|
148
|
+
label: string;
|
|
149
|
+
provenance: {
|
|
150
|
+
source: string;
|
|
151
|
+
assurance: "unknown" | "established" | "inferred";
|
|
152
|
+
evidenceIds: string[];
|
|
153
|
+
observedAt: string;
|
|
154
|
+
};
|
|
155
|
+
} | {
|
|
156
|
+
kind: "deployment";
|
|
157
|
+
applicationId: string;
|
|
158
|
+
environment: string;
|
|
159
|
+
artifactIds: string[];
|
|
160
|
+
targetIds: string[];
|
|
161
|
+
configurationDigest: string | null;
|
|
162
|
+
id: string;
|
|
163
|
+
scope: {
|
|
164
|
+
installationId: string;
|
|
165
|
+
applicationIds: string[];
|
|
166
|
+
targetIds: string[];
|
|
167
|
+
};
|
|
168
|
+
label: string;
|
|
169
|
+
provenance: {
|
|
170
|
+
source: string;
|
|
171
|
+
assurance: "unknown" | "established" | "inferred";
|
|
172
|
+
evidenceIds: string[];
|
|
173
|
+
observedAt: string;
|
|
174
|
+
};
|
|
175
|
+
magnusResourceId?: string | undefined;
|
|
176
|
+
} | {
|
|
177
|
+
kind: "target";
|
|
178
|
+
magnusInstallationId: string;
|
|
179
|
+
magnusTargetId: string;
|
|
180
|
+
agentId: string;
|
|
181
|
+
targetKind: "host" | "container" | "worker";
|
|
182
|
+
enrollment: "discovered" | "legacy" | "draining" | "enrolled";
|
|
183
|
+
platform: string;
|
|
184
|
+
capabilities: string[];
|
|
185
|
+
lastSeenAt: string;
|
|
186
|
+
parentHostId: string | null;
|
|
187
|
+
workloadId: string | null;
|
|
188
|
+
instanceId: string | null;
|
|
189
|
+
executionNamespace: string;
|
|
190
|
+
lifecycle: "active" | "offline" | "retired";
|
|
191
|
+
id: string;
|
|
192
|
+
scope: {
|
|
193
|
+
installationId: string;
|
|
194
|
+
applicationIds: string[];
|
|
195
|
+
targetIds: string[];
|
|
196
|
+
};
|
|
197
|
+
label: string;
|
|
198
|
+
provenance: {
|
|
199
|
+
source: string;
|
|
200
|
+
assurance: "unknown" | "established" | "inferred";
|
|
201
|
+
evidenceIds: string[];
|
|
202
|
+
observedAt: string;
|
|
203
|
+
};
|
|
204
|
+
environment?: string | undefined;
|
|
205
|
+
} | {
|
|
206
|
+
kind: "container-instance";
|
|
207
|
+
runtimeId: string;
|
|
208
|
+
deploymentId: string;
|
|
209
|
+
artifactId: string;
|
|
210
|
+
hostId: string;
|
|
211
|
+
agentId: string | null;
|
|
212
|
+
startedAt: string;
|
|
213
|
+
id: string;
|
|
214
|
+
scope: {
|
|
215
|
+
installationId: string;
|
|
216
|
+
applicationIds: string[];
|
|
217
|
+
targetIds: string[];
|
|
218
|
+
};
|
|
219
|
+
label: string;
|
|
220
|
+
provenance: {
|
|
221
|
+
source: string;
|
|
222
|
+
assurance: "unknown" | "established" | "inferred";
|
|
223
|
+
evidenceIds: string[];
|
|
224
|
+
observedAt: string;
|
|
225
|
+
};
|
|
226
|
+
})[];
|
|
227
|
+
observedAt: string;
|
|
228
|
+
agents?: {
|
|
229
|
+
kind: "management-agent";
|
|
230
|
+
magnusInstallationId: string;
|
|
231
|
+
magnusAgentId: string;
|
|
232
|
+
targetIds: string[];
|
|
233
|
+
capabilities: string[];
|
|
234
|
+
version: string | null;
|
|
235
|
+
lifecycle: "unknown" | "active" | "offline" | "retired";
|
|
236
|
+
id: string;
|
|
237
|
+
scope: {
|
|
238
|
+
installationId: string;
|
|
239
|
+
applicationIds: string[];
|
|
240
|
+
targetIds: string[];
|
|
241
|
+
};
|
|
242
|
+
label: string;
|
|
243
|
+
provenance: {
|
|
244
|
+
source: string;
|
|
245
|
+
assurance: "unknown" | "established" | "inferred";
|
|
246
|
+
evidenceIds: string[];
|
|
247
|
+
observedAt: string;
|
|
248
|
+
};
|
|
249
|
+
}[] | undefined;
|
|
250
|
+
}>;
|
|
251
|
+
dispatch(request: OperationRequest, signal?: AbortSignal): Promise<{
|
|
252
|
+
operationId: string;
|
|
253
|
+
requestDigest: string;
|
|
254
|
+
targetId: string;
|
|
255
|
+
state: "unknown" | "completed" | "failed" | "not-dispatched" | "queued" | "running" | "reconciled";
|
|
256
|
+
evidenceIds: string[];
|
|
257
|
+
result: Record<string, z.core.util.JSONType>;
|
|
258
|
+
ownershipReleased: boolean;
|
|
259
|
+
observedAt: string;
|
|
260
|
+
}>;
|
|
261
|
+
receipt(operationId: string, signal?: AbortSignal): Promise<{
|
|
262
|
+
operationId: string;
|
|
263
|
+
requestDigest: string;
|
|
264
|
+
targetId: string;
|
|
265
|
+
state: "unknown" | "completed" | "failed" | "not-dispatched" | "queued" | "running" | "reconciled";
|
|
266
|
+
evidenceIds: string[];
|
|
267
|
+
result: Record<string, z.core.util.JSONType>;
|
|
268
|
+
ownershipReleased: boolean;
|
|
269
|
+
observedAt: string;
|
|
270
|
+
}>;
|
|
271
|
+
}
|
|
272
|
+
export declare const grantsSchema: z.ZodArray<z.ZodObject<{
|
|
273
|
+
subject: z.ZodString;
|
|
274
|
+
kind: z.ZodEnum<{
|
|
275
|
+
operator: "operator";
|
|
276
|
+
coordinator: "coordinator";
|
|
277
|
+
integration: "integration";
|
|
278
|
+
}>;
|
|
279
|
+
permissions: z.ZodArray<z.ZodEnum<{
|
|
280
|
+
read: "read";
|
|
281
|
+
evidence: "evidence";
|
|
282
|
+
"evidence-restricted": "evidence-restricted";
|
|
283
|
+
assess: "assess";
|
|
284
|
+
prepare: "prepare";
|
|
285
|
+
propose: "propose";
|
|
286
|
+
"publish-explanation": "publish-explanation";
|
|
287
|
+
execute: "execute";
|
|
288
|
+
approve: "approve";
|
|
289
|
+
policy: "policy";
|
|
290
|
+
"repository-write": "repository-write";
|
|
291
|
+
merge: "merge";
|
|
292
|
+
"artifact-publish": "artifact-publish";
|
|
293
|
+
deploy: "deploy";
|
|
294
|
+
exception: "exception";
|
|
295
|
+
recover: "recover";
|
|
296
|
+
ingest: "ingest";
|
|
297
|
+
"audit:read": "audit:read";
|
|
298
|
+
}>>;
|
|
299
|
+
scope: z.ZodObject<{
|
|
300
|
+
installationId: z.ZodString;
|
|
301
|
+
applicationIds: z.ZodArray<z.ZodString>;
|
|
302
|
+
targetIds: z.ZodArray<z.ZodString>;
|
|
303
|
+
}, z.core.$strict>;
|
|
304
|
+
}, z.core.$strict>>;
|
|
305
|
+
/**
|
|
306
|
+
* Oathweave resource-token authentication with the shared hive-common verifier: RS256 only,
|
|
307
|
+
* audience `embermend`, issuer, lifetime (at most 900 s) and `jti` checks, and an online userinfo
|
|
308
|
+
* check of every user token. Product authority comes only from the unique matching grant, or,
|
|
309
|
+
* with `roles` set, an operator's authority comes from its current Oathweave roles instead (see
|
|
310
|
+
* oathweave-roles.ts): its account is read on every request (through the directory's short
|
|
311
|
+
* cache), and `grants` then holds only service (coordinator and integration) grants.
|
|
312
|
+
*
|
|
313
|
+
* Refusals are `OathweaveError`s (401) or plain errors naming the grant problem. An identity
|
|
314
|
+
* provider that cannot be reached, or answers 5xx, is an `OathweaveError` whose reason is
|
|
315
|
+
* `jwks_unavailable` or `identity_unavailable` (503): verification could not run, so the caller
|
|
316
|
+
* should retry rather than sign out. A userinfo 401 or 403 is a revoked session (401).
|
|
317
|
+
*/
|
|
318
|
+
export declare function oathweaveAuthenticator(config: {
|
|
319
|
+
issuer: string;
|
|
320
|
+
jwksUrl: string;
|
|
321
|
+
userinfoUrl: string;
|
|
322
|
+
grants: z.infer<typeof grantsSchema> | (() => z.infer<typeof grantsSchema>);
|
|
323
|
+
roles?: {
|
|
324
|
+
lookup: AccountLookup;
|
|
325
|
+
scopes: RoleScopes | (() => RoleScopes);
|
|
326
|
+
};
|
|
327
|
+
}, overrides?: {
|
|
328
|
+
keys?: JWTVerifyGetKey;
|
|
329
|
+
request?: typeof fetch;
|
|
330
|
+
}): (token: string) => Promise<Actor>;
|
|
331
|
+
/** True when authentication could not run because the identity provider is unavailable. */
|
|
332
|
+
export declare function identityProviderUnavailable(error: unknown): boolean;
|
|
333
|
+
/**
|
|
334
|
+
* A cached client-credentials token for one scoped resource, on the hive-common provider:
|
|
335
|
+
* concurrent callers share one request, a failure backs off briefly, and a token is cached for
|
|
336
|
+
* at most 15 minutes, the longest lifetime Embermend accepts.
|
|
337
|
+
*/
|
|
338
|
+
export declare class ResourceTokenProvider {
|
|
339
|
+
private readonly provider;
|
|
340
|
+
constructor(config: {
|
|
341
|
+
tokenUrl: string;
|
|
342
|
+
clientId: string;
|
|
343
|
+
clientSecret: string;
|
|
344
|
+
scope: string;
|
|
345
|
+
}, request?: typeof fetch);
|
|
346
|
+
token(): Promise<string>;
|
|
347
|
+
/** Forget the cached token, for example after the resource answered 401. */
|
|
348
|
+
invalidate(): void;
|
|
349
|
+
}
|
|
350
|
+
export declare function redact(text: string): string;
|
|
351
|
+
export declare function redactObject(value: unknown): z.infer<typeof jsonObject>;
|
|
352
|
+
export declare const textDigest: (value: string) => string;
|
|
353
|
+
export interface Model {
|
|
354
|
+
ref: string;
|
|
355
|
+
local: boolean;
|
|
356
|
+
analyze(system: string, content: string, signal: AbortSignal): Promise<unknown>;
|
|
357
|
+
}
|
|
358
|
+
export declare class OpenAICompatibleModel implements Model {
|
|
359
|
+
private readonly model;
|
|
360
|
+
private readonly token;
|
|
361
|
+
readonly ref: string;
|
|
362
|
+
readonly local: boolean;
|
|
363
|
+
private readonly url;
|
|
364
|
+
constructor(base: string, model: string, token: string, ref: string, local: boolean, allowLoopback?: boolean);
|
|
365
|
+
analyze(system: string, content: string, signal: AbortSignal): Promise<unknown>;
|
|
366
|
+
}
|
|
367
|
+
export { GitHubClient, githubMergeOperationSchema, type GitHubRepositoryGrant, type GitHubMergeOperation } from './github.js';
|
|
368
|
+
export * from './threat-feeds.js';
|
|
369
|
+
export * from './inference/index.js';
|
|
370
|
+
export * from './registry.js';
|
|
371
|
+
export { OathweaveDirectory, oathweavePermission, roleAuthority, roleScopesSchema, type AccountLookup, type OathweaveAccount, type RoleAuthority, type RoleAuthorityRefusal, type RoleScopes } from './oathweave-roles.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createOathweaveVerifier, createServiceTokenProvider, isOathweaveError, statusForReason } from '@hivemagnus/hive-common/oathweave';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { roleAuthority } from './oathweave-roles.js';
|
|
5
|
+
import { capabilitySchema, operationRequestSchema, receiptSchema, permissions, scopeSchema, jsonObject } from '@hivemagnus/embermend-contracts';
|
|
6
|
+
export class IntegrationError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
uncertain;
|
|
9
|
+
constructor(code, uncertain) {
|
|
10
|
+
super(code);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.uncertain = uncertain;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function endpoint(value, allowLoopback = false) {
|
|
16
|
+
const url = new URL(value);
|
|
17
|
+
if ((url.protocol !== 'https:' && !(allowLoopback && url.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname))) || url.username || url.password || url.search || url.hash)
|
|
18
|
+
throw new Error('Verified HTTPS endpoint required');
|
|
19
|
+
return url;
|
|
20
|
+
}
|
|
21
|
+
/** `value` without trailing `/` characters, in linear time. */
|
|
22
|
+
export function withoutTrailingSlashes(value) {
|
|
23
|
+
let end = value.length;
|
|
24
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47)
|
|
25
|
+
end--;
|
|
26
|
+
return value.slice(0, end);
|
|
27
|
+
}
|
|
28
|
+
export async function responseJson(response) {
|
|
29
|
+
const max = 8 * 1024 * 1024;
|
|
30
|
+
if (Number(response.headers.get('content-length')) > max)
|
|
31
|
+
throw new Error('RESPONSE_TOO_LARGE');
|
|
32
|
+
if (!response.body)
|
|
33
|
+
throw new Error('EMPTY_RESPONSE');
|
|
34
|
+
const reader = response.body.getReader();
|
|
35
|
+
const chunks = [];
|
|
36
|
+
let size = 0;
|
|
37
|
+
try {
|
|
38
|
+
for (;;) {
|
|
39
|
+
const part = await reader.read();
|
|
40
|
+
if (part.done)
|
|
41
|
+
break;
|
|
42
|
+
size += part.value.length;
|
|
43
|
+
if (size > max)
|
|
44
|
+
throw new Error('RESPONSE_TOO_LARGE');
|
|
45
|
+
chunks.push(part.value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await reader.cancel();
|
|
50
|
+
}
|
|
51
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
52
|
+
}
|
|
53
|
+
export class MagnusClient {
|
|
54
|
+
token;
|
|
55
|
+
request;
|
|
56
|
+
base;
|
|
57
|
+
constructor(base, token, request = fetch, allowLoopback = false) {
|
|
58
|
+
this.token = token;
|
|
59
|
+
this.request = request;
|
|
60
|
+
this.base = endpoint(base, allowLoopback);
|
|
61
|
+
}
|
|
62
|
+
async call(path, method, payload, signal) {
|
|
63
|
+
try {
|
|
64
|
+
// Join under the configured base path (`https://host/magnus` + `/api/v1/...`), as `endpoint()` allows one.
|
|
65
|
+
const target = new URL(this.base);
|
|
66
|
+
target.pathname = withoutTrailingSlashes(this.base.pathname) + path;
|
|
67
|
+
const response = await this.request(target, { method, redirect: 'error', headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, signal: signal ?? AbortSignal.timeout(30000), ...(payload === undefined ? {} : { body: JSON.stringify(payload) }) });
|
|
68
|
+
if (!response.ok)
|
|
69
|
+
throw new IntegrationError(`MAGNUS_HTTP_${response.status}`, method !== 'GET' && response.status >= 500);
|
|
70
|
+
return await responseJson(response);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof IntegrationError)
|
|
74
|
+
throw error;
|
|
75
|
+
throw new IntegrationError('MAGNUS_COMMUNICATION_OR_SCHEMA_FAILURE', method !== 'GET');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async capabilities(signal) { return capabilitySchema.parse(await this.call('/api/v1/embermend/capabilities', 'GET', undefined, signal)); }
|
|
79
|
+
async dispatch(request, signal) { try {
|
|
80
|
+
return receiptSchema.parse(await this.call('/api/v1/embermend/operations', 'POST', operationRequestSchema.parse(request), signal));
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof IntegrationError)
|
|
84
|
+
throw error;
|
|
85
|
+
throw new IntegrationError('MAGNUS_INVALID_DISPATCH_RECEIPT', true);
|
|
86
|
+
} }
|
|
87
|
+
async receipt(operationId, signal) { return receiptSchema.parse(await this.call(`/api/v1/embermend/operations/${encodeURIComponent(operationId)}`, 'GET', undefined, signal)); }
|
|
88
|
+
}
|
|
89
|
+
const grantSchema = z.object({ subject: z.string(), kind: z.enum(['operator', 'coordinator', 'integration']), permissions: z.array(z.enum(permissions)), scope: scopeSchema }).strict();
|
|
90
|
+
export const grantsSchema = z.array(grantSchema);
|
|
91
|
+
/**
|
|
92
|
+
* Oathweave resource-token authentication with the shared hive-common verifier: RS256 only,
|
|
93
|
+
* audience `embermend`, issuer, lifetime (at most 900 s) and `jti` checks, and an online userinfo
|
|
94
|
+
* check of every user token. Product authority comes only from the unique matching grant, or,
|
|
95
|
+
* with `roles` set, an operator's authority comes from its current Oathweave roles instead (see
|
|
96
|
+
* oathweave-roles.ts): its account is read on every request (through the directory's short
|
|
97
|
+
* cache), and `grants` then holds only service (coordinator and integration) grants.
|
|
98
|
+
*
|
|
99
|
+
* Refusals are `OathweaveError`s (401) or plain errors naming the grant problem. An identity
|
|
100
|
+
* provider that cannot be reached, or answers 5xx, is an `OathweaveError` whose reason is
|
|
101
|
+
* `jwks_unavailable` or `identity_unavailable` (503): verification could not run, so the caller
|
|
102
|
+
* should retry rather than sign out. A userinfo 401 or 403 is a revoked session (401).
|
|
103
|
+
*/
|
|
104
|
+
export function oathweaveAuthenticator(config, overrides = {}) {
|
|
105
|
+
endpoint(config.issuer);
|
|
106
|
+
endpoint(config.jwksUrl);
|
|
107
|
+
endpoint(config.userinfoUrl);
|
|
108
|
+
const verifier = createOathweaveVerifier({ issuer: config.issuer, audience: 'embermend', jwksUrl: config.jwksUrl, userinfoUrl: config.userinfoUrl, accept: 'any', clientIdClaim: 'clientId', sessionCacheTtlMs: 0, clockToleranceSec: 0, ...(overrides.keys ? { keys: overrides.keys } : {}), ...(overrides.request ? { fetch: overrides.request } : {}) });
|
|
109
|
+
// A function is read on every request, so grants can change without a restart.
|
|
110
|
+
const source = config.grants;
|
|
111
|
+
const grants = typeof source === 'function' ? source : () => source;
|
|
112
|
+
const roles = config.roles;
|
|
113
|
+
const roleSource = roles?.scopes;
|
|
114
|
+
const scopes = typeof roleSource === 'function' ? roleSource : () => roleSource ?? [];
|
|
115
|
+
return async (token) => {
|
|
116
|
+
const principal = await verifier.verify(token);
|
|
117
|
+
if (roles && principal.kind === 'user') {
|
|
118
|
+
// Oathweave always sends roles on a user token; the account's current roles decide.
|
|
119
|
+
if (!Array.isArray(principal.claims['roles']))
|
|
120
|
+
throw new Error('OPERATOR_USER_TOKEN_REQUIRED');
|
|
121
|
+
const derived = roleAuthority(await roles.lookup(principal.subject), scopes());
|
|
122
|
+
if (!derived.ok)
|
|
123
|
+
throw new Error(derived.reason);
|
|
124
|
+
const allowed = derived.permissions.filter(permission => principal.permissions.includes(`embermend:${permission}`));
|
|
125
|
+
return { id: principal.subject, kind: 'operator', scope: derived.scope, permissions: new Set(allowed) };
|
|
126
|
+
}
|
|
127
|
+
const matching = grants().filter(grant => grant.subject === principal.subject);
|
|
128
|
+
if (matching.length !== 1)
|
|
129
|
+
throw new Error('EXPLICIT_UNIQUE_PRODUCT_GRANT_REQUIRED');
|
|
130
|
+
const grant = matching[0];
|
|
131
|
+
if (!grant)
|
|
132
|
+
throw new Error('PRODUCT_GRANT_REQUIRED');
|
|
133
|
+
if (grant.kind === 'operator') {
|
|
134
|
+
// A user token, its session checked online by the verifier; Oathweave always sends roles.
|
|
135
|
+
if (principal.kind !== 'user' || !Array.isArray(principal.claims['roles']))
|
|
136
|
+
throw new Error('OPERATOR_USER_TOKEN_REQUIRED');
|
|
137
|
+
}
|
|
138
|
+
else if (principal.kind !== 'service' || principal.clientId !== grant.subject)
|
|
139
|
+
throw new Error('SERVICE_SUBJECT_MISMATCH');
|
|
140
|
+
const allowed = grant.permissions.filter(permission => principal.permissions.includes(`embermend:${permission}`));
|
|
141
|
+
if (grant.kind !== 'operator' && allowed.some(permission => ['approve', 'policy', 'exception', 'recover'].includes(permission)))
|
|
142
|
+
throw new Error('NON_OPERATOR_AUTHORITY_ESCALATION');
|
|
143
|
+
if (grant.kind === 'coordinator' && allowed.includes('ingest'))
|
|
144
|
+
throw new Error('COORDINATOR_CANNOT_VALIDATE_ITS_OWN_EVIDENCE');
|
|
145
|
+
return { id: grant.subject, kind: grant.kind, scope: grant.scope, permissions: new Set(allowed) };
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** True when authentication could not run because the identity provider is unavailable. */
|
|
149
|
+
export function identityProviderUnavailable(error) {
|
|
150
|
+
return isOathweaveError(error) && statusForReason(error.reason) === 503;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A cached client-credentials token for one scoped resource, on the hive-common provider:
|
|
154
|
+
* concurrent callers share one request, a failure backs off briefly, and a token is cached for
|
|
155
|
+
* at most 15 minutes, the longest lifetime Embermend accepts.
|
|
156
|
+
*/
|
|
157
|
+
export class ResourceTokenProvider {
|
|
158
|
+
provider;
|
|
159
|
+
constructor(config, request = fetch) {
|
|
160
|
+
endpoint(config.tokenUrl);
|
|
161
|
+
this.provider = createServiceTokenProvider({ tokenUrl: config.tokenUrl, clientId: config.clientId, clientSecret: config.clientSecret, scope: config.scope, fetch: request, maxLifetimeMs: 900000 });
|
|
162
|
+
}
|
|
163
|
+
async token() { return this.provider.token(); }
|
|
164
|
+
/** Forget the cached token, for example after the resource answered 401. */
|
|
165
|
+
invalidate() { this.provider.invalidate(); }
|
|
166
|
+
}
|
|
167
|
+
/** The end of a `-----BEGIN|END <label>PRIVATE KEY-----` marker at `at`, where the label holds no `-`; -1 when there is none. */
|
|
168
|
+
function pemMarkerEnd(text, at, prefix) {
|
|
169
|
+
const label = at + prefix.length;
|
|
170
|
+
const dash = text.indexOf('-', label);
|
|
171
|
+
return dash - label >= 11 && text.startsWith('PRIVATE KEY-----', dash - 11) ? dash + 5 : -1;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Replace each private-key block with a placeholder that keeps its line count. A linear scan with the same matches as
|
|
175
|
+
* /-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/g, which is quadratic on repeated BEGIN markers.
|
|
176
|
+
*/
|
|
177
|
+
function redactPrivateKeyBlocks(text) {
|
|
178
|
+
const begin = '-----BEGIN ', end = '-----END ';
|
|
179
|
+
let output = '', copied = 0;
|
|
180
|
+
for (let at = text.indexOf(begin); at !== -1; at = text.indexOf(begin, at + 1)) {
|
|
181
|
+
const header = pemMarkerEnd(text, at, begin);
|
|
182
|
+
if (header === -1)
|
|
183
|
+
continue;
|
|
184
|
+
let footer = -1;
|
|
185
|
+
for (let close = text.indexOf(end, header); close !== -1 && footer === -1; close = text.indexOf(end, close + 1))
|
|
186
|
+
footer = pemMarkerEnd(text, close, end);
|
|
187
|
+
// No closing marker follows this one, so none follows any later opening marker either.
|
|
188
|
+
if (footer === -1)
|
|
189
|
+
break;
|
|
190
|
+
const block = text.slice(at, footer);
|
|
191
|
+
output += text.slice(copied, at) + '[REDACTED PRIVATE KEY]' + '\n'.repeat(block.split('\n').length - 1);
|
|
192
|
+
copied = footer;
|
|
193
|
+
at = footer - 1;
|
|
194
|
+
}
|
|
195
|
+
return output + text.slice(copied);
|
|
196
|
+
}
|
|
197
|
+
export function redact(text) {
|
|
198
|
+
return redactPrivateKeyBlocks(text)
|
|
199
|
+
.replace(/\b(?:gh[pousr]_[A-Za-z0-9_]{16,}|github_pat_[A-Za-z0-9_]{16,}|sk-[A-Za-z0-9_-]{16,}|AKIA[A-Z0-9]{16})\b/g, '[REDACTED CREDENTIAL]')
|
|
200
|
+
.replace(/(authorization["']?\s*[=:]\s*["']?)(?:(?:bearer|basic)\s+)?[^\s"',;}]+/gi, '$1[REDACTED]')
|
|
201
|
+
.replace(/((?:password|passwd|secret|token|api[_-]?key)["']?\s*[=:]\s*["']?)([^\s"',;}]{4,})/gi, '$1[REDACTED]');
|
|
202
|
+
}
|
|
203
|
+
export function redactObject(value) {
|
|
204
|
+
const sanitize = (input) => {
|
|
205
|
+
if (typeof input === 'string')
|
|
206
|
+
return redact(input);
|
|
207
|
+
if (Array.isArray(input))
|
|
208
|
+
return input.map(sanitize);
|
|
209
|
+
if (input === null || typeof input !== 'object')
|
|
210
|
+
return input;
|
|
211
|
+
return Object.fromEntries(Object.entries(input).map(([key, item]) => [key, /(?:password|passwd|secret|token|apikey|authorization|privatekey|signingkey|encryptionkey)$/i.test(key.replace(/[^a-z0-9]/gi, '')) ? '[REDACTED]' : sanitize(item)]));
|
|
212
|
+
};
|
|
213
|
+
return jsonObject.parse(sanitize(jsonObject.parse(value)));
|
|
214
|
+
}
|
|
215
|
+
export const textDigest = (value) => createHash('sha256').update(value).digest('hex');
|
|
216
|
+
export class OpenAICompatibleModel {
|
|
217
|
+
model;
|
|
218
|
+
token;
|
|
219
|
+
ref;
|
|
220
|
+
local;
|
|
221
|
+
url;
|
|
222
|
+
constructor(base, model, token, ref, local, allowLoopback = false) {
|
|
223
|
+
this.model = model;
|
|
224
|
+
this.token = token;
|
|
225
|
+
this.ref = ref;
|
|
226
|
+
this.local = local;
|
|
227
|
+
this.url = endpoint(base, allowLoopback);
|
|
228
|
+
}
|
|
229
|
+
async analyze(system, content, signal) {
|
|
230
|
+
const response = await fetch(new URL('chat/completions', this.url.href.endsWith('/') ? this.url : new URL(this.url.href + '/')), { method: 'POST', redirect: 'error', signal, headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, body: JSON.stringify({ model: this.model, temperature: 0, messages: [{ role: 'system', content: system }, { role: 'user', content }], response_format: { type: 'json_object' } }) });
|
|
231
|
+
if (!response.ok)
|
|
232
|
+
throw new Error('MODEL_UNAVAILABLE');
|
|
233
|
+
const result = z.object({ choices: z.array(z.object({ finish_reason: z.string(), message: z.object({ content: z.string() }) })).min(1) }).parse(await responseJson(response));
|
|
234
|
+
const choice = result.choices[0];
|
|
235
|
+
if (!choice || choice.finish_reason !== 'stop')
|
|
236
|
+
throw new Error('MODEL_ANALYSIS_TRUNCATED');
|
|
237
|
+
return JSON.parse(choice.message.content);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
export { GitHubClient, githubMergeOperationSchema } from './github.js';
|
|
241
|
+
export * from './threat-feeds.js';
|
|
242
|
+
export * from './inference/index.js';
|
|
243
|
+
export * from './registry.js';
|
|
244
|
+
export { OathweaveDirectory, oathweavePermission, roleAu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|
+
export declare class ClaudeCliInference implements Model {
|
|
4
|
+
private readonly config;
|
|
5
|
+
readonly local = false;
|
|
6
|
+
readonly ref: string;
|
|
7
|
+
constructor(config: Extract<InferenceProvider, {
|
|
8
|
+
kind: 'claude-cli';
|
|
9
|
+
}>);
|
|
10
|
+
analyze(system: string, content: string, signal: AbortSignal): Promise<unknown>;
|
|
11
|
+
}
|