@@ -22,7 +22,7 @@ const nb_native = require('../../../util/nb_native');
2222const SensitiveString = require ( '../../../util/sensitive_string' ) ;
2323const NamespaceFS = require ( '../../../sdk/namespace_fs' ) ;
2424const BucketSpaceFS = require ( '../../../sdk/bucketspace_fs' ) ;
25- const { TMP_PATH , generate_s3_policy } = require ( '../../system_tests/test_utils' ) ;
25+ const { TMP_PATH } = require ( '../../system_tests/test_utils' ) ;
2626const { CONFIG_SUBDIRS , JSON_SUFFIX } = require ( '../../../sdk/config_fs' ) ;
2727const nc_mkm = require ( '../../../manage_nsfs/nc_master_key_manager' ) . get_instance ( ) ;
2828
@@ -271,6 +271,17 @@ const account_iam_user1 = {
271271 gid : dummy_object_sdk . requesting_account . nsfs_account_config . gid ,
272272 new_buckets_path : dummy_object_sdk . requesting_account . nsfs_account_config . new_buckets_path
273273 } ,
274+ iam_user_policies : [ {
275+ policy_name : 'ListBucketsPolicy' ,
276+ policy_document : {
277+ Version : '2012-10-17' ,
278+ Statement : [ {
279+ Effect : 'Allow' ,
280+ Action : 's3:ListAllMyBuckets' ,
281+ Resource : '*'
282+ } ]
283+ }
284+ } ] ,
274285 creation_date : '2023-11-30T04:46:33.815Z' ,
275286} ;
276287
@@ -291,6 +302,17 @@ const account_iam_user2 = {
291302 gid : dummy_object_sdk . requesting_account . nsfs_account_config . gid ,
292303 new_buckets_path : dummy_object_sdk . requesting_account . nsfs_account_config . new_buckets_path
293304 } ,
305+ iam_user_policies : [ {
306+ policy_name : 'ListBucketsPolicy' ,
307+ policy_document : {
308+ Version : '2012-10-17' ,
309+ Statement : [ {
310+ Effect : 'Allow' ,
311+ Action : 's3:ListAllMyBuckets' ,
312+ Resource : '*'
313+ } ]
314+ }
315+ } ] ,
294316 creation_date : '2023-12-30T04:46:33.815Z' ,
295317} ;
296318
@@ -501,13 +523,13 @@ mocha.describe('bucketspace_fs', function() {
501523 } ) ;
502524 mocha . it ( 'list buckets - iam accounts' , async function ( ) {
503525 // root account created a bucket
504- // account_iam_user2 can list the created bucket (the implicit policy - same root account )
526+ // account_iam_user1 can list the created bucket (has s3:ListAllMyBuckets policy)
505527 const dummy_object_sdk_for_iam_account = make_dummy_object_sdk_for_account ( dummy_object_sdk , account_iam_user1 ) ;
506528 const res = await bucketspace_fs . list_buckets ( { } , dummy_object_sdk_for_iam_account ) ;
507529 assert . equal ( res . buckets . length , 1 ) ;
508530 assert . equal ( res . buckets [ 0 ] . name . unwrap ( ) , test_bucket ) ;
509531
510- // account_iam_user2 can list the created bucket (the implicit policy - same root account )
532+ // account_iam_user2 can list the created bucket (has s3:ListAllMyBuckets policy)
511533 const dummy_object_sdk_for_iam_account2 = make_dummy_object_sdk_for_account ( dummy_object_sdk , account_iam_user2 ) ;
512534 const res2 = await bucketspace_fs . list_buckets ( { } , dummy_object_sdk_for_iam_account2 ) ;
513535 assert . equal ( res2 . buckets . length , 1 ) ;
@@ -519,27 +541,10 @@ mocha.describe('bucketspace_fs', function() {
519541 const res = await bucketspace_fs . list_buckets ( { } , dummy_object_sdk_for_iam_account ) ;
520542 assert . equal ( res . buckets . length , 0 ) ;
521543 } ) ;
522- mocha . it ( 'list buckets - different account with bucket policy (principal by name)' , async function ( ) {
523- // another user created a bucket
524- // with bucket policy account_user3 can list it
525- const policy = generate_s3_policy ( account_user4 . name , test_bucket , [ 's3:*' ] ) . policy ;
526- const param = { name : test_bucket , policy : policy } ;
527- await bucketspace_fs . put_bucket_policy ( param ) ;
528- const dummy_object_sdk_for_iam_account = make_dummy_object_sdk_for_account ( dummy_object_sdk , account_user4 ) ;
529- const res = await bucketspace_fs . list_buckets ( { } , dummy_object_sdk_for_iam_account ) ;
530- assert . equal ( res . buckets . length , 1 ) ;
531- assert . equal ( res . buckets [ 0 ] . name . unwrap ( ) , test_bucket ) ;
532- } ) ;
533- mocha . it ( 'list buckets - different account with bucket policy (principal by id)' , async function ( ) {
534- // another user created a bucket
535- // with bucket policy account_user3 can list it
536- const policy = generate_s3_policy ( account_user4 . _id , test_bucket , [ 's3:*' ] ) . policy ;
537- const param = { name : test_bucket , policy : policy } ;
538- await bucketspace_fs . put_bucket_policy ( param ) ;
544+ mocha . it ( 'list buckets - different account cannot list buckets they do not own' , async function ( ) {
539545 const dummy_object_sdk_for_iam_account = make_dummy_object_sdk_for_account ( dummy_object_sdk , account_user4 ) ;
540546 const res = await bucketspace_fs . list_buckets ( { } , dummy_object_sdk_for_iam_account ) ;
541- assert . equal ( res . buckets . length , 1 ) ;
542- assert . equal ( res . buckets [ 0 ] . name . unwrap ( ) , test_bucket ) ;
547+ assert . equal ( res . buckets . length , 0 ) ;
543548 } ) ;
544549 mocha . afterEach ( async function ( ) {
545550 await fs_utils . folder_delete ( `${ new_buckets_path } /${ test_bucket } ` ) ;
@@ -626,7 +631,7 @@ mocha.describe('bucketspace_fs', function() {
626631 // root account created the bucket
627632 await create_bucket ( test_bucket_iam_account ) ;
628633
629- // account_iam_user1 can see the bucket in the list
634+ // account_iam_user1 can see the bucket in the list (has s3:ListAllMyBuckets policy)
630635 const dummy_object_sdk_for_account_iam_user1 = make_dummy_object_sdk_for_account ( dummy_object_sdk , account_iam_user1 ) ;
631636 const res = await bucketspace_fs . list_buckets ( { } , dummy_object_sdk_for_account_iam_user1 ) ;
632637 assert . ok ( res . buckets . length > 0 ) ;
0 commit comments