@cloud-copilot/iam-simulate 0.1.0 → 0.1.2

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.
Files changed (239) hide show
  1. package/dist/cjs/condition/baseConditionperatorTests.js +1 -1
  2. package/dist/cjs/condition/baseConditionperatorTests.js.map +1 -1
  3. package/dist/cjs/core_engine/coreSimulatorEngine.d.ts.map +1 -1
  4. package/dist/cjs/core_engine/coreSimulatorEngine.js +4 -1
  5. package/dist/cjs/core_engine/coreSimulatorEngine.js.map +1 -1
  6. package/dist/cjs/index.d.ts +4 -0
  7. package/dist/cjs/index.d.ts.map +1 -1
  8. package/dist/cjs/index.js +8 -0
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/request/request.d.ts +9 -3
  11. package/dist/cjs/request/request.d.ts.map +1 -1
  12. package/dist/cjs/request/request.js +4 -7
  13. package/dist/cjs/request/request.js.map +1 -1
  14. package/dist/cjs/request/requestResource.d.ts +7 -1
  15. package/dist/cjs/request/requestResource.d.ts.map +1 -1
  16. package/dist/cjs/request/requestResource.js +6 -1
  17. package/dist/cjs/request/requestResource.js.map +1 -1
  18. package/dist/cjs/services/DefaultServiceAuthorizer.d.ts.map +1 -1
  19. package/dist/cjs/services/DefaultServiceAuthorizer.js +2 -2
  20. package/dist/cjs/services/DefaultServiceAuthorizer.js.map +1 -1
  21. package/dist/cjs/simulation_engine/contextKeys.d.ts +3 -0
  22. package/dist/cjs/simulation_engine/contextKeys.d.ts.map +1 -0
  23. package/dist/cjs/simulation_engine/contextKeys.js +53 -0
  24. package/dist/cjs/simulation_engine/contextKeys.js.map +1 -0
  25. package/dist/cjs/simulation_engine/simulationEngine.d.ts +25 -0
  26. package/dist/cjs/simulation_engine/simulationEngine.d.ts.map +1 -0
  27. package/dist/cjs/simulation_engine/simulationEngine.js +38 -0
  28. package/dist/cjs/simulation_engine/simulationEngine.js.map +1 -0
  29. package/dist/esm/StatementAnalysis.d.ts +27 -0
  30. package/dist/esm/StatementAnalysis.d.ts.map +1 -0
  31. package/dist/esm/StatementAnalysis.js +2 -0
  32. package/dist/esm/StatementAnalysis.js.map +1 -0
  33. package/dist/esm/action/action.d.ts +9 -1
  34. package/dist/esm/action/action.d.ts.map +1 -1
  35. package/dist/esm/action/action.js +16 -0
  36. package/dist/esm/action/action.js.map +1 -1
  37. package/dist/esm/condition/arn/ArnEquals.d.ts +3 -0
  38. package/dist/esm/condition/arn/ArnEquals.d.ts.map +1 -0
  39. package/dist/esm/condition/arn/ArnEquals.js +8 -0
  40. package/dist/esm/condition/arn/ArnEquals.js.map +1 -0
  41. package/dist/esm/condition/arn/ArnLike.d.ts +3 -0
  42. package/dist/esm/condition/arn/ArnLike.d.ts.map +1 -0
  43. package/dist/esm/condition/arn/ArnLike.js +47 -0
  44. package/dist/esm/condition/arn/ArnLike.js.map +1 -0
  45. package/dist/esm/condition/arn/ArnNotEquals.d.ts +3 -0
  46. package/dist/esm/condition/arn/ArnNotEquals.d.ts.map +1 -0
  47. package/dist/esm/condition/arn/ArnNotEquals.js +8 -0
  48. package/dist/esm/condition/arn/ArnNotEquals.js.map +1 -0
  49. package/dist/esm/condition/arn/ArnNotLike.d.ts +3 -0
  50. package/dist/esm/condition/arn/ArnNotLike.d.ts.map +1 -0
  51. package/dist/esm/condition/arn/ArnNotLike.js +10 -0
  52. package/dist/esm/condition/arn/ArnNotLike.js.map +1 -0
  53. package/dist/esm/condition/baseConditionperatorTests.d.ts +12 -0
  54. package/dist/esm/condition/baseConditionperatorTests.d.ts.map +1 -0
  55. package/dist/esm/condition/baseConditionperatorTests.js +18 -0
  56. package/dist/esm/condition/baseConditionperatorTests.js.map +1 -0
  57. package/dist/esm/condition/binary/BinaryEquals.d.ts +7 -0
  58. package/dist/esm/condition/binary/BinaryEquals.d.ts.map +1 -0
  59. package/dist/esm/condition/binary/BinaryEquals.js +13 -0
  60. package/dist/esm/condition/binary/BinaryEquals.js.map +1 -0
  61. package/dist/esm/condition/boolean/Bool.d.ts +3 -0
  62. package/dist/esm/condition/boolean/Bool.d.ts.map +1 -0
  63. package/dist/esm/condition/boolean/Bool.js +17 -0
  64. package/dist/esm/condition/boolean/Bool.js.map +1 -0
  65. package/dist/esm/condition/condition.d.ts +1 -0
  66. package/dist/esm/condition/condition.d.ts.map +1 -1
  67. package/dist/esm/condition/condition.js +60 -11
  68. package/dist/esm/condition/condition.js.map +1 -1
  69. package/dist/esm/condition/date/DateEquals.d.ts +3 -0
  70. package/dist/esm/condition/date/DateEquals.d.ts.map +1 -0
  71. package/dist/esm/condition/date/DateEquals.js +14 -0
  72. package/dist/esm/condition/date/DateEquals.js.map +1 -0
  73. package/dist/esm/condition/date/DateGreaterThan.d.ts +3 -0
  74. package/dist/esm/condition/date/DateGreaterThan.d.ts.map +1 -0
  75. package/dist/esm/condition/date/DateGreaterThan.js +14 -0
  76. package/dist/esm/condition/date/DateGreaterThan.js.map +1 -0
  77. package/dist/esm/condition/date/DateGreaterThanEquals.d.ts +3 -0
  78. package/dist/esm/condition/date/DateGreaterThanEquals.d.ts.map +1 -0
  79. package/dist/esm/condition/date/DateGreaterThanEquals.js +14 -0
  80. package/dist/esm/condition/date/DateGreaterThanEquals.js.map +1 -0
  81. package/dist/esm/condition/date/DateLessThan.d.ts +3 -0
  82. package/dist/esm/condition/date/DateLessThan.d.ts.map +1 -0
  83. package/dist/esm/condition/date/DateLessThan.js +14 -0
  84. package/dist/esm/condition/date/DateLessThan.js.map +1 -0
  85. package/dist/esm/condition/date/DateLessThanEquals.d.ts +3 -0
  86. package/dist/esm/condition/date/DateLessThanEquals.d.ts.map +1 -0
  87. package/dist/esm/condition/date/DateLessThanEquals.js +14 -0
  88. package/dist/esm/condition/date/DateLessThanEquals.js.map +1 -0
  89. package/dist/esm/condition/date/DateNotEquals.d.ts +3 -0
  90. package/dist/esm/condition/date/DateNotEquals.d.ts.map +1 -0
  91. package/dist/esm/condition/date/DateNotEquals.js +26 -0
  92. package/dist/esm/condition/date/DateNotEquals.js.map +1 -0
  93. package/dist/esm/condition/date/date.d.ts +17 -0
  94. package/dist/esm/condition/date/date.d.ts.map +1 -0
  95. package/dist/esm/condition/date/date.js +38 -0
  96. package/dist/esm/condition/date/date.js.map +1 -0
  97. package/dist/esm/condition/ipaddress/IpAddress.d.ts +3 -0
  98. package/dist/esm/condition/ipaddress/IpAddress.d.ts.map +1 -0
  99. package/dist/esm/condition/ipaddress/IpAddress.js +24 -0
  100. package/dist/esm/condition/ipaddress/IpAddress.js.map +1 -0
  101. package/dist/esm/condition/ipaddress/NotIpAddress.d.ts +3 -0
  102. package/dist/esm/condition/ipaddress/NotIpAddress.d.ts.map +1 -0
  103. package/dist/esm/condition/ipaddress/NotIpAddress.js +28 -0
  104. package/dist/esm/condition/ipaddress/NotIpAddress.js.map +1 -0
  105. package/dist/esm/condition/ipaddress/ipv4.d.ts +24 -0
  106. package/dist/esm/condition/ipaddress/ipv4.d.ts.map +1 -0
  107. package/dist/esm/condition/ipaddress/ipv4.js +54 -0
  108. package/dist/esm/condition/ipaddress/ipv4.js.map +1 -0
  109. package/dist/esm/condition/ipaddress/ipv6.d.ts +24 -0
  110. package/dist/esm/condition/ipaddress/ipv6.d.ts.map +1 -0
  111. package/dist/esm/condition/ipaddress/ipv6.js +106 -0
  112. package/dist/esm/condition/ipaddress/ipv6.js.map +1 -0
  113. package/dist/esm/condition/numeric/NumericEquals.d.ts +3 -0
  114. package/dist/esm/condition/numeric/NumericEquals.d.ts.map +1 -0
  115. package/dist/esm/condition/numeric/NumericEquals.js +14 -0
  116. package/dist/esm/condition/numeric/NumericEquals.js.map +1 -0
  117. package/dist/esm/condition/numeric/NumericGreaterThan.d.ts +3 -0
  118. package/dist/esm/condition/numeric/NumericGreaterThan.d.ts.map +1 -0
  119. package/dist/esm/condition/numeric/NumericGreaterThan.js +14 -0
  120. package/dist/esm/condition/numeric/NumericGreaterThan.js.map +1 -0
  121. package/dist/esm/condition/numeric/NumericGreaterThanEquals.d.ts +3 -0
  122. package/dist/esm/condition/numeric/NumericGreaterThanEquals.d.ts.map +1 -0
  123. package/dist/esm/condition/numeric/NumericGreaterThanEquals.js +14 -0
  124. package/dist/esm/condition/numeric/NumericGreaterThanEquals.js.map +1 -0
  125. package/dist/esm/condition/numeric/NumericLessThan.d.ts +3 -0
  126. package/dist/esm/condition/numeric/NumericLessThan.d.ts.map +1 -0
  127. package/dist/esm/condition/numeric/NumericLessThan.js +14 -0
  128. package/dist/esm/condition/numeric/NumericLessThan.js.map +1 -0
  129. package/dist/esm/condition/numeric/NumericLessThanEquals.d.ts +3 -0
  130. package/dist/esm/condition/numeric/NumericLessThanEquals.d.ts.map +1 -0
  131. package/dist/esm/condition/numeric/NumericLessThanEquals.js +14 -0
  132. package/dist/esm/condition/numeric/NumericLessThanEquals.js.map +1 -0
  133. package/dist/esm/condition/numeric/NumericNotEquals.d.ts +3 -0
  134. package/dist/esm/condition/numeric/NumericNotEquals.d.ts.map +1 -0
  135. package/dist/esm/condition/numeric/NumericNotEquals.js +26 -0
  136. package/dist/esm/condition/numeric/NumericNotEquals.js.map +1 -0
  137. package/dist/esm/condition/numeric/numeric.d.ts +17 -0
  138. package/dist/esm/condition/numeric/numeric.d.ts.map +1 -0
  139. package/dist/esm/condition/numeric/numeric.js +37 -0
  140. package/dist/esm/condition/numeric/numeric.js.map +1 -0
  141. package/dist/esm/condition/string/StringEquals.d.ts.map +1 -0
  142. package/dist/esm/condition/string/StringEquals.js.map +1 -0
  143. package/dist/esm/condition/string/StringEqualsIgnoreCase.d.ts +3 -0
  144. package/dist/esm/condition/string/StringEqualsIgnoreCase.d.ts.map +1 -0
  145. package/dist/esm/condition/string/StringEqualsIgnoreCase.js +14 -0
  146. package/dist/esm/condition/string/StringEqualsIgnoreCase.js.map +1 -0
  147. package/dist/esm/condition/string/StringLike.d.ts +3 -0
  148. package/dist/esm/condition/string/StringLike.d.ts.map +1 -0
  149. package/dist/esm/condition/string/StringLike.js +11 -0
  150. package/dist/esm/condition/string/StringLike.js.map +1 -0
  151. package/dist/esm/condition/string/StringNotEquals.d.ts +3 -0
  152. package/dist/esm/condition/string/StringNotEquals.d.ts.map +1 -0
  153. package/dist/esm/condition/string/StringNotEquals.js +11 -0
  154. package/dist/esm/condition/string/StringNotEquals.js.map +1 -0
  155. package/dist/esm/condition/string/StringNotEqualsIgnoreCase.d.ts +3 -0
  156. package/dist/esm/condition/string/StringNotEqualsIgnoreCase.d.ts.map +1 -0
  157. package/dist/esm/condition/string/StringNotEqualsIgnoreCase.js +10 -0
  158. package/dist/esm/condition/string/StringNotEqualsIgnoreCase.js.map +1 -0
  159. package/dist/esm/condition/string/StringNotLike.d.ts +3 -0
  160. package/dist/esm/condition/string/StringNotLike.d.ts.map +1 -0
  161. package/dist/esm/condition/string/StringNotLike.js +10 -0
  162. package/dist/esm/condition/string/StringNotLike.js.map +1 -0
  163. package/dist/esm/core_engine/coreSimulatorEngine.d.ts +44 -0
  164. package/dist/esm/core_engine/coreSimulatorEngine.d.ts.map +1 -0
  165. package/dist/esm/core_engine/coreSimulatorEngine.js +58 -0
  166. package/dist/esm/core_engine/coreSimulatorEngine.js.map +1 -0
  167. package/dist/esm/evaluate.d.ts +1 -1
  168. package/dist/esm/evaluate.d.ts.map +1 -1
  169. package/dist/esm/index.d.ts +4 -0
  170. package/dist/esm/index.d.ts.map +1 -1
  171. package/dist/esm/index.js +3 -1
  172. package/dist/esm/index.js.map +1 -1
  173. package/dist/esm/principal/principal.d.ts +1 -2
  174. package/dist/esm/principal/principal.d.ts.map +1 -1
  175. package/dist/esm/request/request.d.ts +9 -5
  176. package/dist/esm/request/request.d.ts.map +1 -1
  177. package/dist/esm/request/request.js +4 -8
  178. package/dist/esm/request/request.js.map +1 -1
  179. package/dist/esm/request/requestResource.d.ts +7 -1
  180. package/dist/esm/request/requestResource.d.ts.map +1 -1
  181. package/dist/esm/request/requestResource.js +5 -1
  182. package/dist/esm/request/requestResource.js.map +1 -1
  183. package/dist/esm/resource/resource.d.ts +16 -1
  184. package/dist/esm/resource/resource.d.ts.map +1 -1
  185. package/dist/esm/resource/resource.js +24 -26
  186. package/dist/esm/resource/resource.js.map +1 -1
  187. package/dist/esm/services/DefaultServiceAuthorizer.d.ts +12 -0
  188. package/dist/esm/services/DefaultServiceAuthorizer.d.ts.map +1 -0
  189. package/dist/esm/services/DefaultServiceAuthorizer.js +75 -0
  190. package/dist/esm/services/DefaultServiceAuthorizer.js.map +1 -0
  191. package/dist/esm/services/ServiceAuthorizer.d.ts +11 -0
  192. package/dist/esm/services/ServiceAuthorizer.d.ts.map +1 -0
  193. package/dist/esm/services/ServiceAuthorizer.js +2 -0
  194. package/dist/esm/services/ServiceAuthorizer.js.map +1 -0
  195. package/dist/esm/simulation_engine/contextKeys.d.ts +3 -0
  196. package/dist/esm/simulation_engine/contextKeys.d.ts.map +1 -0
  197. package/dist/esm/simulation_engine/contextKeys.js +49 -0
  198. package/dist/esm/simulation_engine/contextKeys.js.map +1 -0
  199. package/dist/esm/simulation_engine/simulationEngine.d.ts +25 -0
  200. package/dist/esm/simulation_engine/simulationEngine.d.ts.map +1 -0
  201. package/dist/esm/simulation_engine/simulationEngine.js +35 -0
  202. package/dist/esm/simulation_engine/simulationEngine.js.map +1 -0
  203. package/dist/esm/util.d.ts +32 -0
  204. package/dist/esm/util.d.ts.map +1 -1
  205. package/dist/esm/util.js +78 -2
  206. package/dist/esm/util.js.map +1 -1
  207. package/package.json +1 -1
  208. package/dist/cjs/action.d.ts +0 -4
  209. package/dist/cjs/action.d.ts.map +0 -1
  210. package/dist/cjs/action.js +0 -21
  211. package/dist/cjs/action.js.map +0 -1
  212. package/dist/cjs/condition/strings/StringEquals.d.ts.map +0 -1
  213. package/dist/cjs/condition/strings/StringEquals.js +0 -14
  214. package/dist/cjs/condition/strings/StringEquals.js.map +0 -1
  215. package/dist/cjs/request/requestSupplementalData.d.ts +0 -19
  216. package/dist/cjs/request/requestSupplementalData.d.ts.map +0 -1
  217. package/dist/cjs/request/requestSupplementalData.js +0 -37
  218. package/dist/cjs/request/requestSupplementalData.js.map +0 -1
  219. package/dist/cjs/request.d.ts +0 -15
  220. package/dist/cjs/request.d.ts.map +0 -1
  221. package/dist/cjs/request.js +0 -17
  222. package/dist/cjs/request.js.map +0 -1
  223. package/dist/esm/action.d.ts +0 -4
  224. package/dist/esm/action.d.ts.map +0 -1
  225. package/dist/esm/action.js +0 -18
  226. package/dist/esm/action.js.map +0 -1
  227. package/dist/esm/condition/strings/StringEquals.d.ts +0 -3
  228. package/dist/esm/condition/strings/StringEquals.d.ts.map +0 -1
  229. package/dist/esm/condition/strings/StringEquals.js.map +0 -1
  230. package/dist/esm/request/requestSupplementalData.d.ts +0 -19
  231. package/dist/esm/request/requestSupplementalData.d.ts.map +0 -1
  232. package/dist/esm/request/requestSupplementalData.js +0 -30
  233. package/dist/esm/request/requestSupplementalData.js.map +0 -1
  234. package/dist/esm/request.d.ts +0 -15
  235. package/dist/esm/request.d.ts.map +0 -1
  236. package/dist/esm/request.js +0 -9
  237. package/dist/esm/request.js.map +0 -1
  238. /package/dist/{cjs/condition/strings → esm/condition/string}/StringEquals.d.ts +0 -0
  239. /package/dist/esm/condition/{strings → string}/StringEquals.js +0 -0
