From: cao.leilc Date: Thu, 17 Jun 2021 12:04:23 +0000 (+0800) Subject: rgw : add check for tenant provided in RGWCreateRole X-Git-Tag: v16.2.6~86^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=77b663a5e4ea2234fb62e7c682aca8857c70093c;p=ceph.git rgw : add check for tenant provided in RGWCreateRole Fixes: https://tracker.ceph.com/issues/51206 Signed-off-by: caolei (cherry picked from commit 3c99ac14080c9f5b1611c9bbe4a223a9fd2927a0) Conflicts: src/rgw/rgw_rest_role.cc Cherry-pick notes: - Pacific constructs role explicitly vs. using store->get_role(), and does not wrap in a unique_ptr --- diff --git a/src/rgw/rgw_rest_role.cc b/src/rgw/rgw_rest_role.cc index 1e9cdf71b217..61964ba53eef 100644 --- a/src/rgw/rgw_rest_role.cc +++ b/src/rgw/rgw_rest_role.cc @@ -130,8 +130,15 @@ void RGWCreateRole::execute(optional_yield y) if (op_ret < 0) { return; } + std::string user_tenant = s->user->get_tenant(); RGWRole role(s->cct, store->getRados()->pctl, role_name, role_path, trust_policy, - s->user->get_tenant(), max_session_duration); + user_tenant, max_session_duration); + if (!user_tenant.empty() && role.get_tenant() != user_tenant) { + ldpp_dout(this, 20) << "ERROR: the tenant provided in the role name does not match with the tenant of the user creating the role" + << dendl; + op_ret = -EINVAL; + return; + } op_ret = role.create(s, true, y); if (op_ret == -EEXIST) {