@cloud-copilot/iam-simulate 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.txt +661 -0
- package/README.md +5 -0
- package/dist/cjs/StatementAnalysis.d.ts +27 -0
- package/dist/cjs/StatementAnalysis.d.ts.map +1 -0
- package/dist/cjs/StatementAnalysis.js +3 -0
- package/dist/cjs/StatementAnalysis.js.map +1 -0
- package/dist/cjs/action/action.d.ts +27 -0
- package/dist/cjs/action/action.d.ts.map +1 -0
- package/dist/cjs/action/action.js +72 -0
- package/dist/cjs/action/action.js.map +1 -0
- package/dist/cjs/action.d.ts +4 -0
- package/dist/cjs/action.d.ts.map +1 -0
- package/dist/cjs/action.js +21 -0
- package/dist/cjs/action.js.map +1 -0
- package/dist/cjs/condition/BaseConditionOperator.d.ts +8 -0
- package/dist/cjs/condition/BaseConditionOperator.d.ts.map +1 -0
- package/dist/cjs/condition/BaseConditionOperator.js +3 -0
- package/dist/cjs/condition/BaseConditionOperator.js.map +1 -0
- package/dist/cjs/condition/arn/ArnEquals.d.ts +3 -0
- package/dist/cjs/condition/arn/ArnEquals.d.ts.map +1 -0
- package/dist/cjs/condition/arn/ArnEquals.js +11 -0
- package/dist/cjs/condition/arn/ArnEquals.js.map +1 -0
- package/dist/cjs/condition/arn/ArnLike.d.ts +3 -0
- package/dist/cjs/condition/arn/ArnLike.d.ts.map +1 -0
- package/dist/cjs/condition/arn/ArnLike.js +50 -0
- package/dist/cjs/condition/arn/ArnLike.js.map +1 -0
- package/dist/cjs/condition/arn/ArnNotEquals.d.ts +3 -0
- package/dist/cjs/condition/arn/ArnNotEquals.d.ts.map +1 -0
- package/dist/cjs/condition/arn/ArnNotEquals.js +11 -0
- package/dist/cjs/condition/arn/ArnNotEquals.js.map +1 -0
- package/dist/cjs/condition/arn/ArnNotLike.d.ts +3 -0
- package/dist/cjs/condition/arn/ArnNotLike.d.ts.map +1 -0
- package/dist/cjs/condition/arn/ArnNotLike.js +13 -0
- package/dist/cjs/condition/arn/ArnNotLike.js.map +1 -0
- package/dist/cjs/condition/baseConditionperatorTests.d.ts +12 -0
- package/dist/cjs/condition/baseConditionperatorTests.d.ts.map +1 -0
- package/dist/cjs/condition/baseConditionperatorTests.js +21 -0
- package/dist/cjs/condition/baseConditionperatorTests.js.map +1 -0
- package/dist/cjs/condition/binary/BinaryEquals.d.ts +7 -0
- package/dist/cjs/condition/binary/BinaryEquals.d.ts.map +1 -0
- package/dist/cjs/condition/binary/BinaryEquals.js +16 -0
- package/dist/cjs/condition/binary/BinaryEquals.js.map +1 -0
- package/dist/cjs/condition/boolean/Bool.d.ts +3 -0
- package/dist/cjs/condition/boolean/Bool.d.ts.map +1 -0
- package/dist/cjs/condition/boolean/Bool.js +20 -0
- package/dist/cjs/condition/boolean/Bool.js.map +1 -0
- package/dist/cjs/condition/condition.d.ts +6 -0
- package/dist/cjs/condition/condition.d.ts.map +1 -0
- package/dist/cjs/condition/condition.js +123 -0
- package/dist/cjs/condition/condition.js.map +1 -0
- package/dist/cjs/condition/date/DateEquals.d.ts +3 -0
- package/dist/cjs/condition/date/DateEquals.d.ts.map +1 -0
- package/dist/cjs/condition/date/DateEquals.js +17 -0
- package/dist/cjs/condition/date/DateEquals.js.map +1 -0
- package/dist/cjs/condition/date/DateGreaterThan.d.ts +3 -0
- package/dist/cjs/condition/date/DateGreaterThan.d.ts.map +1 -0
- package/dist/cjs/condition/date/DateGreaterThan.js +17 -0
- package/dist/cjs/condition/date/DateGreaterThan.js.map +1 -0
- package/dist/cjs/condition/date/DateGreaterThanEquals.d.ts +3 -0
- package/dist/cjs/condition/date/DateGreaterThanEquals.d.ts.map +1 -0
- package/dist/cjs/condition/date/DateGreaterThanEquals.js +17 -0
- package/dist/cjs/condition/date/DateGreaterThanEquals.js.map +1 -0
- package/dist/cjs/condition/date/DateLessThan.d.ts +3 -0
- package/dist/cjs/condition/date/DateLessThan.d.ts.map +1 -0
- package/dist/cjs/condition/date/DateLessThan.js +17 -0
- package/dist/cjs/condition/date/DateLessThan.js.map +1 -0
- package/dist/cjs/condition/date/DateLessThanEquals.d.ts +3 -0
- package/dist/cjs/condition/date/DateLessThanEquals.d.ts.map +1 -0
- package/dist/cjs/condition/date/DateLessThanEquals.js +17 -0
- package/dist/cjs/condition/date/DateLessThanEquals.js.map +1 -0
- package/dist/cjs/condition/date/DateNotEquals.d.ts +3 -0
- package/dist/cjs/condition/date/DateNotEquals.d.ts.map +1 -0
- package/dist/cjs/condition/date/DateNotEquals.js +29 -0
- package/dist/cjs/condition/date/DateNotEquals.js.map +1 -0
- package/dist/cjs/condition/date/date.d.ts +17 -0
- package/dist/cjs/condition/date/date.d.ts.map +1 -0
- package/dist/cjs/condition/date/date.js +42 -0
- package/dist/cjs/condition/date/date.js.map +1 -0
- package/dist/cjs/condition/ipaddress/IpAddress.d.ts +3 -0
- package/dist/cjs/condition/ipaddress/IpAddress.d.ts.map +1 -0
- package/dist/cjs/condition/ipaddress/IpAddress.js +27 -0
- package/dist/cjs/condition/ipaddress/IpAddress.js.map +1 -0
- package/dist/cjs/condition/ipaddress/NotIpAddress.d.ts +3 -0
- package/dist/cjs/condition/ipaddress/NotIpAddress.d.ts.map +1 -0
- package/dist/cjs/condition/ipaddress/NotIpAddress.js +31 -0
- package/dist/cjs/condition/ipaddress/NotIpAddress.js.map +1 -0
- package/dist/cjs/condition/ipaddress/ipv4.d.ts +24 -0
- package/dist/cjs/condition/ipaddress/ipv4.d.ts.map +1 -0
- package/dist/cjs/condition/ipaddress/ipv4.js +59 -0
- package/dist/cjs/condition/ipaddress/ipv4.js.map +1 -0
- package/dist/cjs/condition/ipaddress/ipv6.d.ts +24 -0
- package/dist/cjs/condition/ipaddress/ipv6.d.ts.map +1 -0
- package/dist/cjs/condition/ipaddress/ipv6.js +111 -0
- package/dist/cjs/condition/ipaddress/ipv6.js.map +1 -0
- package/dist/cjs/condition/numeric/NumericEquals.d.ts +3 -0
- package/dist/cjs/condition/numeric/NumericEquals.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/NumericEquals.js +17 -0
- package/dist/cjs/condition/numeric/NumericEquals.js.map +1 -0
- package/dist/cjs/condition/numeric/NumericGreaterThan.d.ts +3 -0
- package/dist/cjs/condition/numeric/NumericGreaterThan.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/NumericGreaterThan.js +17 -0
- package/dist/cjs/condition/numeric/NumericGreaterThan.js.map +1 -0
- package/dist/cjs/condition/numeric/NumericGreaterThanEquals.d.ts +3 -0
- package/dist/cjs/condition/numeric/NumericGreaterThanEquals.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/NumericGreaterThanEquals.js +17 -0
- package/dist/cjs/condition/numeric/NumericGreaterThanEquals.js.map +1 -0
- package/dist/cjs/condition/numeric/NumericLessThan.d.ts +3 -0
- package/dist/cjs/condition/numeric/NumericLessThan.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/NumericLessThan.js +17 -0
- package/dist/cjs/condition/numeric/NumericLessThan.js.map +1 -0
- package/dist/cjs/condition/numeric/NumericLessThanEquals.d.ts +3 -0
- package/dist/cjs/condition/numeric/NumericLessThanEquals.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/NumericLessThanEquals.js +17 -0
- package/dist/cjs/condition/numeric/NumericLessThanEquals.js.map +1 -0
- package/dist/cjs/condition/numeric/NumericNotEquals.d.ts +3 -0
- package/dist/cjs/condition/numeric/NumericNotEquals.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/NumericNotEquals.js +29 -0
- package/dist/cjs/condition/numeric/NumericNotEquals.js.map +1 -0
- package/dist/cjs/condition/numeric/numeric.d.ts +17 -0
- package/dist/cjs/condition/numeric/numeric.d.ts.map +1 -0
- package/dist/cjs/condition/numeric/numeric.js +41 -0
- package/dist/cjs/condition/numeric/numeric.js.map +1 -0
- package/dist/cjs/condition/string/StringEquals.d.ts +3 -0
- package/dist/cjs/condition/string/StringEquals.d.ts.map +1 -0
- package/dist/cjs/condition/string/StringEquals.js +14 -0
- package/dist/cjs/condition/string/StringEquals.js.map +1 -0
- package/dist/cjs/condition/string/StringEqualsIgnoreCase.d.ts +3 -0
- package/dist/cjs/condition/string/StringEqualsIgnoreCase.d.ts.map +1 -0
- package/dist/cjs/condition/string/StringEqualsIgnoreCase.js +17 -0
- package/dist/cjs/condition/string/StringEqualsIgnoreCase.js.map +1 -0
- package/dist/cjs/condition/string/StringLike.d.ts +3 -0
- package/dist/cjs/condition/string/StringLike.d.ts.map +1 -0
- package/dist/cjs/condition/string/StringLike.js +14 -0
- package/dist/cjs/condition/string/StringLike.js.map +1 -0
- package/dist/cjs/condition/string/StringNotEquals.d.ts +3 -0
- package/dist/cjs/condition/string/StringNotEquals.d.ts.map +1 -0
- package/dist/cjs/condition/string/StringNotEquals.js +14 -0
- package/dist/cjs/condition/string/StringNotEquals.js.map +1 -0
- package/dist/cjs/condition/string/StringNotEqualsIgnoreCase.d.ts +3 -0
- package/dist/cjs/condition/string/StringNotEqualsIgnoreCase.d.ts.map +1 -0
- package/dist/cjs/condition/string/StringNotEqualsIgnoreCase.js +13 -0
- package/dist/cjs/condition/string/StringNotEqualsIgnoreCase.js.map +1 -0
- package/dist/cjs/condition/string/StringNotLike.d.ts +3 -0
- package/dist/cjs/condition/string/StringNotLike.d.ts.map +1 -0
- package/dist/cjs/condition/string/StringNotLike.js +13 -0
- package/dist/cjs/condition/string/StringNotLike.js.map +1 -0
- package/dist/cjs/condition/strings/StringEquals.d.ts +3 -0
- package/dist/cjs/condition/strings/StringEquals.d.ts.map +1 -0
- package/dist/cjs/condition/strings/StringEquals.js +14 -0
- package/dist/cjs/condition/strings/StringEquals.js.map +1 -0
- package/dist/cjs/core_engine/coreSimulatorEngine.d.ts +44 -0
- package/dist/cjs/core_engine/coreSimulatorEngine.d.ts.map +1 -0
- package/dist/cjs/core_engine/coreSimulatorEngine.js +60 -0
- package/dist/cjs/core_engine/coreSimulatorEngine.js.map +1 -0
- package/dist/cjs/evaluate.d.ts +2 -0
- package/dist/cjs/evaluate.d.ts.map +1 -0
- package/dist/cjs/evaluate.js +3 -0
- package/dist/cjs/evaluate.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/principal/principal.d.ts +30 -0
- package/dist/cjs/principal/principal.d.ts.map +1 -0
- package/dist/cjs/principal/principal.js +107 -0
- package/dist/cjs/principal/principal.js.map +1 -0
- package/dist/cjs/request/request.d.ts +50 -0
- package/dist/cjs/request/request.d.ts.map +1 -0
- package/dist/cjs/request/request.js +41 -0
- package/dist/cjs/request/request.js.map +1 -0
- package/dist/cjs/request/requestAction.d.ts +27 -0
- package/dist/cjs/request/requestAction.d.ts.map +1 -0
- package/dist/cjs/request/requestAction.js +20 -0
- package/dist/cjs/request/requestAction.js.map +1 -0
- package/dist/cjs/request/requestPrincipal.d.ts +20 -0
- package/dist/cjs/request/requestPrincipal.d.ts.map +1 -0
- package/dist/cjs/request/requestPrincipal.js +17 -0
- package/dist/cjs/request/requestPrincipal.js.map +1 -0
- package/dist/cjs/request/requestResource.d.ts +37 -0
- package/dist/cjs/request/requestResource.d.ts.map +1 -0
- package/dist/cjs/request/requestResource.js +29 -0
- package/dist/cjs/request/requestResource.js.map +1 -0
- package/dist/cjs/request/requestSupplementalData.d.ts +19 -0
- package/dist/cjs/request/requestSupplementalData.d.ts.map +1 -0
- package/dist/cjs/request/requestSupplementalData.js +37 -0
- package/dist/cjs/request/requestSupplementalData.js.map +1 -0
- package/dist/cjs/request.d.ts +15 -0
- package/dist/cjs/request.d.ts.map +1 -0
- package/dist/cjs/request.js +17 -0
- package/dist/cjs/request.js.map +1 -0
- package/dist/cjs/requestContext.d.ts +63 -0
- package/dist/cjs/requestContext.d.ts.map +1 -0
- package/dist/cjs/requestContext.js +46 -0
- package/dist/cjs/requestContext.js.map +1 -0
- package/dist/cjs/resource/resource.d.ts +27 -0
- package/dist/cjs/resource/resource.d.ts.map +1 -0
- package/dist/cjs/resource/resource.js +100 -0
- package/dist/cjs/resource/resource.js.map +1 -0
- package/dist/cjs/services/DefaultServiceAuthorizer.d.ts +12 -0
- package/dist/cjs/services/DefaultServiceAuthorizer.d.ts.map +1 -0
- package/dist/cjs/services/DefaultServiceAuthorizer.js +79 -0
- package/dist/cjs/services/DefaultServiceAuthorizer.js.map +1 -0
- package/dist/cjs/services/ServiceAuthorizer.d.ts +11 -0
- package/dist/cjs/services/ServiceAuthorizer.d.ts.map +1 -0
- package/dist/cjs/services/ServiceAuthorizer.js +3 -0
- package/dist/cjs/services/ServiceAuthorizer.js.map +1 -0
- package/dist/cjs/util.d.ts +47 -0
- package/dist/cjs/util.d.ts.map +1 -0
- package/dist/cjs/util.js +180 -0
- package/dist/cjs/util.js.map +1 -0
- package/dist/esm/action/action.d.ts +19 -0
- package/dist/esm/action/action.d.ts.map +1 -0
- package/dist/esm/action/action.js +51 -0
- package/dist/esm/action/action.js.map +1 -0
- package/dist/esm/action.d.ts +4 -0
- package/dist/esm/action.d.ts.map +1 -0
- package/dist/esm/action.js +18 -0
- package/dist/esm/action.js.map +1 -0
- package/dist/esm/condition/BaseConditionOperator.d.ts +8 -0
- package/dist/esm/condition/BaseConditionOperator.d.ts.map +1 -0
- package/dist/esm/condition/BaseConditionOperator.js +2 -0
- package/dist/esm/condition/BaseConditionOperator.js.map +1 -0
- package/dist/esm/condition/condition.d.ts +5 -0
- package/dist/esm/condition/condition.d.ts.map +1 -0
- package/dist/esm/condition/condition.js +70 -0
- package/dist/esm/condition/condition.js.map +1 -0
- package/dist/esm/condition/strings/StringEquals.d.ts +3 -0
- package/dist/esm/condition/strings/StringEquals.d.ts.map +1 -0
- package/dist/esm/condition/strings/StringEquals.js +11 -0
- package/dist/esm/condition/strings/StringEquals.js.map +1 -0
- package/dist/esm/evaluate.d.ts +2 -0
- package/dist/esm/evaluate.d.ts.map +1 -0
- package/dist/esm/evaluate.js +2 -0
- package/dist/esm/evaluate.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/principal/principal.d.ts +31 -0
- package/dist/esm/principal/principal.d.ts.map +1 -0
- package/dist/esm/principal/principal.js +100 -0
- package/dist/esm/principal/principal.js.map +1 -0
- package/dist/esm/request/request.d.ts +52 -0
- package/dist/esm/request/request.d.ts.map +1 -0
- package/dist/esm/request/request.js +34 -0
- package/dist/esm/request/request.js.map +1 -0
- package/dist/esm/request/requestAction.d.ts +27 -0
- package/dist/esm/request/requestAction.d.ts.map +1 -0
- package/dist/esm/request/requestAction.js +15 -0
- package/dist/esm/request/requestAction.js.map +1 -0
- package/dist/esm/request/requestPrincipal.d.ts +20 -0
- package/dist/esm/request/requestPrincipal.d.ts.map +1 -0
- package/dist/esm/request/requestPrincipal.js +12 -0
- package/dist/esm/request/requestPrincipal.js.map +1 -0
- package/dist/esm/request/requestResource.d.ts +37 -0
- package/dist/esm/request/requestResource.d.ts.map +1 -0
- package/dist/esm/request/requestResource.js +24 -0
- package/dist/esm/request/requestResource.js.map +1 -0
- package/dist/esm/request/requestSupplementalData.d.ts +19 -0
- package/dist/esm/request/requestSupplementalData.d.ts.map +1 -0
- package/dist/esm/request/requestSupplementalData.js +30 -0
- package/dist/esm/request/requestSupplementalData.js.map +1 -0
- package/dist/esm/request.d.ts +15 -0
- package/dist/esm/request.d.ts.map +1 -0
- package/dist/esm/request.js +9 -0
- package/dist/esm/request.js.map +1 -0
- package/dist/esm/requestContext.d.ts +63 -0
- package/dist/esm/requestContext.d.ts.map +1 -0
- package/dist/esm/requestContext.js +39 -0
- package/dist/esm/requestContext.js.map +1 -0
- package/dist/esm/resource/resource.d.ts +12 -0
- package/dist/esm/resource/resource.d.ts.map +1 -0
- package/dist/esm/resource/resource.js +97 -0
- package/dist/esm/resource/resource.js.map +1 -0
- package/dist/esm/util.d.ts +15 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +97 -0
- package/dist/esm/util.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextKeyImpl = exports.RequestContextImpl = void 0;
|
|
4
|
+
class RequestContextImpl {
|
|
5
|
+
context = new Map();
|
|
6
|
+
constructor(values) {
|
|
7
|
+
for (const key in values) {
|
|
8
|
+
this.context.set(key.toLowerCase(), new ContextKeyImpl(key, values[key]));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
contextKeyExists(name) {
|
|
12
|
+
return this.context.has(name.toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
contextKeyValue(name) {
|
|
15
|
+
return this.context.get(name.toLowerCase());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.RequestContextImpl = RequestContextImpl;
|
|
19
|
+
class ContextKeyImpl {
|
|
20
|
+
name;
|
|
21
|
+
_val;
|
|
22
|
+
constructor(name, _val) {
|
|
23
|
+
this.name = name;
|
|
24
|
+
this._val = _val;
|
|
25
|
+
}
|
|
26
|
+
isStringValue() {
|
|
27
|
+
return typeof this._val === 'string';
|
|
28
|
+
}
|
|
29
|
+
isArrayValue() {
|
|
30
|
+
return Array.isArray(this._val);
|
|
31
|
+
}
|
|
32
|
+
get values() {
|
|
33
|
+
if (Array.isArray(this._val)) {
|
|
34
|
+
return this._val;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`ContextKey ${this.name} is not an array`);
|
|
37
|
+
}
|
|
38
|
+
get value() {
|
|
39
|
+
if (typeof this._val === 'string') {
|
|
40
|
+
return this._val;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`ContextKey ${this.name} is not a string`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ContextKeyImpl = ContextKeyImpl;
|
|
46
|
+
//# sourceMappingURL=requestContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestContext.js","sourceRoot":"","sources":["../../src/requestContext.ts"],"names":[],"mappings":";;;AA2DA,MAAa,kBAAkB;IACrB,OAAO,GAA4B,IAAI,GAAG,EAAE,CAAC;IAErD,YAAY,MAAyC;QACnD,KAAI,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,IAAI,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAGM,gBAAgB,CAAC,IAAY;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEM,eAAe,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAe,CAAC;IAE5D,CAAC;CACF;AAlBD,gDAkBC;AAED,MAAa,cAAc;IACN;IAAsB;IAAzC,YAAmB,IAAY,EAAU,IAAuB;QAA7C,SAAI,GAAJ,IAAI,CAAQ;QAAU,SAAI,GAAJ,IAAI,CAAmB;IAAG,CAAC;IAEpE,aAAa;QACX,OAAO,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;IACvC,CAAC;IACD,YAAY;QACV,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,MAAM;QACR,IAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,CAAC,IAAI,kBAAkB,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,KAAK;QACP,IAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,CAAC,IAAI,kBAAkB,CAAC,CAAC;IAC7D,CAAC;CACF;AAvBD,wCAuBC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Resource, Statement } from "@cloud-copilot/iam-policy";
|
|
2
|
+
import { AwsRequest } from "../request/request.js";
|
|
3
|
+
/**
|
|
4
|
+
* Check if a request matches the Resource or NotResource elements of a statement.
|
|
5
|
+
*
|
|
6
|
+
* @param request the request to check
|
|
7
|
+
* @param statement the statement to check against
|
|
8
|
+
* @returns true if the request matches the resources in the statement, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function requestMatchesStatementResources(request: AwsRequest, statement: Statement): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a request matches a set of resources.
|
|
13
|
+
*
|
|
14
|
+
* @param request the request to check
|
|
15
|
+
* @param policyResources the resources to check against
|
|
16
|
+
* @returns true if the request matches any of the resources, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
export declare function requestMatchesResources(request: AwsRequest, policyResources: Resource[]): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a request matches a NotResource element in a policy.
|
|
21
|
+
*
|
|
22
|
+
* @param request the request to check
|
|
23
|
+
* @param policyResources the resources to check against
|
|
24
|
+
* @returns true if the request does not match any of the resources, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
export declare function requestMatchesNotResources(request: AwsRequest, policyResources: Resource[]): boolean;
|
|
27
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/resource/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAmBnD;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAOnG;AAGD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,OAAO,CAEjG;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,OAAO,CAEpG"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestMatchesStatementResources = requestMatchesStatementResources;
|
|
4
|
+
exports.requestMatchesResources = requestMatchesResources;
|
|
5
|
+
exports.requestMatchesNotResources = requestMatchesNotResources;
|
|
6
|
+
const util_js_1 = require("../util.js");
|
|
7
|
+
//TODO: Make a check to see if the action is a wildcard only action. This will have to happen outside of these functions.
|
|
8
|
+
/**
|
|
9
|
+
* Convert a resource segment to a regular expression. This is without variables.
|
|
10
|
+
*
|
|
11
|
+
* @param segment the segment to convert to a regular expression
|
|
12
|
+
* @returns a regular that replaces any wildcards in the segment with the appropriate regular expression.
|
|
13
|
+
*/
|
|
14
|
+
function convertResourceSegmentToRegex(segment) {
|
|
15
|
+
if (segment.indexOf(':') != -1) {
|
|
16
|
+
throw new Error('Segment should not contain a colon');
|
|
17
|
+
}
|
|
18
|
+
const pattern = "^" + segment.replace(/\?/g, '.').replace(/\*/g, '.*?') + "$";
|
|
19
|
+
return new RegExp(pattern, 'i');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if a request matches the Resource or NotResource elements of a statement.
|
|
23
|
+
*
|
|
24
|
+
* @param request the request to check
|
|
25
|
+
* @param statement the statement to check against
|
|
26
|
+
* @returns true if the request matches the resources in the statement, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
function requestMatchesStatementResources(request, statement) {
|
|
29
|
+
if (statement.isResourceStatement()) {
|
|
30
|
+
return requestMatchesResources(request, statement.resources());
|
|
31
|
+
}
|
|
32
|
+
else if (statement.isNotResourceStatement()) {
|
|
33
|
+
return requestMatchesNotResources(request, statement.notResources());
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if a request matches a set of resources.
|
|
39
|
+
*
|
|
40
|
+
* @param request the request to check
|
|
41
|
+
* @param policyResources the resources to check against
|
|
42
|
+
* @returns true if the request matches any of the resources, false otherwise
|
|
43
|
+
*/
|
|
44
|
+
function requestMatchesResources(request, policyResources) {
|
|
45
|
+
return policyResources.some(policyResource => singleResourceMatchesRequest(request, policyResource));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if a request matches a NotResource element in a policy.
|
|
49
|
+
*
|
|
50
|
+
* @param request the request to check
|
|
51
|
+
* @param policyResources the resources to check against
|
|
52
|
+
* @returns true if the request does not match any of the resources, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
function requestMatchesNotResources(request, policyResources) {
|
|
55
|
+
return !requestMatchesResources(request, policyResources);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if a single resource matches a request.
|
|
59
|
+
*
|
|
60
|
+
* @param request the request to check against
|
|
61
|
+
* @param policyResource the resource to check against
|
|
62
|
+
* @returns true if the request matches the resource, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
function singleResourceMatchesRequest(request, policyResource) {
|
|
65
|
+
if (policyResource.isAllResources()) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
else if (policyResource.isArnResource()) {
|
|
69
|
+
if (!request.resource) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const resource = request.resource;
|
|
73
|
+
if (!convertResourceSegmentToRegex(policyResource.partition()).test(resource.partition())) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (!convertResourceSegmentToRegex(policyResource.service()).test(resource.service())) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!convertResourceSegmentToRegex(policyResource.region()).test(resource.region())) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (!convertResourceSegmentToRegex(policyResource.account()).test(resource.account())) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
//Wildcards and variables are not allowed in the product segment https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html "Incorrect wildcard usage"
|
|
86
|
+
const [policyProduct, policyResourceId] = (0, util_js_1.getResourceSegments)(policyResource.resource());
|
|
87
|
+
if (!resource.resource().startsWith(policyProduct)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const requestResourceId = resource.resource().slice(policyProduct.length);
|
|
91
|
+
if (!(0, util_js_1.convertIamStringToRegex)(policyResourceId, request).test(requestResourceId)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new Error('Unknown resource type');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/resource/resource.ts"],"names":[],"mappings":";;AA2BA,4EAOC;AAUD,0DAEC;AASD,gEAEC;AAvDD,wCAA0E;AAE1E,yHAAyH;AAEzH;;;;;GAKG;AACH,SAAS,6BAA6B,CAAC,OAAe;IACpD,IAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EA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luationResult } from "../evaluate.js";
|
|
2
|
+
import { StatementAnalysis } from "../StatementAnalysis.js";
|
|
3
|
+
import { ServiceAuthorizationRequest, ServiceAuthorizer } from "./ServiceAuthorizer.js";
|
|
4
|
+
export declare class DefaultServiceAuthorizer implements ServiceAuthorizer {
|
|
5
|
+
authorize(request: ServiceAuthorizationRequest): EvaluationResult;
|
|
6
|
+
identityStatementResult(request: ServiceAuthorizationRequest): EvaluationResult;
|
|
7
|
+
identityStatementAllows(statement: StatementAnalysis): boolean;
|
|
8
|
+
identityStatementUknownAllow(statement: StatementAnalysis): boolean;
|
|
9
|
+
identityStatementUknownDeny(statement: StatementAnalysis): boolean;
|
|
10
|
+
identityStatementExplicitDeny(statement: StatementAnalysis): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=DefaultServiceAuthorizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultServiceAuthorizer.d.ts","sourceRoot":"","sources":["../../../src/services/DefaultServiceAuthorizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIxF,qBAAa,wBAAyB,YAAW,iBAAiB;IACzD,SAAS,CAAC,OAAO,EAAE,2BAA2B,GAAG,gBAAgB;IAqBjE,uBAAuB,CAAC,OAAO,EAAE,2BAA2B,GAAG,gBAAgB;IAoB/E,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO;IAU9D,4BAA4B,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO;IAUnE,2BAA2B,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO;IAUlE,6BAA6B,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO;CAS5E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultServiceAuthorizer = void 0;
|
|
4
|
+
class DefaultServiceAuthorizer {
|
|
5
|
+
authorize(request) {
|
|
6
|
+
const identityStatementResult = this.identityStatementResult(request);
|
|
7
|
+
const principalAccount = request.request.principalAccountId;
|
|
8
|
+
const resourceAccount = request.request.resourceAccountId;
|
|
9
|
+
/**
|
|
10
|
+
* Add checks for:
|
|
11
|
+
* * resource policies
|
|
12
|
+
* * service control policies
|
|
13
|
+
* * boundary policies
|
|
14
|
+
* * vpc endpoint policies
|
|
15
|
+
* * session policies (maybe these are just part of identity policies?)
|
|
16
|
+
*/
|
|
17
|
+
if (identityStatementResult === 'Allowed') {
|
|
18
|
+
if (principalAccount === resourceAccount) {
|
|
19
|
+
return identityStatementResult;
|
|
20
|
+
}
|
|
21
|
+
return 'ImplicitlyDenied';
|
|
22
|
+
}
|
|
23
|
+
return identityStatementResult;
|
|
24
|
+
}
|
|
25
|
+
identityStatementResult(request) {
|
|
26
|
+
const explicitDeny = request.identityStatements.some(s => this.identityStatementExplicitDeny(s));
|
|
27
|
+
if (explicitDeny) {
|
|
28
|
+
return 'ExplicitlyDenied';
|
|
29
|
+
}
|
|
30
|
+
const explicitAllow = request.identityStatements.some(s => this.identityStatementAllows(s));
|
|
31
|
+
const possibleDeny = request.identityStatements.some(s => this.identityStatementUknownDeny(s));
|
|
32
|
+
if (explicitAllow) {
|
|
33
|
+
return possibleDeny ? 'Unknown' : 'Allowed';
|
|
34
|
+
}
|
|
35
|
+
const possibleAllow = request.identityStatements.some(s => this.identityStatementUknownAllow(s));
|
|
36
|
+
if (possibleAllow) {
|
|
37
|
+
return 'Unknown';
|
|
38
|
+
}
|
|
39
|
+
return 'ImplicitlyDenied';
|
|
40
|
+
}
|
|
41
|
+
identityStatementAllows(statement) {
|
|
42
|
+
if (statement.resourceMatch &&
|
|
43
|
+
statement.actionMatch &&
|
|
44
|
+
statement.conditionMatch === 'Match' &&
|
|
45
|
+
statement.statement.effect() === 'Allow') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
identityStatementUknownAllow(statement) {
|
|
51
|
+
if (statement.resourceMatch &&
|
|
52
|
+
statement.actionMatch &&
|
|
53
|
+
statement.conditionMatch === 'Unknown' &&
|
|
54
|
+
statement.statement.effect() === 'Allow') {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
identityStatementUknownDeny(statement) {
|
|
60
|
+
if (statement.resourceMatch &&
|
|
61
|
+
statement.actionMatch &&
|
|
62
|
+
statement.conditionMatch === 'Unknown' &&
|
|
63
|
+
statement.statement.effect() === 'Deny') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
identityStatementExplicitDeny(statement) {
|
|
69
|
+
if (statement.resourceMatch &&
|
|
70
|
+
statement.actionMatch &&
|
|
71
|
+
statement.conditionMatch === 'Match' &&
|
|
72
|
+
statement.statement.effect() === 'Deny') {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.DefaultServiceAuthorizer = DefaultServiceAuthorizer;
|
|
79
|
+
//# sourceMappingURL=DefaultServiceAuthorizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultServiceAuthorizer.js","sourceRoot":"","sources":["../../../src/services/DefaultServiceAuthorizer.ts"],"names":[],"mappings":";;;AAMA,MAAa,wBAAwB;IAC5B,SAAS,CAAC,OAAoC;QACnD,MAAM,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACtE,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAA;QAC3D,MAAM,eAAe,GAAG,OAAO,C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OAAO;YACpC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,4BAA4B,CAAC,SAA4B;QAC9D,IAAG,SAAS,CAAC,aAAa;YACxB,SAAS,CAAC,WAAW;YACrB,SAAS,CAAC,cAAc,KAAK,SAAS;YACtC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,OAAO,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAEM,2BAA2B,CAAC,SAA4B;QAC7D,IAAG,SAAS,CAAC,aAAa;YACxB,SAAS,CAAC,WAAW;YACrB,SAAS,CAAC,cAAc,KAAK,SAAS;YACtC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAEM,6BAA6B,CAAC,SAA4B;QAC/D,IAAG,SAAS,CAAC,aAAa;YACxB,SAAS,CAAC,WAAW;YACrB,SAAS,CAAC,cAAc,KAAK,OAAO;YACpC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAjFD,4DAiFC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EvaluationResult } from "../evaluate.js";
|
|
2
|
+
import { AwsRequest } from "../request/request.js";
|
|
3
|
+
import { StatementAnalysis } from "../StatementAnalysis.js";
|
|
4
|
+
export interface ServiceAuthorizationRequest {
|
|
5
|
+
request: AwsRequest;
|
|
6
|
+
identityStatements: StatementAnalysis[];
|
|
7
|
+
}
|
|
8
|
+
export interface ServiceAuthorizer {
|
|
9
|
+
authorize(request: ServiceAuthorizationRequest): EvaluationResult;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ServiceAuthorizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceAuthorizer.d.ts","sourceRoot":"","sources":["../../../src/services/ServiceAuthorizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,UAAU,CAAC;IACpB,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,OAAO,EAAE,2BAA2B,GAAG,gBAAgB,CAAA;CAClE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceAuthorizer.js","sourceRoot":"","sources":["../../../src/services/ServiceAuthorizer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AwsRequest } from './request/request.js';
|
|
2
|
+
interface StringReplaceOptions {
|
|
3
|
+
replaceWildcards: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* This will convert a string to a regex that can be used to match against a string.
|
|
7
|
+
* This will replace any variables in the string with the value of the variable in the request context.
|
|
8
|
+
*
|
|
9
|
+
* @param value the string to convert to a regex
|
|
10
|
+
* @param requestContext the request context to get the variable values from
|
|
11
|
+
* @returns a regex that can be used to match against a string
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertIamStringToRegex(value: string, request: AwsRequest, replaceOptions?: Partial<StringReplaceOptions>): RegExp;
|
|
14
|
+
export interface ArnParts {
|
|
15
|
+
partition: string | undefined;
|
|
16
|
+
service: string | undefined;
|
|
17
|
+
region: string | undefined;
|
|
18
|
+
accountId: string | undefined;
|
|
19
|
+
resource: string | undefined;
|
|
20
|
+
resourceType: string | undefined;
|
|
21
|
+
resourcePath: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function splitArnParts(arn: string): ArnParts;
|
|
24
|
+
/**
|
|
25
|
+
* Splits a resource into two segments. The first segment is the product segment and the second segment is the resource id segment.
|
|
26
|
+
* This could be split by a colon or a slash, so it checks for both.
|
|
27
|
+
*
|
|
28
|
+
* @param resource The resource to split
|
|
29
|
+
* @returns a tuple with the first segment being the product segment (including the separator) and the second segment being the resource id.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getResourceSegments(resource: string): [string, string];
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a value is defined and not null and narrows the type to the defined type
|
|
34
|
+
*
|
|
35
|
+
* @param value the value to check if it is defined
|
|
36
|
+
* @returns if the value is defined and not null
|
|
37
|
+
*/
|
|
38
|
+
export declare function isDefined<T>(value: T | undefined): value is T;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a value is not defined or null
|
|
41
|
+
*
|
|
42
|
+
* @param value the value to check if it is not defined
|
|
43
|
+
* @returns if the value is not defined or null
|
|
44
|
+
*/
|
|
45
|
+
export declare function isNotDefined<T>(value: T | undefined): value is undefined;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAIjD,UAAU,oBAAoB;IAC5B,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAMD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,MAAM,CA4DlI;AAsCD,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAyBnD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBtE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,IAAI,CAAC,CAE7D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,IAAI,SAAS,CAExE"}
|
package/dist/cjs/util.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertIamStringToRegex = convertIamStringToRegex;
|
|
4
|
+
exports.splitArnParts = splitArnParts;
|
|
5
|
+
exports.getResourceSegments = getResourceSegments;
|
|
6
|
+
exports.isDefined = isDefined;
|
|
7
|
+
exports.isNotDefined = isNotDefined;
|
|
8
|
+
const matchesNothing = new RegExp('a^');
|
|
9
|
+
const defaultStringReplaceOptions = {
|
|
10
|
+
replaceWildcards: true
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* This will convert a string to a regex that can be used to match against a string.
|
|
14
|
+
* This will replace any variables in the string with the value of the variable in the request context.
|
|
15
|
+
*
|
|
16
|
+
* @param value the string to convert to a regex
|
|
17
|
+
* @param requestContext the request context to get the variable values from
|
|
18
|
+
* @returns a regex that can be used to match against a string
|
|
19
|
+
*/
|
|
20
|
+
function convertIamStringToRegex(value, request, replaceOptions) {
|
|
21
|
+
const options = { ...defaultStringReplaceOptions, ...replaceOptions };
|
|
22
|
+
let invalidVariableFound = false;
|
|
23
|
+
const newValue = value.replaceAll(/(\$\{.*?\})|(\*)|(\?)/ig, (match, args) => {
|
|
24
|
+
if (match == "?") {
|
|
25
|
+
return replacementValue('\\?', '.', options.replaceWildcards);
|
|
26
|
+
// return '.'
|
|
27
|
+
}
|
|
28
|
+
else if (match == "*") {
|
|
29
|
+
return replacementValue('\\*', ".*?", options.replaceWildcards);
|
|
30
|
+
// return ".*?"
|
|
31
|
+
}
|
|
32
|
+
else if (match == "${*}") {
|
|
33
|
+
return replacementValue("\\$\\{\\*\\}", "\\*", options.replaceWildcards);
|
|
34
|
+
// return "\\*"
|
|
35
|
+
}
|
|
36
|
+
else if (match == "${?}") {
|
|
37
|
+
return replacementValue("\\$\\{\\?\\}", "\\?", options.replaceWildcards);
|
|
38
|
+
// return "\\?"
|
|
39
|
+
}
|
|
40
|
+
else if (match == "${$}") {
|
|
41
|
+
return replacementValue("\\$\\{\\$\\}", "\\$", options.replaceWildcards);
|
|
42
|
+
// return "\\$"
|
|
43
|
+
}
|
|
44
|
+
//
|
|
45
|
+
//This means it'a a variable
|
|
46
|
+
const inTheBrackets = match.slice(2, -1);
|
|
47
|
+
let defaultValue = undefined;
|
|
48
|
+
const defaultParts = inTheBrackets.split(', ');
|
|
49
|
+
if (defaultParts.length == 2) {
|
|
50
|
+
const segmentAfterComma = defaultParts.at(1);
|
|
51
|
+
if (segmentAfterComma?.startsWith("'") && segmentAfterComma.endsWith("'")) {
|
|
52
|
+
defaultValue = segmentAfterComma.slice(1, -1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const variableName = defaultParts.at(0).trim();
|
|
56
|
+
const requestValue = getContextSingleValue(request, variableName);
|
|
57
|
+
if (requestValue) {
|
|
58
|
+
return escapeRegexCharacters(requestValue);
|
|
59
|
+
}
|
|
60
|
+
else if (defaultValue) {
|
|
61
|
+
/*
|
|
62
|
+
TODO: What happens in a request if a multi value context key is used in a string and there
|
|
63
|
+
is a default value? Will it use the default value or will it fail the condition test?
|
|
64
|
+
*/
|
|
65
|
+
return escapeRegexCharacters(defaultValue);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
invalidVariableFound = true;
|
|
69
|
+
/*
|
|
70
|
+
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#policy-vars-no-value
|
|
71
|
+
*/
|
|
72
|
+
return "--undefined---";
|
|
73
|
+
}
|
|
74
|
+
throw new Error('This should never happen');
|
|
75
|
+
});
|
|
76
|
+
if (invalidVariableFound) {
|
|
77
|
+
return matchesNothing;
|
|
78
|
+
}
|
|
79
|
+
return new RegExp('^' + newValue + '$');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Replace regex characters in a string with their escaped versions
|
|
83
|
+
*
|
|
84
|
+
* @param str the string to escape regex characters in
|
|
85
|
+
* @returns the string with regex characters escaped
|
|
86
|
+
*/
|
|
87
|
+
function escapeRegexCharacters(str) {
|
|
88
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the string value of a context key only if it is a single value key
|
|
92
|
+
*
|
|
93
|
+
* @param requestContext the request context to get the value from
|
|
94
|
+
* @param contextKeyName the name of the context key to get the value of
|
|
95
|
+
* @returns the value of the context key if it is a single value key, undefined otherwise
|
|
96
|
+
*/
|
|
97
|
+
function getContextSingleValue(request, contextKeyName) {
|
|
98
|
+
if (!request.contextKeyExists(contextKeyName)) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
const keyValue = request.getContextKeyValue(contextKeyName);
|
|
102
|
+
if (keyValue.isStringValue()) {
|
|
103
|
+
return keyValue.value;
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
function replacementValue(rawString, wildcard, replaceWildcards) {
|
|
108
|
+
if (replaceWildcards) {
|
|
109
|
+
return wildcard;
|
|
110
|
+
}
|
|
111
|
+
return rawString;
|
|
112
|
+
}
|
|
113
|
+
function splitArnParts(arn) {
|
|
114
|
+
const parts = arn.split(':');
|
|
115
|
+
const partition = parts.at(1);
|
|
116
|
+
const service = parts.at(2);
|
|
117
|
+
const region = parts.at(3);
|
|
118
|
+
const accountId = parts.at(4);
|
|
119
|
+
const resource = parts.slice(5).join(":");
|
|
120
|
+
let resourceType = undefined;
|
|
121
|
+
let resourcePath = undefined;
|
|
122
|
+
if (resource?.includes('/') || resource?.includes(':')) {
|
|
123
|
+
const [resourceTypeSegment, resourcePathSegment] = getResourceSegments(resource);
|
|
124
|
+
resourceType = resourceTypeSegment;
|
|
125
|
+
resourcePath = resourcePathSegment;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
partition,
|
|
129
|
+
service,
|
|
130
|
+
region,
|
|
131
|
+
accountId,
|
|
132
|
+
resource,
|
|
133
|
+
resourceType,
|
|
134
|
+
resourcePath
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Splits a resource into two segments. The first segment is the product segment and the second segment is the resource id segment.
|
|
139
|
+
* This could be split by a colon or a slash, so it checks for both.
|
|
140
|
+
*
|
|
141
|
+
* @param resource The resource to split
|
|
142
|
+
* @returns a tuple with the first segment being the product segment (including the separator) and the second segment being the resource id.
|
|
143
|
+
*/
|
|
144
|
+
function getResourceSegments(resource) {
|
|
145
|
+
const slashIndex = resource.indexOf('/');
|
|
146
|
+
const colonIndex = resource.indexOf(':');
|
|
147
|
+
let splitIndex = slashIndex;
|
|
148
|
+
if (slashIndex != -1 && colonIndex != -1) {
|
|
149
|
+
splitIndex = Math.min(slashIndex, colonIndex) + 1;
|
|
150
|
+
}
|
|
151
|
+
else if (colonIndex == -1) {
|
|
152
|
+
splitIndex = slashIndex + 1;
|
|
153
|
+
}
|
|
154
|
+
else if (slashIndex == -1) {
|
|
155
|
+
splitIndex = colonIndex + 1;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw new Error(`Unable to split resource ${resource}`);
|
|
159
|
+
}
|
|
160
|
+
return [resource.slice(0, splitIndex), resource.slice(splitIndex)];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a value is defined and not null and narrows the type to the defined type
|
|
164
|
+
*
|
|
165
|
+
* @param value the value to check if it is defined
|
|
166
|
+
* @returns if the value is defined and not null
|
|
167
|
+
*/
|
|
168
|
+
function isDefined(value) {
|
|
169
|
+
return value !== undefined && value !== null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Checks if a value is not defined or null
|
|
173
|
+
*
|
|
174
|
+
* @param value the value to check if it is not defined
|
|
175
|
+
* @returns if the value is not defined or null
|
|
176
|
+
*/
|
|
177
|
+
function isNotDefined(value) {
|
|
178
|
+
return !isDefined(value);
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;AAoBA,0DA4DC;AAgDD,sCAyBC;AASD,kDAgBC;AAQD,8BAEC;AAQD,oCAEC;AApMD,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAA;AAMvC,MAAM,2BAA2B,GAAyB;IACxD,gBAAgB,EAAE,IAAI;CACvB,CAAA;AAED;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CAAC,KAAa,EAAE,OAAmB,EAAE,cAA8C;IACxH,MAAM,OAAO,GAAG,EAAC,GAAG,2BAA2B,EAAE,GAAG,cAAc,EAAC,CAAA;IAEnE,IAAI,oBAAoB,GAAG,KAAK,CAAA;IAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,yBAAyB,EAAE,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AAG,CAAC,CAAA;IACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAExC,IAAI,UAAU,GAAG,UAAU,CAAA;IAC3B,IAAG,UAAU,IAAI,CAAC,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QACxC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;IACnD,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;AACpE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAI,KAAoB;IAC/C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAI,KAAoB;IAClD,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Action } from "@cloud-copilot/iam-policy";
|
|
2
|
+
import { AwsRequest } from "../request/request.js";
|
|
3
|
+
/**
|
|
4
|
+
* Check if a request matches a set of actions.
|
|
5
|
+
*
|
|
6
|
+
* @param request the request to check
|
|
7
|
+
* @param actions the actions to check against
|
|
8
|
+
* @returns true if the request matches any of the actions, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function requestMatchesActions(request: AwsRequest, actions: Action[]): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a request does not match a set of actions.
|
|
13
|
+
*
|
|
14
|
+
* @param request the request to check
|
|
15
|
+
* @param actions the actions to check against
|
|
16
|
+
* @returns true if the request does not match any of the actions, false if the request matches any of the actions
|
|
17
|
+
*/
|
|
18
|
+
export declare function requestMatchesNotActions(request: AwsRequest, actions: Action[]): boolean;
|
|
19
|
+
//# sourceMappingURL=action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/action/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAiBnD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAiBrF;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAExF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an action action (the part after the colon) to a regular expression.
|
|
3
|
+
*
|
|
4
|
+
* @param action the action to convert to a regular expression
|
|
5
|
+
* @returns a regular that replaces any wildcards in the action with the appropriate regular expression.
|
|
6
|
+
*/
|
|
7
|
+
function convertActionToRegex(action) {
|
|
8
|
+
if (action.indexOf(':') != -1) {
|
|
9
|
+
throw new Error('Action should not contain a colon');
|
|
10
|
+
}
|
|
11
|
+
const pattern = "^" + action.replace(/\?/g, '.').replace(/\*/g, '.*?') + "$";
|
|
12
|
+
return new RegExp(pattern, 'i');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if a request matches a set of actions.
|
|
16
|
+
*
|
|
17
|
+
* @param request the request to check
|
|
18
|
+
* @param actions the actions to check against
|
|
19
|
+
* @returns true if the request matches any of the actions, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
export function requestMatchesActions(request, actions) {
|
|
22
|
+
for (const action of actions) {
|
|
23
|
+
if (action.isWildcardAction()) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
else if (action.isServiceAction()) {
|
|
27
|
+
if (request.action.service() != action.service()) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const actionRegex = convertActionToRegex(action.action());
|
|
31
|
+
if (actionRegex.test(request.action.action())) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error('Unknown action type');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a request does not match a set of actions.
|
|
43
|
+
*
|
|
44
|
+
* @param request the request to check
|
|
45
|
+
* @param actions the actions to check against
|
|
46
|
+
* @returns true if the request does not match any of the actions, false if the request matches any of the actions
|
|
47
|
+
*/
|
|
48
|
+
export function requestMatchesNotActions(request, actions) {
|
|
49
|
+
return !requestMatchesActions(request, actions);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../../src/action/action.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAc;IAC1C,IAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,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