1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include <system_error>
11 #include <boost/algorithm/string/predicate.hpp>
12 #include <boost/bind.hpp>
13 #include <boost/optional.hpp>
14 #include <boost/utility/in_place_factory.hpp>
15 #include <boost/utility/string_view.hpp>
17 #include "include/scope_guard.h"
18 #include "common/Clock.h"
19 #include "common/armor.h"
20 #include "common/errno.h"
21 #include "common/mime.h"
22 #include "common/utf8.h"
23 #include "common/ceph_json.h"
24 #include "common/static_ptr.h"
26 #include "rgw_rados.h"
31 #include "rgw_acl_s3.h"
32 #include "rgw_acl_swift.h"
33 #include "rgw_aio_throttle.h"
35 #include "rgw_bucket.h"
37 #include "rgw_multi.h"
38 #include "rgw_multi_del.h"
40 #include "rgw_cors_s3.h"
41 #include "rgw_rest_conn.h"
42 #include "rgw_rest_s3.h"
44 #include "rgw_client_io.h"
45 #include "rgw_compression.h"
47 #include "rgw_tag_s3.h"
48 #include "rgw_putobj_processor.h"
49 #include "rgw_crypt.h"
50 #include "rgw_perf_counters.h"
52 #include "services/svc_zone.h"
53 #include "services/svc_quota.h"
54 #include "services/svc_sys_obj.h"
56 #include "cls/lock/cls_lock_client.h"
57 #include "cls/rgw/cls_rgw_client.h"
60 #include "include/ceph_assert.h"
62 #include "compressor/Compressor.h"
65 #define TRACEPOINT_DEFINE
66 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
67 #include "tracing/rgw_op.h"
68 #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
69 #undef TRACEPOINT_DEFINE
71 #define tracepoint(...)
74 #define dout_context g_ceph_context
75 #define dout_subsys ceph_subsys_rgw
77 using namespace librados
;
78 using ceph::crypto::MD5
;
79 using boost::optional
;
83 using rgw::IAM::Effect
;
84 using rgw::IAM::Policy
;
86 using rgw::IAM::Policy
;
88 static string mp_ns
= RGW_OBJ_NS_MULTIPART
;
89 static string shadow_ns
= RGW_OBJ_NS_SHADOW
;
91 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
);
92 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
, RGWRados
*store
,
93 bufferlist
& in_data
, JSONParser
*jp
, req_info
*forward_info
= nullptr);
95 static MultipartMetaFilter mp_filter
;
97 // this probably should belong in the rgw_iam_policy_keywords, I'll get it to it
99 static constexpr auto S3_EXISTING_OBJTAG
= "s3:ExistingObjectTag";
101 int RGWGetObj::parse_range(void)
104 string
rs(range_str
);
108 ignore_invalid_range
= s
->cct
->_conf
->rgw_ignore_get_invalid_range
;
109 partial_content
= false;
111 size_t pos
= rs
.find("bytes=");
112 if (pos
== string::npos
) {
114 while (isspace(rs
[pos
]))
117 while (isalpha(rs
[end
]))
119 if (strncasecmp(rs
.c_str(), "bytes", end
- pos
) != 0)
121 while (isspace(rs
[end
]))
125 rs
= rs
.substr(end
+ 1);
127 rs
= rs
.substr(pos
+ 6); /* size of("bytes=") */
130 if (pos
== string::npos
)
133 partial_content
= true;
135 ofs_str
= rs
.substr(0, pos
);
136 end_str
= rs
.substr(pos
+ 1);
137 if (end_str
.length()) {
138 end
= atoll(end_str
.c_str());
143 if (ofs_str
.length()) {
144 ofs
= atoll(ofs_str
.c_str());
145 } else { // RFC2616 suffix-byte-range-spec
150 if (end
>= 0 && end
< ofs
)
157 if (ignore_invalid_range
) {
158 partial_content
= false;
161 range_parsed
= false; // allow retry
168 static int decode_policy(CephContext
*cct
,
170 RGWAccessControlPolicy
*policy
)
172 auto iter
= bl
.cbegin();
174 policy
->decode(iter
);
175 } catch (buffer::error
& err
) {
176 ldout(cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
179 if (cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 15>()) {
180 ldout(cct
, 15) << __func__
<< " Read AccessControlPolicy";
181 RGWAccessControlPolicy_S3
*s3policy
= static_cast<RGWAccessControlPolicy_S3
*>(policy
);
182 s3policy
->to_xml(*_dout
);
189 static int get_user_policy_from_attr(CephContext
* const cct
,
190 RGWRados
* const store
,
191 map
<string
, bufferlist
>& attrs
,
192 RGWAccessControlPolicy
& policy
/* out */)
194 auto aiter
= attrs
.find(RGW_ATTR_ACL
);
195 if (aiter
!= attrs
.end()) {
196 int ret
= decode_policy(cct
, aiter
->second
, &policy
);
207 static int get_bucket_instance_policy_from_attr(CephContext
*cct
,
209 RGWBucketInfo
& bucket_info
,
210 map
<string
, bufferlist
>& bucket_attrs
,
211 RGWAccessControlPolicy
*policy
)
213 map
<string
, bufferlist
>::iterator aiter
= bucket_attrs
.find(RGW_ATTR_ACL
);
215 if (aiter
!= bucket_attrs
.end()) {
216 int ret
= decode_policy(cct
, aiter
->second
, policy
);
220 ldout(cct
, 0) << "WARNING: couldn't find acl header for bucket, generating default" << dendl
;
222 /* object exists, but policy is broken */
223 int r
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
227 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
232 static int get_obj_policy_from_attr(CephContext
*cct
,
234 RGWObjectCtx
& obj_ctx
,
235 RGWBucketInfo
& bucket_info
,
236 map
<string
, bufferlist
>& bucket_attrs
,
237 RGWAccessControlPolicy
*policy
,
238 string
*storage_class
,
244 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
245 RGWRados::Object::Read
rop(&op_target
);
247 ret
= rop
.get_attr(RGW_ATTR_ACL
, bl
);
249 ret
= decode_policy(cct
, bl
, policy
);
252 } else if (ret
== -ENODATA
) {
253 /* object exists, but policy is broken */
254 ldout(cct
, 0) << "WARNING: couldn't find acl header for object, generating default" << dendl
;
256 ret
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
260 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
265 int r
= rop
.get_attr(RGW_ATTR_STORAGE_CLASS
, scbl
);
267 *storage_class
= scbl
.to_str();
269 storage_class
->clear();
278 * Get the AccessControlPolicy for an object off of disk.
279 * policy: must point to a valid RGWACL, and will be filled upon return.
280 * bucket: name of the bucket containing the object.
281 * object: name of the object to get the ACL for.
282 * Returns: 0 on success, -ERR# otherwise.
284 int rgw_op_get_bucket_policy_from_attr(CephContext
*cct
,
286 RGWBucketInfo
& bucket_info
,
287 map
<string
, bufferlist
>& bucket_attrs
,
288 RGWAccessControlPolicy
*policy
)
290 return get_bucket_instance_policy_from_attr(cct
, store
, bucket_info
, bucket_attrs
, policy
);
293 static boost::optional
<Policy
> get_iam_policy_from_attr(CephContext
* cct
,
295 map
<string
, bufferlist
>& attrs
,
296 const string
& tenant
) {
297 auto i
= attrs
.find(RGW_ATTR_IAM_POLICY
);
298 if (i
!= attrs
.end()) {
299 return Policy(cct
, tenant
, i
->second
);
305 vector
<Policy
> get_iam_user_policy_from_attr(CephContext
* cct
,
307 map
<string
, bufferlist
>& attrs
,
308 const string
& tenant
) {
309 vector
<Policy
> policies
;
310 if (auto it
= attrs
.find(RGW_ATTR_USER_POLICY
); it
!= attrs
.end()) {
311 bufferlist out_bl
= attrs
[RGW_ATTR_USER_POLICY
];
312 map
<string
, string
> policy_map
;
313 decode(policy_map
, out_bl
);
314 for (auto& it
: policy_map
) {
315 bufferlist bl
= bufferlist::static_from_string(it
.second
);
316 Policy
p(cct
, tenant
, bl
);
317 policies
.push_back(std::move(p
));
323 static int get_obj_attrs(RGWRados
*store
, struct req_state
*s
, const rgw_obj
& obj
, map
<string
, bufferlist
>& attrs
)
325 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
326 RGWRados::Object::Read
read_op(&op_target
);
328 read_op
.params
.attrs
= &attrs
;
330 return read_op
.prepare();
333 static int get_obj_head(RGWRados
*store
, struct req_state
*s
,
335 map
<string
, bufferlist
> *attrs
,
338 store
->set_prefetch_data(s
->obj_ctx
, obj
);
340 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
341 RGWRados::Object::Read
read_op(&op_target
);
343 read_op
.params
.attrs
= attrs
;
345 int ret
= read_op
.prepare();
354 ret
= read_op
.read(0, s
->cct
->_conf
->rgw_max_chunk_size
, *pbl
);
359 struct multipart_upload_info
361 rgw_placement_rule dest_placement
;
363 void encode(bufferlist
& bl
) const {
364 ENCODE_START(1, 1, bl
);
365 encode(dest_placement
, bl
);
369 void decode(bufferlist::const_iterator
& bl
) {
371 decode(dest_placement
, bl
);
375 WRITE_CLASS_ENCODER(multipart_upload_info
)
377 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
379 RGWAccessControlPolicy
*policy
,
380 map
<string
, bufferlist
> *attrs
,
381 multipart_upload_info
*upload_info
)
386 bufferlist
*pheadbl
= (upload_info
? &headbl
: nullptr);
388 int op_ret
= get_obj_head(store
, s
, obj
, attrs
, pheadbl
);
390 if (op_ret
== -ENOENT
) {
391 return -ERR_NO_SUCH_UPLOAD
;
396 if (upload_info
&& headbl
.length() > 0) {
397 auto hiter
= headbl
.cbegin();
399 decode(*upload_info
, hiter
);
400 } catch (buffer::error
& err
) {
401 ldpp_dout(s
, 0) << "ERROR: failed to decode multipart upload info" << dendl
;
406 if (policy
&& attrs
) {
407 for (auto& iter
: *attrs
) {
408 string name
= iter
.first
;
409 if (name
.compare(RGW_ATTR_ACL
) == 0) {
410 bufferlist
& bl
= iter
.second
;
411 auto bli
= bl
.cbegin();
413 decode(*policy
, bli
);
414 } catch (buffer::error
& err
) {
415 ldpp_dout(s
, 0) << "ERROR: could not decode policy" << dendl
;
426 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
427 const string
& meta_oid
,
428 RGWAccessControlPolicy
*policy
,
429 map
<string
, bufferlist
> *attrs
,
430 multipart_upload_info
*upload_info
)
432 map
<string
, bufferlist
>::iterator iter
;
436 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
437 meta_obj
.set_in_extra_data(true);
439 return get_multipart_info(store
, s
, meta_obj
, policy
, attrs
, upload_info
);
442 static int modify_obj_attr(RGWRados
*store
, struct req_state
*s
, const rgw_obj
& obj
, const char* attr_name
, bufferlist
& attr_val
)
444 map
<string
, bufferlist
> attrs
;
445 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
446 RGWRados::Object::Read
read_op(&op_target
);
448 read_op
.params
.attrs
= &attrs
;
450 int r
= read_op
.prepare();
454 store
->set_atomic(s
->obj_ctx
, read_op
.state
.obj
);
455 attrs
[attr_name
] = attr_val
;
456 return store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, read_op
.state
.obj
, attrs
, NULL
);
459 static int read_bucket_policy(RGWRados
*store
,
461 RGWBucketInfo
& bucket_info
,
462 map
<string
, bufferlist
>& bucket_attrs
,
463 RGWAccessControlPolicy
*policy
,
466 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
467 ldpp_dout(s
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
468 << " is suspended" << dendl
;
469 return -ERR_USER_SUSPENDED
;
472 if (bucket
.name
.empty()) {
476 int ret
= rgw_op_get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, policy
);
477 if (ret
== -ENOENT
) {
478 ret
= -ERR_NO_SUCH_BUCKET
;
484 static int read_obj_policy(RGWRados
*store
,
486 RGWBucketInfo
& bucket_info
,
487 map
<string
, bufferlist
>& bucket_attrs
,
488 RGWAccessControlPolicy
* acl
,
489 string
*storage_class
,
490 boost::optional
<Policy
>& policy
,
495 upload_id
= s
->info
.args
.get("uploadId");
498 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
499 ldpp_dout(s
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
500 << " is suspended" << dendl
;
501 return -ERR_USER_SUSPENDED
;
504 if (!upload_id
.empty()) {
505 /* multipart upload */
506 RGWMPObj
mp(object
.name
, upload_id
);
507 string oid
= mp
.get_meta();
508 obj
.init_ns(bucket
, oid
, mp_ns
);
509 obj
.set_in_extra_data(true);
511 obj
= rgw_obj(bucket
, object
);
513 policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
, bucket
.tenant
);
515 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
516 int ret
= get_obj_policy_from_attr(s
->cct
, store
, *obj_ctx
,
517 bucket_info
, bucket_attrs
, acl
, storage_class
, obj
);
518 if (ret
== -ENOENT
) {
519 /* object does not exist checking the bucket's ACL to make sure
520 that we send a proper error code */
521 RGWAccessControlPolicy
bucket_policy(s
->cct
);
522 ret
= rgw_op_get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, &bucket_policy
);
526 const rgw_user
& bucket_owner
= bucket_policy
.get_owner().get_id();
527 if (bucket_owner
.compare(s
->user
->user_id
) != 0 &&
528 ! s
->auth
.identity
->is_admin_of(bucket_owner
)) {
530 auto r
= policy
->eval(s
->env
, *s
->auth
.identity
, rgw::IAM::s3ListBucket
, ARN(bucket
));
531 if (r
== Effect::Allow
)
533 if (r
== Effect::Deny
)
536 if (! bucket_policy
.verify_permission(s
, *s
->auth
.identity
, s
->perm_mask
, RGW_PERM_READ
))
549 * Get the AccessControlPolicy for an user, bucket or object off of disk.
550 * s: The req_state to draw information from.
551 * only_bucket: If true, reads the user and bucket ACLs rather than the object ACL.
552 * Returns: 0 on success, -ERR# otherwise.
554 int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
)
558 RGWUserInfo bucket_owner_info
;
559 auto obj_ctx
= store
->svc
.sysobj
->init_obj_ctx();
561 string bi
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"bucket-instance");
563 ret
= rgw_bucket_parse_bucket_instance(bi
, &s
->bucket_instance_id
, &s
->bucket_instance_shard_id
);
569 if(s
->dialect
.compare("s3") == 0) {
570 s
->bucket_acl
= std::make_unique
<RGWAccessControlPolicy_S3
>(s
->cct
);
571 } else if(s
->dialect
.compare("swift") == 0) {
572 /* We aren't allocating the account policy for those operations using
573 * the Swift's infrastructure that don't really need req_state::user.
574 * Typical example here is the implementation of /info. */
575 if (!s
->user
->user_id
.empty()) {
576 s
->user_acl
= std::make_unique
<RGWAccessControlPolicy_SWIFTAcct
>(s
->cct
);
578 s
->bucket_acl
= std::make_unique
<RGWAccessControlPolicy_SWIFT
>(s
->cct
);
580 s
->bucket_acl
= std::make_unique
<RGWAccessControlPolicy
>(s
->cct
);
583 /* check if copy source is within the current domain */
584 if (!s
->src_bucket_name
.empty()) {
585 RGWBucketInfo source_info
;
587 if (s
->bucket_instance_id
.empty()) {
588 ret
= store
->get_bucket_info(obj_ctx
, s
->src_tenant_name
, s
->src_bucket_name
, source_info
, NULL
);
590 ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, source_info
, NULL
, NULL
);
593 string
& zonegroup
= source_info
.zonegroup
;
594 s
->local_source
= store
->svc
.zone
->get_zonegroup().equals(zonegroup
);
600 std::string display_name
;
603 s
->user
->display_name
,
606 if (!s
->bucket_name
.empty()) {
607 s
->bucket_exists
= true;
608 if (s
->bucket_instance_id
.empty()) {
609 ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
610 s
->bucket_info
, &s
->bucket_mtime
,
613 ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
,
614 s
->bucket_info
, &s
->bucket_mtime
,
618 if (ret
!= -ENOENT
) {
620 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_log
);
621 ldpp_dout(s
, 0) << "NOTICE: couldn't get bucket from bucket_name (name="
622 << bucket_log
<< ")" << dendl
;
625 s
->bucket_exists
= false;
627 s
->bucket
= s
->bucket_info
.bucket
;
629 if (s
->bucket_exists
) {
630 ret
= read_bucket_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
,
631 s
->bucket_acl
.get(), s
->bucket
);
633 s
->bucket_info
.owner
,
634 s
->bucket_acl
->get_owner().get_display_name(),
637 s
->bucket_acl
->create_default(s
->user
->user_id
, s
->user
->display_name
);
638 ret
= -ERR_NO_SUCH_BUCKET
;
641 s
->bucket_owner
= s
->bucket_acl
->get_owner();
643 RGWZoneGroup zonegroup
;
644 int r
= store
->svc
.zone
->get_zonegroup(s
->bucket_info
.zonegroup
, zonegroup
);
646 if (!zonegroup
.endpoints
.empty()) {
647 s
->zonegroup_endpoint
= zonegroup
.endpoints
.front();
649 // use zonegroup's master zone endpoints
650 auto z
= zonegroup
.zones
.find(zonegroup
.master_zone
);
651 if (z
!= zonegroup
.zones
.end() && !z
->second
.endpoints
.empty()) {
652 s
->zonegroup_endpoint
= z
->second
.endpoints
.front();
655 s
->zonegroup_name
= zonegroup
.get_name();
657 if (r
< 0 && ret
== 0) {
661 if (s
->bucket_exists
&& !store
->svc
.zone
->get_zonegroup().equals(s
->bucket_info
.zonegroup
)) {
662 ldpp_dout(s
, 0) << "NOTICE: request for data in a different zonegroup ("
663 << s
->bucket_info
.zonegroup
<< " != "
664 << store
->svc
.zone
->get_zonegroup().get_id() << ")" << dendl
;
665 /* we now need to make sure that the operation actually requires copy source, that is
666 * it's a copy operation
668 if (store
->svc
.zone
->get_zonegroup().is_master_zonegroup() && s
->system_request
) {
669 /*If this is the master, don't redirect*/
670 } else if (s
->op_type
== RGW_OP_GET_BUCKET_LOCATION
) {
671 /* If op is get bucket location, don't redirect */
672 } else if (!s
->local_source
||
673 (s
->op
!= OP_PUT
&& s
->op
!= OP_COPY
) ||
675 return -ERR_PERMANENT_REDIRECT
;
679 /* init dest placement -- only if bucket exists, otherwise request is either not relevant, or
680 * it's a create_bucket request, in which case the op will deal with the placement later */
681 if (s
->bucket_exists
) {
682 s
->dest_placement
.storage_class
= s
->info
.storage_class
;
683 s
->dest_placement
.inherit_from(s
->bucket_info
.placement_rule
);
685 if (!store
->svc
.zone
->get_zone_params().valid_placement(s
->dest_placement
)) {
686 ldpp_dout(s
, 0) << "NOTICE: invalid dest placement: " << s
->dest_placement
.to_str() << dendl
;
692 /* handle user ACL only for those APIs which support it */
694 map
<string
, bufferlist
> uattrs
;
695 ret
= rgw_get_user_attrs_by_uid(store
, acct_acl_user
.uid
, uattrs
);
697 ret
= get_user_policy_from_attr(s
->cct
, store
, uattrs
, *s
->user_acl
);
699 if (-ENOENT
== ret
) {
700 /* In already existing clusters users won't have ACL. In such case
701 * assuming that only account owner has the rights seems to be
702 * reasonable. That allows to have only one verification logic.
703 * NOTE: there is small compatibility kludge for global, empty tenant:
704 * 1. if we try to reach an existing bucket, its owner is considered
706 * 2. otherwise account owner is identity stored in s->user->user_id. */
707 s
->user_acl
->create_default(acct_acl_user
.uid
,
708 acct_acl_user
.display_name
);
710 } else if (ret
< 0) {
711 ldpp_dout(s
, 0) << "NOTICE: couldn't get user attrs for handling ACL "
712 "(user_id=" << s
->user
->user_id
<< ", ret=" << ret
<< ")" << dendl
;
716 // We don't need user policies in case of STS token returned by AssumeRole,
717 // hence the check for user type
718 if (! s
->user
->user_id
.empty() && s
->auth
.identity
->get_identity_type() != TYPE_ROLE
) {
720 map
<string
, bufferlist
> uattrs
;
721 if (ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, uattrs
); ! ret
) {
722 if (s
->iam_user_policies
.empty()) {
723 s
->iam_user_policies
= get_iam_user_policy_from_attr(s
->cct
, store
, uattrs
, s
->user
->user_id
.tenant
);
725 // This scenario can happen when a STS token has a policy, then we need to append other user policies
726 // to the existing ones. (e.g. token returned by GetSessionToken)
727 auto user_policies
= get_iam_user_policy_from_attr(s
->cct
, store
, uattrs
, s
->user
->user_id
.tenant
);
728 s
->iam_user_policies
.insert(s
->iam_user_policies
.end(), user_policies
.begin(), user_policies
.end());
735 } catch (const std::exception
& e
) {
736 lderr(s
->cct
) << "Error reading IAM User Policy: " << e
.what() << dendl
;
742 s
->iam_policy
= get_iam_policy_from_attr(s
->cct
, store
, s
->bucket_attrs
,
744 } catch (const std::exception
& e
) {
745 // Really this is a can't happen condition. We parse the policy
746 // when it's given to us, so perhaps we should abort or otherwise
747 // raise bloody murder.
748 ldpp_dout(s
, 0) << "Error reading IAM Policy: " << e
.what() << dendl
;
752 bool success
= store
->svc
.zone
->get_redirect_zone_endpoint(&s
->redirect_zone_endpoint
);
754 ldpp_dout(s
, 20) << "redirect_zone_endpoint=" << s
->redirect_zone_endpoint
<< dendl
;
761 * Get the AccessControlPolicy for a bucket or object off of disk.
762 * s: The req_state to draw information from.
763 * only_bucket: If true, reads the bucket ACL rather than the object ACL.
764 * Returns: 0 on success, -ERR# otherwise.
766 int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
771 if (!s
->object
.empty()) {
772 if (!s
->bucket_exists
) {
773 return -ERR_NO_SUCH_BUCKET
;
775 s
->object_acl
= std::make_unique
<RGWAccessControlPolicy
>(s
->cct
);
776 rgw_obj
obj(s
->bucket
, s
->object
);
778 store
->set_atomic(s
->obj_ctx
, obj
);
780 store
->set_prefetch_data(s
->obj_ctx
, obj
);
782 ret
= read_obj_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
,
783 s
->object_acl
.get(), nullptr, s
->iam_policy
, s
->bucket
,
790 void rgw_add_to_iam_environment(rgw::IAM::Environment
& e
, std::string_view key
, std::string_view val
){
791 // This variant just adds non empty key pairs to IAM env., values can be empty
792 // in certain cases like tagging
797 static int rgw_iam_add_tags_from_bl(struct req_state
* s
, bufferlist
& bl
){
800 auto bliter
= bl
.cbegin();
801 tagset
.decode(bliter
);
802 } catch (buffer::error
& err
) {
803 ldpp_dout(s
, 0) << "ERROR: caught buffer::error, couldn't decode TagSet" << dendl
;
807 for (const auto& tag
: tagset
.get_tags()){
808 rgw_add_to_iam_environment(s
->env
, "s3:ExistingObjectTag/" + tag
.first
, tag
.second
);
813 static int rgw_iam_add_existing_objtags(RGWRados
* store
, struct req_state
* s
, rgw_obj
& obj
, std::uint64_t action
){
814 map
<string
, bufferlist
> attrs
;
815 store
->set_atomic(s
->obj_ctx
, obj
);
816 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
819 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
820 if (tags
!= attrs
.end()){
821 return rgw_iam_add_tags_from_bl(s
, tags
->second
);
826 static void rgw_add_grant_to_iam_environment(rgw::IAM::Environment
& e
, struct req_state
*s
){
828 using header_pair_t
= std::pair
<const char*, const char*>;
829 static const std::initializer_list
<header_pair_t
> acl_header_conditionals
{
830 {"HTTP_X_AMZ_GRANT_READ", "s3:x-amz-grant-read"},
831 {"HTTP_X_AMZ_GRANT_WRITE", "s3:x-amz-grant-write"},
832 {"HTTP_X_AMZ_GRANT_READ_ACP", "s3:x-amz-grant-read-acp"},
833 {"HTTP_X_AMZ_GRANT_WRITE_ACP", "s3:x-amz-grant-write-acp"},
834 {"HTTP_X_AMZ_GRANT_FULL_CONTROL", "s3:x-amz-grant-full-control"}
837 if (s
->has_acl_header
){
838 for (const auto& c
: acl_header_conditionals
){
839 auto hdr
= s
->info
.env
->get(c
.first
);
847 void rgw_build_iam_environment(RGWRados
* store
,
850 const auto& m
= s
->info
.env
->get_map();
851 auto t
= ceph::real_clock::now();
852 s
->env
.emplace("aws:CurrentTime", std::to_string(ceph::real_clock::to_time_t(t
)));
853 s
->env
.emplace("aws:EpochTime", ceph::to_iso_8601(t
));
854 // TODO: This is fine for now, but once we have STS we'll need to
855 // look and see. Also this won't work with the IdentityApplier
856 // model, since we need to know the actual credential.
857 s
->env
.emplace("aws:PrincipalType", "User");
859 auto i
= m
.find("HTTP_REFERER");
861 s
->env
.emplace("aws:Referer", i
->second
);
864 if (rgw_transport_is_secure(s
->cct
, *s
->info
.env
)) {
865 s
->env
.emplace("aws:SecureTransport", "true");
868 const auto remote_addr_param
= s
->cct
->_conf
->rgw_remote_addr_param
;
869 if (remote_addr_param
.length()) {
870 i
= m
.find(remote_addr_param
);
872 i
= m
.find("REMOTE_ADDR");
875 const string
* ip
= &(i
->second
);
877 if (remote_addr_param
== "HTTP_X_FORWARDED_FOR") {
878 const auto comma
= ip
->find(',');
879 if (comma
!= string::npos
) {
880 temp
.assign(*ip
, 0, comma
);
884 s
->env
.emplace("aws:SourceIp", *ip
);
887 i
= m
.find("HTTP_USER_AGENT"); {
889 s
->env
.emplace("aws:UserAgent", i
->second
);
893 // What to do about aws::userid? One can have multiple access
894 // keys so that isn't really suitable. Do we have a durable
895 // identifier that can persist through name changes?
896 s
->env
.emplace("aws:username", s
->user
->user_id
.id
);
899 i
= m
.find("HTTP_X_AMZ_SECURITY_TOKEN");
901 s
->env
.emplace("sts:authentication", "true");
903 s
->env
.emplace("sts:authentication", "false");
907 void rgw_bucket_object_pre_exec(struct req_state
*s
)
912 dump_bucket_from_state(s
);
915 // So! Now and then when we try to update bucket information, the
916 // bucket has changed during the course of the operation. (Or we have
917 // a cache consistency problem that Watch/Notify isn't ruling out
920 // When this happens, we need to update the bucket info and try
921 // again. We have, however, to try the right *part* again. We can't
922 // simply re-send, since that will obliterate the previous update.
924 // Thus, callers of this function should include everything that
925 // merges information to be changed into the bucket information as
926 // well as the call to set it.
928 // The called function must return an integer, negative on error. In
929 // general, they should just return op_ret.
932 int retry_raced_bucket_write(RGWRados
* g
, req_state
* s
, const F
& f
) {
934 for (auto i
= 0u; i
< 15u && r
== -ECANCELED
; ++i
) {
935 r
= g
->try_refresh_bucket_info(s
->bucket_info
, nullptr,
946 int RGWGetObj::verify_permission()
948 obj
= rgw_obj(s
->bucket
, s
->object
);
949 store
->set_atomic(s
->obj_ctx
, obj
);
951 store
->set_prefetch_data(s
->obj_ctx
, obj
);
954 if (torrent
.get_flag()) {
955 if (obj
.key
.instance
.empty()) {
956 action
= rgw::IAM::s3GetObjectTorrent
;
958 action
= rgw::IAM::s3GetObjectVersionTorrent
;
961 if (obj
.key
.instance
.empty()) {
962 action
= rgw::IAM::s3GetObject
;
964 action
= rgw::IAM::s3GetObjectVersion
;
966 if (s
->iam_policy
&& s
->iam_policy
->has_partial_conditional(S3_EXISTING_OBJTAG
))
967 rgw_iam_add_existing_objtags(store
, s
, obj
, action
);
968 if (! s
->iam_user_policies
.empty()) {
969 for (auto& user_policy
: s
->iam_user_policies
) {
970 if (user_policy
.has_partial_conditional(S3_EXISTING_OBJTAG
))
971 rgw_iam_add_existing_objtags(store
, s
, obj
, action
);
976 if (!verify_object_permission(this, s
, action
)) {
984 int RGWOp::verify_op_mask()
986 uint32_t required_mask
= op_mask();
988 ldpp_dout(this, 20) << "required_mask= " << required_mask
989 << " user.op_mask=" << s
->user
->op_mask
<< dendl
;
991 if ((s
->user
->op_mask
& required_mask
) != required_mask
) {
995 if (!s
->system_request
&& (required_mask
& RGW_OP_TYPE_MODIFY
) && !store
->svc
.zone
->zone_is_writeable()) {
996 ldpp_dout(this, 5) << "NOTICE: modify request to a read-only zone by a "
997 "non-system user, permission denied" << dendl
;
1004 int RGWGetObjTags::verify_permission()
1006 auto iam_action
= s
->object
.instance
.empty()?
1007 rgw::IAM::s3GetObjectTagging
:
1008 rgw::IAM::s3GetObjectVersionTagging
;
1009 // TODO since we are parsing the bl now anyway, we probably change
1010 // the send_response function to accept RGWObjTag instead of a bl
1011 if (s
->iam_policy
&& s
->iam_policy
->has_partial_conditional(S3_EXISTING_OBJTAG
)){
1012 rgw_obj obj
= rgw_obj(s
->bucket
, s
->object
);
1013 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
1015 if (! s
->iam_user_policies
.empty()) {
1016 for (auto& user_policy
: s
->iam_user_policies
) {
1017 if (user_policy
.has_partial_conditional(S3_EXISTING_OBJTAG
)) {
1018 rgw_obj obj
= rgw_obj(s
->bucket
, s
->object
);
1019 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
1023 if (!verify_object_permission(this, s
,iam_action
))
1029 void RGWGetObjTags::pre_exec()
1031 rgw_bucket_object_pre_exec(s
);
1034 void RGWGetObjTags::execute()
1037 map
<string
,bufferlist
> attrs
;
1039 obj
= rgw_obj(s
->bucket
, s
->object
);
1041 store
->set_atomic(s
->obj_ctx
, obj
);
1043 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
1045 ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << obj
1046 << " ret=" << op_ret
<< dendl
;
1050 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
1051 if(tags
!= attrs
.end()){
1053 tags_bl
.append(tags
->second
);
1055 send_response_data(tags_bl
);
1058 int RGWPutObjTags::verify_permission()
1060 auto iam_action
= s
->object
.instance
.empty() ?
1061 rgw::IAM::s3PutObjectTagging
:
1062 rgw::IAM::s3PutObjectVersionTagging
;
1064 if(s
->iam_policy
&& s
->iam_policy
->has_partial_conditional(S3_EXISTING_OBJTAG
)){
1065 auto obj
= rgw_obj(s
->bucket
, s
->object
);
1066 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
1068 if (! s
->iam_user_policies
.empty()) {
1069 for (auto& user_policy
: s
->iam_user_policies
) {
1070 if (user_policy
.has_partial_conditional(S3_EXISTING_OBJTAG
)) {
1071 rgw_obj obj
= rgw_obj(s
->bucket
, s
->object
);
1072 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
1076 if (!verify_object_permission(this, s
,iam_action
))
1081 void RGWPutObjTags::execute()
1083 op_ret
= get_params();
1087 if (s
->object
.empty()){
1088 op_ret
= -EINVAL
; // we only support tagging on existing objects
1093 obj
= rgw_obj(s
->bucket
, s
->object
);
1094 store
->set_atomic(s
->obj_ctx
, obj
);
1095 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_TAGS
, tags_bl
);
1096 if (op_ret
== -ECANCELED
){
1097 op_ret
= -ERR_TAG_CONFLICT
;
1101 void RGWDeleteObjTags::pre_exec()
1103 rgw_bucket_object_pre_exec(s
);
1107 int RGWDeleteObjTags::verify_permission()
1109 if (!s
->object
.empty()) {
1110 auto iam_action
= s
->object
.instance
.empty() ?
1111 rgw::IAM::s3DeleteObjectTagging
:
1112 rgw::IAM::s3DeleteObjectVersionTagging
;
1114 if (s
->iam_policy
&& s
->iam_policy
->has_partial_conditional(S3_EXISTING_OBJTAG
)){
1115 auto obj
= rgw_obj(s
->bucket
, s
->object
);
1116 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
1118 if (! s
->iam_user_policies
.empty()) {
1119 for (auto& user_policy
: s
->iam_user_policies
) {
1120 if (user_policy
.has_partial_conditional(S3_EXISTING_OBJTAG
)) {
1121 auto obj
= rgw_obj(s
->bucket
, s
->object
);
1122 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
1126 if (!verify_object_permission(this, s
, iam_action
))
1132 void RGWDeleteObjTags::execute()
1134 if (s
->object
.empty())
1138 obj
= rgw_obj(s
->bucket
, s
->object
);
1139 store
->set_atomic(s
->obj_ctx
, obj
);
1140 map
<string
, bufferlist
> attrs
;
1141 map
<string
, bufferlist
> rmattr
;
1143 rmattr
[RGW_ATTR_TAGS
] = bl
;
1144 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattr
);
1147 int RGWOp::do_aws4_auth_completion()
1149 ldpp_dout(this, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl
;
1150 if (s
->auth
.completer
) {
1151 if (!s
->auth
.completer
->complete()) {
1152 return -ERR_AMZ_CONTENT_SHA256_MISMATCH
;
1154 ldpp_dout(this, 10) << "v4 auth ok -- do_aws4_auth_completion" << dendl
;
1157 /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first
1158 * call passes, so we disable second one. This is old behaviour, sorry!
1159 * Plan for tomorrow: seek and destroy. */
1160 s
->auth
.completer
= nullptr;
1166 int RGWOp::init_quota()
1168 /* no quota enforcement for system requests */
1169 if (s
->system_request
)
1172 /* init quota related stuff */
1173 if (!(s
->user
->op_mask
& RGW_OP_TYPE_MODIFY
)) {
1177 /* only interested in object related ops */
1178 if (s
->object
.empty()) {
1182 RGWUserInfo owner_info
;
1185 if (s
->user
->user_id
== s
->bucket_owner
.get_id()) {
1188 int r
= rgw_get_user_info_by_uid(store
, s
->bucket_info
.owner
, owner_info
);
1191 uinfo
= &owner_info
;
1194 if (s
->bucket_info
.quota
.enabled
) {
1195 bucket_quota
= s
->bucket_info
.quota
;
1196 } else if (uinfo
->bucket_quota
.enabled
) {
1197 bucket_quota
= uinfo
->bucket_quota
;
1199 bucket_quota
= store
->svc
.quota
->get_bucket_quota();
1202 if (uinfo
->user_quota
.enabled
) {
1203 user_quota
= uinfo
->user_quota
;
1205 user_quota
= store
->svc
.quota
->get_user_quota();
1211 static bool validate_cors_rule_method(RGWCORSRule
*rule
, const char *req_meth
) {
1215 dout(5) << "req_meth is null" << dendl
;
1219 if (strcmp(req_meth
, "GET") == 0) flags
= RGW_CORS_GET
;
1220 else if (strcmp(req_meth
, "POST") == 0) flags
= RGW_CORS_POST
;
1221 else if (strcmp(req_meth
, "PUT") == 0) flags
= RGW_CORS_PUT
;
1222 else if (strcmp(req_meth
, "DELETE") == 0) flags
= RGW_CORS_DELETE
;
1223 else if (strcmp(req_meth
, "HEAD") == 0) flags
= RGW_CORS_HEAD
;
1225 if (rule
->get_allowed_methods() & flags
) {
1226 dout(10) << "Method " << req_meth
<< " is supported" << dendl
;
1228 dout(5) << "Method " << req_meth
<< " is not supported" << dendl
;
1235 static bool validate_cors_rule_header(RGWCORSRule
*rule
, const char *req_hdrs
) {
1237 vector
<string
> hdrs
;
1238 get_str_vec(req_hdrs
, hdrs
);
1239 for (const auto& hdr
: hdrs
) {
1240 if (!rule
->is_header_allowed(hdr
.c_str(), hdr
.length())) {
1241 dout(5) << "Header " << hdr
<< " is not registered in this rule" << dendl
;
1249 int RGWOp::read_bucket_cors()
1253 map
<string
, bufferlist
>::iterator aiter
= s
->bucket_attrs
.find(RGW_ATTR_CORS
);
1254 if (aiter
== s
->bucket_attrs
.end()) {
1255 ldpp_dout(this, 20) << "no CORS configuration attr found" << dendl
;
1257 return 0; /* no CORS configuration found */
1264 auto iter
= bl
.cbegin();
1266 bucket_cors
.decode(iter
);
1267 } catch (buffer::error
& err
) {
1268 ldpp_dout(this, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
1271 if (s
->cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 15>()) {
1272 RGWCORSConfiguration_S3
*s3cors
= static_cast<RGWCORSConfiguration_S3
*>(&bucket_cors
);
1273 ldpp_dout(this, 15) << "Read RGWCORSConfiguration";
1274 s3cors
->to_xml(*_dout
);
1281 * If any of the header field-names is not a ASCII case-insensitive match for
1282 * any of the values in list of headers do not set any additional headers and
1283 * terminate this set of steps.
1285 static void get_cors_response_headers(RGWCORSRule
*rule
, const char *req_hdrs
, string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
1288 get_str_list(req_hdrs
, hl
);
1289 for(list
<string
>::iterator it
= hl
.begin(); it
!= hl
.end(); ++it
) {
1290 if (!rule
->is_header_allowed((*it
).c_str(), (*it
).length())) {
1291 dout(5) << "Header " << (*it
) << " is not registered in this rule" << dendl
;
1293 if (hdrs
.length() > 0) hdrs
.append(",");
1298 rule
->format_exp_headers(exp_hdrs
);
1299 *max_age
= rule
->get_max_age();
1303 * Generate the CORS header response
1305 * This is described in the CORS standard, section 6.2.
1307 bool RGWOp::generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
)
1310 const char *orig
= s
->info
.env
->get("HTTP_ORIGIN");
1317 op_ret
= read_bucket_cors();
1323 ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl
;
1328 RGWCORSRule
*rule
= bucket_cors
.host_name_rule(orig
);
1333 * Set the Allowed-Origin header to a asterisk if this is allowed in the rule
1334 * and no Authorization was send by the client
1336 * The origin parameter specifies a URI that may access the resource. The browser must enforce this.
1337 * For requests without credentials, the server may specify "*" as a wildcard,
1338 * thereby allowing any origin to access the resource.
1340 const char *authorization
= s
->info
.env
->get("HTTP_AUTHORIZATION");
1341 if (!authorization
&& rule
->has_wildcard_origin())
1345 const char *req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
1347 req_meth
= s
->info
.method
;
1353 if (!validate_cors_rule_method(rule
, req_meth
)) {
1359 const char *req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
1362 get_cors_response_headers(rule
, req_hdrs
, headers
, exp_headers
, max_age
);
1367 int RGWGetObj::read_user_manifest_part(rgw_bucket
& bucket
,
1368 const rgw_bucket_dir_entry
& ent
,
1369 RGWAccessControlPolicy
* const bucket_acl
,
1370 const boost::optional
<Policy
>& bucket_policy
,
1371 const off_t start_ofs
,
1372 const off_t end_ofs
,
1375 ldpp_dout(this, 20) << "user manifest obj=" << ent
.key
.name
1376 << "[" << ent
.key
.instance
<< "]" << dendl
;
1377 RGWGetObj_CB
cb(this);
1378 RGWGetObj_Filter
* filter
= &cb
;
1379 boost::optional
<RGWGetObj_Decompress
> decompress
;
1381 int64_t cur_ofs
= start_ofs
;
1382 int64_t cur_end
= end_ofs
;
1384 rgw_obj
part(bucket
, ent
.key
);
1386 map
<string
, bufferlist
> attrs
;
1389 RGWObjectCtx
obj_ctx(store
);
1390 RGWAccessControlPolicy
obj_policy(s
->cct
);
1392 ldpp_dout(this, 20) << "reading obj=" << part
<< " ofs=" << cur_ofs
1393 << " end=" << cur_end
<< dendl
;
1395 obj_ctx
.set_atomic(part
);
1396 store
->set_prefetch_data(&obj_ctx
, part
);
1398 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, part
);
1399 RGWRados::Object::Read
read_op(&op_target
);
1402 /* SLO etag is optional */
1403 read_op
.conds
.if_match
= ent
.meta
.etag
.c_str();
1405 read_op
.params
.attrs
= &attrs
;
1406 read_op
.params
.obj_size
= &obj_size
;
1408 op_ret
= read_op
.prepare();
1411 op_ret
= read_op
.range_to_ofs(ent
.meta
.accounted_size
, cur_ofs
, cur_end
);
1414 bool need_decompress
;
1415 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1417 ldpp_dout(this, 0) << "ERROR: failed to decode compression info" << dendl
;
1421 if (need_decompress
)
1423 if (cs_info
.orig_size
!= ent
.meta
.accounted_size
) {
1424 // hmm.. something wrong, object not as expected, abort!
1425 ldpp_dout(this, 0) << "ERROR: expected cs_info.orig_size=" << cs_info
.orig_size
1426 << ", actual read size=" << ent
.meta
.size
<< dendl
;
1429 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1430 filter
= &*decompress
;
1434 if (obj_size
!= ent
.meta
.size
) {
1435 // hmm.. something wrong, object not as expected, abort!
1436 ldpp_dout(this, 0) << "ERROR: expected obj_size=" << obj_size
1437 << ", actual read size=" << ent
.meta
.size
<< dendl
;
1442 op_ret
= rgw_policy_from_attrset(s
->cct
, attrs
, &obj_policy
);
1446 /* We can use global user_acl because LOs cannot have segments
1447 * stored inside different accounts. */
1448 if (s
->system_request
) {
1449 ldpp_dout(this, 2) << "overriding permissions due to system operation" << dendl
;
1450 } else if (s
->auth
.identity
->is_admin_of(s
->user
->user_id
)) {
1451 ldpp_dout(this, 2) << "overriding permissions due to admin operation" << dendl
;
1452 } else if (!verify_object_permission(this, s
, part
, s
->user_acl
.get(), bucket_acl
,
1453 &obj_policy
, bucket_policy
, s
->iam_user_policies
, action
)) {
1456 if (ent
.meta
.size
== 0) {
1460 perfcounter
->inc(l_rgw_get_b
, cur_end
- cur_ofs
);
1461 filter
->fixup_range(cur_ofs
, cur_end
);
1462 op_ret
= read_op
.iterate(cur_ofs
, cur_end
, filter
);
1464 op_ret
= filter
->flush();
1468 static int iterate_user_manifest_parts(CephContext
* const cct
,
1469 RGWRados
* const store
,
1472 RGWBucketInfo
*pbucket_info
,
1473 const string
& obj_prefix
,
1474 RGWAccessControlPolicy
* const bucket_acl
,
1475 const boost::optional
<Policy
>& bucket_policy
,
1476 uint64_t * const ptotal_len
,
1477 uint64_t * const pobj_size
,
1478 string
* const pobj_sum
,
1479 int (*cb
)(rgw_bucket
& bucket
,
1480 const rgw_bucket_dir_entry
& ent
,
1481 RGWAccessControlPolicy
* const bucket_acl
,
1482 const boost::optional
<Policy
>& bucket_policy
,
1487 void * const cb_param
)
1489 rgw_bucket
& bucket
= pbucket_info
->bucket
;
1490 uint64_t obj_ofs
= 0, len_count
= 0;
1491 bool found_start
= false, found_end
= false, handled_end
= false;
1494 vector
<rgw_bucket_dir_entry
> objs
;
1496 utime_t start_time
= ceph_clock_now();
1498 RGWRados::Bucket
target(store
, *pbucket_info
);
1499 RGWRados::Bucket::List
list_op(&target
);
1501 list_op
.params
.prefix
= obj_prefix
;
1502 list_op
.params
.delim
= delim
;
1506 #define MAX_LIST_OBJS 100
1507 int r
= list_op
.list_objects(MAX_LIST_OBJS
, &objs
, NULL
, &is_truncated
);
1512 for (rgw_bucket_dir_entry
& ent
: objs
) {
1513 const uint64_t cur_total_len
= obj_ofs
;
1514 const uint64_t obj_size
= ent
.meta
.accounted_size
;
1515 uint64_t start_ofs
= 0, end_ofs
= obj_size
;
1517 if ((ptotal_len
|| cb
) && !found_start
&& cur_total_len
+ obj_size
> (uint64_t)ofs
) {
1518 start_ofs
= ofs
- obj_ofs
;
1522 obj_ofs
+= obj_size
;
1524 etag_sum
.Update((const unsigned char *)ent
.meta
.etag
.c_str(),
1525 ent
.meta
.etag
.length());
1528 if ((ptotal_len
|| cb
) && !found_end
&& obj_ofs
> (uint64_t)end
) {
1529 end_ofs
= end
- cur_total_len
+ 1;
1533 perfcounter
->tinc(l_rgw_get_lat
,
1534 (ceph_clock_now() - start_time
));
1536 if (found_start
&& !handled_end
) {
1537 len_count
+= end_ofs
- start_ofs
;
1540 r
= cb(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
,
1541 cb_param
, false /* swift_slo */);
1548 handled_end
= found_end
;
1549 start_time
= ceph_clock_now();
1551 } while (is_truncated
);
1554 *ptotal_len
= len_count
;
1557 *pobj_size
= obj_ofs
;
1560 complete_etag(etag_sum
, pobj_sum
);
1566 struct rgw_slo_part
{
1567 RGWAccessControlPolicy
*bucket_acl
= nullptr;
1568 Policy
* bucket_policy
= nullptr;
1575 static int iterate_slo_parts(CephContext
*cct
,
1579 map
<uint64_t, rgw_slo_part
>& slo_parts
,
1580 int (*cb
)(rgw_bucket
& bucket
,
1581 const rgw_bucket_dir_entry
& ent
,
1582 RGWAccessControlPolicy
*bucket_acl
,
1583 const boost::optional
<Policy
>& bucket_policy
,
1590 bool found_start
= false, found_end
= false;
1592 if (slo_parts
.empty()) {
1596 utime_t start_time
= ceph_clock_now();
1598 map
<uint64_t, rgw_slo_part
>::iterator iter
= slo_parts
.upper_bound(ofs
);
1599 if (iter
!= slo_parts
.begin()) {
1603 uint64_t obj_ofs
= iter
->first
;
1605 for (; iter
!= slo_parts
.end() && !found_end
; ++iter
) {
1606 rgw_slo_part
& part
= iter
->second
;
1607 rgw_bucket_dir_entry ent
;
1609 ent
.key
.name
= part
.obj_name
;
1610 ent
.meta
.accounted_size
= ent
.meta
.size
= part
.size
;
1611 ent
.meta
.etag
= part
.etag
;
1613 uint64_t cur_total_len
= obj_ofs
;
1614 uint64_t start_ofs
= 0, end_ofs
= ent
.meta
.size
;
1616 if (!found_start
&& cur_total_len
+ ent
.meta
.size
> (uint64_t)ofs
) {
1617 start_ofs
= ofs
- obj_ofs
;
1621 obj_ofs
+= ent
.meta
.size
;
1623 if (!found_end
&& obj_ofs
> (uint64_t)end
) {
1624 end_ofs
= end
- cur_total_len
+ 1;
1628 perfcounter
->tinc(l_rgw_get_lat
,
1629 (ceph_clock_now() - start_time
));
1633 // SLO is a Swift thing, and Swift has no knowledge of S3 Policies.
1634 int r
= cb(part
.bucket
, ent
, part
.bucket_acl
,
1635 (part
.bucket_policy
?
1636 boost::optional
<Policy
>(*part
.bucket_policy
) : none
),
1637 start_ofs
, end_ofs
, cb_param
, true /* swift_slo */);
1643 start_time
= ceph_clock_now();
1649 static int get_obj_user_manifest_iterate_cb(rgw_bucket
& bucket
,
1650 const rgw_bucket_dir_entry
& ent
,
1651 RGWAccessControlPolicy
* const bucket_acl
,
1652 const boost::optional
<Policy
>& bucket_policy
,
1653 const off_t start_ofs
,
1654 const off_t end_ofs
,
1656 bool swift_slo
= false)
1658 RGWGetObj
*op
= static_cast<RGWGetObj
*>(param
);
1659 return op
->read_user_manifest_part(
1660 bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
, swift_slo
);
1663 int RGWGetObj::handle_user_manifest(const char *prefix
)
1665 const boost::string_view
prefix_view(prefix
);
1666 ldpp_dout(this, 2) << "RGWGetObj::handle_user_manifest() prefix="
1667 << prefix_view
<< dendl
;
1669 const size_t pos
= prefix_view
.find('/');
1670 if (pos
== string::npos
) {
1674 const std::string bucket_name
= url_decode(prefix_view
.substr(0, pos
));
1675 const std::string obj_prefix
= url_decode(prefix_view
.substr(pos
+ 1));
1679 RGWAccessControlPolicy
_bucket_acl(s
->cct
);
1680 RGWAccessControlPolicy
*bucket_acl
;
1681 boost::optional
<Policy
> _bucket_policy
;
1682 boost::optional
<Policy
>* bucket_policy
;
1683 RGWBucketInfo bucket_info
;
1684 RGWBucketInfo
*pbucket_info
;
1686 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1687 map
<string
, bufferlist
> bucket_attrs
;
1688 auto obj_ctx
= store
->svc
.sysobj
->init_obj_ctx();
1689 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1690 bucket_name
, bucket_info
, NULL
,
1693 ldpp_dout(this, 0) << "could not get bucket info for bucket="
1694 << bucket_name
<< dendl
;
1697 bucket
= bucket_info
.bucket
;
1698 pbucket_info
= &bucket_info
;
1699 bucket_acl
= &_bucket_acl
;
1700 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
, bucket
);
1702 ldpp_dout(this, 0) << "failed to read bucket policy" << dendl
;
1705 _bucket_policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
,
1706 bucket_info
.bucket
.tenant
);
1707 bucket_policy
= &_bucket_policy
;
1710 pbucket_info
= &s
->bucket_info
;
1711 bucket_acl
= s
->bucket_acl
.get();
1712 bucket_policy
= &s
->iam_policy
;
1715 /* dry run to find out:
1716 * - total length (of the parts we are going to send to client),
1717 * - overall DLO's content size,
1718 * - md5 sum of overall DLO's content (for etag of Swift API). */
1719 int r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1720 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1721 nullptr, &s
->obj_size
, &lo_etag
,
1722 nullptr /* cb */, nullptr /* cb arg */);
1727 r
= RGWRados::Object::Read::range_to_ofs(s
->obj_size
, ofs
, end
);
1732 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1733 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1734 &total_len
, nullptr, nullptr,
1742 send_response_data(bl
, 0, 0);
1746 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1747 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1748 nullptr, nullptr, nullptr,
1749 get_obj_user_manifest_iterate_cb
, (void *)this);
1756 send_response_data(bl
, 0, 0);
1762 int RGWGetObj::handle_slo_manifest(bufferlist
& bl
)
1764 RGWSLOInfo slo_info
;
1765 auto bliter
= bl
.cbegin();
1767 decode(slo_info
, bliter
);
1768 } catch (buffer::error
& err
) {
1769 ldpp_dout(this, 0) << "ERROR: failed to decode slo manifest" << dendl
;
1772 ldpp_dout(this, 2) << "RGWGetObj::handle_slo_manifest()" << dendl
;
1774 vector
<RGWAccessControlPolicy
> allocated_acls
;
1775 map
<string
, pair
<RGWAccessControlPolicy
*, boost::optional
<Policy
>>> policies
;
1776 map
<string
, rgw_bucket
> buckets
;
1778 map
<uint64_t, rgw_slo_part
> slo_parts
;
1783 for (const auto& entry
: slo_info
.entries
) {
1784 const string
& path
= entry
.path
;
1786 /* If the path starts with slashes, strip them all. */
1787 const size_t pos_init
= path
.find_first_not_of('/');
1788 /* According to the documentation of std::string::find following check
1789 * is not necessary as we should get the std::string::npos propagation
1790 * here. This might be true with the accuracy to implementation's bugs.
1791 * See following question on SO:
1792 * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos
1794 if (pos_init
== string::npos
) {
1798 const size_t pos_sep
= path
.find('/', pos_init
);
1799 if (pos_sep
== string::npos
) {
1803 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
1804 string obj_name
= path
.substr(pos_sep
+ 1);
1807 RGWAccessControlPolicy
*bucket_acl
;
1808 Policy
* bucket_policy
;
1810 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1811 const auto& piter
= policies
.find(bucket_name
);
1812 if (piter
!= policies
.end()) {
1813 bucket_acl
= piter
->second
.first
;
1814 bucket_policy
= piter
->second
.second
.get_ptr();
1815 bucket
= buckets
[bucket_name
];
1817 allocated_acls
.push_back(RGWAccessControlPolicy(s
->cct
));
1818 RGWAccessControlPolicy
& _bucket_acl
= allocated_acls
.back();
1820 RGWBucketInfo bucket_info
;
1821 map
<string
, bufferlist
> bucket_attrs
;
1822 auto obj_ctx
= store
->svc
.sysobj
->init_obj_ctx();
1823 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1824 bucket_name
, bucket_info
, nullptr,
1827 ldpp_dout(this, 0) << "could not get bucket info for bucket="
1828 << bucket_name
<< dendl
;
1831 bucket
= bucket_info
.bucket
;
1832 bucket_acl
= &_bucket_acl
;
1833 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
,
1836 ldpp_dout(this, 0) << "failed to read bucket ACL for bucket "
1840 auto _bucket_policy
= get_iam_policy_from_attr(
1841 s
->cct
, store
, bucket_attrs
, bucket_info
.bucket
.tenant
);
1842 bucket_policy
= _bucket_policy
.get_ptr();
1843 buckets
[bucket_name
] = bucket
;
1844 policies
[bucket_name
] = make_pair(bucket_acl
, _bucket_policy
);
1848 bucket_acl
= s
->bucket_acl
.get();
1849 bucket_policy
= s
->iam_policy
.get_ptr();
1853 part
.bucket_acl
= bucket_acl
;
1854 part
.bucket_policy
= bucket_policy
;
1855 part
.bucket
= bucket
;
1856 part
.obj_name
= obj_name
;
1857 part
.size
= entry
.size_bytes
;
1858 part
.etag
= entry
.etag
;
1859 ldpp_dout(this, 20) << "slo_part: ofs=" << ofs
1860 << " bucket=" << part
.bucket
1861 << " obj=" << part
.obj_name
1862 << " size=" << part
.size
1863 << " etag=" << part
.etag
1866 etag_sum
.Update((const unsigned char *)entry
.etag
.c_str(),
1867 entry
.etag
.length());
1869 slo_parts
[total_len
] = part
;
1870 total_len
+= part
.size
;
1871 } /* foreach entry */
1873 complete_etag(etag_sum
, &lo_etag
);
1875 s
->obj_size
= slo_info
.total_size
;
1876 ldpp_dout(this, 20) << "s->obj_size=" << s
->obj_size
<< dendl
;
1878 int r
= RGWRados::Object::Read::range_to_ofs(total_len
, ofs
, end
);
1883 total_len
= end
- ofs
+ 1;
1885 r
= iterate_slo_parts(s
->cct
, store
, ofs
, end
, slo_parts
,
1886 get_obj_user_manifest_iterate_cb
, (void *)this);
1894 int RGWGetObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
1896 /* garbage collection related handling */
1897 utime_t start_time
= ceph_clock_now();
1898 if (start_time
> gc_invalidate_time
) {
1899 int r
= store
->defer_gc(s
->obj_ctx
, s
->bucket_info
, obj
);
1901 ldpp_dout(this, 0) << "WARNING: could not defer gc entry for obj" << dendl
;
1903 gc_invalidate_time
= start_time
;
1904 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1906 return send_response_data(bl
, bl_ofs
, bl_len
);
1909 bool RGWGetObj::prefetch_data()
1911 /* HEAD request, stop prefetch*/
1916 bool prefetch_first_chunk
= true;
1917 range_str
= s
->info
.env
->get("HTTP_RANGE");
1920 int r
= parse_range();
1921 /* error on parsing the range, stop prefetch and will fail in execute() */
1923 return false; /* range_parsed==false */
1925 /* range get goes to shadow objects, stop prefetch */
1926 if (ofs
>= s
->cct
->_conf
->rgw_max_chunk_size
) {
1927 prefetch_first_chunk
= false;
1931 return get_data
&& prefetch_first_chunk
;
1934 void RGWGetObj::pre_exec()
1936 rgw_bucket_object_pre_exec(s
);
1939 static bool object_is_expired(map
<string
, bufferlist
>& attrs
) {
1940 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1941 if (iter
!= attrs
.end()) {
1944 decode(delete_at
, iter
->second
);
1945 } catch (buffer::error
& err
) {
1946 dout(0) << "ERROR: " << __func__
<< ": failed to decode " RGW_ATTR_DELETE_AT
" attr" << dendl
;
1950 if (delete_at
<= ceph_clock_now() && !delete_at
.is_zero()) {
1958 void RGWGetObj::execute()
1961 gc_invalidate_time
= ceph_clock_now();
1962 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1964 bool need_decompress
;
1965 int64_t ofs_x
, end_x
;
1967 RGWGetObj_CB
cb(this);
1968 RGWGetObj_Filter
* filter
= (RGWGetObj_Filter
*)&cb
;
1969 boost::optional
<RGWGetObj_Decompress
> decompress
;
1970 std::unique_ptr
<RGWGetObj_Filter
> decrypt
;
1971 map
<string
, bufferlist
>::iterator attr_iter
;
1973 perfcounter
->inc(l_rgw_get
);
1975 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
1976 RGWRados::Object::Read
read_op(&op_target
);
1978 op_ret
= get_params();
1982 op_ret
= init_common();
1986 read_op
.conds
.mod_ptr
= mod_ptr
;
1987 read_op
.conds
.unmod_ptr
= unmod_ptr
;
1988 read_op
.conds
.high_precision_time
= s
->system_request
; /* system request need to use high precision time */
1989 read_op
.conds
.mod_zone_id
= mod_zone_id
;
1990 read_op
.conds
.mod_pg_ver
= mod_pg_ver
;
1991 read_op
.conds
.if_match
= if_match
;
1992 read_op
.conds
.if_nomatch
= if_nomatch
;
1993 read_op
.params
.attrs
= &attrs
;
1994 read_op
.params
.lastmod
= &lastmod
;
1995 read_op
.params
.obj_size
= &s
->obj_size
;
1997 op_ret
= read_op
.prepare();
2000 version_id
= read_op
.state
.obj
.key
.instance
;
2002 /* STAT ops don't need data, and do no i/o */
2003 if (get_type() == RGW_OP_STAT_OBJ
) {
2007 /* start gettorrent */
2008 if (torrent
.get_flag())
2010 attr_iter
= attrs
.find(RGW_ATTR_CRYPT_MODE
);
2011 if (attr_iter
!= attrs
.end() && attr_iter
->second
.to_str() == "SSE-C-AES256") {
2012 ldpp_dout(this, 0) << "ERROR: torrents are not supported for objects "
2013 "encrypted with SSE-C" << dendl
;
2017 torrent
.init(s
, store
);
2018 op_ret
= torrent
.get_torrent_file(read_op
, total_len
, bl
, obj
);
2021 ldpp_dout(this, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
2025 op_ret
= send_response_data(bl
, 0, total_len
);
2028 ldpp_dout(this, 0) << "ERROR: failed to send_response_data ret= " << op_ret
<< dendl
;
2033 /* end gettorrent */
2035 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
2037 ldpp_dout(s
, 0) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
2040 if (need_decompress
) {
2041 s
->obj_size
= cs_info
.orig_size
;
2042 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
2043 filter
= &*decompress
;
2046 attr_iter
= attrs
.find(RGW_ATTR_USER_MANIFEST
);
2047 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
2048 op_ret
= handle_user_manifest(attr_iter
->second
.c_str());
2050 ldpp_dout(this, 0) << "ERROR: failed to handle user manifest ret="
2057 attr_iter
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
2058 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
2060 op_ret
= handle_slo_manifest(attr_iter
->second
);
2062 ldpp_dout(this, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
2069 // for range requests with obj size 0
2070 if (range_str
&& !(s
->obj_size
)) {
2076 op_ret
= read_op
.range_to_ofs(s
->obj_size
, ofs
, end
);
2079 total_len
= (ofs
<= end
? end
+ 1 - ofs
: 0);
2081 /* Check whether the object has expired. Swift API documentation
2082 * stands that we should return 404 Not Found in such case. */
2083 if (need_object_expiration() && object_is_expired(attrs
)) {
2090 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
2091 op_ret
= this->get_decrypt_filter(&decrypt
, filter
,
2092 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
2093 if (decrypt
!= nullptr) {
2094 filter
= decrypt
.get();
2100 if (!get_data
|| ofs
> end
) {
2101 send_response_data(bl
, 0, 0);
2105 perfcounter
->inc(l_rgw_get_b
, end
- ofs
);
2109 filter
->fixup_range(ofs_x
, end_x
);
2110 op_ret
= read_op
.iterate(ofs_x
, end_x
, filter
);
2113 op_ret
= filter
->flush();
2115 perfcounter
->tinc(l_rgw_get_lat
, s
->time_elapsed());
2120 op_ret
= send_response_data(bl
, 0, 0);
2127 send_response_data_error();
2130 int RGWGetObj::init_common()
2133 /* range parsed error when prefetch */
2134 if (!range_parsed
) {
2135 int r
= parse_range();
2141 if (parse_time(if_mod
, &mod_time
) < 0)
2143 mod_ptr
= &mod_time
;
2147 if (parse_time(if_unmod
, &unmod_time
) < 0)
2149 unmod_ptr
= &unmod_time
;
2155 int RGWListBuckets::verify_permission()
2157 rgw::IAM::Partition partition
= rgw::IAM::Partition::aws
;
2158 rgw::IAM::Service service
= rgw::IAM::Service::s3
;
2160 if (!verify_user_permission(this, s
, ARN(partition
, service
, "", s
->user
->user_id
.tenant
, "*"), rgw::IAM::s3ListAllMyBuckets
)) {
2167 int RGWGetUsage::verify_permission()
2169 if (s
->auth
.identity
->is_anonymous()) {
2176 void RGWListBuckets::execute()
2179 bool started
= false;
2180 uint64_t total_count
= 0;
2182 const uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
2184 op_ret
= get_params();
2189 if (supports_account_metadata()) {
2190 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, attrs
);
2196 is_truncated
= false;
2198 RGWUserBuckets buckets
;
2199 uint64_t read_count
;
2201 read_count
= min(limit
- total_count
, max_buckets
);
2203 read_count
= max_buckets
;
2206 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2207 marker
, end_marker
, read_count
,
2208 should_get_stats(), &is_truncated
,
2211 /* hmm.. something wrong here.. the user was authenticated, so it
2213 ldpp_dout(this, 10) << "WARNING: failed on rgw_get_user_buckets uid="
2214 << s
->user
->user_id
<< dendl
;
2218 /* We need to have stats for all our policies - even if a given policy
2219 * isn't actually used in a given account. In such situation its usage
2220 * stats would be simply full of zeros. */
2221 for (const auto& policy
: store
->svc
.zone
->get_zonegroup().placement_targets
) {
2222 policies_stats
.emplace(policy
.second
.name
,
2223 decltype(policies_stats
)::mapped_type());
2226 std::map
<std::string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2227 for (const auto& kv
: m
) {
2228 const auto& bucket
= kv
.second
;
2230 global_stats
.bytes_used
+= bucket
.size
;
2231 global_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2232 global_stats
.objects_count
+= bucket
.count
;
2234 /* operator[] still can create a new entry for storage policy seen
2235 * for first time. */
2236 auto& policy_stats
= policies_stats
[bucket
.placement_rule
.to_str()];
2237 policy_stats
.bytes_used
+= bucket
.size
;
2238 policy_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2239 policy_stats
.buckets_count
++;
2240 policy_stats
.objects_count
+= bucket
.count
;
2242 global_stats
.buckets_count
+= m
.size();
2243 total_count
+= m
.size();
2245 done
= (m
.size() < read_count
|| (limit
>= 0 && total_count
>= (uint64_t)limit
));
2248 send_response_begin(buckets
.count() > 0);
2253 map
<string
, RGWBucketEnt
>::reverse_iterator riter
= m
.rbegin();
2254 marker
= riter
->first
;
2256 handle_listing_chunk(std::move(buckets
));
2258 } while (is_truncated
&& !done
);
2262 send_response_begin(false);
2264 send_response_end();
2267 void RGWGetUsage::execute()
2269 uint64_t start_epoch
= 0;
2270 uint64_t end_epoch
= (uint64_t)-1;
2271 op_ret
= get_params();
2275 if (!start_date
.empty()) {
2276 op_ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
2278 ldpp_dout(this, 0) << "ERROR: failed to parse start date" << dendl
;
2283 if (!end_date
.empty()) {
2284 op_ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
2286 ldpp_dout(this, 0) << "ERROR: failed to parse end date" << dendl
;
2291 uint32_t max_entries
= 1000;
2293 bool is_truncated
= true;
2295 RGWUsageIter usage_iter
;
2297 while (is_truncated
) {
2298 op_ret
= store
->read_usage(s
->user
->user_id
, s
->bucket_name
, start_epoch
, end_epoch
, max_entries
,
2299 &is_truncated
, usage_iter
, usage
);
2301 if (op_ret
== -ENOENT
) {
2303 is_truncated
= false;
2311 op_ret
= rgw_user_sync_all_stats(store
, s
->user
->user_id
);
2313 ldpp_dout(this, 0) << "ERROR: failed to sync user stats" << dendl
;
2317 op_ret
= rgw_user_get_all_buckets_stats(store
, s
->user
->user_id
, buckets_usage
);
2319 ldpp_dout(this, 0) << "ERROR: failed to get user's buckets stats" << dendl
;
2323 string user_str
= s
->user
->user_id
.to_str();
2324 op_ret
= store
->cls_user_get_header(user_str
, &header
);
2326 ldpp_dout(this, 0) << "ERROR: can't read user header" << dendl
;
2333 int RGWStatAccount::verify_permission()
2335 if (!verify_user_permission_no_policy(this, s
, RGW_PERM_READ
)) {
2342 void RGWStatAccount::execute()
2345 bool is_truncated
= false;
2346 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
2349 RGWUserBuckets buckets
;
2351 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
, marker
,
2352 string(), max_buckets
, true, &is_truncated
);
2354 /* hmm.. something wrong here.. the user was authenticated, so it
2356 ldpp_dout(this, 10) << "WARNING: failed on rgw_get_user_buckets uid="
2357 << s
->user
->user_id
<< dendl
;
2360 /* We need to have stats for all our policies - even if a given policy
2361 * isn't actually used in a given account. In such situation its usage
2362 * stats would be simply full of zeros. */
2363 for (const auto& policy
: store
->svc
.zone
->get_zonegroup().placement_targets
) {
2364 policies_stats
.emplace(policy
.second
.name
,
2365 decltype(policies_stats
)::mapped_type());
2368 std::map
<std::string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2369 for (const auto& kv
: m
) {
2370 const auto& bucket
= kv
.second
;
2372 global_stats
.bytes_used
+= bucket
.size
;
2373 global_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2374 global_stats
.objects_count
+= bucket
.count
;
2376 /* operator[] still can create a new entry for storage policy seen
2377 * for first time. */
2378 auto& policy_stats
= policies_stats
[bucket
.placement_rule
.to_str()];
2379 policy_stats
.bytes_used
+= bucket
.size
;
2380 policy_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2381 policy_stats
.buckets_count
++;
2382 policy_stats
.objects_count
+= bucket
.count
;
2384 global_stats
.buckets_count
+= m
.size();
2387 } while (is_truncated
);
2390 int RGWGetBucketVersioning::verify_permission()
2392 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketVersioning
);
2395 void RGWGetBucketVersioning::pre_exec()
2397 rgw_bucket_object_pre_exec(s
);
2400 void RGWGetBucketVersioning::execute()
2402 versioned
= s
->bucket_info
.versioned();
2403 versioning_enabled
= s
->bucket_info
.versioning_enabled();
2404 mfa_enabled
= s
->bucket_info
.mfa_enabled();
2407 int RGWSetBucketVersioning::verify_permission()
2409 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketVersioning
);
2412 void RGWSetBucketVersioning::pre_exec()
2414 rgw_bucket_object_pre_exec(s
);
2417 void RGWSetBucketVersioning::execute()
2419 op_ret
= get_params();
2423 bool cur_mfa_status
= (s
->bucket_info
.flags
& BUCKET_MFA_ENABLED
) != 0;
2425 mfa_set_status
&= (mfa_status
!= cur_mfa_status
);
2427 if (mfa_set_status
&&
2429 op_ret
= -ERR_MFA_REQUIRED
;
2433 if (!store
->svc
.zone
->is_meta_master()) {
2434 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2436 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
2441 bool modified
= mfa_set_status
;
2443 op_ret
= retry_raced_bucket_write(store
, s
, [&] {
2444 if (mfa_set_status
) {
2446 s
->bucket_info
.flags
|= BUCKET_MFA_ENABLED
;
2448 s
->bucket_info
.flags
&= ~BUCKET_MFA_ENABLED
;
2452 if (versioning_status
== VersioningEnabled
) {
2453 s
->bucket_info
.flags
|= BUCKET_VERSIONED
;
2454 s
->bucket_info
.flags
&= ~BUCKET_VERSIONS_SUSPENDED
;
2456 } else if (versioning_status
== VersioningSuspended
) {
2457 s
->bucket_info
.flags
|= (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
);
2462 return store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
2471 ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2472 << " returned err=" << op_ret
<< dendl
;
2477 int RGWGetBucketWebsite::verify_permission()
2479 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketWebsite
);
2482 void RGWGetBucketWebsite::pre_exec()
2484 rgw_bucket_object_pre_exec(s
);
2487 void RGWGetBucketWebsite::execute()
2489 if (!s
->bucket_info
.has_website
) {
2490 op_ret
= -ERR_NO_SUCH_WEBSITE_CONFIGURATION
;
2494 int RGWSetBucketWebsite::verify_permission()
2496 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketWebsite
);
2499 void RGWSetBucketWebsite::pre_exec()
2501 rgw_bucket_object_pre_exec(s
);
2504 void RGWSetBucketWebsite::execute()
2506 op_ret
= get_params();
2511 if (!store
->svc
.zone
->is_meta_master()) {
2512 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2514 ldpp_dout(this, 0) << " forward_request_to_master returned ret=" << op_ret
<< dendl
;
2519 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2520 s
->bucket_info
.has_website
= true;
2521 s
->bucket_info
.website_conf
= website_conf
;
2522 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false,
2523 real_time(), &s
->bucket_attrs
);
2528 ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2529 << " returned err=" << op_ret
<< dendl
;
2534 int RGWDeleteBucketWebsite::verify_permission()
2536 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3DeleteBucketWebsite
);
2539 void RGWDeleteBucketWebsite::pre_exec()
2541 rgw_bucket_object_pre_exec(s
);
2544 void RGWDeleteBucketWebsite::execute()
2547 if (!store
->svc
.zone
->is_meta_master()) {
2549 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, nullptr);
2551 ldpp_dout(this, 0) << "NOTICE: forward_to_master failed on bucket=" << s
->bucket
.name
2552 << "returned err=" << op_ret
<< dendl
;
2556 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2557 s
->bucket_info
.has_website
= false;
2558 s
->bucket_info
.website_conf
= RGWBucketWebsiteConf();
2559 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false,
2560 real_time(), &s
->bucket_attrs
);
2564 ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2565 << " returned err=" << op_ret
<< dendl
;
2570 int RGWStatBucket::verify_permission()
2572 // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission.
2573 if (!verify_bucket_permission(this, s
, rgw::IAM::s3ListBucket
)) {
2580 void RGWStatBucket::pre_exec()
2582 rgw_bucket_object_pre_exec(s
);
2585 void RGWStatBucket::execute()
2587 if (!s
->bucket_exists
) {
2588 op_ret
= -ERR_NO_SUCH_BUCKET
;
2592 RGWUserBuckets buckets
;
2593 bucket
.bucket
= s
->bucket
;
2594 buckets
.add(bucket
);
2595 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2596 op_ret
= store
->update_containers_stats(m
);
2601 map
<string
, RGWBucketEnt
>::iterator iter
= m
.find(bucket
.bucket
.name
);
2602 if (iter
!= m
.end()) {
2603 bucket
= iter
->second
;
2610 int RGWListBucket::verify_permission()
2612 op_ret
= get_params();
2616 if (!prefix
.empty())
2617 s
->env
.emplace("s3:prefix", prefix
);
2619 if (!delimiter
.empty())
2620 s
->env
.emplace("s3:delimiter", delimiter
);
2622 s
->env
.emplace("s3:max-keys", std::to_string(max
));
2624 if (!verify_bucket_permission(this,
2627 rgw::IAM::s3ListBucketVersions
:
2628 rgw::IAM::s3ListBucket
)) {
2635 int RGWListBucket::parse_max_keys()
2637 // Bound max value of max-keys to configured value for security
2638 // Bound min value of max-keys to '0'
2639 // Some S3 clients explicitly send max-keys=0 to detect if the bucket is
2640 // empty without listing any items.
2641 return parse_value_and_bound(max_keys
, max
, 0,
2642 g_conf().get_val
<uint64_t>("rgw_max_listing_results"),
2646 void RGWListBucket::pre_exec()
2648 rgw_bucket_object_pre_exec(s
);
2651 void RGWListBucket::execute()
2653 if (!s
->bucket_exists
) {
2654 op_ret
= -ERR_NO_SUCH_BUCKET
;
2658 if (allow_unordered
&& !delimiter
.empty()) {
2659 ldpp_dout(this, 0) <<
2660 "ERROR: unordered bucket listing requested with a delimiter" << dendl
;
2665 if (need_container_stats()) {
2666 map
<string
, RGWBucketEnt
> m
;
2667 m
[s
->bucket
.name
] = RGWBucketEnt();
2668 m
.begin()->second
.bucket
= s
->bucket
;
2669 op_ret
= store
->update_containers_stats(m
);
2671 bucket
= m
.begin()->second
;
2675 RGWRados::Bucket
target(store
, s
->bucket_info
);
2676 if (shard_id
>= 0) {
2677 target
.set_shard_id(shard_id
);
2679 RGWRados::Bucket::List
list_op(&target
);
2681 list_op
.params
.prefix
= prefix
;
2682 list_op
.params
.delim
= delimiter
;
2683 list_op
.params
.marker
= marker
;
2684 list_op
.params
.end_marker
= end_marker
;
2685 list_op
.params
.list_versions
= list_versions
;
2686 list_op
.params
.allow_unordered
= allow_unordered
;
2688 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2690 next_marker
= list_op
.get_next_marker();
2694 int RGWGetBucketLogging::verify_permission()
2696 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLogging
);
2699 int RGWGetBucketLocation::verify_permission()
2701 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLocation
);
2704 int RGWCreateBucket::verify_permission()
2706 /* This check is mostly needed for S3 that doesn't support account ACL.
2707 * Swift doesn't allow to delegate any permission to an anonymous user,
2708 * so it will become an early exit in such case. */
2709 if (s
->auth
.identity
->is_anonymous()) {
2714 bucket
.name
= s
->bucket_name
;
2715 bucket
.tenant
= s
->bucket_tenant
;
2716 ARN arn
= ARN(bucket
);
2717 if (!verify_user_permission(this, s
, arn
, rgw::IAM::s3CreateBucket
)) {
2721 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2722 ldpp_dout(this, 10) << "user cannot create a bucket in a different tenant"
2723 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2724 << " requested=" << s
->bucket_tenant
<< ")"
2728 if (s
->user
->max_buckets
< 0) {
2732 if (s
->user
->max_buckets
) {
2733 RGWUserBuckets buckets
;
2735 bool is_truncated
= false;
2736 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2737 marker
, string(), s
->user
->max_buckets
,
2738 false, &is_truncated
);
2743 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2744 return -ERR_TOO_MANY_BUCKETS
;
2751 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2752 RGWRados
*store
, bufferlist
& in_data
,
2753 JSONParser
*jp
, req_info
*forward_info
)
2755 if (!store
->svc
.zone
->get_master_conn()) {
2756 ldpp_dout(s
, 0) << "rest connection is invalid" << dendl
;
2759 ldpp_dout(s
, 0) << "sending request to master zonegroup" << dendl
;
2760 bufferlist response
;
2761 string uid_str
= s
->user
->user_id
.to_str();
2762 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2763 int ret
= store
->svc
.zone
->get_master_conn()->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2764 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2768 ldpp_dout(s
, 20) << "response: " << response
.c_str() << dendl
;
2769 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2770 ldpp_dout(s
, 0) << "failed parsing response from master zonegroup" << dendl
;
2777 void RGWCreateBucket::pre_exec()
2779 rgw_bucket_object_pre_exec(s
);
2782 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2783 map
<string
, bufferlist
>& out_attrs
,
2784 map
<string
, bufferlist
>& out_rmattrs
)
2786 for (const auto& kv
: orig_attrs
) {
2787 const string
& name
= kv
.first
;
2789 /* Check if the attr is user-defined metadata item. */
2790 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2791 RGW_ATTR_META_PREFIX
) == 0) {
2792 /* For the objects all existing meta attrs have to be removed. */
2793 out_rmattrs
[name
] = kv
.second
;
2794 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2795 out_attrs
[name
] = kv
.second
;
2800 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2801 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2802 * @out_attrs. Place results in @out_attrs.
2804 * NOTE: it's supposed that all special attrs already present in @out_attrs
2805 * will be preserved without any change. Special attributes are those which
2806 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2807 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2808 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2809 const set
<string
>& rmattr_names
,
2810 map
<string
, bufferlist
>& out_attrs
)
2812 for (const auto& kv
: orig_attrs
) {
2813 const string
& name
= kv
.first
;
2815 /* Check if the attr is user-defined metadata item. */
2816 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2817 RGW_ATTR_META_PREFIX
) == 0) {
2818 /* For the buckets all existing meta attrs are preserved,
2819 except those that are listed in rmattr_names. */
2820 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2821 const auto aiter
= out_attrs
.find(name
);
2823 if (aiter
!= std::end(out_attrs
)) {
2824 out_attrs
.erase(aiter
);
2827 /* emplace() won't alter the map if the key is already present.
2828 * This behaviour is fully intensional here. */
2829 out_attrs
.emplace(kv
);
2831 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2832 out_attrs
[name
] = kv
.second
;
2838 static void populate_with_generic_attrs(const req_state
* const s
,
2839 map
<string
, bufferlist
>& out_attrs
)
2841 for (const auto& kv
: s
->generic_attrs
) {
2842 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2843 const string
& val
= kv
.second
;
2845 attrbl
.append(val
.c_str(), val
.size() + 1);
2850 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2851 const std::set
<std::string
>& rmattr_names
,
2852 RGWQuotaInfo
& quota
,
2853 bool * quota_extracted
= nullptr)
2855 bool extracted
= false;
2857 /* Put new limit on max objects. */
2858 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2860 if (std::end(add_attrs
) != iter
) {
2862 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2866 add_attrs
.erase(iter
);
2870 /* Put new limit on bucket (container) size. */
2871 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2872 if (iter
!= add_attrs
.end()) {
2874 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2878 add_attrs
.erase(iter
);
2882 for (const auto& name
: rmattr_names
) {
2883 /* Remove limit on max objects. */
2884 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2885 quota
.max_objects
= -1;
2889 /* Remove limit on max bucket size. */
2890 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2891 quota
.max_size
= -1;
2896 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2897 quota
.check_on_raw
= true;
2898 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2900 if (quota_extracted
) {
2901 *quota_extracted
= extracted
;
2908 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2909 const std::set
<std::string
>& rmattr_names
,
2910 RGWBucketWebsiteConf
& ws_conf
)
2914 /* Let's define a mapping between each custom attribute and the memory where
2915 * attribute's value should be stored. The memory location is expressed by
2916 * a non-const reference. */
2917 const auto mapping
= {
2918 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2919 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2920 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2921 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2922 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2925 for (const auto& kv
: mapping
) {
2926 const char * const key
= kv
.first
;
2927 auto& target
= kv
.second
;
2929 auto iter
= add_attrs
.find(key
);
2931 if (std::end(add_attrs
) != iter
) {
2932 /* The "target" is a reference to ws_conf. */
2933 target
= iter
->second
.c_str();
2934 add_attrs
.erase(iter
);
2937 if (rmattr_names
.count(key
)) {
2938 target
= std::string();
2942 if (! lstval
.empty()) {
2943 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2948 void RGWCreateBucket::execute()
2950 RGWAccessControlPolicy
old_policy(s
->cct
);
2952 buffer::list corsbl
;
2955 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2956 rgw_raw_obj
obj(store
->svc
.zone
->get_zone_params().domain_root
, bucket_name
);
2957 obj_version objv
, *pobjv
= NULL
;
2959 op_ret
= get_params();
2963 if (!relaxed_region_enforcement
&&
2964 !location_constraint
.empty() &&
2965 !store
->svc
.zone
->has_zonegroup_api(location_constraint
)) {
2966 ldpp_dout(this, 0) << "location constraint (" << location_constraint
<< ")"
2967 << " can't be found." << dendl
;
2968 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2969 s
->err
.message
= "The specified location-constraint is not valid";
2973 if (!relaxed_region_enforcement
&& !store
->svc
.zone
->get_zonegroup().is_master_zonegroup() && !location_constraint
.empty() &&
2974 store
->svc
.zone
->get_zonegroup().api_name
!= location_constraint
) {
2975 ldpp_dout(this, 0) << "location constraint (" << location_constraint
<< ")"
2976 << " doesn't match zonegroup" << " (" << store
->svc
.zone
->get_zonegroup().api_name
<< ")"
2978 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2979 s
->err
.message
= "The specified location-constraint is not valid";
2983 const auto& zonegroup
= store
->svc
.zone
->get_zonegroup();
2984 if (!placement_rule
.name
.empty() &&
2985 !zonegroup
.placement_targets
.count(placement_rule
.name
)) {
2986 ldpp_dout(this, 0) << "placement target (" << placement_rule
.name
<< ")"
2987 << " doesn't exist in the placement targets of zonegroup"
2988 << " (" << store
->svc
.zone
->get_zonegroup().api_name
<< ")" << dendl
;
2989 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2990 s
->err
.message
= "The specified placement target does not exist";
2994 /* we need to make sure we read bucket info, it's not read before for this
2995 * specific request */
2996 op_ret
= store
->get_bucket_info(*s
->sysobj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2997 s
->bucket_info
, nullptr, &s
->bucket_attrs
);
2998 if (op_ret
< 0 && op_ret
!= -ENOENT
)
3000 s
->bucket_exists
= (op_ret
!= -ENOENT
);
3002 s
->bucket_owner
.set_id(s
->user
->user_id
);
3003 s
->bucket_owner
.set_name(s
->user
->display_name
);
3004 if (s
->bucket_exists
) {
3005 int r
= rgw_op_get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
3006 s
->bucket_attrs
, &old_policy
);
3008 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
3015 RGWBucketInfo master_info
;
3016 rgw_bucket
*pmaster_bucket
;
3017 uint32_t *pmaster_num_shards
;
3018 real_time creation_time
;
3020 if (!store
->svc
.zone
->is_meta_master()) {
3022 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
3027 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
3028 JSONDecoder::decode_json("object_ver", objv
, &jp
);
3029 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
3030 ldpp_dout(this, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
3031 ldpp_dout(this, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
3032 pmaster_bucket
= &master_info
.bucket
;
3033 creation_time
= master_info
.creation_time
;
3034 pmaster_num_shards
= &master_info
.num_shards
;
3037 pmaster_bucket
= NULL
;
3038 pmaster_num_shards
= NULL
;
3041 string zonegroup_id
;
3043 if (s
->system_request
) {
3044 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
3045 if (zonegroup_id
.empty()) {
3046 zonegroup_id
= store
->svc
.zone
->get_zonegroup().get_id();
3049 zonegroup_id
= store
->svc
.zone
->get_zonegroup().get_id();
3052 if (s
->bucket_exists
) {
3053 rgw_placement_rule selected_placement_rule
;
3055 bucket
.tenant
= s
->bucket_tenant
;
3056 bucket
.name
= s
->bucket_name
;
3057 op_ret
= store
->svc
.zone
->select_bucket_placement(*(s
->user
), zonegroup_id
,
3059 &selected_placement_rule
, nullptr);
3060 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
3066 /* Encode special metadata first as we're using std::map::emplace under
3067 * the hood. This method will add the new items only if the map doesn't
3068 * contain such keys yet. */
3069 policy
.encode(aclbl
);
3070 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3073 cors_config
.encode(corsbl
);
3074 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
3077 RGWQuotaInfo quota_info
;
3078 const RGWQuotaInfo
* pquota_info
= nullptr;
3079 if (need_metadata_upload()) {
3080 /* It's supposed that following functions WILL NOT change any special
3081 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
3082 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3086 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
3087 populate_with_generic_attrs(s
, attrs
);
3089 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
3093 pquota_info
= "a_info
;
3096 /* Web site of Swift API. */
3097 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
3098 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
3101 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
3102 s
->bucket
.name
= s
->bucket_name
;
3104 /* Handle updates of the metadata for Swift's object versioning. */
3105 if (swift_ver_location
) {
3106 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
3107 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
3110 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
3111 placement_rule
, s
->bucket_info
.swift_ver_location
,
3113 info
, pobjv
, &ep_objv
, creation_time
,
3114 pmaster_bucket
, pmaster_num_shards
, true);
3115 /* continue if EEXIST and create_bucket will fail below. this way we can
3116 * recover from a partial create by retrying it. */
3117 ldpp_dout(this, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
3119 if (op_ret
&& op_ret
!= -EEXIST
)
3122 existed
= (op_ret
== -EEXIST
);
3125 /* bucket already existed, might have raced with another bucket creation, or
3126 * might be partial bucket creation that never completed. Read existing bucket
3127 * info, verify that the reported bucket owner is the current user.
3128 * If all is ok then update the user's list of buckets.
3129 * Otherwise inform client about a name conflict.
3131 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
3135 s
->bucket
= info
.bucket
;
3138 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
3139 info
.creation_time
, false);
3140 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
3141 /* if it exists (or previously existed), don't remove it! */
3142 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
3145 ldpp_dout(this, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
3148 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
3149 op_ret
= -ERR_BUCKET_EXISTS
;
3152 if (need_metadata_upload() && existed
) {
3153 /* OK, it looks we lost race with another request. As it's required to
3154 * handle metadata fusion and upload, the whole operation becomes very
3155 * similar in nature to PutMetadataBucket. However, as the attrs may
3156 * changed in the meantime, we have to refresh. */
3159 RGWBucketInfo binfo
;
3160 map
<string
, bufferlist
> battrs
;
3162 op_ret
= store
->get_bucket_info(*s
->sysobj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
3163 binfo
, nullptr, &battrs
);
3166 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
3167 /* New bucket doesn't belong to the account we're operating on. */
3171 s
->bucket_info
= binfo
;
3172 s
->bucket_attrs
= battrs
;
3177 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3181 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
3182 populate_with_generic_attrs(s
, attrs
);
3183 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
3188 /* Handle updates of the metadata for Swift's object versioning. */
3189 if (swift_ver_location
) {
3190 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
3191 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
3194 /* Web site of Swift API. */
3195 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
3196 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
3198 /* This will also set the quota on the bucket. */
3199 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
3200 &s
->bucket_info
.objv_tracker
);
3201 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
3203 /* Restore the proper return code. */
3205 op_ret
= -ERR_BUCKET_EXISTS
;
3210 int RGWDeleteBucket::verify_permission()
3212 if (!verify_bucket_permission(this, s
, rgw::IAM::s3DeleteBucket
)) {
3219 void RGWDeleteBucket::pre_exec()
3221 rgw_bucket_object_pre_exec(s
);
3224 void RGWDeleteBucket::execute()
3226 if (s
->bucket_name
.empty()) {
3231 if (!s
->bucket_exists
) {
3232 ldpp_dout(this, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
3233 op_ret
= -ERR_NO_SUCH_BUCKET
;
3236 RGWObjVersionTracker ot
;
3237 ot
.read_version
= s
->bucket_info
.ep_objv
;
3239 if (s
->system_request
) {
3240 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
3241 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
3243 ot
.read_version
.tag
= tag
;
3246 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
3248 ldpp_dout(this, 0) << "failed to parse ver param" << dendl
;
3252 ot
.read_version
.ver
= ver
;
3256 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
3258 ldpp_dout(this, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
3261 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
3266 if (!store
->svc
.zone
->is_meta_master()) {
3268 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
3271 if (op_ret
== -ENOENT
) {
3272 /* adjust error, we want to return with NoSuchBucket and not
3274 op_ret
= -ERR_NO_SUCH_BUCKET
;
3280 string prefix
, delimiter
;
3282 if (s
->prot_flags
& RGW_REST_SWIFT
) {
3284 path_args
= s
->info
.args
.get("path");
3285 if (!path_args
.empty()) {
3286 if (!delimiter
.empty() || !prefix
.empty()) {
3295 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
3301 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
3303 if (op_ret
== -ECANCELED
) {
3304 // lost a race, either with mdlog sync or another delete bucket operation.
3305 // in either case, we've already called rgw_unlink_bucket()
3311 op_ret
= rgw_unlink_bucket(store
, s
->bucket_info
.owner
, s
->bucket
.tenant
,
3312 s
->bucket
.name
, false);
3314 ldpp_dout(this, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
3320 int RGWPutObj::verify_permission()
3322 if (! copy_source
.empty()) {
3324 RGWAccessControlPolicy
cs_acl(s
->cct
);
3325 boost::optional
<Policy
> policy
;
3326 map
<string
, bufferlist
> cs_attrs
;
3327 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
3328 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
3330 rgw_obj
obj(cs_bucket
, cs_object
);
3331 store
->set_atomic(s
->obj_ctx
, obj
);
3332 store
->set_prefetch_data(s
->obj_ctx
, obj
);
3334 /* check source object permissions */
3335 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
, nullptr,
3336 policy
, cs_bucket
, cs_object
) < 0) {
3340 /* admin request overrides permission checks */
3341 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
3342 if (policy
|| ! s
->iam_user_policies
.empty()) {
3343 auto usr_policy_res
= Effect::Pass
;
3344 for (auto& user_policy
: s
->iam_user_policies
) {
3345 if (usr_policy_res
= user_policy
.eval(s
->env
, *s
->auth
.identity
,
3346 cs_object
.instance
.empty() ?
3347 rgw::IAM::s3GetObject
:
3348 rgw::IAM::s3GetObjectVersion
,
3349 rgw::IAM::ARN(obj
)); usr_policy_res
== Effect::Deny
)
3351 else if (usr_policy_res
== Effect::Allow
)
3354 rgw::IAM::Effect e
= Effect::Pass
;
3356 e
= policy
->eval(s
->env
, *s
->auth
.identity
,
3357 cs_object
.instance
.empty() ?
3358 rgw::IAM::s3GetObject
:
3359 rgw::IAM::s3GetObjectVersion
,
3360 rgw::IAM::ARN(obj
));
3362 if (e
== Effect::Deny
) {
3364 } else if (usr_policy_res
== Effect::Pass
&& e
== Effect::Pass
&&
3365 !cs_acl
.verify_permission(this, *s
->auth
.identity
, s
->perm_mask
,
3369 } else if (!cs_acl
.verify_permission(this, *s
->auth
.identity
, s
->perm_mask
,
3376 auto op_ret
= get_params();
3378 ldpp_dout(this, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3382 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
3383 rgw_add_grant_to_iam_environment(s
->env
, s
);
3385 rgw_add_to_iam_environment(s
->env
, "s3:x-amz-acl", s
->canned_acl
);
3387 if (obj_tags
!= nullptr && obj_tags
->count() > 0){
3388 auto tags
= obj_tags
->get_tags();
3389 for (const auto& kv
: tags
){
3390 rgw_add_to_iam_environment(s
->env
, "s3:RequestObjectTag/"+kv
.first
, kv
.second
);
3394 constexpr auto encrypt_attr
= "x-amz-server-side-encryption";
3395 constexpr auto s3_encrypt_attr
= "s3:x-amz-server-side-encryption";
3396 auto enc_header
= s
->info
.x_meta_map
.find(encrypt_attr
);
3397 if (enc_header
!= s
->info
.x_meta_map
.end()){
3398 rgw_add_to_iam_environment(s
->env
, s3_encrypt_attr
, enc_header
->second
);
3401 constexpr auto kms_attr
= "x-amz-server-side-encryption-aws-kms-key-id";
3402 constexpr auto s3_kms_attr
= "s3:x-amz-server-side-encryption-aws-kms-key-id";
3403 auto kms_header
= s
->info
.x_meta_map
.find(kms_attr
);
3404 if (kms_header
!= s
->info
.x_meta_map
.end()){
3405 rgw_add_to_iam_environment(s
->env
, s3_kms_attr
, kms_header
->second
);
3408 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
3410 rgw::IAM::s3PutObject
,
3411 rgw_obj(s
->bucket
, s
->object
));
3412 if (usr_policy_res
== Effect::Deny
)
3415 rgw::IAM::Effect e
= Effect::Pass
;
3416 if (s
->iam_policy
) {
3417 e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3418 rgw::IAM::s3PutObject
,
3419 rgw_obj(s
->bucket
, s
->object
));
3421 if (e
== Effect::Allow
) {
3423 } else if (e
== Effect::Deny
) {
3425 } else if (usr_policy_res
== Effect::Allow
) {
3430 if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
3438 void RGWPutObj::pre_exec()
3440 rgw_bucket_object_pre_exec(s
);
3443 class RGWPutObj_CB
: public RGWGetObj_Filter
3447 explicit RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3448 ~RGWPutObj_CB() override
{}
3450 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3451 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3455 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3458 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3460 bl_aux
.append(bl_tmp
);
3465 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3467 RGWPutObj_CB
cb(this);
3468 RGWGetObj_Filter
* filter
= &cb
;
3469 boost::optional
<RGWGetObj_Decompress
> decompress
;
3470 std::unique_ptr
<RGWGetObj_Filter
> decrypt
;
3471 RGWCompressionInfo cs_info
;
3472 map
<string
, bufferlist
> attrs
;
3473 map
<string
, bufferlist
>::iterator attr_iter
;
3477 int64_t new_ofs
, new_end
;
3482 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3483 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3485 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3486 RGWRados::Object::Read
read_op(&op_target
);
3487 read_op
.params
.obj_size
= &obj_size
;
3488 read_op
.params
.attrs
= &attrs
;
3490 ret
= read_op
.prepare();
3494 bool need_decompress
;
3495 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3497 ldpp_dout(s
, 0) << "ERROR: failed to decode compression info" << dendl
;
3501 bool partial_content
= true;
3502 if (need_decompress
)
3504 obj_size
= cs_info
.orig_size
;
3505 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3506 filter
= &*decompress
;
3509 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3510 op_ret
= this->get_decrypt_filter(&decrypt
,
3513 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3514 if (decrypt
!= nullptr) {
3515 filter
= decrypt
.get();
3521 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3525 filter
->fixup_range(new_ofs
, new_end
);
3526 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3529 ret
= filter
->flush();
3531 bl
.claim_append(bl_aux
);
3536 // special handling for compression type = "random" with multipart uploads
3537 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3538 const std::string
& compression_type
)
3540 if (compression_type
!= "random") {
3541 return Compressor::create(s
->cct
, compression_type
);
3544 bool is_multipart
{false};
3545 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3547 if (!is_multipart
) {
3548 return Compressor::create(s
->cct
, compression_type
);
3551 // use a hash of the multipart upload id so all parts use the same plugin
3552 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3553 if (alg
== Compressor::COMP_ALG_NONE
) {
3556 return Compressor::create(s
->cct
, alg
);
3559 void RGWPutObj::execute()
3561 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3562 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3563 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3564 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3566 bufferlist bl
, aclbl
, bs
;
3572 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3573 perfcounter
->inc(l_rgw_put
);
3574 // report latency on return
3575 auto put_lat
= make_scope_guard([&] {
3576 perfcounter
->tinc(l_rgw_put_lat
, s
->time_elapsed());
3580 if (s
->object
.empty()) {
3584 if (!s
->bucket_exists
) {
3585 op_ret
= -ERR_NO_SUCH_BUCKET
;
3590 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3592 ldpp_dout(this, 20) << "get_system_versioning_params() returned ret="
3597 if (supplied_md5_b64
) {
3598 need_calc_md5
= true;
3600 ldpp_dout(this, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3601 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3602 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3603 ldpp_dout(this, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3604 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3605 op_ret
= -ERR_INVALID_DIGEST
;
3609 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3610 ldpp_dout(this, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3613 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3614 we also check sizes at the end anyway */
3615 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3616 user_quota
, bucket_quota
, s
->content_length
);
3618 ldpp_dout(this, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3621 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3623 ldpp_dout(this, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3628 if (supplied_etag
) {
3629 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3630 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3633 const bool multipart
= !multipart_upload_id
.empty();
3634 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
3635 rgw_obj obj
{s
->bucket
, s
->object
};
3637 /* Handle object versioning of Swift API. */
3639 op_ret
= store
->swift_versioning_copy(obj_ctx
,
3640 s
->bucket_owner
.get_id(),
3648 // create the object processor
3649 rgw::AioThrottle
aio(store
->ctx()->_conf
->rgw_put_obj_min_window_size
);
3650 using namespace rgw::putobj
;
3651 constexpr auto max_processor_size
= std::max({sizeof(MultipartObjectProcessor
),
3652 sizeof(AtomicObjectProcessor
),
3653 sizeof(AppendObjectProcessor
)});
3654 ceph::static_ptr
<ObjectProcessor
, max_processor_size
> processor
;
3656 rgw_placement_rule
*pdest_placement
;
3659 RGWMPObj
mp(s
->object
.name
, multipart_upload_id
);
3661 multipart_upload_info upload_info
;
3662 op_ret
= get_multipart_info(store
, s
, mp
.get_meta(), nullptr, nullptr, &upload_info
);
3664 if (op_ret
!= -ENOENT
) {
3665 ldpp_dout(this, 0) << "ERROR: get_multipart_info returned " << op_ret
<< ": " << cpp_strerror(-op_ret
) << dendl
;
3666 } else {// -ENOENT: raced with upload complete/cancel, no need to spam log
3667 ldpp_dout(this, 20) << "failed to get multipart info (returned " << op_ret
<< ": " << cpp_strerror(-op_ret
) << "): probably raced with upload complete / cancel" << dendl
;
3671 pdest_placement
= &upload_info
.dest_placement
;
3672 ldpp_dout(this, 20) << "dest_placement for part=" << upload_info
.dest_placement
<< dendl
;
3673 processor
.emplace
<MultipartObjectProcessor
>(
3674 &aio
, store
, s
->bucket_info
, pdest_placement
,
3675 s
->owner
.get_id(), obj_ctx
, obj
,
3676 multipart_upload_id
, multipart_part_num
, multipart_part_str
);
3678 if (s
->bucket_info
.versioned()) {
3679 op_ret
= -ERR_INVALID_BUCKET_STATE
;
3682 pdest_placement
= &s
->dest_placement
;
3683 processor
.emplace
<AppendObjectProcessor
>(
3684 &aio
, store
, s
->bucket_info
, pdest_placement
, s
->bucket_owner
.get_id(),obj_ctx
, obj
,
3685 s
->req_id
, position
, &cur_accounted_size
);
3687 if (s
->bucket_info
.versioning_enabled()) {
3688 if (!version_id
.empty()) {
3689 obj
.key
.set_instance(version_id
);
3691 store
->gen_rand_obj_instance_name(&obj
);
3692 version_id
= obj
.key
.instance
;
3695 pdest_placement
= &s
->dest_placement
;
3696 processor
.emplace
<AtomicObjectProcessor
>(
3697 &aio
, store
, s
->bucket_info
, pdest_placement
,
3698 s
->bucket_owner
.get_id(), obj_ctx
, obj
, olh_epoch
, s
->req_id
);
3701 op_ret
= processor
->prepare();
3703 ldpp_dout(this, 20) << "processor->prepare() returned ret=" << op_ret
3708 if ((! copy_source
.empty()) && !copy_source_range
) {
3709 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3710 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
.name
);
3712 RGWObjState
*astate
;
3713 op_ret
= store
->get_obj_state(&obj_ctx
, copy_source_bucket_info
, obj
,
3714 &astate
, true, false);
3716 ldpp_dout(this, 0) << "ERROR: get copy source obj state returned with error" << op_ret
<< dendl
;
3719 if (!astate
->exists
){
3723 lst
= astate
->accounted_size
- 1;
3725 lst
= copy_source_range_lst
;
3728 fst
= copy_source_range_fst
;
3730 // no filters by default
3731 DataProcessor
*filter
= processor
.get();
3733 const auto& compression_type
= store
->svc
.zone
->get_zone_params().get_compression_type(*pdest_placement
);
3734 CompressorRef plugin
;
3735 boost::optional
<RGWPutObj_Compress
> compressor
;
3737 std::unique_ptr
<DataProcessor
> encrypt
;
3738 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3742 if (encrypt
!= nullptr) {
3744 } else if (compression_type
!= "none") {
3745 plugin
= get_compressor_plugin(s
, compression_type
);
3747 ldpp_dout(this, 1) << "Cannot load plugin for compression type "
3748 << compression_type
<< dendl
;
3750 compressor
.emplace(s
->cct
, plugin
, filter
);
3751 filter
= &*compressor
;
3754 tracepoint(rgw_op
, before_data_transfer
, s
->req_id
.c_str());
3759 if (copy_source
.empty()) {
3760 len
= get_data(data
);
3762 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3763 op_ret
= get_data(fst
, cur_lst
, data
);
3766 len
= data
.length();
3767 s
->content_length
+= len
;
3772 ldpp_dout(this, 20) << "get_data() returned ret=" << op_ret
<< dendl
;
3774 } else if (len
== 0) {
3778 if (need_calc_md5
) {
3779 hash
.Update((const unsigned char *)data
.c_str(), data
.length());
3782 /* update torrrent */
3783 torrent
.update(data
);
3785 op_ret
= filter
->process(std::move(data
), ofs
);
3787 ldpp_dout(this, 20) << "processor->process() returned ret="
3794 tracepoint(rgw_op
, after_data_transfer
, s
->req_id
.c_str(), ofs
);
3796 // flush any data in filters
3797 op_ret
= filter
->process({}, ofs
);
3802 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3803 op_ret
= -ERR_REQUEST_TIMEOUT
;
3808 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3810 op_ret
= do_aws4_auth_completion();
3815 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3816 user_quota
, bucket_quota
, s
->obj_size
);
3818 ldpp_dout(this, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3822 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3824 ldpp_dout(this, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3830 if (compressor
&& compressor
->is_compressed()) {
3832 RGWCompressionInfo cs_info
;
3833 cs_info
.compression_type
= plugin
->get_type_name();
3834 cs_info
.orig_size
= s
->obj_size
;
3835 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3836 encode(cs_info
, tmp
);
3837 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3838 ldpp_dout(this, 20) << "storing " << RGW_ATTR_COMPRESSION
3839 << " with type=" << cs_info
.compression_type
3840 << ", orig_size=" << cs_info
.orig_size
3841 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3844 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3848 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3849 op_ret
= -ERR_BAD_DIGEST
;
3853 policy
.encode(aclbl
);
3854 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3857 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3859 ldpp_dout(this, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3865 bufferlist manifest_bl
;
3866 encode(*slo_info
, manifest_bl
);
3867 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3870 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3871 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3874 bl
.append(etag
.c_str(), etag
.size());
3875 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3877 populate_with_generic_attrs(s
, attrs
);
3878 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3882 encode_delete_at_attr(delete_at
, attrs
);
3883 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3885 /* Add a custom metadata to expose the information whether an object
3886 * is an SLO or not. Appending the attribute must be performed AFTER
3887 * processing any input from user in order to prohibit overwriting. */
3889 bufferlist slo_userindicator_bl
;
3890 slo_userindicator_bl
.append("True", 4);
3891 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3894 tracepoint(rgw_op
, processor_complete_enter
, s
->req_id
.c_str());
3895 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3896 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3897 (user_data
.empty() ? nullptr : &user_data
), nullptr, nullptr);
3898 tracepoint(rgw_op
, processor_complete_exit
, s
->req_id
.c_str());
3900 /* produce torrent */
3901 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3903 torrent
.init(s
, store
);
3904 torrent
.set_create_date(mtime
);
3905 op_ret
= torrent
.complete();
3908 ldpp_dout(this, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3914 int RGWPostObj::verify_permission()
3919 void RGWPostObj::pre_exec()
3921 rgw_bucket_object_pre_exec(s
);
3924 void RGWPostObj::execute()
3926 boost::optional
<RGWPutObj_Compress
> compressor
;
3927 CompressorRef plugin
;
3928 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3930 /* Read in the data from the POST form. */
3931 op_ret
= get_params();
3936 op_ret
= verify_params();
3941 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
3942 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
3944 rgw::IAM::s3PutObject
,
3945 rgw_obj(s
->bucket
, s
->object
));
3946 if (usr_policy_res
== Effect::Deny
) {
3951 rgw::IAM::Effect e
= Effect::Pass
;
3952 if (s
->iam_policy
) {
3953 e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3954 rgw::IAM::s3PutObject
,
3955 rgw_obj(s
->bucket
, s
->object
));
3957 if (e
== Effect::Deny
) {
3960 } else if (usr_policy_res
== Effect::Pass
&& e
== Effect::Pass
&& !verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
3964 } else if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
3969 /* Start iteration over data fields. It's necessary as Swift's FormPost
3970 * is capable to handle multiple files in single form. */
3972 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3973 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3975 ceph::buffer::list bl
, aclbl
;
3978 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3987 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3992 if (supplied_md5_b64
) {
3993 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3994 ldpp_dout(this, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3995 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3996 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3997 ldpp_dout(this, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3998 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3999 op_ret
= -ERR_INVALID_DIGEST
;
4003 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
4004 ldpp_dout(this, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
4007 rgw_obj
obj(s
->bucket
, get_current_filename());
4008 if (s
->bucket_info
.versioning_enabled()) {
4009 store
->gen_rand_obj_instance_name(&obj
);
4012 rgw::AioThrottle
aio(s
->cct
->_conf
->rgw_put_obj_min_window_size
);
4014 using namespace rgw::putobj
;
4015 AtomicObjectProcessor
processor(&aio
, store
, s
->bucket_info
,
4017 s
->bucket_owner
.get_id(),
4018 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
4020 op_ret
= processor
.prepare();
4025 /* No filters by default. */
4026 DataProcessor
*filter
= &processor
;
4028 std::unique_ptr
<DataProcessor
> encrypt
;
4029 op_ret
= get_encrypt_filter(&encrypt
, filter
);
4033 if (encrypt
!= nullptr) {
4034 filter
= encrypt
.get();
4036 const auto& compression_type
= store
->svc
.zone
->get_zone_params().get_compression_type(
4038 if (compression_type
!= "none") {
4039 plugin
= Compressor::create(s
->cct
, compression_type
);
4041 ldpp_dout(this, 1) << "Cannot load plugin for compression type "
4042 << compression_type
<< dendl
;
4044 compressor
.emplace(s
->cct
, plugin
, filter
);
4045 filter
= &*compressor
;
4052 ceph::bufferlist data
;
4053 len
= get_data(data
, again
);
4064 hash
.Update((const unsigned char *)data
.c_str(), data
.length());
4065 op_ret
= filter
->process(std::move(data
), ofs
);
4069 if (ofs
> max_len
) {
4070 op_ret
= -ERR_TOO_LARGE
;
4076 op_ret
= filter
->process({}, ofs
);
4081 if (len
< min_len
) {
4082 op_ret
= -ERR_TOO_SMALL
;
4089 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
4090 user_quota
, bucket_quota
, s
->obj_size
);
4095 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
4101 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
4105 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
4106 op_ret
= -ERR_BAD_DIGEST
;
4110 bl
.append(etag
.c_str(), etag
.size());
4111 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
4113 policy
.encode(aclbl
);
4114 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4116 const std::string content_type
= get_current_content_type();
4117 if (! content_type
.empty()) {
4118 ceph::bufferlist ct_bl
;
4119 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
4120 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
4123 if (compressor
&& compressor
->is_compressed()) {
4124 ceph::bufferlist tmp
;
4125 RGWCompressionInfo cs_info
;
4126 cs_info
.compression_type
= plugin
->get_type_name();
4127 cs_info
.orig_size
= s
->obj_size
;
4128 cs_info
.blocks
= move(compressor
->get_compression_blocks());
4129 encode(cs_info
, tmp
);
4130 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
4133 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(), attrs
,
4134 (delete_at
? *delete_at
: real_time()),
4135 nullptr, nullptr, nullptr, nullptr, nullptr);
4139 } while (is_next_file_to_upload());
4143 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
4144 const set
<string
>& rmattr_names
,
4145 map
<int, string
>& temp_url_keys
)
4147 map
<string
, bufferlist
>::iterator iter
;
4149 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
4150 if (iter
!= add_attrs
.end()) {
4151 temp_url_keys
[0] = iter
->second
.c_str();
4152 add_attrs
.erase(iter
);
4155 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
4156 if (iter
!= add_attrs
.end()) {
4157 temp_url_keys
[1] = iter
->second
.c_str();
4158 add_attrs
.erase(iter
);
4161 for (const string
& name
: rmattr_names
) {
4162 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
4163 temp_url_keys
[0] = string();
4165 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
4166 temp_url_keys
[1] = string();
4171 int RGWPutMetadataAccount::init_processing()
4173 /* First, go to the base class. At the time of writing the method was
4174 * responsible only for initializing the quota. This isn't necessary
4175 * here as we are touching metadata only. I'm putting this call only
4176 * for the future. */
4177 op_ret
= RGWOp::init_processing();
4182 op_ret
= get_params();
4187 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
4195 policy
.encode(acl_bl
);
4196 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
4199 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
4203 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
4204 populate_with_generic_attrs(s
, attrs
);
4206 /* Try extract the TempURL-related stuff now to allow verify_permission
4207 * evaluate whether we need FULL_CONTROL or not. */
4208 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
4210 /* The same with quota except a client needs to be reseller admin. */
4211 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
4212 &new_quota_extracted
);
4220 int RGWPutMetadataAccount::verify_permission()
4222 if (s
->auth
.identity
->is_anonymous()) {
4226 if (!verify_user_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
4230 /* Altering TempURL keys requires FULL_CONTROL. */
4231 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
4235 /* We are failing this intensionally to allow system user/reseller admin
4236 * override in rgw_process.cc. This is the way to specify a given RGWOp
4237 * expect extra privileges. */
4238 if (new_quota_extracted
) {
4245 void RGWPutMetadataAccount::execute()
4247 /* Params have been extracted earlier. See init_processing(). */
4248 RGWUserInfo new_uinfo
;
4249 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
4255 /* Handle the TempURL-related stuff. */
4256 if (!temp_url_keys
.empty()) {
4257 for (auto& pair
: temp_url_keys
) {
4258 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
4262 /* Handle the quota extracted at the verify_permission step. */
4263 if (new_quota_extracted
) {
4264 new_uinfo
.user_quota
= std::move(new_quota
);
4267 /* We are passing here the current (old) user info to allow the function
4268 * optimize-out some operations. */
4269 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
4270 &acct_op_tracker
, real_time(), false, &attrs
);
4273 int RGWPutMetadataBucket::verify_permission()
4275 if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
4282 void RGWPutMetadataBucket::pre_exec()
4284 rgw_bucket_object_pre_exec(s
);
4287 void RGWPutMetadataBucket::execute()
4289 op_ret
= get_params();
4294 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
4299 if (!placement_rule
.empty() &&
4300 placement_rule
!= s
->bucket_info
.placement_rule
) {
4305 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
4306 /* Encode special metadata first as we're using std::map::emplace under
4307 * the hood. This method will add the new items only if the map doesn't
4308 * contain such keys yet. */
4310 if (s
->dialect
.compare("swift") == 0) {
4312 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
4313 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
4314 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
4315 policy
= *new_policy
;
4319 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
4324 cors_config
.encode(bl
);
4325 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
4328 /* It's supposed that following functions WILL NOT change any
4329 * special attributes (like RGW_ATTR_ACL) if they are already
4330 * present in attrs. */
4331 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
4332 populate_with_generic_attrs(s
, attrs
);
4334 /* According to the Swift's behaviour and its container_quota
4335 * WSGI middleware implementation: anyone with write permissions
4336 * is able to set the bucket quota. This stays in contrast to
4337 * account quotas that can be set only by clients holding
4338 * reseller admin privileges. */
4339 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
4344 if (swift_ver_location
) {
4345 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
4346 s
->bucket_info
.swift_versioning
= (!swift_ver_location
->empty());
4349 /* Web site of Swift API. */
4350 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
4351 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
4353 /* Setting attributes also stores the provided bucket info. Due
4354 * to this fact, the new quota settings can be serialized with
4356 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
4357 &s
->bucket_info
.objv_tracker
);
4362 int RGWPutMetadataObject::verify_permission()
4364 // This looks to be something specific to Swift. We could add
4365 // operations like swift:PutMetadataObject to the Policy Engine.
4366 if (!verify_object_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
4373 void RGWPutMetadataObject::pre_exec()
4375 rgw_bucket_object_pre_exec(s
);
4378 void RGWPutMetadataObject::execute()
4380 rgw_obj
obj(s
->bucket
, s
->object
);
4381 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4383 store
->set_atomic(s
->obj_ctx
, obj
);
4385 op_ret
= get_params();
4390 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4395 /* check if obj exists, read orig attrs */
4396 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4401 /* Check whether the object has expired. Swift API documentation
4402 * stands that we should return 404 Not Found in such case. */
4403 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4408 /* Filter currently existing attributes. */
4409 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4410 populate_with_generic_attrs(s
, attrs
);
4411 encode_delete_at_attr(delete_at
, attrs
);
4414 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4416 ldpp_dout(this, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4421 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4424 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4426 RGWSLOInfo slo_info
;
4427 auto bliter
= bl
.cbegin();
4429 decode(slo_info
, bliter
);
4430 } catch (buffer::error
& err
) {
4431 ldpp_dout(this, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4436 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4437 new RGWBulkDelete::Deleter(this, store
, s
));
4438 } catch (const std::bad_alloc
&) {
4442 list
<RGWBulkDelete::acct_path_t
> items
;
4443 for (const auto& iter
: slo_info
.entries
) {
4444 const string
& path_str
= iter
.path
;
4446 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4447 if (boost::string_view::npos
== sep_pos
) {
4451 RGWBulkDelete::acct_path_t path
;
4453 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4454 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4456 items
.push_back(path
);
4459 /* Request removal of the manifest object itself. */
4460 RGWBulkDelete::acct_path_t path
;
4461 path
.bucket_name
= s
->bucket_name
;
4462 path
.obj_key
= s
->object
;
4463 items
.push_back(path
);
4465 int ret
= deleter
->delete_chunk(items
);
4473 int RGWDeleteObj::verify_permission()
4475 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
4476 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
4478 s
->object
.instance
.empty() ?
4479 rgw::IAM::s3DeleteObject
:
4480 rgw::IAM::s3DeleteObjectVersion
,
4481 ARN(s
->bucket
, s
->object
.name
));
4482 if (usr_policy_res
== Effect::Deny
) {
4486 rgw::IAM::Effect r
= Effect::Pass
;
4487 if (s
->iam_policy
) {
4488 r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4489 s
->object
.instance
.empty() ?
4490 rgw::IAM::s3DeleteObject
:
4491 rgw::IAM::s3DeleteObjectVersion
,
4492 ARN(s
->bucket
, s
->object
.name
));
4494 if (r
== Effect::Allow
)
4496 else if (r
== Effect::Deny
)
4498 else if (usr_policy_res
== Effect::Allow
)
4502 if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
4506 if (s
->bucket_info
.mfa_enabled() &&
4507 !s
->object
.instance
.empty() &&
4509 ldpp_dout(this, 5) << "NOTICE: object delete request with a versioned object, mfa auth not provided" << dendl
;
4510 return -ERR_MFA_REQUIRED
;
4516 void RGWDeleteObj::pre_exec()
4518 rgw_bucket_object_pre_exec(s
);
4521 void RGWDeleteObj::execute()
4523 if (!s
->bucket_exists
) {
4524 op_ret
= -ERR_NO_SUCH_BUCKET
;
4528 op_ret
= get_params();
4533 rgw_obj
obj(s
->bucket
, s
->object
);
4534 map
<string
, bufferlist
> attrs
;
4537 if (!s
->object
.empty()) {
4538 if (need_object_expiration() || multipart_delete
) {
4539 /* check if obj exists, read orig attrs */
4540 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4546 if (multipart_delete
) {
4547 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4549 if (slo_attr
!= attrs
.end()) {
4550 op_ret
= handle_slo_manifest(slo_attr
->second
);
4552 ldpp_dout(this, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4555 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4561 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4562 obj_ctx
->set_atomic(obj
);
4564 bool ver_restored
= false;
4565 op_ret
= store
->swift_versioning_restore(*s
->sysobj_ctx
, *obj_ctx
, s
->bucket_owner
.get_id(),
4566 s
->bucket_info
, obj
, ver_restored
);
4571 if (!ver_restored
) {
4572 /* Swift's versioning mechanism hasn't found any previous version of
4573 * the object that could be restored. This means we should proceed
4574 * with the regular delete path. */
4575 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4576 RGWRados::Object::Delete
del_op(&del_target
);
4578 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4579 &del_op
.params
.marker_version_id
);
4584 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4585 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4586 del_op
.params
.obj_owner
= s
->owner
;
4587 del_op
.params
.unmod_since
= unmod_since
;
4588 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4590 op_ret
= del_op
.delete_obj();
4592 delete_marker
= del_op
.result
.delete_marker
;
4593 version_id
= del_op
.result
.version_id
;
4596 /* Check whether the object has expired. Swift API documentation
4597 * stands that we should return 404 Not Found in such case. */
4598 if (need_object_expiration() && object_is_expired(attrs
)) {
4604 if (op_ret
== -ECANCELED
) {
4607 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4615 bool RGWCopyObj::parse_copy_location(const boost::string_view
& url_src
,
4616 string
& bucket_name
,
4619 boost::string_view name_str
;
4620 boost::string_view params_str
;
4622 // search for ? before url-decoding so we don't accidentally match %3F
4623 size_t pos
= url_src
.find('?');
4624 if (pos
== string::npos
) {
4627 name_str
= url_src
.substr(0, pos
);
4628 params_str
= url_src
.substr(pos
+ 1);
4631 boost::string_view dec_src
{name_str
};
4632 if (dec_src
[0] == '/')
4633 dec_src
.remove_prefix(1);
4635 pos
= dec_src
.find('/');
4636 if (pos
== string::npos
)
4639 bucket_name
= url_decode(dec_src
.substr(0, pos
));
4640 key
.name
= url_decode(dec_src
.substr(pos
+ 1));
4642 if (key
.name
.empty()) {
4646 if (! params_str
.empty()) {
4648 args
.set(params_str
.to_string());
4651 key
.instance
= args
.get("versionId", NULL
);
4657 int RGWCopyObj::verify_permission()
4659 RGWAccessControlPolicy
src_acl(s
->cct
);
4660 boost::optional
<Policy
> src_policy
;
4661 op_ret
= get_params();
4665 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4669 map
<string
, bufferlist
> src_attrs
;
4671 if (s
->bucket_instance_id
.empty()) {
4672 op_ret
= store
->get_bucket_info(*s
->sysobj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4674 /* will only happen in intra region sync where the source and dest bucket is the same */
4675 op_ret
= store
->get_bucket_instance_info(*s
->sysobj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4678 if (op_ret
== -ENOENT
) {
4679 op_ret
= -ERR_NO_SUCH_BUCKET
;
4684 src_bucket
= src_bucket_info
.bucket
;
4686 /* get buckets info (source and dest) */
4687 if (s
->local_source
&& source_zone
.empty()) {
4688 rgw_obj
src_obj(src_bucket
, src_object
);
4689 store
->set_atomic(s
->obj_ctx
, src_obj
);
4690 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4692 rgw_placement_rule src_placement
;
4694 /* check source object permissions */
4695 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
, &src_placement
.storage_class
,
4696 src_policy
, src_bucket
, src_object
);
4701 /* follow up on previous checks that required reading source object head */
4702 if (need_to_check_storage_class
) {
4703 src_placement
.inherit_from(src_bucket_info
.placement_rule
);
4705 op_ret
= check_storage_class(src_placement
);
4711 /* admin request overrides permission checks */
4712 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4714 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4715 src_object
.instance
.empty() ?
4716 rgw::IAM::s3GetObject
:
4717 rgw::IAM::s3GetObjectVersion
,
4719 if (e
== Effect::Deny
) {
4721 } else if (e
== Effect::Pass
&&
4722 !src_acl
.verify_permission(this, *s
->auth
.identity
, s
->perm_mask
,
4726 } else if (!src_acl
.verify_permission(this, *s
->auth
.identity
,
4734 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4735 map
<string
, bufferlist
> dest_attrs
;
4737 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4738 or intra region sync */
4739 dest_bucket_info
= src_bucket_info
;
4740 dest_attrs
= src_attrs
;
4742 op_ret
= store
->get_bucket_info(*s
->sysobj_ctx
, dest_tenant_name
, dest_bucket_name
,
4743 dest_bucket_info
, nullptr, &dest_attrs
);
4745 if (op_ret
== -ENOENT
) {
4746 op_ret
= -ERR_NO_SUCH_BUCKET
;
4752 dest_bucket
= dest_bucket_info
.bucket
;
4754 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4755 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4757 /* check dest bucket permissions */
4758 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4759 &dest_bucket_policy
, dest_bucket
);
4763 auto dest_iam_policy
= get_iam_policy_from_attr(s
->cct
, store
, dest_attrs
, dest_bucket
.tenant
);
4764 /* admin request overrides permission checks */
4765 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id())){
4766 if (dest_iam_policy
!= boost::none
) {
4767 rgw_add_to_iam_environment(s
->env
, "s3:x-amz-copy-source", copy_source
);
4769 rgw_add_to_iam_environment(s
->env
, "s3:x-amz-metadata-directive",
4772 auto e
= dest_iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4773 rgw::IAM::s3PutObject
,
4775 if (e
== Effect::Deny
) {
4777 } else if (e
== Effect::Pass
&&
4778 ! dest_bucket_policy
.verify_permission(this,
4785 } else if (! dest_bucket_policy
.verify_permission(this, *s
->auth
.identity
, s
->perm_mask
,
4790 op_ret
= init_dest_policy();
4799 int RGWCopyObj::init_common()
4802 if (parse_time(if_mod
, &mod_time
) < 0) {
4806 mod_ptr
= &mod_time
;
4810 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4814 unmod_ptr
= &unmod_time
;
4818 dest_policy
.encode(aclbl
);
4819 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4821 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4825 populate_with_generic_attrs(s
, attrs
);
4830 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4832 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4833 op
->progress_cb(ofs
);
4836 void RGWCopyObj::progress_cb(off_t ofs
)
4838 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4841 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4844 send_partial_response(ofs
);
4849 void RGWCopyObj::pre_exec()
4851 rgw_bucket_object_pre_exec(s
);
4854 void RGWCopyObj::execute()
4856 if (init_common() < 0)
4859 rgw_obj
src_obj(src_bucket
, src_object
);
4860 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4862 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4863 if ( ! version_id
.empty()) {
4864 dst_obj
.key
.set_instance(version_id
);
4865 } else if (dest_bucket_info
.versioning_enabled()) {
4866 store
->gen_rand_obj_instance_name(&dst_obj
);
4869 obj_ctx
.set_atomic(src_obj
);
4870 obj_ctx
.set_atomic(dst_obj
);
4872 encode_delete_at_attr(delete_at
, attrs
);
4874 bool high_precision_time
= (s
->system_request
);
4876 /* Handle object versioning of Swift API. In case of copying to remote this
4877 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4878 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4879 dest_bucket_info
.owner
,
4886 op_ret
= store
->copy_obj(obj_ctx
,
4899 high_precision_time
,
4904 attrs
, RGWObjCategory::Main
,
4906 (delete_at
? *delete_at
: real_time()),
4907 (version_id
.empty() ? NULL
: &version_id
),
4908 &s
->req_id
, /* use req_id as tag */
4910 copy_obj_progress_cb
, (void *)this
4914 int RGWGetACLs::verify_permission()
4917 if (!s
->object
.empty()) {
4918 auto iam_action
= s
->object
.instance
.empty() ?
4919 rgw::IAM::s3GetObjectAcl
:
4920 rgw::IAM::s3GetObjectVersionAcl
;
4922 if (s
->iam_policy
&& s
->iam_policy
->has_partial_conditional(S3_EXISTING_OBJTAG
)){
4923 rgw_obj obj
= rgw_obj(s
->bucket
, s
->object
);
4924 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
4926 if (! s
->iam_user_policies
.empty()) {
4927 for (auto& user_policy
: s
->iam_user_policies
) {
4928 if (user_policy
.has_partial_conditional(S3_EXISTING_OBJTAG
)) {
4929 rgw_obj obj
= rgw_obj(s
->bucket
, s
->object
);
4930 rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
4934 perm
= verify_object_permission(this, s
, iam_action
);
4936 if (!s
->bucket_exists
) {
4937 return -ERR_NO_SUCH_BUCKET
;
4939 perm
= verify_bucket_permission(this, s
, rgw::IAM::s3GetBucketAcl
);
4947 void RGWGetACLs::pre_exec()
4949 rgw_bucket_object_pre_exec(s
);
4952 void RGWGetACLs::execute()
4955 RGWAccessControlPolicy
* const acl
= \
4956 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4957 RGWAccessControlPolicy_S3
* const s3policy
= \
4958 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4959 s3policy
->to_xml(ss
);
4965 int RGWPutACLs::verify_permission()
4969 rgw_add_to_iam_environment(s
->env
, "s3:x-amz-acl", s
->canned_acl
);
4971 rgw_add_grant_to_iam_environment(s
->env
, s
);
4972 if (!s
->object
.empty()) {
4973 auto iam_action
= s
->object
.instance
.empty() ? rgw::IAM::s3PutObjectAcl
: rgw::IAM::s3PutObjectVersionAcl
;
4974 auto obj
= rgw_obj(s
->bucket
, s
->object
);
4975 op_ret
= rgw_iam_add_existing_objtags(store
, s
, obj
, iam_action
);
4976 perm
= verify_object_permission(this, s
, iam_action
);
4978 perm
= verify_bucket_permission(this, s
, rgw::IAM::s3PutBucketAcl
);
4986 int RGWGetLC::verify_permission()
4989 perm
= verify_bucket_permission(this, s
, rgw::IAM::s3GetLifecycleConfiguration
);
4996 int RGWPutLC::verify_permission()
4999 perm
= verify_bucket_permission(this, s
, rgw::IAM::s3PutLifecycleConfiguration
);
5006 int RGWDeleteLC::verify_permission()
5009 perm
= verify_bucket_permission(this, s
, rgw::IAM::s3PutLifecycleConfiguration
);
5016 void RGWPutACLs::pre_exec()
5018 rgw_bucket_object_pre_exec(s
);
5021 void RGWGetLC::pre_exec()
5023 rgw_bucket_object_pre_exec(s
);
5026 void RGWPutLC::pre_exec()
5028 rgw_bucket_object_pre_exec(s
);
5031 void RGWDeleteLC::pre_exec()
5033 rgw_bucket_object_pre_exec(s
);
5036 void RGWPutACLs::execute()
5040 RGWAccessControlPolicy_S3
*policy
= NULL
;
5041 RGWACLXMLParser_S3
parser(s
->cct
);
5042 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
5046 op_ret
= 0; /* XXX redundant? */
5048 if (!parser
.init()) {
5054 RGWAccessControlPolicy
* const existing_policy
= \
5055 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
5057 owner
= existing_policy
->get_owner();
5059 op_ret
= get_params();
5061 if (op_ret
== -ERANGE
) {
5062 ldpp_dout(this, 4) << "The size of request xml data is larger than the max limitation, data size = "
5063 << s
->length
<< dendl
;
5064 op_ret
= -ERR_MALFORMED_XML
;
5065 s
->err
.message
= "The XML you provided was larger than the maximum " +
5066 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
5072 char* buf
= data
.c_str();
5073 ldpp_dout(this, 15) << "read len=" << data
.length() << " data=" << (buf
? buf
: "") << dendl
;
5075 if (!s
->canned_acl
.empty() && data
.length() > 0) {
5080 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
5081 op_ret
= get_policy_from_state(store
, s
, ss
);
5086 data
.append(ss
.str());
5089 if (!parser
.parse(data
.c_str(), data
.length(), 1)) {
5093 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
5099 const RGWAccessControlList
& req_acl
= policy
->get_acl();
5100 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
5101 #define ACL_GRANTS_MAX_NUM 100
5102 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
5104 max_num
= ACL_GRANTS_MAX_NUM
;
5107 int grants_num
= req_grant_map
.size();
5108 if (grants_num
> max_num
) {
5109 ldpp_dout(this, 4) << "An acl can have up to " << max_num
5110 << " grants, request acl grants num: " << grants_num
<< dendl
;
5111 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
5112 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
5113 + std::to_string(max_num
)
5114 + " grants allowed in an acl.";
5118 // forward bucket acl requests to meta master zone
5119 if (s
->object
.empty() && !store
->svc
.zone
->is_meta_master()) {
5121 // include acl data unless it was generated from a canned_acl
5122 if (s
->canned_acl
.empty()) {
5123 in_data
.append(data
);
5125 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
5127 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5132 if (s
->cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 15>()) {
5133 ldpp_dout(this, 15) << "Old AccessControlPolicy";
5134 policy
->to_xml(*_dout
);
5138 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
5142 if (s
->cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 15>()) {
5143 ldpp_dout(this, 15) << "New AccessControlPolicy:";
5144 new_policy
.to_xml(*_dout
);
5148 new_policy
.encode(bl
);
5149 map
<string
, bufferlist
> attrs
;
5151 if (!s
->object
.empty()) {
5152 obj
= rgw_obj(s
->bucket
, s
->object
);
5153 store
->set_atomic(s
->obj_ctx
, obj
);
5154 //if instance is empty, we should modify the latest object
5155 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
5157 attrs
= s
->bucket_attrs
;
5158 attrs
[RGW_ATTR_ACL
] = bl
;
5159 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5161 if (op_ret
== -ECANCELED
) {
5162 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
5166 void RGWPutLC::execute()
5170 RGWLifecycleConfiguration_S3
config(s
->cct
);
5171 RGWXMLParser parser
;
5172 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
5174 content_md5
= s
->info
.env
->get("HTTP_CONTENT_MD5");
5175 if (content_md5
== nullptr) {
5176 op_ret
= -ERR_INVALID_REQUEST
;
5177 s
->err
.message
= "Missing required header for this request: Content-MD5";
5178 ldpp_dout(this, 5) << s
->err
.message
<< dendl
;
5182 std::string content_md5_bin
;
5184 content_md5_bin
= rgw::from_base64(boost::string_view(content_md5
));
5186 s
->err
.message
= "Request header Content-MD5 contains character "
5187 "that is not base64 encoded.";
5188 ldpp_dout(this, 5) << s
->err
.message
<< dendl
;
5189 op_ret
= -ERR_BAD_DIGEST
;
5193 if (!parser
.init()) {
5198 op_ret
= get_params();
5202 char* buf
= data
.c_str();
5203 ldpp_dout(this, 15) << "read len=" << data
.length() << " data=" << (buf
? buf
: "") << dendl
;
5206 unsigned char data_hash_res
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5207 data_hash
.Update(reinterpret_cast<const unsigned char*>(buf
), data
.length());
5208 data_hash
.Final(data_hash_res
);
5210 if (memcmp(data_hash_res
, content_md5_bin
.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE
) != 0) {
5211 op_ret
= -ERR_BAD_DIGEST
;
5212 s
->err
.message
= "The Content-MD5 you specified did not match what we received.";
5213 ldpp_dout(this, 5) << s
->err
.message
5214 << " Specified content md5: " << content_md5
5215 << ", calculated content md5: " << data_hash_res
5220 if (!parser
.parse(buf
, data
.length(), 1)) {
5221 op_ret
= -ERR_MALFORMED_XML
;
5226 RGWXMLDecoder::decode_xml("LifecycleConfiguration", config
, &parser
);
5227 } catch (RGWXMLDecoder::err
& err
) {
5228 ldpp_dout(this, 5) << "Bad lifecycle configuration: " << err
<< dendl
;
5229 op_ret
= -ERR_MALFORMED_XML
;
5233 op_ret
= config
.rebuild(store
, new_config
);
5237 if (s
->cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 15>()) {
5239 new_config
.dump_xml(&xf
);
5242 ldpp_dout(this, 15) << "New LifecycleConfiguration:" << ss
.str() << dendl
;
5245 if (!store
->svc
.zone
->is_meta_master()) {
5246 op_ret
= forward_request_to_master(s
, nullptr, store
, data
, nullptr);
5248 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5253 op_ret
= store
->get_lc()->set_bucket_config(s
->bucket_info
, s
->bucket_attrs
, &new_config
);
5260 void RGWDeleteLC::execute()
5262 if (!store
->svc
.zone
->is_meta_master()) {
5264 op_ret
= forward_request_to_master(s
, nullptr, store
, data
, nullptr);
5266 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5270 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
5271 attrs
.erase(RGW_ATTR_LC
);
5272 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
5273 &s
->bucket_info
.objv_tracker
);
5275 ldpp_dout(this, 0) << "RGWLC::RGWDeleteLC() failed to set attrs on bucket="
5276 << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
5280 op_ret
= store
->get_lc()->remove_bucket_config(s
->bucket_info
, s
->bucket_attrs
);
5287 int RGWGetCORS::verify_permission()
5289 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketCORS
);
5292 void RGWGetCORS::execute()
5294 op_ret
= read_bucket_cors();
5299 ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl
;
5300 op_ret
= -ERR_NO_CORS_FOUND
;
5305 int RGWPutCORS::verify_permission()
5307 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5310 void RGWPutCORS::execute()
5314 op_ret
= get_params();
5318 if (!store
->svc
.zone
->is_meta_master()) {
5319 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
5321 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5326 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5327 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
5328 attrs
[RGW_ATTR_CORS
] = cors_bl
;
5329 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5333 int RGWDeleteCORS::verify_permission()
5335 // No separate delete permission
5336 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5339 void RGWDeleteCORS::execute()
5341 if (!store
->svc
.zone
->is_meta_master()) {
5343 op_ret
= forward_request_to_master(s
, nullptr, store
, data
, nullptr);
5345 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5350 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5351 op_ret
= read_bucket_cors();
5356 ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl
;
5361 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
5362 attrs
.erase(RGW_ATTR_CORS
);
5363 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
5364 &s
->bucket_info
.objv_tracker
);
5366 ldpp_dout(this, 0) << "RGWLC::RGWDeleteCORS() failed to set attrs on bucket=" << s
->bucket
.name
5367 << " returned err=" << op_ret
<< dendl
;
5373 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
5374 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
5377 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
5378 rule
= cc
->host_name_rule(origin
);
5380 ldpp_dout(this, 10) << "There is no cors rule present for " << origin
<< dendl
;
5384 if (!validate_cors_rule_method(rule
, req_meth
)) {
5388 if (!validate_cors_rule_header(rule
, req_hdrs
)) {
5395 void RGWOptionsCORS::execute()
5397 op_ret
= read_bucket_cors();
5401 origin
= s
->info
.env
->get("HTTP_ORIGIN");
5403 ldpp_dout(this, 0) << "Missing mandatory Origin header" << dendl
;
5407 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
5409 ldpp_dout(this, 0) << "Missing mandatory Access-control-request-method header" << dendl
;
5414 ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl
;
5418 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5419 op_ret
= validate_cors_request(&bucket_cors
);
5421 origin
= req_meth
= NULL
;
5427 int RGWGetRequestPayment::verify_permission()
5429 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketRequestPayment
);
5432 void RGWGetRequestPayment::pre_exec()
5434 rgw_bucket_object_pre_exec(s
);
5437 void RGWGetRequestPayment::execute()
5439 requester_pays
= s
->bucket_info
.requester_pays
;
5442 int RGWSetRequestPayment::verify_permission()
5444 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketRequestPayment
);
5447 void RGWSetRequestPayment::pre_exec()
5449 rgw_bucket_object_pre_exec(s
);
5452 void RGWSetRequestPayment::execute()
5455 if (!store
->svc
.zone
->is_meta_master()) {
5456 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, nullptr);
5458 ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5463 op_ret
= get_params();
5468 s
->bucket_info
.requester_pays
= requester_pays
;
5469 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5472 ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5473 << " returned err=" << op_ret
<< dendl
;
5478 int RGWInitMultipart::verify_permission()
5480 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
5481 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
5483 rgw::IAM::s3PutObject
,
5484 rgw_obj(s
->bucket
, s
->object
));
5485 if (usr_policy_res
== Effect::Deny
) {
5489 rgw::IAM::Effect e
= Effect::Pass
;
5490 if (s
->iam_policy
) {
5491 e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5492 rgw::IAM::s3PutObject
,
5493 rgw_obj(s
->bucket
, s
->object
));
5495 if (e
== Effect::Allow
) {
5497 } else if (e
== Effect::Deny
) {
5499 } else if (usr_policy_res
== Effect::Allow
) {
5504 if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
5511 void RGWInitMultipart::pre_exec()
5513 rgw_bucket_object_pre_exec(s
);
5516 void RGWInitMultipart::execute()
5519 map
<string
, bufferlist
> attrs
;
5522 if (get_params() < 0)
5525 if (s
->object
.empty())
5528 policy
.encode(aclbl
);
5529 attrs
[RGW_ATTR_ACL
] = aclbl
;
5531 populate_with_generic_attrs(s
, attrs
);
5533 /* select encryption mode */
5534 op_ret
= prepare_encryption(attrs
);
5538 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5545 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5546 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5547 upload_id
.append(buf
);
5549 string tmp_obj_name
;
5550 RGWMPObj
mp(s
->object
.name
, upload_id
);
5551 tmp_obj_name
= mp
.get_meta();
5553 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5554 // the meta object will be indexed with 0 size, we c
5555 obj
.set_in_extra_data(true);
5556 obj
.index_hash_source
= s
->object
.name
;
5558 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5559 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5561 RGWRados::Object::Write
obj_op(&op_target
);
5563 obj_op
.meta
.owner
= s
->owner
.get_id();
5564 obj_op
.meta
.category
= RGWObjCategory::MultiMeta
;
5565 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5567 multipart_upload_info upload_info
;
5568 upload_info
.dest_placement
= s
->dest_placement
;
5571 encode(upload_info
, bl
);
5572 obj_op
.meta
.data
= &bl
;
5574 op_ret
= obj_op
.write_meta(bl
.length(), 0, attrs
);
5575 } while (op_ret
== -EEXIST
);
5578 int RGWCompleteMultipart::verify_permission()
5580 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
5581 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
5583 rgw::IAM::s3PutObject
,
5584 rgw_obj(s
->bucket
, s
->object
));
5585 if (usr_policy_res
== Effect::Deny
) {
5589 rgw::IAM::Effect e
= Effect::Pass
;
5590 if (s
->iam_policy
) {
5591 e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5592 rgw::IAM::s3PutObject
,
5593 rgw_obj(s
->bucket
, s
->object
));
5595 if (e
== Effect::Allow
) {
5597 } else if (e
== Effect::Deny
) {
5599 } else if (usr_policy_res
== Effect::Allow
) {
5604 if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
5611 void RGWCompleteMultipart::pre_exec()
5613 rgw_bucket_object_pre_exec(s
);
5616 void RGWCompleteMultipart::execute()
5618 RGWMultiCompleteUpload
*parts
;
5619 map
<int, string
>::iterator iter
;
5620 RGWMultiXMLParser parser
;
5622 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5623 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5624 map
<string
, bufferlist
> attrs
;
5627 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5628 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5633 RGWObjManifest manifest
;
5634 uint64_t olh_epoch
= 0;
5636 op_ret
= get_params();
5639 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5644 if (!data
.length()) {
5645 op_ret
= -ERR_MALFORMED_XML
;
5649 if (!parser
.init()) {
5654 if (!parser
.parse(data
.c_str(), data
.length(), 1)) {
5655 op_ret
= -ERR_MALFORMED_XML
;
5659 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5660 if (!parts
|| parts
->parts
.empty()) {
5661 op_ret
= -ERR_MALFORMED_XML
;
5665 if ((int)parts
->parts
.size() >
5666 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5671 mp
.init(s
->object
.name
, upload_id
);
5672 meta_oid
= mp
.get_meta();
5674 int total_parts
= 0;
5675 int handled_parts
= 0;
5676 int max_parts
= 1000;
5679 RGWCompressionInfo cs_info
;
5680 bool compressed
= false;
5681 uint64_t accounted_size
= 0;
5683 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5685 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5687 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5689 iter
= parts
->parts
.begin();
5691 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5692 meta_obj
.set_in_extra_data(true);
5693 meta_obj
.index_hash_source
= s
->object
.name
;
5695 /*take a cls lock on meta_obj to prevent racing completions (or retries)
5696 from deleting the parts*/
5698 rgw_raw_obj raw_obj
;
5699 int max_lock_secs_mp
=
5700 s
->cct
->_conf
.get_val
<int64_t>("rgw_mp_lock_max_time");
5701 utime_t
dur(max_lock_secs_mp
, 0);
5703 store
->obj_to_raw((s
->bucket_info
).placement_rule
, meta_obj
, &raw_obj
);
5704 store
->get_obj_data_pool((s
->bucket_info
).placement_rule
,
5705 meta_obj
,&meta_pool
);
5706 store
->open_pool_ctx(meta_pool
, serializer
.ioctx
, true);
5708 op_ret
= serializer
.try_lock(raw_obj
.oid
, dur
);
5710 ldpp_dout(this, 0) << "failed to acquire lock" << dendl
;
5711 op_ret
= -ERR_INTERNAL_ERROR
;
5712 s
->err
.message
= "This multipart completion is already in progress";
5716 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5719 ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5720 << " ret=" << op_ret
<< dendl
;
5725 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5726 marker
, obj_parts
, &marker
, &truncated
);
5727 if (op_ret
== -ENOENT
) {
5728 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5733 total_parts
+= obj_parts
.size();
5734 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5735 ldpp_dout(this, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5736 << " expected: " << parts
->parts
.size() << dendl
;
5737 op_ret
= -ERR_INVALID_PART
;
5741 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5742 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5743 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5744 part_size
< min_part_size
) {
5745 op_ret
= -ERR_TOO_SMALL
;
5749 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5750 if (iter
->first
!= (int)obj_iter
->first
) {
5751 ldpp_dout(this, 0) << "NOTICE: parts num mismatch: next requested: "
5752 << iter
->first
<< " next uploaded: "
5753 << obj_iter
->first
<< dendl
;
5754 op_ret
= -ERR_INVALID_PART
;
5757 string part_etag
= rgw_string_unquote(iter
->second
);
5758 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5759 ldpp_dout(this, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5760 << " etag: " << iter
->second
<< dendl
;
5761 op_ret
= -ERR_INVALID_PART
;
5765 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5766 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5767 hash
.Update((const unsigned char *)petag
, sizeof(petag
));
5769 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5771 /* update manifest for part */
5772 string oid
= mp
.get_part(obj_iter
->second
.num
);
5774 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5776 if (obj_part
.manifest
.empty()) {
5777 ldpp_dout(this, 0) << "ERROR: empty manifest for object part: obj="
5778 << src_obj
<< dendl
;
5779 op_ret
= -ERR_INVALID_PART
;
5782 manifest
.append(obj_part
.manifest
, store
->svc
.zone
);
5785 bool part_compressed
= (obj_part
.cs_info
.compression_type
!= "none");
5786 if ((obj_iter
!= obj_parts
.begin()) &&
5787 ((part_compressed
!= compressed
) ||
5788 (cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
))) {
5789 ldpp_dout(this, 0) << "ERROR: compression type was changed during multipart upload ("
5790 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5791 op_ret
= -ERR_INVALID_PART
;
5795 if (part_compressed
) {
5796 int64_t new_ofs
; // offset in compression data for new part
5797 if (cs_info
.blocks
.size() > 0)
5798 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5801 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5802 compression_block cb
;
5803 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5804 cb
.new_ofs
= new_ofs
;
5806 cs_info
.blocks
.push_back(cb
);
5807 new_ofs
= cb
.new_ofs
+ cb
.len
;
5810 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5811 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5815 rgw_obj_index_key remove_key
;
5816 src_obj
.key
.get_index_key(&remove_key
);
5818 remove_objs
.push_back(remove_key
);
5820 ofs
+= obj_part
.size
;
5821 accounted_size
+= obj_part
.accounted_size
;
5823 } while (truncated
);
5824 hash
.Final((unsigned char *)final_etag
);
5826 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5827 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5828 "-%lld", (long long)parts
->parts
.size());
5829 etag
= final_etag_str
;
5830 ldpp_dout(this, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5832 etag_bl
.append(final_etag_str
, strlen(final_etag_str
));
5834 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5837 // write compression attribute to full object
5839 encode(cs_info
, tmp
);
5840 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5843 target_obj
.init(s
->bucket
, s
->object
.name
);
5844 if (versioned_object
) {
5845 if (!version_id
.empty()) {
5846 target_obj
.key
.set_instance(version_id
);
5848 store
->gen_rand_obj_instance_name(&target_obj
);
5849 version_id
= target_obj
.key
.get_instance();
5853 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5855 obj_ctx
.set_atomic(target_obj
);
5857 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5858 RGWRados::Object::Write
obj_op(&op_target
);
5860 obj_op
.meta
.manifest
= &manifest
;
5861 obj_op
.meta
.remove_objs
= &remove_objs
;
5863 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5864 obj_op
.meta
.owner
= s
->owner
.get_id();
5865 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5866 obj_op
.meta
.modify_tail
= true;
5867 obj_op
.meta
.completeMultipart
= true;
5868 obj_op
.meta
.olh_epoch
= olh_epoch
;
5869 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5873 // remove the upload obj
5874 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5875 s
->bucket_info
, meta_obj
, 0);
5877 /* serializer's exclusive lock is released */
5878 serializer
.clear_locked();
5880 ldpp_dout(this, 0) << "WARNING: failed to remove object " << meta_obj
<< dendl
;
5884 int RGWCompleteMultipart::MPSerializer::try_lock(
5885 const std::string
& _oid
,
5890 lock
.set_duration(dur
);
5891 lock
.lock_exclusive(&op
);
5892 int ret
= ioctx
.operate(oid
, &op
);
5899 void RGWCompleteMultipart::complete()
5901 /* release exclusive lock iff not already */
5902 if (unlikely(serializer
.locked
)) {
5903 int r
= serializer
.unlock();
5905 ldpp_dout(this, 0) << "WARNING: failed to unlock " << serializer
.oid
<< dendl
;
5911 int RGWAbortMultipart::verify_permission()
5913 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
5914 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
5916 rgw::IAM::s3AbortMultipartUpload
,
5917 rgw_obj(s
->bucket
, s
->object
));
5918 if (usr_policy_res
== Effect::Deny
) {
5922 rgw::IAM::Effect e
= Effect::Pass
;
5923 if (s
->iam_policy
) {
5924 e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5925 rgw::IAM::s3AbortMultipartUpload
,
5926 rgw_obj(s
->bucket
, s
->object
));
5928 if (e
== Effect::Allow
) {
5930 } else if (e
== Effect::Deny
) {
5932 } else if (usr_policy_res
== Effect::Allow
)
5936 if (!verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
5943 void RGWAbortMultipart::pre_exec()
5945 rgw_bucket_object_pre_exec(s
);
5948 void RGWAbortMultipart::execute()
5953 upload_id
= s
->info
.args
.get("uploadId");
5957 if (upload_id
.empty() || s
->object
.empty())
5960 mp
.init(s
->object
.name
, upload_id
);
5961 meta_oid
= mp
.get_meta();
5963 op_ret
= get_multipart_info(store
, s
, meta_oid
, nullptr, nullptr, nullptr);
5967 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5968 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5971 int RGWListMultipart::verify_permission()
5973 if (!verify_object_permission(this, s
, rgw::IAM::s3ListMultipartUploadParts
))
5979 void RGWListMultipart::pre_exec()
5981 rgw_bucket_object_pre_exec(s
);
5984 void RGWListMultipart::execute()
5989 op_ret
= get_params();
5993 mp
.init(s
->object
.name
, upload_id
);
5994 meta_oid
= mp
.get_meta();
5996 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, nullptr, nullptr);
6000 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
6001 marker
, parts
, NULL
, &truncated
);
6004 int RGWListBucketMultiparts::verify_permission()
6006 if (!verify_bucket_permission(this,
6008 rgw::IAM::s3ListBucketMultipartUploads
))
6014 void RGWListBucketMultiparts::pre_exec()
6016 rgw_bucket_object_pre_exec(s
);
6019 void RGWListBucketMultiparts::execute()
6021 vector
<rgw_bucket_dir_entry
> objs
;
6024 op_ret
= get_params();
6028 if (s
->prot_flags
& RGW_REST_SWIFT
) {
6030 path_args
= s
->info
.args
.get("path");
6031 if (!path_args
.empty()) {
6032 if (!delimiter
.empty() || !prefix
.empty()) {
6040 marker_meta
= marker
.get_meta();
6042 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
6043 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
6048 if (!objs
.empty()) {
6049 vector
<rgw_bucket_dir_entry
>::iterator iter
;
6050 RGWMultipartUploadEntry entry
;
6051 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
6052 rgw_obj_key
key(iter
->key
);
6053 if (!entry
.mp
.from_meta(key
.name
))
6056 uploads
.push_back(entry
);
6058 next_marker
= entry
;
6062 void RGWGetHealthCheck::execute()
6064 if (!g_conf()->rgw_healthcheck_disabling_path
.empty() &&
6065 (::access(g_conf()->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
6066 /* Disabling path specified & existent in the filesystem. */
6067 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
6069 op_ret
= 0; /* 200 OK */
6073 int RGWDeleteMultiObj::verify_permission()
6075 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
6076 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
6078 s
->object
.instance
.empty() ?
6079 rgw::IAM::s3DeleteObject
:
6080 rgw::IAM::s3DeleteObjectVersion
,
6082 if (usr_policy_res
== Effect::Deny
) {
6086 rgw::IAM::Effect r
= Effect::Pass
;
6087 if (s
->iam_policy
) {
6088 r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
6089 s
->object
.instance
.empty() ?
6090 rgw::IAM::s3DeleteObject
:
6091 rgw::IAM::s3DeleteObjectVersion
,
6094 if (r
== Effect::Allow
)
6096 else if (r
== Effect::Deny
)
6098 else if (usr_policy_res
== Effect::Allow
)
6102 acl_allowed
= verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
);
6109 void RGWDeleteMultiObj::pre_exec()
6111 rgw_bucket_object_pre_exec(s
);
6114 void RGWDeleteMultiObj::execute()
6116 RGWMultiDelDelete
*multi_delete
;
6117 vector
<rgw_obj_key
>::iterator iter
;
6118 RGWMultiDelXMLParser parser
;
6119 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6122 op_ret
= get_params();
6133 if (!parser
.init()) {
6138 if (!parser
.parse(buf
, data
.length(), 1)) {
6143 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
6144 if (!multi_delete
) {
6148 #define DELETE_MULTI_OBJ_MAX_NUM 1000
6149 int max_num
= s
->cct
->_conf
->rgw_delete_multi_obj_max_num
;
6151 max_num
= DELETE_MULTI_OBJ_MAX_NUM
;
6153 int multi_delete_object_num
= multi_delete
->objects
.size();
6154 if (multi_delete_object_num
> max_num
) {
6155 op_ret
= -ERR_MALFORMED_XML
;
6160 if (multi_delete
->is_quiet())
6163 if (s
->bucket_info
.mfa_enabled()) {
6164 bool has_versioned
= false;
6165 for (auto i
: multi_delete
->objects
) {
6166 if (!i
.instance
.empty()) {
6167 has_versioned
= true;
6171 if (has_versioned
&& !s
->mfa_verified
) {
6172 ldpp_dout(this, 5) << "NOTICE: multi-object delete request with a versioned object, mfa auth not provided" << dendl
;
6173 op_ret
= -ERR_MFA_REQUIRED
;
6179 if (multi_delete
->objects
.empty()) {
6183 for (iter
= multi_delete
->objects
.begin();
6184 iter
!= multi_delete
->objects
.end();
6186 rgw_obj
obj(bucket
, *iter
);
6187 if (s
->iam_policy
|| ! s
->iam_user_policies
.empty()) {
6188 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
6190 iter
->instance
.empty() ?
6191 rgw::IAM::s3DeleteObject
:
6192 rgw::IAM::s3DeleteObjectVersion
,
6194 if (usr_policy_res
== Effect::Deny
) {
6195 send_partial_response(*iter
, false, "", -EACCES
);
6199 rgw::IAM::Effect e
= Effect::Pass
;
6200 if (s
->iam_policy
) {
6201 e
= s
->iam_policy
->eval(s
->env
,
6203 iter
->instance
.empty() ?
6204 rgw::IAM::s3DeleteObject
:
6205 rgw::IAM::s3DeleteObjectVersion
,
6208 if ((e
== Effect::Deny
) ||
6209 (usr_policy_res
== Effect::Pass
&& e
== Effect::Pass
&& !acl_allowed
)) {
6210 send_partial_response(*iter
, false, "", -EACCES
);
6215 obj_ctx
->set_atomic(obj
);
6217 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
6218 RGWRados::Object::Delete
del_op(&del_target
);
6220 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
6221 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
6222 del_op
.params
.obj_owner
= s
->owner
;
6224 op_ret
= del_op
.delete_obj();
6225 if (op_ret
== -ENOENT
) {
6229 send_partial_response(*iter
, del_op
.result
.delete_marker
,
6230 del_op
.result
.version_id
, op_ret
);
6233 /* set the return code to zero, errors at this point will be
6234 dumped to the response */
6238 // will likely segfault if begin_response() has not been called
6248 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
6249 map
<string
, bufferlist
>& battrs
,
6250 ACLOwner
& bucket_owner
/* out */)
6252 RGWAccessControlPolicy
bacl(store
->ctx());
6253 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6258 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6260 bucket_owner
= bacl
.get_owner();
6262 /* We can use global user_acl because each BulkDelete request is allowed
6263 * to work on entities from a single account only. */
6264 return verify_bucket_permission(dpp
, s
, binfo
.bucket
, s
->user_acl
.get(),
6265 &bacl
, policy
, s
->iam_user_policies
, rgw::IAM::s3DeleteBucket
);
6268 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
6270 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6272 RGWBucketInfo binfo
;
6273 map
<string
, bufferlist
> battrs
;
6276 int ret
= store
->get_bucket_info(*s
->sysobj_ctx
, s
->user
->user_id
.tenant
,
6277 path
.bucket_name
, binfo
, nullptr,
6283 if (!verify_permission(binfo
, battrs
, bowner
)) {
6288 if (!path
.obj_key
.empty()) {
6289 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
6290 obj_ctx
.set_atomic(obj
);
6292 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
6293 RGWRados::Object::Delete
del_op(&del_target
);
6295 del_op
.params
.bucket_owner
= binfo
.owner
;
6296 del_op
.params
.versioning_status
= binfo
.versioning_status();
6297 del_op
.params
.obj_owner
= bowner
;
6299 ret
= del_op
.delete_obj();
6304 RGWObjVersionTracker ot
;
6305 ot
.read_version
= binfo
.ep_objv
;
6307 ret
= store
->delete_bucket(binfo
, ot
);
6309 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
6310 binfo
.bucket
.name
, false);
6312 ldpp_dout(s
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
<< dendl
;
6319 if (!store
->svc
.zone
->is_meta_master()) {
6321 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
6324 if (ret
== -ENOENT
) {
6325 /* adjust error, we want to return with NoSuchBucket and not
6327 ret
= -ERR_NO_SUCH_BUCKET
;
6339 if (-ENOENT
== ret
) {
6340 ldpp_dout(s
, 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
6343 ldpp_dout(s
, 20) << "cannot get bucket info, ret = " << ret
<< dendl
;
6345 fail_desc_t failed_item
= {
6349 failures
.push_back(failed_item
);
6354 ldpp_dout(s
, 20) << "wrong auth for " << path
<< dendl
;
6356 fail_desc_t failed_item
= {
6360 failures
.push_back(failed_item
);
6365 if (-ENOENT
== ret
) {
6366 ldpp_dout(s
, 20) << "cannot find entry " << path
<< dendl
;
6369 fail_desc_t failed_item
= {
6373 failures
.push_back(failed_item
);
6378 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
6380 ldpp_dout(s
, 20) << "in delete_chunk" << dendl
;
6381 for (auto path
: paths
) {
6382 ldpp_dout(s
, 20) << "bulk deleting path: " << path
<< dendl
;
6383 delete_single(path
);
6389 int RGWBulkDelete::verify_permission()
6394 void RGWBulkDelete::pre_exec()
6396 rgw_bucket_object_pre_exec(s
);
6399 void RGWBulkDelete::execute()
6401 deleter
= std::unique_ptr
<Deleter
>(new Deleter(this, store
, s
));
6403 bool is_truncated
= false;
6405 list
<RGWBulkDelete::acct_path_t
> items
;
6407 int ret
= get_data(items
, &is_truncated
);
6412 ret
= deleter
->delete_chunk(items
);
6413 } while (!op_ret
&& is_truncated
);
6419 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
6421 int RGWBulkUploadOp::verify_permission()
6423 if (s
->auth
.identity
->is_anonymous()) {
6427 if (! verify_user_permission_no_policy(this, s
, RGW_PERM_WRITE
)) {
6431 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
6432 ldpp_dout(this, 10) << "user cannot create a bucket in a different tenant"
6433 << " (user_id.tenant=" << s
->user
->user_id
.tenant
6434 << " requested=" << s
->bucket_tenant
<< ")" << dendl
;
6438 if (s
->user
->max_buckets
< 0) {
6445 void RGWBulkUploadOp::pre_exec()
6447 rgw_bucket_object_pre_exec(s
);
6450 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
6451 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
6453 /* We need to skip all slashes at the beginning in order to preserve
6454 * compliance with Swift. */
6455 const size_t start_pos
= path
.find_first_not_of('/');
6457 if (boost::string_ref::npos
!= start_pos
) {
6458 /* Seperator is the first slash after the leading ones. */
6459 const size_t sep_pos
= path
.substr(start_pos
).find('/');
6461 if (boost::string_ref::npos
!= sep_pos
) {
6462 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
6463 const auto obj_name
= path
.substr(sep_pos
+ 1);
6465 return std::make_pair(bucket_name
.to_string(),
6466 rgw_obj_key(obj_name
.to_string()));
6468 /* It's guaranteed here that bucket name is at least one character
6469 * long and is different than slash. */
6470 return std::make_pair(path
.substr(start_pos
).to_string(),
6478 std::pair
<std::string
, std::string
>
6479 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
6481 std::string bucket_path
, file_prefix
;
6482 if (! s
->init_state
.url_bucket
.empty()) {
6483 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
6484 if (! s
->object
.empty()) {
6485 std::string
& object_name
= s
->object
.name
;
6487 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
6488 * we can safely examine its last element. */
6489 if (object_name
.back() == '/') {
6490 file_prefix
.append(object_name
);
6492 file_prefix
.append(object_name
).append("/");
6496 return std::make_pair(bucket_path
, file_prefix
);
6499 int RGWBulkUploadOp::handle_dir_verify_permission()
6501 if (s
->user
->max_buckets
> 0) {
6502 RGWUserBuckets buckets
;
6504 bool is_truncated
= false;
6505 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
6506 marker
, std::string(), s
->user
->max_buckets
,
6507 false, &is_truncated
);
6512 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
6513 return -ERR_TOO_MANY_BUCKETS
;
6520 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
6522 /* the request of container or object level will contain bucket name.
6523 * only at account level need to append the bucket name */
6524 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
6528 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
6529 info
.script_uri
.append("/").append(bucket_name
);
6530 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
6531 info
.effective_uri
= "/" + bucket_name
;
6534 void RGWBulkUploadOp::init(RGWRados
* const store
,
6535 struct req_state
* const s
,
6536 RGWHandler
* const h
)
6538 RGWOp::init(store
, s
, h
);
6539 dir_ctx
.emplace(store
->svc
.sysobj
->init_obj_ctx());
6542 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
6544 ldpp_dout(this, 20) << "got directory=" << path
<< dendl
;
6546 op_ret
= handle_dir_verify_permission();
6551 std::string bucket_name
;
6552 rgw_obj_key object_junk
;
6553 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
6555 rgw_raw_obj
obj(store
->svc
.zone
->get_zone_params().domain_root
,
6556 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
6558 /* we need to make sure we read bucket info, it's not read before for this
6559 * specific request */
6560 RGWBucketInfo binfo
;
6561 std::map
<std::string
, ceph::bufferlist
> battrs
;
6562 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6563 binfo
, nullptr, &battrs
);
6564 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6567 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6569 if (bucket_exists
) {
6570 RGWAccessControlPolicy
old_policy(s
->cct
);
6571 int r
= rgw_op_get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6572 battrs
, &old_policy
);
6574 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6581 RGWBucketInfo master_info
;
6582 rgw_bucket
*pmaster_bucket
= nullptr;
6583 uint32_t *pmaster_num_shards
= nullptr;
6584 real_time creation_time
;
6585 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6587 if (! store
->svc
.zone
->is_meta_master()) {
6589 ceph::bufferlist in_data
;
6590 req_info info
= s
->info
;
6591 forward_req_info(s
->cct
, info
, bucket_name
);
6592 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6597 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6598 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6599 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6601 ldpp_dout(this, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
6602 ldpp_dout(this, 20) << "got creation_time="<< master_info
.creation_time
<< dendl
;
6604 pmaster_bucket
= &master_info
.bucket
;
6605 creation_time
= master_info
.creation_time
;
6606 pmaster_num_shards
= &master_info
.num_shards
;
6609 pmaster_bucket
= nullptr;
6610 pmaster_num_shards
= nullptr;
6613 rgw_placement_rule
placement_rule(binfo
.placement_rule
, s
->info
.storage_class
);
6615 if (bucket_exists
) {
6616 rgw_placement_rule selected_placement_rule
;
6618 bucket
.tenant
= s
->bucket_tenant
;
6619 bucket
.name
= s
->bucket_name
;
6620 op_ret
= store
->svc
.zone
->select_bucket_placement(*(s
->user
),
6621 store
->svc
.zone
->get_zonegroup().get_id(),
6623 &selected_placement_rule
,
6625 if (selected_placement_rule
!= binfo
.placement_rule
) {
6627 ldpp_dout(this, 20) << "non-coherent placement rule" << dendl
;
6632 /* Create metadata: ACLs. */
6633 std::map
<std::string
, ceph::bufferlist
> attrs
;
6634 RGWAccessControlPolicy policy
;
6635 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6636 ceph::bufferlist aclbl
;
6637 policy
.encode(aclbl
);
6638 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6640 RGWQuotaInfo quota_info
;
6641 const RGWQuotaInfo
* pquota_info
= nullptr;
6644 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6645 bucket
.name
= bucket_name
;
6648 RGWBucketInfo out_info
;
6649 op_ret
= store
->create_bucket(*(s
->user
),
6651 store
->svc
.zone
->get_zonegroup().get_id(),
6652 placement_rule
, binfo
.swift_ver_location
,
6654 out_info
, pobjv
, &ep_objv
, creation_time
,
6655 pmaster_bucket
, pmaster_num_shards
, true);
6656 /* continue if EEXIST and create_bucket will fail below. this way we can
6657 * recover from a partial create by retrying it. */
6658 ldpp_dout(this, 20) << "rgw_create_bucket returned ret=" << op_ret
6659 << ", bucket=" << bucket
<< dendl
;
6661 if (op_ret
&& op_ret
!= -EEXIST
) {
6665 const bool existed
= (op_ret
== -EEXIST
);
6667 /* bucket already existed, might have raced with another bucket creation, or
6668 * might be partial bucket creation that never completed. Read existing bucket
6669 * info, verify that the reported bucket owner is the current user.
6670 * If all is ok then update the user's list of buckets.
6671 * Otherwise inform client about a name conflict.
6673 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6675 ldpp_dout(this, 20) << "conflicting bucket name" << dendl
;
6678 bucket
= out_info
.bucket
;
6681 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6682 out_info
.creation_time
, false);
6683 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6684 /* if it exists (or previously existed), don't remove it! */
6685 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6686 bucket
.tenant
, bucket
.name
);
6688 ldpp_dout(this, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
<< dendl
;
6690 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6691 ldpp_dout(this, 20) << "containers already exists" << dendl
;
6692 op_ret
= -ERR_BUCKET_EXISTS
;
6699 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6701 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6702 ACLOwner
& bucket_owner
/* out */)
6704 RGWAccessControlPolicy
bacl(store
->ctx());
6705 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6707 ldpp_dout(this, 20) << "cannot read_policy() for bucket" << dendl
;
6711 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6713 bucket_owner
= bacl
.get_owner();
6714 if (policy
|| ! s
->iam_user_policies
.empty()) {
6715 auto usr_policy_res
= eval_user_policies(s
->iam_user_policies
, s
->env
,
6717 rgw::IAM::s3PutObject
, obj
);
6718 if (usr_policy_res
== Effect::Deny
) {
6721 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6722 rgw::IAM::s3PutObject
, obj
);
6723 if (e
== Effect::Allow
) {
6725 } else if (e
== Effect::Deny
) {
6727 } else if (usr_policy_res
== Effect::Allow
) {
6732 return verify_bucket_permission_no_policy(this, s
, s
->user_acl
.get(),
6733 &bacl
, RGW_PERM_WRITE
);
6736 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6738 AlignedStreamGetter
& body
)
6741 ldpp_dout(this, 20) << "got file=" << path
<< ", size=" << size
<< dendl
;
6743 if (size
> static_cast<size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6744 op_ret
= -ERR_TOO_LARGE
;
6748 std::string bucket_name
;
6750 std::tie(bucket_name
, object
) = *parse_path(path
);
6752 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6753 RGWBucketInfo binfo
;
6754 std::map
<std::string
, ceph::bufferlist
> battrs
;
6756 op_ret
= store
->get_bucket_info(*s
->sysobj_ctx
, s
->user
->user_id
.tenant
,
6757 bucket_name
, binfo
, nullptr, &battrs
);
6758 if (op_ret
== -ENOENT
) {
6759 ldpp_dout(this, 20) << "non existent directory=" << bucket_name
<< dendl
;
6760 } else if (op_ret
< 0) {
6764 if (! handle_file_verify_permission(binfo
,
6765 rgw_obj(binfo
.bucket
, object
),
6767 ldpp_dout(this, 20) << "object creation unauthorized" << dendl
;
6772 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6773 user_quota
, bucket_quota
, size
);
6778 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6783 rgw_obj
obj(binfo
.bucket
, object
);
6784 if (s
->bucket_info
.versioning_enabled()) {
6785 store
->gen_rand_obj_instance_name(&obj
);
6788 rgw_placement_rule dest_placement
= s
->dest_placement
;
6789 dest_placement
.inherit_from(binfo
.placement_rule
);
6791 rgw::AioThrottle
aio(store
->ctx()->_conf
->rgw_put_obj_min_window_size
);
6793 using namespace rgw::putobj
;
6795 AtomicObjectProcessor
processor(&aio
, store
, binfo
, &s
->dest_placement
, bowner
.get_id(),
6796 obj_ctx
, obj
, 0, s
->req_id
);
6798 op_ret
= processor
.prepare();
6800 ldpp_dout(this, 20) << "cannot prepare processor due to ret=" << op_ret
<< dendl
;
6804 /* No filters by default. */
6805 DataProcessor
*filter
= &processor
;
6807 const auto& compression_type
= store
->svc
.zone
->get_zone_params().get_compression_type(
6809 CompressorRef plugin
;
6810 boost::optional
<RGWPutObj_Compress
> compressor
;
6811 if (compression_type
!= "none") {
6812 plugin
= Compressor::create(s
->cct
, compression_type
);
6814 ldpp_dout(this, 1) << "Cannot load plugin for rgw_compression_type "
6815 << compression_type
<< dendl
;
6817 compressor
.emplace(s
->cct
, plugin
, filter
);
6818 filter
= &*compressor
;
6822 /* Upload file content. */
6827 ceph::bufferlist data
;
6828 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6830 ldpp_dout(this, 20) << "body=" << data
.c_str() << dendl
;
6834 } else if (len
> 0) {
6835 hash
.Update((const unsigned char *)data
.c_str(), data
.length());
6836 op_ret
= filter
->process(std::move(data
), ofs
);
6838 ldpp_dout(this, 20) << "filter->process() returned ret=" << op_ret
<< dendl
;
6848 op_ret
= filter
->process({}, ofs
);
6854 ldpp_dout(this, 10) << "real file size different from declared" << dendl
;
6859 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6860 user_quota
, bucket_quota
, size
);
6862 ldpp_dout(this, 20) << "quota exceeded for path=" << path
<< dendl
;
6866 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6871 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6872 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6874 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6876 /* Create metadata: ETAG. */
6877 std::map
<std::string
, ceph::bufferlist
> attrs
;
6878 std::string etag
= calc_md5
;
6879 ceph::bufferlist etag_bl
;
6880 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6881 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6883 /* Create metadata: ACLs. */
6884 RGWAccessControlPolicy policy
;
6885 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6886 ceph::bufferlist aclbl
;
6887 policy
.encode(aclbl
);
6888 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6890 /* Create metadata: compression info. */
6891 if (compressor
&& compressor
->is_compressed()) {
6892 ceph::bufferlist tmp
;
6893 RGWCompressionInfo cs_info
;
6894 cs_info
.compression_type
= plugin
->get_type_name();
6895 cs_info
.orig_size
= s
->obj_size
;
6896 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6897 encode(cs_info
, tmp
);
6898 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6901 /* Complete the transaction. */
6902 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(),
6903 attrs
, ceph::real_time() /* delete_at */,
6904 nullptr, nullptr, nullptr, nullptr, nullptr);
6906 ldpp_dout(this, 20) << "processor::complete returned op_ret=" << op_ret
<< dendl
;
6912 void RGWBulkUploadOp::execute()
6914 ceph::bufferlist
buffer(64 * 1024);
6916 ldpp_dout(this, 20) << "start" << dendl
;
6918 /* Create an instance of stream-abstracting class. Having this indirection
6919 * allows for easy introduction of decompressors like gzip and bzip2. */
6920 auto stream
= create_stream();
6925 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6926 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6927 std::string bucket_path
, file_prefix
;
6928 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6930 auto status
= rgw::tar::StatusIndicator::create();
6932 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6934 ldpp_dout(this, 2) << "cannot read header" << dendl
;
6938 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6939 * must be tracked to detect out end-of-archive. It occurs when both of
6940 * them are empty (zeroed). Tracing this particular inter-block dependency
6941 * is responsibility of the rgw::tar::StatusIndicator class. */
6942 boost::optional
<rgw::tar::HeaderView
> header
;
6943 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6945 if (! status
.empty() && header
) {
6946 /* This specific block isn't empty (entirely zeroed), so we can parse
6947 * it as a TAR header and dispatch. At the moment we do support only
6948 * regular files and directories. Everything else (symlinks, devices)
6949 * will be ignored but won't cease the whole upload. */
6950 switch (header
->get_filetype()) {
6951 case rgw::tar::FileType::NORMAL_FILE
: {
6952 ldpp_dout(this, 2) << "handling regular file" << dendl
;
6954 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6955 file_prefix
+ header
->get_filename().to_string();
6956 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6957 rgw::tar::BLOCK_SIZE
, *stream
);
6958 op_ret
= handle_file(filename
,
6959 header
->get_filesize(),
6962 /* Only regular files counts. */
6965 failures
.emplace_back(op_ret
, filename
.to_string());
6969 case rgw::tar::FileType::DIRECTORY
: {
6970 ldpp_dout(this, 2) << "handling regular directory" << dendl
;
6972 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6973 op_ret
= handle_dir(dirname
);
6974 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6975 failures
.emplace_back(op_ret
, dirname
.to_string());
6980 /* Not recognized. Skip. */
6986 /* In case of any problems with sub-request authorization Swift simply
6987 * terminates whole upload immediately. */
6988 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6990 ldpp_dout(this, 2) << "terminating due to ret=" << op_ret
<< dendl
;
6994 ldpp_dout(this, 2) << "an empty block" << dendl
;
6999 } while (! status
.eof());
7004 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
7006 const size_t aligned_legnth
= length
+ (-length
% alignment
);
7007 ceph::bufferlist junk
;
7009 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
7012 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
7013 ceph::bufferlist
& dst
)
7015 const size_t max_to_read
= std::min(want
, length
- position
);
7016 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
7023 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
7024 ceph::bufferlist
& dst
)
7026 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
7033 int RGWSetAttrs::verify_permission()
7035 // This looks to be part of the RGW-NFS machinery and has no S3 or
7036 // Swift equivalent.
7038 if (!s
->object
.empty()) {
7039 perm
= verify_object_permission_no_policy(this, s
, RGW_PERM_WRITE
);
7041 perm
= verify_bucket_permission_no_policy(this, s
, RGW_PERM_WRITE
);
7049 void RGWSetAttrs::pre_exec()
7051 rgw_bucket_object_pre_exec(s
);
7054 void RGWSetAttrs::execute()
7056 op_ret
= get_params();
7060 rgw_obj
obj(s
->bucket
, s
->object
);
7062 if (!s
->object
.empty()) {
7063 store
->set_atomic(s
->obj_ctx
, obj
);
7064 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
7066 for (auto& iter
: attrs
) {
7067 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
7069 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
7070 &s
->bucket_info
.objv_tracker
);
7074 void RGWGetObjLayout::pre_exec()
7076 rgw_bucket_object_pre_exec(s
);
7079 void RGWGetObjLayout::execute()
7081 rgw_obj
obj(s
->bucket
, s
->object
);
7082 RGWRados::Object
target(store
,
7084 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
7085 rgw_obj(s
->bucket
, s
->object
));
7086 RGWRados::Object::Read
stat_op(&target
);
7088 op_ret
= stat_op
.prepare();
7093 head_obj
= stat_op
.state
.head_obj
;
7095 op_ret
= target
.get_manifest(&manifest
);
7099 int RGWConfigBucketMetaSearch::verify_permission()
7101 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
7108 void RGWConfigBucketMetaSearch::pre_exec()
7110 rgw_bucket_object_pre_exec(s
);
7113 void RGWConfigBucketMetaSearch::execute()
7115 op_ret
= get_params();
7117 ldpp_dout(this, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
7121 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
7123 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
7125 ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
7126 << " returned err=" << op_ret
<< dendl
;
7131 int RGWGetBucketMetaSearch::verify_permission()
7133 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
7140 void RGWGetBucketMetaSearch::pre_exec()
7142 rgw_bucket_object_pre_exec(s
);
7145 int RGWDelBucketMetaSearch::verify_permission()
7147 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
7154 void RGWDelBucketMetaSearch::pre_exec()
7156 rgw_bucket_object_pre_exec(s
);
7159 void RGWDelBucketMetaSearch::execute()
7161 s
->bucket_info
.mdsearch_config
.clear();
7163 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
7165 ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
7166 << " returned err=" << op_ret
<< dendl
;
7172 RGWHandler::~RGWHandler()
7176 int RGWHandler::init(RGWRados
*_store
,
7177 struct req_state
*_s
,
7178 rgw::io::BasicClient
*cio
)
7186 int RGWHandler::do_init_permissions()
7188 int ret
= rgw_build_bucket_policies(store
, s
);
7190 ldpp_dout(s
, 10) << "init_permissions on " << s
->bucket
7191 << " failed, ret=" << ret
<< dendl
;
7192 return ret
==-ENODATA
? -EACCES
: ret
;
7195 rgw_build_iam_environment(store
, s
);
7199 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
7202 /* already read bucket info */
7205 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
7208 ldpp_dout(op
, 10) << "read_permissions on " << s
->bucket
<< ":"
7209 << s
->object
<< " only_bucket=" << only_bucket
7210 << " ret=" << ret
<< dendl
;
7211 if (ret
== -ENODATA
)
7218 int RGWOp::error_handler(int err_no
, string
*error_content
) {
7219 return dialect_handler
->error_handler(err_no
, error_content
);
7222 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
7223 // This is the do-nothing error handler
7227 std::ostream
& RGWOp::gen_prefix(std::ostream
& out
) const
7229 // append <dialect>:<op name> to the prefix
7230 return s
->gen_prefix(out
) << s
->dialect
<< ':' << name() << ' ';
7233 void RGWDefaultResponseOp::send_response() {
7235 set_req_state_err(s
, op_ret
);
7241 void RGWPutBucketPolicy::send_response()
7244 set_req_state_err(s
, op_ret
);
7250 int RGWPutBucketPolicy::verify_permission()
7252 if (!verify_bucket_permission(this, s
, rgw::IAM::s3PutBucketPolicy
)) {
7259 int RGWPutBucketPolicy::get_params()
7261 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
7262 // At some point when I have more time I want to make a version of
7263 // rgw_rest_read_all_input that doesn't use malloc.
7264 std::tie(op_ret
, data
) = rgw_rest_read_all_input(s
, max_size
, false);
7266 // And throws exceptions.
7270 void RGWPutBucketPolicy::execute()
7272 op_ret
= get_params();
7277 if (!store
->svc
.zone
->is_meta_master()) {
7278 op_ret
= forward_request_to_master(s
, NULL
, store
, data
, nullptr);
7280 ldpp_dout(this, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
7286 const Policy
p(s
->cct
, s
->bucket_tenant
, data
);
7287 op_ret
= retry_raced_bucket_write(store
, s
, [&p
, this] {
7288 auto attrs
= s
->bucket_attrs
;
7289 attrs
[RGW_ATTR_IAM_POLICY
].clear();
7290 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
7291 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
7292 &s
->bucket_info
.objv_tracker
);
7295 } catch (rgw::IAM::PolicyParseException
& e
) {
7296 ldpp_dout(this, 20) << "failed to parse policy: " << e
.what() << dendl
;
7301 void RGWGetBucketPolicy::send_response()
7304 set_req_state_err(s
, op_ret
);
7307 end_header(s
, this, "application/json");
7308 dump_body(s
, policy
);
7311 int RGWGetBucketPolicy::verify_permission()
7313 if (!verify_bucket_permission(this, s
, rgw::IAM::s3GetBucketPolicy
)) {
7320 void RGWGetBucketPolicy::execute()
7322 auto attrs
= s
->bucket_attrs
;
7323 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
7324 if (aiter
== attrs
.end()) {
7325 ldpp_dout(this, 0) << "can't find bucket IAM POLICY attr bucket_name = "
7326 << s
->bucket_name
<< dendl
;
7327 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
7328 s
->err
.message
= "The bucket policy does not exist";
7331 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
7333 if (policy
.length() == 0) {
7334 ldpp_dout(this, 10) << "The bucket policy does not exist, bucket: "
7335 << s
->bucket_name
<< dendl
;
7336 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
7337 s
->err
.message
= "The bucket policy does not exist";
7343 void RGWDeleteBucketPolicy::send_response()
7346 set_req_state_err(s
, op_ret
);
7352 int RGWDeleteBucketPolicy::verify_permission()
7354 if (!verify_bucket_permission(this, s
, rgw::IAM::s3DeleteBucketPolicy
)) {
7361 void RGWDeleteBucketPolicy::execute()
7363 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
7364 auto attrs
= s
->bucket_attrs
;
7365 attrs
.erase(RGW_ATTR_IAM_POLICY
);
7366 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
7367 &s
->bucket_info
.objv_tracker
);
7372 void RGWGetClusterStat::execute()
7374 op_ret
= this->store
->get_rados_handle()->cluster_stat(stats_op
);