Skip to content

Commit 85c41c8

Browse files
Added support for iam user in list_buckets
Signed-off-by: Aayush Chouhan <achouhan@redhat.com>
1 parent 33924d7 commit 85c41c8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/server/common_services/auth_server.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,17 @@ function is_bucket_claim_owner(bucket, account) {
557557
return account.bucket_claim_owner.name.unwrap() === bucket.name.unwrap();
558558
}
559559

560+
/**
561+
* is_iam_and_same_root_account_owner checks if the account is the IAM user and the same root account owner of the bucket
562+
* @param {Record<string, any>} account
563+
* @param {Record<string, any>} bucket
564+
* @returns {boolean}
565+
*/
566+
function is_iam_and_same_root_account_owner(account, bucket) {
567+
if (!account?.owner || !bucket?.owner_account) return false;
568+
return account.owner._id.toString() === bucket.owner_account._id.toString();
569+
}
570+
560571
/**
561572
* has_bucket_ownership_permission returns true if the account can list the bucket in ListBuckets operation
562573
*
@@ -586,7 +597,7 @@ async function has_bucket_ownership_permission(bucket, account, role) {
586597
if (is_bucket_claim_owner(bucket, account)) return true;
587598

588599
// special case: iam user can list the buckets of their owner
589-
// TODO: handle iam user
600+
if (is_iam_and_same_root_account_owner(account, bucket)) return true;
590601

591602
return false;
592603
}
@@ -621,9 +632,7 @@ async function has_bucket_action_permission(bucket, account, action, req_query,
621632
if (!bucket_policy) {
622633
// in case we do not have bucket policy
623634
// we allow IAM account to access a bucket that is owned by their root account
624-
const is_iam_and_same_root_account_owner = account.owner !== undefined &&
625-
account.owner._id.toString() === bucket.owner_account._id.toString();
626-
return has_owner_access || is_iam_and_same_root_account_owner;
635+
return has_owner_access || is_iam_and_same_root_account_owner(account, bucket);
627636
}
628637
if (!action) {
629638
throw new Error('has_bucket_action_permission: action is required');

0 commit comments

Comments
 (0)