@@ -137,18 +137,31 @@ async function _is_object_tag_fit(req, predicate, value) {
137
137
return res ;
138
138
}
139
139
140
- async function has_bucket_policy_permission ( policy , account , method , arn_path , req ) {
140
+ async function has_bucket_policy_permission ( policy , account , method , arn_path , req , account_identifier_name = undefined ) {
141
141
const [ allow_statements , deny_statements ] = _ . partition ( policy . Statement , statement => statement . Effect === 'Allow' ) ;
142
142
143
143
// the case where the permission is an array started in op get_object_attributes
144
144
const method_arr = Array . isArray ( method ) ? method : [ method ] ;
145
145
146
146
// look for explicit denies
147
- const res_arr_deny = await is_statement_fit_of_method_array ( deny_statements , account , method_arr , arn_path , req ) ;
147
+ const res_arr_deny = await is_statement_fit_of_method_array ( deny_statements ,
148
+ account ,
149
+ method_arr ,
150
+ arn_path ,
151
+ req ,
152
+ account_identifier_name
153
+ ) ;
148
154
if ( res_arr_deny . every ( item => item ) ) return 'DENY' ;
149
155
150
156
// look for explicit allows
151
- const res_arr_allow = await is_statement_fit_of_method_array ( allow_statements , account , method_arr , arn_path , req ) ;
157
+ const res_arr_allow = await is_statement_fit_of_method_array (
158
+ allow_statements ,
159
+ account ,
160
+ method_arr ,
161
+ arn_path ,
162
+ req ,
163
+ account_identifier_name
164
+ ) ;
152
165
if ( res_arr_allow . every ( item => item ) ) return 'ALLOW' ;
153
166
154
167
// implicit deny
@@ -168,14 +181,13 @@ function _is_action_fit(method, statement) {
168
181
return statement . Action ? action_fit : ! action_fit ;
169
182
}
170
183
171
- function _is_principal_fit ( account , statement ) {
184
+ function _is_principal_fit ( account , statement , account_identifier_name = undefined ) {
172
185
let statement_principal = statement . Principal || statement . NotPrincipal ;
173
-
174
186
let principal_fit = false ;
175
187
statement_principal = statement_principal . AWS ? statement_principal . AWS : statement_principal ;
176
188
for ( const principal of _ . flatten ( [ statement_principal ] ) ) {
177
189
dbg . log1 ( 'bucket_policy: ' , statement . Principal ? 'Principal' : 'NotPrincipal' , ' fit?' , principal , account ) ;
178
- if ( ( principal . unwrap ( ) === '*' ) || ( principal . unwrap ( ) === account ) ) {
190
+ if ( ( principal . unwrap ( ) === '*' ) || ( principal . unwrap ( ) === account ) || ( account_identifier_name && ( principal . unwrap ( ) === account_identifier_name ) ) ) {
179
191
principal_fit = true ;
180
192
break ;
181
193
}
@@ -198,15 +210,15 @@ function _is_resource_fit(arn_path, statement) {
198
210
return statement . Resource ? resource_fit : ! resource_fit ;
199
211
}
200
212
201
- async function is_statement_fit_of_method_array ( statements , account , method_arr , arn_path , req ) {
213
+ async function is_statement_fit_of_method_array ( statements , account , method_arr , arn_path , req , account_identifier_name = undefined ) {
202
214
return Promise . all ( method_arr . map ( method_permission =>
203
- _is_statements_fit ( statements , account , method_permission , arn_path , req ) ) ) ;
215
+ _is_statements_fit ( statements , account , method_permission , arn_path , req , account_identifier_name ) ) ) ;
204
216
}
205
217
206
- async function _is_statements_fit ( statements , account , method , arn_path , req ) {
218
+ async function _is_statements_fit ( statements , account , method , arn_path , req , account_identifier_name = undefined ) {
207
219
for ( const statement of statements ) {
208
220
const action_fit = _is_action_fit ( method , statement ) ;
209
- const principal_fit = _is_principal_fit ( account , statement ) ;
221
+ const principal_fit = _is_principal_fit ( account , statement , account_identifier_name ) ;
210
222
const resource_fit = _is_resource_fit ( arn_path , statement ) ;
211
223
const condition_fit = await _is_condition_fit ( statement , req , method ) ;
212
224
0 commit comments