Skip to content

Commit 1bc1c5e

Browse files
authored
Merge pull request ceph#61433 from smanjara/wip-fix-tenant-replication
rgw/multisite: fix forwarded requests for tenanted buckets Reviewed-by: Casey Bodley <[email protected]>
2 parents db36317 + d9b0e78 commit 1bc1c5e

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/rgw/rgw_auth_filters.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class SysReqApplier : public DecoratedApplier<T> {
238238
const RGWHTTPArgs& args;
239239
mutable boost::tribool is_system;
240240
mutable std::optional<ACLOwner> effective_owner;
241+
mutable std::optional<std::string> effective_tenant;
241242

242243
public:
243244
template <typename U>
@@ -262,6 +263,14 @@ class SysReqApplier : public DecoratedApplier<T> {
262263
}
263264
return DecoratedApplier<T>::get_aclowner();
264265
}
266+
267+
const std::string& get_tenant() const override {
268+
if (effective_tenant) {
269+
return *effective_tenant;
270+
}
271+
return DecoratedApplier<T>::get_tenant();
272+
}
273+
265274
};
266275

267276
template <typename T>
@@ -287,6 +296,7 @@ auto SysReqApplier<T>::load_acct_info(const DoutPrefixProvider* dpp) const -> st
287296
std::string str = args.sys_get(RGW_SYS_PARAM_PREFIX "uid");
288297
if (!str.empty()) {
289298
effective_owner.emplace();
299+
290300
effective_owner->id = parse_owner(str);
291301

292302
if (const auto* uid = std::get_if<rgw_user>(&effective_owner->id); uid) {
@@ -296,7 +306,17 @@ auto SysReqApplier<T>::load_acct_info(const DoutPrefixProvider* dpp) const -> st
296306
throw -EACCES;
297307
}
298308
effective_owner->display_name = user->get_display_name();
299-
}
309+
effective_tenant = uid->tenant;
310+
} else if (const auto* id = std::get_if<rgw_account_id>(&effective_owner->id); id) {
311+
RGWAccountInfo info;
312+
rgw::sal::Attrs attrs;
313+
RGWObjVersionTracker objv;
314+
int r = driver->load_account_by_id(dpp, null_yield, *id, info, attrs, objv);
315+
if (r < 0) {
316+
throw -EACCES;
317+
}
318+
effective_tenant = info.tenant;
319+
}
300320
}
301321
}
302322
return user;

src/test/rgw/rgw_multi/tests.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,50 @@ def test_bucket_create():
586586
for zone in zonegroup_conns.zones:
587587
assert check_all_buckets_exist(zone, buckets)
588588

589+
def test_bucket_create_with_tenant():
590+
591+
''' create a bucket from secondary zone under tenant namespace. check if it successfully syncs
592+
under the same namespace'''
593+
594+
zonegroup = realm.master_zonegroup()
595+
zonegroup_conns = ZonegroupConns(zonegroup)
596+
primary = zonegroup_conns.rw_zones[0]
597+
secondary = zonegroup_conns.rw_zones[1]
598+
599+
access_key = 'abcd'
600+
secret_key = 'efgh'
601+
tenant = 'testx'
602+
uid = 'test'
603+
604+
tenant_secondary_conn = boto.s3.connection.S3Connection(aws_access_key_id=access_key,
605+
aws_secret_access_key=secret_key,
606+
is_secure=False,
607+
port=secondary.zone.gateways[0].port,
608+
host=secondary.zone.gateways[0].host,
609+
calling_format='boto.s3.connection.OrdinaryCallingFormat')
610+
611+
tenant_primary_conn = boto.s3.connection.S3Connection(aws_access_key_id=access_key,
612+
aws_secret_access_key=secret_key,
613+
is_secure=False,
614+
port=primary.zone.gateways[0].port,
615+
host=primary.zone.gateways[0].host,
616+
calling_format='boto.s3.connection.OrdinaryCallingFormat')
617+
618+
cmd = ['user', 'create', '--tenant', tenant, '--uid', uid, '--access-key', access_key, '--secret-key', secret_key, '--display-name', 'tenanted-user']
619+
primary.zone.cluster.admin(cmd)
620+
zonegroup_meta_checkpoint(zonegroup)
621+
try:
622+
bucket = tenant_secondary_conn.create_bucket('tenanted-bucket')
623+
zonegroup_meta_checkpoint(zonegroup)
624+
assert tenant_primary_conn.get_bucket(bucket.name)
625+
log.info("bucket exists in tenant namespace")
626+
e = assert_raises(boto.exception.S3ResponseError, primary.get_bucket, bucket.name)
627+
assert e.error_code == 'NoSuchBucket'
628+
log.info("bucket does not exist in default user namespace")
629+
finally:
630+
cmd = ['user', 'rm', '--tenant', tenant, '--uid', uid, '--purge-data']
631+
primary.zone.cluster.admin(cmd)
632+
589633
def test_bucket_recreate():
590634
zonegroup = realm.master_zonegroup()
591635
zonegroup_conns = ZonegroupConns(zonegroup)

0 commit comments

Comments
 (0)