@@ -0,0 +1,44 @@
1
+ import { Policy } from "@cloud-copilot/iam-policy";
2
+ import { EvaluationResult } from "../evaluate.js";
3
+ import { AwsRequest } from "../request/request.js";
4
+ import { ServiceAuthorizer } from "../services/ServiceAuthorizer.js";
5
+ import { StatementAnalysis } from "../StatementAnalysis.js";
6
+ /**
7
+ * A reqest to authorize a service action.
8
+ */
9
+ export interface AuthorizationRequest {
10
+ /**
11
+ * The request to authorize.
12
+ */
13
+ request: AwsRequest;
14
+ /**
15
+ * The identity policies that are applicable to the principal making the request.
16
+ */
17
+ identityPolicies: Policy[];
18
+ }
19
+ /**
20
+ * Authorizes a request.
21
+ *
22
+ * This assumes all policies have been validated and the request is fully complete and valid.
23
+ *
24
+ * @param request the request to authorize
25
+ * @returns the result of the authorization
26
+ */
27
+ export declare function authorize(request: AuthorizationRequest): EvaluationResult;
28
+ /**
29
+ * Get the appropriate service authorizer for the request. Some services have specific authorization logic in
30
+ * them. If there is no service specific authorizer, a default one will be used.
31
+ *
32
+ * @param request the request to get the authorizer for
33
+ * @returns the service authorizer for the request
34
+ */
35
+ export declare function getServiceAuthorizer(request: AuthorizationRequest): ServiceAuthorizer;
36
+ /**
37
+ * Analyzes a set of identity policies
38
+ *
39
+ * @param identityPolicies the identity policies to analyze
40
+ * @param request the request to analyze against
41
+ * @returns an array of statement analysis results
42
+ */
43
+ export declare function analyzeIdentityPolicies(identityPolicies: Policy[], request: AwsRequest): StatementAnalysis[];
44
+ //# sourceMappingURL=coreSimulatorEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreSimulatorEngine.d.ts","sourceRoot":"","sources":["../../../src/core_engine/coreSimulatorEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAGnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,EAAE,UAAU,CAAC;IAEpB;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAC3B;AAID;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CAOzE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,oBAAoB,GAAG,iBAAiB,CAMrF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,iBAAiB,EAAE,CAe5G"}
@@ -0,0 +1,58 @@
1
+ import { requestMatchesStatementActions } from "../action/action.js";
2
+ import { requestMatchesConditions } from "../condition/condition.js";
3
+ import { requestMatchesStatementResources } from "../resource/resource.js";
4
+ import { DefaultServiceAuthorizer } from "../services/DefaultServiceAuthorizer.js";
5
+ const serviceEngines = {};
6
+ /**
7
+ * Authorizes a request.
8
+ *
9
+ * This assumes all policies have been validated and the request is fully complete and valid.
10
+ *
11
+ * @param request the request to authorize
12
+ * @returns the result of the authorization
13
+ */
14
+ export function authorize(request) {
15
+ const identityAnalysis = analyzeIdentityPolicies(request.identityPolicies, request.request);
16
+ const serviceAuthorizer = getServiceAuthorizer(request);
17
+ return serviceAuthorizer.authorize({
18
+ request: request.request,
19
+ identityStatements: identityAnalysis,
20
+ });
21
+ }
22
+ /**
23
+ * Get the appropriate service authorizer for the request. Some services have specific authorization logic in
24
+ * them. If there is no service specific authorizer, a default one will be used.
25
+ *
26
+ * @param request the request to get the authorizer for
27
+ * @returns the service authorizer for the request
28
+ */
29
+ export function getServiceAuthorizer(request) {
30
+ const serviceName = request.request.action.service().toLowerCase();
31
+ if (serviceEngines[serviceName]) {
32
+ return new serviceEngines[serviceName]();
33
+ }
34
+ return new DefaultServiceAuthorizer;
35
+ }
36
+ /**
37
+ * Analyzes a set of identity policies
38
+ *
39
+ * @param identityPolicies the identity policies to analyze
40
+ * @param request the request to analyze against
41
+ * @returns an array of statement analysis results
42
+ */
43
+ export function analyzeIdentityPolicies(identityPolicies, request) {
44
+ const analysis = [];
45
+ for (const policy of identityPolicies) {
46
+ for (const statement of policy.statements()) {
47
+ analysis.push({
48
+ statement,
49
+ resourceMatch: requestMatchesStatementResources(request, statement),
50
+ actionMatch: requestMatchesStatementActions(request, statement),
51
+ conditionMatch: requestMatchesConditions(request, statement.conditions()),
52
+ principalMatch: 'Match',
53
+ });
54
+ }
55
+ }
56
+ return analysis;
57
+ }
58
+ //# sourceMappingURL=coreSimulatorEngine.js.map
@@ -0,0 +1 @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C3C,QAAQ,CAAC,IAAI,CAAC;gBACZ,SAAS;gBACT,aAAa,EAAE,gCAAgC,CAAC,OAAO,EAAE,SAAS,CAAC;gBACnE,WAAW,EAAE,8BAA8B,CAAC,OAAO,EAAE,SAAS,CAAC;gBAC/D,cAAc,EAAE,wBAAwB,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC;gBACzE,cAAc,EAAE,OAAO;aACxB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,2 +1,2 @@
1
- export type EvaluationResult = 'Allowed' | 'Denied' | 'AllowedWithConditions' | 'ImplicitlyDenied';
1
+ export type EvaluationResult = 'Allowed' | 'ExplicitlyDenied' | 'AllowedWithConditions' | 'ImplicitlyDenied' | 'Unknown';
2
2
  //# sourceMappingURL=evaluate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/evaluate.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,uBAAuB,GAAG,kBAAkB,CAAC"}
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/evaluate.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,kBAAkB,GAAG,uBAAuB,GAAG,kBAAkB,GAAG,SAAS,CAAC"}
@@ -1 +1,5 @@
1
+ export { authorize, type AuthorizationRequest } from './core_engine/coreSimulatorEngine.js';
2
+ export { type EvaluationResult } from './evaluate.js';
3
+ export { AwsRequestImpl, type AwsRequest } from './request/request.js';
4
+ export { RequestContextImpl, type RequestContext } from './requestContext.js';
1
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5F,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,4 @@
1
- "use strict";
1
+ export { authorize } from './core_engine/coreSimulatorEngine.js';
2
+ export { AwsRequestImpl } from './request/request.js';
3
+ export { RequestContextImpl } from './requestContext.js';
2
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA6B,MAAM,sCAAsC,CAAC;AAE5F,OAAO,EAAE,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAuB,MAAM,qBAAqB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Principal } from "@cloud-copilot/iam-policy";
2
2
  import { AwsRequest } from "../request/request.js";
