Skip to content

Commit bceddc4

Browse files
authored
Merge pull request ceph#61565 from AliMasarweh/wip-alimasa-bn-policy-with-tenant
RGW | bucket notifications: support cross tenant operations Reviewed-by: yuvalif<[email protected]>
2 parents 7ecb025 + 0884e99 commit bceddc4

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

src/rgw/rgw_rest_pubsub.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class RGWPSGetTopicOp : public RGWOp {
560560
if (ret < 0) {
561561
return ret;
562562
}
563-
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
563+
const RGWPubSub ps(driver, topic_arn.account, *s->penv.site);
564564
ret = ps.get_topic(this, topic_name, result, y, nullptr);
565565
if (ret < 0) {
566566
ldpp_dout(this, 4) << "failed to get topic '" << topic_name << "', ret=" << ret << dendl;
@@ -646,7 +646,7 @@ class RGWPSGetTopicAttributesOp : public RGWOp {
646646
if (ret < 0) {
647647
return ret;
648648
}
649-
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
649+
const RGWPubSub ps(driver, topic_arn.account, *s->penv.site);
650650
ret = ps.get_topic(this, topic_name, result, y, nullptr);
651651
if (ret < 0) {
652652
ldpp_dout(this, 4) << "failed to get topic '" << topic_name << "', ret=" << ret << dendl;
@@ -811,7 +811,7 @@ class RGWPSSetTopicAttributesOp : public RGWOp {
811811
return ret;
812812
}
813813

814-
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
814+
const RGWPubSub ps(driver, topic_arn.account, *s->penv.site);
815815
ret = ps.get_topic(this, topic_name, result, y, nullptr);
816816
if (ret < 0) {
817817
ldpp_dout(this, 4) << "failed to get topic '" << topic_name
@@ -884,8 +884,7 @@ void RGWPSSetTopicAttributesOp::execute(optional_yield y) {
884884
if (!already_persistent && topic_needs_queue(dest)) {
885885
// initialize the persistent queue's location, using ':' as the namespace
886886
// delimiter because its inclusion in a TopicName would break ARNs
887-
dest.persistent_queue = string_cat_reserve(
888-
get_account_or_tenant(s->owner.id), ":", topic_name);
887+
dest.persistent_queue = string_cat_reserve(topic_arn.account, ":", topic_name);
889888

890889
op_ret = driver->add_persistent_topic(this, y, dest.persistent_queue);
891890
if (op_ret < 0) {
@@ -905,7 +904,7 @@ void RGWPSSetTopicAttributesOp::execute(optional_yield y) {
905904
return;
906905
}
907906
}
908-
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
907+
const RGWPubSub ps(driver, topic_arn.account, *s->penv.site);
909908
op_ret = ps.create_topic(this, topic_name, dest, topic_arn.to_string(),
910909
opaque_data, topic_owner, policy_text, y);
911910
if (op_ret < 0) {
@@ -947,7 +946,7 @@ class RGWPSDeleteTopicOp : public RGWOp {
947946
return ret;
948947
}
949948

950-
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
949+
const RGWPubSub ps(driver, topic_arn.account, *s->penv.site);
951950
rgw_pubsub_topic result;
952951
ret = ps.get_topic(this, topic_name, result, y, nullptr);
953952
if (ret == -ENOENT) {
@@ -1030,7 +1029,7 @@ void RGWPSDeleteTopicOp::execute(optional_yield y) {
10301029
return;
10311030
}
10321031

1033-
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
1032+
const RGWPubSub ps(driver, topic_arn.account, *s->penv.site);
10341033
op_ret = ps.remove_topic(this, topic_name, y);
10351034
if (op_ret < 0 && op_ret != -ENOENT) {
10361035
ldpp_dout(this, 4) << "failed to remove topic '" << topic_name << ", ret=" << op_ret << dendl;

src/test/rgw/bucket_notification/test_bn.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,11 +4631,10 @@ def test_ps_s3_list_topics_v1():
46314631
tenant_topic_conf.del_config(tenant_topic_arn2)
46324632

46334633

4634-
@attr('basic_test')
4635-
def test_ps_s3_topic_permissions():
4634+
def ps_s3_topic_permissions(another_tenant=""):
46364635
""" test s3 topic set/get/delete permissions """
46374636
conn1 = connection()
4638-
conn2, arn2 = another_user()
4637+
conn2, arn2 = another_user(tenant=another_tenant)
46394638
zonegroup = get_config_zonegroup()
46404639
bucket_name = gen_bucket_name()
46414640
topic_name = bucket_name + TOPIC_SUFFIX
@@ -4658,17 +4657,20 @@ def test_ps_s3_topic_permissions():
46584657
topic_arn = topic_conf.set_config()
46594658

46604659
topic_conf2 = PSTopicS3(conn2, topic_name, zonegroup, endpoint_args=endpoint_args)
4661-
try:
4662-
# 2nd user tries to override the topic
4663-
topic_arn = topic_conf2.set_config()
4664-
assert False, "'AuthorizationError' error is expected"
4665-
except ClientError as err:
4666-
if 'Error' in err.response:
4667-
assert_equal(err.response['Error']['Code'], 'AuthorizationError')
4668-
else:
4669-
assert_equal(err.response['Code'], 'AuthorizationError')
4670-
except Exception as err:
4671-
print('unexpected error type: '+type(err).__name__)
4660+
# only on the same tenant we can try to override the topic
4661+
if another_tenant == "":
4662+
try:
4663+
# 2nd user tries to override the topic
4664+
topic_arn = topic_conf2.set_config()
4665+
assert False, "'AuthorizationError' error is expected"
4666+
except ClientError as err:
4667+
if 'Error' in err.response:
4668+
assert_equal(err.response['Error']['Code'], 'AuthorizationError')
4669+
else:
4670+
assert_equal(err.response['Code'], 'AuthorizationError')
4671+
except Exception as err:
4672+
print('unexpected error type: '+type(err).__name__)
4673+
assert False, "'AuthorizationError' error is expected"
46724674

46734675
# 2nd user tries to fetch the topic
46744676
_, status = topic_conf2.get_config(topic_arn=topic_arn)
@@ -4685,6 +4687,7 @@ def test_ps_s3_topic_permissions():
46854687
assert_equal(err.response['Code'], 'AuthorizationError')
46864688
except Exception as err:
46874689
print('unexpected error type: '+type(err).__name__)
4690+
assert False, "'AuthorizationError' error is expected"
46884691

46894692
# create bucket for conn2 and try publishing notification to topic
46904693
_ = conn2.create_bucket(bucket_name)
@@ -4703,6 +4706,7 @@ def test_ps_s3_topic_permissions():
47034706
assert_equal(err.response['Code'], 'AccessDenied')
47044707
except Exception as err:
47054708
print('unexpected error type: '+type(err).__name__)
4709+
assert False, "'AuthorizationError' error is expected"
47064710

47074711
try:
47084712
# 2nd user tries to delete the topic
@@ -4715,9 +4719,10 @@ def test_ps_s3_topic_permissions():
47154719
assert_equal(err.response['Code'], 'AuthorizationError')
47164720
except Exception as err:
47174721
print('unexpected error type: '+type(err).__name__)
4722+
assert False, "'AuthorizationError' error is expected"
47184723

47194724
# Topic policy is now added by the 1st user to allow 2nd user.
4720-
topic_policy = topic_policy.replace("Deny", "Allow")
4725+
topic_policy = topic_policy.replace("Deny", "Allow")
47214726
topic_conf = PSTopicS3(conn1, topic_name, zonegroup, endpoint_args=endpoint_args, policy_text=topic_policy)
47224727
topic_arn = topic_conf.set_config()
47234728
# 2nd user try to fetch topic again
@@ -4740,6 +4745,16 @@ def test_ps_s3_topic_permissions():
47404745
conn2.delete_bucket(bucket_name)
47414746

47424747

4748+
@attr('basic_test')
4749+
def test_ps_s3_topic_permissions_same_tenant():
4750+
ps_s3_topic_permissions()
4751+
4752+
4753+
@attr('basic_test')
4754+
def test_ps_s3_topic_permissions_cross_tenant():
4755+
ps_s3_topic_permissions(another_tenant="boom")
4756+
4757+
47434758
@attr('basic_test')
47444759
def test_ps_s3_topic_no_permissions():
47454760
""" test s3 topic set/get/delete permissions """

0 commit comments

Comments
 (0)