Skip to content

Commit 5ed9b1f

Browse files
committed
rgw/s3: ObjectOwnership interacts with canned acls
when object uploads specify a canned acl, they call create_canned_acl() to build the corresponding RGWAccessControlPolicy ObjectOwnership adds two special cases to this: * BucketOwnerEnforced denies acls other than "bucket-owner-full-control" * BucketOwnerPreferred overrides owner for "bucket-owner-full-control" Signed-off-by: Casey Bodley <[email protected]>
1 parent 373d638 commit 5ed9b1f

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/rgw/rgw_acl_s3.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,32 @@ void write_policy_xml(const RGWAccessControlPolicy& policy,
677677

678678
int create_canned_acl(const ACLOwner& owner,
679679
const ACLOwner& bucket_owner,
680+
ObjectOwnership object_ownership,
680681
const std::string& canned_acl,
681-
RGWAccessControlPolicy& policy)
682+
RGWAccessControlPolicy& policy,
683+
std::string& error_message)
682684
{
683685
if (owner.id == parse_owner("anonymous")) {
684686
policy.set_owner(bucket_owner);
685687
} else {
686688
policy.set_owner(owner);
687689
}
690+
691+
// special handling for BucketOwnerEnforced/Preferred
692+
if (object_ownership == ObjectOwnership::BucketOwnerEnforced) {
693+
// only supports bucket-owner-full-control
694+
if (canned_acl != "" && canned_acl != "bucket-owner-full-control") {
695+
error_message = "Cannot set ACLs when ObjectOwnership is BucketOwnerEnforced.";
696+
return -ERR_ACLS_NOT_SUPPORTED;
697+
}
698+
policy.set_owner(bucket_owner);
699+
} else if (object_ownership == ObjectOwnership::BucketOwnerPreferred) {
700+
// prefer bucket owner only for bucket-owner-full-control
701+
if (canned_acl == "bucket-owner-full-control") {
702+
policy.set_owner(bucket_owner);
703+
}
704+
}
705+
688706
return create_canned(owner, bucket_owner, canned_acl, policy.get_acl());
689707
}
690708

src/rgw/rgw_acl_s3.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "common/async/yield_context.h"
1212
#include "rgw_xml.h"
1313
#include "rgw_acl.h"
14+
#include "rgw_object_ownership.h"
1415
#include "rgw_sal_fwd.h"
1516

1617
class RGWEnv;
@@ -34,8 +35,10 @@ void write_policy_xml(const RGWAccessControlPolicy& policy,
3435
/// Construct a policy from a s3 canned acl string.
3536
int create_canned_acl(const ACLOwner& owner,
3637
const ACLOwner& bucket_owner,
38+
ObjectOwnership object_ownership,
3739
const std::string& canned_acl,
38-
RGWAccessControlPolicy& policy);
40+
RGWAccessControlPolicy& policy,
41+
std::string& error_message);
3942

4043
/// Construct a policy from x-amz-grant-* request headers.
4144
int create_policy_from_headers(const DoutPrefixProvider* dpp,

src/rgw/rgw_rest_s3.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,8 @@ static int create_s3_policy(req_state *s, rgw::sal::Driver* driver,
25262526
}
25272527

25282528
return rgw::s3::create_canned_acl(owner, s->bucket_owner,
2529-
s->canned_acl, policy);
2529+
s->bucket_object_ownership,
2530+
s->canned_acl, policy, s->err.message);
25302531
}
25312532

25322533
class RGWLocationConstraint : public XMLObj
@@ -3423,7 +3424,8 @@ int RGWPostObj_ObjStore_S3::get_policy(optional_yield y)
34233424

34243425
ldpp_dout(this, 20) << "canned_acl=" << canned_acl << dendl;
34253426
int r = rgw::s3::create_canned_acl(s->owner, s->bucket_owner,
3426-
canned_acl, policy);
3427+
s->bucket_object_ownership,
3428+
canned_acl, policy, s->err.message);
34273429
if (r < 0) {
34283430
err_msg = "Bad canned ACLs";
34293431
return r;

0 commit comments

Comments
 (0)