Skip to content

Commit f97e90d

Browse files
committed
rgw/s3: CreateBucket accepts x-amz-object-ownership header
Signed-off-by: Casey Bodley <[email protected]>
1 parent b373329 commit f97e90d

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/rgw/rgw_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ using ceph::crypto::MD5;
120120
#define RGW_ATTR_OBJECT_RETENTION RGW_ATTR_PREFIX "object-retention"
121121
#define RGW_ATTR_OBJECT_LEGAL_HOLD RGW_ATTR_PREFIX "object-legal-hold"
122122

123+
// S3 Object Ownership
124+
#define RGW_ATTR_OWNERSHIP_CONTROLS RGW_ATTR_PREFIX "ownership-controls"
123125

124126
#define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
125127
#define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"

src/rgw/rgw_op.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,6 +3452,13 @@ int RGWCreateBucket::verify_permission(optional_yield y)
34523452
return -EACCES;
34533453
}
34543454

3455+
if (object_ownership) {
3456+
// x-amz-object-ownership requires s3:PutBucketOwnershipControls permission
3457+
if (!verify_user_permission(this, s, arn, rgw::IAM::s3PutBucketOwnershipControls, false)) {
3458+
return -EACCES;
3459+
}
3460+
}
3461+
34553462
if (s->auth.identity->get_tenant() != s->bucket_tenant) {
34563463
//AssumeRole is meant for cross account access
34573464
if (s->auth.identity->get_identity_type() != TYPE_ROLE) {
@@ -3814,6 +3821,12 @@ void RGWCreateBucket::execute(optional_yield y)
38143821
createparams.attrs[RGW_ATTR_CORS] = std::move(corsbl);
38153822
}
38163823

3824+
if (object_ownership) {
3825+
rgw::s3::OwnershipControls controls;
3826+
controls.object_ownership = *object_ownership;
3827+
encode(controls, createparams.attrs[RGW_ATTR_OWNERSHIP_CONTROLS]);
3828+
} // TODO: config option to set default ownership when not requested
3829+
38173830
if (need_metadata_upload()) {
38183831
/* It's supposed that following functions WILL NOT change any special
38193832
* attributes (like RGW_ATTR_ACL) if they are already present in attrs. */

src/rgw/rgw_op.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ class RGWCreateBucket : public RGWOp {
11531153
RGWCORSConfiguration cors_config;
11541154
std::set<std::string> rmattr_names;
11551155
bufferlist in_data;
1156+
std::optional<rgw::s3::ObjectOwnership> object_ownership;
11561157

11571158
virtual bool need_metadata_upload() const { return false; }
11581159

src/rgw/rgw_rest_s3.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,15 @@ int RGWCreateBucket_ObjStore_S3::get_params(optional_yield y)
26912691
}
26922692
createparams.obj_lock_enabled = boost::algorithm::iequals(iter->second, "true");
26932693
}
2694+
2695+
if (auto i = s->info.x_meta_map.find("x-amz-object-ownership");
2696+
i != s->info.x_meta_map.end()) {
2697+
rgw::s3::ObjectOwnership tmp;
2698+
if (!rgw::s3::parse(i->second, tmp, s->err.message)) {
2699+
return -EINVAL;
2700+
}
2701+
object_ownership = std::move(tmp);
2702+
}
26942703
return 0;
26952704
}
26962705

0 commit comments

Comments
 (0)