@@ -556,6 +556,17 @@ function is_bucket_claim_owner(bucket, account) {
556556 return account . bucket_claim_owner . name . unwrap ( ) === bucket . name . unwrap ( ) ;
557557}
558558
559+ /**
560+ * is_iam_and_same_root_account_owner checks if the account is the IAM user and the same root account owner of the bucket
561+ * @param {Record<string, any> } account
562+ * @param {Record<string, any> } bucket
563+ * @returns {boolean }
564+ */
565+ function is_iam_and_same_root_account_owner ( account , bucket ) {
566+ if ( ! account ?. owner || ! bucket ?. owner_account ) return false ;
567+ return account . owner . _id . toString ( ) === bucket . owner_account . _id . toString ( ) ;
568+ }
569+
559570/**
560571 * has_bucket_ownership_permission returns true if the account can list the bucket in ListBuckets operation
561572 *
@@ -585,7 +596,7 @@ async function has_bucket_ownership_permission(bucket, account, role) {
585596 if ( is_bucket_claim_owner ( bucket , account ) ) return true ;
586597
587598 // special case: iam user can list the buckets of their owner
588- // TODO: handle iam user
599+ if ( is_iam_and_same_root_account_owner ( account , bucket ) ) return true ;
589600
590601 return false ;
591602}
@@ -620,9 +631,7 @@ async function has_bucket_action_permission(bucket, account, action, req_query,
620631 if ( ! bucket_policy ) {
621632 // in case we do not have bucket policy
622633 // we allow IAM account to access a bucket that is owned by their root account
623- const is_iam_and_same_root_account_owner = account . owner !== undefined &&
624- account . owner . _id . toString ( ) === bucket . owner_account . _id . toString ( ) ;
625- return has_owner_access || is_iam_and_same_root_account_owner ;
634+ return has_owner_access || is_iam_and_same_root_account_owner ( account , bucket ) ;
626635 }
627636 if ( ! action ) {
628637 throw new Error ( 'has_bucket_action_permission: action is required' ) ;
0 commit comments