@vorim/sdk 3.15.0 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +15 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.d.cts +1 -1
- package/dist/integrations/anthropic.d.ts +1 -1
- package/dist/integrations/ap2.d.cts +1 -1
- package/dist/integrations/ap2.d.ts +1 -1
- package/dist/integrations/aws-iam.cjs +225 -0
- package/dist/integrations/aws-iam.cjs.map +1 -0
- package/dist/integrations/aws-iam.d.cts +156 -0
- package/dist/integrations/aws-iam.d.ts +156 -0
- package/dist/integrations/aws-iam.js +199 -0
- package/dist/integrations/aws-iam.js.map +1 -0
- package/dist/integrations/bank-rails.d.cts +1 -1
- package/dist/integrations/bank-rails.d.ts +1 -1
- package/dist/integrations/circle.d.cts +1 -1
- package/dist/integrations/circle.d.ts +1 -1
- package/dist/integrations/cloudflare.d.cts +1 -1
- package/dist/integrations/cloudflare.d.ts +1 -1
- package/dist/integrations/coinbase-cdp.d.cts +1 -1
- package/dist/integrations/coinbase-cdp.d.ts +1 -1
- package/dist/integrations/crewai.d.cts +1 -1
- package/dist/integrations/crewai.d.ts +1 -1
- package/dist/integrations/entra.cjs +225 -0
- package/dist/integrations/entra.cjs.map +1 -0
- package/dist/integrations/entra.d.cts +155 -0
- package/dist/integrations/entra.d.ts +155 -0
- package/dist/integrations/entra.js +199 -0
- package/dist/integrations/entra.js.map +1 -0
- package/dist/integrations/fhir.d.cts +1 -1
- package/dist/integrations/fhir.d.ts +1 -1
- package/dist/integrations/guidewire.d.cts +1 -1
- package/dist/integrations/guidewire.d.ts +1 -1
- package/dist/integrations/hermes.d.cts +1 -1
- package/dist/integrations/hermes.d.ts +1 -1
- package/dist/integrations/langchain.d.cts +1 -1
- package/dist/integrations/langchain.d.ts +1 -1
- package/dist/integrations/langgraph.d.cts +1 -1
- package/dist/integrations/langgraph.d.ts +1 -1
- package/dist/integrations/legal.d.cts +1 -1
- package/dist/integrations/legal.d.ts +1 -1
- package/dist/integrations/life-sciences.d.cts +1 -1
- package/dist/integrations/life-sciences.d.ts +1 -1
- package/dist/integrations/lithic.d.cts +1 -1
- package/dist/integrations/lithic.d.ts +1 -1
- package/dist/integrations/llamaindex.d.cts +1 -1
- package/dist/integrations/llamaindex.d.ts +1 -1
- package/dist/integrations/marqeta.d.cts +1 -1
- package/dist/integrations/marqeta.d.ts +1 -1
- package/dist/integrations/modern-treasury.d.cts +1 -1
- package/dist/integrations/modern-treasury.d.ts +1 -1
- package/dist/integrations/nekuda.d.cts +1 -1
- package/dist/integrations/nekuda.d.ts +1 -1
- package/dist/integrations/okta.cjs +229 -0
- package/dist/integrations/okta.cjs.map +1 -0
- package/dist/integrations/okta.d.cts +172 -0
- package/dist/integrations/okta.d.ts +172 -0
- package/dist/integrations/okta.js +203 -0
- package/dist/integrations/okta.js.map +1 -0
- package/dist/integrations/openai.d.cts +1 -1
- package/dist/integrations/openai.d.ts +1 -1
- package/dist/integrations/paypal-agent.d.cts +1 -1
- package/dist/integrations/paypal-agent.d.ts +1 -1
- package/dist/integrations/plaid.d.cts +1 -1
- package/dist/integrations/plaid.d.ts +1 -1
- package/dist/integrations/ramp.d.cts +1 -1
- package/dist/integrations/ramp.d.ts +1 -1
- package/dist/integrations/shopify.d.cts +1 -1
- package/dist/integrations/shopify.d.ts +1 -1
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.d.cts +1 -1
- package/dist/integrations/skyfire.d.ts +1 -1
- package/dist/integrations/stripe-acp.d.cts +1 -1
- package/dist/integrations/stripe-acp.d.ts +1 -1
- package/dist/integrations/stripe-issuing.d.cts +1 -1
- package/dist/integrations/stripe-issuing.d.ts +1 -1
- package/dist/integrations/truanon.d.cts +1 -1
- package/dist/integrations/truanon.d.ts +1 -1
- package/dist/integrations/ucp.d.cts +1 -1
- package/dist/integrations/ucp.d.ts +1 -1
- package/dist/integrations/vercel-ai.d.cts +1 -1
- package/dist/integrations/vercel-ai.d.ts +1 -1
- package/dist/integrations/x402.d.cts +1 -1
- package/dist/integrations/x402.d.ts +1 -1
- package/dist/{types-zzK9YOoa.d.cts → types-Lp1iHEDz.d.cts} +21 -1
- package/dist/{types-zzK9YOoa.d.ts → types-Lp1iHEDz.d.ts} +21 -1
- package/package.json +31 -1
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// src/integrations/aws-iam.ts
|
|
2
|
+
var ESCALATION_OPS = /* @__PURE__ */ new Set(["CreateAccessKey", "CreateRole", "AttachRolePolicy", "PutRolePolicy"]);
|
|
3
|
+
var OPERATION_SCOPE = {
|
|
4
|
+
read: "agent:read",
|
|
5
|
+
CreateUser: "agent:write",
|
|
6
|
+
AssumeRole: "agent:write",
|
|
7
|
+
CreateRole: "agent:elevate",
|
|
8
|
+
AttachRolePolicy: "agent:elevate",
|
|
9
|
+
PutRolePolicy: "agent:elevate",
|
|
10
|
+
CreateAccessKey: "agent:elevate"
|
|
11
|
+
};
|
|
12
|
+
var VorimAwsIam = class {
|
|
13
|
+
sdk;
|
|
14
|
+
agentId;
|
|
15
|
+
accountId;
|
|
16
|
+
adminId;
|
|
17
|
+
minTrustScore;
|
|
18
|
+
escalatePrivileged;
|
|
19
|
+
escalationTimeoutMs;
|
|
20
|
+
onError;
|
|
21
|
+
constructor(sdk, config) {
|
|
22
|
+
if (!config?.agentId) throw new Error("[vorim] AWS IAM integration requires an agentId.");
|
|
23
|
+
if (!config?.accountId) throw new Error("[vorim] AWS IAM integration requires an accountId.");
|
|
24
|
+
this.sdk = sdk;
|
|
25
|
+
this.agentId = config.agentId;
|
|
26
|
+
this.accountId = config.accountId;
|
|
27
|
+
this.adminId = config.adminId;
|
|
28
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
29
|
+
this.escalatePrivileged = config.escalatePrivileged ?? true;
|
|
30
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
|
|
31
|
+
this.onError = config.onError ?? "closed";
|
|
32
|
+
}
|
|
33
|
+
isPrivileged(operation) {
|
|
34
|
+
return ESCALATION_OPS.has(operation);
|
|
35
|
+
}
|
|
36
|
+
scopeFor(operation) {
|
|
37
|
+
return OPERATION_SCOPE[operation] ?? "agent:write";
|
|
38
|
+
}
|
|
39
|
+
async authorize(action) {
|
|
40
|
+
const privileged = this.isPrivileged(action.operation);
|
|
41
|
+
const scope = this.scopeFor(action.operation);
|
|
42
|
+
try {
|
|
43
|
+
if (this.minTrustScore > 0) {
|
|
44
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
45
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
46
|
+
return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: privileged ? "privileged-denied" : "ordinary" };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (privileged) {
|
|
50
|
+
if (!this.escalatePrivileged) {
|
|
51
|
+
return { authorized: false, reason: `${action.operation} requires a human admin and escalatePrivileged is off`, outcome: "privileged-denied" };
|
|
52
|
+
}
|
|
53
|
+
if (!this.adminId) {
|
|
54
|
+
return {
|
|
55
|
+
authorized: false,
|
|
56
|
+
reason: `${action.operation} requires a configured adminId (the approving human admin)`,
|
|
57
|
+
outcome: "privileged-denied"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const esc = await this.escalate(action, scope);
|
|
61
|
+
return {
|
|
62
|
+
authorized: esc.approved,
|
|
63
|
+
reason: esc.approved ? void 0 : esc.reason ?? "admin did not approve",
|
|
64
|
+
outcome: esc.approved ? "approved-by-admin" : "privileged-denied",
|
|
65
|
+
adminId: esc.approved ? this.adminId : void 0,
|
|
66
|
+
decisionId: esc.decisionId
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
70
|
+
return perm.allowed ? { authorized: true, outcome: "ordinary", adminId: this.adminId } : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: "ordinary" };
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open", outcome: privileged ? "approved-by-admin" : "ordinary" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}`, outcome: privileged ? "privileged-denied" : "ordinary" };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async escalate(action, scope) {
|
|
76
|
+
const decision = await this.sdk.beforeAction(
|
|
77
|
+
{
|
|
78
|
+
agentId: this.agentId,
|
|
79
|
+
actionType: "api_request",
|
|
80
|
+
actionTarget: `aws-iam:${action.operation}`,
|
|
81
|
+
requiredScope: scope,
|
|
82
|
+
payload: { operation: action.operation, target_id: action.targetId, policy: action.policy },
|
|
83
|
+
context: { integration: "aws-iam", account_id: this.accountId, requires_human_admin: true, admin_hint: this.adminId }
|
|
84
|
+
},
|
|
85
|
+
{ throwOnDeny: false }
|
|
86
|
+
);
|
|
87
|
+
if (decision.decision === "escalate") {
|
|
88
|
+
const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });
|
|
89
|
+
const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
|
|
90
|
+
return { approved, reason: approved ? void 0 : "admin refused", decisionId: decision.decisionId };
|
|
91
|
+
}
|
|
92
|
+
if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
|
|
93
|
+
if (decision.decision === "fallback")
|
|
94
|
+
return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
|
|
95
|
+
return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
|
|
96
|
+
}
|
|
97
|
+
async record(action, result, extra = {}) {
|
|
98
|
+
const scope = this.scopeFor(action.operation);
|
|
99
|
+
try {
|
|
100
|
+
await this.sdk.emit(
|
|
101
|
+
{
|
|
102
|
+
agent_id: this.agentId,
|
|
103
|
+
event_type: "api_request",
|
|
104
|
+
action: `aws-iam:${action.operation}${action.targetId ? " " + action.targetId : ""}`,
|
|
105
|
+
resource: action.targetId || this.accountId,
|
|
106
|
+
permission: scope,
|
|
107
|
+
result,
|
|
108
|
+
input_hash: action.inputHash,
|
|
109
|
+
metadata: {
|
|
110
|
+
integration: "aws-iam",
|
|
111
|
+
account_id: this.accountId,
|
|
112
|
+
operation: action.operation,
|
|
113
|
+
privileged: this.isPrivileged(action.operation),
|
|
114
|
+
...action.policy ? { policy: action.policy } : {},
|
|
115
|
+
...extra.outcome ? { outcome: extra.outcome } : {},
|
|
116
|
+
...extra.adminId ?? this.adminId ? { approved_by_admin: extra.adminId ?? this.adminId } : {},
|
|
117
|
+
...extra.decisionId ? { decision_id: extra.decisionId } : {},
|
|
118
|
+
...extra.reason ? { reason: extra.reason } : {}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{ sign: true }
|
|
122
|
+
);
|
|
123
|
+
return true;
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async guard(action, run) {
|
|
129
|
+
const auth = await this.authorize(action);
|
|
130
|
+
if (!auth.authorized) {
|
|
131
|
+
const recorded = await this.record(action, "denied", { reason: auth.reason, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
132
|
+
return { receipt: this.receipt(action, false, "denied", auth, recorded) };
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const value = await run();
|
|
136
|
+
const recorded = await this.record(action, "success", { outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
137
|
+
return { receipt: this.receipt(action, true, "success", auth, recorded), value };
|
|
138
|
+
} catch (e) {
|
|
139
|
+
const recorded = await this.record(action, "error", { reason: e?.message, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
140
|
+
throw Object.assign(e ?? new Error("aws iam operation failed"), {
|
|
141
|
+
vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// --- Named helpers ---------------------------------------------------------
|
|
146
|
+
/** Guard iam:CreateUser. Requires agent:write. */
|
|
147
|
+
guardedCreateUser(meta, run) {
|
|
148
|
+
return this.guard({ operation: "CreateUser", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
149
|
+
}
|
|
150
|
+
/** Guard iam:CreateRole (creates a role + its trust policy). Always escalates. */
|
|
151
|
+
guardedCreateRole(meta, run) {
|
|
152
|
+
return this.guard({ operation: "CreateRole", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
153
|
+
}
|
|
154
|
+
/** Guard iam:AttachRolePolicy (attach a managed policy). Always escalates.
|
|
155
|
+
* Pass the policy arn (e.g. AdministratorAccess) so it lands in the record. */
|
|
156
|
+
guardedAttachRolePolicy(meta, run) {
|
|
157
|
+
return this.guard({ operation: "AttachRolePolicy", targetId: meta.targetId, policy: meta.policy, inputHash: meta.inputHash }, run);
|
|
158
|
+
}
|
|
159
|
+
/** Guard iam:PutRolePolicy (embed an inline policy). Always escalates. */
|
|
160
|
+
guardedPutRolePolicy(meta, run) {
|
|
161
|
+
return this.guard({ operation: "PutRolePolicy", targetId: meta.targetId, policy: meta.policy, inputHash: meta.inputHash }, run);
|
|
162
|
+
}
|
|
163
|
+
/** Guard iam:CreateAccessKey (mints a long-lived static credential). Always
|
|
164
|
+
* escalates to the named admin — the single highest-stakes IAM op. */
|
|
165
|
+
guardedCreateAccessKey(meta, run) {
|
|
166
|
+
return this.guard({ operation: "CreateAccessKey", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
167
|
+
}
|
|
168
|
+
/** Guard sts:AssumeRole (short-lived credential). Requires agent:write —
|
|
169
|
+
* lighter friction than CreateAccessKey, the safer path to nudge agents to. */
|
|
170
|
+
guardedAssumeRole(meta, run) {
|
|
171
|
+
return this.guard({ operation: "AssumeRole", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
172
|
+
}
|
|
173
|
+
receipt(action, authorized, result, auth, recorded) {
|
|
174
|
+
return {
|
|
175
|
+
authorized,
|
|
176
|
+
agentId: this.agentId,
|
|
177
|
+
accountId: this.accountId,
|
|
178
|
+
operation: action.operation,
|
|
179
|
+
targetId: action.targetId,
|
|
180
|
+
policy: action.policy,
|
|
181
|
+
privileged: this.isPrivileged(action.operation),
|
|
182
|
+
outcome: auth.outcome ?? "ordinary",
|
|
183
|
+
adminId: auth.adminId ?? this.adminId,
|
|
184
|
+
result,
|
|
185
|
+
scope: this.scopeFor(action.operation),
|
|
186
|
+
reason: auth.reason,
|
|
187
|
+
decisionId: auth.decisionId,
|
|
188
|
+
recorded
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
function createVorimAwsIam(sdk, config) {
|
|
193
|
+
return new VorimAwsIam(sdk, config);
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
VorimAwsIam,
|
|
197
|
+
createVorimAwsIam
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=aws-iam.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/aws-iam.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — AWS IAM / STS Integration\n//\n// This guards an AI agent that manages AWS identity through IAM and STS —\n// creating users and roles, attaching policies, minting access keys, assuming\n// roles. Before each write runs it verifies the agent's Vorim identity and\n// scoped permission, and for the highest-stakes operations (minting a long-lived\n// access key, escalating privilege via a role/policy change) it escalates to a\n// named human admin and waits. Either way it signs a tamper-evident record.\n//\n// WHY IAM, NOT AGENTCORE\n// This connector guards the stable, universally-available IAM/STS admin surface\n// (free on any AWS account, no Bedrock/region gating). It is NOT Bedrock\n// AgentCore Identity: that is a separate, agent-native product that presupposes\n// a billable, Bedrock-enabled account. IAM is where the real privilege-\n// escalation and long-lived-credential minting happen, so it is the right first\n// target. An AgentCore connector can be a second wave.\n//\n// THE ESCALATION RULE (the wedge)\n// CreateAccessKey mints a long-lived, non-expiring static credential (the secret\n// is shown once, defaults to Active) — the single highest-stakes IAM op, and it\n// always escalates to a named human admin. Broad privilege-escalation ops\n// (CreateRole, AttachRolePolicy, PutRolePolicy) also escalate. Prefer steering\n// agents to AssumeRole (short-lived STS credentials), which passes with lighter\n// friction.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// read IAM -> agent:read\n// create user, assume role (STS) -> agent:write\n// create access key / create role / -> agent:elevate (named-admin approval)\n// attach or put role policy\n//\n// HONEST COMPLIANCE FRAMING\n// A signed, attributable record of each IAM change supports SOC 2 (CC6 logical\n// access, CC7 change monitoring). No regime mandates cryptographic signatures on\n// audit logs; signing satisfies the tamper-evident + attributable intent. Say\n// \"cryptographic proof of which agent made which change\", never \"required for\n// compliance\".\n//\n// This layer never holds AWS credentials and never calls AWS itself. You pass\n// the AWS SDK call as a closure; it authorizes, escalates if needed, runs it,\n// and signs the receipt.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimAwsIam } from '@vorim/sdk/integrations/aws-iam';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const iam = createVorimAwsIam(vorim, {\n// agentId: 'agid_abc123',\n// accountId: '123456789012',\n// adminId: 'admin_42',\n// });\n//\n// const { receipt, value } = await iam.guardedCreateAccessKey(\n// { targetId: 'ci-bot' },\n// () => iamClient.send(new CreateAccessKeyCommand({ UserName: 'ci-bot' })),\n// );\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** The AWS IAM / STS operations this guard classifies (real API call names). */\nexport type AwsIamOperation =\n | 'CreateUser' // iam:CreateUser\n | 'CreateRole' // iam:CreateRole (+ trust/assume-role policy)\n | 'AttachRolePolicy' // iam:AttachRolePolicy (managed policy)\n | 'PutRolePolicy' // iam:PutRolePolicy (inline policy)\n | 'CreateAccessKey' // iam:CreateAccessKey (long-lived static credential)\n | 'AssumeRole' // sts:AssumeRole (short-lived credential)\n | 'read';\n\n/** Operations that mint a long-lived credential or escalate privilege — always\n * escalate to a named human admin. */\nconst ESCALATION_OPS = new Set<string>(['CreateAccessKey', 'CreateRole', 'AttachRolePolicy', 'PutRolePolicy']);\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n read: 'agent:read',\n CreateUser: 'agent:write',\n AssumeRole: 'agent:write',\n CreateRole: 'agent:elevate',\n AttachRolePolicy: 'agent:elevate',\n PutRolePolicy: 'agent:elevate',\n CreateAccessKey: 'agent:elevate',\n};\n\nexport interface AwsIamGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The AWS account id, e.g. '123456789012'. Recorded on every receipt. */\n accountId: string;\n /** The human admin who approves privileged operations. Required if any\n * escalation-class op will be run. */\n adminId?: string;\n minTrustScore?: number;\n /** For a privileged op, escalate to the named admin and wait. Default true. */\n escalatePrivileged?: boolean;\n escalationTimeoutMs?: number;\n onError?: 'closed' | 'open';\n}\n\nexport interface AwsIamAction {\n /** The IAM/STS operation, e.g. 'CreateAccessKey'. Drives scope + escalation. */\n operation: AwsIamOperation | string;\n /** The target the action affects (user name, role name/arn). Recorded. */\n targetId?: string;\n /** For AttachRolePolicy / PutRolePolicy: the policy arn/name being granted,\n * e.g. 'arn:aws:iam::aws:policy/AdministratorAccess'. Recorded. */\n policy?: string;\n inputHash?: string;\n}\n\nexport type AwsIamOutcome = 'ordinary' | 'approved-by-admin' | 'privileged-denied';\n\nexport interface AwsIamReceipt {\n authorized: boolean;\n agentId: string;\n accountId: string;\n operation: string;\n targetId?: string;\n policy?: string;\n privileged: boolean;\n outcome: AwsIamOutcome;\n adminId?: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\nexport class VorimAwsIam {\n private sdk: VorimSDK;\n private agentId: string;\n private accountId: string;\n private adminId?: string;\n private minTrustScore: number;\n private escalatePrivileged: boolean;\n private escalationTimeoutMs: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: AwsIamGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] AWS IAM integration requires an agentId.');\n if (!config?.accountId) throw new Error('[vorim] AWS IAM integration requires an accountId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.accountId = config.accountId;\n this.adminId = config.adminId;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.escalatePrivileged = config.escalatePrivileged ?? true;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 300_000;\n this.onError = config.onError ?? 'closed';\n }\n\n private isPrivileged(operation: string): boolean {\n return ESCALATION_OPS.has(operation);\n }\n\n private scopeFor(operation: string): PermissionScope {\n return OPERATION_SCOPE[operation] ?? 'agent:write';\n }\n\n async authorize(\n action: AwsIamAction,\n ): Promise<{ authorized: boolean; reason?: string; outcome: AwsIamOutcome; adminId?: string; decisionId?: string }> {\n const privileged = this.isPrivileged(action.operation);\n const scope = this.scopeFor(action.operation);\n\n try {\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: privileged ? 'privileged-denied' : 'ordinary' };\n }\n }\n\n if (privileged) {\n if (!this.escalatePrivileged) {\n return { authorized: false, reason: `${action.operation} requires a human admin and escalatePrivileged is off`, outcome: 'privileged-denied' };\n }\n if (!this.adminId) {\n return {\n authorized: false,\n reason: `${action.operation} requires a configured adminId (the approving human admin)`,\n outcome: 'privileged-denied',\n };\n }\n const esc = await this.escalate(action, scope);\n return {\n authorized: esc.approved,\n reason: esc.approved ? undefined : (esc.reason ?? 'admin did not approve'),\n outcome: esc.approved ? 'approved-by-admin' : 'privileged-denied',\n adminId: esc.approved ? this.adminId : undefined,\n decisionId: esc.decisionId,\n };\n }\n\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true, outcome: 'ordinary', adminId: this.adminId }\n : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: 'ordinary' };\n } catch (e: any) {\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open', outcome: privileged ? 'approved-by-admin' : 'ordinary' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}`, outcome: privileged ? 'privileged-denied' : 'ordinary' };\n }\n }\n\n private async escalate(action: AwsIamAction, scope: PermissionScope): Promise<{ approved: boolean; reason?: string; decisionId?: string }> {\n const decision = await this.sdk.beforeAction(\n {\n agentId: this.agentId,\n actionType: 'api_request',\n actionTarget: `aws-iam:${action.operation}`,\n requiredScope: scope,\n payload: { operation: action.operation, target_id: action.targetId, policy: action.policy },\n context: { integration: 'aws-iam', account_id: this.accountId, requires_human_admin: true, admin_hint: this.adminId },\n },\n { throwOnDeny: false },\n );\n if (decision.decision === 'escalate') {\n const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });\n const approved = resolved.decision === 'allow' || resolved.escalationResolution === 'approved';\n return { approved, reason: approved ? undefined : 'admin refused', decisionId: decision.decisionId };\n }\n if (decision.decision === 'allow') return { approved: true, decisionId: decision.decisionId };\n if (decision.decision === 'fallback')\n return { approved: this.onError === 'open', reason: 'runtime unreachable', decisionId: decision.decisionId };\n return { approved: false, reason: decision.reason ?? 'denied', decisionId: decision.decisionId };\n }\n\n async record(\n action: AwsIamAction,\n result: 'success' | 'denied' | 'error',\n extra: { reason?: string; outcome?: AwsIamOutcome; adminId?: string; decisionId?: string } = {},\n ): Promise<boolean> {\n const scope = this.scopeFor(action.operation);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `aws-iam:${action.operation}${action.targetId ? ' ' + action.targetId : ''}`,\n resource: action.targetId || this.accountId,\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: 'aws-iam',\n account_id: this.accountId,\n operation: action.operation,\n privileged: this.isPrivileged(action.operation),\n ...(action.policy ? { policy: action.policy } : {}),\n ...(extra.outcome ? { outcome: extra.outcome } : {}),\n ...(extra.adminId ?? this.adminId ? { approved_by_admin: extra.adminId ?? this.adminId } : {}),\n ...(extra.decisionId ? { decision_id: extra.decisionId } : {}),\n ...(extra.reason ? { reason: extra.reason } : {}),\n },\n },\n { sign: true },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n async guard<T>(action: AwsIamAction, run: () => Promise<T>): Promise<{ receipt: AwsIamReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', { reason: auth.reason, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, false, 'denied', auth, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success', { outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, true, 'success', auth, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', { reason: e?.message, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n throw Object.assign(e ?? new Error('aws iam operation failed'), {\n vorimReceipt: this.receipt(action, true, 'error', { ...auth, reason: e?.message }, recorded),\n });\n }\n }\n\n // --- Named helpers ---------------------------------------------------------\n\n /** Guard iam:CreateUser. Requires agent:write. */\n guardedCreateUser<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'CreateUser', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard iam:CreateRole (creates a role + its trust policy). Always escalates. */\n guardedCreateRole<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'CreateRole', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard iam:AttachRolePolicy (attach a managed policy). Always escalates.\n * Pass the policy arn (e.g. AdministratorAccess) so it lands in the record. */\n guardedAttachRolePolicy<T>(meta: { targetId?: string; policy?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'AttachRolePolicy', targetId: meta.targetId, policy: meta.policy, inputHash: meta.inputHash }, run);\n }\n\n /** Guard iam:PutRolePolicy (embed an inline policy). Always escalates. */\n guardedPutRolePolicy<T>(meta: { targetId?: string; policy?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'PutRolePolicy', targetId: meta.targetId, policy: meta.policy, inputHash: meta.inputHash }, run);\n }\n\n /** Guard iam:CreateAccessKey (mints a long-lived static credential). Always\n * escalates to the named admin — the single highest-stakes IAM op. */\n guardedCreateAccessKey<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'CreateAccessKey', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard sts:AssumeRole (short-lived credential). Requires agent:write —\n * lighter friction than CreateAccessKey, the safer path to nudge agents to. */\n guardedAssumeRole<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'AssumeRole', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n private receipt(\n action: AwsIamAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n auth: { reason?: string; outcome?: AwsIamOutcome; adminId?: string; decisionId?: string },\n recorded: boolean,\n ): AwsIamReceipt {\n return {\n authorized,\n agentId: this.agentId,\n accountId: this.accountId,\n operation: action.operation,\n targetId: action.targetId,\n policy: action.policy,\n privileged: this.isPrivileged(action.operation),\n outcome: auth.outcome ?? 'ordinary',\n adminId: auth.adminId ?? this.adminId,\n result,\n scope: this.scopeFor(action.operation),\n reason: auth.reason,\n decisionId: auth.decisionId,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimAwsIam guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimAwsIam } from '@vorim/sdk/integrations/aws-iam';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const iam = createVorimAwsIam(vorim, {\n * agentId: 'agid_abc123',\n * accountId: '123456789012',\n * adminId: 'admin_42',\n * });\n *\n * // Minting a long-lived access key always escalates to the named admin:\n * const { receipt } = await iam.guardedCreateAccessKey(\n * { targetId: 'ci-bot' },\n * () => iamClient.send(new CreateAccessKeyCommand({ UserName: 'ci-bot' })),\n * );\n * ```\n */\nexport function createVorimAwsIam(sdk: VorimSDK, config: AwsIamGuardConfig): VorimAwsIam {\n return new VorimAwsIam(sdk, config);\n}\n"],"mappings":";AA2EA,IAAM,iBAAiB,oBAAI,IAAY,CAAC,mBAAmB,cAAc,oBAAoB,eAAe,CAAC;AAE7G,IAAM,kBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AACnB;AA+CO,IAAM,cAAN,MAAkB;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAA2B;AACpD,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,kDAAkD;AACxF,QAAI,CAAC,QAAQ,UAAW,OAAM,IAAI,MAAM,oDAAoD;AAC5F,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,YAAY,OAAO;AACxB,SAAK,UAAU,OAAO;AACtB,SAAK,gBAAgB,OAAO,iBAAiB;AAC7C,SAAK,qBAAqB,OAAO,sBAAsB;AACvD,SAAK,sBAAsB,OAAO,uBAAuB;AACzD,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA,EAEQ,aAAa,WAA4B;AAC/C,WAAO,eAAe,IAAI,SAAS;AAAA,EACrC;AAAA,EAEQ,SAAS,WAAoC;AACnD,WAAO,gBAAgB,SAAS,KAAK;AAAA,EACvC;AAAA,EAEA,MAAM,UACJ,QACkH;AAClH,UAAM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AA,EAIA,kBAAqB,MAAiD,KAAuB;AAC3F,WAAO,KAAK,MAAM,EAAE,WAAW,cAAc,UAAU,KAAK,UAAU,WAAW,KAAK,UAAU,GAAG,GAAG;AAAA,EACxG;AAAA,EAEQ,QACN,QACA,YACA,QACA,MACA,UACe;AACf,WAAO;AAAA,MACL;AAAA,MACA,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,MAChB,WAAW,OAAO;AAAA,MAClB,UAAU,OAAO;AAAA,MACjB,QAAQ,OAAO;AAAA,MACf,YAAY,KAAK,aAAa,OAAO,SAAS;AAAA,MAC9C,SAAS,KAAK,WAAW;AAAA,MACzB,SAAS,KAAK,WAAW,KAAK;AAAA,MAC9B;AAAA,MACA,OAAO,KAAK,SAAS,OAAO,SAAS;AAAA,MACrC,QAAQ,KAAK;AAAA,MACb,YAAY,KAAK;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;AAwBO,SAAS,kBAAkB,KAAe,QAAwC;AACvF,SAAO,IAAI,YAAY,KAAK,MAAM;AACpC;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-Lp1iHEDz.cjs';
|
|
3
3
|
|
|
4
4
|
type CdpOperation = 'sendTransaction' | 'transfer' | 'signMessage';
|
|
5
5
|
interface CoinbaseCdpConfig {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
2
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-Lp1iHEDz.cjs';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
2
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-Lp1iHEDz.js';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/integrations/entra.ts
|
|
21
|
+
var entra_exports = {};
|
|
22
|
+
__export(entra_exports, {
|
|
23
|
+
VorimEntra: () => VorimEntra,
|
|
24
|
+
createVorimEntra: () => createVorimEntra
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(entra_exports);
|
|
27
|
+
var ESCALATION_OPS = /* @__PURE__ */ new Set(["assignDirectoryRole", "addAppSecret", "grantAppRoleAssignment"]);
|
|
28
|
+
var OPERATION_SCOPE = {
|
|
29
|
+
read: "agent:read",
|
|
30
|
+
createUser: "agent:write",
|
|
31
|
+
disableUser: "agent:write",
|
|
32
|
+
createAppRegistration: "agent:write",
|
|
33
|
+
addAppSecret: "agent:elevate",
|
|
34
|
+
grantAppRoleAssignment: "agent:elevate",
|
|
35
|
+
assignDirectoryRole: "agent:elevate"
|
|
36
|
+
};
|
|
37
|
+
var VorimEntra = class {
|
|
38
|
+
sdk;
|
|
39
|
+
agentId;
|
|
40
|
+
tenantId;
|
|
41
|
+
adminId;
|
|
42
|
+
minTrustScore;
|
|
43
|
+
escalatePrivileged;
|
|
44
|
+
escalationTimeoutMs;
|
|
45
|
+
onError;
|
|
46
|
+
constructor(sdk, config) {
|
|
47
|
+
if (!config?.agentId) throw new Error("[vorim] Entra integration requires an agentId.");
|
|
48
|
+
if (!config?.tenantId) throw new Error("[vorim] Entra integration requires a tenantId.");
|
|
49
|
+
this.sdk = sdk;
|
|
50
|
+
this.agentId = config.agentId;
|
|
51
|
+
this.tenantId = config.tenantId;
|
|
52
|
+
this.adminId = config.adminId;
|
|
53
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
54
|
+
this.escalatePrivileged = config.escalatePrivileged ?? true;
|
|
55
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
|
|
56
|
+
this.onError = config.onError ?? "closed";
|
|
57
|
+
}
|
|
58
|
+
isPrivileged(operation) {
|
|
59
|
+
return ESCALATION_OPS.has(operation);
|
|
60
|
+
}
|
|
61
|
+
scopeFor(operation) {
|
|
62
|
+
return OPERATION_SCOPE[operation] ?? "agent:write";
|
|
63
|
+
}
|
|
64
|
+
async authorize(action) {
|
|
65
|
+
const privileged = this.isPrivileged(action.operation);
|
|
66
|
+
const scope = this.scopeFor(action.operation);
|
|
67
|
+
try {
|
|
68
|
+
if (this.minTrustScore > 0) {
|
|
69
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
70
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
71
|
+
return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: privileged ? "privileged-denied" : "ordinary" };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (privileged) {
|
|
75
|
+
if (!this.escalatePrivileged) {
|
|
76
|
+
return { authorized: false, reason: `${action.operation} requires a human admin and escalatePrivileged is off`, outcome: "privileged-denied" };
|
|
77
|
+
}
|
|
78
|
+
if (!this.adminId) {
|
|
79
|
+
return {
|
|
80
|
+
authorized: false,
|
|
81
|
+
reason: `${action.operation} requires a configured adminId (the approving human admin)`,
|
|
82
|
+
outcome: "privileged-denied"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const esc = await this.escalate(action, scope);
|
|
86
|
+
return {
|
|
87
|
+
authorized: esc.approved,
|
|
88
|
+
reason: esc.approved ? void 0 : esc.reason ?? "admin did not approve",
|
|
89
|
+
outcome: esc.approved ? "approved-by-admin" : "privileged-denied",
|
|
90
|
+
adminId: esc.approved ? this.adminId : void 0,
|
|
91
|
+
decisionId: esc.decisionId
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
95
|
+
return perm.allowed ? { authorized: true, outcome: "ordinary", adminId: this.adminId } : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: "ordinary" };
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open", outcome: privileged ? "approved-by-admin" : "ordinary" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}`, outcome: privileged ? "privileged-denied" : "ordinary" };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async escalate(action, scope) {
|
|
101
|
+
const decision = await this.sdk.beforeAction(
|
|
102
|
+
{
|
|
103
|
+
agentId: this.agentId,
|
|
104
|
+
actionType: "api_request",
|
|
105
|
+
actionTarget: `entra:${action.operation}`,
|
|
106
|
+
requiredScope: scope,
|
|
107
|
+
payload: { operation: action.operation, target_id: action.targetId, role: action.role },
|
|
108
|
+
context: { integration: "entra", tenant_id: this.tenantId, requires_human_admin: true, admin_hint: this.adminId }
|
|
109
|
+
},
|
|
110
|
+
{ throwOnDeny: false }
|
|
111
|
+
);
|
|
112
|
+
if (decision.decision === "escalate") {
|
|
113
|
+
const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });
|
|
114
|
+
const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
|
|
115
|
+
return { approved, reason: approved ? void 0 : "admin refused", decisionId: decision.decisionId };
|
|
116
|
+
}
|
|
117
|
+
if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
|
|
118
|
+
if (decision.decision === "fallback")
|
|
119
|
+
return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
|
|
120
|
+
return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
|
|
121
|
+
}
|
|
122
|
+
async record(action, result, extra = {}) {
|
|
123
|
+
const scope = this.scopeFor(action.operation);
|
|
124
|
+
try {
|
|
125
|
+
await this.sdk.emit(
|
|
126
|
+
{
|
|
127
|
+
agent_id: this.agentId,
|
|
128
|
+
event_type: "api_request",
|
|
129
|
+
action: `entra:${action.operation}${action.targetId ? " " + action.targetId : ""}`,
|
|
130
|
+
resource: action.targetId || this.tenantId,
|
|
131
|
+
permission: scope,
|
|
132
|
+
result,
|
|
133
|
+
input_hash: action.inputHash,
|
|
134
|
+
metadata: {
|
|
135
|
+
integration: "entra",
|
|
136
|
+
tenant_id: this.tenantId,
|
|
137
|
+
operation: action.operation,
|
|
138
|
+
privileged: this.isPrivileged(action.operation),
|
|
139
|
+
...action.role ? { role: action.role } : {},
|
|
140
|
+
...extra.outcome ? { outcome: extra.outcome } : {},
|
|
141
|
+
...extra.adminId ?? this.adminId ? { approved_by_admin: extra.adminId ?? this.adminId } : {},
|
|
142
|
+
...extra.decisionId ? { decision_id: extra.decisionId } : {},
|
|
143
|
+
...extra.reason ? { reason: extra.reason } : {}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{ sign: true }
|
|
147
|
+
);
|
|
148
|
+
return true;
|
|
149
|
+
} catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async guard(action, run) {
|
|
154
|
+
const auth = await this.authorize(action);
|
|
155
|
+
if (!auth.authorized) {
|
|
156
|
+
const recorded = await this.record(action, "denied", { reason: auth.reason, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
157
|
+
return { receipt: this.receipt(action, false, "denied", auth, recorded) };
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const value = await run();
|
|
161
|
+
const recorded = await this.record(action, "success", { outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
162
|
+
return { receipt: this.receipt(action, true, "success", auth, recorded), value };
|
|
163
|
+
} catch (e) {
|
|
164
|
+
const recorded = await this.record(action, "error", { reason: e?.message, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
165
|
+
throw Object.assign(e ?? new Error("entra operation failed"), {
|
|
166
|
+
vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// --- Named helpers ---------------------------------------------------------
|
|
171
|
+
/** Guard creating a user (POST /users). Requires agent:write. */
|
|
172
|
+
guardedCreateUser(meta, run) {
|
|
173
|
+
return this.guard({ operation: "createUser", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
174
|
+
}
|
|
175
|
+
/** Guard disabling a user (PATCH /users/{id} accountEnabled:false). agent:write. */
|
|
176
|
+
guardedDisableUser(meta, run) {
|
|
177
|
+
return this.guard({ operation: "disableUser", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
178
|
+
}
|
|
179
|
+
/** Guard creating an app registration (POST /applications). agent:write. */
|
|
180
|
+
guardedCreateAppRegistration(meta, run) {
|
|
181
|
+
return this.guard({ operation: "createAppRegistration", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
182
|
+
}
|
|
183
|
+
/** Guard adding a client secret to an app (POST /applications/{id}/addPassword).
|
|
184
|
+
* Mints a long-lived credential; always escalates to the named admin. */
|
|
185
|
+
guardedAddAppSecret(meta, run) {
|
|
186
|
+
return this.guard({ operation: "addAppSecret", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
187
|
+
}
|
|
188
|
+
/** Guard granting an app-role assignment. Always escalates to the named admin
|
|
189
|
+
* (an application-permission grant is tenant-wide privilege). */
|
|
190
|
+
guardedGrantAppRoleAssignment(meta, run) {
|
|
191
|
+
return this.guard({ operation: "grantAppRoleAssignment", targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);
|
|
192
|
+
}
|
|
193
|
+
/** Guard assigning a directory role (POST /roleManagement/directory/roleAssignments).
|
|
194
|
+
* Always escalates to the named admin. Pass the role (e.g. 'Global Administrator'). */
|
|
195
|
+
guardedAssignDirectoryRole(meta, run) {
|
|
196
|
+
return this.guard({ operation: "assignDirectoryRole", targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);
|
|
197
|
+
}
|
|
198
|
+
receipt(action, authorized, result, auth, recorded) {
|
|
199
|
+
return {
|
|
200
|
+
authorized,
|
|
201
|
+
agentId: this.agentId,
|
|
202
|
+
tenantId: this.tenantId,
|
|
203
|
+
operation: action.operation,
|
|
204
|
+
targetId: action.targetId,
|
|
205
|
+
role: action.role,
|
|
206
|
+
privileged: this.isPrivileged(action.operation),
|
|
207
|
+
outcome: auth.outcome ?? "ordinary",
|
|
208
|
+
adminId: auth.adminId ?? this.adminId,
|
|
209
|
+
result,
|
|
210
|
+
scope: this.scopeFor(action.operation),
|
|
211
|
+
reason: auth.reason,
|
|
212
|
+
decisionId: auth.decisionId,
|
|
213
|
+
recorded
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
function createVorimEntra(sdk, config) {
|
|
218
|
+
return new VorimEntra(sdk, config);
|
|
219
|
+
}
|
|
220
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
+
0 && (module.exports = {
|
|
222
|
+
VorimEntra,
|
|
223
|
+
createVorimEntra
|
|
224
|
+
});
|
|
225
|
+
//# sourceMappingURL=entra.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/entra.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Microsoft Entra ID (Microsoft Graph) Integration\n//\n// This guards an AI agent that administers Microsoft Entra ID through the\n// Microsoft Graph v1.0 API — creating users, registering apps, assigning app\n// roles, minting app credentials, assigning directory roles. Before each write\n// runs it verifies the agent's Vorim identity and scoped permission, and for the\n// highest-stakes operations (assigning a directory role, adding an app secret,\n// granting a tenant-wide app-role assignment) it escalates to a named human\n// admin and waits. Either way it signs a tamper-evident record.\n//\n// GRAPH v1.0 ONLY — HONEST SCOPE\n// This connector guards the STABLE, GA Microsoft Graph v1.0 admin writes. It is\n// NOT an integration with \"Entra Agent ID\": that product's identity-create API\n// is Microsoft Graph /beta, which Microsoft states is \"not supported in\n// production.\" We do not imply otherwise. When the Agent ID API reaches v1.0\n// GA, a second connector can guard it.\n//\n// THE ESCALATION RULE (the wedge)\n// Three operations grant standing, tenant-wide authority or mint a long-lived\n// credential and must always route to a named human admin: assigning a directory\n// role (e.g. Global Administrator), adding a client secret to an app (the\n// secretText is returned once and never retrievable again), and granting an\n// app-role assignment that is an application permission. An agent may propose\n// these; a human authorizes them.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// read directory -> agent:read\n// create/disable user, register app -> agent:write\n// assign directory role / add app -> agent:elevate (named-admin approval)\n// secret / grant app-role\n//\n// HONEST COMPLIANCE FRAMING\n// A signed, attributable record of each directory change supports SOC 2 (CC6\n// logical access, CC7 change monitoring). No regime mandates cryptographic\n// signatures on audit logs; signing satisfies the tamper-evident + attributable\n// intent. Say \"cryptographic proof of which agent made which change\", never\n// \"required for compliance\".\n//\n// This layer never holds the Graph app credential and never calls Graph itself.\n// You pass the Graph SDK call as a closure; it authorizes, escalates if needed,\n// runs it, and signs the receipt.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimEntra } from '@vorim/sdk/integrations/entra';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const entra = createVorimEntra(vorim, {\n// agentId: 'agid_abc123',\n// tenantId: 'contoso.onmicrosoft.com',\n// adminId: 'admin_42',\n// });\n//\n// const { receipt, value } = await entra.guardedAssignDirectoryRole(\n// { targetId: 'user_9', role: 'Global Administrator' },\n// () => graphClient.api('/roleManagement/directory/roleAssignments').post(body),\n// );\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** The Microsoft Graph (Entra) operations this guard classifies. */\nexport type EntraOperation =\n | 'createUser' // POST /users\n | 'disableUser' // PATCH /users/{id} accountEnabled:false\n | 'createAppRegistration' // POST /applications\n | 'addAppSecret' // POST /applications/{id}/addPassword\n | 'grantAppRoleAssignment' // POST /servicePrincipals/{id}/appRoleAssignedTo\n | 'assignDirectoryRole' // POST /roleManagement/directory/roleAssignments\n | 'read';\n\n/** Operations that grant standing tenant-wide authority or mint a long-lived\n * credential — always escalate to a named human admin. */\nconst ESCALATION_OPS = new Set<string>(['assignDirectoryRole', 'addAppSecret', 'grantAppRoleAssignment']);\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n read: 'agent:read',\n createUser: 'agent:write',\n disableUser: 'agent:write',\n createAppRegistration: 'agent:write',\n addAppSecret: 'agent:elevate',\n grantAppRoleAssignment: 'agent:elevate',\n assignDirectoryRole: 'agent:elevate',\n};\n\nexport interface EntraGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The Entra tenant, e.g. 'contoso.onmicrosoft.com' or a tenant GUID.\n * Recorded on every receipt. */\n tenantId: string;\n /** The human admin who approves privileged operations. Required if any\n * escalation-class op will be run. */\n adminId?: string;\n minTrustScore?: number;\n /** For a privileged op, escalate to the named admin and wait. Default true. */\n escalatePrivileged?: boolean;\n escalationTimeoutMs?: number;\n onError?: 'closed' | 'open';\n}\n\nexport interface EntraAction {\n operation: EntraOperation | string;\n /** The target the action affects (user id, app/service-principal id).\n * Recorded for attribution. */\n targetId?: string;\n /** For assignDirectoryRole: the role, e.g. 'Global Administrator'. Recorded. */\n role?: string;\n inputHash?: string;\n}\n\nexport type EntraOutcome = 'ordinary' | 'approved-by-admin' | 'privileged-denied';\n\nexport interface EntraReceipt {\n authorized: boolean;\n agentId: string;\n tenantId: string;\n operation: string;\n targetId?: string;\n role?: string;\n privileged: boolean;\n outcome: EntraOutcome;\n adminId?: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\nexport class VorimEntra {\n private sdk: VorimSDK;\n private agentId: string;\n private tenantId: string;\n private adminId?: string;\n private minTrustScore: number;\n private escalatePrivileged: boolean;\n private escalationTimeoutMs: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: EntraGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] Entra integration requires an agentId.');\n if (!config?.tenantId) throw new Error('[vorim] Entra integration requires a tenantId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.tenantId = config.tenantId;\n this.adminId = config.adminId;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.escalatePrivileged = config.escalatePrivileged ?? true;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 300_000;\n this.onError = config.onError ?? 'closed';\n }\n\n private isPrivileged(operation: string): boolean {\n return ESCALATION_OPS.has(operation);\n }\n\n private scopeFor(operation: string): PermissionScope {\n return OPERATION_SCOPE[operation] ?? 'agent:write';\n }\n\n async authorize(\n action: EntraAction,\n ): Promise<{ authorized: boolean; reason?: string; outcome: EntraOutcome; adminId?: string; decisionId?: string }> {\n const privileged = this.isPrivileged(action.operation);\n const scope = this.scopeFor(action.operation);\n\n try {\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: privileged ? 'privileged-denied' : 'ordinary' };\n }\n }\n\n if (privileged) {\n if (!this.escalatePrivileged) {\n return { authorized: false, reason: `${action.operation} requires a human admin and escalatePrivileged is off`, outcome: 'privileged-denied' };\n }\n if (!this.adminId) {\n return {\n authorized: false,\n reason: `${action.operation} requires a configured adminId (the approving human admin)`,\n outcome: 'privileged-denied',\n };\n }\n const esc = await this.escalate(action, scope);\n return {\n authorized: esc.approved,\n reason: esc.approved ? undefined : (esc.reason ?? 'admin did not approve'),\n outcome: esc.approved ? 'approved-by-admin' : 'privileged-denied',\n adminId: esc.approved ? this.adminId : undefined,\n decisionId: esc.decisionId,\n };\n }\n\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true, outcome: 'ordinary', adminId: this.adminId }\n : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: 'ordinary' };\n } catch (e: any) {\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open', outcome: privileged ? 'approved-by-admin' : 'ordinary' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}`, outcome: privileged ? 'privileged-denied' : 'ordinary' };\n }\n }\n\n private async escalate(action: EntraAction, scope: PermissionScope): Promise<{ approved: boolean; reason?: string; decisionId?: string }> {\n const decision = await this.sdk.beforeAction(\n {\n agentId: this.agentId,\n actionType: 'api_request',\n actionTarget: `entra:${action.operation}`,\n requiredScope: scope,\n payload: { operation: action.operation, target_id: action.targetId, role: action.role },\n context: { integration: 'entra', tenant_id: this.tenantId, requires_human_admin: true, admin_hint: this.adminId },\n },\n { throwOnDeny: false },\n );\n if (decision.decision === 'escalate') {\n const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });\n const approved = resolved.decision === 'allow' || resolved.escalationResolution === 'approved';\n return { approved, reason: approved ? undefined : 'admin refused', decisionId: decision.decisionId };\n }\n if (decision.decision === 'allow') return { approved: true, decisionId: decision.decisionId };\n if (decision.decision === 'fallback')\n return { approved: this.onError === 'open', reason: 'runtime unreachable', decisionId: decision.decisionId };\n return { approved: false, reason: decision.reason ?? 'denied', decisionId: decision.decisionId };\n }\n\n async record(\n action: EntraAction,\n result: 'success' | 'denied' | 'error',\n extra: { reason?: string; outcome?: EntraOutcome; adminId?: string; decisionId?: string } = {},\n ): Promise<boolean> {\n const scope = this.scopeFor(action.operation);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `entra:${action.operation}${action.targetId ? ' ' + action.targetId : ''}`,\n resource: action.targetId || this.tenantId,\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: 'entra',\n tenant_id: this.tenantId,\n operation: action.operation,\n privileged: this.isPrivileged(action.operation),\n ...(action.role ? { role: action.role } : {}),\n ...(extra.outcome ? { outcome: extra.outcome } : {}),\n ...(extra.adminId ?? this.adminId ? { approved_by_admin: extra.adminId ?? this.adminId } : {}),\n ...(extra.decisionId ? { decision_id: extra.decisionId } : {}),\n ...(extra.reason ? { reason: extra.reason } : {}),\n },\n },\n { sign: true },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n async guard<T>(action: EntraAction, run: () => Promise<T>): Promise<{ receipt: EntraReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', { reason: auth.reason, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, false, 'denied', auth, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success', { outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, true, 'success', auth, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', { reason: e?.message, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n throw Object.assign(e ?? new Error('entra operation failed'), {\n vorimReceipt: this.receipt(action, true, 'error', { ...auth, reason: e?.message }, recorded),\n });\n }\n }\n\n // --- Named helpers ---------------------------------------------------------\n\n /** Guard creating a user (POST /users). Requires agent:write. */\n guardedCreateUser<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'createUser', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard disabling a user (PATCH /users/{id} accountEnabled:false). agent:write. */\n guardedDisableUser<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'disableUser', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard creating an app registration (POST /applications). agent:write. */\n guardedCreateAppRegistration<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'createAppRegistration', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard adding a client secret to an app (POST /applications/{id}/addPassword).\n * Mints a long-lived credential; always escalates to the named admin. */\n guardedAddAppSecret<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'addAppSecret', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard granting an app-role assignment. Always escalates to the named admin\n * (an application-permission grant is tenant-wide privilege). */\n guardedGrantAppRoleAssignment<T>(meta: { targetId?: string; role?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'grantAppRoleAssignment', targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);\n }\n\n /** Guard assigning a directory role (POST /roleManagement/directory/roleAssignments).\n * Always escalates to the named admin. Pass the role (e.g. 'Global Administrator'). */\n guardedAssignDirectoryRole<T>(meta: { targetId?: string; role?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'assignDirectoryRole', targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);\n }\n\n private receipt(\n action: EntraAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n auth: { reason?: string; outcome?: EntraOutcome; adminId?: string; decisionId?: string },\n recorded: boolean,\n ): EntraReceipt {\n return {\n authorized,\n agentId: this.agentId,\n tenantId: this.tenantId,\n operation: action.operation,\n targetId: action.targetId,\n role: action.role,\n privileged: this.isPrivileged(action.operation),\n outcome: auth.outcome ?? 'ordinary',\n adminId: auth.adminId ?? this.adminId,\n result,\n scope: this.scopeFor(action.operation),\n reason: auth.reason,\n decisionId: auth.decisionId,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimEntra guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimEntra } from '@vorim/sdk/integrations/entra';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const entra = createVorimEntra(vorim, {\n * agentId: 'agid_abc123',\n * tenantId: 'contoso.onmicrosoft.com',\n * adminId: 'admin_42',\n * });\n *\n * const { receipt } = await entra.guardedAssignDirectoryRole(\n * { targetId: 'user_9', role: 'Global Administrator' },\n * () => graphClient.api('/roleManagement/directory/roleAssignments').post(body),\n * );\n * ```\n */\nexport function createVorimEntra(sdk: VorimSDK, config: EntraGuardConfig): VorimEntra {\n return new VorimEntra(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2EA,IAAM,iBAAiB,oBAAI,IAAY,CAAC,uBAAuB,gBAAgB,wBAAwB,CAAC;AAExG,IAAM,kBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,uBAAuB;AAAA,EACvB,cAAc;AAAA,EACd,wBAAwB;AAAA,EACxB,qBAAqB;AACvB;AA+CO,IAAM,aAAN,MAAiB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAA0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