3
- type PrincipalMatchResult = 'Match' | 'NoMatch' | 'AccountLevelMatch';
3
+ export type PrincipalMatchResult = 'Match' | 'NoMatch' | 'AccountLevelMatch';
4
4
  /**
5
5
  * Check to see if a request matches a Principal element in an IAM policy statement
6
6
  *
@@ -27,5 +27,4 @@ export declare function requestMatchesNotPrincipal(request: AwsRequest, notPrinc
27
27
  export declare function requestMatchesPrincipalStatement(request: AwsRequest, principalStatement: Principal): PrincipalMatchResult;
28
28
  export declare function isAssumedRoleArn(principal: string): boolean;
29
29
  export declare function roleArnFromAssumedRoleArn(assumedRoleArn: string): string;
30
- export {};
31
30
  //# sourceMappingURL=principal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"principal.d.ts","sourceRoot":"","sources":["../../../src/principal/principal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AA4CnD,KAAK,oBAAoB,GAAG,OAAO,GAAG,SAAS,GAAG,mBAAmB,CAAA;AAErE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAWzG;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAiB/G;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,SAAS,GAAG,oBAAoB,CAgDzH;AAID,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAKxE"}
1
+ {"version":3,"file":"principal.d.ts","sourceRoot":"","sources":["../../../src/principal/principal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AA4CnD,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,SAAS,GAAG,mBAAmB,CAAA;AAE5E;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAWzG;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAiB/G;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,SAAS,GAAG,oBAAoB,CAgDzH;AAID,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAKxE"}
@@ -2,7 +2,6 @@ import { ContextKey, RequestContext } from "../requestContext.js";
2
2
  import { RequestAction } from "./requestAction.js";
3
3
  import { RequestPrincipal } from "./requestPrincipal.js";
4
4
  import { RequestResource } from "./requestResource.js";
5
- import { RequestSupplementalData } from "./requestSupplementalData.js";
6
5
  /**
7
6
  * A request to be evaluated by the policy engine
8
7
  */
