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 "common/Clock.h"
18 #include "common/armor.h"
19 #include "common/errno.h"
20 #include "common/mime.h"
21 #include "common/utf8.h"
22 #include "common/ceph_json.h"
24 #include "rgw_rados.h"
28 #include "rgw_acl_s3.h"
29 #include "rgw_acl_swift.h"
31 #include "rgw_bucket.h"
33 #include "rgw_multi.h"
34 #include "rgw_multi_del.h"
36 #include "rgw_cors_s3.h"
37 #include "rgw_rest_conn.h"
38 #include "rgw_rest_s3.h"
40 #include "rgw_client_io.h"
41 #include "rgw_compression.h"
43 #include "rgw_tag_s3.h"
44 #include "cls/lock/cls_lock_client.h"
45 #include "cls/rgw/cls_rgw_client.h"
48 #include "include/assert.h"
50 #include "compressor/Compressor.h"
52 #include "rgw_acl_swift.h"
54 #define dout_context g_ceph_context
55 #define dout_subsys ceph_subsys_rgw
58 using namespace librados
;
59 using ceph::crypto::MD5
;
60 using boost::optional
;
64 using rgw::IAM::Effect
;
65 using rgw::IAM::Policy
;
67 using rgw::IAM::Policy
;
69 static string mp_ns
= RGW_OBJ_NS_MULTIPART
;
70 static string shadow_ns
= RGW_OBJ_NS_SHADOW
;
72 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
);
73 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
, RGWRados
*store
,
74 bufferlist
& in_data
, JSONParser
*jp
, req_info
*forward_info
= nullptr);
76 static MultipartMetaFilter mp_filter
;
78 static int parse_range(const char *range
, off_t
& ofs
, off_t
& end
, bool *partial_content
)
85 *partial_content
= false;
87 size_t pos
= s
.find("bytes=");
88 if (pos
== string::npos
) {
90 while (isspace(s
[pos
]))
93 while (isalpha(s
[end
]))
95 if (strncasecmp(s
.c_str(), "bytes", end
- pos
) != 0)
97 while (isspace(s
[end
]))
101 s
= s
.substr(end
+ 1);
103 s
= s
.substr(pos
+ 6); /* size of("bytes=") */
106 if (pos
== string::npos
)
109 *partial_content
= true;
111 ofs_str
= s
.substr(0, pos
);
112 end_str
= s
.substr(pos
+ 1);
113 if (end_str
.length()) {
114 end
= atoll(end_str
.c_str());
119 if (ofs_str
.length()) {
120 ofs
= atoll(ofs_str
.c_str());
121 } else { // RFC2616 suffix-byte-range-spec
126 if (end
>= 0 && end
< ofs
)
134 static int decode_policy(CephContext
*cct
,
136 RGWAccessControlPolicy
*policy
)
138 bufferlist::iterator iter
= bl
.begin();
140 policy
->decode(iter
);
141 } catch (buffer::error
& err
) {
142 ldout(cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
145 if (cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
146 RGWAccessControlPolicy_S3
*s3policy
= static_cast<RGWAccessControlPolicy_S3
*>(policy
);
147 ldout(cct
, 15) << __func__
<< " Read AccessControlPolicy";
148 s3policy
->to_xml(*_dout
);
155 static int get_user_policy_from_attr(CephContext
* const cct
,
156 RGWRados
* const store
,
157 map
<string
, bufferlist
>& attrs
,
158 RGWAccessControlPolicy
& policy
/* out */)
160 auto aiter
= attrs
.find(RGW_ATTR_ACL
);
161 if (aiter
!= attrs
.end()) {
162 int ret
= decode_policy(cct
, aiter
->second
, &policy
);
173 static int get_bucket_instance_policy_from_attr(CephContext
*cct
,
175 RGWBucketInfo
& bucket_info
,
176 map
<string
, bufferlist
>& bucket_attrs
,
177 RGWAccessControlPolicy
*policy
,
180 map
<string
, bufferlist
>::iterator aiter
= bucket_attrs
.find(RGW_ATTR_ACL
);
182 if (aiter
!= bucket_attrs
.end()) {
183 int ret
= decode_policy(cct
, aiter
->second
, policy
);
187 ldout(cct
, 0) << "WARNING: couldn't find acl header for bucket, generating default" << dendl
;
189 /* object exists, but policy is broken */
190 int r
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
194 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
199 static int get_obj_policy_from_attr(CephContext
*cct
,
201 RGWObjectCtx
& obj_ctx
,
202 RGWBucketInfo
& bucket_info
,
203 map
<string
, bufferlist
>& bucket_attrs
,
204 RGWAccessControlPolicy
*policy
,
210 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
211 RGWRados::Object::Read
rop(&op_target
);
213 ret
= rop
.get_attr(RGW_ATTR_ACL
, bl
);
215 ret
= decode_policy(cct
, bl
, policy
);
218 } else if (ret
== -ENODATA
) {
219 /* object exists, but policy is broken */
220 ldout(cct
, 0) << "WARNING: couldn't find acl header for object, generating default" << dendl
;
222 ret
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
226 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
233 * Get the AccessControlPolicy for an object off of disk.
234 * policy: must point to a valid RGWACL, and will be filled upon return.
235 * bucket: name of the bucket containing the object.
236 * object: name of the object to get the ACL for.
237 * Returns: 0 on success, -ERR# otherwise.
239 static int get_bucket_policy_from_attr(CephContext
*cct
,
241 RGWBucketInfo
& bucket_info
,
242 map
<string
, bufferlist
>& bucket_attrs
,
243 RGWAccessControlPolicy
*policy
)
245 rgw_raw_obj instance_obj
;
246 store
->get_bucket_instance_obj(bucket_info
.bucket
, instance_obj
);
247 return get_bucket_instance_policy_from_attr(cct
, store
, bucket_info
, bucket_attrs
,
248 policy
, instance_obj
);
251 static optional
<Policy
> get_iam_policy_from_attr(CephContext
* cct
,
253 map
<string
, bufferlist
>& attrs
,
254 const string
& tenant
) {
255 auto i
= attrs
.find(RGW_ATTR_IAM_POLICY
);
256 if (i
!= attrs
.end()) {
257 return Policy(cct
, tenant
, i
->second
);
263 static int get_obj_attrs(RGWRados
*store
, struct req_state
*s
, rgw_obj
& obj
, map
<string
, bufferlist
>& attrs
)
265 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
266 RGWRados::Object::Read
read_op(&op_target
);
268 read_op
.params
.attrs
= &attrs
;
270 return read_op
.prepare();
273 static int modify_obj_attr(RGWRados
*store
, struct req_state
*s
, rgw_obj
& obj
, const char* attr_name
, bufferlist
& attr_val
)
275 map
<string
, bufferlist
> attrs
;
276 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
277 RGWRados::Object::Read
read_op(&op_target
);
279 read_op
.params
.attrs
= &attrs
;
281 int r
= read_op
.prepare();
285 store
->set_atomic(s
->obj_ctx
, read_op
.state
.obj
);
286 attrs
[attr_name
] = attr_val
;
287 return store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, read_op
.state
.obj
, attrs
, NULL
);
290 static int get_system_obj_attrs(RGWRados
*store
, struct req_state
*s
, rgw_raw_obj
& obj
, map
<string
, bufferlist
>& attrs
,
291 uint64_t *obj_size
, RGWObjVersionTracker
*objv_tracker
)
293 RGWRados::SystemObject
src(store
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
294 RGWRados::SystemObject::Read
rop(&src
);
296 rop
.stat_params
.attrs
= &attrs
;
297 rop
.stat_params
.obj_size
= obj_size
;
299 int ret
= rop
.stat(objv_tracker
);
303 static int read_bucket_policy(RGWRados
*store
,
305 RGWBucketInfo
& bucket_info
,
306 map
<string
, bufferlist
>& bucket_attrs
,
307 RGWAccessControlPolicy
*policy
,
310 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
311 ldout(s
->cct
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
<< " is suspended" << dendl
;
312 return -ERR_USER_SUSPENDED
;
315 if (bucket
.name
.empty()) {
319 int ret
= get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, policy
);
320 if (ret
== -ENOENT
) {
321 ret
= -ERR_NO_SUCH_BUCKET
;
327 static int read_obj_policy(RGWRados
*store
,
329 RGWBucketInfo
& bucket_info
,
330 map
<string
, bufferlist
>& bucket_attrs
,
331 RGWAccessControlPolicy
* acl
,
332 optional
<Policy
>& policy
,
337 upload_id
= s
->info
.args
.get("uploadId");
340 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
341 ldout(s
->cct
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
<< " is suspended" << dendl
;
342 return -ERR_USER_SUSPENDED
;
345 if (!upload_id
.empty()) {
346 /* multipart upload */
347 RGWMPObj
mp(object
.name
, upload_id
);
348 string oid
= mp
.get_meta();
349 obj
.init_ns(bucket
, oid
, mp_ns
);
350 obj
.set_in_extra_data(true);
352 obj
= rgw_obj(bucket
, object
);
354 policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
, bucket
.tenant
);
356 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
357 int ret
= get_obj_policy_from_attr(s
->cct
, store
, *obj_ctx
,
358 bucket_info
, bucket_attrs
, acl
, obj
);
359 if (ret
== -ENOENT
) {
360 /* object does not exist checking the bucket's ACL to make sure
361 that we send a proper error code */
362 RGWAccessControlPolicy
bucket_policy(s
->cct
);
363 ret
= get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, &bucket_policy
);
368 const rgw_user
& bucket_owner
= bucket_policy
.get_owner().get_id();
369 if (bucket_owner
.compare(s
->user
->user_id
) != 0 &&
370 ! s
->auth
.identity
->is_admin_of(bucket_owner
) &&
371 ! bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
383 * Get the AccessControlPolicy for an user, bucket or object off of disk.
384 * s: The req_state to draw information from.
385 * only_bucket: If true, reads the user and bucket ACLs rather than the object ACL.
386 * Returns: 0 on success, -ERR# otherwise.
388 int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
)
392 RGWUserInfo bucket_owner_info
;
393 RGWObjectCtx
obj_ctx(store
);
395 string bi
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"bucket-instance");
397 ret
= rgw_bucket_parse_bucket_instance(bi
, &s
->bucket_instance_id
, &s
->bucket_instance_shard_id
);
403 if(s
->dialect
.compare("s3") == 0) {
404 s
->bucket_acl
= new RGWAccessControlPolicy_S3(s
->cct
);
405 } else if(s
->dialect
.compare("swift") == 0) {
406 /* We aren't allocating the account policy for those operations using
407 * the Swift's infrastructure that don't really need req_state::user.
408 * Typical example here is the implementation of /info. */
409 if (!s
->user
->user_id
.empty()) {
410 s
->user_acl
= std::unique_ptr
<RGWAccessControlPolicy
>(
411 new RGWAccessControlPolicy_SWIFTAcct(s
->cct
));
413 s
->bucket_acl
= new RGWAccessControlPolicy_SWIFT(s
->cct
);
415 s
->bucket_acl
= new RGWAccessControlPolicy(s
->cct
);
418 /* check if copy source is within the current domain */
419 if (!s
->src_bucket_name
.empty()) {
420 RGWBucketInfo source_info
;
422 if (s
->bucket_instance_id
.empty()) {
423 ret
= store
->get_bucket_info(obj_ctx
, s
->src_tenant_name
, s
->src_bucket_name
, source_info
, NULL
);
425 ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, source_info
, NULL
, NULL
);
428 string
& zonegroup
= source_info
.zonegroup
;
429 s
->local_source
= store
->get_zonegroup().equals(zonegroup
);
435 std::string display_name
;
438 s
->user
->display_name
,
441 if (!s
->bucket_name
.empty()) {
442 s
->bucket_exists
= true;
443 if (s
->bucket_instance_id
.empty()) {
444 ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
, s
->bucket_info
, NULL
, &s
->bucket_attrs
);
446 ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, s
->bucket_info
, NULL
, &s
->bucket_attrs
);
449 if (ret
!= -ENOENT
) {
451 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_log
);
452 ldout(s
->cct
, 0) << "NOTICE: couldn't get bucket from bucket_name (name=" << bucket_log
<< ")" << dendl
;
455 s
->bucket_exists
= false;
457 s
->bucket
= s
->bucket_info
.bucket
;
459 if (s
->bucket_exists
) {
460 ret
= read_bucket_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
, s
->bucket_acl
, s
->bucket
);
462 s
->bucket_info
.owner
,
463 s
->bucket_acl
->get_owner().get_display_name(),
466 s
->bucket_acl
->create_default(s
->user
->user_id
, s
->user
->display_name
);
467 ret
= -ERR_NO_SUCH_BUCKET
;
470 s
->bucket_owner
= s
->bucket_acl
->get_owner();
472 RGWZoneGroup zonegroup
;
473 int r
= store
->get_zonegroup(s
->bucket_info
.zonegroup
, zonegroup
);
475 if (!zonegroup
.endpoints
.empty()) {
476 s
->zonegroup_endpoint
= zonegroup
.endpoints
.front();
478 // use zonegroup's master zone endpoints
479 auto z
= zonegroup
.zones
.find(zonegroup
.master_zone
);
480 if (z
!= zonegroup
.zones
.end() && !z
->second
.endpoints
.empty()) {
481 s
->zonegroup_endpoint
= z
->second
.endpoints
.front();
484 s
->zonegroup_name
= zonegroup
.get_name();
486 if (r
< 0 && ret
== 0) {
490 if (s
->bucket_exists
&& !store
->get_zonegroup().equals(s
->bucket_info
.zonegroup
)) {
491 ldout(s
->cct
, 0) << "NOTICE: request for data in a different zonegroup (" << s
->bucket_info
.zonegroup
<< " != " << store
->get_zonegroup().get_id() << ")" << dendl
;
492 /* we now need to make sure that the operation actually requires copy source, that is
493 * it's a copy operation
495 if (store
->get_zonegroup().is_master_zonegroup() && s
->system_request
) {
496 /*If this is the master, don't redirect*/
497 } else if (!s
->local_source
||
498 (s
->op
!= OP_PUT
&& s
->op
!= OP_COPY
) ||
500 return -ERR_PERMANENT_REDIRECT
;
505 /* handle user ACL only for those APIs which support it */
507 map
<string
, bufferlist
> uattrs
;
509 ret
= rgw_get_user_attrs_by_uid(store
, acct_acl_user
.uid
, uattrs
);
511 ret
= get_user_policy_from_attr(s
->cct
, store
, uattrs
, *s
->user_acl
);
513 if (-ENOENT
== ret
) {
514 /* In already existing clusters users won't have ACL. In such case
515 * assuming that only account owner has the rights seems to be
516 * reasonable. That allows to have only one verification logic.
517 * NOTE: there is small compatibility kludge for global, empty tenant:
518 * 1. if we try to reach an existing bucket, its owner is considered
520 * 2. otherwise account owner is identity stored in s->user->user_id. */
521 s
->user_acl
->create_default(acct_acl_user
.uid
,
522 acct_acl_user
.display_name
);
525 ldout(s
->cct
, 0) << "NOTICE: couldn't get user attrs for handling ACL (user_id="
535 s
->iam_policy
= get_iam_policy_from_attr(s
->cct
, store
, s
->bucket_attrs
,
537 } catch (const std::exception
& e
) {
538 // Really this is a can't happen condition. We parse the policy
539 // when it's given to us, so perhaps we should abort or otherwise
540 // raise bloody murder.
541 lderr(s
->cct
) << "Error reading IAM Policy: " << e
.what() << dendl
;
549 * Get the AccessControlPolicy for a bucket or object off of disk.
550 * s: The req_state to draw information from.
551 * only_bucket: If true, reads the bucket ACL rather than the object ACL.
552 * Returns: 0 on success, -ERR# otherwise.
554 int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
559 if (!s
->object
.empty()) {
560 if (!s
->bucket_exists
) {
561 return -ERR_NO_SUCH_BUCKET
;
563 s
->object_acl
= new RGWAccessControlPolicy(s
->cct
);
565 rgw_obj
obj(s
->bucket
, s
->object
);
567 store
->set_atomic(s
->obj_ctx
, obj
);
569 store
->set_prefetch_data(s
->obj_ctx
, obj
);
571 ret
= read_obj_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
, s
->object_acl
, s
->iam_policy
, s
->bucket
, s
->object
);
577 rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
580 rgw::IAM::Environment e
;
581 const auto& m
= s
->info
.env
->get_map();
582 auto t
= ceph::real_clock::now();
583 e
.emplace(std::piecewise_construct
,
584 std::forward_as_tuple("aws:CurrentTime"),
585 std::forward_as_tuple(std::to_string(
586 ceph::real_clock::to_time_t(t
))));
587 e
.emplace(std::piecewise_construct
,
588 std::forward_as_tuple("aws:EpochTime"),
589 std::forward_as_tuple(ceph::to_iso_8601(t
)));
590 // TODO: This is fine for now, but once we have STS we'll need to
591 // look and see. Also this won't work with the IdentityApplier
592 // model, since we need to know the actual credential.
593 e
.emplace(std::piecewise_construct
,
594 std::forward_as_tuple("aws:PrincipalType"),
595 std::forward_as_tuple("User"));
597 auto i
= m
.find("HTTP_REFERER");
599 e
.emplace(std::piecewise_construct
,
600 std::forward_as_tuple("aws:Referer"),
601 std::forward_as_tuple(i
->second
));
604 // These seem to be the semantics, judging from rest_rgw_s3.cc
605 i
= m
.find("SERVER_PORT_SECURE");
607 e
.emplace(std::piecewise_construct
,
608 std::forward_as_tuple("aws:SecureTransport"),
609 std::forward_as_tuple("true"));
612 i
= m
.find("HTTP_HOST");
614 e
.emplace(std::piecewise_construct
,
615 std::forward_as_tuple("aws:SourceIp"),
616 std::forward_as_tuple(i
->second
));
619 i
= m
.find("HTTP_USER_AGENT"); {
621 e
.emplace(std::piecewise_construct
,
622 std::forward_as_tuple("aws:UserAgent"),
623 std::forward_as_tuple(i
->second
));
627 // What to do about aws::userid? One can have multiple access
628 // keys so that isn't really suitable. Do we have a durable
629 // identifier that can persist through name changes?
630 e
.emplace(std::piecewise_construct
,
631 std::forward_as_tuple("aws:username"),
632 std::forward_as_tuple(s
->user
->user_id
.id
));
637 void rgw_bucket_object_pre_exec(struct req_state
*s
)
642 dump_bucket_from_state(s
);
645 int RGWGetObj::verify_permission()
647 obj
= rgw_obj(s
->bucket
, s
->object
);
648 store
->set_atomic(s
->obj_ctx
, obj
);
650 store
->set_prefetch_data(s
->obj_ctx
, obj
);
653 if (torrent
.get_flag()) {
654 if (obj
.key
.instance
.empty()) {
655 action
= rgw::IAM::s3GetObjectTorrent
;
657 action
= rgw::IAM::s3GetObjectVersionTorrent
;
660 if (obj
.key
.instance
.empty()) {
661 action
= rgw::IAM::s3GetObject
;
663 action
= rgw::IAM::s3GetObjectVersion
;
667 if (!verify_object_permission(s
, action
)) {
675 int RGWOp::verify_op_mask()
677 uint32_t required_mask
= op_mask();
679 ldout(s
->cct
, 20) << "required_mask= " << required_mask
680 << " user.op_mask=" << s
->user
->op_mask
<< dendl
;
682 if ((s
->user
->op_mask
& required_mask
) != required_mask
) {
686 if (!s
->system_request
&& (required_mask
& RGW_OP_TYPE_MODIFY
) && !store
->zone_is_writeable()) {
687 ldout(s
->cct
, 5) << "NOTICE: modify request to a read-only zone by a non-system user, permission denied" << dendl
;
694 int RGWGetObjTags::verify_permission()
696 if (!verify_object_permission(s
,
697 s
->object
.instance
.empty() ?
698 rgw::IAM::s3GetObjectTagging
:
699 rgw::IAM::s3GetObjectVersionTagging
))
705 void RGWGetObjTags::pre_exec()
707 rgw_bucket_object_pre_exec(s
);
710 void RGWGetObjTags::execute()
713 map
<string
,bufferlist
> attrs
;
715 obj
= rgw_obj(s
->bucket
, s
->object
);
717 store
->set_atomic(s
->obj_ctx
, obj
);
719 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
720 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
721 if(tags
!= attrs
.end()){
723 tags_bl
.append(tags
->second
);
725 send_response_data(tags_bl
);
728 int RGWPutObjTags::verify_permission()
730 if (!verify_object_permission(s
,
731 s
->object
.instance
.empty() ?
732 rgw::IAM::s3PutObjectTagging
:
733 rgw::IAM::s3PutObjectVersionTagging
))
738 void RGWPutObjTags::execute()
740 op_ret
= get_params();
744 if (s
->object
.empty()){
745 op_ret
= -EINVAL
; // we only support tagging on existing objects
750 obj
= rgw_obj(s
->bucket
, s
->object
);
751 store
->set_atomic(s
->obj_ctx
, obj
);
752 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_TAGS
, tags_bl
);
753 if (op_ret
== -ECANCELED
){
754 op_ret
= -ERR_TAG_CONFLICT
;
758 void RGWDeleteObjTags::pre_exec()
760 rgw_bucket_object_pre_exec(s
);
764 int RGWDeleteObjTags::verify_permission()
766 if (!s
->object
.empty()) {
767 if (!verify_object_permission(s
,
768 s
->object
.instance
.empty() ?
769 rgw::IAM::s3DeleteObjectTagging
:
770 rgw::IAM::s3DeleteObjectVersionTagging
))
776 void RGWDeleteObjTags::execute()
778 if (s
->object
.empty())
782 obj
= rgw_obj(s
->bucket
, s
->object
);
783 store
->set_atomic(s
->obj_ctx
, obj
);
784 map
<string
, bufferlist
> attrs
;
785 map
<string
, bufferlist
> rmattr
;
787 rmattr
[RGW_ATTR_TAGS
] = bl
;
788 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattr
);
791 int RGWOp::do_aws4_auth_completion()
793 ldout(s
->cct
, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl
;
794 if (s
->auth
.completer
) {
795 if (!s
->auth
.completer
->complete()) {
796 return -ERR_AMZ_CONTENT_SHA256_MISMATCH
;
798 dout(10) << "v4 auth ok -- do_aws4_auth_completion" << dendl
;
801 /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first
802 * call passes, so we disable second one. This is old behaviour, sorry!
803 * Plan for tomorrow: seek and destroy. */
804 s
->auth
.completer
= nullptr;
810 int RGWOp::init_quota()
812 /* no quota enforcement for system requests */
813 if (s
->system_request
)
816 /* init quota related stuff */
817 if (!(s
->user
->op_mask
& RGW_OP_TYPE_MODIFY
)) {
821 /* only interested in object related ops */
822 if (s
->object
.empty()) {
826 RGWUserInfo owner_info
;
829 if (s
->user
->user_id
== s
->bucket_owner
.get_id()) {
832 int r
= rgw_get_user_info_by_uid(store
, s
->bucket_info
.owner
, owner_info
);
838 if (s
->bucket_info
.quota
.enabled
) {
839 bucket_quota
= s
->bucket_info
.quota
;
840 } else if (uinfo
->bucket_quota
.enabled
) {
841 bucket_quota
= uinfo
->bucket_quota
;
843 bucket_quota
= store
->get_bucket_quota();
846 if (uinfo
->user_quota
.enabled
) {
847 user_quota
= uinfo
->user_quota
;
849 user_quota
= store
->get_user_quota();
855 static bool validate_cors_rule_method(RGWCORSRule
*rule
, const char *req_meth
) {
859 dout(5) << "req_meth is null" << dendl
;
863 if (strcmp(req_meth
, "GET") == 0) flags
= RGW_CORS_GET
;
864 else if (strcmp(req_meth
, "POST") == 0) flags
= RGW_CORS_POST
;
865 else if (strcmp(req_meth
, "PUT") == 0) flags
= RGW_CORS_PUT
;
866 else if (strcmp(req_meth
, "DELETE") == 0) flags
= RGW_CORS_DELETE
;
867 else if (strcmp(req_meth
, "HEAD") == 0) flags
= RGW_CORS_HEAD
;
869 if ((rule
->get_allowed_methods() & flags
) == flags
) {
870 dout(10) << "Method " << req_meth
<< " is supported" << dendl
;
872 dout(5) << "Method " << req_meth
<< " is not supported" << dendl
;
879 int RGWOp::read_bucket_cors()
883 map
<string
, bufferlist
>::iterator aiter
= s
->bucket_attrs
.find(RGW_ATTR_CORS
);
884 if (aiter
== s
->bucket_attrs
.end()) {
885 ldout(s
->cct
, 20) << "no CORS configuration attr found" << dendl
;
887 return 0; /* no CORS configuration found */
894 bufferlist::iterator iter
= bl
.begin();
896 bucket_cors
.decode(iter
);
897 } catch (buffer::error
& err
) {
898 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
901 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
902 RGWCORSConfiguration_S3
*s3cors
= static_cast<RGWCORSConfiguration_S3
*>(&bucket_cors
);
903 ldout(s
->cct
, 15) << "Read RGWCORSConfiguration";
904 s3cors
->to_xml(*_dout
);
911 * If any of the header field-names is not a ASCII case-insensitive match for
912 * any of the values in list of headers do not set any additional headers and
913 * terminate this set of steps.
915 static void get_cors_response_headers(RGWCORSRule
*rule
, const char *req_hdrs
, string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
918 get_str_list(req_hdrs
, hl
);
919 for(list
<string
>::iterator it
= hl
.begin(); it
!= hl
.end(); ++it
) {
920 if (!rule
->is_header_allowed((*it
).c_str(), (*it
).length())) {
921 dout(5) << "Header " << (*it
) << " is not registered in this rule" << dendl
;
923 if (hdrs
.length() > 0) hdrs
.append(",");
928 rule
->format_exp_headers(exp_hdrs
);
929 *max_age
= rule
->get_max_age();
933 * Generate the CORS header response
935 * This is described in the CORS standard, section 6.2.
937 bool RGWOp::generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
)
940 const char *orig
= s
->info
.env
->get("HTTP_ORIGIN");
947 op_ret
= read_bucket_cors();
953 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
958 RGWCORSRule
*rule
= bucket_cors
.host_name_rule(orig
);
963 * Set the Allowed-Origin header to a asterisk if this is allowed in the rule
964 * and no Authorization was send by the client
966 * The origin parameter specifies a URI that may access the resource. The browser must enforce this.
967 * For requests without credentials, the server may specify "*" as a wildcard,
968 * thereby allowing any origin to access the resource.
970 const char *authorization
= s
->info
.env
->get("HTTP_AUTHORIZATION");
971 if (!authorization
&& rule
->has_wildcard_origin())
975 const char *req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
977 req_meth
= s
->info
.method
;
983 if (!validate_cors_rule_method(rule
, req_meth
)) {
989 const char *req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
992 get_cors_response_headers(rule
, req_hdrs
, headers
, exp_headers
, max_age
);
997 int RGWGetObj::read_user_manifest_part(rgw_bucket
& bucket
,
998 const rgw_bucket_dir_entry
& ent
,
999 RGWAccessControlPolicy
* const bucket_acl
,
1000 const optional
<Policy
>& bucket_policy
,
1001 const off_t start_ofs
,
1002 const off_t end_ofs
)
1004 ldout(s
->cct
, 20) << "user manifest obj=" << ent
.key
.name
<< "[" << ent
.key
.instance
<< "]" << dendl
;
1005 RGWGetObj_CB
cb(this);
1006 RGWGetDataCB
* filter
= &cb
;
1007 boost::optional
<RGWGetObj_Decompress
> decompress
;
1009 int64_t cur_ofs
= start_ofs
;
1010 int64_t cur_end
= end_ofs
;
1012 rgw_obj
part(bucket
, ent
.key
);
1014 map
<string
, bufferlist
> attrs
;
1017 RGWObjectCtx
obj_ctx(store
);
1018 RGWAccessControlPolicy
obj_policy(s
->cct
);
1020 ldout(s
->cct
, 20) << "reading obj=" << part
<< " ofs=" << cur_ofs
<< " end=" << cur_end
<< dendl
;
1022 obj_ctx
.obj
.set_atomic(part
);
1023 store
->set_prefetch_data(&obj_ctx
, part
);
1025 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, part
);
1026 RGWRados::Object::Read
read_op(&op_target
);
1028 read_op
.conds
.if_match
= ent
.meta
.etag
.c_str();
1029 read_op
.params
.attrs
= &attrs
;
1030 read_op
.params
.obj_size
= &obj_size
;
1032 op_ret
= read_op
.prepare();
1035 op_ret
= read_op
.range_to_ofs(ent
.meta
.accounted_size
, cur_ofs
, cur_end
);
1038 bool need_decompress
;
1039 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1041 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1045 if (need_decompress
)
1047 if (cs_info
.orig_size
!= ent
.meta
.accounted_size
) {
1048 // hmm.. something wrong, object not as expected, abort!
1049 ldout(s
->cct
, 0) << "ERROR: expected cs_info.orig_size=" << cs_info
.orig_size
<<
1050 ", actual read size=" << ent
.meta
.size
<< dendl
;
1053 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1054 filter
= &*decompress
;
1058 if (obj_size
!= ent
.meta
.size
) {
1059 // hmm.. something wrong, object not as expected, abort!
1060 ldout(s
->cct
, 0) << "ERROR: expected obj_size=" << obj_size
<< ", actual read size=" << ent
.meta
.size
<< dendl
;
1065 op_ret
= rgw_policy_from_attrset(s
->cct
, attrs
, &obj_policy
);
1069 /* We can use global user_acl because LOs cannot have segments
1070 * stored inside different accounts. */
1071 if (s
->system_request
) {
1072 ldout(s
->cct
, 2) << "overriding permissions due to system operation" << dendl
;
1073 } else if (s
->auth
.identity
->is_admin_of(s
->user
->user_id
)) {
1074 ldout(s
->cct
, 2) << "overriding permissions due to admin operation" << dendl
;
1075 } else if (!verify_object_permission(s
, part
, s
->user_acl
.get(), bucket_acl
,
1076 &obj_policy
, bucket_policy
, action
)) {
1080 if (ent
.meta
.size
== 0) {
1084 perfcounter
->inc(l_rgw_get_b
, cur_end
- cur_ofs
);
1085 filter
->fixup_range(cur_ofs
, cur_end
);
1086 op_ret
= read_op
.iterate(cur_ofs
, cur_end
, filter
);
1088 op_ret
= filter
->flush();
1092 static int iterate_user_manifest_parts(CephContext
* const cct
,
1093 RGWRados
* const store
,
1096 RGWBucketInfo
*pbucket_info
,
1097 const string
& obj_prefix
,
1098 RGWAccessControlPolicy
* const bucket_acl
,
1099 const optional
<Policy
>& bucket_policy
,
1100 uint64_t * const ptotal_len
,
1101 uint64_t * const pobj_size
,
1102 string
* const pobj_sum
,
1103 int (*cb
)(rgw_bucket
& bucket
,
1104 const rgw_bucket_dir_entry
& ent
,
1105 RGWAccessControlPolicy
* const bucket_acl
,
1106 const optional
<Policy
>& bucket_policy
,
1110 void * const cb_param
)
1112 rgw_bucket
& bucket
= pbucket_info
->bucket
;
1113 uint64_t obj_ofs
= 0, len_count
= 0;
1114 bool found_start
= false, found_end
= false, handled_end
= false;
1117 vector
<rgw_bucket_dir_entry
> objs
;
1119 utime_t start_time
= ceph_clock_now();
1121 RGWRados::Bucket
target(store
, *pbucket_info
);
1122 RGWRados::Bucket::List
list_op(&target
);
1124 list_op
.params
.prefix
= obj_prefix
;
1125 list_op
.params
.delim
= delim
;
1129 #define MAX_LIST_OBJS 100
1130 int r
= list_op
.list_objects(MAX_LIST_OBJS
, &objs
, NULL
, &is_truncated
);
1135 for (rgw_bucket_dir_entry
& ent
: objs
) {
1136 const uint64_t cur_total_len
= obj_ofs
;
1137 const uint64_t obj_size
= ent
.meta
.accounted_size
;
1138 uint64_t start_ofs
= 0, end_ofs
= obj_size
;
1140 if ((ptotal_len
|| cb
) && !found_start
&& cur_total_len
+ obj_size
> (uint64_t)ofs
) {
1141 start_ofs
= ofs
- obj_ofs
;
1145 obj_ofs
+= obj_size
;
1147 etag_sum
.Update((const byte
*)ent
.meta
.etag
.c_str(),
1148 ent
.meta
.etag
.length());
1151 if ((ptotal_len
|| cb
) && !found_end
&& obj_ofs
> (uint64_t)end
) {
1152 end_ofs
= end
- cur_total_len
+ 1;
1156 perfcounter
->tinc(l_rgw_get_lat
,
1157 (ceph_clock_now() - start_time
));
1159 if (found_start
&& !handled_end
) {
1160 len_count
+= end_ofs
- start_ofs
;
1163 r
= cb(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
, cb_param
);
1170 handled_end
= found_end
;
1171 start_time
= ceph_clock_now();
1173 } while (is_truncated
);
1176 *ptotal_len
= len_count
;
1179 *pobj_size
= obj_ofs
;
1182 complete_etag(etag_sum
, pobj_sum
);
1188 struct rgw_slo_part
{
1189 RGWAccessControlPolicy
*bucket_acl
= nullptr;
1190 Policy
* bucket_policy
= nullptr;
1197 static int iterate_slo_parts(CephContext
*cct
,
1201 map
<uint64_t, rgw_slo_part
>& slo_parts
,
1202 int (*cb
)(rgw_bucket
& bucket
,
1203 const rgw_bucket_dir_entry
& ent
,
1204 RGWAccessControlPolicy
*bucket_acl
,
1205 const optional
<Policy
>& bucket_policy
,
1211 bool found_start
= false, found_end
= false;
1213 if (slo_parts
.empty()) {
1217 utime_t start_time
= ceph_clock_now();
1219 map
<uint64_t, rgw_slo_part
>::iterator iter
= slo_parts
.upper_bound(ofs
);
1220 if (iter
!= slo_parts
.begin()) {
1224 uint64_t obj_ofs
= iter
->first
;
1226 for (; iter
!= slo_parts
.end() && !found_end
; ++iter
) {
1227 rgw_slo_part
& part
= iter
->second
;
1228 rgw_bucket_dir_entry ent
;
1230 ent
.key
.name
= part
.obj_name
;
1231 ent
.meta
.accounted_size
= ent
.meta
.size
= part
.size
;
1232 ent
.meta
.etag
= part
.etag
;
1234 uint64_t cur_total_len
= obj_ofs
;
1235 uint64_t start_ofs
= 0, end_ofs
= ent
.meta
.size
;
1237 if (!found_start
&& cur_total_len
+ ent
.meta
.size
> (uint64_t)ofs
) {
1238 start_ofs
= ofs
- obj_ofs
;
1242 obj_ofs
+= ent
.meta
.size
;
1244 if (!found_end
&& obj_ofs
> (uint64_t)end
) {
1245 end_ofs
= end
- cur_total_len
+ 1;
1249 perfcounter
->tinc(l_rgw_get_lat
,
1250 (ceph_clock_now() - start_time
));
1254 // SLO is a Swift thing, and Swift has no knowledge of S3 Policies.
1255 int r
= cb(part
.bucket
, ent
, part
.bucket_acl
,
1256 (part
.bucket_policy
?
1257 optional
<Policy
>(*part
.bucket_policy
) : none
),
1258 start_ofs
, end_ofs
, cb_param
);
1264 start_time
= ceph_clock_now();
1270 static int get_obj_user_manifest_iterate_cb(rgw_bucket
& bucket
,
1271 const rgw_bucket_dir_entry
& ent
,
1272 RGWAccessControlPolicy
* const bucket_acl
,
1273 const optional
<Policy
>& bucket_policy
,
1274 const off_t start_ofs
,
1275 const off_t end_ofs
,
1278 RGWGetObj
*op
= static_cast<RGWGetObj
*>(param
);
1279 return op
->read_user_manifest_part(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
);
1282 int RGWGetObj::handle_user_manifest(const char *prefix
)
1284 const boost::string_view
prefix_view(prefix
);
1285 ldout(s
->cct
, 2) << "RGWGetObj::handle_user_manifest() prefix="
1286 << prefix_view
<< dendl
;
1288 const size_t pos
= prefix_view
.find('/');
1289 if (pos
== string::npos
) {
1293 const std::string bucket_name
= url_decode(prefix_view
.substr(0, pos
));
1294 const std::string obj_prefix
= url_decode(prefix_view
.substr(pos
+ 1));
1298 RGWAccessControlPolicy
_bucket_acl(s
->cct
);
1299 RGWAccessControlPolicy
*bucket_acl
;
1300 optional
<Policy
> _bucket_policy
;
1301 optional
<Policy
>* bucket_policy
;
1302 RGWBucketInfo bucket_info
;
1303 RGWBucketInfo
*pbucket_info
;
1305 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1306 map
<string
, bufferlist
> bucket_attrs
;
1307 RGWObjectCtx
obj_ctx(store
);
1308 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1309 bucket_name
, bucket_info
, NULL
,
1312 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1313 << bucket_name
<< dendl
;
1316 bucket
= bucket_info
.bucket
;
1317 pbucket_info
= &bucket_info
;
1318 bucket_acl
= &_bucket_acl
;
1319 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
, bucket
);
1321 ldout(s
->cct
, 0) << "failed to read bucket policy" << dendl
;
1324 _bucket_policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
,
1325 bucket_info
.bucket
.tenant
);
1326 bucket_policy
= &_bucket_policy
;
1329 pbucket_info
= &s
->bucket_info
;
1330 bucket_acl
= s
->bucket_acl
;
1331 bucket_policy
= &s
->iam_policy
;
1334 /* dry run to find out:
1335 * - total length (of the parts we are going to send to client),
1336 * - overall DLO's content size,
1337 * - md5 sum of overall DLO's content (for etag of Swift API). */
1338 int r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1339 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1340 nullptr, &s
->obj_size
, &lo_etag
,
1341 nullptr /* cb */, nullptr /* cb arg */);
1346 r
= RGWRados::Object::Read::range_to_ofs(s
->obj_size
, ofs
, end
);
1351 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1352 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1353 &total_len
, nullptr, nullptr,
1361 send_response_data(bl
, 0, 0);
1365 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1366 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1367 nullptr, nullptr, nullptr,
1368 get_obj_user_manifest_iterate_cb
, (void *)this);
1375 send_response_data(bl
, 0, 0);
1381 int RGWGetObj::handle_slo_manifest(bufferlist
& bl
)
1383 RGWSLOInfo slo_info
;
1384 bufferlist::iterator bliter
= bl
.begin();
1386 ::decode(slo_info
, bliter
);
1387 } catch (buffer::error
& err
) {
1388 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
1391 ldout(s
->cct
, 2) << "RGWGetObj::handle_slo_manifest()" << dendl
;
1393 vector
<RGWAccessControlPolicy
> allocated_acls
;
1394 map
<string
, pair
<RGWAccessControlPolicy
*, optional
<Policy
>>> policies
;
1395 map
<string
, rgw_bucket
> buckets
;
1397 map
<uint64_t, rgw_slo_part
> slo_parts
;
1402 for (const auto& entry
: slo_info
.entries
) {
1403 const string
& path
= entry
.path
;
1405 /* If the path starts with slashes, strip them all. */
1406 const size_t pos_init
= path
.find_first_not_of('/');
1407 /* According to the documentation of std::string::find following check
1408 * is not necessary as we should get the std::string::npos propagation
1409 * here. This might be true with the accuracy to implementation's bugs.
1410 * See following question on SO:
1411 * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos
1413 if (pos_init
== string::npos
) {
1417 const size_t pos_sep
= path
.find('/', pos_init
);
1418 if (pos_sep
== string::npos
) {
1422 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
1423 string obj_name
= path
.substr(pos_sep
+ 1);
1426 RGWAccessControlPolicy
*bucket_acl
;
1427 Policy
* bucket_policy
;
1429 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1430 const auto& piter
= policies
.find(bucket_name
);
1431 if (piter
!= policies
.end()) {
1432 bucket_acl
= piter
->second
.first
;
1433 bucket_policy
= piter
->second
.second
.get_ptr();
1434 bucket
= buckets
[bucket_name
];
1436 allocated_acls
.push_back(RGWAccessControlPolicy(s
->cct
));
1437 RGWAccessControlPolicy
& _bucket_acl
= allocated_acls
.back();
1439 RGWBucketInfo bucket_info
;
1440 map
<string
, bufferlist
> bucket_attrs
;
1441 RGWObjectCtx
obj_ctx(store
);
1442 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1443 bucket_name
, bucket_info
, nullptr,
1446 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1447 << bucket_name
<< dendl
;
1450 bucket
= bucket_info
.bucket
;
1451 bucket_acl
= &_bucket_acl
;
1452 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
,
1455 ldout(s
->cct
, 0) << "failed to read bucket ACL for bucket "
1459 auto _bucket_policy
= get_iam_policy_from_attr(
1460 s
->cct
, store
, bucket_attrs
, bucket_info
.bucket
.tenant
);
1461 bucket_policy
= _bucket_policy
.get_ptr();
1462 buckets
[bucket_name
] = bucket
;
1463 policies
[bucket_name
] = make_pair(bucket_acl
, _bucket_policy
);
1467 bucket_acl
= s
->bucket_acl
;
1468 bucket_policy
= s
->iam_policy
.get_ptr();
1472 part
.bucket_acl
= bucket_acl
;
1473 part
.bucket_policy
= bucket_policy
;
1474 part
.bucket
= bucket
;
1475 part
.obj_name
= obj_name
;
1476 part
.size
= entry
.size_bytes
;
1477 part
.etag
= entry
.etag
;
1478 ldout(s
->cct
, 20) << "slo_part: ofs=" << ofs
1479 << " bucket=" << part
.bucket
1480 << " obj=" << part
.obj_name
1481 << " size=" << part
.size
1482 << " etag=" << part
.etag
1485 etag_sum
.Update((const byte
*)entry
.etag
.c_str(),
1486 entry
.etag
.length());
1488 slo_parts
[total_len
] = part
;
1489 total_len
+= part
.size
;
1492 complete_etag(etag_sum
, &lo_etag
);
1494 s
->obj_size
= slo_info
.total_size
;
1495 ldout(s
->cct
, 20) << "s->obj_size=" << s
->obj_size
<< dendl
;
1497 int r
= RGWRados::Object::Read::range_to_ofs(total_len
, ofs
, end
);
1502 total_len
= end
- ofs
+ 1;
1504 r
= iterate_slo_parts(s
->cct
, store
, ofs
, end
, slo_parts
,
1505 get_obj_user_manifest_iterate_cb
, (void *)this);
1513 int RGWGetObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
1515 /* garbage collection related handling */
1516 utime_t start_time
= ceph_clock_now();
1517 if (start_time
> gc_invalidate_time
) {
1518 int r
= store
->defer_gc(s
->obj_ctx
, s
->bucket_info
, obj
);
1520 dout(0) << "WARNING: could not defer gc entry for obj" << dendl
;
1522 gc_invalidate_time
= start_time
;
1523 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1525 return send_response_data(bl
, bl_ofs
, bl_len
);
1528 bool RGWGetObj::prefetch_data()
1530 /* HEAD request, stop prefetch*/
1535 bool prefetch_first_chunk
= true;
1536 range_str
= s
->info
.env
->get("HTTP_RANGE");
1539 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1540 /* error on parsing the range, stop prefetch and will fail in execte() */
1542 range_parsed
= false;
1545 range_parsed
= true;
1547 /* range get goes to shadown objects, stop prefetch */
1548 if (ofs
>= s
->cct
->_conf
->rgw_max_chunk_size
) {
1549 prefetch_first_chunk
= false;
1553 return get_data
&& prefetch_first_chunk
;
1555 void RGWGetObj::pre_exec()
1557 rgw_bucket_object_pre_exec(s
);
1560 static bool object_is_expired(map
<string
, bufferlist
>& attrs
) {
1561 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1562 if (iter
!= attrs
.end()) {
1565 ::decode(delete_at
, iter
->second
);
1566 } catch (buffer::error
& err
) {
1567 dout(0) << "ERROR: " << __func__
<< ": failed to decode " RGW_ATTR_DELETE_AT
" attr" << dendl
;
1571 if (delete_at
<= ceph_clock_now() && !delete_at
.is_zero()) {
1579 void RGWGetObj::execute()
1581 utime_t start_time
= s
->time
;
1583 gc_invalidate_time
= ceph_clock_now();
1584 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1586 bool need_decompress
;
1587 int64_t ofs_x
, end_x
;
1589 RGWGetObj_CB
cb(this);
1590 RGWGetDataCB
* filter
= (RGWGetDataCB
*)&cb
;
1591 boost::optional
<RGWGetObj_Decompress
> decompress
;
1592 std::unique_ptr
<RGWGetDataCB
> decrypt
;
1593 map
<string
, bufferlist
>::iterator attr_iter
;
1595 perfcounter
->inc(l_rgw_get
);
1597 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
1598 RGWRados::Object::Read
read_op(&op_target
);
1600 op_ret
= get_params();
1604 op_ret
= init_common();
1608 read_op
.conds
.mod_ptr
= mod_ptr
;
1609 read_op
.conds
.unmod_ptr
= unmod_ptr
;
1610 read_op
.conds
.high_precision_time
= s
->system_request
; /* system request need to use high precision time */
1611 read_op
.conds
.mod_zone_id
= mod_zone_id
;
1612 read_op
.conds
.mod_pg_ver
= mod_pg_ver
;
1613 read_op
.conds
.if_match
= if_match
;
1614 read_op
.conds
.if_nomatch
= if_nomatch
;
1615 read_op
.params
.attrs
= &attrs
;
1616 read_op
.params
.lastmod
= &lastmod
;
1617 read_op
.params
.obj_size
= &s
->obj_size
;
1619 op_ret
= read_op
.prepare();
1622 version_id
= read_op
.state
.obj
.key
.instance
;
1624 /* STAT ops don't need data, and do no i/o */
1625 if (get_type() == RGW_OP_STAT_OBJ
) {
1629 /* start gettorrent */
1630 if (torrent
.get_flag())
1632 torrent
.init(s
, store
);
1633 torrent
.get_torrent_file(op_ret
, read_op
, total_len
, bl
, obj
);
1636 ldout(s
->cct
, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
1640 op_ret
= send_response_data(bl
, 0, total_len
);
1643 ldout(s
->cct
, 0) << "ERROR: failed to send_response_data ret= " << op_ret
1649 /* end gettorrent */
1651 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1653 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1656 if (need_decompress
) {
1657 s
->obj_size
= cs_info
.orig_size
;
1658 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1659 filter
= &*decompress
;
1662 attr_iter
= attrs
.find(RGW_ATTR_USER_MANIFEST
);
1663 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1664 op_ret
= handle_user_manifest(attr_iter
->second
.c_str());
1666 ldout(s
->cct
, 0) << "ERROR: failed to handle user manifest ret="
1673 attr_iter
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
1674 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1676 op_ret
= handle_slo_manifest(attr_iter
->second
);
1678 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
1685 // for range requests with obj size 0
1686 if (range_str
&& !(s
->obj_size
)) {
1692 op_ret
= read_op
.range_to_ofs(s
->obj_size
, ofs
, end
);
1695 total_len
= (ofs
<= end
? end
+ 1 - ofs
: 0);
1697 /* Check whether the object has expired. Swift API documentation
1698 * stands that we should return 404 Not Found in such case. */
1699 if (need_object_expiration() && object_is_expired(attrs
)) {
1706 /* STAT ops don't need data, and do no i/o */
1707 if (get_type() == RGW_OP_STAT_OBJ
) {
1711 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1712 op_ret
= this->get_decrypt_filter(&decrypt
, filter
,
1713 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
1714 if (decrypt
!= nullptr) {
1715 filter
= decrypt
.get();
1721 if (!get_data
|| ofs
> end
) {
1722 send_response_data(bl
, 0, 0);
1726 perfcounter
->inc(l_rgw_get_b
, end
- ofs
);
1730 filter
->fixup_range(ofs_x
, end_x
);
1731 op_ret
= read_op
.iterate(ofs_x
, end_x
, filter
);
1734 op_ret
= filter
->flush();
1736 perfcounter
->tinc(l_rgw_get_lat
,
1737 (ceph_clock_now() - start_time
));
1742 op_ret
= send_response_data(bl
, 0, 0);
1749 send_response_data_error();
1752 int RGWGetObj::init_common()
1755 /* range parsed error when prefetch*/
1756 if (!range_parsed
) {
1757 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1763 if (parse_time(if_mod
, &mod_time
) < 0)
1765 mod_ptr
= &mod_time
;
1769 if (parse_time(if_unmod
, &unmod_time
) < 0)
1771 unmod_ptr
= &unmod_time
;
1777 int RGWListBuckets::verify_permission()
1779 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1786 int RGWGetUsage::verify_permission()
1788 if (s
->auth
.identity
->is_anonymous()) {
1795 void RGWListBuckets::execute()
1798 bool started
= false;
1799 uint64_t total_count
= 0;
1801 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1803 op_ret
= get_params();
1808 if (supports_account_metadata()) {
1809 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, attrs
);
1815 is_truncated
= false;
1817 RGWUserBuckets buckets
;
1818 uint64_t read_count
;
1820 read_count
= min(limit
- total_count
, (uint64_t)max_buckets
);
1822 read_count
= max_buckets
;
1825 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
1826 marker
, end_marker
, read_count
,
1827 should_get_stats(), &is_truncated
,
1830 /* hmm.. something wrong here.. the user was authenticated, so it
1832 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1833 << s
->user
->user_id
<< dendl
;
1836 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1837 map
<string
, RGWBucketEnt
>::iterator iter
;
1838 for (iter
= m
.begin(); iter
!= m
.end(); ++iter
) {
1839 RGWBucketEnt
& bucket
= iter
->second
;
1840 buckets_size
+= bucket
.size
;
1841 buckets_size_rounded
+= bucket
.size_rounded
;
1842 buckets_objcount
+= bucket
.count
;
1844 buckets_count
+= m
.size();
1845 total_count
+= m
.size();
1847 done
= (m
.size() < read_count
|| (limit
>= 0 && total_count
>= (uint64_t)limit
));
1850 send_response_begin(buckets
.count() > 0);
1855 send_response_data(buckets
);
1857 map
<string
, RGWBucketEnt
>::reverse_iterator riter
= m
.rbegin();
1858 marker
= riter
->first
;
1860 } while (is_truncated
&& !done
);
1864 send_response_begin(false);
1866 send_response_end();
1869 void RGWGetUsage::execute()
1871 uint64_t start_epoch
= 0;
1872 uint64_t end_epoch
= (uint64_t)-1;
1873 op_ret
= get_params();
1877 if (!start_date
.empty()) {
1878 op_ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
1880 ldout(store
->ctx(), 0) << "ERROR: failed to parse start date" << dendl
;
1885 if (!end_date
.empty()) {
1886 op_ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
1888 ldout(store
->ctx(), 0) << "ERROR: failed to parse end date" << dendl
;
1893 uint32_t max_entries
= 1000;
1895 bool is_truncated
= true;
1897 RGWUsageIter usage_iter
;
1899 while (is_truncated
) {
1900 op_ret
= store
->read_usage(s
->user
->user_id
, start_epoch
, end_epoch
, max_entries
,
1901 &is_truncated
, usage_iter
, usage
);
1903 if (op_ret
== -ENOENT
) {
1905 is_truncated
= false;
1913 op_ret
= rgw_user_sync_all_stats(store
, s
->user
->user_id
);
1915 ldout(store
->ctx(), 0) << "ERROR: failed to sync user stats: " << dendl
;
1919 string user_str
= s
->user
->user_id
.to_str();
1920 op_ret
= store
->cls_user_get_header(user_str
, &header
);
1922 ldout(store
->ctx(), 0) << "ERROR: can't read user header: " << dendl
;
1929 int RGWStatAccount::verify_permission()
1931 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1938 void RGWStatAccount::execute()
1941 bool is_truncated
= false;
1942 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1945 RGWUserBuckets buckets
;
1947 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
, marker
,
1948 string(), max_buckets
, true, &is_truncated
);
1950 /* hmm.. something wrong here.. the user was authenticated, so it
1952 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1953 << s
->user
->user_id
<< dendl
;
1956 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1957 map
<string
, RGWBucketEnt
>::iterator iter
;
1958 for (iter
= m
.begin(); iter
!= m
.end(); ++iter
) {
1959 RGWBucketEnt
& bucket
= iter
->second
;
1960 buckets_size
+= bucket
.size
;
1961 buckets_size_rounded
+= bucket
.size_rounded
;
1962 buckets_objcount
+= bucket
.count
;
1964 marker
= iter
->first
;
1966 buckets_count
+= m
.size();
1969 } while (is_truncated
);
1972 int RGWGetBucketVersioning::verify_permission()
1974 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
1981 void RGWGetBucketVersioning::pre_exec()
1983 rgw_bucket_object_pre_exec(s
);
1986 void RGWGetBucketVersioning::execute()
1988 versioned
= s
->bucket_info
.versioned();
1989 versioning_enabled
= s
->bucket_info
.versioning_enabled();
1992 int RGWSetBucketVersioning::verify_permission()
1994 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2001 void RGWSetBucketVersioning::pre_exec()
2003 rgw_bucket_object_pre_exec(s
);
2006 void RGWSetBucketVersioning::execute()
2008 op_ret
= get_params();
2012 if (!store
->is_meta_master()) {
2013 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2015 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
2020 if (enable_versioning
) {
2021 s
->bucket_info
.flags
|= BUCKET_VERSIONED
;
2022 s
->bucket_info
.flags
&= ~BUCKET_VERSIONS_SUSPENDED
;
2024 s
->bucket_info
.flags
|= (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
);
2027 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
2030 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2031 << " returned err=" << op_ret
<< dendl
;
2036 int RGWGetBucketWebsite::verify_permission()
2038 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2044 void RGWGetBucketWebsite::pre_exec()
2046 rgw_bucket_object_pre_exec(s
);
2049 void RGWGetBucketWebsite::execute()
2051 if (!s
->bucket_info
.has_website
) {
2056 int RGWSetBucketWebsite::verify_permission()
2058 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2064 void RGWSetBucketWebsite::pre_exec()
2066 rgw_bucket_object_pre_exec(s
);
2069 void RGWSetBucketWebsite::execute()
2071 op_ret
= get_params();
2076 if (!store
->is_meta_master()) {
2077 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2079 ldout(s
->cct
, 20) << __func__
<< " forward_request_to_master returned ret=" << op_ret
<< dendl
;
2084 s
->bucket_info
.has_website
= true;
2085 s
->bucket_info
.website_conf
= website_conf
;
2087 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
2089 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2094 int RGWDeleteBucketWebsite::verify_permission()
2096 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2102 void RGWDeleteBucketWebsite::pre_exec()
2104 rgw_bucket_object_pre_exec(s
);
2107 void RGWDeleteBucketWebsite::execute()
2109 s
->bucket_info
.has_website
= false;
2110 s
->bucket_info
.website_conf
= RGWBucketWebsiteConf();
2112 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
2114 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2119 int RGWStatBucket::verify_permission()
2121 // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission.
2122 if (!verify_bucket_permission(s
, rgw::IAM::s3ListBucket
)) {
2129 void RGWStatBucket::pre_exec()
2131 rgw_bucket_object_pre_exec(s
);
2134 void RGWStatBucket::execute()
2136 if (!s
->bucket_exists
) {
2137 op_ret
= -ERR_NO_SUCH_BUCKET
;
2141 RGWUserBuckets buckets
;
2142 bucket
.bucket
= s
->bucket
;
2143 buckets
.add(bucket
);
2144 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2145 op_ret
= store
->update_containers_stats(m
);
2150 map
<string
, RGWBucketEnt
>::iterator iter
= m
.find(bucket
.bucket
.name
);
2151 if (iter
!= m
.end()) {
2152 bucket
= iter
->second
;
2159 int RGWListBucket::verify_permission()
2161 op_ret
= get_params();
2166 if (!verify_bucket_permission(s
,
2168 rgw::IAM::s3ListBucketVersions
:
2169 rgw::IAM::s3ListBucket
)) {
2176 int RGWListBucket::parse_max_keys()
2178 if (!max_keys
.empty()) {
2180 max
= strtol(max_keys
.c_str(), &endptr
, 10);
2182 while (*endptr
&& isspace(*endptr
)) // ignore white space
2195 void RGWListBucket::pre_exec()
2197 rgw_bucket_object_pre_exec(s
);
2200 void RGWListBucket::execute()
2202 if (!s
->bucket_exists
) {
2203 op_ret
= -ERR_NO_SUCH_BUCKET
;
2207 if (need_container_stats()) {
2208 map
<string
, RGWBucketEnt
> m
;
2209 m
[s
->bucket
.name
] = RGWBucketEnt();
2210 m
.begin()->second
.bucket
= s
->bucket
;
2211 op_ret
= store
->update_containers_stats(m
);
2213 bucket
= m
.begin()->second
;
2217 RGWRados::Bucket
target(store
, s
->bucket_info
);
2218 if (shard_id
>= 0) {
2219 target
.set_shard_id(shard_id
);
2221 RGWRados::Bucket::List
list_op(&target
);
2223 list_op
.params
.prefix
= prefix
;
2224 list_op
.params
.delim
= delimiter
;
2225 list_op
.params
.marker
= marker
;
2226 list_op
.params
.end_marker
= end_marker
;
2227 list_op
.params
.list_versions
= list_versions
;
2229 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2231 next_marker
= list_op
.get_next_marker();
2235 int RGWGetBucketLogging::verify_permission()
2237 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2244 int RGWGetBucketLocation::verify_permission()
2246 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2253 int RGWCreateBucket::verify_permission()
2255 /* This check is mostly needed for S3 that doesn't support account ACL.
2256 * Swift doesn't allow to delegate any permission to an anonymous user,
2257 * so it will become an early exit in such case. */
2258 if (s
->auth
.identity
->is_anonymous()) {
2262 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
2266 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2267 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
2268 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2269 << " requested=" << s
->bucket_tenant
<< ")"
2273 if (s
->user
->max_buckets
< 0) {
2277 if (s
->user
->max_buckets
) {
2278 RGWUserBuckets buckets
;
2280 bool is_truncated
= false;
2281 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2282 marker
, string(), s
->user
->max_buckets
,
2283 false, &is_truncated
);
2288 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2289 return -ERR_TOO_MANY_BUCKETS
;
2296 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2297 RGWRados
*store
, bufferlist
& in_data
,
2298 JSONParser
*jp
, req_info
*forward_info
)
2300 if (!store
->rest_master_conn
) {
2301 ldout(s
->cct
, 0) << "rest connection is invalid" << dendl
;
2304 ldout(s
->cct
, 0) << "sending request to master zonegroup" << dendl
;
2305 bufferlist response
;
2306 string uid_str
= s
->user
->user_id
.to_str();
2307 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2308 int ret
= store
->rest_master_conn
->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2309 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2313 ldout(s
->cct
, 20) << "response: " << response
.c_str() << dendl
;
2314 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2315 ldout(s
->cct
, 0) << "failed parsing response from master zonegroup" << dendl
;
2322 void RGWCreateBucket::pre_exec()
2324 rgw_bucket_object_pre_exec(s
);
2327 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2328 map
<string
, bufferlist
>& out_attrs
,
2329 map
<string
, bufferlist
>& out_rmattrs
)
2331 for (const auto& kv
: orig_attrs
) {
2332 const string
& name
= kv
.first
;
2334 /* Check if the attr is user-defined metadata item. */
2335 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2336 RGW_ATTR_META_PREFIX
) == 0) {
2337 /* For the objects all existing meta attrs have to be removed. */
2338 out_rmattrs
[name
] = kv
.second
;
2339 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2340 out_attrs
[name
] = kv
.second
;
2345 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2346 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2347 * @out_attrs. Place results in @out_attrs.
2349 * NOTE: it's supposed that all special attrs already present in @out_attrs
2350 * will be preserved without any change. Special attributes are those which
2351 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2352 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2353 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2354 const set
<string
>& rmattr_names
,
2355 map
<string
, bufferlist
>& out_attrs
)
2357 for (const auto& kv
: orig_attrs
) {
2358 const string
& name
= kv
.first
;
2360 /* Check if the attr is user-defined metadata item. */
2361 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2362 RGW_ATTR_META_PREFIX
) == 0) {
2363 /* For the buckets all existing meta attrs are preserved,
2364 except those that are listed in rmattr_names. */
2365 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2366 const auto aiter
= out_attrs
.find(name
);
2368 if (aiter
!= std::end(out_attrs
)) {
2369 out_attrs
.erase(aiter
);
2372 /* emplace() won't alter the map if the key is already present.
2373 * This behaviour is fully intensional here. */
2374 out_attrs
.emplace(kv
);
2376 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2377 out_attrs
[name
] = kv
.second
;
2383 static void populate_with_generic_attrs(const req_state
* const s
,
2384 map
<string
, bufferlist
>& out_attrs
)
2386 for (const auto& kv
: s
->generic_attrs
) {
2387 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2388 const string
& val
= kv
.second
;
2390 attrbl
.append(val
.c_str(), val
.size() + 1);
2395 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2396 const std::set
<std::string
>& rmattr_names
,
2397 RGWQuotaInfo
& quota
,
2398 bool * quota_extracted
= nullptr)
2400 bool extracted
= false;
2402 /* Put new limit on max objects. */
2403 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2405 if (std::end(add_attrs
) != iter
) {
2407 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2411 add_attrs
.erase(iter
);
2415 /* Put new limit on bucket (container) size. */
2416 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2417 if (iter
!= add_attrs
.end()) {
2419 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2423 add_attrs
.erase(iter
);
2427 for (const auto& name
: rmattr_names
) {
2428 /* Remove limit on max objects. */
2429 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2430 quota
.max_objects
= -1;
2434 /* Remove limit on max bucket size. */
2435 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2436 quota
.max_size
= -1;
2441 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2442 quota
.check_on_raw
= true;
2443 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2445 if (quota_extracted
) {
2446 *quota_extracted
= extracted
;
2453 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2454 const std::set
<std::string
>& rmattr_names
,
2455 RGWBucketWebsiteConf
& ws_conf
)
2459 /* Let's define a mapping between each custom attribute and the memory where
2460 * attribute's value should be stored. The memory location is expressed by
2461 * a non-const reference. */
2462 const auto mapping
= {
2463 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2464 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2465 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2466 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2467 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2470 for (const auto& kv
: mapping
) {
2471 const char * const key
= kv
.first
;
2472 auto& target
= kv
.second
;
2474 auto iter
= add_attrs
.find(key
);
2476 if (std::end(add_attrs
) != iter
) {
2477 /* The "target" is a reference to ws_conf. */
2478 target
= iter
->second
.c_str();
2479 add_attrs
.erase(iter
);
2482 if (rmattr_names
.count(key
)) {
2483 target
= std::string();
2487 if (! lstval
.empty()) {
2488 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2493 void RGWCreateBucket::execute()
2495 RGWAccessControlPolicy
old_policy(s
->cct
);
2497 buffer::list corsbl
;
2500 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2501 rgw_raw_obj
obj(store
->get_zone_params().domain_root
, bucket_name
);
2502 obj_version objv
, *pobjv
= NULL
;
2504 op_ret
= get_params();
2508 if (!location_constraint
.empty() &&
2509 !store
->has_zonegroup_api(location_constraint
)) {
2510 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2511 << " can't be found." << dendl
;
2512 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2513 s
->err
.message
= "The specified location-constraint is not valid";
2517 if (!store
->get_zonegroup().is_master_zonegroup() &&
2518 store
->get_zonegroup().api_name
!= location_constraint
) {
2519 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2520 << " doesn't match zonegroup" << " (" << store
->get_zonegroup().api_name
<< ")"
2522 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2523 s
->err
.message
= "The specified location-constraint is not valid";
2527 /* we need to make sure we read bucket info, it's not read before for this
2528 * specific request */
2529 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2530 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2531 s
->bucket_info
, NULL
, &s
->bucket_attrs
);
2532 if (op_ret
< 0 && op_ret
!= -ENOENT
)
2534 s
->bucket_exists
= (op_ret
!= -ENOENT
);
2536 s
->bucket_owner
.set_id(s
->user
->user_id
);
2537 s
->bucket_owner
.set_name(s
->user
->display_name
);
2538 if (s
->bucket_exists
) {
2539 int r
= get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
2540 s
->bucket_attrs
, &old_policy
);
2542 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
2549 RGWBucketInfo master_info
;
2550 rgw_bucket
*pmaster_bucket
;
2551 uint32_t *pmaster_num_shards
;
2552 real_time creation_time
;
2554 if (!store
->is_meta_master()) {
2556 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
2561 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
2562 JSONDecoder::decode_json("object_ver", objv
, &jp
);
2563 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
2564 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
2565 ldout(s
->cct
, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
2566 pmaster_bucket
= &master_info
.bucket
;
2567 creation_time
= master_info
.creation_time
;
2568 pmaster_num_shards
= &master_info
.num_shards
;
2571 pmaster_bucket
= NULL
;
2572 pmaster_num_shards
= NULL
;
2575 string zonegroup_id
;
2577 if (s
->system_request
) {
2578 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
2579 if (zonegroup_id
.empty()) {
2580 zonegroup_id
= store
->get_zonegroup().get_id();
2583 zonegroup_id
= store
->get_zonegroup().get_id();
2586 if (s
->bucket_exists
) {
2587 string selected_placement_rule
;
2589 bucket
.tenant
= s
->bucket_tenant
;
2590 bucket
.name
= s
->bucket_name
;
2591 op_ret
= store
->select_bucket_placement(*(s
->user
), zonegroup_id
,
2593 &selected_placement_rule
, nullptr);
2594 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
2600 /* Encode special metadata first as we're using std::map::emplace under
2601 * the hood. This method will add the new items only if the map doesn't
2602 * contain such keys yet. */
2603 policy
.encode(aclbl
);
2604 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
2607 cors_config
.encode(corsbl
);
2608 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
2611 RGWQuotaInfo quota_info
;
2612 const RGWQuotaInfo
* pquota_info
= nullptr;
2613 if (need_metadata_upload()) {
2614 /* It's supposed that following functions WILL NOT change any special
2615 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
2616 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2617 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2618 populate_with_generic_attrs(s
, attrs
);
2620 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
2624 pquota_info
= "a_info
;
2627 /* Web site of Swift API. */
2628 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2629 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2632 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
2633 s
->bucket
.name
= s
->bucket_name
;
2635 /* Handle updates of the metadata for Swift's object versioning. */
2636 if (swift_ver_location
) {
2637 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2638 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2641 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
2642 placement_rule
, s
->bucket_info
.swift_ver_location
,
2644 info
, pobjv
, &ep_objv
, creation_time
,
2645 pmaster_bucket
, pmaster_num_shards
, true);
2646 /* continue if EEXIST and create_bucket will fail below. this way we can
2647 * recover from a partial create by retrying it. */
2648 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
2650 if (op_ret
&& op_ret
!= -EEXIST
)
2653 existed
= (op_ret
== -EEXIST
);
2656 /* bucket already existed, might have raced with another bucket creation, or
2657 * might be partial bucket creation that never completed. Read existing bucket
2658 * info, verify that the reported bucket owner is the current user.
2659 * If all is ok then update the user's list of buckets.
2660 * Otherwise inform client about a name conflict.
2662 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
2666 s
->bucket
= info
.bucket
;
2669 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
2670 info
.creation_time
, false);
2671 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
2672 /* if it exists (or previously existed), don't remove it! */
2673 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2676 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2679 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
2680 op_ret
= -ERR_BUCKET_EXISTS
;
2683 if (need_metadata_upload() && existed
) {
2684 /* OK, it looks we lost race with another request. As it's required to
2685 * handle metadata fusion and upload, the whole operation becomes very
2686 * similar in nature to PutMetadataBucket. However, as the attrs may
2687 * changed in the meantime, we have to refresh. */
2690 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2691 RGWBucketInfo binfo
;
2692 map
<string
, bufferlist
> battrs
;
2694 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2695 binfo
, nullptr, &battrs
);
2698 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
2699 /* New bucket doesn't belong to the account we're operating on. */
2703 s
->bucket_info
= binfo
;
2704 s
->bucket_attrs
= battrs
;
2709 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2710 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2711 populate_with_generic_attrs(s
, attrs
);
2712 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
2717 /* Handle updates of the metadata for Swift's object versioning. */
2718 if (swift_ver_location
) {
2719 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2720 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2723 /* Web site of Swift API. */
2724 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2725 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2727 /* This will also set the quota on the bucket. */
2728 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
2729 &s
->bucket_info
.objv_tracker
);
2730 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
2732 /* Restore the proper return code. */
2734 op_ret
= -ERR_BUCKET_EXISTS
;
2739 int RGWDeleteBucket::verify_permission()
2741 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucket
)) {
2748 void RGWDeleteBucket::pre_exec()
2750 rgw_bucket_object_pre_exec(s
);
2753 void RGWDeleteBucket::execute()
2757 if (s
->bucket_name
.empty())
2760 if (!s
->bucket_exists
) {
2761 ldout(s
->cct
, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
2762 op_ret
= -ERR_NO_SUCH_BUCKET
;
2765 RGWObjVersionTracker ot
;
2766 ot
.read_version
= s
->bucket_info
.ep_objv
;
2768 if (s
->system_request
) {
2769 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
2770 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
2772 ot
.read_version
.tag
= tag
;
2775 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
2777 ldout(s
->cct
, 0) << "failed to parse ver param" << dendl
;
2781 ot
.read_version
.ver
= ver
;
2785 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
2787 ldout(s
->cct
, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
2790 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
2795 if (!store
->is_meta_master()) {
2797 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
2800 if (op_ret
== -ENOENT
) {
2801 /* adjust error, we want to return with NoSuchBucket and not
2803 op_ret
= -ERR_NO_SUCH_BUCKET
;
2809 string prefix
, delimiter
;
2811 if (s
->prot_flags
& RGW_REST_SWIFT
) {
2813 path_args
= s
->info
.args
.get("path");
2814 if (!path_args
.empty()) {
2815 if (!delimiter
.empty() || !prefix
.empty()) {
2824 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
2830 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
2832 if (op_ret
== -ECANCELED
) {
2833 // lost a race, either with mdlog sync or another delete bucket operation.
2834 // in either case, we've already called rgw_unlink_bucket()
2840 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2841 s
->bucket
.name
, false);
2843 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2855 int RGWPutObj::verify_permission()
2859 RGWAccessControlPolicy
cs_acl(s
->cct
);
2860 optional
<Policy
> policy
;
2861 map
<string
, bufferlist
> cs_attrs
;
2862 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
2863 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
2865 rgw_obj
obj(cs_bucket
, cs_object
);
2866 store
->set_atomic(s
->obj_ctx
, obj
);
2867 store
->set_prefetch_data(s
->obj_ctx
, obj
);
2869 /* check source object permissions */
2870 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
, policy
,
2871 cs_bucket
, cs_object
) < 0) {
2875 /* admin request overrides permission checks */
2876 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
2878 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
2879 cs_object
.instance
.empty() ?
2880 rgw::IAM::s3GetObject
:
2881 rgw::IAM::s3GetObjectVersion
,
2882 rgw::IAM::ARN(obj
));
2883 if (e
== Effect::Deny
) {
2885 } else if (e
== Effect::Pass
&&
2886 !cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2890 } else if (!cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2897 if (s
->iam_policy
) {
2898 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
2899 rgw::IAM::s3PutObject
,
2900 rgw_obj(s
->bucket
, s
->object
));
2901 if (e
== Effect::Allow
) {
2903 } else if (e
== Effect::Deny
) {
2908 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
2915 void RGWPutObjProcessor_Multipart::get_mp(RGWMPObj
** _mp
){
2919 int RGWPutObjProcessor_Multipart::prepare(RGWRados
*store
, string
*oid_rand
)
2921 string oid
= obj_str
;
2922 upload_id
= s
->info
.args
.get("uploadId");
2924 mp
.init(oid
, upload_id
);
2926 mp
.init(oid
, upload_id
, *oid_rand
);
2929 part_num
= s
->info
.args
.get("partNumber");
2930 if (part_num
.empty()) {
2931 ldout(s
->cct
, 10) << "part number is empty" << dendl
;
2936 uint64_t num
= (uint64_t)strict_strtol(part_num
.c_str(), 10, &err
);
2939 ldout(s
->cct
, 10) << "bad part number: " << part_num
<< ": " << err
<< dendl
;
2943 string upload_prefix
= oid
+ ".";
2946 upload_prefix
.append(upload_id
);
2948 upload_prefix
.append(*oid_rand
);
2952 target_obj
.init(bucket
, oid
);
2954 manifest
.set_prefix(upload_prefix
);
2956 manifest
.set_multipart_part_rule(store
->ctx()->_conf
->rgw_obj_stripe_size
, num
);
2958 int r
= manifest_gen
.create_begin(store
->ctx(), &manifest
, s
->bucket_info
.placement_rule
, bucket
, target_obj
);
2963 cur_obj
= manifest_gen
.get_cur_obj(store
);
2964 rgw_raw_obj_to_obj(bucket
, cur_obj
, &head_obj
);
2965 head_obj
.index_hash_source
= obj_str
;
2967 r
= prepare_init(store
, NULL
);
2975 int RGWPutObjProcessor_Multipart::do_complete(size_t accounted_size
,
2977 real_time
*mtime
, real_time set_mtime
,
2978 map
<string
, bufferlist
>& attrs
,
2979 real_time delete_at
,
2980 const char *if_match
,
2981 const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
)
2983 complete_writing_data();
2985 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, head_obj
);
2986 op_target
.set_versioning_disabled(true);
2987 RGWRados::Object::Write
head_obj_op(&op_target
);
2989 head_obj_op
.meta
.set_mtime
= set_mtime
;
2990 head_obj_op
.meta
.mtime
= mtime
;
2991 head_obj_op
.meta
.owner
= s
->owner
.get_id();
2992 head_obj_op
.meta
.delete_at
= delete_at
;
2993 head_obj_op
.meta
.zones_trace
= zones_trace
;
2995 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3000 RGWUploadPartInfo info
;
3002 bool sorted_omap
= is_v2_upload_id(upload_id
);
3006 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3008 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3012 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3017 info
.num
= atoi(part_num
.c_str());
3019 info
.size
= obj_len
;
3020 info
.accounted_size
= accounted_size
;
3021 info
.modified
= real_clock::now();
3022 info
.manifest
= manifest
;
3025 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3027 dout(1) << "cannot get compression info" << dendl
;
3033 string multipart_meta_obj
= mp
.get_meta();
3036 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3037 meta_obj
.set_in_extra_data(true);
3039 rgw_raw_obj raw_meta_obj
;
3041 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3043 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3048 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3050 RGWPutObjProcessor
*processor
;
3052 bool multipart
= s
->info
.args
.exists("uploadId");
3054 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3057 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3058 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3059 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3061 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3065 *is_multipart
= multipart
;
3071 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3076 void RGWPutObj::pre_exec()
3078 rgw_bucket_object_pre_exec(s
);
3081 class RGWPutObj_CB
: public RGWGetDataCB
3085 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3086 ~RGWPutObj_CB() override
{}
3088 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3089 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3093 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3096 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3098 bl_aux
.append(bl_tmp
);
3103 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3105 RGWPutObj_CB
cb(this);
3106 RGWGetDataCB
* filter
= &cb
;
3107 boost::optional
<RGWGetObj_Decompress
> decompress
;
3108 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3109 RGWCompressionInfo cs_info
;
3110 map
<string
, bufferlist
> attrs
;
3111 map
<string
, bufferlist
>::iterator attr_iter
;
3115 int64_t new_ofs
, new_end
;
3120 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3121 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3123 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3124 RGWRados::Object::Read
read_op(&op_target
);
3125 read_op
.params
.obj_size
= &obj_size
;
3126 read_op
.params
.attrs
= &attrs
;
3128 ret
= read_op
.prepare();
3132 bool need_decompress
;
3133 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3135 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3139 bool partial_content
= true;
3140 if (need_decompress
)
3142 obj_size
= cs_info
.orig_size
;
3143 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3144 filter
= &*decompress
;
3147 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3148 op_ret
= this->get_decrypt_filter(&decrypt
,
3151 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3152 if (decrypt
!= nullptr) {
3153 filter
= decrypt
.get();
3159 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3163 filter
->fixup_range(new_ofs
, new_end
);
3164 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3167 ret
= filter
->flush();
3169 bl
.claim_append(bl_aux
);
3174 // special handling for compression type = "random" with multipart uploads
3175 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3176 const std::string
& compression_type
)
3178 if (compression_type
!= "random") {
3179 return Compressor::create(s
->cct
, compression_type
);
3182 bool is_multipart
{false};
3183 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3185 if (!is_multipart
) {
3186 return Compressor::create(s
->cct
, compression_type
);
3189 // use a hash of the multipart upload id so all parts use the same plugin
3190 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3191 if (alg
== Compressor::COMP_ALG_NONE
) {
3194 return Compressor::create(s
->cct
, alg
);
3197 void RGWPutObj::execute()
3199 RGWPutObjProcessor
*processor
= NULL
;
3200 RGWPutObjDataProcessor
*filter
= nullptr;
3201 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3202 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3203 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3204 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3205 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3207 bufferlist bl
, aclbl
, bs
;
3209 map
<string
, string
>::iterator iter
;
3214 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3215 s
->bucket_info
.placement_rule
);
3216 CompressorRef plugin
;
3217 boost::optional
<RGWPutObj_Compress
> compressor
;
3219 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3220 perfcounter
->inc(l_rgw_put
);
3222 if (s
->object
.empty()) {
3226 if (!s
->bucket_exists
) {
3227 op_ret
= -ERR_NO_SUCH_BUCKET
;
3231 op_ret
= get_params();
3233 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3237 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3239 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3244 if (supplied_md5_b64
) {
3245 need_calc_md5
= true;
3247 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3248 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3249 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3250 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3251 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3252 op_ret
= -ERR_INVALID_DIGEST
;
3256 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3257 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3260 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3261 we also check sizes at the end anyway */
3262 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3263 user_quota
, bucket_quota
, s
->content_length
);
3265 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3268 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3270 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3275 if (supplied_etag
) {
3276 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3277 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3280 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3282 // no filters by default
3285 /* Handle object versioning of Swift API. */
3287 rgw_obj
obj(s
->bucket
, s
->object
);
3288 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3289 s
->bucket_owner
.get_id(),
3297 op_ret
= processor
->prepare(store
, NULL
);
3299 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3304 fst
= copy_source_range_fst
;
3305 lst
= copy_source_range_lst
;
3307 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3311 if (encrypt
!= nullptr) {
3312 filter
= encrypt
.get();
3314 //no encryption, we can try compression
3315 if (compression_type
!= "none") {
3316 plugin
= get_compressor_plugin(s
, compression_type
);
3318 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3319 << compression_type
<< dendl
;
3321 compressor
.emplace(s
->cct
, plugin
, filter
);
3322 filter
= &*compressor
;
3332 len
= get_data(data
);
3334 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3335 op_ret
= get_data(fst
, cur_lst
, data
);
3338 len
= data
.length();
3339 s
->content_length
+= len
;
3347 if (need_calc_md5
) {
3348 hash
.Update((const byte
*)data
.c_str(), data
.length());
3351 /* update torrrent */
3352 torrent
.update(data
);
3354 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3355 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3357 bool need_to_wait
= (ofs
== 0) && multipart
;
3359 bufferlist orig_data
;
3365 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3367 if (!need_to_wait
|| op_ret
!= -EEXIST
) {
3368 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3372 /* need_to_wait == true and op_ret == -EEXIST */
3373 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3375 /* restore original data */
3376 data
.swap(orig_data
);
3378 /* restart processing with different oid suffix */
3380 dispose_processor(processor
);
3381 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3386 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3387 oid_rand
.append(buf
);
3389 op_ret
= processor
->prepare(store
, &oid_rand
);
3391 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3396 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3400 if (encrypt
!= nullptr) {
3401 filter
= encrypt
.get();
3404 compressor
.emplace(s
->cct
, plugin
, filter
);
3405 filter
= &*compressor
;
3408 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3419 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3425 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3426 op_ret
= -ERR_REQUEST_TIMEOUT
;
3431 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3433 op_ret
= do_aws4_auth_completion();
3438 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3439 user_quota
, bucket_quota
, s
->obj_size
);
3441 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3445 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3447 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3453 if (compressor
&& compressor
->is_compressed()) {
3455 RGWCompressionInfo cs_info
;
3456 cs_info
.compression_type
= plugin
->get_type_name();
3457 cs_info
.orig_size
= s
->obj_size
;
3458 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3459 ::encode(cs_info
, tmp
);
3460 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3461 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3462 << " with type=" << cs_info
.compression_type
3463 << ", orig_size=" << cs_info
.orig_size
3464 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3467 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3471 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3472 op_ret
= -ERR_BAD_DIGEST
;
3476 policy
.encode(aclbl
);
3477 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3480 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3482 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3485 complete_etag(hash
, &etag
);
3486 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3490 bufferlist manifest_bl
;
3491 ::encode(*slo_info
, manifest_bl
);
3492 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3494 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3495 complete_etag(hash
, &etag
);
3496 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3499 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3500 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3503 bl
.append(etag
.c_str(), etag
.size() + 1);
3504 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3506 populate_with_generic_attrs(s
, attrs
);
3507 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3508 encode_delete_at_attr(delete_at
, attrs
);
3509 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3511 /* Add a custom metadata to expose the information whether an object
3512 * is an SLO or not. Appending the attribute must be performed AFTER
3513 * processing any input from user in order to prohibit overwriting. */
3515 bufferlist slo_userindicator_bl
;
3516 slo_userindicator_bl
.append("True", 4);
3517 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3520 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3521 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3522 (user_data
.empty() ? nullptr : &user_data
));
3524 /* produce torrent */
3525 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3527 torrent
.init(s
, store
);
3528 torrent
.set_create_date(mtime
);
3529 op_ret
= torrent
.complete();
3532 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3538 dispose_processor(processor
);
3539 perfcounter
->tinc(l_rgw_put_lat
,
3540 (ceph_clock_now() - s
->time
));
3543 int RGWPostObj::verify_permission()
3548 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3550 RGWPutObjProcessor *processor;
3552 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3554 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3559 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3564 void RGWPostObj::pre_exec()
3566 rgw_bucket_object_pre_exec(s
);
3569 void RGWPostObj::execute()
3571 RGWPutObjDataProcessor
*filter
= nullptr;
3572 boost::optional
<RGWPutObj_Compress
> compressor
;
3573 CompressorRef plugin
;
3574 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3576 /* Read in the data from the POST form. */
3577 op_ret
= get_params();
3582 op_ret
= verify_params();
3587 if (s
->iam_policy
) {
3588 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3589 rgw::IAM::s3PutObject
,
3590 rgw_obj(s
->bucket
, s
->object
));
3591 if (e
== Effect::Deny
) {
3594 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3598 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3603 /* Start iteration over data fields. It's necessary as Swift's FormPost
3604 * is capable to handle multiple files in single form. */
3606 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3607 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3608 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3610 ceph::buffer::list bl
, aclbl
;
3613 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3622 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3627 if (supplied_md5_b64
) {
3628 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3629 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3630 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3631 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3632 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3633 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3634 op_ret
= -ERR_INVALID_DIGEST
;
3638 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3639 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3642 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3645 get_current_filename(),
3647 s
->cct
->_conf
->rgw_obj_stripe_size
,
3649 s
->bucket_info
.versioning_enabled());
3650 /* No filters by default. */
3651 filter
= &processor
;
3653 op_ret
= processor
.prepare(store
, nullptr);
3658 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3662 if (encrypt
!= nullptr) {
3663 filter
= encrypt
.get();
3665 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3666 s
->bucket_info
.placement_rule
);
3667 if (compression_type
!= "none") {
3668 plugin
= Compressor::create(s
->cct
, compression_type
);
3670 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3671 << compression_type
<< dendl
;
3673 compressor
.emplace(s
->cct
, plugin
, filter
);
3674 filter
= &*compressor
;
3681 ceph::bufferlist data
;
3682 len
= get_data(data
, again
);
3693 hash
.Update((const byte
*)data
.c_str(), data
.length());
3694 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3698 if (ofs
> max_len
) {
3699 op_ret
= -ERR_TOO_LARGE
;
3706 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3709 if (len
< min_len
) {
3710 op_ret
= -ERR_TOO_SMALL
;
3716 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3717 op_ret
= -ERR_BAD_DIGEST
;
3721 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3722 user_quota
, bucket_quota
, s
->obj_size
);
3727 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3733 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3736 bl
.append(etag
.c_str(), etag
.size() + 1);
3737 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3739 policy
.encode(aclbl
);
3740 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3742 const std::string content_type
= get_current_content_type();
3743 if (! content_type
.empty()) {
3744 ceph::bufferlist ct_bl
;
3745 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3746 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3749 if (compressor
&& compressor
->is_compressed()) {
3750 ceph::bufferlist tmp
;
3751 RGWCompressionInfo cs_info
;
3752 cs_info
.compression_type
= plugin
->get_type_name();
3753 cs_info
.orig_size
= s
->obj_size
;
3754 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3755 ::encode(cs_info
, tmp
);
3756 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3759 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3760 attrs
, (delete_at
? *delete_at
: real_time()));
3761 } while (is_next_file_to_upload());
3765 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3766 const set
<string
>& rmattr_names
,
3767 map
<int, string
>& temp_url_keys
)
3769 map
<string
, bufferlist
>::iterator iter
;
3771 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3772 if (iter
!= add_attrs
.end()) {
3773 temp_url_keys
[0] = iter
->second
.c_str();
3774 add_attrs
.erase(iter
);
3777 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3778 if (iter
!= add_attrs
.end()) {
3779 temp_url_keys
[1] = iter
->second
.c_str();
3780 add_attrs
.erase(iter
);
3783 for (const string
& name
: rmattr_names
) {
3784 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3785 temp_url_keys
[0] = string();
3787 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3788 temp_url_keys
[1] = string();
3793 int RGWPutMetadataAccount::init_processing()
3795 /* First, go to the base class. At the time of writing the method was
3796 * responsible only for initializing the quota. This isn't necessary
3797 * here as we are touching metadata only. I'm putting this call only
3798 * for the future. */
3799 op_ret
= RGWOp::init_processing();
3804 op_ret
= get_params();
3809 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3817 policy
.encode(acl_bl
);
3818 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3821 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3822 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3823 populate_with_generic_attrs(s
, attrs
);
3825 /* Try extract the TempURL-related stuff now to allow verify_permission
3826 * evaluate whether we need FULL_CONTROL or not. */
3827 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3829 /* The same with quota except a client needs to be reseller admin. */
3830 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3831 &new_quota_extracted
);
3839 int RGWPutMetadataAccount::verify_permission()
3841 if (s
->auth
.identity
->is_anonymous()) {
3845 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
3849 /* Altering TempURL keys requires FULL_CONTROL. */
3850 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
3854 /* We are failing this intensionally to allow system user/reseller admin
3855 * override in rgw_process.cc. This is the way to specify a given RGWOp
3856 * expect extra privileges. */
3857 if (new_quota_extracted
) {
3864 void RGWPutMetadataAccount::execute()
3866 /* Params have been extracted earlier. See init_processing(). */
3867 RGWUserInfo new_uinfo
;
3868 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
3874 /* Handle the TempURL-related stuff. */
3875 if (!temp_url_keys
.empty()) {
3876 for (auto& pair
: temp_url_keys
) {
3877 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
3881 /* Handle the quota extracted at the verify_permission step. */
3882 if (new_quota_extracted
) {
3883 new_uinfo
.user_quota
= std::move(new_quota
);
3886 /* We are passing here the current (old) user info to allow the function
3887 * optimize-out some operations. */
3888 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
3889 &acct_op_tracker
, real_time(), false, &attrs
);
3892 int RGWPutMetadataBucket::verify_permission()
3894 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3901 void RGWPutMetadataBucket::pre_exec()
3903 rgw_bucket_object_pre_exec(s
);
3906 void RGWPutMetadataBucket::execute()
3908 op_ret
= get_params();
3913 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3915 if (!placement_rule
.empty() &&
3916 placement_rule
!= s
->bucket_info
.placement_rule
) {
3921 /* Encode special metadata first as we're using std::map::emplace under
3922 * the hood. This method will add the new items only if the map doesn't
3923 * contain such keys yet. */
3925 if (s
->dialect
.compare("swift") == 0) {
3926 auto old_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
);
3927 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
3928 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
3929 policy
= *new_policy
;
3933 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
3938 cors_config
.encode(bl
);
3939 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
3942 /* It's supposed that following functions WILL NOT change any special
3943 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
3944 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
3945 populate_with_generic_attrs(s
, attrs
);
3947 /* According to the Swift's behaviour and its container_quota WSGI middleware
3948 * implementation: anyone with write permissions is able to set the bucket
3949 * quota. This stays in contrast to account quotas that can be set only by
3950 * clients holding reseller admin privileges. */
3951 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
3956 if (swift_ver_location
) {
3957 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
3958 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
3961 /* Web site of Swift API. */
3962 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
3963 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
3965 /* Setting attributes also stores the provided bucket info. Due to this
3966 * fact, the new quota settings can be serialized with the same call. */
3967 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
3968 &s
->bucket_info
.objv_tracker
);
3971 int RGWPutMetadataObject::verify_permission()
3973 // This looks to be something specific to Swift. We could add
3974 // operations like swift:PutMetadataObject to the Policy Engine.
3975 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3982 void RGWPutMetadataObject::pre_exec()
3984 rgw_bucket_object_pre_exec(s
);
3987 void RGWPutMetadataObject::execute()
3989 rgw_obj
obj(s
->bucket
, s
->object
);
3990 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
3992 store
->set_atomic(s
->obj_ctx
, obj
);
3994 op_ret
= get_params();
3999 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4000 /* check if obj exists, read orig attrs */
4001 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4006 /* Check whether the object has expired. Swift API documentation
4007 * stands that we should return 404 Not Found in such case. */
4008 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4013 /* Filter currently existing attributes. */
4014 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4015 populate_with_generic_attrs(s
, attrs
);
4016 encode_delete_at_attr(delete_at
, attrs
);
4019 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4021 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4026 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4029 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4031 RGWSLOInfo slo_info
;
4032 bufferlist::iterator bliter
= bl
.begin();
4034 ::decode(slo_info
, bliter
);
4035 } catch (buffer::error
& err
) {
4036 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4041 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4042 new RGWBulkDelete::Deleter(store
, s
));
4043 } catch (std::bad_alloc
) {
4047 list
<RGWBulkDelete::acct_path_t
> items
;
4048 for (const auto& iter
: slo_info
.entries
) {
4049 const string
& path_str
= iter
.path
;
4051 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4052 if (boost::string_view::npos
== sep_pos
) {
4056 RGWBulkDelete::acct_path_t path
;
4058 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4059 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4061 items
.push_back(path
);
4064 /* Request removal of the manifest object itself. */
4065 RGWBulkDelete::acct_path_t path
;
4066 path
.bucket_name
= s
->bucket_name
;
4067 path
.obj_key
= s
->object
;
4068 items
.push_back(path
);
4070 int ret
= deleter
->delete_chunk(items
);
4078 int RGWDeleteObj::verify_permission()
4080 if (s
->iam_policy
) {
4081 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4082 s
->object
.instance
.empty() ?
4083 rgw::IAM::s3DeleteObject
:
4084 rgw::IAM::s3DeleteObjectVersion
,
4085 ARN(s
->bucket
, s
->object
.name
));
4086 if (r
== Effect::Allow
)
4088 else if (r
== Effect::Deny
)
4092 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4099 void RGWDeleteObj::pre_exec()
4101 rgw_bucket_object_pre_exec(s
);
4104 void RGWDeleteObj::execute()
4106 if (!s
->bucket_exists
) {
4107 op_ret
= -ERR_NO_SUCH_BUCKET
;
4111 op_ret
= get_params();
4116 rgw_obj
obj(s
->bucket
, s
->object
);
4117 map
<string
, bufferlist
> attrs
;
4120 if (!s
->object
.empty()) {
4121 if (need_object_expiration() || multipart_delete
) {
4122 /* check if obj exists, read orig attrs */
4123 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4129 if (multipart_delete
) {
4130 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4132 if (slo_attr
!= attrs
.end()) {
4133 op_ret
= handle_slo_manifest(slo_attr
->second
);
4135 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4138 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4144 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4145 obj_ctx
->obj
.set_atomic(obj
);
4147 bool ver_restored
= false;
4148 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4149 s
->bucket_info
, obj
, ver_restored
);
4154 if (!ver_restored
) {
4155 /* Swift's versioning mechanism hasn't found any previous version of
4156 * the object that could be restored. This means we should proceed
4157 * with the regular delete path. */
4158 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4159 RGWRados::Object::Delete
del_op(&del_target
);
4161 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4162 &del_op
.params
.marker_version_id
);
4167 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4168 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4169 del_op
.params
.obj_owner
= s
->owner
;
4170 del_op
.params
.unmod_since
= unmod_since
;
4171 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4173 op_ret
= del_op
.delete_obj();
4175 delete_marker
= del_op
.result
.delete_marker
;
4176 version_id
= del_op
.result
.version_id
;
4179 /* Check whether the object has expired. Swift API documentation
4180 * stands that we should return 404 Not Found in such case. */
4181 if (need_object_expiration() && object_is_expired(attrs
)) {
4187 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4196 bool RGWCopyObj::parse_copy_location(const string
& url_src
, string
& bucket_name
, rgw_obj_key
& key
)
4201 size_t pos
= url_src
.find('?');
4202 if (pos
== string::npos
) {
4205 name_str
= url_src
.substr(0, pos
);
4206 params_str
= url_src
.substr(pos
+ 1);
4209 std::string dec_src
= url_decode(name_str
);
4210 const char *src
= dec_src
.c_str();
4212 if (*src
== '/') ++src
;
4216 pos
= str
.find('/');
4217 if (pos
==string::npos
)
4220 bucket_name
= str
.substr(0, pos
);
4221 key
.name
= str
.substr(pos
+ 1);
4223 if (key
.name
.empty()) {
4227 if (!params_str
.empty()) {
4229 args
.set(params_str
);
4232 key
.instance
= args
.get("versionId", NULL
);
4238 int RGWCopyObj::verify_permission()
4240 RGWAccessControlPolicy
src_acl(s
->cct
);
4241 optional
<Policy
> src_policy
;
4242 op_ret
= get_params();
4246 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4250 map
<string
, bufferlist
> src_attrs
;
4252 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4254 if (s
->bucket_instance_id
.empty()) {
4255 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4257 /* will only happen in intra region sync where the source and dest bucket is the same */
4258 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4261 if (op_ret
== -ENOENT
) {
4262 op_ret
= -ERR_NO_SUCH_BUCKET
;
4267 src_bucket
= src_bucket_info
.bucket
;
4269 /* get buckets info (source and dest) */
4270 if (s
->local_source
&& source_zone
.empty()) {
4271 rgw_obj
src_obj(src_bucket
, src_object
);
4272 store
->set_atomic(s
->obj_ctx
, src_obj
);
4273 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4275 /* check source object permissions */
4276 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4277 src_policy
, src_bucket
, src_object
);
4282 /* admin request overrides permission checks */
4283 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4285 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4286 src_object
.instance
.empty() ?
4287 rgw::IAM::s3GetObject
:
4288 rgw::IAM::s3GetObjectVersion
,
4290 if (e
== Effect::Deny
) {
4292 } else if (e
== Effect::Pass
&&
4293 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4297 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4305 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4306 map
<string
, bufferlist
> dest_attrs
;
4308 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4309 or intra region sync */
4310 dest_bucket_info
= src_bucket_info
;
4311 dest_attrs
= src_attrs
;
4313 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4314 dest_bucket_info
, nullptr, &dest_attrs
);
4316 if (op_ret
== -ENOENT
) {
4317 op_ret
= -ERR_NO_SUCH_BUCKET
;
4323 dest_bucket
= dest_bucket_info
.bucket
;
4325 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4326 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4328 /* check dest bucket permissions */
4329 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4330 &dest_bucket_policy
, dest_bucket
);
4335 /* admin request overrides permission checks */
4336 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4337 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4342 op_ret
= init_dest_policy();
4351 int RGWCopyObj::init_common()
4354 if (parse_time(if_mod
, &mod_time
) < 0) {
4358 mod_ptr
= &mod_time
;
4362 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4366 unmod_ptr
= &unmod_time
;
4370 dest_policy
.encode(aclbl
);
4371 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4373 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4374 populate_with_generic_attrs(s
, attrs
);
4379 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4381 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4382 op
->progress_cb(ofs
);
4385 void RGWCopyObj::progress_cb(off_t ofs
)
4387 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4390 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4393 send_partial_response(ofs
);
4398 void RGWCopyObj::pre_exec()
4400 rgw_bucket_object_pre_exec(s
);
4403 void RGWCopyObj::execute()
4405 if (init_common() < 0)
4408 rgw_obj
src_obj(src_bucket
, src_object
);
4409 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4411 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4412 obj_ctx
.obj
.set_atomic(src_obj
);
4413 obj_ctx
.obj
.set_atomic(dst_obj
);
4415 encode_delete_at_attr(delete_at
, attrs
);
4417 bool high_precision_time
= (s
->system_request
);
4419 /* Handle object versioning of Swift API. In case of copying to remote this
4420 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4421 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4422 dest_bucket_info
.owner
,
4429 op_ret
= store
->copy_obj(obj_ctx
,
4443 high_precision_time
,
4448 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4450 (delete_at
? *delete_at
: real_time()),
4451 (version_id
.empty() ? NULL
: &version_id
),
4452 &s
->req_id
, /* use req_id as tag */
4454 copy_obj_progress_cb
, (void *)this
4458 int RGWGetACLs::verify_permission()
4461 if (!s
->object
.empty()) {
4462 perm
= verify_object_permission(s
,
4463 s
->object
.instance
.empty() ?
4464 rgw::IAM::s3GetObjectAcl
:
4465 rgw::IAM::s3GetObjectVersionAcl
);
4467 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetObjectAcl
);
4475 void RGWGetACLs::pre_exec()
4477 rgw_bucket_object_pre_exec(s
);
4480 void RGWGetACLs::execute()
4483 RGWAccessControlPolicy
*acl
= (!s
->object
.empty() ? s
->object_acl
: s
->bucket_acl
);
4484 RGWAccessControlPolicy_S3
*s3policy
= static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4485 s3policy
->to_xml(ss
);
4491 int RGWPutACLs::verify_permission()
4494 if (!s
->object
.empty()) {
4495 perm
= verify_object_permission(s
,
4496 s
->object
.instance
.empty() ?
4497 rgw::IAM::s3PutObjectAcl
:
4498 rgw::IAM::s3PutObjectVersionAcl
);
4500 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4508 int RGWGetLC::verify_permission()
4511 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4518 int RGWPutLC::verify_permission()
4521 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4528 int RGWDeleteLC::verify_permission()
4531 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4538 void RGWPutACLs::pre_exec()
4540 rgw_bucket_object_pre_exec(s
);
4543 void RGWGetLC::pre_exec()
4545 rgw_bucket_object_pre_exec(s
);
4548 void RGWPutLC::pre_exec()
4550 rgw_bucket_object_pre_exec(s
);
4553 void RGWDeleteLC::pre_exec()
4555 rgw_bucket_object_pre_exec(s
);
4558 void RGWPutACLs::execute()
4562 RGWAccessControlPolicy_S3
*policy
= NULL
;
4563 RGWACLXMLParser_S3
parser(s
->cct
);
4564 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4566 char *new_data
= NULL
;
4569 op_ret
= 0; /* XXX redundant? */
4571 if (!parser
.init()) {
4577 RGWAccessControlPolicy
*existing_policy
= (s
->object
.empty() ? s
->bucket_acl
: s
->object_acl
);
4579 owner
= existing_policy
->get_owner();
4581 op_ret
= get_params();
4585 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4587 if (!s
->canned_acl
.empty() && len
) {
4592 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4593 op_ret
= get_policy_from_state(store
, s
, ss
);
4597 new_data
= strdup(ss
.str().c_str());
4600 len
= ss
.str().size();
4603 if (!parser
.parse(data
, len
, 1)) {
4607 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4613 // forward bucket acl requests to meta master zone
4614 if (s
->object
.empty() && !store
->is_meta_master()) {
4616 // include acl data unless it was generated from a canned_acl
4617 if (s
->canned_acl
.empty()) {
4618 in_data
.append(data
, len
);
4620 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4622 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4627 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4628 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4629 policy
->to_xml(*_dout
);
4633 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4637 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4638 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4639 new_policy
.to_xml(*_dout
);
4643 new_policy
.encode(bl
);
4644 map
<string
, bufferlist
> attrs
;
4646 if (!s
->object
.empty()) {
4647 obj
= rgw_obj(s
->bucket
, s
->object
);
4648 store
->set_atomic(s
->obj_ctx
, obj
);
4649 //if instance is empty, we should modify the latest object
4650 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4652 attrs
= s
->bucket_attrs
;
4653 attrs
[RGW_ATTR_ACL
] = bl
;
4654 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4656 if (op_ret
== -ECANCELED
) {
4657 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4661 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4663 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4664 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4665 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4666 oid
= lc_oid_prefix
;
4668 snprintf(buf
, 32, ".%d", index
);
4673 void RGWPutLC::execute()
4677 RGWLifecycleConfiguration_S3
*config
= NULL
;
4678 RGWLCXMLParser_S3
parser(s
->cct
);
4679 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4681 if (!parser
.init()) {
4686 op_ret
= get_params();
4690 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4692 if (!parser
.parse(data
, len
, 1)) {
4693 op_ret
= -ERR_MALFORMED_XML
;
4696 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4698 op_ret
= -ERR_MALFORMED_XML
;
4702 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4703 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4704 config
->to_xml(*_dout
);
4708 op_ret
= config
->rebuild(store
, new_config
);
4712 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4713 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4714 new_config
.to_xml(*_dout
);
4718 new_config
.encode(bl
);
4719 map
<string
, bufferlist
> attrs
;
4720 attrs
= s
->bucket_attrs
;
4721 attrs
[RGW_ATTR_LC
] = bl
;
4722 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4725 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4728 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4729 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4730 rados::cls::lock::Lock
l(lc_index_lock_name
);
4731 utime_t
time(max_lock_secs
, 0);
4732 l
.set_duration(time
);
4733 l
.set_cookie(cookie
);
4734 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4736 op_ret
= l
.lock_exclusive(ctx
, oid
);
4737 if (op_ret
== -EBUSY
) {
4738 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4743 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4746 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4748 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4756 void RGWDeleteLC::execute()
4759 map
<string
, bufferlist
> orig_attrs
, attrs
;
4760 map
<string
, bufferlist
>::iterator iter
;
4762 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4763 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4764 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4768 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4769 const string
& name
= iter
->first
;
4770 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
4771 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
4772 if (attrs
.find(name
) == attrs
.end()) {
4773 attrs
[name
] = iter
->second
;
4777 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4778 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4779 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4782 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4783 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4784 rados::cls::lock::Lock
l(lc_index_lock_name
);
4785 utime_t
time(max_lock_secs
, 0);
4786 l
.set_duration(time
);
4788 op_ret
= l
.lock_exclusive(ctx
, oid
);
4789 if (op_ret
== -EBUSY
) {
4790 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4795 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4798 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
4800 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4808 int RGWGetCORS::verify_permission()
4810 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4817 void RGWGetCORS::execute()
4819 op_ret
= read_bucket_cors();
4824 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4830 int RGWPutCORS::verify_permission()
4832 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4839 void RGWPutCORS::execute()
4843 op_ret
= get_params();
4847 if (!store
->is_meta_master()) {
4848 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
4850 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4855 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
4856 attrs
[RGW_ATTR_CORS
] = cors_bl
;
4857 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4860 int RGWDeleteCORS::verify_permission()
4862 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4869 void RGWDeleteCORS::execute()
4871 op_ret
= read_bucket_cors();
4878 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4882 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4883 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4884 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
4885 map
<string
, bufferlist
>::iterator iter
;
4887 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4891 /* only remove meta attrs */
4892 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4893 const string
& name
= iter
->first
;
4894 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
4895 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
4896 rmattrs
[name
] = iter
->second
;
4897 } else if (attrs
.find(name
) == attrs
.end()) {
4898 attrs
[name
] = iter
->second
;
4901 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4904 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
4905 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
4908 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
4909 rule
= cc
->host_name_rule(origin
);
4911 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
4915 if (!validate_cors_rule_method(rule
, req_meth
)) {
4921 void RGWOptionsCORS::execute()
4923 op_ret
= read_bucket_cors();
4927 origin
= s
->info
.env
->get("HTTP_ORIGIN");
4930 "Preflight request without mandatory Origin header"
4935 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
4938 "Preflight request without mandatory Access-control-request-method header"
4944 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4948 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
4949 op_ret
= validate_cors_request(&bucket_cors
);
4951 origin
= req_meth
= NULL
;
4957 int RGWGetRequestPayment::verify_permission()
4962 void RGWGetRequestPayment::pre_exec()
4964 rgw_bucket_object_pre_exec(s
);
4967 void RGWGetRequestPayment::execute()
4969 requester_pays
= s
->bucket_info
.requester_pays
;
4972 int RGWSetRequestPayment::verify_permission()
4974 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4981 void RGWSetRequestPayment::pre_exec()
4983 rgw_bucket_object_pre_exec(s
);
4986 void RGWSetRequestPayment::execute()
4988 op_ret
= get_params();
4993 s
->bucket_info
.requester_pays
= requester_pays
;
4994 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
4997 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
4998 << " returned err=" << op_ret
<< dendl
;
5003 int RGWInitMultipart::verify_permission()
5005 if (s
->iam_policy
) {
5006 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5007 rgw::IAM::s3PutObject
,
5008 rgw_obj(s
->bucket
, s
->object
));
5009 if (e
== Effect::Allow
) {
5011 } else if (e
== Effect::Deny
) {
5016 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5023 void RGWInitMultipart::pre_exec()
5025 rgw_bucket_object_pre_exec(s
);
5028 void RGWInitMultipart::execute()
5031 map
<string
, bufferlist
> attrs
;
5034 if (get_params() < 0)
5037 if (s
->object
.empty())
5040 policy
.encode(aclbl
);
5041 attrs
[RGW_ATTR_ACL
] = aclbl
;
5043 populate_with_generic_attrs(s
, attrs
);
5045 /* select encryption mode */
5046 op_ret
= prepare_encryption(attrs
);
5050 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5054 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5055 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5056 upload_id
.append(buf
);
5058 string tmp_obj_name
;
5059 RGWMPObj
mp(s
->object
.name
, upload_id
);
5060 tmp_obj_name
= mp
.get_meta();
5062 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5063 // the meta object will be indexed with 0 size, we c
5064 obj
.set_in_extra_data(true);
5065 obj
.index_hash_source
= s
->object
.name
;
5067 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5068 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5070 RGWRados::Object::Write
obj_op(&op_target
);
5072 obj_op
.meta
.owner
= s
->owner
.get_id();
5073 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5074 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5076 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5077 } while (op_ret
== -EEXIST
);
5080 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5082 RGWAccessControlPolicy
*policy
,
5083 map
<string
, bufferlist
>& attrs
)
5085 map
<string
, bufferlist
>::iterator iter
;
5089 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5090 obj
.set_in_extra_data(true);
5092 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5094 if (op_ret
== -ENOENT
) {
5095 return -ERR_NO_SUCH_UPLOAD
;
5101 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5102 string name
= iter
->first
;
5103 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5104 bufferlist
& bl
= iter
->second
;
5105 bufferlist::iterator bli
= bl
.begin();
5107 ::decode(*policy
, bli
);
5108 } catch (buffer::error
& err
) {
5109 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5120 int RGWCompleteMultipart::verify_permission()
5122 if (s
->iam_policy
) {
5123 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5124 rgw::IAM::s3PutObject
,
5125 rgw_obj(s
->bucket
, s
->object
));
5126 if (e
== Effect::Allow
) {
5128 } else if (e
== Effect::Deny
) {
5133 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5140 void RGWCompleteMultipart::pre_exec()
5142 rgw_bucket_object_pre_exec(s
);
5145 void RGWCompleteMultipart::execute()
5147 RGWMultiCompleteUpload
*parts
;
5148 map
<int, string
>::iterator iter
;
5149 RGWMultiXMLParser parser
;
5151 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5152 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5153 map
<string
, bufferlist
> attrs
;
5156 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5157 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5162 RGWObjManifest manifest
;
5163 uint64_t olh_epoch
= 0;
5166 op_ret
= get_params();
5169 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5174 if (!data
|| !len
) {
5175 op_ret
= -ERR_MALFORMED_XML
;
5179 if (!parser
.init()) {
5184 if (!parser
.parse(data
, len
, 1)) {
5185 op_ret
= -ERR_MALFORMED_XML
;
5189 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5190 if (!parts
|| parts
->parts
.empty()) {
5191 op_ret
= -ERR_MALFORMED_XML
;
5195 if ((int)parts
->parts
.size() >
5196 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5201 mp
.init(s
->object
.name
, upload_id
);
5202 meta_oid
= mp
.get_meta();
5204 int total_parts
= 0;
5205 int handled_parts
= 0;
5206 int max_parts
= 1000;
5209 RGWCompressionInfo cs_info
;
5210 bool compressed
= false;
5211 uint64_t accounted_size
= 0;
5213 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5215 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5217 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5219 iter
= parts
->parts
.begin();
5221 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5222 meta_obj
.set_in_extra_data(true);
5223 meta_obj
.index_hash_source
= s
->object
.name
;
5225 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5228 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5229 << " ret=" << op_ret
<< dendl
;
5234 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5235 marker
, obj_parts
, &marker
, &truncated
);
5236 if (op_ret
== -ENOENT
) {
5237 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5242 total_parts
+= obj_parts
.size();
5243 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5244 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5245 << " expected: " << parts
->parts
.size() << dendl
;
5246 op_ret
= -ERR_INVALID_PART
;
5250 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5251 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5252 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5253 part_size
< min_part_size
) {
5254 op_ret
= -ERR_TOO_SMALL
;
5258 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5259 if (iter
->first
!= (int)obj_iter
->first
) {
5260 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5261 << iter
->first
<< " next uploaded: "
5262 << obj_iter
->first
<< dendl
;
5263 op_ret
= -ERR_INVALID_PART
;
5266 string part_etag
= rgw_string_unquote(iter
->second
);
5267 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5268 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5269 << " etag: " << iter
->second
<< dendl
;
5270 op_ret
= -ERR_INVALID_PART
;
5274 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5275 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5276 hash
.Update((const byte
*)petag
, sizeof(petag
));
5278 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5280 /* update manifest for part */
5281 string oid
= mp
.get_part(obj_iter
->second
.num
);
5283 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5285 if (obj_part
.manifest
.empty()) {
5286 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5287 << src_obj
<< dendl
;
5288 op_ret
= -ERR_INVALID_PART
;
5291 manifest
.append(obj_part
.manifest
, store
);
5294 if (obj_part
.cs_info
.compression_type
!= "none") {
5295 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5296 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5297 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5298 op_ret
= -ERR_INVALID_PART
;
5301 int64_t new_ofs
; // offset in compression data for new part
5302 if (cs_info
.blocks
.size() > 0)
5303 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5306 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5307 compression_block cb
;
5308 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5309 cb
.new_ofs
= new_ofs
;
5311 cs_info
.blocks
.push_back(cb
);
5312 new_ofs
= cb
.new_ofs
+ cb
.len
;
5315 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5316 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5320 rgw_obj_index_key remove_key
;
5321 src_obj
.key
.get_index_key(&remove_key
);
5323 remove_objs
.push_back(remove_key
);
5325 ofs
+= obj_part
.size
;
5326 accounted_size
+= obj_part
.accounted_size
;
5328 } while (truncated
);
5329 hash
.Final((byte
*)final_etag
);
5331 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5332 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5333 "-%lld", (long long)parts
->parts
.size());
5334 etag
= final_etag_str
;
5335 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5337 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5339 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5342 // write compression attribute to full object
5344 ::encode(cs_info
, tmp
);
5345 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5348 target_obj
.init(s
->bucket
, s
->object
.name
);
5349 if (versioned_object
) {
5350 store
->gen_rand_obj_instance_name(&target_obj
);
5353 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5355 obj_ctx
.obj
.set_atomic(target_obj
);
5357 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5358 RGWRados::Object::Write
obj_op(&op_target
);
5360 obj_op
.meta
.manifest
= &manifest
;
5361 obj_op
.meta
.remove_objs
= &remove_objs
;
5363 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5364 obj_op
.meta
.owner
= s
->owner
.get_id();
5365 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5366 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5370 // remove the upload obj
5371 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5372 s
->bucket_info
, meta_obj
, 0);
5374 ldout(store
->ctx(), 0) << "WARNING: failed to remove object " << meta_obj
<< dendl
;
5378 int RGWAbortMultipart::verify_permission()
5380 if (s
->iam_policy
) {
5381 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5382 rgw::IAM::s3AbortMultipartUpload
,
5383 rgw_obj(s
->bucket
, s
->object
));
5384 if (e
== Effect::Allow
) {
5386 } else if (e
== Effect::Deny
) {
5391 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5398 void RGWAbortMultipart::pre_exec()
5400 rgw_bucket_object_pre_exec(s
);
5403 void RGWAbortMultipart::execute()
5408 upload_id
= s
->info
.args
.get("uploadId");
5409 map
<string
, bufferlist
> attrs
;
5413 if (upload_id
.empty() || s
->object
.empty())
5416 mp
.init(s
->object
.name
, upload_id
);
5417 meta_oid
= mp
.get_meta();
5419 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5423 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5424 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5427 int RGWListMultipart::verify_permission()
5429 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5435 void RGWListMultipart::pre_exec()
5437 rgw_bucket_object_pre_exec(s
);
5440 void RGWListMultipart::execute()
5442 map
<string
, bufferlist
> xattrs
;
5446 op_ret
= get_params();
5450 mp
.init(s
->object
.name
, upload_id
);
5451 meta_oid
= mp
.get_meta();
5453 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5457 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5458 marker
, parts
, NULL
, &truncated
);
5461 int RGWListBucketMultiparts::verify_permission()
5463 if (!verify_bucket_permission(s
,
5464 rgw::IAM::s3ListBucketMultiPartUploads
))
5470 void RGWListBucketMultiparts::pre_exec()
5472 rgw_bucket_object_pre_exec(s
);
5475 void RGWListBucketMultiparts::execute()
5477 vector
<rgw_bucket_dir_entry
> objs
;
5480 op_ret
= get_params();
5484 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5486 path_args
= s
->info
.args
.get("path");
5487 if (!path_args
.empty()) {
5488 if (!delimiter
.empty() || !prefix
.empty()) {
5496 marker_meta
= marker
.get_meta();
5498 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5499 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5504 if (!objs
.empty()) {
5505 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5506 RGWMultipartUploadEntry entry
;
5507 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5508 rgw_obj_key
key(iter
->key
);
5509 if (!entry
.mp
.from_meta(key
.name
))
5512 uploads
.push_back(entry
);
5514 next_marker
= entry
;
5518 void RGWGetHealthCheck::execute()
5520 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5521 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5522 /* Disabling path specified & existent in the filesystem. */
5523 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5525 op_ret
= 0; /* 200 OK */
5529 int RGWDeleteMultiObj::verify_permission()
5531 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5532 if (!acl_allowed
&& !s
->iam_policy
)
5538 void RGWDeleteMultiObj::pre_exec()
5540 rgw_bucket_object_pre_exec(s
);
5543 void RGWDeleteMultiObj::execute()
5545 RGWMultiDelDelete
*multi_delete
;
5546 vector
<rgw_obj_key
>::iterator iter
;
5547 RGWMultiDelXMLParser parser
;
5548 int num_processed
= 0;
5549 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5551 op_ret
= get_params();
5561 if (!parser
.init()) {
5566 if (!parser
.parse(data
, len
, 1)) {
5571 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5572 if (!multi_delete
) {
5577 if (multi_delete
->is_quiet())
5581 if (multi_delete
->objects
.empty()) {
5585 for (iter
= multi_delete
->objects
.begin();
5586 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5587 ++iter
, num_processed
++) {
5588 rgw_obj
obj(bucket
, *iter
);
5589 if (s
->iam_policy
) {
5590 auto e
= s
->iam_policy
->eval(s
->env
,
5592 iter
->instance
.empty() ?
5593 rgw::IAM::s3DeleteObject
:
5594 rgw::IAM::s3DeleteObjectVersion
,
5596 if ((e
== Effect::Deny
) ||
5597 (e
== Effect::Pass
&& !acl_allowed
)) {
5598 send_partial_response(*iter
, false, "", -EACCES
);
5603 obj_ctx
->obj
.set_atomic(obj
);
5605 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5606 RGWRados::Object::Delete
del_op(&del_target
);
5608 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5609 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5610 del_op
.params
.obj_owner
= s
->owner
;
5612 op_ret
= del_op
.delete_obj();
5613 if (op_ret
== -ENOENT
) {
5617 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5618 del_op
.result
.version_id
, op_ret
);
5621 /* set the return code to zero, errors at this point will be
5622 dumped to the response */
5626 // will likely segfault if begin_response() has not been called
5638 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5639 map
<string
, bufferlist
>& battrs
,
5640 ACLOwner
& bucket_owner
/* out */)
5642 RGWAccessControlPolicy
bacl(store
->ctx());
5643 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5648 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5650 bucket_owner
= bacl
.get_owner();
5652 /* We can use global user_acl because each BulkDelete request is allowed
5653 * to work on entities from a single account only. */
5654 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5655 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5658 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5660 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5662 RGWBucketInfo binfo
;
5663 map
<string
, bufferlist
> battrs
;
5666 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5667 path
.bucket_name
, binfo
, nullptr,
5673 if (!verify_permission(binfo
, battrs
, bowner
)) {
5678 if (!path
.obj_key
.empty()) {
5679 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5680 obj_ctx
.obj
.set_atomic(obj
);
5682 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5683 RGWRados::Object::Delete
del_op(&del_target
);
5685 del_op
.params
.bucket_owner
= binfo
.owner
;
5686 del_op
.params
.versioning_status
= binfo
.versioning_status();
5687 del_op
.params
.obj_owner
= bowner
;
5689 ret
= del_op
.delete_obj();
5694 RGWObjVersionTracker ot
;
5695 ot
.read_version
= binfo
.ep_objv
;
5697 ret
= store
->delete_bucket(binfo
, ot
);
5699 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5700 binfo
.bucket
.name
, false);
5702 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
5710 if (!store
->is_meta_master()) {
5712 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
5715 if (ret
== -ENOENT
) {
5716 /* adjust error, we want to return with NoSuchBucket and not
5718 ret
= -ERR_NO_SUCH_BUCKET
;
5730 if (-ENOENT
== ret
) {
5731 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
5734 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
5737 fail_desc_t failed_item
= {
5741 failures
.push_back(failed_item
);
5746 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
5748 fail_desc_t failed_item
= {
5752 failures
.push_back(failed_item
);
5757 if (-ENOENT
== ret
) {
5758 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
5761 fail_desc_t failed_item
= {
5765 failures
.push_back(failed_item
);
5770 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
5772 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
5773 for (auto path
: paths
) {
5774 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
5775 delete_single(path
);
5781 int RGWBulkDelete::verify_permission()
5786 void RGWBulkDelete::pre_exec()
5788 rgw_bucket_object_pre_exec(s
);
5791 void RGWBulkDelete::execute()
5793 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
5795 bool is_truncated
= false;
5797 list
<RGWBulkDelete::acct_path_t
> items
;
5799 int ret
= get_data(items
, &is_truncated
);
5804 ret
= deleter
->delete_chunk(items
);
5805 } while (!op_ret
&& is_truncated
);
5811 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
5813 int RGWBulkUploadOp::verify_permission()
5815 if (s
->auth
.identity
->is_anonymous()) {
5819 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
5823 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
5824 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
5825 << " (user_id.tenant=" << s
->user
->user_id
.tenant
5826 << " requested=" << s
->bucket_tenant
<< ")"
5831 if (s
->user
->max_buckets
< 0) {
5838 void RGWBulkUploadOp::pre_exec()
5840 rgw_bucket_object_pre_exec(s
);
5843 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
5844 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
5846 /* We need to skip all slashes at the beginning in order to preserve
5847 * compliance with Swift. */
5848 const size_t start_pos
= path
.find_first_not_of('/');
5850 if (boost::string_ref::npos
!= start_pos
) {
5851 /* Seperator is the first slash after the leading ones. */
5852 const size_t sep_pos
= path
.substr(start_pos
).find('/');
5854 if (boost::string_ref::npos
!= sep_pos
) {
5855 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
5856 const auto obj_name
= path
.substr(sep_pos
+ 1);
5858 return std::make_pair(bucket_name
.to_string(),
5859 rgw_obj_key(obj_name
.to_string()));
5861 /* It's guaranteed here that bucket name is at least one character
5862 * long and is different than slash. */
5863 return std::make_pair(path
.substr(start_pos
).to_string(),
5871 std::pair
<std::string
, std::string
>
5872 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
5874 std::string bucket_path
, file_prefix
;
5875 if (! s
->init_state
.url_bucket
.empty()) {
5876 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
5877 if (! s
->object
.empty()) {
5878 std::string
& object_name
= s
->object
.name
;
5880 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
5881 * we can safely examine its last element. */
5882 if (object_name
.back() == '/') {
5883 file_prefix
.append(object_name
);
5885 file_prefix
.append(object_name
).append("/");
5889 return std::make_pair(bucket_path
, file_prefix
);
5892 int RGWBulkUploadOp::handle_dir_verify_permission()
5894 if (s
->user
->max_buckets
> 0) {
5895 RGWUserBuckets buckets
;
5897 bool is_truncated
= false;
5898 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
5899 marker
, std::string(), s
->user
->max_buckets
,
5900 false, &is_truncated
);
5905 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
5906 return -ERR_TOO_MANY_BUCKETS
;
5913 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
5915 /* the request of container or object level will contain bucket name.
5916 * only at account level need to append the bucket name */
5917 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
5921 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
5922 info
.script_uri
.append("/").append(bucket_name
);
5923 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
5924 info
.effective_uri
= "/" + bucket_name
;
5927 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
5929 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
5931 op_ret
= handle_dir_verify_permission();
5936 std::string bucket_name
;
5937 rgw_obj_key object_junk
;
5938 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
5940 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
5941 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
5943 /* we need to make sure we read bucket info, it's not read before for this
5944 * specific request */
5945 RGWBucketInfo binfo
;
5946 std::map
<std::string
, ceph::bufferlist
> battrs
;
5947 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
5948 binfo
, NULL
, &battrs
);
5949 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
5952 const bool bucket_exists
= (op_ret
!= -ENOENT
);
5954 if (bucket_exists
) {
5955 RGWAccessControlPolicy
old_policy(s
->cct
);
5956 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
5957 battrs
, &old_policy
);
5959 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
5966 RGWBucketInfo master_info
;
5967 rgw_bucket
*pmaster_bucket
= nullptr;
5968 uint32_t *pmaster_num_shards
= nullptr;
5969 real_time creation_time
;
5970 obj_version objv
, ep_objv
, *pobjv
= nullptr;
5972 if (! store
->is_meta_master()) {
5974 ceph::bufferlist in_data
;
5975 req_info info
= s
->info
;
5976 forward_req_info(s
->cct
, info
, bucket_name
);
5977 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
5982 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
5983 JSONDecoder::decode_json("object_ver", objv
, &jp
);
5984 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
5986 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
5987 << objv
.ver
<< dendl
;
5988 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
5991 pmaster_bucket
= &master_info
.bucket
;
5992 creation_time
= master_info
.creation_time
;
5993 pmaster_num_shards
= &master_info
.num_shards
;
5996 pmaster_bucket
= nullptr;
5997 pmaster_num_shards
= nullptr;
6001 std::string placement_rule
;
6002 if (bucket_exists
) {
6003 std::string selected_placement_rule
;
6005 bucket
.tenant
= s
->bucket_tenant
;
6006 bucket
.name
= s
->bucket_name
;
6007 op_ret
= store
->select_bucket_placement(*(s
->user
),
6008 store
->get_zonegroup().get_id(),
6010 &selected_placement_rule
,
6012 if (selected_placement_rule
!= binfo
.placement_rule
) {
6014 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6019 /* Create metadata: ACLs. */
6020 std::map
<std::string
, ceph::bufferlist
> attrs
;
6021 RGWAccessControlPolicy policy
;
6022 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6023 ceph::bufferlist aclbl
;
6024 policy
.encode(aclbl
);
6025 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6027 RGWQuotaInfo quota_info
;
6028 const RGWQuotaInfo
* pquota_info
= nullptr;
6031 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6032 bucket
.name
= bucket_name
;
6035 RGWBucketInfo out_info
;
6036 op_ret
= store
->create_bucket(*(s
->user
),
6038 store
->get_zonegroup().get_id(),
6039 placement_rule
, binfo
.swift_ver_location
,
6041 out_info
, pobjv
, &ep_objv
, creation_time
,
6042 pmaster_bucket
, pmaster_num_shards
, true);
6043 /* continue if EEXIST and create_bucket will fail below. this way we can
6044 * recover from a partial create by retrying it. */
6045 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6046 << ", bucket=" << bucket
<< dendl
;
6048 if (op_ret
&& op_ret
!= -EEXIST
) {
6052 const bool existed
= (op_ret
== -EEXIST
);
6054 /* bucket already existed, might have raced with another bucket creation, or
6055 * might be partial bucket creation that never completed. Read existing bucket
6056 * info, verify that the reported bucket owner is the current user.
6057 * If all is ok then update the user's list of buckets.
6058 * Otherwise inform client about a name conflict.
6060 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6062 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6065 bucket
= out_info
.bucket
;
6068 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6069 out_info
.creation_time
, false);
6070 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6071 /* if it exists (or previously existed), don't remove it! */
6072 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6073 bucket
.tenant
, bucket
.name
);
6075 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6078 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6079 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6081 op_ret
= -ERR_BUCKET_EXISTS
;
6088 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6090 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6091 ACLOwner
& bucket_owner
/* out */)
6093 RGWAccessControlPolicy
bacl(store
->ctx());
6094 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6096 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6101 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6103 bucket_owner
= bacl
.get_owner();
6105 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6106 rgw::IAM::s3PutObject
, obj
);
6107 if (e
== Effect::Allow
) {
6109 } else if (e
== Effect::Deny
) {
6114 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6115 &bacl
, RGW_PERM_WRITE
);
6118 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6120 AlignedStreamGetter
& body
)
6123 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6126 RGWPutObjDataProcessor
*filter
= nullptr;
6127 boost::optional
<RGWPutObj_Compress
> compressor
;
6129 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6130 op_ret
= -ERR_TOO_LARGE
;
6134 std::string bucket_name
;
6136 std::tie(bucket_name
, object
) = *parse_path(path
);
6138 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6139 RGWBucketInfo binfo
;
6140 std::map
<std::string
, ceph::bufferlist
> battrs
;
6142 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6143 bucket_name
, binfo
, nullptr, &battrs
);
6144 if (op_ret
== -ENOENT
) {
6145 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6147 } else if (op_ret
< 0) {
6151 if (! handle_file_verify_permission(binfo
,
6152 rgw_obj(binfo
.bucket
, object
),
6154 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6159 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6160 user_quota
, bucket_quota
, size
);
6165 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6170 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6175 s
->cct
->_conf
->rgw_obj_stripe_size
,
6177 binfo
.versioning_enabled());
6179 /* No filters by default. */
6180 filter
= &processor
;
6182 op_ret
= processor
.prepare(store
, nullptr);
6184 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6189 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6190 binfo
.placement_rule
);
6191 CompressorRef plugin
;
6192 if (compression_type
!= "none") {
6193 plugin
= Compressor::create(s
->cct
, compression_type
);
6195 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6196 << compression_type
<< dendl
;
6198 compressor
.emplace(s
->cct
, plugin
, filter
);
6199 filter
= &*compressor
;
6203 /* Upload file content. */
6208 ceph::bufferlist data
;
6209 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6211 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6215 } else if (len
> 0) {
6216 hash
.Update((const byte
*)data
.c_str(), data
.length());
6217 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6219 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6230 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6235 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6236 user_quota
, bucket_quota
, size
);
6238 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6243 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6248 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6249 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6251 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6253 /* Create metadata: ETAG. */
6254 std::map
<std::string
, ceph::bufferlist
> attrs
;
6255 std::string etag
= calc_md5
;
6256 ceph::bufferlist etag_bl
;
6257 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6258 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6260 /* Create metadata: ACLs. */
6261 RGWAccessControlPolicy policy
;
6262 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6263 ceph::bufferlist aclbl
;
6264 policy
.encode(aclbl
);
6265 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6267 /* Create metadata: compression info. */
6268 if (compressor
&& compressor
->is_compressed()) {
6269 ceph::bufferlist tmp
;
6270 RGWCompressionInfo cs_info
;
6271 cs_info
.compression_type
= plugin
->get_type_name();
6272 cs_info
.orig_size
= s
->obj_size
;
6273 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6274 ::encode(cs_info
, tmp
);
6275 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6278 /* Complete the transaction. */
6279 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6280 ceph::real_time() /* delete_at */);
6282 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6289 void RGWBulkUploadOp::execute()
6291 ceph::bufferlist
buffer(64 * 1024);
6293 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6295 /* Create an instance of stream-abstracting class. Having this indirection
6296 * allows for easy introduction of decompressors like gzip and bzip2. */
6297 auto stream
= create_stream();
6302 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6303 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6304 std::string bucket_path
, file_prefix
;
6305 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6307 auto status
= rgw::tar::StatusIndicator::create();
6309 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6311 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6315 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6316 * must be tracked to detect out end-of-archive. It occurs when both of
6317 * them are empty (zeroed). Tracing this particular inter-block dependency
6318 * is responsibility of the rgw::tar::StatusIndicator class. */
6319 boost::optional
<rgw::tar::HeaderView
> header
;
6320 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6322 if (! status
.empty() && header
) {
6323 /* This specific block isn't empty (entirely zeroed), so we can parse
6324 * it as a TAR header and dispatch. At the moment we do support only
6325 * regular files and directories. Everything else (symlinks, devices)
6326 * will be ignored but won't cease the whole upload. */
6327 switch (header
->get_filetype()) {
6328 case rgw::tar::FileType::NORMAL_FILE
: {
6329 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6331 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6332 file_prefix
+ header
->get_filename().to_string();
6333 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6334 rgw::tar::BLOCK_SIZE
, *stream
);
6335 op_ret
= handle_file(filename
,
6336 header
->get_filesize(),
6339 /* Only regular files counts. */
6342 failures
.emplace_back(op_ret
, filename
.to_string());
6346 case rgw::tar::FileType::DIRECTORY
: {
6347 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6349 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6350 op_ret
= handle_dir(dirname
);
6351 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6352 failures
.emplace_back(op_ret
, dirname
.to_string());
6357 /* Not recognized. Skip. */
6363 /* In case of any problems with sub-request authorization Swift simply
6364 * terminates whole upload immediately. */
6365 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6367 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6372 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6377 } while (! status
.eof());
6382 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6384 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6385 ceph::bufferlist junk
;
6387 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6390 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6391 ceph::bufferlist
& dst
)
6393 const size_t max_to_read
= std::min(want
, length
- position
);
6394 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6401 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6402 ceph::bufferlist
& dst
)
6404 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6411 int RGWSetAttrs::verify_permission()
6413 // This looks to be part of the RGW-NFS machinery and has no S3 or
6414 // Swift equivalent.
6416 if (!s
->object
.empty()) {
6417 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6419 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6427 void RGWSetAttrs::pre_exec()
6429 rgw_bucket_object_pre_exec(s
);
6432 void RGWSetAttrs::execute()
6434 op_ret
= get_params();
6438 rgw_obj
obj(s
->bucket
, s
->object
);
6440 if (!s
->object
.empty()) {
6441 store
->set_atomic(s
->obj_ctx
, obj
);
6442 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6444 for (auto& iter
: attrs
) {
6445 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6447 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6448 &s
->bucket_info
.objv_tracker
);
6452 void RGWGetObjLayout::pre_exec()
6454 rgw_bucket_object_pre_exec(s
);
6457 void RGWGetObjLayout::execute()
6459 rgw_obj
obj(s
->bucket
, s
->object
);
6460 RGWRados::Object
target(store
,
6462 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6463 rgw_obj(s
->bucket
, s
->object
));
6464 RGWRados::Object::Read
stat_op(&target
);
6466 op_ret
= stat_op
.prepare();
6471 head_obj
= stat_op
.state
.head_obj
;
6473 op_ret
= target
.get_manifest(&manifest
);
6477 int RGWConfigBucketMetaSearch::verify_permission()
6479 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6486 void RGWConfigBucketMetaSearch::pre_exec()
6488 rgw_bucket_object_pre_exec(s
);
6491 void RGWConfigBucketMetaSearch::execute()
6493 op_ret
= get_params();
6495 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6499 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6501 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6503 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6508 int RGWGetBucketMetaSearch::verify_permission()
6510 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6517 void RGWGetBucketMetaSearch::pre_exec()
6519 rgw_bucket_object_pre_exec(s
);
6522 int RGWDelBucketMetaSearch::verify_permission()
6524 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6531 void RGWDelBucketMetaSearch::pre_exec()
6533 rgw_bucket_object_pre_exec(s
);
6536 void RGWDelBucketMetaSearch::execute()
6538 s
->bucket_info
.mdsearch_config
.clear();
6540 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6542 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6548 RGWHandler::~RGWHandler()
6552 int RGWHandler::init(RGWRados
*_store
,
6553 struct req_state
*_s
,
6554 rgw::io::BasicClient
*cio
)
6562 int RGWHandler::do_init_permissions()
6564 int ret
= rgw_build_bucket_policies(store
, s
);
6565 s
->env
= rgw_build_iam_environment(store
, s
);
6568 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6569 if (ret
== -ENODATA
)
6576 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6579 /* already read bucket info */
6582 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6585 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6586 << s
->object
<< " only_bucket=" << only_bucket
6587 << " ret=" << ret
<< dendl
;
6588 if (ret
== -ENODATA
)
6595 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6596 return dialect_handler
->error_handler(err_no
, error_content
);
6599 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6600 // This is the do-nothing error handler
6605 void RGWPutBucketPolicy::send_response()
6608 set_req_state_err(s
, op_ret
);
6614 int RGWPutBucketPolicy::verify_permission()
6616 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6623 int RGWPutBucketPolicy::get_params()
6625 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6626 // At some point when I have more time I want to make a version of
6627 // rgw_rest_read_all_input that doesn't use malloc.
6628 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6629 // And throws exceptions.
6633 void RGWPutBucketPolicy::execute()
6635 op_ret
= get_params();
6640 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6642 if (!store
->is_meta_master()) {
6643 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6645 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6651 Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6652 auto attrs
= s
->bucket_attrs
;
6653 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6654 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6655 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6656 &s
->bucket_info
.objv_tracker
);
6657 if (op_ret
== -ECANCELED
) {
6658 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */
6660 } catch (rgw::IAM::PolicyParseException
& e
) {
6661 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6666 void RGWGetBucketPolicy::send_response()
6669 set_req_state_err(s
, op_ret
);
6672 end_header(s
, this, "application/json");
6673 dump_body(s
, policy
);
6676 int RGWGetBucketPolicy::verify_permission()
6678 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6685 void RGWGetBucketPolicy::execute()
6687 auto attrs
= s
->bucket_attrs
;
6688 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6689 if (aiter
== attrs
.end()) {
6690 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6691 << " bucket_name = " << s
->bucket_name
<< dendl
;
6692 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6693 s
->err
.message
= "The bucket policy does not exist";
6696 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6698 if (policy
.length() == 0) {
6699 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6700 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6701 s
->err
.message
= "The bucket policy does not exist";
6707 void RGWDeleteBucketPolicy::send_response()
6710 set_req_state_err(s
, op_ret
);
6716 int RGWDeleteBucketPolicy::verify_permission()
6718 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
6725 void RGWDeleteBucketPolicy::execute()
6727 auto attrs
= s
->bucket_attrs
;
6728 attrs
.erase(RGW_ATTR_IAM_POLICY
);
6729 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6730 &s
->bucket_info
.objv_tracker
);
6731 if (op_ret
== -ECANCELED
) {
6732 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */