Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgw/multisite: validate bucket location during bucket creation #15333

Merged
merged 3 commits into from Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/rgw/rgw_common.cc
Expand Up @@ -61,6 +61,7 @@ rgw_http_errors rgw_http_s3_errors({
{ ERR_INVALID_REQUEST, {400, "InvalidRequest" }},
{ ERR_INVALID_DIGEST, {400, "InvalidDigest" }},
{ ERR_BAD_DIGEST, {400, "BadDigest" }},
{ ERR_INVALID_LOCATION_CONSTRAINT, {400, "InvalidLocationConstraint" }},
{ ERR_INVALID_BUCKET_NAME, {400, "InvalidBucketName" }},
{ ERR_INVALID_OBJECT_NAME, {400, "InvalidObjectName" }},
{ ERR_UNRESOLVABLE_EMAIL, {400, "UnresolvableGrantByEmailAddress" }},
Expand Down
2 changes: 2 additions & 0 deletions src/rgw/rgw_common.h
Expand Up @@ -205,6 +205,8 @@ using ceph::crypto::MD5;
#define ERR_NO_ROLE_FOUND 2205
#define ERR_DELETE_CONFLICT 2206
#define ERR_NO_SUCH_BUCKET_POLICY 2207
#define ERR_INVALID_LOCATION_CONSTRAINT 2208

#define ERR_BUSY_RESHARDING 2300

#ifndef UINT32_MAX
Expand Down
22 changes: 17 additions & 5 deletions src/rgw/rgw_op.cc
Expand Up @@ -490,7 +490,7 @@ int rgw_build_bucket_policies(RGWRados* store, struct req_state* s)
/* we now need to make sure that the operation actually requires copy source, that is
* it's a copy operation
*/
if (store->get_zonegroup().is_master && s->system_request) {
if (store->get_zonegroup().is_master_zonegroup() && s->system_request) {
/*If this is the master, don't redirect*/
} else if (!s->local_source ||
(s->op != OP_PUT && s->op != OP_COPY) ||
Expand Down Expand Up @@ -2394,10 +2394,22 @@ void RGWCreateBucket::execute()
if (op_ret < 0)
return;

if (!store->get_zonegroup().is_master &&
if (!location_constraint.empty() &&
!store->has_zonegroup_api(location_constraint)) {
ldout(s->cct, 0) << "location constraint (" << location_constraint << ")"
<< " can't be found." << dendl;
op_ret = -ERR_INVALID_LOCATION_CONSTRAINT;
s->err.message = "The specified location-constraint is not valid";
return;
}

if (!store->get_zonegroup().is_master_zonegroup() &&
store->get_zonegroup().api_name != location_constraint) {
ldout(s->cct, 0) << "location constraint (" << location_constraint << ") doesn't match zonegroup" << " (" << store->get_zonegroup().api_name << ")" << dendl;
op_ret = -EINVAL;
ldout(s->cct, 0) << "location constraint (" << location_constraint << ")"
<< " doesn't match zonegroup" << " (" << store->get_zonegroup().api_name << ")"
<< dendl;
op_ret = -ERR_INVALID_LOCATION_CONSTRAINT;
s->err.message = "The specified location-constraint is not valid";
return;
}

Expand Down Expand Up @@ -5537,7 +5549,7 @@ bool RGWBulkDelete::Deleter::delete_single(const acct_path_t& path)
goto delop_fail;
}

if (!store->get_zonegroup().is_master) {
if (!store->get_zonegroup().is_master_zonegroup()) {
bufferlist in_data;
ret = forward_request_to_master(s, &ot.read_version, store, in_data,
nullptr);
Expand Down
16 changes: 8 additions & 8 deletions src/rgw/rgw_rados.cc
Expand Up @@ -1852,7 +1852,7 @@ void RGWPeriodMap::decode(bufferlist::iterator& bl) {
iter != zonegroups.end(); ++iter) {
RGWZoneGroup& zonegroup = iter->second;
zonegroups_by_api[zonegroup.api_name] = zonegroup;
if (zonegroup.is_master) {
if (zonegroup.is_master_zonegroup()) {
master_zonegroup = zonegroup.get_id();
}
}
Expand All @@ -1873,7 +1873,7 @@ static uint32_t gen_short_zone_id(const std::string zone_id)

int RGWPeriodMap::update(const RGWZoneGroup& zonegroup, CephContext *cct)
{
if (zonegroup.is_master && (!master_zonegroup.empty() && zonegroup.get_id() != master_zonegroup)) {
if (zonegroup.is_master_zonegroup() && (!master_zonegroup.empty() && zonegroup.get_id() != master_zonegroup)) {
ldout(cct,0) << "Error updating periodmap, multiple master zonegroups configured "<< dendl;
ldout(cct,0) << "master zonegroup: " << master_zonegroup << " and " << zonegroup.get_id() <<dendl;
return -EINVAL;
Expand All @@ -1891,7 +1891,7 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup, CephContext *cct)
zonegroups_by_api[zonegroup.api_name] = zonegroup;
}

if (zonegroup.is_master) {
if (zonegroup.is_master_zonegroup()) {
master_zonegroup = zonegroup.get_id();
} else if (master_zonegroup == zonegroup.get_id()) {
master_zonegroup = "";
Expand Down Expand Up @@ -1993,7 +1993,7 @@ void RGWZoneGroupMap::decode(bufferlist::iterator& bl) {
iter != zonegroups.end(); ++iter) {
RGWZoneGroup& zonegroup = iter->second;
zonegroups_by_api[zonegroup.api_name] = zonegroup;
if (zonegroup.is_master) {
if (zonegroup.is_master_zonegroup()) {
master_zonegroup = zonegroup.get_name();
}
}
Expand Down Expand Up @@ -3942,7 +3942,7 @@ int RGWRados::replace_region_with_zonegroup()
ldout(cct, 0) << __func__ << " failed init region "<< *iter << ": " << cpp_strerror(-ret) << dendl;
return ret;
}
if (region.is_master) {
if (region.is_master_zonegroup()) {
master_region = region.get_id();
master_zone = region.master_zone;
}
Expand Down Expand Up @@ -4234,7 +4234,7 @@ int RGWRados::init_zg_from_local(bool *creating_defaults)
}
}
ldout(cct, 20) << "zonegroup " << zonegroup.get_name() << dendl;
if (zonegroup.is_master) {
if (zonegroup.is_master_zonegroup()) {
// use endpoints from the zonegroup's master zone
auto master = zonegroup.zones.find(zonegroup.master_zone);
if (master == zonegroup.zones.end()) {
Expand Down Expand Up @@ -8175,7 +8175,7 @@ int RGWRados::copy_obj_data(RGWObjectCtx& obj_ctx,

bool RGWRados::is_meta_master()
{
if (!get_zonegroup().is_master) {
if (!get_zonegroup().is_master_zonegroup()) {
return false;
}

Expand All @@ -8196,7 +8196,7 @@ bool RGWRados::is_syncing_bucket_meta(const rgw_bucket& bucket)
}

/* zonegroup is not master zonegroup */
if (!get_zonegroup().is_master) {
if (!get_zonegroup().is_master_zonegroup()) {
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions src/rgw/rgw_rados.h
Expand Up @@ -2465,6 +2465,16 @@ class RGWRados
const string& get_current_period_id() {
return current_period.get_id();
}

bool has_zonegroup_api(const std::string& api) const {
if (!current_period.get_id().empty()) {
const auto& zonegroups_by_api = current_period.get_map().zonegroups_by_api;
if (zonegroups_by_api.find(api) != zonegroups_by_api.end())
return true;
}
return false;
}

// pulls missing periods for period_history
std::unique_ptr<RGWPeriodPuller> period_puller;
// maintains a connected history of periods
Expand Down