@highflame/policy 1.1.3
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/actions.gen.d.ts +29 -0
- package/dist/actions.gen.d.ts.map +1 -0
- package/dist/actions.gen.js +31 -0
- package/dist/actions.gen.js.map +1 -0
- package/dist/builder.d.ts +189 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +385 -0
- package/dist/builder.js.map +1 -0
- package/dist/context.gen.d.ts +99 -0
- package/dist/context.gen.d.ts.map +1 -0
- package/dist/context.gen.js +103 -0
- package/dist/context.gen.js.map +1 -0
- package/dist/engine.d.ts +92 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +203 -0
- package/dist/engine.js.map +1 -0
- package/dist/entities.gen.d.ts +45 -0
- package/dist/entities.gen.d.ts.map +1 -0
- package/dist/entities.gen.js +39 -0
- package/dist/entities.gen.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.gen.d.ts +6 -0
- package/dist/schema.gen.d.ts.map +1 -0
- package/dist/schema.gen.js +301 -0
- package/dist/schema.gen.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -0
- package/src/actions.gen.ts +36 -0
- package/src/builder.ts +478 -0
- package/src/context.gen.ts +107 -0
- package/src/engine.ts +252 -0
- package/src/entities.gen.ts +60 -0
- package/src/index.ts +14 -0
- package/src/schema.gen.ts +301 -0
- package/src/types.ts +15 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EntityUID } from './entities.gen.js';
|
|
2
|
+
/**
|
|
3
|
+
* Action types defined in the Highflame Cedar schema.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ActionType: {
|
|
6
|
+
readonly AccessServerResource: "access_server_resource";
|
|
7
|
+
readonly CallTool: "call_tool";
|
|
8
|
+
readonly ConnectServer: "connect_server";
|
|
9
|
+
readonly DeployModel: "deploy_model";
|
|
10
|
+
readonly HttpRequest: "http_request";
|
|
11
|
+
readonly LoadModel: "load_model";
|
|
12
|
+
readonly ProcessPrompt: "process_prompt";
|
|
13
|
+
readonly ProcessResponse: "process_response";
|
|
14
|
+
readonly QuarantineArtifact: "quarantine_artifact";
|
|
15
|
+
readonly ReadFile: "read_file";
|
|
16
|
+
readonly ScanArtifact: "scan_artifact";
|
|
17
|
+
readonly ScanPackage: "scan_package";
|
|
18
|
+
readonly ScanTarget: "scan_target";
|
|
19
|
+
readonly SkipGuardrails: "skip_guardrails";
|
|
20
|
+
readonly ValidateIntegrity: "validate_integrity";
|
|
21
|
+
readonly ValidateProvenance: "validate_provenance";
|
|
22
|
+
readonly WriteFile: "write_file";
|
|
23
|
+
};
|
|
24
|
+
export type ActionType = (typeof ActionType)[keyof typeof ActionType];
|
|
25
|
+
/**
|
|
26
|
+
* Create an EntityUID for an action.
|
|
27
|
+
*/
|
|
28
|
+
export declare function actionUID(action: ActionType): EntityUID;
|
|
29
|
+
//# sourceMappingURL=actions.gen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.gen.d.ts","sourceRoot":"","sources":["../src/actions.gen.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;CAkBb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEtE;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAEvD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Code generated by highflame-policy-codegen. DO NOT EDIT.
|
|
2
|
+
// Source: schema/highflame.cedarschema
|
|
3
|
+
/**
|
|
4
|
+
* Action types defined in the Highflame Cedar schema.
|
|
5
|
+
*/
|
|
6
|
+
export const ActionType = {
|
|
7
|
+
AccessServerResource: 'access_server_resource',
|
|
8
|
+
CallTool: 'call_tool',
|
|
9
|
+
ConnectServer: 'connect_server',
|
|
10
|
+
DeployModel: 'deploy_model',
|
|
11
|
+
HttpRequest: 'http_request',
|
|
12
|
+
LoadModel: 'load_model',
|
|
13
|
+
ProcessPrompt: 'process_prompt',
|
|
14
|
+
ProcessResponse: 'process_response',
|
|
15
|
+
QuarantineArtifact: 'quarantine_artifact',
|
|
16
|
+
ReadFile: 'read_file',
|
|
17
|
+
ScanArtifact: 'scan_artifact',
|
|
18
|
+
ScanPackage: 'scan_package',
|
|
19
|
+
ScanTarget: 'scan_target',
|
|
20
|
+
SkipGuardrails: 'skip_guardrails',
|
|
21
|
+
ValidateIntegrity: 'validate_integrity',
|
|
22
|
+
ValidateProvenance: 'validate_provenance',
|
|
23
|
+
WriteFile: 'write_file',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Create an EntityUID for an action.
|
|
27
|
+
*/
|
|
28
|
+
export function actionUID(action) {
|
|
29
|
+
return { type: 'Action', id: action };
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=actions.gen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.gen.js","sourceRoot":"","sources":["../src/actions.gen.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,uCAAuC;AAIvC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,oBAAoB,EAAE,wBAAwB;IAC9C,QAAQ,EAAE,WAAW;IACrB,aAAa,EAAE,gBAAgB;IAC/B,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,cAAc;IAC3B,SAAS,EAAE,YAAY;IACvB,aAAa,EAAE,gBAAgB;IAC/B,eAAe,EAAE,kBAAkB;IACnC,kBAAkB,EAAE,qBAAqB;IACzC,QAAQ,EAAE,WAAW;IACrB,YAAY,EAAE,eAAe;IAC7B,WAAW,EAAE,cAAc;IAC3B,UAAU,EAAE,aAAa;IACzB,cAAc,EAAE,iBAAiB;IACjC,iBAAiB,EAAE,oBAAoB;IACvC,kBAAkB,EAAE,qBAAqB;IACzC,SAAS,EAAE,YAAY;CACjB,CAAC;AAIX;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAkB;IACxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyBuilder - Type-safe Cedar policy construction for Highflame.
|
|
3
|
+
*
|
|
4
|
+
* This builder ensures that policies created from the UI are always valid
|
|
5
|
+
* by construction. It uses the generated types from the Cedar schema to
|
|
6
|
+
* provide compile-time safety and autocomplete support.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const policy = PolicyBuilder.permit()
|
|
11
|
+
* .principal(EntityType.User, "user-123")
|
|
12
|
+
* .action(ActionType.ReadFile)
|
|
13
|
+
* .resource(EntityType.FilePath, "/data/reports")
|
|
14
|
+
* .when("context.environment == \"production\"")
|
|
15
|
+
* .build();
|
|
16
|
+
*
|
|
17
|
+
* // Get Cedar policy text
|
|
18
|
+
* const cedarText = policy.toCedar();
|
|
19
|
+
*
|
|
20
|
+
* // Get JSON representation (for storage/editing)
|
|
21
|
+
* const policyJson = policy.toJSON();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { EntityType, EntityUID } from './entities.gen.js';
|
|
25
|
+
import { ActionType } from './actions.gen.js';
|
|
26
|
+
import { ContextKey } from './context.gen.js';
|
|
27
|
+
/**
|
|
28
|
+
* Policy effect - permit or forbid
|
|
29
|
+
*/
|
|
30
|
+
export type PolicyEffect = 'permit' | 'forbid';
|
|
31
|
+
/**
|
|
32
|
+
* Condition operator types
|
|
33
|
+
*/
|
|
34
|
+
export type ConditionOperator = 'eq' | 'neq' | 'lt' | 'lte' | 'gt' | 'gte' | 'contains' | 'in' | 'like';
|
|
35
|
+
/**
|
|
36
|
+
* A single condition in a policy
|
|
37
|
+
*/
|
|
38
|
+
export interface PolicyCondition {
|
|
39
|
+
/** The context key or attribute path */
|
|
40
|
+
field: string;
|
|
41
|
+
/** The comparison operator */
|
|
42
|
+
operator: ConditionOperator;
|
|
43
|
+
/** The value to compare against */
|
|
44
|
+
value: string | number | boolean | string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* JSON representation of a policy for storage and editing
|
|
48
|
+
*/
|
|
49
|
+
export interface PolicyJSON {
|
|
50
|
+
/** Unique identifier for this policy */
|
|
51
|
+
id?: string;
|
|
52
|
+
/** Human-readable name/description */
|
|
53
|
+
name?: string;
|
|
54
|
+
/** Policy effect */
|
|
55
|
+
effect: PolicyEffect;
|
|
56
|
+
/** Principal constraint */
|
|
57
|
+
principal: {
|
|
58
|
+
type: string;
|
|
59
|
+
id?: string;
|
|
60
|
+
} | null;
|
|
61
|
+
/** Action constraint */
|
|
62
|
+
action: string | string[];
|
|
63
|
+
/** Resource constraint */
|
|
64
|
+
resource: {
|
|
65
|
+
type: string;
|
|
66
|
+
id?: string;
|
|
67
|
+
} | null;
|
|
68
|
+
/** Conditions (when clause) */
|
|
69
|
+
conditions: PolicyCondition[];
|
|
70
|
+
/** Raw condition string (for advanced users) */
|
|
71
|
+
rawCondition?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A built policy that can be converted to Cedar text or JSON
|
|
75
|
+
*/
|
|
76
|
+
export declare class Policy {
|
|
77
|
+
private readonly data;
|
|
78
|
+
constructor(data: PolicyJSON);
|
|
79
|
+
/**
|
|
80
|
+
* Convert to Cedar policy text
|
|
81
|
+
*/
|
|
82
|
+
toCedar(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Convert a condition to Cedar syntax
|
|
85
|
+
*/
|
|
86
|
+
private conditionToCedar;
|
|
87
|
+
/**
|
|
88
|
+
* Convert a value to Cedar string representation
|
|
89
|
+
*/
|
|
90
|
+
private valueToString;
|
|
91
|
+
/**
|
|
92
|
+
* Get JSON representation for storage
|
|
93
|
+
*/
|
|
94
|
+
toJSON(): PolicyJSON;
|
|
95
|
+
/**
|
|
96
|
+
* Get the policy ID
|
|
97
|
+
*/
|
|
98
|
+
getId(): string | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Get the policy name
|
|
101
|
+
*/
|
|
102
|
+
getName(): string | undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Builder for constructing Cedar policies with type safety.
|
|
106
|
+
*/
|
|
107
|
+
export declare class PolicyBuilder {
|
|
108
|
+
private data;
|
|
109
|
+
private constructor();
|
|
110
|
+
/**
|
|
111
|
+
* Start building a permit policy
|
|
112
|
+
*/
|
|
113
|
+
static permit(): PolicyBuilder;
|
|
114
|
+
/**
|
|
115
|
+
* Start building a forbid policy
|
|
116
|
+
*/
|
|
117
|
+
static forbid(): PolicyBuilder;
|
|
118
|
+
/**
|
|
119
|
+
* Create a builder from existing JSON (for editing)
|
|
120
|
+
*/
|
|
121
|
+
static fromJSON(json: PolicyJSON): PolicyBuilder;
|
|
122
|
+
/**
|
|
123
|
+
* Set policy ID
|
|
124
|
+
*/
|
|
125
|
+
id(id: string): PolicyBuilder;
|
|
126
|
+
/**
|
|
127
|
+
* Set policy name/description
|
|
128
|
+
*/
|
|
129
|
+
name(name: string): PolicyBuilder;
|
|
130
|
+
/**
|
|
131
|
+
* Set principal constraint by type only (any entity of this type)
|
|
132
|
+
*/
|
|
133
|
+
principalType(type: EntityType | string): PolicyBuilder;
|
|
134
|
+
/**
|
|
135
|
+
* Set principal constraint by type and ID (specific entity)
|
|
136
|
+
*/
|
|
137
|
+
principal(type: EntityType | string, id: string): PolicyBuilder;
|
|
138
|
+
/**
|
|
139
|
+
* Set principal from EntityUID
|
|
140
|
+
*/
|
|
141
|
+
principalEntity(entity: EntityUID): PolicyBuilder;
|
|
142
|
+
/**
|
|
143
|
+
* Set single action constraint
|
|
144
|
+
*/
|
|
145
|
+
action(action: ActionType | string): PolicyBuilder;
|
|
146
|
+
/**
|
|
147
|
+
* Set multiple action constraints (action in [list])
|
|
148
|
+
*/
|
|
149
|
+
actions(actions: (ActionType | string)[]): PolicyBuilder;
|
|
150
|
+
/**
|
|
151
|
+
* Set resource constraint by type only (any entity of this type)
|
|
152
|
+
*/
|
|
153
|
+
resourceType(type: EntityType | string): PolicyBuilder;
|
|
154
|
+
/**
|
|
155
|
+
* Set resource constraint by type and ID (specific entity)
|
|
156
|
+
*/
|
|
157
|
+
resource(type: EntityType | string, id: string): PolicyBuilder;
|
|
158
|
+
/**
|
|
159
|
+
* Set resource from EntityUID
|
|
160
|
+
*/
|
|
161
|
+
resourceEntity(entity: EntityUID): PolicyBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* Add a structured condition
|
|
164
|
+
*/
|
|
165
|
+
when(field: ContextKey | string, operator: ConditionOperator, value: string | number | boolean | string[]): PolicyBuilder;
|
|
166
|
+
/**
|
|
167
|
+
* Add a raw condition string (for advanced users)
|
|
168
|
+
*/
|
|
169
|
+
whenRaw(condition: string): PolicyBuilder;
|
|
170
|
+
/**
|
|
171
|
+
* Clear all conditions
|
|
172
|
+
*/
|
|
173
|
+
clearConditions(): PolicyBuilder;
|
|
174
|
+
/**
|
|
175
|
+
* Build the policy
|
|
176
|
+
*/
|
|
177
|
+
build(): Policy;
|
|
178
|
+
/**
|
|
179
|
+
* Get current state as JSON (for preview/debugging)
|
|
180
|
+
*/
|
|
181
|
+
toJSON(): PolicyJSON;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Parse Cedar policy text back to PolicyJSON (best effort)
|
|
185
|
+
* Note: This is a simplified parser for policies created by PolicyBuilder.
|
|
186
|
+
* Complex hand-written policies may not parse correctly.
|
|
187
|
+
*/
|
|
188
|
+
export declare function parseCedarPolicy(cedarText: string): PolicyJSON | null;
|
|
189
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACvB,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,UAAU,GACV,IAAI,GACJ,MAAM,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,mCAAmC;IACnC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,wCAAwC;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB;IACpB,MAAM,EAAE,YAAY,CAAC;IACrB,2BAA2B;IAC3B,SAAS,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,IAAI,CAAC;IACT,wBAAwB;IACxB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,0BAA0B;IAC1B,QAAQ,EAAE;QACN,IAAI,EA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AAC,OAAO,EAAE,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,GAAG,aAAa;IAKxD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,aAAa;IAKtD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa;IAK9D;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa;IAKhD;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,aAAa;IAKzH;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa;IAKzC;;OAEG;IACH,eAAe,IAAI,aAAa;IAMhC;;OAEG;IACH,KAAK,IAAI,MAAM;IASf;;OAEG;IACH,MAAM,IAAI,UAAU;CAGvB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAyErE"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyBuilder - Type-safe Cedar policy construction for Highflame.
|
|
3
|
+
*
|
|
4
|
+
* This builder ensures that policies created from the UI are always valid
|
|
5
|
+
* by construction. It uses the generated types from the Cedar schema to
|
|
6
|
+
* provide compile-time safety and autocomplete support.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const policy = PolicyBuilder.permit()
|
|
11
|
+
* .principal(EntityType.User, "user-123")
|
|
12
|
+
* .action(ActionType.ReadFile)
|
|
13
|
+
* .resource(EntityType.FilePath, "/data/reports")
|
|
14
|
+
* .when("context.environment == \"production\"")
|
|
15
|
+
* .build();
|
|
16
|
+
*
|
|
17
|
+
* // Get Cedar policy text
|
|
18
|
+
* const cedarText = policy.toCedar();
|
|
19
|
+
*
|
|
20
|
+
* // Get JSON representation (for storage/editing)
|
|
21
|
+
* const policyJson = policy.toJSON();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* A built policy that can be converted to Cedar text or JSON
|
|
26
|
+
*/
|
|
27
|
+
export class Policy {
|
|
28
|
+
data;
|
|
29
|
+
constructor(data) {
|
|
30
|
+
this.data = data;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convert to Cedar policy text
|
|
34
|
+
*/
|
|
35
|
+
toCedar() {
|
|
36
|
+
const lines = [];
|
|
37
|
+
// Policy annotation (comment with name)
|
|
38
|
+
if (this.data.name) {
|
|
39
|
+
lines.push(`// @name: ${this.data.name}`);
|
|
40
|
+
}
|
|
41
|
+
if (this.data.id) {
|
|
42
|
+
lines.push(`// @id: ${this.data.id}`);
|
|
43
|
+
}
|
|
44
|
+
// Effect and principal
|
|
45
|
+
let policyLine = `${this.data.effect} (`;
|
|
46
|
+
// Principal
|
|
47
|
+
if (this.data.principal) {
|
|
48
|
+
if (this.data.principal.id) {
|
|
49
|
+
policyLine += `\n principal == ${this.data.principal.type}::\"${this.data.principal.id}\"`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
policyLine += `\n principal is ${this.data.principal.type}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
policyLine += `\n principal`;
|
|
57
|
+
}
|
|
58
|
+
// Action
|
|
59
|
+
if (Array.isArray(this.data.action)) {
|
|
60
|
+
if (this.data.action.length === 1) {
|
|
61
|
+
policyLine += `,\n action == Action::\"${this.data.action[0]}\"`;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const actions = this.data.action.map(a => `Action::\"${a}\"`).join(', ');
|
|
65
|
+
policyLine += `,\n action in [${actions}]`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
policyLine += `,\n action == Action::\"${this.data.action}\"`;
|
|
70
|
+
}
|
|
71
|
+
// Resource
|
|
72
|
+
if (this.data.resource) {
|
|
73
|
+
if (this.data.resource.id) {
|
|
74
|
+
policyLine += `,\n resource == ${this.data.resource.type}::\"${this.data.resource.id}\"`;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
policyLine += `,\n resource is ${this.data.resource.type}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
policyLine += `,\n resource`;
|
|
82
|
+
}
|
|
83
|
+
policyLine += '\n)';
|
|
84
|
+
lines.push(policyLine);
|
|
85
|
+
// When clause
|
|
86
|
+
if (this.data.rawCondition) {
|
|
87
|
+
lines.push(`when { ${this.data.rawCondition} };`);
|
|
88
|
+
}
|
|
89
|
+
else if (this.data.conditions.length > 0) {
|
|
90
|
+
const conditionStr = this.data.conditions
|
|
91
|
+
.map(c => this.conditionToCedar(c))
|
|
92
|
+
.join(' && ');
|
|
93
|
+
lines.push(`when { ${conditionStr} };`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
lines.push(';');
|
|
97
|
+
}
|
|
98
|
+
return lines.join('\n');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Convert a condition to Cedar syntax
|
|
102
|
+
*/
|
|
103
|
+
conditionToCedar(condition) {
|
|
104
|
+
const { field, operator, value } = condition;
|
|
105
|
+
const valueStr = this.valueToString(value);
|
|
106
|
+
switch (operator) {
|
|
107
|
+
case 'eq':
|
|
108
|
+
return `context.${field} == ${valueStr}`;
|
|
109
|
+
case 'neq':
|
|
110
|
+
return `context.${field} != ${valueStr}`;
|
|
111
|
+
case 'lt':
|
|
112
|
+
return `context.${field} < ${valueStr}`;
|
|
113
|
+
case 'lte':
|
|
114
|
+
return `context.${field} <= ${valueStr}`;
|
|
115
|
+
case 'gt':
|
|
116
|
+
return `context.${field} > ${valueStr}`;
|
|
117
|
+
case 'gte':
|
|
118
|
+
return `context.${field} >= ${valueStr}`;
|
|
119
|
+
case 'contains':
|
|
120
|
+
return `context.${field}.contains(${valueStr})`;
|
|
121
|
+
case 'in':
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
const items = value.map(v => `\"${v}\"`).join(', ');
|
|
124
|
+
return `context.${field} in [${items}]`;
|
|
125
|
+
}
|
|
126
|
+
return `context.${field} in ${valueStr}`;
|
|
127
|
+
case 'like':
|
|
128
|
+
return `context.${field} like ${valueStr}`;
|
|
129
|
+
default:
|
|
130
|
+
return `context.${field} == ${valueStr}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Convert a value to Cedar string representation
|
|
135
|
+
*/
|
|
136
|
+
valueToString(value) {
|
|
137
|
+
if (typeof value === 'string') {
|
|
138
|
+
return `\"${value}\"`;
|
|
139
|
+
}
|
|
140
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
141
|
+
return String(value);
|
|
142
|
+
}
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
return `[${value.map(v => `\"${v}\"`).join(', ')}]`;
|
|
145
|
+
}
|
|
146
|
+
return String(value);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get JSON representation for storage
|
|
150
|
+
*/
|
|
151
|
+
toJSON() {
|
|
152
|
+
return { ...this.data };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the policy ID
|
|
156
|
+
*/
|
|
157
|
+
getId() {
|
|
158
|
+
return this.data.id;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the policy name
|
|
162
|
+
*/
|
|
163
|
+
getName() {
|
|
164
|
+
return this.data.name;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Builder for constructing Cedar policies with type safety.
|
|
169
|
+
*/
|
|
170
|
+
export class PolicyBuilder {
|
|
171
|
+
data = {
|
|
172
|
+
effect: 'permit',
|
|
173
|
+
principal: null,
|
|
174
|
+
action: '',
|
|
175
|
+
resource: null,
|
|
176
|
+
conditions: [],
|
|
177
|
+
};
|
|
178
|
+
constructor(effect) {
|
|
179
|
+
this.data.effect = effect;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Start building a permit policy
|
|
183
|
+
*/
|
|
184
|
+
static permit() {
|
|
185
|
+
return new PolicyBuilder('permit');
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Start building a forbid policy
|
|
189
|
+
*/
|
|
190
|
+
static forbid() {
|
|
191
|
+
return new PolicyBuilder('forbid');
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Create a builder from existing JSON (for editing)
|
|
195
|
+
*/
|
|
196
|
+
static fromJSON(json) {
|
|
197
|
+
const builder = new PolicyBuilder(json.effect);
|
|
198
|
+
builder.data = { ...json };
|
|
199
|
+
return builder;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Set policy ID
|
|
203
|
+
*/
|
|
204
|
+
id(id) {
|
|
205
|
+
this.data.id = id;
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Set policy name/description
|
|
210
|
+
*/
|
|
211
|
+
name(name) {
|
|
212
|
+
this.data.name = name;
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Set principal constraint by type only (any entity of this type)
|
|
217
|
+
*/
|
|
218
|
+
principalType(type) {
|
|
219
|
+
this.data.principal = { type };
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Set principal constraint by type and ID (specific entity)
|
|
224
|
+
*/
|
|
225
|
+
principal(type, id) {
|
|
226
|
+
this.data.principal = { type, id };
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Set principal from EntityUID
|
|
231
|
+
*/
|
|
232
|
+
principalEntity(entity) {
|
|
233
|
+
this.data.principal = { type: entity.type, id: entity.id };
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Set single action constraint
|
|
238
|
+
*/
|
|
239
|
+
action(action) {
|
|
240
|
+
this.data.action = action;
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Set multiple action constraints (action in [list])
|
|
245
|
+
*/
|
|
246
|
+
actions(actions) {
|
|
247
|
+
this.data.action = actions;
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Set resource constraint by type only (any entity of this type)
|
|
252
|
+
*/
|
|
253
|
+
resourceType(type) {
|
|
254
|
+
this.data.resource = { type };
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Set resource constraint by type and ID (specific entity)
|
|
259
|
+
*/
|
|
260
|
+
resource(type, id) {
|
|
261
|
+
this.data.resource = { type, id };
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Set resource from EntityUID
|
|
266
|
+
*/
|
|
267
|
+
resourceEntity(entity) {
|
|
268
|
+
this.data.resource = { type: entity.type, id: entity.id };
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Add a structured condition
|
|
273
|
+
*/
|
|
274
|
+
when(field, operator, value) {
|
|
275
|
+
this.data.conditions.push({ field, operator, value });
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Add a raw condition string (for advanced users)
|
|
280
|
+
*/
|
|
281
|
+
whenRaw(condition) {
|
|
282
|
+
this.data.rawCondition = condition;
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Clear all conditions
|
|
287
|
+
*/
|
|
288
|
+
clearConditions() {
|
|
289
|
+
this.data.conditions = [];
|
|
290
|
+
this.data.rawCondition = undefined;
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Build the policy
|
|
295
|
+
*/
|
|
296
|
+
build() {
|
|
297
|
+
// Validate required fields
|
|
298
|
+
if (!this.data.action || (Array.isArray(this.data.action) && this.data.action.length === 0)) {
|
|
299
|
+
throw new Error('Policy must have at least one action');
|
|
300
|
+
}
|
|
301
|
+
return new Policy({ ...this.data });
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get current state as JSON (for preview/debugging)
|
|
305
|
+
*/
|
|
306
|
+
toJSON() {
|
|
307
|
+
return { ...this.data };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Parse Cedar policy text back to PolicyJSON (best effort)
|
|
312
|
+
* Note: This is a simplified parser for policies created by PolicyBuilder.
|
|
313
|
+
* Complex hand-written policies may not parse correctly.
|
|
314
|
+
*/
|
|
315
|
+
export function parseCedarPolicy(cedarText) {
|
|
316
|
+
try {
|
|
317
|
+
const result = {
|
|
318
|
+
effect: 'permit',
|
|
319
|
+
principal: null,
|
|
320
|
+
action: '',
|
|
321
|
+
resource: null,
|
|
322
|
+
conditions: [],
|
|
323
|
+
};
|
|
324
|
+
// Extract name from annotation
|
|
325
|
+
const nameMatch = cedarText.match(/\/\/ @name: (.+)/);
|
|
326
|
+
if (nameMatch) {
|
|
327
|
+
result.name = nameMatch[1].trim();
|
|
328
|
+
}
|
|
329
|
+
// Extract id from annotation
|
|
330
|
+
const idMatch = cedarText.match(/\/\/ @id: (.+)/);
|
|
331
|
+
if (idMatch) {
|
|
332
|
+
result.id = idMatch[1].trim();
|
|
333
|
+
}
|
|
334
|
+
// Extract effect
|
|
335
|
+
if (cedarText.includes('forbid')) {
|
|
336
|
+
result.effect = 'forbid';
|
|
337
|
+
}
|
|
338
|
+
// Extract principal
|
|
339
|
+
const principalMatch = cedarText.match(/principal\s*==\s*(\w+)::"([^"]+)"/);
|
|
340
|
+
if (principalMatch) {
|
|
341
|
+
result.principal = { type: principalMatch[1], id: principalMatch[2] };
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
const principalTypeMatch = cedarText.match(/principal\s+is\s+(\w+)/);
|
|
345
|
+
if (principalTypeMatch) {
|
|
346
|
+
result.principal = { type: principalTypeMatch[1] };
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// Extract action(s)
|
|
350
|
+
const actionMatch = cedarText.match(/action\s*==\s*Action::"([^"]+)"/);
|
|
351
|
+
if (actionMatch) {
|
|
352
|
+
result.action = actionMatch[1];
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
const actionsMatch = cedarText.match(/action\s+in\s+\[([^\]]+)\]/);
|
|
356
|
+
if (actionsMatch) {
|
|
357
|
+
const actions = actionsMatch[1].match(/Action::"([^"]+)"/g);
|
|
358
|
+
if (actions) {
|
|
359
|
+
result.action = actions.map(a => a.replace(/Action::"([^"]+)"/, '$1'));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
// Extract resource
|
|
364
|
+
const resourceMatch = cedarText.match(/resource\s*==\s*(\w+)::"([^"]+)"/);
|
|
365
|
+
if (resourceMatch) {
|
|
366
|
+
result.resource = { type: resourceMatch[1], id: resourceMatch[2] };
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
const resourceTypeMatch = cedarText.match(/resource\s+is\s+(\w+)/);
|
|
370
|
+
if (resourceTypeMatch) {
|
|
371
|
+
result.resource = { type: resourceTypeMatch[1] };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// Extract when clause (as raw condition)
|
|
375
|
+
const whenMatch = cedarText.match(/when\s*\{([^}]+)\}/);
|
|
376
|
+
if (whenMatch) {
|
|
377
|
+
result.rawCondition = whenMatch[1].trim();
|
|
378
|
+
}
|
|
379
|
+
return result;
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 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