@cloud-copilot/iam-simulate 0.1.11 → 0.1.13-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/SCPAnalysis.d.ts.map +1 -1
- package/dist/cjs/StatementAnalysis.d.ts +14 -0
- package/dist/cjs/StatementAnalysis.d.ts.map +1 -1
- package/dist/cjs/StatementAnalysis.js +51 -0
- package/dist/cjs/StatementAnalysis.js.map +1 -1
- package/dist/cjs/action/action.d.ts +13 -3
- package/dist/cjs/action/action.d.ts.map +1 -1
- package/dist/cjs/action/action.js +43 -21
- package/dist/cjs/action/action.js.map +1 -1
- package/dist/cjs/condition/condition.d.ts +7 -3
- package/dist/cjs/condition/condition.d.ts.map +1 -1
- package/dist/cjs/condition/condition.js +138 -27
- package/dist/cjs/condition/condition.js.map +1 -1
- package/dist/cjs/core_engine/coreSimulatorEngine.d.ts +9 -11
- package/dist/cjs/core_engine/coreSimulatorEngine.d.ts.map +1 -1
- package/dist/cjs/core_engine/coreSimulatorEngine.js +136 -26
- package/dist/cjs/core_engine/coreSimulatorEngine.js.map +1 -1
- package/dist/cjs/evaluate.d.ts +46 -0
- package/dist/cjs/evaluate.d.ts.map +1 -1
- package/dist/cjs/explain/displayExplainCli.d.ts +3 -0
- package/dist/cjs/explain/displayExplainCli.d.ts.map +1 -0
- package/dist/cjs/explain/displayExplainCli.js +145 -0
- package/dist/cjs/explain/displayExplainCli.js.map +1 -0
- package/dist/cjs/explain/statementExplain.d.ts +50 -0
- package/dist/cjs/explain/statementExplain.d.ts.map +1 -0
- package/dist/cjs/explain/statementExplain.js +7 -0
- package/dist/cjs/explain/statementExplain.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/principal/principal.d.ts +14 -4
- package/dist/cjs/principal/principal.d.ts.map +1 -1
- package/dist/cjs/principal/principal.js +101 -33
- package/dist/cjs/principal/principal.js.map +1 -1
- package/dist/cjs/resource/resource.d.ts +13 -3
- package/dist/cjs/resource/resource.d.ts.map +1 -1
- package/dist/cjs/resource/resource.js +66 -14
- package/dist/cjs/resource/resource.js.map +1 -1
- package/dist/cjs/services/DefaultServiceAuthorizer.d.ts +2 -34
- package/dist/cjs/services/DefaultServiceAuthorizer.d.ts.map +1 -1
- package/dist/cjs/services/DefaultServiceAuthorizer.js +43 -127
- package/dist/cjs/services/DefaultServiceAuthorizer.js.map +1 -1
- package/dist/cjs/services/ServiceAuthorizer.d.ts +5 -7
- package/dist/cjs/services/ServiceAuthorizer.d.ts.map +1 -1
- package/dist/cjs/simulation_engine/simulationEngine.d.ts +2 -4
- package/dist/cjs/simulation_engine/simulationEngine.d.ts.map +1 -1
- package/dist/cjs/simulation_engine/simulationEngine.js +19 -8
- package/dist/cjs/simulation_engine/simulationEngine.js.map +1 -1
- package/dist/cjs/simulation_engine/unsafeSimulationEngine.d.ts.map +1 -1
- package/dist/cjs/simulation_engine/unsafeSimulationEngine.js +5 -4
- package/dist/cjs/simulation_engine/unsafeSimulationEngine.js.map +1 -1
- package/dist/cjs/util.js +1 -1
- package/dist/esm/SCPAnalysis.d.ts.map +1 -1
- package/dist/esm/StatementAnalysis.d.ts +14 -0
- package/dist/esm/StatementAnalysis.d.ts.map +1 -1
- package/dist/esm/StatementAnalysis.js +48 -1
- package/dist/esm/StatementAnalysis.js.map +1 -1
- package/dist/esm/action/action.d.ts +13 -3
- package/dist/esm/action/action.d.ts.map +1 -1
- package/dist/esm/action/action.js +43 -21
- package/dist/esm/action/action.js.map +1 -1
- package/dist/esm/condition/condition.d.ts +7 -3
- package/dist/esm/condition/condition.d.ts.map +1 -1
- package/dist/esm/condition/condition.js +138 -27
- package/dist/esm/condition/condition.js.map +1 -1
- package/dist/esm/core_engine/coreSimulatorEngine.d.ts +9 -11
- package/dist/esm/core_engine/coreSimulatorEngine.d.ts.map +1 -1
- package/dist/esm/core_engine/coreSimulatorEngine.js +136 -26
- package/dist/esm/core_engine/coreSimulatorEngine.js.map +1 -1
- package/dist/esm/evaluate.d.ts +46 -0
- package/dist/esm/evaluate.d.ts.map +1 -1
- package/dist/esm/explain/displayExplainCli.d.ts +3 -0
- package/dist/esm/explain/displayExplainCli.d.ts.map +1 -0
- package/dist/esm/explain/displayExplainCli.js +142 -0
- package/dist/esm/explain/displayExplainCli.js.map +1 -0
- package/dist/esm/explain/statementExplain.d.ts +50 -0
- package/dist/esm/explain/statementExplain.d.ts.map +1 -0
- package/dist/esm/explain/statementExplain.js +6 -0
- package/dist/esm/explain/statementExplain.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/principal/principal.d.ts +14 -4
- package/dist/esm/principal/principal.d.ts.map +1 -1
- package/dist/esm/principal/principal.js +101 -33
- package/dist/esm/principal/principal.js.map +1 -1
- package/dist/esm/resource/resource.d.ts +13 -3
- package/dist/esm/resource/resource.d.ts.map +1 -1
- package/dist/esm/resource/resource.js +66 -14
- package/dist/esm/resource/resource.js.map +1 -1
- package/dist/esm/services/DefaultServiceAuthorizer.d.ts +2 -34
- package/dist/esm/services/DefaultServiceAuthorizer.d.ts.map +1 -1
- package/dist/esm/services/DefaultServiceAuthorizer.js +43 -127
- package/dist/esm/services/DefaultServiceAuthorizer.js.map +1 -1
- package/dist/esm/services/ServiceAuthorizer.d.ts +5 -7
- package/dist/esm/services/ServiceAuthorizer.d.ts.map +1 -1
- package/dist/esm/simulation_engine/simulationEngine.d.ts +2 -4
- package/dist/esm/simulation_engine/simulationEngine.d.ts.map +1 -1
- package/dist/esm/simulation_engine/simulationEngine.js +20 -9
- package/dist/esm/simulation_engine/simulationEngine.js.map +1 -1
- package/dist/esm/simulation_engine/unsafeSimulationEngine.d.ts.map +1 -1
- package/dist/esm/simulation_engine/unsafeSimulationEngine.js +6 -5
- package/dist/esm/simulation_engine/unsafeSimulationEngine.js.map +1 -1
- package/dist/esm/util.js +1 -1
- package/package.json +2 -2
|
@@ -14,14 +14,23 @@ exports.requestMatchesStatementPrincipals = requestMatchesStatementPrincipals;
|
|
|
14
14
|
* @returns if the request matches the Principal element, and if so, how it matches
|
|
15
15
|
*/
|
|
16
16
|
function requestMatchesPrincipal(request, principal) {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
return
|
|
17
|
+
const explains = principal.map(principalStatement => requestMatchesPrincipalStatement(request, principalStatement));
|
|
18
|
+
if (explains.some(exp => exp.matches === 'Match')) {
|
|
19
|
+
return {
|
|
20
|
+
matches: 'Match',
|
|
21
|
+
explains
|
|
22
|
+
};
|
|
20
23
|
}
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
24
|
+
if (explains.some(exp => exp.matches === 'AccountLevelMatch')) {
|
|
25
|
+
return {
|
|
26
|
+
matches: 'AccountLevelMatch',
|
|
27
|
+
explains
|
|
28
|
+
};
|
|
23
29
|
}
|
|
24
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
matches: 'NoMatch',
|
|
32
|
+
explains
|
|
33
|
+
};
|
|
25
34
|
}
|
|
26
35
|
/**
|
|
27
36
|
* Check to see if a request matches a NotPrincipal element in an IAM policy statement
|
|
@@ -31,20 +40,40 @@ function requestMatchesPrincipal(request, principal) {
|
|
|
31
40
|
* @returns
|
|
32
41
|
*/
|
|
33
42
|
function requestMatchesNotPrincipal(request, notPrincipal) {
|
|
34
|
-
const matches = notPrincipal.map(principalStatement => requestMatchesPrincipalStatement(request, principalStatement))
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
// const matches = notPrincipal.map(principalStatement => requestMatchesPrincipalStatement(request, principalStatement))
|
|
44
|
+
const explains = notPrincipal.map(principalStatement => {
|
|
45
|
+
const explain = requestMatchesPrincipalStatement(request, principalStatement);
|
|
46
|
+
/**
|
|
47
|
+
* Need to do research on this. If there is an account level match on a NotPrincipal, does that
|
|
48
|
+
* mean it tentatively matches the NotPrincipal, or does it mean it does not match the NotPrincipal?
|
|
49
|
+
*
|
|
50
|
+
* We need to test this.
|
|
51
|
+
*/
|
|
52
|
+
if (explain.matches === 'Match' || explain.matches === 'AccountLevelMatch') {
|
|
53
|
+
explain.matches = 'NoMatch';
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
explain.matches = 'Match';
|
|
57
|
+
}
|
|
58
|
+
return explain;
|
|
59
|
+
});
|
|
60
|
+
if (explains.some(exp => exp.matches === 'Match')) {
|
|
61
|
+
return {
|
|
62
|
+
matches: 'Match',
|
|
63
|
+
explains
|
|
64
|
+
};
|
|
46
65
|
}
|
|
47
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
matches: 'NoMatch',
|
|
68
|
+
explains
|
|
69
|
+
};
|
|
70
|
+
// if(matches.includes('Match')) {
|
|
71
|
+
// return 'NoMatch'
|
|
72
|
+
// }
|
|
73
|
+
// if(matches.includes('AccountLevelMatch')) {
|
|
74
|
+
// return 'NoMatch'
|
|
75
|
+
// }
|
|
76
|
+
// return 'Match'
|
|
48
77
|
}
|
|
49
78
|
/**
|
|
50
79
|
* Check to see if a request matches a principal statement
|
|
@@ -56,44 +85,81 @@ function requestMatchesNotPrincipal(request, notPrincipal) {
|
|
|
56
85
|
function requestMatchesPrincipalStatement(request, principalStatement) {
|
|
57
86
|
if (principalStatement.isServicePrincipal()) {
|
|
58
87
|
if (principalStatement.service() === request.principal.value()) {
|
|
59
|
-
return
|
|
88
|
+
return {
|
|
89
|
+
matches: 'Match',
|
|
90
|
+
principal: principalStatement.value(),
|
|
91
|
+
};
|
|
60
92
|
}
|
|
61
|
-
return
|
|
93
|
+
return {
|
|
94
|
+
matches: 'NoMatch',
|
|
95
|
+
principal: principalStatement.value(),
|
|
96
|
+
};
|
|
62
97
|
}
|
|
63
98
|
if (principalStatement.isCanonicalUserPrincipal()) {
|
|
64
99
|
if (principalStatement.canonicalUser() === request.principal.value()) {
|
|
65
|
-
return
|
|
100
|
+
return {
|
|
101
|
+
matches: 'Match',
|
|
102
|
+
principal: principalStatement.value(),
|
|
103
|
+
};
|
|
66
104
|
}
|
|
67
|
-
return
|
|
105
|
+
return {
|
|
106
|
+
matches: 'NoMatch',
|
|
107
|
+
principal: principalStatement.value(),
|
|
108
|
+
};
|
|
68
109
|
}
|
|
69
110
|
if (principalStatement.isFederatedPrincipal()) {
|
|
70
111
|
if (principalStatement.federated() === request.principal.value()) {
|
|
71
|
-
return
|
|
112
|
+
return {
|
|
113
|
+
matches: 'Match',
|
|
114
|
+
principal: principalStatement.value(),
|
|
115
|
+
};
|
|
72
116
|
}
|
|
73
|
-
return
|
|
117
|
+
return {
|
|
118
|
+
matches: 'NoMatch',
|
|
119
|
+
principal: principalStatement.value(),
|
|
120
|
+
};
|
|
74
121
|
}
|
|
75
122
|
if (principalStatement.isWildcardPrincipal()) {
|
|
76
|
-
return
|
|
123
|
+
return {
|
|
124
|
+
matches: 'Match',
|
|
125
|
+
principal: principalStatement.value(),
|
|
126
|
+
};
|
|
77
127
|
}
|
|
78
128
|
if (principalStatement.isAccountPrincipal()) {
|
|
79
129
|
if (principalStatement.accountId() === request.principal.accountId()) {
|
|
80
|
-
return
|
|
130
|
+
return {
|
|
131
|
+
matches: 'AccountLevelMatch',
|
|
132
|
+
principal: principalStatement.value(),
|
|
133
|
+
};
|
|
81
134
|
}
|
|
82
|
-
return
|
|
135
|
+
return {
|
|
136
|
+
matches: 'NoMatch',
|
|
137
|
+
principal: principalStatement.value(),
|
|
138
|
+
};
|
|
83
139
|
}
|
|
84
140
|
if (principalStatement.isAwsPrincipal()) {
|
|
85
141
|
if (isAssumedRoleArn(request.principal.value())) {
|
|
86
142
|
const sessionArn = request.principal.value();
|
|
87
143
|
const roleArn = roleArnFromAssumedRoleArn(sessionArn);
|
|
88
144
|
if (principalStatement.arn() === roleArn || principalStatement.arn() === sessionArn) {
|
|
89
|
-
return
|
|
145
|
+
return {
|
|
146
|
+
matches: 'Match',
|
|
147
|
+
principal: principalStatement.value(),
|
|
148
|
+
roleForSessionArn: roleArn,
|
|
149
|
+
};
|
|
90
150
|
}
|
|
91
151
|
}
|
|
92
152
|
if (principalStatement.arn() === request.principal.value()) {
|
|
93
|
-
return
|
|
153
|
+
return {
|
|
154
|
+
matches: 'Match',
|
|
155
|
+
principal: principalStatement.value(),
|
|
156
|
+
};
|
|
94
157
|
}
|
|
95
158
|
}
|
|
96
|
-
return
|
|
159
|
+
return {
|
|
160
|
+
matches: 'NoMatch',
|
|
161
|
+
principal: principalStatement.value(),
|
|
162
|
+
};
|
|
97
163
|
}
|
|
98
164
|
const assumedRoleArnRegex = /^arn:aws:sts::\d{12}:assumed-role\/.*$/;
|
|
99
165
|
function isAssumedRoleArn(principal) {
|
|
@@ -114,10 +180,12 @@ function roleArnFromAssumedRoleArn(assumedRoleArn) {
|
|
|
114
180
|
*/
|
|
115
181
|
function requestMatchesStatementPrincipals(request, statement) {
|
|
116
182
|
if (statement.isPrincipalStatement()) {
|
|
117
|
-
|
|
183
|
+
const { matches, explains } = requestMatchesPrincipal(request, statement.principals());
|
|
184
|
+
return { matches, details: { principals: explains } };
|
|
118
185
|
}
|
|
119
186
|
else if (statement.isNotPrincipalStatement()) {
|
|
120
|
-
|
|
187
|
+
const { matches, explains } = requestMatchesNotPrincipal(request, statement.notPrincipals());
|
|
188
|
+
return { matches, details: { notPrincipals: explains } };
|
|
121
189
|
}
|
|
122
190
|
throw new Error('Statement should have Principal or NotPrincipal');
|
|
123
191
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../../src/principal/principal.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../../src/principal/principal.ts"],"names":[],"mappings":";;AAuDA,0DAoBC;AASD,gEAyCC;AASD,4EAqFC;AAID,4CAEC;AAED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AC,OAAO,EAAE,SAAS,CAAC,aAAa,EAAE,CAAC,CAAA;QAC1F,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,EAAC,aAAa,EAAE,QAAQ,EAAC,EAAC,CAAA;IACtD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;AACpE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Resource, Statement } from "@cloud-copilot/iam-policy";
|
|
2
|
+
import { ResourceExplain, StatementExplain } from "../explain/statementExplain.js";
|
|
2
3
|
import { AwsRequest } from "../request/request.js";
|
|
3
4
|
/**
|
|
4
5
|
* Check if a request matches the Resource or NotResource elements of a statement.
|
|
@@ -7,7 +8,10 @@ import { AwsRequest } from "../request/request.js";
|
|
|
7
8
|
* @param statement the statement to check against
|
|
8
9
|
* @returns true if the request matches the resources in the statement, false otherwise
|
|
9
10
|
*/
|
|
10
|
-
export declare function requestMatchesStatementResources(request: AwsRequest, statement: Statement):
|
|
11
|
+
export declare function requestMatchesStatementResources(request: AwsRequest, statement: Statement): {
|
|
12
|
+
matches: boolean;
|
|
13
|
+
details: Pick<StatementExplain, 'resources' | 'notResources'>;
|
|
14
|
+
};
|
|
11
15
|
/**
|
|
12
16
|
* Check if a request matches a set of resources.
|
|
13
17
|
*
|
|
@@ -15,7 +19,10 @@ export declare function requestMatchesStatementResources(request: AwsRequest, st
|
|
|
15
19
|
* @param policyResources the resources to check against
|
|
16
20
|
* @returns true if the request matches any of the resources, false otherwise
|
|
17
21
|
*/
|
|
18
|
-
export declare function requestMatchesResources(request: AwsRequest, policyResources: Resource[]):
|
|
22
|
+
export declare function requestMatchesResources(request: AwsRequest, policyResources: Resource[]): {
|
|
23
|
+
matches: boolean;
|
|
24
|
+
explains: ResourceExplain[];
|
|
25
|
+
};
|
|
19
26
|
/**
|
|
20
27
|
* Check if a request matches a NotResource element in a policy.
|
|
21
28
|
*
|
|
@@ -23,5 +30,8 @@ export declare function requestMatchesResources(request: AwsRequest, policyResou
|
|
|
23
30
|
* @param policyResources the resources to check against
|
|
24
31
|
* @returns true if the request does not match any of the resources, false otherwise
|
|
25
32
|
*/
|
|
26
|
-
export declare function requestMatchesNotResources(request: AwsRequest, policyResources: Resource[]):
|
|
33
|
+
export declare function requestMatchesNotResources(request: AwsRequest, policyResources: Resource[]): {
|
|
34
|
+
matches: boolean;
|
|
35
|
+
explains: ResourceExplain[];
|
|
36
|
+
};
|
|
27
37
|
//# 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,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,
|
|
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,eAAe,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAmBnD;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,cAAc,CAAC,CAAA;CAAC,CAiB7K;AAGD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;CAAC,CAIzI;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;CAAC,CAQ5I"}
|
|
@@ -27,12 +27,22 @@ function convertResourceSegmentToRegex(segment) {
|
|
|
27
27
|
*/
|
|
28
28
|
function requestMatchesStatementResources(request, statement) {
|
|
29
29
|
if (statement.isResourceStatement()) {
|
|
30
|
-
|
|
30
|
+
const { matches, explains } = requestMatchesResources(request, statement.resources());
|
|
31
|
+
if (!statement.resourceIsArray()) {
|
|
32
|
+
return { matches, details: { resources: explains[0] } };
|
|
33
|
+
}
|
|
34
|
+
return { matches, details: { resources: explains } };
|
|
35
|
+
// return requestMatchesResources(request, statement.resources());
|
|
31
36
|
}
|
|
32
37
|
else if (statement.isNotResourceStatement()) {
|
|
33
|
-
|
|
38
|
+
const { matches, explains } = requestMatchesNotResources(request, statement.notResources());
|
|
39
|
+
if (!statement.notResourceIsArray()) {
|
|
40
|
+
return { matches, details: { notResources: explains[0] } };
|
|
41
|
+
}
|
|
42
|
+
return { matches, details: { notResources: explains } };
|
|
43
|
+
// return requestMatchesNotResources(request, statement.notResources());
|
|
34
44
|
}
|
|
35
|
-
return true;
|
|
45
|
+
return { matches: true, details: {} };
|
|
36
46
|
}
|
|
37
47
|
/**
|
|
38
48
|
* Check if a request matches a set of resources.
|
|
@@ -42,7 +52,9 @@ function requestMatchesStatementResources(request, statement) {
|
|
|
42
52
|
* @returns true if the request matches any of the resources, false otherwise
|
|
43
53
|
*/
|
|
44
54
|
function requestMatchesResources(request, policyResources) {
|
|
45
|
-
|
|
55
|
+
const explains = policyResources.map(policyResource => singleResourceMatchesRequest(request, policyResource));
|
|
56
|
+
const matches = explains.some(explain => explain.matches);
|
|
57
|
+
return { matches, explains };
|
|
46
58
|
}
|
|
47
59
|
/**
|
|
48
60
|
* Check if a request matches a NotResource element in a policy.
|
|
@@ -52,7 +64,13 @@ function requestMatchesResources(request, policyResources) {
|
|
|
52
64
|
* @returns true if the request does not match any of the resources, false otherwise
|
|
53
65
|
*/
|
|
54
66
|
function requestMatchesNotResources(request, policyResources) {
|
|
55
|
-
|
|
67
|
+
const explains = policyResources.map(policyResource => {
|
|
68
|
+
const explain = singleResourceMatchesRequest(request, policyResource);
|
|
69
|
+
explain.matches = !explain.matches;
|
|
70
|
+
return explain;
|
|
71
|
+
});
|
|
72
|
+
const matches = explains.some(explain => explain.matches);
|
|
73
|
+
return { matches, explains };
|
|
56
74
|
}
|
|
57
75
|
/**
|
|
58
76
|
* Check if a single resource matches a request.
|
|
@@ -63,35 +81,69 @@ function requestMatchesNotResources(request, policyResources) {
|
|
|
63
81
|
*/
|
|
64
82
|
function singleResourceMatchesRequest(request, policyResource) {
|
|
65
83
|
if (policyResource.isAllResources()) {
|
|
66
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
resource: policyResource.value(),
|
|
86
|
+
matches: true,
|
|
87
|
+
};
|
|
67
88
|
}
|
|
68
89
|
else if (policyResource.isArnResource()) {
|
|
69
90
|
if (!request.resource) {
|
|
70
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
resource: policyResource.value(),
|
|
93
|
+
matches: false,
|
|
94
|
+
errors: ['Request does not have a resource'],
|
|
95
|
+
};
|
|
71
96
|
}
|
|
72
97
|
const resource = request.resource;
|
|
73
98
|
if (!convertResourceSegmentToRegex(policyResource.partition()).test(resource.partition())) {
|
|
74
|
-
return
|
|
99
|
+
return {
|
|
100
|
+
resource: policyResource.value(),
|
|
101
|
+
matches: false,
|
|
102
|
+
errors: ['Partition does not match'],
|
|
103
|
+
};
|
|
75
104
|
}
|
|
76
105
|
if (!convertResourceSegmentToRegex(policyResource.service()).test(resource.service())) {
|
|
77
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
resource: policyResource.value(),
|
|
108
|
+
matches: false,
|
|
109
|
+
errors: ['Service does not match'],
|
|
110
|
+
};
|
|
78
111
|
}
|
|
79
112
|
if (!convertResourceSegmentToRegex(policyResource.region()).test(resource.region())) {
|
|
80
|
-
return
|
|
113
|
+
return {
|
|
114
|
+
resource: policyResource.value(),
|
|
115
|
+
matches: false,
|
|
116
|
+
errors: ['Region does not match'],
|
|
117
|
+
};
|
|
81
118
|
}
|
|
82
119
|
if (!convertResourceSegmentToRegex(policyResource.account()).test(resource.account())) {
|
|
83
|
-
return
|
|
120
|
+
return {
|
|
121
|
+
resource: policyResource.value(),
|
|
122
|
+
matches: false,
|
|
123
|
+
errors: ['Account does not match'],
|
|
124
|
+
};
|
|
84
125
|
}
|
|
85
126
|
//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
127
|
const [policyProduct, policyResourceId] = (0, util_js_1.getResourceSegments)(policyResource.resource());
|
|
87
128
|
if (!resource.resource().startsWith(policyProduct)) {
|
|
88
|
-
return
|
|
129
|
+
return {
|
|
130
|
+
resource: policyResource.value(),
|
|
131
|
+
matches: false,
|
|
132
|
+
errors: ['Product does not match'],
|
|
133
|
+
};
|
|
89
134
|
}
|
|
90
135
|
const requestResourceId = resource.resource().slice(policyProduct.length);
|
|
91
136
|
if (!(0, util_js_1.convertIamStringToRegex)(policyResourceId, request).test(requestResourceId)) {
|
|
92
|
-
return
|
|
137
|
+
return {
|
|
138
|
+
resource: policyResource.value(),
|
|
139
|
+
matches: false,
|
|
140
|
+
errors: ['Resource does not match'],
|
|
141
|
+
};
|
|
93
142
|
}
|
|
94
|
-
return
|
|
143
|
+
return {
|
|
144
|
+
resource: policyResource.value(),
|
|
145
|
+
matches: true,
|
|
146
|
+
};
|
|
95
147
|
}
|
|
96
148
|
else {
|
|
97
149
|
throw new Error('Unknown resource type');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/resource/resource.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/resource/resource.ts"],"names":[],"mappings":";;AA4BA,4EAiBC;AAUD,0DAIC;AASD,gEAQC;AAzED,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,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,SAAgB,gCAAgC,CAAC,OAAmB,EAAE,SAAoB;IACxF,IAAG,SAAS,CAAC,mBAAmB,EAAE,EAAE,CAAC;QACnC,MAAM,EAAC,OAAO,EAAE,QAAQ,EAAC,GAAG,uBAAuB,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;QACpF,IAAG,CAAC,SAAS,CAAC,eAAe,EAAE,EAAE,CAAC;YAChC,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,EAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAC,EAAC,CAAA;QACrD,CAAC;QACD,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,EAAC,SAAS,EAAE,QAAQ,EAAC,EAAC,CAAA;QAChD,kEAAkE;IACpE,CAAC;SAAM,IAAG,SAAS,CAAC,sBAAsB,EAAE,EAAE,CAAC;QAC7C,MAAM,EAAC,OAAO,EAAE,QAAQ,EAAC,GAAG,0BAA0B,CAAC,OAAO,EAAE,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1,41 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StatementAnalysis } from "../StatementAnalysis.js";
|
|
1
|
+
import { RequestAnalysis } from "../evaluate.js";
|
|
3
2
|
import { ServiceAuthorizationRequest, ServiceAuthorizer } from "./ServiceAuthorizer.js";
|
|
4
3
|
/**
|
|
5
4
|
* The default authorizer for services.
|
|
6
5
|
*/
|
|
7
6
|
export declare class DefaultServiceAuthorizer implements ServiceAuthorizer {
|
|
8
|
-
authorize(request: ServiceAuthorizationRequest):
|
|
9
|
-
/**
|
|
10
|
-
* Determine the result of the SCP analysis.
|
|
11
|
-
*
|
|
12
|
-
* @param request The request to authorize.
|
|
13
|
-
* @returns The result of the SCP analysis.
|
|
14
|
-
*/
|
|
15
|
-
serviceControlPolicyResult(request: ServiceAuthorizationRequest): EvaluationResult;
|
|
16
|
-
/**
|
|
17
|
-
* Evaluate the identity statements to determine the result.
|
|
18
|
-
*
|
|
19
|
-
* @param request The request to authorize.
|
|
20
|
-
* @returns The result of the identity statement analysis.
|
|
21
|
-
*/
|
|
22
|
-
identityStatementResult(request: ServiceAuthorizationRequest): EvaluationResult;
|
|
23
|
-
/**
|
|
24
|
-
* Evaluate the resource policy to determine the result.
|
|
25
|
-
*
|
|
26
|
-
* @param request the request to authorize
|
|
27
|
-
* @returns the result of the resource policy analysis
|
|
28
|
-
*/
|
|
29
|
-
resourcePolicyResult(request: ServiceAuthorizationRequest): ResourceEvaluationResult;
|
|
30
|
-
/**
|
|
31
|
-
* Checks if a statement is an identity statement that allows the request.
|
|
32
|
-
*
|
|
33
|
-
* @param statement The statement to check.
|
|
34
|
-
* @returns Whether the statement is an identity statement that allows the request.
|
|
35
|
-
*/
|
|
36
|
-
identityStatementAllows(statement: StatementAnalysis): boolean;
|
|
37
|
-
identityStatementUknownAllow(statement: StatementAnalysis): boolean;
|
|
38
|
-
identityStatementUknownDeny(statement: StatementAnalysis): boolean;
|
|
39
|
-
identityStatementExplicitDeny(statement: StatementAnalysis): boolean;
|
|
7
|
+
authorize(request: ServiceAuthorizationRequest): RequestAnalysis;
|
|
40
8
|
}
|
|
41
9
|
//# sourceMappingURL=DefaultServiceAuthorizer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultServiceAuthorizer.d.ts","sourceRoot":"","sources":["../../../src/services/DefaultServiceAuthorizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"DefaultServiceAuthorizer.d.ts","sourceRoot":"","sources":["../../../src/services/DefaultServiceAuthorizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAExF;;GAEG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IACzD,SAAS,CAAC,OAAO,EAAE,2BAA2B,GAAG,eAAe;CA6KxE"}
|
|
@@ -6,35 +6,66 @@ exports.DefaultServiceAuthorizer = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
class DefaultServiceAuthorizer {
|
|
8
8
|
authorize(request) {
|
|
9
|
-
const scpResult =
|
|
10
|
-
const identityStatementResult =
|
|
11
|
-
const resourcePolicyResult =
|
|
9
|
+
const scpResult = request.scpAnalysis.result;
|
|
10
|
+
const identityStatementResult = request.identityAnalysis.result;
|
|
11
|
+
const resourcePolicyResult = request.resourceAnalysis?.result;
|
|
12
12
|
const principalAccount = request.request.principal.accountId();
|
|
13
13
|
const resourceAccount = request.request.resource?.accountId();
|
|
14
|
+
const sameAccount = principalAccount === resourceAccount;
|
|
15
|
+
const baseResult = {
|
|
16
|
+
sameAccount,
|
|
17
|
+
identityAnalysis: request.identityAnalysis,
|
|
18
|
+
scpAnalysis: request.scpAnalysis,
|
|
19
|
+
resourceAnalysis: request.resourceAnalysis
|
|
20
|
+
};
|
|
14
21
|
if (scpResult !== 'Allowed') {
|
|
15
|
-
return
|
|
22
|
+
return {
|
|
23
|
+
result: scpResult,
|
|
24
|
+
...baseResult
|
|
25
|
+
};
|
|
16
26
|
}
|
|
17
27
|
if (resourcePolicyResult === 'ExplicitlyDenied' || resourcePolicyResult === 'DeniedForAccount') {
|
|
18
|
-
return
|
|
28
|
+
return {
|
|
29
|
+
result: 'ExplicitlyDenied',
|
|
30
|
+
...baseResult
|
|
31
|
+
};
|
|
19
32
|
}
|
|
20
33
|
if (identityStatementResult === 'ExplicitlyDenied') {
|
|
21
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
result: 'ExplicitlyDenied',
|
|
36
|
+
...baseResult
|
|
37
|
+
};
|
|
22
38
|
}
|
|
23
39
|
//Same Account
|
|
24
40
|
if (principalAccount === resourceAccount) {
|
|
25
41
|
if (resourcePolicyResult === 'Allowed' || resourcePolicyResult === 'AllowedForAccount' || identityStatementResult === 'Allowed') {
|
|
26
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
result: 'Allowed',
|
|
44
|
+
...baseResult
|
|
45
|
+
};
|
|
27
46
|
}
|
|
28
|
-
return
|
|
47
|
+
return {
|
|
48
|
+
result: 'ImplicitlyDenied',
|
|
49
|
+
...baseResult
|
|
50
|
+
};
|
|
29
51
|
}
|
|
30
52
|
//Cross Account
|
|
31
53
|
if (resourcePolicyResult === 'Allowed' || resourcePolicyResult === 'AllowedForAccount') {
|
|
32
54
|
if (identityStatementResult === 'Allowed') {
|
|
33
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
result: 'Allowed',
|
|
57
|
+
...baseResult
|
|
58
|
+
};
|
|
34
59
|
}
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
60
|
+
return {
|
|
61
|
+
result: 'ImplicitlyDenied',
|
|
62
|
+
...baseResult
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
result: 'ImplicitlyDenied',
|
|
67
|
+
...baseResult
|
|
68
|
+
};
|
|
38
69
|
/**
|
|
39
70
|
* Add checks for:
|
|
40
71
|
* * root user
|
|
@@ -45,121 +76,6 @@ class DefaultServiceAuthorizer {
|
|
|
45
76
|
* * session policies (maybe these are just part of identity policies?)
|
|
46
77
|
*/
|
|
47
78
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Determine the result of the SCP analysis.
|
|
50
|
-
*
|
|
51
|
-
* @param request The request to authorize.
|
|
52
|
-
* @returns The result of the SCP analysis.
|
|
53
|
-
*/
|
|
54
|
-
serviceControlPolicyResult(request) {
|
|
55
|
-
const orgAllows = request.scpAnalysis.map((scpAnalysis) => {
|
|
56
|
-
return scpAnalysis.statementAnalysis.some((statement) => {
|
|
57
|
-
return this.identityStatementAllows(statement);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
if (orgAllows.includes(false)) {
|
|
61
|
-
return 'ImplicitlyDenied';
|
|
62
|
-
}
|
|
63
|
-
const anyScpDeny = request.scpAnalysis.some((scpAnalysis) => {
|
|
64
|
-
return scpAnalysis.statementAnalysis.some((statement) => {
|
|
65
|
-
return this.identityStatementExplicitDeny(statement);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
if (anyScpDeny) {
|
|
69
|
-
return 'ExplicitlyDenied';
|
|
70
|
-
}
|
|
71
|
-
return 'Allowed';
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Evaluate the identity statements to determine the result.
|
|
75
|
-
*
|
|
76
|
-
* @param request The request to authorize.
|
|
77
|
-
* @returns The result of the identity statement analysis.
|
|
78
|
-
*/
|
|
79
|
-
identityStatementResult(request) {
|
|
80
|
-
const explicitDeny = request.identityStatements.some(s => this.identityStatementExplicitDeny(s));
|
|
81
|
-
if (explicitDeny) {
|
|
82
|
-
return 'ExplicitlyDenied';
|
|
83
|
-
}
|
|
84
|
-
const explicitAllow = request.identityStatements.some(s => this.identityStatementAllows(s));
|
|
85
|
-
const possibleDeny = request.identityStatements.some(s => this.identityStatementUknownDeny(s));
|
|
86
|
-
if (explicitAllow) {
|
|
87
|
-
return possibleDeny ? 'Unknown' : 'Allowed';
|
|
88
|
-
}
|
|
89
|
-
const possibleAllow = request.identityStatements.some(s => this.identityStatementUknownAllow(s));
|
|
90
|
-
if (possibleAllow) {
|
|
91
|
-
return 'Unknown';
|
|
92
|
-
}
|
|
93
|
-
return 'ImplicitlyDenied';
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Evaluate the resource policy to determine the result.
|
|
97
|
-
*
|
|
98
|
-
* @param request the request to authorize
|
|
99
|
-
* @returns the result of the resource policy analysis
|
|
100
|
-
*/
|
|
101
|
-
resourcePolicyResult(request) {
|
|
102
|
-
if (!request.resourceAnalysis) {
|
|
103
|
-
return 'NotApplicable';
|
|
104
|
-
}
|
|
105
|
-
const denyStatements = request.resourceAnalysis.filter(s => this.identityStatementExplicitDeny(s));
|
|
106
|
-
if (denyStatements.some(s => s.principalMatch === 'Match')) {
|
|
107
|
-
return 'ExplicitlyDenied';
|
|
108
|
-
}
|
|
109
|
-
if (denyStatements.some(s => s.principalMatch === 'AccountLevelMatch')) {
|
|
110
|
-
return 'DeniedForAccount';
|
|
111
|
-
}
|
|
112
|
-
const allowStatements = request.resourceAnalysis.filter(s => this.identityStatementAllows(s));
|
|
113
|
-
if (allowStatements.some(s => s.principalMatch === 'Match')) {
|
|
114
|
-
return 'Allowed';
|
|
115
|
-
}
|
|
116
|
-
if (allowStatements.some(s => s.principalMatch === 'AccountLevelMatch')) {
|
|
117
|
-
return 'AllowedForAccount';
|
|
118
|
-
}
|
|
119
|
-
return 'ImplicityDenied';
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Checks if a statement is an identity statement that allows the request.
|
|
123
|
-
*
|
|
124
|
-
* @param statement The statement to check.
|
|
125
|
-
* @returns Whether the statement is an identity statement that allows the request.
|
|
126
|
-
*/
|
|
127
|
-
identityStatementAllows(statement) {
|
|
128
|
-
if (statement.resourceMatch &&
|
|
129
|
-
statement.actionMatch &&
|
|
130
|
-
statement.conditionMatch === 'Match' &&
|
|
131
|
-
statement.statement.effect() === 'Allow') {
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
identityStatementUknownAllow(statement) {
|
|
137
|
-
if (statement.resourceMatch &&
|
|
138
|
-
statement.actionMatch &&
|
|
139
|
-
statement.conditionMatch === 'Unknown' &&
|
|
140
|
-
statement.statement.effect() === 'Allow') {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
identityStatementUknownDeny(statement) {
|
|
146
|
-
if (statement.resourceMatch &&
|
|
147
|
-
statement.actionMatch &&
|
|
148
|
-
statement.conditionMatch === 'Unknown' &&
|
|
149
|
-
statement.statement.effect() === 'Deny') {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
identityStatementExplicitDeny(statement) {
|
|
155
|
-
if (statement.resourceMatch &&
|
|
156
|
-
statement.actionMatch &&
|
|
157
|
-
statement.conditionMatch === 'Match' &&
|
|
158
|
-
statement.statement.effect() === 'Deny') {
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
79
|
}
|
|
164
80
|
exports.DefaultServiceAuthorizer = DefaultServiceAuthorizer;
|
|
165
81
|
//# sourceMappingURL=DefaultServiceAuthorizer.js.map
|