@@ -12,6 +12,7 @@ const s3_logging = require('./s3_bucket_logging');
1212const time_utils = require ( '../../util/time_utils' ) ;
1313const http_utils = require ( '../../util/http_utils' ) ;
1414const signature_utils = require ( '../../util/signature_utils' ) ;
15+ const iam_utils = require ( '../../endpoint/iam/iam_utils' ) ;
1516const config = require ( '../../../config' ) ;
1617const s3_utils = require ( './s3_utils' ) ;
1718
@@ -254,6 +255,8 @@ async function authorize_request_policy(req) {
254255 const account = req . object_sdk . requesting_account ;
255256 const account_identifier_name = req . object_sdk . nsfs_config_root ? account . name . unwrap ( ) : account . email . unwrap ( ) ;
256257 const account_identifier_id = req . object_sdk . nsfs_config_root ? account . _id : undefined ;
258+ const arn = account . owner ? iam_utils . create_arn_for_user ( account . owner , account . name . unwrap ( ) . split ( ':' ) [ 0 ] , account . iam_path ) :
259+ iam_utils . create_arn_for_account ( account . _id ) ;
257260
258261 // deny delete_bucket permissions from bucket_claim_owner accounts (accounts that were created by OBC from openshift\k8s)
259262 // the OBC bucket can still be delete by normal accounts according to the access policy which is checked below
@@ -292,6 +295,7 @@ async function authorize_request_policy(req) {
292295 // in case we have bucket policy
293296 let permission_by_id ;
294297 let permission_by_name ;
298+ let permission_by_arn ;
295299
296300 // In NC, we allow principal to be:
297301 // 1. account name (for backwards compatibility)
@@ -303,15 +307,20 @@ async function authorize_request_policy(req) {
303307 dbg . log3 ( 'authorize_request_policy: permission_by_id' , permission_by_id ) ;
304308 }
305309 if ( permission_by_id === "DENY" ) throw new S3Error ( S3Error . AccessDenied ) ;
306-
307310 if ( ( ! account_identifier_id || permission_by_id !== "DENY" ) && account . owner === undefined ) {
308311 permission_by_name = await s3_bucket_policy_utils . has_bucket_policy_permission (
309312 s3_policy , account_identifier_name , method , arn_path , req , public_access_block ?. restrict_public_buckets
310313 ) ;
311314 dbg . log3 ( 'authorize_request_policy: permission_by_name' , permission_by_name ) ;
312315 }
313316 if ( permission_by_name === "DENY" ) throw new S3Error ( S3Error . AccessDenied ) ;
314- if ( ( permission_by_id === "ALLOW" || permission_by_name === "ALLOW" ) || is_owner ) return ;
317+ if ( ! account_identifier_id ) {
318+ permission_by_arn = await s3_bucket_policy_utils . has_bucket_policy_permission (
319+ s3_policy , arn , method , arn_path , req , public_access_block ?. restrict_public_buckets
320+ ) ;
321+ dbg . log3 ( 'authorize_request_policy: permission_by_arn' , permission_by_arn ) ;
322+ }
323+ if ( ( permission_by_id === "ALLOW" || permission_by_name === "ALLOW" || permission_by_arn === "ALLOW" ) || is_owner ) return ;
315324
316325 throw new S3Error ( S3Error . AccessDenied ) ;
317326}
0 commit comments