@@ -4395,6 +4395,7 @@ def test_ps_s3_multiple_topics_notification():
43954395 conn .delete_bucket (bucket_name )
43964396 http_server .close ()
43974397
4398+
43984399@attr ('basic_test' )
43994400def test_ps_s3_topic_permissions ():
44004401 """ test s3 topic set/get/delete permissions """
@@ -4410,7 +4411,7 @@ def test_ps_s3_topic_permissions():
44104411 "Sid" : "Statement" ,
44114412 "Effect" : "Deny" ,
44124413 "Principal" : "*" ,
4413- "Action" : ["sns:Publish" , "sns:SetTopicAttributes" , "sns:GetTopicAttributes" ],
4414+ "Action" : ["sns:Publish" , "sns:SetTopicAttributes" , "sns:GetTopicAttributes" , "sns:DeleteTopic" , "sns:CreateTopic" ],
44144415 "Resource" : f"arn:aws:sns:{ zonegroup } ::{ topic_name } "
44154416 }
44164417 ]
@@ -4421,10 +4422,23 @@ def test_ps_s3_topic_permissions():
44214422 topic_conf = PSTopicS3 (conn1 , topic_name , zonegroup , endpoint_args = endpoint_args , policy_text = topic_policy )
44224423 topic_arn = topic_conf .set_config ()
44234424
4424- # 2nd user tries to fetch the topic
44254425 topic_conf2 = PSTopicS3 (conn2 , topic_name , zonegroup , endpoint_args = endpoint_args )
4426+ try :
4427+ # 2nd user tries to override the topic
4428+ topic_arn = topic_conf2 .set_config ()
4429+ assert False , "'AccessDenied' error is expected"
4430+ except ClientError as err :
4431+ if 'Error' in err .response :
4432+ assert_equal (err .response ['Error' ]['Code' ], 'AccessDenied' )
4433+ else :
4434+ assert_equal (err .response ['Code' ], 'AccessDenied' )
4435+ except Exception as err :
4436+ print ('unexpected error type: ' + type (err ).__name__ )
4437+
4438+ # 2nd user tries to fetch the topic
44264439 _ , status = topic_conf2 .get_config (topic_arn = topic_arn )
44274440 assert_equal (status , 403 )
4441+
44284442 try :
44294443 # 2nd user tries to set the attribute
44304444 status = topic_conf2 .set_attributes (attribute_name = "persistent" , attribute_val = "false" , topic_arn = topic_arn )
@@ -4455,6 +4469,18 @@ def test_ps_s3_topic_permissions():
44554469 except Exception as err :
44564470 print ('unexpected error type: ' + type (err ).__name__ )
44574471
4472+ try :
4473+ # 2nd user tries to delete the topic
4474+ status = topic_conf2 .del_config (topic_arn = topic_arn )
4475+ assert False , "'AccessDenied' error is expected"
4476+ except ClientError as err :
4477+ if 'Error' in err .response :
4478+ assert_equal (err .response ['Error' ]['Code' ], 'AccessDenied' )
4479+ else :
4480+ assert_equal (err .response ['Code' ], 'AccessDenied' )
4481+ except Exception as err :
4482+ print ('unexpected error type: ' + type (err ).__name__ )
4483+
44584484 # Topic policy is now added by the 1st user to allow 2nd user.
44594485 topic_policy = topic_policy .replace ("Deny" , "Allow" )
44604486 topic_conf = PSTopicS3 (conn1 , topic_name , zonegroup , endpoint_args = endpoint_args , policy_text = topic_policy )
@@ -4469,13 +4495,90 @@ def test_ps_s3_topic_permissions():
44694495 s3_notification_conf2 = PSNotificationS3 (conn2 , bucket_name , topic_conf_list )
44704496 _ , status = s3_notification_conf2 .set_config ()
44714497 assert_equal (status , 200 )
4498+ # 2nd user tries to delete the topic again
4499+ status = topic_conf2 .del_config (topic_arn = topic_arn )
4500+ assert_equal (status , 200 )
4501+
4502+ # cleanup
4503+ s3_notification_conf2 .del_config ()
4504+ # delete the bucket
4505+ conn2 .delete_bucket (bucket_name )
4506+
4507+
4508+ @attr ('basic_test' )
4509+ def test_ps_s3_topic_no_permissions ():
4510+ """ test s3 topic set/get/delete permissions """
4511+ conn1 = connection ()
4512+ conn2 = another_user ()
4513+ zonegroup = 'default'
4514+ bucket_name = gen_bucket_name ()
4515+ topic_name = bucket_name + TOPIC_SUFFIX
4516+
4517+ # create s3 topic without policy
4518+ endpoint_address = 'amqp://127.0.0.1:7001'
4519+ endpoint_args = 'push-endpoint=' + endpoint_address + '&amqp-exchange=amqp.direct&amqp-ack-level=none'
4520+ topic_conf = PSTopicS3 (conn1 , topic_name , zonegroup , endpoint_args = endpoint_args )
4521+ topic_arn = topic_conf .set_config ()
4522+
4523+ topic_conf2 = PSTopicS3 (conn2 , topic_name , zonegroup , endpoint_args = endpoint_args )
4524+ try :
4525+ # 2nd user tries to override the topic
4526+ topic_arn = topic_conf2 .set_config ()
4527+ assert False , "'AccessDenied' error is expected"
4528+ except ClientError as err :
4529+ if 'Error' in err .response :
4530+ assert_equal (err .response ['Error' ]['Code' ], 'AccessDenied' )
4531+ else :
4532+ assert_equal (err .response ['Code' ], 'AccessDenied' )
4533+ except Exception as err :
4534+ print ('unexpected error type: ' + type (err ).__name__ )
4535+
4536+ # 2nd user tries to fetch the topic
4537+ _ , status = topic_conf2 .get_config (topic_arn = topic_arn )
4538+ assert_equal (status , 403 )
4539+
4540+ try :
4541+ # 2nd user tries to set the attribute
4542+ status = topic_conf2 .set_attributes (attribute_name = "persistent" , attribute_val = "false" , topic_arn = topic_arn )
4543+ assert False , "'AccessDenied' error is expected"
4544+ except ClientError as err :
4545+ if 'Error' in err .response :
4546+ assert_equal (err .response ['Error' ]['Code' ], 'AccessDenied' )
4547+ else :
4548+ assert_equal (err .response ['Code' ], 'AccessDenied' )
4549+ except Exception as err :
4550+ print ('unexpected error type: ' + type (err ).__name__ )
4551+
4552+ # create bucket for conn2 publish notification to topic
4553+ # should be allowed based on the default value of rgw_topic_require_publish_policy=false
4554+ _ = conn2 .create_bucket (bucket_name )
4555+ notification_name = bucket_name + NOTIFICATION_SUFFIX
4556+ topic_conf_list = [{'Id' : notification_name , 'TopicArn' : topic_arn ,
4557+ 'Events' : []
4558+ }]
4559+ s3_notification_conf2 = PSNotificationS3 (conn2 , bucket_name , topic_conf_list )
4560+ _ , status = s3_notification_conf2 .set_config ()
4561+ assert_equal (status , 200 )
4562+
4563+ try :
4564+ # 2nd user tries to delete the topic
4565+ status = topic_conf2 .del_config (topic_arn = topic_arn )
4566+ assert False , "'AccessDenied' error is expected"
4567+ except ClientError as err :
4568+ if 'Error' in err .response :
4569+ assert_equal (err .response ['Error' ]['Code' ], 'AccessDenied' )
4570+ else :
4571+ assert_equal (err .response ['Code' ], 'AccessDenied' )
4572+ except Exception as err :
4573+ print ('unexpected error type: ' + type (err ).__name__ )
44724574
44734575 # cleanup
44744576 s3_notification_conf2 .del_config ()
44754577 topic_conf .del_config ()
44764578 # delete the bucket
44774579 conn2 .delete_bucket (bucket_name )
44784580
4581+
44794582def kafka_security (security_type , mechanism = 'PLAIN' ):
44804583 """ test pushing kafka s3 notification securly to master """
44814584 conn = connection ()
0 commit comments