@@ -15,7 +14,7 @@ export interface AwsRequest {
15
14
  /**
16
15
  * The resource to be acted upon
17
16
  */
18
- resource?: RequestResource;
17
+ resource: RequestResource;
19
18
  /**
20
19
  * The context of the request
21
20
  */
@@ -38,11 +37,16 @@ export interface AwsRequest {
38
37
  }
39
38
  export declare class AwsRequestImpl implements AwsRequest {
40
39
  readonly principalString: string;
41
- readonly resourceString: string | undefined;
40
+ readonly resourceIdentifier: {
41
+ resource: string;
42
+ accountId: string;
43
+ };
42
44
  readonly actionString: string;
43
45
  readonly context: RequestContext;
44
- readonly supplementalData: RequestSupplementalData;
45
- constructor(principalString: string, resourceString: string | undefined, actionString: string, context: RequestContext, supplementalData: RequestSupplementalData);
46
+ constructor(principalString: string, resourceIdentifier: {
47
+ resource: string;
48
+ accountId: string;
49
+ }, actionString: string, context: RequestContext);
46
50
  get action(): RequestAction;
47
51
  get resource(): RequestResource;
48
52
  get principal(): RequestPrincipal;
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/request/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAqB,MAAM,o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B,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAuB,MAAM,sBAAsB,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,gBAAgB,CAAC;IAE5B;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,eAAe,CAAC;IAE1B;;OAEG;IACH,OAAO,EAAE,cAAc,CAAA;IAEvB;;;;;;OAMG;IACH,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvC;;;;;OAKG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC7C;AAED,qBAAa,cAAe,YAAW,UAAU;aAEnB,eAAe,EAAE,MAAM;aACvB,kBAAkB,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC;aACzD,YAAY,EAAE,MAAM;aACpB,OAAO,EAAE,cAAc;gBAHvB,eAAe,EAAE,MAAM,EACvB,kBAAkB,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,EACzD,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,cAAc;IAInD,IAAI,MAAM,IAAI,aAAa,CAE1B;IAED,IAAI,QAAQ,IAAI,eAAe,CAE9B;IAED,IAAI,SAAS,IAAI,gBAAgB,CAEhC;IAGM,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKtC,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;CAOnD"}
@@ -2,27 +2,23 @@ import { RequestActionImpl } from "./requestAction.js";
2
2
  import { RequestPrincipalImpl } from "./requestPrincipal.js";
3
3
  import { ResourceRequestImpl } from "./requestResource.js";
4
4
  export class AwsRequestImpl {
5
- constructor(principalString, resourceString, actionString, context, supplementalData) {
5
+ constructor(principalString, resourceIdentifier, actionString, context) {
6
6
  this.principalString = principalString;
7
- this.resourceString = resourceString;
7
+ this.resourceIdentifier = resourceIdentifier;
8
8
  this.actionString = actionString;
9
9
  this.context = context;
10
- this.supplementalData = supplementalData;
11
10
  }
12
11
  get action() {
13
12
  return new RequestActionImpl(this.actionString);
14
13
  }
15
14
  get resource() {
16
- if (this.resourceString === undefined) {
17
- throw new Error('Resource is undefined');
18
- }
19
- return new ResourceRequestImpl(this.resourceString);
15
+ return new ResourceRequestImpl(this.resourceIdentifier.resource, this.resourceIdentifier.accountId);
20
16
  }
21
17
  get principal() {
22
18
  return new RequestPrincipalImpl(this.principalString);
23
19
  }
24
20
  contextKeyExists(key) {
25
- return this.supplementalData.contextKeyValidForRequest(key) && this.context.contextKeyExists(key);
21
+ return this.context.contextKeyExists(key);
26
22
  }
27
23
  getContextKeyValue(key) {
28
24
  if (!this.contextKeyExists(key)) {
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/request/request.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAoB,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAmB,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AA0C5E,MAAM,OAAO,cAAc;IAEzB,YAA4B,eAAuB,EACvB,cAAkC,EAClC,YAAoB,EACpB,OAAuB,EACvB,gBAAyC;QAJzC,oBAAe,GAAf,eAAe,CAAQ;QACvB,mBAAc,GAAd,cAAc,CAAoB;QAClC,iBAAY,GAAZ,YAAY,CAAQ;QACpB,YAAO,GAAP,OAAO,CAAgB;QACvB,qBAAgB,GAAhB,gBAAgB,CAAyB;IAErE,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,QAAQ;QACV,IAAG,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AAC;IAClD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACtG,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACxD,CAAC;IAGM,gBAAgB,CAAC,GAAW;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAGM,kBAAkB,CAAC,GAAW;QACnC,IAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,EAAE,CAAC,CAAA;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;CAEF"}
@@ -23,15 +23,21 @@ export interface RequestResource {
23
23
  * The resource of the ARN
24
24
  */
25
25
  resource(): string;
26
+ /**
27
+ * The account ID of the resource, independent of what is in the ARN
28
+ */
29
+ accountId(): string;
26
30
  }
27
31
  export declare class ResourceRequestImpl implements RequestResource {
28
32
  private readonly rawValue;
29
- constructor(rawValue: string);
33
+ private readonly accountIdString;
34
+ constructor(rawValue: string, accountIdString: string);
30
35
  partition(): string;
31
36
  service(): string;
32
37
  region(): string;
33
38
  account(): string;
34
39
  resource(): string;
35
40
  value(): string;
41
+ accountId(): string;
36
42
  }
37
43
  //# sourceMappingURL=requestResource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestResource.d.ts","sourceRoot":"","sources":["../../../src/request/requestResource.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,IAAI,MAAM,CAAA;IAEf;;OAEG;IACH,SAAS,IAAI,MAAM,CAAA;IAEnB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAA;IAEjB;;OAEG;IACH,MAAM,IAAI,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAA;IAEjB;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAA;CACnB;AAGD,qBAAa,mBAAoB,YAAW,eAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAE7C,SAAS,IAAI,MAAM;IAInB,OAAO,IAAI,MAAM;IAIjB,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,MAAM;IAIjB,QAAQ,IAAI,MAAM;IAIlB,KAAK,IAAI,MAAM;CAGhB"}
1
+ {"version":3,"file":"requestResource.d.ts","sourceRoot":"","sources":["../../../src/request/requestResource.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,IAAI,MAAM,CAAA;IAEf;;OAEG;IACH,SAAS,IAAI,MAAM,CAAA;IAEnB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAA;IAEjB;;OAEG;IACH,MAAM,IAAI,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAA;IAEjB;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAA;IAElB;;OAEG;IACH,SAAS,IAAI,MAAM,CAAA;CACpB;AAGD,qBAAa,mBAAoB,YAAW,eAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAU,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAlD,QAAQ,EAAE,MAAM,EAAmB,eAAe,EAAE,MAAM;IAEvF,SAAS,IAAI,MAAM;IAInB,OAAO,IAAI,MAAM;IAIjB,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,MAAM;IAIjB,QAAQ,IAAI,MAAM;IAIlB,KAAK,IAAI,MAAM;IAIf,SAAS,IAAI,MAAM;CAGpB"}
@@ -1,6 +1,7 @@
1
1
  export class ResourceRequestImpl {
2
- constructor(rawValue) {
2
+ constructor(rawValue, accountIdString) {
3
3
  this.rawValue = rawValue;
4
+ this.accountIdString = accountIdString;
4
5
  }
5
6
  partition() {
6
7
  return this.value().split(":").at(1);
@@ -20,5 +21,8 @@ export class ResourceRequestImpl {
20
21
  value() {
21
22
  return this.rawValue;
22
23
  }
24
+ accountId() {
25
+ return this.accountIdString;
26
+ }
23
27
  }
24
28
  //# sourceMappingURL=requestResource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestResource.js","sourceRoot":"","sources":["../../../src/request/requestResource.ts"],"names":[],"mappings":"AAkCA,MAAM,OAAO,mBAAmB;IAC9B,YAA6B,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;IAAG,CAAC;IAEjD,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACnD,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
1
+ {"version":3,"file":"requestResource.js","sourceRoot":"","sources":["../../../src/request/requestResource.ts"],"names":[],"mappings":"AAuCA,MAAM,OAAO,mBAAmB;IAC9B,YAA6B,QAAgB,EAAmB,eAAuB;QAA1D,aAAQ,GAAR,QAAQ,CAAQ;QAAmB,oBAAe,GAAf,eAAe,CAAQ;IAAI,CAAC;IAE5F,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IACvC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACnD,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;CACF"}
@@ -1,5 +1,13 @@
1
- import { Resource } from "@cloud-copilot/iam-policy";
1
+ import { Resource, Statement } from "@cloud-copilot/iam-policy";
2
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;
3
11
  /**
4
12
  * Check if a request matches a set of resources.
5
13
  *
@@ -8,5 +16,12 @@ import { AwsRequest } from "../request/request.js";
8
16
  * @returns true if the request matches any of the resources, false otherwise
9
17
  */
10
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
+ */
11
26
  export declare function requestMatchesNotResources(request: AwsRequest, policyResources: Resource[]): boolean;
12
27
  //# sourceMappingURL=resource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/resource/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAmBnD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,OAAO,CAEjG;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,OAAO,CAEpG"}
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"}
@@ -1,4 +1,4 @@
1
- import { convertIamStringToRegex } from "../util.js";
1
+ import { convertIamStringToRegex, getResourceSegments } from "../util.js";
2
2
  //TODO: Make a check to see if the action is a wildcard only action. This will have to happen outside of these functions.
3
3
  /**
4
4
  * Convert a resource segment to a regular expression. This is without variables.
@@ -13,6 +13,22 @@ function convertResourceSegmentToRegex(segment) {
13
13
  const pattern = "^" + segment.replace(/\?/g, '.').replace(/\*/g, '.*?') + "$";
14
14
  return new RegExp(pattern, 'i');
15
15
  }
16
+ /**
17
+ * Check if a request matches the Resource or NotResource elements of a statement.
18
+ *
19
+ * @param request the request to check
20
+ * @param statement the statement to check against
21
+ * @returns true if the request matches the resources in the statement, false otherwise
22
+ */
23
+ export function requestMatchesStatementResources(request, statement) {
24
+ if (statement.isResourceStatement()) {
25
+ return requestMatchesResources(request, statement.resources());
26
+ }
27
+ else if (statement.isNotResourceStatement()) {
28
+ return requestMatchesNotResources(request, statement.notResources());
29
+ }
30
+ return true;
31
+ }
16
32
  /**
17
33
  * Check if a request matches a set of resources.
18
34
  *
@@ -23,6 +39,13 @@ function convertResourceSegmentToRegex(segment) {
23
39
  export function requestMatchesResources(request, policyResources) {
24
40
  return policyResources.some(policyResource => singleResourceMatchesRequest(request, policyResource));
25
41
  }
42
+ /**
43
+ * Check if a request matches a NotResource element in a policy.
44
+ *
45
+ * @param request the request to check
46
+ * @param policyResources the resources to check against
47
+ * @returns true if the request does not match any of the resources, false otherwise
48
+ */
26
49
  export function requestMatchesNotResources(request, policyResources) {
27
50
  return !requestMatchesResources(request, policyResources);
28
51
  }
@@ -69,29 +92,4 @@ function singleResourceMatchesRequest(request, policyResource) {
69
92
  throw new Error('Unknown resource type');
70
93
  }
71
94
  }
72
- /**
73
- * Splits a resource into two segments. The first segment is the product segment and the second segment is the resource id segment.
74
- * This could be split by a colon or a slash, so it checks for both.
75
- *
76
- * @param resource The resource to split
77
- * @returns a tuple with the first segment being the product segment (including the separator) and the second segment being the resource id.
78
- */
79
- function getResourceSegments(resource) {
80
- const slashIndex = resource.indexOf('/');
81
- const colonIndex = resource.indexOf(':');
82
- let splitIndex = slashIndex;
83
- if (slashIndex != -1 && colonIndex != -1) {
84
- splitIndex = Math.min(slashIndex, colonIndex) + 1;
85
- }
86
- else if (colonIndex == -1) {
87
- splitIndex = slashIndex + 1;
88
- }
89
- else if (slashIndex == -1) {
90
- splitIndex = colonIndex + 1;
91
- }
92
- else {
93
- throw new Error(`Unable to split resource ${resource}`);
94
- }
95
- return [resource.slice(0, splitIndex), resource.slice(splitIndex)];
96
- }
97
95
  //# sourceMappingURL=resource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/resource/resource.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,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,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,CAAA;IAC7E,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAmB,EAAE,eAA2B;IACtF,OAAO,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,4BAA4B,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAA;AACtG,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,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AAK,CAAA;QACd,CAAC;QAED,MAAM,iBAAiB,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAEzE,IAAG,CAAC,uBAAuB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC/E,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { EvaluationResult } 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;AAExF,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,75 @@
1
+ export class DefaultServiceAuthorizer {
2
+ authorize(request) {
3
+ const identityStatementResult = this.identityStatementResult(request);
4
+ const principalAccount = request.request.principal.accountId();
5
+ const resourceAccount = request.request.resource?.accountId();
6
+ /**
7
+ * Add checks for:
8
+ * * resource policies
9
+ * * service control policies
10
+ * * boundary policies
11
+ * * vpc endpoint policies
12
+ * * session policies (maybe these are just part of identity policies?)
13
+ */
14
+ if (identityStatementResult === 'Allowed') {
15
+ if (principalAccount === resourceAccount) {
16
+ return identityStatementResult;
17
+ }
18
+ return 'ImplicitlyDenied';
19
+ }
20
+ return identityStatementResult;
21
+ }
22
+ identityStatementResult(request) {
23
+ const explicitDeny = request.identityStatements.some(s => this.identityStatementExplicitDeny(s));
24
+ if (explicitDeny) {
25
+ return 'ExplicitlyDenied';
26
+ }
27
+ const explicitAllow = request.identityStatements.some(s => this.identityStatementAllows(s));
28
+ const possibleDeny = request.identityStatements.some(s => this.identityStatementUknownDeny(s));
29
+ if (explicitAllow) {
30
+ return possibleDeny ? 'Unknown' : 'Allowed';
31
+ }
32
+ const possibleAllow = request.identityStatements.some(s => this.identityStatementUknownAllow(s));
33
+ if (possibleAllow) {
34
+ return 'Unknown';
35
+ }
36
+ return 'ImplicitlyDenied';
37
+ }
38
+ identityStatementAllows(statement) {
39
+ if (statement.resourceMatch &&
40
+ statement.actionMatch &&
41
+ statement.conditionMatch === 'Match' &&
42
+ statement.statement.effect() === 'Allow') {
43
+ return true;
44
+ }
45
+ return false;
46
+ }
47
+ identityStatementUknownAllow(statement) {
48
+ if (statement.resourceMatch &&
49
+ statement.actionMatch &&
50
+ statement.conditionMatch === 'Unknown' &&
51
+ statement.statement.effect() === 'Allow') {
52
+ return true;
53
+ }
54
+ return false;
55
+ }
56
+ identityStatementUknownDeny(statement) {
57
+ if (statement.resourceMatch &&
58
+ statement.actionMatch &&
59
+ statement.conditionMatch === 'Unknown' &&
60
+ statement.statement.effect() === 'Deny') {
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ identityStatementExplicitDeny(statement) {
66
+ if (statement.resourceMatch &&
67
+ statement.actionMatch &&
68
+ statement.conditionMatch === 'Match' &&
69
+ statement.statement.effect() === 'Deny') {
70
+ return true;
71
+ }
72
+ return false;
73
+ }
74
+ }
75
+ //# sourceMappingURL=DefaultServiceAuthorizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultServiceAuthorizer.js","sourceRoot":"","sources":["../../../src/services/DefaultServiceAuthorizer.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,wBAAwB;IAC5B,SAAS,CAAC,OAAoC;QACnD,MAAM,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACtE,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,CAAA;QAC9D,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAA;QAC7D;;;;;;;WAOG;QACH,IAAG,uBAAuB,KAAK,SAAS,EAAE,CAAC;YACzC,IAAG,gBAAgB,KAAK,eAAe,EAAE,CAAC;gBACxC,OAAO,uBAAuB,CAAA;YAChC,CAAC;YACD,OAAO,kBAAkB,CAAA;QAC3B,CAAC;QACD,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAEM,uBAAuB,CAAC,OAAoC;QACjE,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,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,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"}
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ServiceAuthorizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServiceAuthorizer.js","sourceRoot":"","sources":["../../../src/services/ServiceAuthorizer.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare function allowedContextKeysForRequest(service: string, action: string, resource: string): Promise<string[]>;
2
+ export declare function convertPatternToRegex(pattern: string): string;
3
+ //# sourceMappingURL=contextKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextKeys.d.ts","sourceRoot":"","sources":["../../../src/simulation_engine/contextKeys.ts"],"names":[],"mappings":"AAEA,wBAAsB,4BAA4B,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA4BvH;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB7D"}
@@ -0,0 +1,49 @@
1
+ import { iamActionDetails, iamResourceTypeDetails } from "@cloud-copilot/iam-data";
2
+ export async function allowedContextKeysForRequest(service, action, resource) {
3
+ const actionDetails = await iamActionDetails(service, action);
4
+ const actionConditionKeys = actionDetails.conditionKeys;
5
+ if (actionDetails.resourceTypes.length === 0) {
6
+ return actionConditionKeys;
7
+ }
8
+ const matchingResourceTypes = [];
9
+ for (const rt of actionDetails.resourceTypes) {
10
+ const resourceType = await iamResourceTypeDetails(service, rt.name);
11
+ const pattern = convertPatternToRegex(resourceType.arn);
12
+ const match = resource.match(new RegExp(pattern));
13
+ if (match) {
14
+ matchingResourceTypes.push(resourceType);
15
+ }
16
+ }
17
+ if (matchingResourceTypes.length != 1) {
18
+ const matchNames = matchingResourceTypes.map(rt => rt.key).join(", ");
19
+ throw new Error(`found ${matchingResourceTypes.length} matching resource types for ${resource}: ${matchNames}`);
20
+ }
21
+ console.log(matchingResourceTypes[0].key);
22
+ return [
23
+ ...matchingResourceTypes[0].conditionKeys,
24
+ ...actionConditionKeys
25
+ ];
26
+ }
27
+ export function convertPatternToRegex(pattern) {
28
+ const regex = pattern.replace(/\$\{.*?\}/g, (match) => {
29
+ const name = match.substring(2, match.length - 1);
30
+ const camelName = name.at(0)?.toLowerCase() + name.substring(1);
31
+ return `(?<${camelName}>(.*?))`;
32
+ });
33
+ return `^${regex}$`;
34
+ // const parts = pattern.split('/')
35
+ // const lastPart = parts[parts.length - 1]
36
+ // const modifiedParts = parts.map((part) => {
37
+ // if (part.startsWith('${') && part.endsWith('}')) {
38
+ // const name = part.substring(2, part.length - 1)
39
+ // const camelName = name.at(0)?.toLowerCase() + name.substring(1)
40
+ // if (part === lastPart) {
41
+ // return `(?<${camelName}>(.*))`
42
+ // }
43
+ // return `(?<${camelName}>([^\/]+))`
44
+ // }
45
+ // return part
46
+ // })
47
+ // return modifiedParts.join('\/')
48
+ }
49
+ //# sourceMappingURL=contextKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextKeys.js","sourceRoot":"","sources":["../../../src/simulation_engine/contextKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAgB,MAAM,yBAAyB,CAAC;AAEjG,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,OAAe,EAAE,MAAc,EAAE,QAAgB;IAClG,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9D,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC;IACxD,IAAG,aAAa,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5C,OAAO,mBAAmB,CAAA;IAC5B,CAAC;IAED,MAAM,qBAAqB,GAAmB,EAAE,CAAC;IACjD,KAAI,MAAM,EAAE,IAAI,aAA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