@@ -230,14 +230,21 @@ async function authorize_request_policy(req) {
230
230
if ( req . op_name === 'put_bucket' ) return ;
231
231
232
232
// owner_account is { id: bucket.owner_account, email: bucket.bucket_owner };
233
- const { s3_policy, system_owner, bucket_owner, owner_account } = await req . object_sdk . read_bucket_sdk_policy_info ( req . params . bucket ) ;
233
+ const {
234
+ s3_policy,
235
+ system_owner,
236
+ bucket_owner,
237
+ owner_account,
238
+ public_access_block,
239
+ } = await req . object_sdk . read_bucket_sdk_policy_info ( req . params . bucket ) ;
240
+
234
241
const auth_token = req . object_sdk . get_auth_token ( ) ;
235
242
const arn_path = _get_arn_from_req_path ( req ) ;
236
243
const method = _get_method_from_req ( req ) ;
237
244
238
245
const is_anon = ! ( auth_token && auth_token . access_key ) ;
239
246
if ( is_anon ) {
240
- await authorize_anonymous_access ( s3_policy , method , arn_path , req ) ;
247
+ await authorize_anonymous_access ( s3_policy , method , arn_path , req , public_access_block ) ;
241
248
return ;
242
249
}
243
250
@@ -283,21 +290,20 @@ async function authorize_request_policy(req) {
283
290
let permission_by_id ;
284
291
let permission_by_name ;
285
292
286
- const public_access_block_cfg = await req . object_sdk . get_public_access_block ( { name : req . params . bucket } ) ;
287
293
// In NC, we allow principal to be:
288
294
// 1. account name (for backwards compatibility)
289
295
// 2. account id
290
296
// we start the permission check on account identifier intentionally
291
297
if ( account_identifier_id ) {
292
298
permission_by_id = await s3_bucket_policy_utils . has_bucket_policy_permission (
293
- s3_policy , account_identifier_id , method , arn_path , req , public_access_block_cfg ?. public_access_block ?. restrict_public_buckets ) ;
299
+ s3_policy , account_identifier_id , method , arn_path , req , public_access_block ?. restrict_public_buckets ) ;
294
300
dbg . log3 ( 'authorize_request_policy: permission_by_id' , permission_by_id ) ;
295
301
}
296
302
if ( permission_by_id === "DENY" ) throw new S3Error ( S3Error . AccessDenied ) ;
297
303
298
304
if ( ( ! account_identifier_id || permission_by_id !== "DENY" ) && account . owner === undefined ) {
299
305
permission_by_name = await s3_bucket_policy_utils . has_bucket_policy_permission (
300
- s3_policy , account_identifier_name , method , arn_path , req , public_access_block_cfg ?. public_access_block ?. restrict_public_buckets
306
+ s3_policy , account_identifier_name , method , arn_path , req , public_access_block ?. restrict_public_buckets
301
307
) ;
302
308
dbg . log3 ( 'authorize_request_policy: permission_by_name' , permission_by_name ) ;
303
309
}
@@ -307,11 +313,11 @@ async function authorize_request_policy(req) {
307
313
throw new S3Error ( S3Error . AccessDenied ) ;
308
314
}
309
315
310
- async function authorize_anonymous_access ( s3_policy , method , arn_path , req ) {
316
+ async function authorize_anonymous_access ( s3_policy , method , arn_path , req , public_access_block ) {
311
317
if ( ! s3_policy ) throw new S3Error ( S3Error . AccessDenied ) ;
312
318
313
319
const permission = await s3_bucket_policy_utils . has_bucket_policy_permission (
314
- s3_policy , undefined , method , arn_path , req ) ;
320
+ s3_policy , undefined , method , arn_path , req , public_access_block ?. restrict_public_buckets ) ;
315
321
if ( permission === "ALLOW" ) return ;
316
322
317
323
throw new S3Error ( S3Error . AccessDenied ) ;
0 commit comments