@vorionsys/a3i 0.1.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/LICENSE +190 -0
- package/dist/api/handlers.d.ts +231 -0
- package/dist/api/handlers.d.ts.map +1 -0
- package/dist/api/handlers.js +279 -0
- package/dist/api/handlers.js.map +1 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +27 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middleware.d.ts +106 -0
- package/dist/api/middleware.d.ts.map +1 -0
- package/dist/api/middleware.js +186 -0
- package/dist/api/middleware.js.map +1 -0
- package/dist/api/routes.d.ts +41 -0
- package/dist/api/routes.d.ts.map +1 -0
- package/dist/api/routes.js +91 -0
- package/dist/api/routes.js.map +1 -0
- package/dist/authorization/constraints.d.ts +75 -0
- package/dist/authorization/constraints.d.ts.map +1 -0
- package/dist/authorization/constraints.js +302 -0
- package/dist/authorization/constraints.js.map +1 -0
- package/dist/authorization/decision.d.ts +98 -0
- package/dist/authorization/decision.d.ts.map +1 -0
- package/dist/authorization/decision.js +202 -0
- package/dist/authorization/decision.js.map +1 -0
- package/dist/authorization/engine.d.ts +141 -0
- package/dist/authorization/engine.d.ts.map +1 -0
- package/dist/authorization/engine.js +339 -0
- package/dist/authorization/engine.js.map +1 -0
- package/dist/authorization/index.d.ts +10 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +13 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/banding/band-calculator.d.ts +137 -0
- package/dist/banding/band-calculator.d.ts.map +1 -0
- package/dist/banding/band-calculator.js +252 -0
- package/dist/banding/band-calculator.js.map +1 -0
- package/dist/banding/bands.d.ts +56 -0
- package/dist/banding/bands.d.ts.map +1 -0
- package/dist/banding/bands.js +200 -0
- package/dist/banding/bands.js.map +1 -0
- package/dist/banding/hysteresis.d.ts +64 -0
- package/dist/banding/hysteresis.d.ts.map +1 -0
- package/dist/banding/hysteresis.js +143 -0
- package/dist/banding/hysteresis.js.map +1 -0
- package/dist/banding/index.d.ts +10 -0
- package/dist/banding/index.d.ts.map +1 -0
- package/dist/banding/index.js +10 -0
- package/dist/banding/index.js.map +1 -0
- package/dist/canary/canary-service.d.ts +123 -0
- package/dist/canary/canary-service.d.ts.map +1 -0
- package/dist/canary/canary-service.js +353 -0
- package/dist/canary/canary-service.js.map +1 -0
- package/dist/canary/index.d.ts +12 -0
- package/dist/canary/index.d.ts.map +1 -0
- package/dist/canary/index.js +14 -0
- package/dist/canary/index.js.map +1 -0
- package/dist/canary/probe-library.d.ts +43 -0
- package/dist/canary/probe-library.d.ts.map +1 -0
- package/dist/canary/probe-library.js +655 -0
- package/dist/canary/probe-library.js.map +1 -0
- package/dist/execution/engine.d.ts +120 -0
- package/dist/execution/engine.d.ts.map +1 -0
- package/dist/execution/engine.js +220 -0
- package/dist/execution/engine.js.map +1 -0
- package/dist/execution/index.d.ts +7 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +7 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/gate/index.d.ts +12 -0
- package/dist/gate/index.d.ts.map +1 -0
- package/dist/gate/index.js +14 -0
- package/dist/gate/index.js.map +1 -0
- package/dist/gate/pre-action-gate.d.ts +87 -0
- package/dist/gate/pre-action-gate.d.ts.map +1 -0
- package/dist/gate/pre-action-gate.js +286 -0
- package/dist/gate/pre-action-gate.js.map +1 -0
- package/dist/gate/risk-classifier.d.ts +43 -0
- package/dist/gate/risk-classifier.d.ts.map +1 -0
- package/dist/gate/risk-classifier.js +157 -0
- package/dist/gate/risk-classifier.js.map +1 -0
- package/dist/hooks/executor.d.ts +56 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +217 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +45 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +49 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/manager.d.ts +156 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +267 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/registry.d.ts +130 -0
- package/dist/hooks/registry.d.ts.map +1 -0
- package/dist/hooks/registry.js +238 -0
- package/dist/hooks/registry.js.map +1 -0
- package/dist/hooks/types.d.ts +226 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +41 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/observation/attestation.d.ts +102 -0
- package/dist/observation/attestation.d.ts.map +1 -0
- package/dist/observation/attestation.js +127 -0
- package/dist/observation/attestation.js.map +1 -0
- package/dist/observation/ceilings.d.ts +60 -0
- package/dist/observation/ceilings.d.ts.map +1 -0
- package/dist/observation/ceilings.js +110 -0
- package/dist/observation/ceilings.js.map +1 -0
- package/dist/observation/index.d.ts +11 -0
- package/dist/observation/index.d.ts.map +1 -0
- package/dist/observation/index.js +14 -0
- package/dist/observation/index.js.map +1 -0
- package/dist/observation/tiers.d.ts +96 -0
- package/dist/observation/tiers.d.ts.map +1 -0
- package/dist/observation/tiers.js +225 -0
- package/dist/observation/tiers.js.map +1 -0
- package/dist/orchestrator/index.d.ts +8 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +8 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +225 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +302 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/orchestrator/proof-plane-adapter.d.ts +80 -0
- package/dist/orchestrator/proof-plane-adapter.d.ts.map +1 -0
- package/dist/orchestrator/proof-plane-adapter.js +78 -0
- package/dist/orchestrator/proof-plane-adapter.js.map +1 -0
- package/dist/trust/calculator.d.ts +60 -0
- package/dist/trust/calculator.d.ts.map +1 -0
- package/dist/trust/calculator.js +163 -0
- package/dist/trust/calculator.js.map +1 -0
- package/dist/trust/dimensions.d.ts +133 -0
- package/dist/trust/dimensions.d.ts.map +1 -0
- package/dist/trust/dimensions.js +257 -0
- package/dist/trust/dimensions.js.map +1 -0
- package/dist/trust/index.d.ts +14 -0
- package/dist/trust/index.d.ts.map +1 -0
- package/dist/trust/index.js +25 -0
- package/dist/trust/index.js.map +1 -0
- package/dist/trust/profile-service.d.ts +179 -0
- package/dist/trust/profile-service.d.ts.map +1 -0
- package/dist/trust/profile-service.js +378 -0
- package/dist/trust/profile-service.js.map +1 -0
- package/dist/trust/profile-store.d.ts +122 -0
- package/dist/trust/profile-store.d.ts.map +1 -0
- package/dist/trust/profile-store.js +132 -0
- package/dist/trust/profile-store.js.map +1 -0
- package/dist/trust/trust-calculator.d.ts +111 -0
- package/dist/trust/trust-calculator.d.ts.map +1 -0
- package/dist/trust/trust-calculator.js +271 -0
- package/dist/trust/trust-calculator.js.map +1 -0
- package/dist/trust/trust-dynamics.d.ts +152 -0
- package/dist/trust/trust-dynamics.d.ts.map +1 -0
- package/dist/trust/trust-dynamics.js +302 -0
- package/dist/trust/trust-dynamics.js.map +1 -0
- package/dist/trust/weights.d.ts +57 -0
- package/dist/trust/weights.d.ts.map +1 -0
- package/dist/trust/weights.js +75 -0
- package/dist/trust/weights.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authorization Engine - Core authorization decision-making
|
|
3
|
+
*
|
|
4
|
+
* The AuthorizationEngine is the central component of A3I that makes
|
|
5
|
+
* permit/deny decisions for agent intents based on:
|
|
6
|
+
* - Agent's trust profile and band
|
|
7
|
+
* - Intent characteristics (action type, data sensitivity, reversibility)
|
|
8
|
+
* - Policy rules and constraints
|
|
9
|
+
* - Context factors
|
|
10
|
+
* - Hook system for extensibility
|
|
11
|
+
*
|
|
12
|
+
* Key principles:
|
|
13
|
+
* - Deterministic: Same inputs always produce same outputs
|
|
14
|
+
* - Fast: <50ms latency target for decisions
|
|
15
|
+
* - Auditable: All decisions logged with reasoning
|
|
16
|
+
* - Extensible: Hooks for pre/post authorization
|
|
17
|
+
*/
|
|
18
|
+
import { TrustBand, ActionType, DataSensitivity, Reversibility, DenialReason, } from '@vorionsys/contracts';
|
|
19
|
+
import { generateConstraints, BAND_CONSTRAINT_PRESETS, } from './constraints.js';
|
|
20
|
+
import { buildPermitDecision, buildDenyDecision, getRemediations, } from './decision.js';
|
|
21
|
+
import { TrustProfileService } from '../trust/profile-service.js';
|
|
22
|
+
/**
|
|
23
|
+
* Minimum trust band required for each action type
|
|
24
|
+
*/
|
|
25
|
+
export const ACTION_TYPE_REQUIREMENTS = {
|
|
26
|
+
[ActionType.READ]: TrustBand.T1_OBSERVED,
|
|
27
|
+
[ActionType.WRITE]: TrustBand.T2_PROVISIONAL,
|
|
28
|
+
[ActionType.DELETE]: TrustBand.T2_PROVISIONAL,
|
|
29
|
+
[ActionType.EXECUTE]: TrustBand.T2_PROVISIONAL,
|
|
30
|
+
[ActionType.COMMUNICATE]: TrustBand.T2_PROVISIONAL,
|
|
31
|
+
[ActionType.TRANSFER]: TrustBand.T3_MONITORED,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Minimum trust band required for each data sensitivity level
|
|
35
|
+
*/
|
|
36
|
+
export const DATA_SENSITIVITY_REQUIREMENTS = {
|
|
37
|
+
[DataSensitivity.PUBLIC]: TrustBand.T1_OBSERVED,
|
|
38
|
+
[DataSensitivity.INTERNAL]: TrustBand.T2_PROVISIONAL,
|
|
39
|
+
[DataSensitivity.CONFIDENTIAL]: TrustBand.T3_MONITORED,
|
|
40
|
+
[DataSensitivity.RESTRICTED]: TrustBand.T4_STANDARD,
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Trust band adjustments for reversibility
|
|
44
|
+
*/
|
|
45
|
+
export const REVERSIBILITY_ADJUSTMENTS = {
|
|
46
|
+
[Reversibility.REVERSIBLE]: 0,
|
|
47
|
+
[Reversibility.PARTIALLY_REVERSIBLE]: 0,
|
|
48
|
+
[Reversibility.IRREVERSIBLE]: 1, // Requires one band higher
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* No-op proof plane logger for when proof plane is not connected
|
|
52
|
+
*/
|
|
53
|
+
export const noopProofLogger = {
|
|
54
|
+
async logDecision() { },
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* AuthorizationEngine - Makes permit/deny decisions for agent intents
|
|
58
|
+
*/
|
|
59
|
+
export class AuthorizationEngine {
|
|
60
|
+
profileService;
|
|
61
|
+
actionRequirements;
|
|
62
|
+
sensitivityRequirements;
|
|
63
|
+
proofLogger;
|
|
64
|
+
hookManager;
|
|
65
|
+
config;
|
|
66
|
+
constructor(config = {}) {
|
|
67
|
+
this.profileService = config.profileService ?? new TrustProfileService();
|
|
68
|
+
this.actionRequirements = {
|
|
69
|
+
...ACTION_TYPE_REQUIREMENTS,
|
|
70
|
+
...config.actionTypeRequirements,
|
|
71
|
+
};
|
|
72
|
+
this.sensitivityRequirements = {
|
|
73
|
+
...DATA_SENSITIVITY_REQUIREMENTS,
|
|
74
|
+
...config.dataSensitivityRequirements,
|
|
75
|
+
};
|
|
76
|
+
this.proofLogger = config.proofLogger ?? noopProofLogger;
|
|
77
|
+
this.hookManager = config.hookManager;
|
|
78
|
+
this.config = {
|
|
79
|
+
defaultPolicySetId: config.defaultPolicySetId ?? 'default',
|
|
80
|
+
decisionValidityMs: config.decisionValidityMs ?? 5 * 60 * 1000,
|
|
81
|
+
strictMode: config.strictMode ?? false,
|
|
82
|
+
enableHooks: config.enableHooks ?? (config.hookManager !== undefined),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Authorize an intent
|
|
87
|
+
*
|
|
88
|
+
* This is the main entry point for authorization decisions.
|
|
89
|
+
* Returns a Decision object indicating whether the intent is permitted.
|
|
90
|
+
*
|
|
91
|
+
* Hook integration:
|
|
92
|
+
* - PRE_AUTHORIZE hooks run before evaluation (can abort)
|
|
93
|
+
* - POST_AUTHORIZE hooks run after decision is made
|
|
94
|
+
*/
|
|
95
|
+
async authorize(request) {
|
|
96
|
+
const startTime = Date.now();
|
|
97
|
+
const { intent, constraintOptions, policySetId } = request;
|
|
98
|
+
const now = new Date();
|
|
99
|
+
const buildOptions = {
|
|
100
|
+
policySetId: policySetId ?? this.config.defaultPolicySetId,
|
|
101
|
+
validityDurationMs: this.config.decisionValidityMs,
|
|
102
|
+
now,
|
|
103
|
+
};
|
|
104
|
+
// Check if intent is expired
|
|
105
|
+
if (intent.expiresAt && intent.expiresAt < now) {
|
|
106
|
+
const decision = buildDenyDecision(intent, null, DenialReason.EXPIRED_INTENT, ['Intent has expired'], buildOptions);
|
|
107
|
+
decision.latencyMs = Date.now() - startTime;
|
|
108
|
+
await this.proofLogger.logDecision(decision, intent);
|
|
109
|
+
return {
|
|
110
|
+
decision,
|
|
111
|
+
remediations: getRemediations(DenialReason.EXPIRED_INTENT),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// Get trust profile for agent
|
|
115
|
+
const profile = await this.profileService.get(intent.agentId);
|
|
116
|
+
if (!profile) {
|
|
117
|
+
const decision = buildDenyDecision(intent, null, DenialReason.INSUFFICIENT_TRUST, ['No trust profile found for agent', 'Agent must be registered before authorization'], buildOptions);
|
|
118
|
+
decision.latencyMs = Date.now() - startTime;
|
|
119
|
+
await this.proofLogger.logDecision(decision, intent);
|
|
120
|
+
return {
|
|
121
|
+
decision,
|
|
122
|
+
remediations: ['Register agent with trust profile before requesting authorization'],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Execute pre-authorize hooks
|
|
126
|
+
let preAuthorizeResult;
|
|
127
|
+
if (this.config.enableHooks && this.hookManager) {
|
|
128
|
+
preAuthorizeResult = await this.hookManager.executePreAuthorize({
|
|
129
|
+
correlationId: intent.correlationId,
|
|
130
|
+
intent,
|
|
131
|
+
profile,
|
|
132
|
+
});
|
|
133
|
+
// If a hook aborted, deny the authorization
|
|
134
|
+
if (preAuthorizeResult.aborted) {
|
|
135
|
+
const decision = buildDenyDecision(intent, profile, DenialReason.POLICY_VIOLATION, [
|
|
136
|
+
'Authorization aborted by pre-authorize hook',
|
|
137
|
+
`Reason: ${preAuthorizeResult.abortReason ?? 'No reason provided'}`,
|
|
138
|
+
], buildOptions);
|
|
139
|
+
decision.latencyMs = Date.now() - startTime;
|
|
140
|
+
await this.proofLogger.logDecision(decision, intent);
|
|
141
|
+
return {
|
|
142
|
+
decision,
|
|
143
|
+
remediations: [preAuthorizeResult.abortReason ?? 'Pre-authorize hook aborted the request'],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Evaluate authorization
|
|
148
|
+
const evaluation = this.evaluate(intent, profile);
|
|
149
|
+
let response;
|
|
150
|
+
if (evaluation.permitted) {
|
|
151
|
+
// Generate constraints
|
|
152
|
+
const constraints = generateConstraints(profile.band, intent, constraintOptions);
|
|
153
|
+
const decision = buildPermitDecision(intent, profile, constraints, evaluation.reasoning, buildOptions);
|
|
154
|
+
decision.latencyMs = Date.now() - startTime;
|
|
155
|
+
await this.proofLogger.logDecision(decision, intent);
|
|
156
|
+
response = { decision };
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const decision = buildDenyDecision(intent, profile, evaluation.denialReason, evaluation.reasoning, buildOptions);
|
|
160
|
+
decision.latencyMs = Date.now() - startTime;
|
|
161
|
+
await this.proofLogger.logDecision(decision, intent);
|
|
162
|
+
response = {
|
|
163
|
+
decision,
|
|
164
|
+
remediations: getRemediations(evaluation.denialReason),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
// Execute post-authorize hooks
|
|
168
|
+
if (this.config.enableHooks && this.hookManager) {
|
|
169
|
+
await this.hookManager.executePostAuthorize({
|
|
170
|
+
correlationId: intent.correlationId,
|
|
171
|
+
intent,
|
|
172
|
+
decision: response.decision,
|
|
173
|
+
profile,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return response;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Evaluate an intent against a trust profile
|
|
180
|
+
* This is the core authorization logic - deterministic and fast
|
|
181
|
+
*/
|
|
182
|
+
evaluate(intent, profile) {
|
|
183
|
+
const reasoning = [];
|
|
184
|
+
// Calculate minimum required trust band
|
|
185
|
+
const actionBand = this.actionRequirements[intent.actionType];
|
|
186
|
+
const sensitivityBand = this.sensitivityRequirements[intent.dataSensitivity];
|
|
187
|
+
const reversibilityAdjustment = REVERSIBILITY_ADJUSTMENTS[intent.reversibility];
|
|
188
|
+
// Take the maximum of all requirements
|
|
189
|
+
let requiredBand = Math.max(actionBand, sensitivityBand);
|
|
190
|
+
// Apply reversibility adjustment
|
|
191
|
+
if (reversibilityAdjustment > 0) {
|
|
192
|
+
requiredBand = Math.min(requiredBand + reversibilityAdjustment, TrustBand.T5_TRUSTED);
|
|
193
|
+
}
|
|
194
|
+
reasoning.push(`Action type '${intent.actionType}' requires band ${TrustBand[actionBand]}`, `Data sensitivity '${intent.dataSensitivity}' requires band ${TrustBand[sensitivityBand]}`);
|
|
195
|
+
if (reversibilityAdjustment > 0) {
|
|
196
|
+
reasoning.push(`Irreversible action increases requirement by ${reversibilityAdjustment} band(s)`);
|
|
197
|
+
}
|
|
198
|
+
reasoning.push(`Minimum required band: ${TrustBand[requiredBand]}`);
|
|
199
|
+
reasoning.push(`Agent's current band: ${TrustBand[profile.band]} (score: ${profile.adjustedScore})`);
|
|
200
|
+
// Check band requirement
|
|
201
|
+
if (profile.band < requiredBand) {
|
|
202
|
+
reasoning.push(`DENIED: Agent band ${TrustBand[profile.band]} is below required ${TrustBand[requiredBand]}`);
|
|
203
|
+
return {
|
|
204
|
+
permitted: false,
|
|
205
|
+
reasoning,
|
|
206
|
+
denialReason: DenialReason.INSUFFICIENT_TRUST,
|
|
207
|
+
requiredBand,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
// Check T0 always denied
|
|
211
|
+
if (profile.band === TrustBand.T0_SANDBOX) {
|
|
212
|
+
reasoning.push('DENIED: T0_SANDBOX agents cannot perform any actions');
|
|
213
|
+
return {
|
|
214
|
+
permitted: false,
|
|
215
|
+
reasoning,
|
|
216
|
+
denialReason: DenialReason.INSUFFICIENT_TRUST,
|
|
217
|
+
requiredBand,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Check resource scope restrictions
|
|
221
|
+
const scopeCheck = this.checkResourceScope(intent, profile);
|
|
222
|
+
if (!scopeCheck.allowed) {
|
|
223
|
+
reasoning.push(`DENIED: ${scopeCheck.reason}`);
|
|
224
|
+
return {
|
|
225
|
+
permitted: false,
|
|
226
|
+
reasoning,
|
|
227
|
+
denialReason: DenialReason.RESOURCE_RESTRICTED,
|
|
228
|
+
requiredBand,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// Check context restrictions
|
|
232
|
+
const contextCheck = this.checkContext(intent, profile);
|
|
233
|
+
if (!contextCheck.allowed) {
|
|
234
|
+
reasoning.push(`DENIED: ${contextCheck.reason}`);
|
|
235
|
+
return {
|
|
236
|
+
permitted: false,
|
|
237
|
+
reasoning,
|
|
238
|
+
denialReason: DenialReason.CONTEXT_MISMATCH,
|
|
239
|
+
requiredBand,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
// All checks passed
|
|
243
|
+
reasoning.push('PERMITTED: All authorization checks passed');
|
|
244
|
+
return {
|
|
245
|
+
permitted: true,
|
|
246
|
+
reasoning,
|
|
247
|
+
denialReason: DenialReason.POLICY_VIOLATION, // Not used
|
|
248
|
+
requiredBand,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Check resource scope restrictions
|
|
253
|
+
*/
|
|
254
|
+
checkResourceScope(intent, profile) {
|
|
255
|
+
const preset = BAND_CONSTRAINT_PRESETS[profile.band];
|
|
256
|
+
// Check if band allows any data scopes
|
|
257
|
+
if (preset.defaultDataScopes.length === 0) {
|
|
258
|
+
return { allowed: false, reason: 'Band does not allow any data access' };
|
|
259
|
+
}
|
|
260
|
+
// Check for restricted resources at lower bands
|
|
261
|
+
if (intent.dataSensitivity === DataSensitivity.RESTRICTED &&
|
|
262
|
+
!preset.defaultDataScopes.includes('restricted') &&
|
|
263
|
+
!preset.defaultDataScopes.includes('*')) {
|
|
264
|
+
return {
|
|
265
|
+
allowed: false,
|
|
266
|
+
reason: 'Restricted data requires higher trust band',
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return { allowed: true };
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Check context restrictions
|
|
273
|
+
*/
|
|
274
|
+
checkContext(intent, profile) {
|
|
275
|
+
const context = intent.context;
|
|
276
|
+
// Check production environment restrictions
|
|
277
|
+
if (context?.environment === 'production' && profile.band < TrustBand.T3_MONITORED) {
|
|
278
|
+
return {
|
|
279
|
+
allowed: false,
|
|
280
|
+
reason: 'Production environment requires T3+ trust band',
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
// Check PII handling restrictions
|
|
284
|
+
if (context?.handlesPii && profile.band < TrustBand.T2_PROVISIONAL) {
|
|
285
|
+
return {
|
|
286
|
+
allowed: false,
|
|
287
|
+
reason: 'PII handling requires T2+ trust band',
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
// Check PHI handling restrictions
|
|
291
|
+
if (context?.handlesPhi && profile.band < TrustBand.T3_MONITORED) {
|
|
292
|
+
return {
|
|
293
|
+
allowed: false,
|
|
294
|
+
reason: 'PHI handling requires T3+ trust band',
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
// In strict mode, require domain match
|
|
298
|
+
if (this.config.strictMode && context?.domain) {
|
|
299
|
+
// This would be extended with actual domain policy checks
|
|
300
|
+
}
|
|
301
|
+
return { allowed: true };
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Quick check if an agent can perform an action type
|
|
305
|
+
* (Without full profile lookup - uses cached band if available)
|
|
306
|
+
*/
|
|
307
|
+
canPerformActionType(band, actionType) {
|
|
308
|
+
return band >= this.actionRequirements[actionType];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Quick check if an agent can access data sensitivity level
|
|
312
|
+
*/
|
|
313
|
+
canAccessDataSensitivity(band, sensitivity) {
|
|
314
|
+
return band >= this.sensitivityRequirements[sensitivity];
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get the minimum band required for an action + sensitivity combination
|
|
318
|
+
*/
|
|
319
|
+
getRequiredBand(actionType, dataSensitivity, reversibility = Reversibility.REVERSIBLE) {
|
|
320
|
+
const actionBand = this.actionRequirements[actionType];
|
|
321
|
+
const sensitivityBand = this.sensitivityRequirements[dataSensitivity];
|
|
322
|
+
const adjustment = REVERSIBILITY_ADJUSTMENTS[reversibility];
|
|
323
|
+
const required = Math.max(actionBand, sensitivityBand) + adjustment;
|
|
324
|
+
return Math.min(required, TrustBand.T5_TRUSTED);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get the profile service
|
|
328
|
+
*/
|
|
329
|
+
getProfileService() {
|
|
330
|
+
return this.profileService;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Create an AuthorizationEngine with default configuration
|
|
335
|
+
*/
|
|
336
|
+
export function createAuthorizationEngine(config) {
|
|
337
|
+
return new AuthorizationEngine(config);
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/authorization/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,SAAS,EACT,UAAU,EACV,eAAe,EACf,aAAa,EACb,YAAY,GAKb,MAAM,sBAAs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,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,wBAAwB,CAAC,IAAe,EAAE,WAA4B;QACpE,OAAO,IAAI,IAAI,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,eAAe,CACb,UAAsB,EACtB,eAAgC,EAChC,gBAA+B,aAAa,CAAC,UAAU;QAEvD,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACvD,MAAM,eAAe,GAAG,IAAI,CAAC,uBAAuB,CAAC,eAAe,CAAC,CAAC;QACtE,MAAM,UAAU,GAAG,yBAAyB,CAAC,aAAa,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,GAAG,UAAU,CAAC;QACpE,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,UAAU,CAAc,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAkC;IAElC,OAAO,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A3I Authorization Module
|
|
3
|
+
*
|
|
4
|
+
* Core authorization functionality including the authorization engine,
|
|
5
|
+
* constraint generation, and decision building.
|
|
6
|
+
*/
|
|
7
|
+
export { generateConstraints, constraintsPermit, mergeConstraints, BAND_CONSTRAINT_PRESETS, DEFAULT_APPROVAL_POLICIES, type ConstraintPreset, type ApprovalPolicy, type ConstraintGenerationOptions, } from './constraints.js';
|
|
8
|
+
export { buildPermitDecision, buildDenyDecision, getRemediations, determineDenialReason, summarizeDecision, isDecisionValid, DecisionBuilder, type DecisionBuildOptions, type PermitResult, type DenyResult, type AuthorizationResult, } from './decision.js';
|
|
9
|
+
export { AuthorizationEngine, createAuthorizationEngine, ACTION_TYPE_REQUIREMENTS, DATA_SENSITIVITY_REQUIREMENTS, REVERSIBILITY_ADJUSTMENTS, noopProofLogger, type AuthorizationEngineConfig, type AuthorizeRequest, type ProofPlaneLogger, } from './engine.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,2BAA2B,GACjC,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,mBAAmB,GACzB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A3I Authorization Module
|
|
3
|
+
*
|
|
4
|
+
* Core authorization functionality including the authorization engine,
|
|
5
|
+
* constraint generation, and decision building.
|
|
6
|
+
*/
|
|
7
|
+
// Constraints
|
|
8
|
+
export { generateConstraints, constraintsPermit, mergeConstraints, BAND_CONSTRAINT_PRESETS, DEFAULT_APPROVAL_POLICIES, } from './constraints.js';
|
|
9
|
+
// Decision building
|
|
10
|
+
export { buildPermitDecision, buildDenyDecision, getRemediations, determineDenialReason, summarizeDecision, isDecisionValid, DecisionBuilder, } from './decision.js';
|
|
11
|
+
// Authorization Engine
|
|
12
|
+
export { AuthorizationEngine, createAuthorizationEngine, ACTION_TYPE_REQUIREMENTS, DATA_SENSITIVITY_REQUIREMENTS, REVERSIBILITY_ADJUSTMENTS, noopProofLogger, } from './engine.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc;AACd,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,yBAAyB,GAI1B,MAAM,kBAAkB,CAAC;AAE1B,oBAAoB;AACpB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAKhB,MAAM,eAAe,CAAC;AAEvB,uBAAuB;AACvB,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,GAIhB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BandCalculator - Trust band management with asymmetric transitions
|
|
3
|
+
*
|
|
4
|
+
* Key principles:
|
|
5
|
+
* - Fast demotion: Safety-critical, immediate response to issues
|
|
6
|
+
* - Slow promotion: Build trust gradually over time
|
|
7
|
+
* - Hysteresis: Prevent oscillation near thresholds
|
|
8
|
+
* - History tracking: Evidence-based promotion decisions
|
|
9
|
+
*/
|
|
10
|
+
import { TrustBand, type BandingConfig } from '@vorionsys/contracts';
|
|
11
|
+
import { type BandHistoryEntry } from './hysteresis.js';
|
|
12
|
+
/**
|
|
13
|
+
* Band transition types
|
|
14
|
+
*/
|
|
15
|
+
export declare enum TransitionType {
|
|
16
|
+
NONE = "none",
|
|
17
|
+
PROMOTION = "promotion",
|
|
18
|
+
DEMOTION = "demotion"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result of a band transition attempt
|
|
22
|
+
*/
|
|
23
|
+
export interface TransitionResult {
|
|
24
|
+
/** Was the transition allowed? */
|
|
25
|
+
allowed: boolean;
|
|
26
|
+
/** Type of transition */
|
|
27
|
+
transitionType: TransitionType;
|
|
28
|
+
/** Previous band */
|
|
29
|
+
previousBand: TrustBand;
|
|
30
|
+
/** New band (same as previous if not allowed) */
|
|
31
|
+
newBand: TrustBand;
|
|
32
|
+
/** Reason for the result */
|
|
33
|
+
reason: string;
|
|
34
|
+
/** Days until promotion (if blocked by time) */
|
|
35
|
+
daysUntilPromotion?: number;
|
|
36
|
+
/** Score needed for transition */
|
|
37
|
+
scoreThreshold?: number;
|
|
38
|
+
/** Timestamp */
|
|
39
|
+
timestamp: Date;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Band stability metrics
|
|
43
|
+
*/
|
|
44
|
+
export interface BandStability {
|
|
45
|
+
/** Current band */
|
|
46
|
+
currentBand: TrustBand;
|
|
47
|
+
/** Days at current band */
|
|
48
|
+
daysAtBand: number;
|
|
49
|
+
/** Number of transitions in last 30 days */
|
|
50
|
+
recentTransitions: number;
|
|
51
|
+
/** Is the band stable? */
|
|
52
|
+
stable: boolean;
|
|
53
|
+
/** Stability score (0-1) */
|
|
54
|
+
stabilityScore: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Band transition event for audit trail
|
|
58
|
+
*/
|
|
59
|
+
export interface BandTransitionEvent {
|
|
60
|
+
/** Unique event ID */
|
|
61
|
+
eventId: string;
|
|
62
|
+
/** Agent ID */
|
|
63
|
+
agentId: string;
|
|
64
|
+
/** Transition type */
|
|
65
|
+
transitionType: TransitionType;
|
|
66
|
+
/** Previous band */
|
|
67
|
+
fromBand: TrustBand;
|
|
68
|
+
/** New band */
|
|
69
|
+
toBand: TrustBand;
|
|
70
|
+
/** Score at transition */
|
|
71
|
+
score: number;
|
|
72
|
+
/** Reason for transition */
|
|
73
|
+
reason: string;
|
|
74
|
+
/** Timestamp */
|
|
75
|
+
timestamp: Date;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* BandCalculator - Manages trust band transitions
|
|
79
|
+
*/
|
|
80
|
+
export declare class BandCalculator {
|
|
81
|
+
private readonly config;
|
|
82
|
+
private readonly hysteresis;
|
|
83
|
+
private readonly historyByAgent;
|
|
84
|
+
private readonly transitionEvents;
|
|
85
|
+
constructor(config?: Partial<BandingConfig>);
|
|
86
|
+
/**
|
|
87
|
+
* Get the trust band for a score
|
|
88
|
+
*/
|
|
89
|
+
getBand(score: number): TrustBand;
|
|
90
|
+
/**
|
|
91
|
+
* Evaluate a potential band transition
|
|
92
|
+
*/
|
|
93
|
+
evaluateTransition(agentId: string, currentBand: TrustBand, newScore: number, options?: {
|
|
94
|
+
now?: Date;
|
|
95
|
+
}): TransitionResult;
|
|
96
|
+
/**
|
|
97
|
+
* Evaluate a demotion (always immediate for safety)
|
|
98
|
+
*/
|
|
99
|
+
private evaluateDemotion;
|
|
100
|
+
/**
|
|
101
|
+
* Evaluate a promotion (requires time at current band)
|
|
102
|
+
*/
|
|
103
|
+
private evaluatePromotion;
|
|
104
|
+
/**
|
|
105
|
+
* Record a band transition
|
|
106
|
+
*/
|
|
107
|
+
private recordTransition;
|
|
108
|
+
/**
|
|
109
|
+
* Record a score snapshot (for history tracking)
|
|
110
|
+
*/
|
|
111
|
+
recordScoreSnapshot(agentId: string, band: TrustBand, score: number, timestamp?: Date): void;
|
|
112
|
+
/**
|
|
113
|
+
* Get band history for an agent
|
|
114
|
+
*/
|
|
115
|
+
getHistory(agentId: string): BandHistoryEntry[];
|
|
116
|
+
/**
|
|
117
|
+
* Get transition events for an agent
|
|
118
|
+
*/
|
|
119
|
+
getTransitionEvents(agentId: string): BandTransitionEvent[];
|
|
120
|
+
/**
|
|
121
|
+
* Calculate band stability metrics
|
|
122
|
+
*/
|
|
123
|
+
calculateStability(agentId: string, now?: Date): BandStability;
|
|
124
|
+
/**
|
|
125
|
+
* Clear history for an agent (for testing)
|
|
126
|
+
*/
|
|
127
|
+
clearHistory(agentId: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* Get configuration
|
|
130
|
+
*/
|
|
131
|
+
getConfig(): Readonly<BandingConfig>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a BandCalculator with default configuration
|
|
135
|
+
*/
|
|
136
|
+
export declare function createBandCalculator(config?: Partial<BandingConfig>): BandCalculator;
|
|
137
|
+
//# sourceMappingURL=band-calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"band-calculator.d.ts","sourceRoot":"","sources":["../../src/banding/band-calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAA0B,MAAM,sBAAsB,CAAC;AAE7F,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE9E;;GAEG;AACH,oBAAY,cAAc;IACxB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,yBAAyB;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,oBAAoB;IACpB,YAAY,EAAE,SAAS,CAAC;IACxB,iDAAiD;IACjD,OAAO,EAAE,SAAS,CAAC;IACnB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kCAAkC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAE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