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/backport14.h"
20 #include "common/errno.h"
21 #include "common/mime.h"
22 #include "common/utf8.h"
23 #include "common/ceph_json.h"
25 #include "rgw_rados.h"
29 #include "rgw_acl_s3.h"
30 #include "rgw_acl_swift.h"
32 #include "rgw_bucket.h"
34 #include "rgw_multi.h"
35 #include "rgw_multi_del.h"
37 #include "rgw_cors_s3.h"
38 #include "rgw_rest_conn.h"
39 #include "rgw_rest_s3.h"
41 #include "rgw_client_io.h"
42 #include "rgw_compression.h"
44 #include "rgw_tag_s3.h"
45 #include "cls/lock/cls_lock_client.h"
46 #include "cls/rgw/cls_rgw_client.h"
49 #include "include/assert.h"
51 #include "compressor/Compressor.h"
53 #include "rgw_acl_swift.h"
55 #define dout_context g_ceph_context
56 #define dout_subsys ceph_subsys_rgw
59 using namespace librados
;
60 using ceph::crypto::MD5
;
61 using boost::optional
;
65 using rgw::IAM::Effect
;
66 using rgw::IAM::Policy
;
68 using rgw::IAM::Policy
;
70 static string mp_ns
= RGW_OBJ_NS_MULTIPART
;
71 static string shadow_ns
= RGW_OBJ_NS_SHADOW
;
73 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
);
74 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
, RGWRados
*store
,
75 bufferlist
& in_data
, JSONParser
*jp
, req_info
*forward_info
= nullptr);
77 static MultipartMetaFilter mp_filter
;
79 static int parse_range(const char *range
, off_t
& ofs
, off_t
& end
, bool *partial_content
)
86 *partial_content
= false;
88 size_t pos
= s
.find("bytes=");
89 if (pos
== string::npos
) {
91 while (isspace(s
[pos
]))
94 while (isalpha(s
[end
]))
96 if (strncasecmp(s
.c_str(), "bytes", end
- pos
) != 0)
98 while (isspace(s
[end
]))
102 s
= s
.substr(end
+ 1);
104 s
= s
.substr(pos
+ 6); /* size of("bytes=") */
107 if (pos
== string::npos
)
110 *partial_content
= true;
112 ofs_str
= s
.substr(0, pos
);
113 end_str
= s
.substr(pos
+ 1);
114 if (end_str
.length()) {
115 end
= atoll(end_str
.c_str());
120 if (ofs_str
.length()) {
121 ofs
= atoll(ofs_str
.c_str());
122 } else { // RFC2616 suffix-byte-range-spec
127 if (end
>= 0 && end
< ofs
)
135 static int decode_policy(CephContext
*cct
,
137 RGWAccessControlPolicy
*policy
)
139 bufferlist::iterator iter
= bl
.begin();
141 policy
->decode(iter
);
142 } catch (buffer::error
& err
) {
143 ldout(cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
146 if (cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
147 RGWAccessControlPolicy_S3
*s3policy
= static_cast<RGWAccessControlPolicy_S3
*>(policy
);
148 ldout(cct
, 15) << __func__
<< " Read AccessControlPolicy";
149 s3policy
->to_xml(*_dout
);
156 static int get_user_policy_from_attr(CephContext
* const cct
,
157 RGWRados
* const store
,
158 map
<string
, bufferlist
>& attrs
,
159 RGWAccessControlPolicy
& policy
/* out */)
161 auto aiter
= attrs
.find(RGW_ATTR_ACL
);
162 if (aiter
!= attrs
.end()) {
163 int ret
= decode_policy(cct
, aiter
->second
, &policy
);
174 static int get_bucket_instance_policy_from_attr(CephContext
*cct
,
176 RGWBucketInfo
& bucket_info
,
177 map
<string
, bufferlist
>& bucket_attrs
,
178 RGWAccessControlPolicy
*policy
,
181 map
<string
, bufferlist
>::iterator aiter
= bucket_attrs
.find(RGW_ATTR_ACL
);
183 if (aiter
!= bucket_attrs
.end()) {
184 int ret
= decode_policy(cct
, aiter
->second
, policy
);
188 ldout(cct
, 0) << "WARNING: couldn't find acl header for bucket, generating default" << dendl
;
190 /* object exists, but policy is broken */
191 int r
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
195 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
200 static int get_obj_policy_from_attr(CephContext
*cct
,
202 RGWObjectCtx
& obj_ctx
,
203 RGWBucketInfo
& bucket_info
,
204 map
<string
, bufferlist
>& bucket_attrs
,
205 RGWAccessControlPolicy
*policy
,
211 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
212 RGWRados::Object::Read
rop(&op_target
);
214 ret
= rop
.get_attr(RGW_ATTR_ACL
, bl
);
216 ret
= decode_policy(cct
, bl
, policy
);
219 } else if (ret
== -ENODATA
) {
220 /* object exists, but policy is broken */
221 ldout(cct
, 0) << "WARNING: couldn't find acl header for object, generating default" << dendl
;
223 ret
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
227 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
234 * Get the AccessControlPolicy for an object off of disk.
235 * policy: must point to a valid RGWACL, and will be filled upon return.
236 * bucket: name of the bucket containing the object.
237 * object: name of the object to get the ACL for.
238 * Returns: 0 on success, -ERR# otherwise.
240 static int get_bucket_policy_from_attr(CephContext
*cct
,
242 RGWBucketInfo
& bucket_info
,
243 map
<string
, bufferlist
>& bucket_attrs
,
244 RGWAccessControlPolicy
*policy
)
246 rgw_raw_obj instance_obj
;
247 store
->get_bucket_instance_obj(bucket_info
.bucket
, instance_obj
);
248 return get_bucket_instance_policy_from_attr(cct
, store
, bucket_info
, bucket_attrs
,
249 policy
, instance_obj
);
252 static optional
<Policy
> get_iam_policy_from_attr(CephContext
* cct
,
254 map
<string
, bufferlist
>& attrs
,
255 const string
& tenant
) {
256 auto i
= attrs
.find(RGW_ATTR_IAM_POLICY
);
257 if (i
!= attrs
.end()) {
258 return Policy(cct
, tenant
, i
->second
);
264 static int get_obj_attrs(RGWRados
*store
, struct req_state
*s
, rgw_obj
& obj
, map
<string
, bufferlist
>& attrs
)
266 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
267 RGWRados::Object::Read
read_op(&op_target
);
269 read_op
.params
.attrs
= &attrs
;
271 return read_op
.prepare();
274 static int modify_obj_attr(RGWRados
*store
, struct req_state
*s
, rgw_obj
& obj
, const char* attr_name
, bufferlist
& attr_val
)
276 map
<string
, bufferlist
> attrs
;
277 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
278 RGWRados::Object::Read
read_op(&op_target
);
280 read_op
.params
.attrs
= &attrs
;
282 int r
= read_op
.prepare();
286 store
->set_atomic(s
->obj_ctx
, read_op
.state
.obj
);
287 attrs
[attr_name
] = attr_val
;
288 return store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, read_op
.state
.obj
, attrs
, NULL
);
291 static int get_system_obj_attrs(RGWRados
*store
, struct req_state
*s
, rgw_raw_obj
& obj
, map
<string
, bufferlist
>& attrs
,
292 uint64_t *obj_size
, RGWObjVersionTracker
*objv_tracker
)
294 RGWRados::SystemObject
src(store
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
295 RGWRados::SystemObject::Read
rop(&src
);
297 rop
.stat_params
.attrs
= &attrs
;
298 rop
.stat_params
.obj_size
= obj_size
;
300 int ret
= rop
.stat(objv_tracker
);
304 static int read_bucket_policy(RGWRados
*store
,
306 RGWBucketInfo
& bucket_info
,
307 map
<string
, bufferlist
>& bucket_attrs
,
308 RGWAccessControlPolicy
*policy
,
311 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
312 ldout(s
->cct
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
<< " is suspended" << dendl
;
313 return -ERR_USER_SUSPENDED
;
316 if (bucket
.name
.empty()) {
320 int ret
= get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, policy
);
321 if (ret
== -ENOENT
) {
322 ret
= -ERR_NO_SUCH_BUCKET
;
328 static int read_obj_policy(RGWRados
*store
,
330 RGWBucketInfo
& bucket_info
,
331 map
<string
, bufferlist
>& bucket_attrs
,
332 RGWAccessControlPolicy
* acl
,
333 optional
<Policy
>& policy
,
338 upload_id
= s
->info
.args
.get("uploadId");
341 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
342 ldout(s
->cct
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
<< " is suspended" << dendl
;
343 return -ERR_USER_SUSPENDED
;
346 if (!upload_id
.empty()) {
347 /* multipart upload */
348 RGWMPObj
mp(object
.name
, upload_id
);
349 string oid
= mp
.get_meta();
350 obj
.init_ns(bucket
, oid
, mp_ns
);
351 obj
.set_in_extra_data(true);
353 obj
= rgw_obj(bucket
, object
);
355 policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
, bucket
.tenant
);
357 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
358 int ret
= get_obj_policy_from_attr(s
->cct
, store
, *obj_ctx
,
359 bucket_info
, bucket_attrs
, acl
, obj
);
360 if (ret
== -ENOENT
) {
361 /* object does not exist checking the bucket's ACL to make sure
362 that we send a proper error code */
363 RGWAccessControlPolicy
bucket_policy(s
->cct
);
364 ret
= get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, &bucket_policy
);
369 const rgw_user
& bucket_owner
= bucket_policy
.get_owner().get_id();
370 if (bucket_owner
.compare(s
->user
->user_id
) != 0 &&
371 ! s
->auth
.identity
->is_admin_of(bucket_owner
) &&
372 ! bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
384 * Get the AccessControlPolicy for an user, bucket or object off of disk.
385 * s: The req_state to draw information from.
386 * only_bucket: If true, reads the user and bucket ACLs rather than the object ACL.
387 * Returns: 0 on success, -ERR# otherwise.
389 int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
)
393 RGWUserInfo bucket_owner_info
;
394 RGWObjectCtx
obj_ctx(store
);
396 string bi
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"bucket-instance");
398 ret
= rgw_bucket_parse_bucket_instance(bi
, &s
->bucket_instance_id
, &s
->bucket_instance_shard_id
);
404 if(s
->dialect
.compare("s3") == 0) {
405 s
->bucket_acl
= ceph::make_unique
<RGWAccessControlPolicy_S3
>(s
->cct
);
406 } else if(s
->dialect
.compare("swift") == 0) {
407 /* We aren't allocating the account policy for those operations using
408 * the Swift's infrastructure that don't really need req_state::user.
409 * Typical example here is the implementation of /info. */
410 if (!s
->user
->user_id
.empty()) {
411 s
->user_acl
= ceph::make_unique
<RGWAccessControlPolicy_SWIFTAcct
>(s
->cct
);
413 s
->bucket_acl
= ceph::make_unique
<RGWAccessControlPolicy_SWIFT
>(s
->cct
);
415 s
->bucket_acl
= ceph::make_unique
<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
,
461 s
->bucket_acl
.get(), s
->bucket
);
463 s
->bucket_info
.owner
,
464 s
->bucket_acl
->get_owner().get_display_name(),
467 s
->bucket_acl
->create_default(s
->user
->user_id
, s
->user
->display_name
);
468 ret
= -ERR_NO_SUCH_BUCKET
;
471 s
->bucket_owner
= s
->bucket_acl
->get_owner();
473 RGWZoneGroup zonegroup
;
474 int r
= store
->get_zonegroup(s
->bucket_info
.zonegroup
, zonegroup
);
476 if (!zonegroup
.endpoints
.empty()) {
477 s
->zonegroup_endpoint
= zonegroup
.endpoints
.front();
479 // use zonegroup's master zone endpoints
480 auto z
= zonegroup
.zones
.find(zonegroup
.master_zone
);
481 if (z
!= zonegroup
.zones
.end() && !z
->second
.endpoints
.empty()) {
482 s
->zonegroup_endpoint
= z
->second
.endpoints
.front();
485 s
->zonegroup_name
= zonegroup
.get_name();
487 if (r
< 0 && ret
== 0) {
491 if (s
->bucket_exists
&& !store
->get_zonegroup().equals(s
->bucket_info
.zonegroup
)) {
492 ldout(s
->cct
, 0) << "NOTICE: request for data in a different zonegroup (" << s
->bucket_info
.zonegroup
<< " != " << store
->get_zonegroup().get_id() << ")" << dendl
;
493 /* we now need to make sure that the operation actually requires copy source, that is
494 * it's a copy operation
496 if (store
->get_zonegroup().is_master_zonegroup() && s
->system_request
) {
497 /*If this is the master, don't redirect*/
498 } else if (s
->op_type
== RGW_OP_GET_BUCKET_LOCATION
) {
499 /* If op is get bucket location, don't redirect */
500 } else if (!s
->local_source
||
501 (s
->op
!= OP_PUT
&& s
->op
!= OP_COPY
) ||
503 return -ERR_PERMANENT_REDIRECT
;
508 /* handle user ACL only for those APIs which support it */
510 map
<string
, bufferlist
> uattrs
;
512 ret
= rgw_get_user_attrs_by_uid(store
, acct_acl_user
.uid
, uattrs
);
514 ret
= get_user_policy_from_attr(s
->cct
, store
, uattrs
, *s
->user_acl
);
516 if (-ENOENT
== ret
) {
517 /* In already existing clusters users won't have ACL. In such case
518 * assuming that only account owner has the rights seems to be
519 * reasonable. That allows to have only one verification logic.
520 * NOTE: there is small compatibility kludge for global, empty tenant:
521 * 1. if we try to reach an existing bucket, its owner is considered
523 * 2. otherwise account owner is identity stored in s->user->user_id. */
524 s
->user_acl
->create_default(acct_acl_user
.uid
,
525 acct_acl_user
.display_name
);
528 ldout(s
->cct
, 0) << "NOTICE: couldn't get user attrs for handling ACL (user_id="
538 s
->iam_policy
= get_iam_policy_from_attr(s
->cct
, store
, s
->bucket_attrs
,
540 } catch (const std::exception
& e
) {
541 // Really this is a can't happen condition. We parse the policy
542 // when it's given to us, so perhaps we should abort or otherwise
543 // raise bloody murder.
544 lderr(s
->cct
) << "Error reading IAM Policy: " << e
.what() << dendl
;
552 * Get the AccessControlPolicy for a bucket or object off of disk.
553 * s: The req_state to draw information from.
554 * only_bucket: If true, reads the bucket ACL rather than the object ACL.
555 * Returns: 0 on success, -ERR# otherwise.
557 int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
562 if (!s
->object
.empty()) {
563 if (!s
->bucket_exists
) {
564 return -ERR_NO_SUCH_BUCKET
;
566 s
->object_acl
= ceph::make_unique
<RGWAccessControlPolicy
>(s
->cct
);
568 rgw_obj
obj(s
->bucket
, s
->object
);
570 store
->set_atomic(s
->obj_ctx
, obj
);
572 store
->set_prefetch_data(s
->obj_ctx
, obj
);
574 ret
= read_obj_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
,
575 s
->object_acl
.get(), s
->iam_policy
, s
->bucket
,
582 rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
585 rgw::IAM::Environment e
;
586 const auto& m
= s
->info
.env
->get_map();
587 auto t
= ceph::real_clock::now();
588 e
.emplace("aws:CurrentTime", std::to_string(ceph::real_clock::to_time_t(t
)));
589 e
.emplace("aws:EpochTime", 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("aws:PrincipalType", "User");
595 auto i
= m
.find("HTTP_REFERER");
597 e
.emplace("aws:Referer", i
->second
);
600 // These seem to be the semantics, judging from rest_rgw_s3.cc
601 i
= m
.find("SERVER_PORT_SECURE");
603 e
.emplace("aws:SecureTransport", "true");
606 const auto remote_addr_param
= s
->cct
->_conf
->rgw_remote_addr_param
;
607 if (remote_addr_param
.length()) {
608 i
= m
.find(remote_addr_param
);
610 i
= m
.find("REMOTE_ADDR");
613 const string
* ip
= &(i
->second
);
615 if (remote_addr_param
== "HTTP_X_FORWARDED_FOR") {
616 const auto comma
= ip
->find(',');
617 if (comma
!= string::npos
) {
618 temp
.assign(*ip
, 0, comma
);
622 e
.emplace("aws:SourceIp", *ip
);
625 i
= m
.find("HTTP_USER_AGENT"); {
627 e
.emplace("aws:UserAgent", i
->second
);
631 // What to do about aws::userid? One can have multiple access
632 // keys so that isn't really suitable. Do we have a durable
633 // identifier that can persist through name changes?
634 e
.emplace("aws:username", s
->user
->user_id
.id
);
639 void rgw_bucket_object_pre_exec(struct req_state
*s
)
644 dump_bucket_from_state(s
);
647 // So! Now and then when we try to update bucket information, the
648 // bucket has changed during the course of the operation. (Or we have
649 // a cache consistency problem that Watch/Notify isn't ruling out
652 // When this happens, we need to update the bucket info and try
653 // again. We have, however, to try the right *part* again. We can't
654 // simply re-send, since that will obliterate the previous update.
656 // Thus, callers of this function should include everything that
657 // merges information to be changed into the bucket information as
658 // well as the call to set it.
660 // The called function must return an integer, negative on error. In
661 // general, they should just return op_ret.
664 int retry_raced_bucket_write(RGWRados
* g
, req_state
* s
, const F
& f
) {
666 for (auto i
= 0u; i
< 15u && r
== -ECANCELED
; ++i
) {
667 r
= g
->try_refresh_bucket_info(s
->bucket_info
, nullptr,
678 int RGWGetObj::verify_permission()
680 obj
= rgw_obj(s
->bucket
, s
->object
);
681 store
->set_atomic(s
->obj_ctx
, obj
);
683 store
->set_prefetch_data(s
->obj_ctx
, obj
);
686 if (torrent
.get_flag()) {
687 if (obj
.key
.instance
.empty()) {
688 action
= rgw::IAM::s3GetObjectTorrent
;
690 action
= rgw::IAM::s3GetObjectVersionTorrent
;
693 if (obj
.key
.instance
.empty()) {
694 action
= rgw::IAM::s3GetObject
;
696 action
= rgw::IAM::s3GetObjectVersion
;
700 if (!verify_object_permission(s
, action
)) {
708 int RGWOp::verify_op_mask()
710 uint32_t required_mask
= op_mask();
712 ldout(s
->cct
, 20) << "required_mask= " << required_mask
713 << " user.op_mask=" << s
->user
->op_mask
<< dendl
;
715 if ((s
->user
->op_mask
& required_mask
) != required_mask
) {
719 if (!s
->system_request
&& (required_mask
& RGW_OP_TYPE_MODIFY
) && !store
->zone_is_writeable()) {
720 ldout(s
->cct
, 5) << "NOTICE: modify request to a read-only zone by a non-system user, permission denied" << dendl
;
727 int RGWGetObjTags::verify_permission()
729 if (!verify_object_permission(s
,
730 s
->object
.instance
.empty() ?
731 rgw::IAM::s3GetObjectTagging
:
732 rgw::IAM::s3GetObjectVersionTagging
))
738 void RGWGetObjTags::pre_exec()
740 rgw_bucket_object_pre_exec(s
);
743 void RGWGetObjTags::execute()
746 map
<string
,bufferlist
> attrs
;
748 obj
= rgw_obj(s
->bucket
, s
->object
);
750 store
->set_atomic(s
->obj_ctx
, obj
);
752 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
754 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << obj
755 << " ret=" << op_ret
<< dendl
;
759 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
760 if(tags
!= attrs
.end()){
762 tags_bl
.append(tags
->second
);
764 send_response_data(tags_bl
);
767 int RGWPutObjTags::verify_permission()
769 if (!verify_object_permission(s
,
770 s
->object
.instance
.empty() ?
771 rgw::IAM::s3PutObjectTagging
:
772 rgw::IAM::s3PutObjectVersionTagging
))
777 void RGWPutObjTags::execute()
779 op_ret
= get_params();
783 if (s
->object
.empty()){
784 op_ret
= -EINVAL
; // we only support tagging on existing objects
789 obj
= rgw_obj(s
->bucket
, s
->object
);
790 store
->set_atomic(s
->obj_ctx
, obj
);
791 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_TAGS
, tags_bl
);
792 if (op_ret
== -ECANCELED
){
793 op_ret
= -ERR_TAG_CONFLICT
;
797 void RGWDeleteObjTags::pre_exec()
799 rgw_bucket_object_pre_exec(s
);
803 int RGWDeleteObjTags::verify_permission()
805 if (!s
->object
.empty()) {
806 if (!verify_object_permission(s
,
807 s
->object
.instance
.empty() ?
808 rgw::IAM::s3DeleteObjectTagging
:
809 rgw::IAM::s3DeleteObjectVersionTagging
))
815 void RGWDeleteObjTags::execute()
817 if (s
->object
.empty())
821 obj
= rgw_obj(s
->bucket
, s
->object
);
822 store
->set_atomic(s
->obj_ctx
, obj
);
823 map
<string
, bufferlist
> attrs
;
824 map
<string
, bufferlist
> rmattr
;
826 rmattr
[RGW_ATTR_TAGS
] = bl
;
827 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattr
);
830 int RGWOp::do_aws4_auth_completion()
832 ldout(s
->cct
, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl
;
833 if (s
->auth
.completer
) {
834 if (!s
->auth
.completer
->complete()) {
835 return -ERR_AMZ_CONTENT_SHA256_MISMATCH
;
837 dout(10) << "v4 auth ok -- do_aws4_auth_completion" << dendl
;
840 /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first
841 * call passes, so we disable second one. This is old behaviour, sorry!
842 * Plan for tomorrow: seek and destroy. */
843 s
->auth
.completer
= nullptr;
849 int RGWOp::init_quota()
851 /* no quota enforcement for system requests */
852 if (s
->system_request
)
855 /* init quota related stuff */
856 if (!(s
->user
->op_mask
& RGW_OP_TYPE_MODIFY
)) {
860 /* only interested in object related ops */
861 if (s
->object
.empty()) {
865 RGWUserInfo owner_info
;
868 if (s
->user
->user_id
== s
->bucket_owner
.get_id()) {
871 int r
= rgw_get_user_info_by_uid(store
, s
->bucket_info
.owner
, owner_info
);
877 if (s
->bucket_info
.quota
.enabled
) {
878 bucket_quota
= s
->bucket_info
.quota
;
879 } else if (uinfo
->bucket_quota
.enabled
) {
880 bucket_quota
= uinfo
->bucket_quota
;
882 bucket_quota
= store
->get_bucket_quota();
885 if (uinfo
->user_quota
.enabled
) {
886 user_quota
= uinfo
->user_quota
;
888 user_quota
= store
->get_user_quota();
894 static bool validate_cors_rule_method(RGWCORSRule
*rule
, const char *req_meth
) {
898 dout(5) << "req_meth is null" << dendl
;
902 if (strcmp(req_meth
, "GET") == 0) flags
= RGW_CORS_GET
;
903 else if (strcmp(req_meth
, "POST") == 0) flags
= RGW_CORS_POST
;
904 else if (strcmp(req_meth
, "PUT") == 0) flags
= RGW_CORS_PUT
;
905 else if (strcmp(req_meth
, "DELETE") == 0) flags
= RGW_CORS_DELETE
;
906 else if (strcmp(req_meth
, "HEAD") == 0) flags
= RGW_CORS_HEAD
;
908 if ((rule
->get_allowed_methods() & flags
) == flags
) {
909 dout(10) << "Method " << req_meth
<< " is supported" << dendl
;
911 dout(5) << "Method " << req_meth
<< " is not supported" << dendl
;
918 static bool validate_cors_rule_header(RGWCORSRule
*rule
, const char *req_hdrs
) {
921 get_str_vec(req_hdrs
, hdrs
);
922 for (const auto& hdr
: hdrs
) {
923 if (!rule
->is_header_allowed(hdr
.c_str(), hdr
.length())) {
924 dout(5) << "Header " << hdr
<< " is not registered in this rule" << dendl
;
932 int RGWOp::read_bucket_cors()
936 map
<string
, bufferlist
>::iterator aiter
= s
->bucket_attrs
.find(RGW_ATTR_CORS
);
937 if (aiter
== s
->bucket_attrs
.end()) {
938 ldout(s
->cct
, 20) << "no CORS configuration attr found" << dendl
;
940 return 0; /* no CORS configuration found */
947 bufferlist::iterator iter
= bl
.begin();
949 bucket_cors
.decode(iter
);
950 } catch (buffer::error
& err
) {
951 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
954 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
955 RGWCORSConfiguration_S3
*s3cors
= static_cast<RGWCORSConfiguration_S3
*>(&bucket_cors
);
956 ldout(s
->cct
, 15) << "Read RGWCORSConfiguration";
957 s3cors
->to_xml(*_dout
);
964 * If any of the header field-names is not a ASCII case-insensitive match for
965 * any of the values in list of headers do not set any additional headers and
966 * terminate this set of steps.
968 static void get_cors_response_headers(RGWCORSRule
*rule
, const char *req_hdrs
, string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
971 get_str_list(req_hdrs
, hl
);
972 for(list
<string
>::iterator it
= hl
.begin(); it
!= hl
.end(); ++it
) {
973 if (!rule
->is_header_allowed((*it
).c_str(), (*it
).length())) {
974 dout(5) << "Header " << (*it
) << " is not registered in this rule" << dendl
;
976 if (hdrs
.length() > 0) hdrs
.append(",");
981 rule
->format_exp_headers(exp_hdrs
);
982 *max_age
= rule
->get_max_age();
986 * Generate the CORS header response
988 * This is described in the CORS standard, section 6.2.
990 bool RGWOp::generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
)
993 const char *orig
= s
->info
.env
->get("HTTP_ORIGIN");
1000 op_ret
= read_bucket_cors();
1006 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
1011 RGWCORSRule
*rule
= bucket_cors
.host_name_rule(orig
);
1016 * Set the Allowed-Origin header to a asterisk if this is allowed in the rule
1017 * and no Authorization was send by the client
1019 * The origin parameter specifies a URI that may access the resource. The browser must enforce this.
1020 * For requests without credentials, the server may specify "*" as a wildcard,
1021 * thereby allowing any origin to access the resource.
1023 const char *authorization
= s
->info
.env
->get("HTTP_AUTHORIZATION");
1024 if (!authorization
&& rule
->has_wildcard_origin())
1028 const char *req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
1030 req_meth
= s
->info
.method
;
1036 if (!validate_cors_rule_method(rule
, req_meth
)) {
1042 const char *req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
1045 get_cors_response_headers(rule
, req_hdrs
, headers
, exp_headers
, max_age
);
1050 int RGWGetObj::read_user_manifest_part(rgw_bucket
& bucket
,
1051 const rgw_bucket_dir_entry
& ent
,
1052 RGWAccessControlPolicy
* const bucket_acl
,
1053 const optional
<Policy
>& bucket_policy
,
1054 const off_t start_ofs
,
1055 const off_t end_ofs
)
1057 ldout(s
->cct
, 20) << "user manifest obj=" << ent
.key
.name
<< "[" << ent
.key
.instance
<< "]" << dendl
;
1058 RGWGetObj_CB
cb(this);
1059 RGWGetDataCB
* filter
= &cb
;
1060 boost::optional
<RGWGetObj_Decompress
> decompress
;
1062 int64_t cur_ofs
= start_ofs
;
1063 int64_t cur_end
= end_ofs
;
1065 rgw_obj
part(bucket
, ent
.key
);
1067 map
<string
, bufferlist
> attrs
;
1070 RGWObjectCtx
obj_ctx(store
);
1071 RGWAccessControlPolicy
obj_policy(s
->cct
);
1073 ldout(s
->cct
, 20) << "reading obj=" << part
<< " ofs=" << cur_ofs
<< " end=" << cur_end
<< dendl
;
1075 obj_ctx
.obj
.set_atomic(part
);
1076 store
->set_prefetch_data(&obj_ctx
, part
);
1078 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, part
);
1079 RGWRados::Object::Read
read_op(&op_target
);
1081 read_op
.conds
.if_match
= ent
.meta
.etag
.c_str();
1082 read_op
.params
.attrs
= &attrs
;
1083 read_op
.params
.obj_size
= &obj_size
;
1085 op_ret
= read_op
.prepare();
1088 op_ret
= read_op
.range_to_ofs(ent
.meta
.accounted_size
, cur_ofs
, cur_end
);
1091 bool need_decompress
;
1092 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1094 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1098 if (need_decompress
)
1100 if (cs_info
.orig_size
!= ent
.meta
.accounted_size
) {
1101 // hmm.. something wrong, object not as expected, abort!
1102 ldout(s
->cct
, 0) << "ERROR: expected cs_info.orig_size=" << cs_info
.orig_size
<<
1103 ", actual read size=" << ent
.meta
.size
<< dendl
;
1106 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1107 filter
= &*decompress
;
1111 if (obj_size
!= ent
.meta
.size
) {
1112 // hmm.. something wrong, object not as expected, abort!
1113 ldout(s
->cct
, 0) << "ERROR: expected obj_size=" << obj_size
<< ", actual read size=" << ent
.meta
.size
<< dendl
;
1118 op_ret
= rgw_policy_from_attrset(s
->cct
, attrs
, &obj_policy
);
1122 /* We can use global user_acl because LOs cannot have segments
1123 * stored inside different accounts. */
1124 if (s
->system_request
) {
1125 ldout(s
->cct
, 2) << "overriding permissions due to system operation" << dendl
;
1126 } else if (s
->auth
.identity
->is_admin_of(s
->user
->user_id
)) {
1127 ldout(s
->cct
, 2) << "overriding permissions due to admin operation" << dendl
;
1128 } else if (!verify_object_permission(s
, part
, s
->user_acl
.get(), bucket_acl
,
1129 &obj_policy
, bucket_policy
, action
)) {
1133 if (ent
.meta
.size
== 0) {
1137 perfcounter
->inc(l_rgw_get_b
, cur_end
- cur_ofs
);
1138 filter
->fixup_range(cur_ofs
, cur_end
);
1139 op_ret
= read_op
.iterate(cur_ofs
, cur_end
, filter
);
1141 op_ret
= filter
->flush();
1145 static int iterate_user_manifest_parts(CephContext
* const cct
,
1146 RGWRados
* const store
,
1149 RGWBucketInfo
*pbucket_info
,
1150 const string
& obj_prefix
,
1151 RGWAccessControlPolicy
* const bucket_acl
,
1152 const optional
<Policy
>& bucket_policy
,
1153 uint64_t * const ptotal_len
,
1154 uint64_t * const pobj_size
,
1155 string
* const pobj_sum
,
1156 int (*cb
)(rgw_bucket
& bucket
,
1157 const rgw_bucket_dir_entry
& ent
,
1158 RGWAccessControlPolicy
* const bucket_acl
,
1159 const optional
<Policy
>& bucket_policy
,
1163 void * const cb_param
)
1165 rgw_bucket
& bucket
= pbucket_info
->bucket
;
1166 uint64_t obj_ofs
= 0, len_count
= 0;
1167 bool found_start
= false, found_end
= false, handled_end
= false;
1170 vector
<rgw_bucket_dir_entry
> objs
;
1172 utime_t start_time
= ceph_clock_now();
1174 RGWRados::Bucket
target(store
, *pbucket_info
);
1175 RGWRados::Bucket::List
list_op(&target
);
1177 list_op
.params
.prefix
= obj_prefix
;
1178 list_op
.params
.delim
= delim
;
1182 #define MAX_LIST_OBJS 100
1183 int r
= list_op
.list_objects(MAX_LIST_OBJS
, &objs
, NULL
, &is_truncated
);
1188 for (rgw_bucket_dir_entry
& ent
: objs
) {
1189 const uint64_t cur_total_len
= obj_ofs
;
1190 const uint64_t obj_size
= ent
.meta
.accounted_size
;
1191 uint64_t start_ofs
= 0, end_ofs
= obj_size
;
1193 if ((ptotal_len
|| cb
) && !found_start
&& cur_total_len
+ obj_size
> (uint64_t)ofs
) {
1194 start_ofs
= ofs
- obj_ofs
;
1198 obj_ofs
+= obj_size
;
1200 etag_sum
.Update((const byte
*)ent
.meta
.etag
.c_str(),
1201 ent
.meta
.etag
.length());
1204 if ((ptotal_len
|| cb
) && !found_end
&& obj_ofs
> (uint64_t)end
) {
1205 end_ofs
= end
- cur_total_len
+ 1;
1209 perfcounter
->tinc(l_rgw_get_lat
,
1210 (ceph_clock_now() - start_time
));
1212 if (found_start
&& !handled_end
) {
1213 len_count
+= end_ofs
- start_ofs
;
1216 r
= cb(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
, cb_param
);
1223 handled_end
= found_end
;
1224 start_time
= ceph_clock_now();
1226 } while (is_truncated
);
1229 *ptotal_len
= len_count
;
1232 *pobj_size
= obj_ofs
;
1235 complete_etag(etag_sum
, pobj_sum
);
1241 struct rgw_slo_part
{
1242 RGWAccessControlPolicy
*bucket_acl
= nullptr;
1243 Policy
* bucket_policy
= nullptr;
1250 static int iterate_slo_parts(CephContext
*cct
,
1254 map
<uint64_t, rgw_slo_part
>& slo_parts
,
1255 int (*cb
)(rgw_bucket
& bucket
,
1256 const rgw_bucket_dir_entry
& ent
,
1257 RGWAccessControlPolicy
*bucket_acl
,
1258 const optional
<Policy
>& bucket_policy
,
1264 bool found_start
= false, found_end
= false;
1266 if (slo_parts
.empty()) {
1270 utime_t start_time
= ceph_clock_now();
1272 map
<uint64_t, rgw_slo_part
>::iterator iter
= slo_parts
.upper_bound(ofs
);
1273 if (iter
!= slo_parts
.begin()) {
1277 uint64_t obj_ofs
= iter
->first
;
1279 for (; iter
!= slo_parts
.end() && !found_end
; ++iter
) {
1280 rgw_slo_part
& part
= iter
->second
;
1281 rgw_bucket_dir_entry ent
;
1283 ent
.key
.name
= part
.obj_name
;
1284 ent
.meta
.accounted_size
= ent
.meta
.size
= part
.size
;
1285 ent
.meta
.etag
= part
.etag
;
1287 uint64_t cur_total_len
= obj_ofs
;
1288 uint64_t start_ofs
= 0, end_ofs
= ent
.meta
.size
;
1290 if (!found_start
&& cur_total_len
+ ent
.meta
.size
> (uint64_t)ofs
) {
1291 start_ofs
= ofs
- obj_ofs
;
1295 obj_ofs
+= ent
.meta
.size
;
1297 if (!found_end
&& obj_ofs
> (uint64_t)end
) {
1298 end_ofs
= end
- cur_total_len
+ 1;
1302 perfcounter
->tinc(l_rgw_get_lat
,
1303 (ceph_clock_now() - start_time
));
1307 // SLO is a Swift thing, and Swift has no knowledge of S3 Policies.
1308 int r
= cb(part
.bucket
, ent
, part
.bucket_acl
,
1309 (part
.bucket_policy
?
1310 optional
<Policy
>(*part
.bucket_policy
) : none
),
1311 start_ofs
, end_ofs
, cb_param
);
1317 start_time
= ceph_clock_now();
1323 static int get_obj_user_manifest_iterate_cb(rgw_bucket
& bucket
,
1324 const rgw_bucket_dir_entry
& ent
,
1325 RGWAccessControlPolicy
* const bucket_acl
,
1326 const optional
<Policy
>& bucket_policy
,
1327 const off_t start_ofs
,
1328 const off_t end_ofs
,
1331 RGWGetObj
*op
= static_cast<RGWGetObj
*>(param
);
1332 return op
->read_user_manifest_part(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
);
1335 int RGWGetObj::handle_user_manifest(const char *prefix
)
1337 const boost::string_view
prefix_view(prefix
);
1338 ldout(s
->cct
, 2) << "RGWGetObj::handle_user_manifest() prefix="
1339 << prefix_view
<< dendl
;
1341 const size_t pos
= prefix_view
.find('/');
1342 if (pos
== string::npos
) {
1346 const std::string bucket_name
= url_decode(prefix_view
.substr(0, pos
));
1347 const std::string obj_prefix
= url_decode(prefix_view
.substr(pos
+ 1));
1351 RGWAccessControlPolicy
_bucket_acl(s
->cct
);
1352 RGWAccessControlPolicy
*bucket_acl
;
1353 optional
<Policy
> _bucket_policy
;
1354 optional
<Policy
>* bucket_policy
;
1355 RGWBucketInfo bucket_info
;
1356 RGWBucketInfo
*pbucket_info
;
1358 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1359 map
<string
, bufferlist
> bucket_attrs
;
1360 RGWObjectCtx
obj_ctx(store
);
1361 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1362 bucket_name
, bucket_info
, NULL
,
1365 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1366 << bucket_name
<< dendl
;
1369 bucket
= bucket_info
.bucket
;
1370 pbucket_info
= &bucket_info
;
1371 bucket_acl
= &_bucket_acl
;
1372 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
, bucket
);
1374 ldout(s
->cct
, 0) << "failed to read bucket policy" << dendl
;
1377 _bucket_policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
,
1378 bucket_info
.bucket
.tenant
);
1379 bucket_policy
= &_bucket_policy
;
1382 pbucket_info
= &s
->bucket_info
;
1383 bucket_acl
= s
->bucket_acl
.get();
1384 bucket_policy
= &s
->iam_policy
;
1387 /* dry run to find out:
1388 * - total length (of the parts we are going to send to client),
1389 * - overall DLO's content size,
1390 * - md5 sum of overall DLO's content (for etag of Swift API). */
1391 int r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1392 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1393 nullptr, &s
->obj_size
, &lo_etag
,
1394 nullptr /* cb */, nullptr /* cb arg */);
1399 r
= RGWRados::Object::Read::range_to_ofs(s
->obj_size
, ofs
, end
);
1404 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1405 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1406 &total_len
, nullptr, nullptr,
1414 send_response_data(bl
, 0, 0);
1418 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1419 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1420 nullptr, nullptr, nullptr,
1421 get_obj_user_manifest_iterate_cb
, (void *)this);
1428 send_response_data(bl
, 0, 0);
1434 int RGWGetObj::handle_slo_manifest(bufferlist
& bl
)
1436 RGWSLOInfo slo_info
;
1437 bufferlist::iterator bliter
= bl
.begin();
1439 ::decode(slo_info
, bliter
);
1440 } catch (buffer::error
& err
) {
1441 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
1444 ldout(s
->cct
, 2) << "RGWGetObj::handle_slo_manifest()" << dendl
;
1446 vector
<RGWAccessControlPolicy
> allocated_acls
;
1447 map
<string
, pair
<RGWAccessControlPolicy
*, optional
<Policy
>>> policies
;
1448 map
<string
, rgw_bucket
> buckets
;
1450 map
<uint64_t, rgw_slo_part
> slo_parts
;
1455 for (const auto& entry
: slo_info
.entries
) {
1456 const string
& path
= entry
.path
;
1458 /* If the path starts with slashes, strip them all. */
1459 const size_t pos_init
= path
.find_first_not_of('/');
1460 /* According to the documentation of std::string::find following check
1461 * is not necessary as we should get the std::string::npos propagation
1462 * here. This might be true with the accuracy to implementation's bugs.
1463 * See following question on SO:
1464 * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos
1466 if (pos_init
== string::npos
) {
1470 const size_t pos_sep
= path
.find('/', pos_init
);
1471 if (pos_sep
== string::npos
) {
1475 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
1476 string obj_name
= path
.substr(pos_sep
+ 1);
1479 RGWAccessControlPolicy
*bucket_acl
;
1480 Policy
* bucket_policy
;
1482 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1483 const auto& piter
= policies
.find(bucket_name
);
1484 if (piter
!= policies
.end()) {
1485 bucket_acl
= piter
->second
.first
;
1486 bucket_policy
= piter
->second
.second
.get_ptr();
1487 bucket
= buckets
[bucket_name
];
1489 allocated_acls
.push_back(RGWAccessControlPolicy(s
->cct
));
1490 RGWAccessControlPolicy
& _bucket_acl
= allocated_acls
.back();
1492 RGWBucketInfo bucket_info
;
1493 map
<string
, bufferlist
> bucket_attrs
;
1494 RGWObjectCtx
obj_ctx(store
);
1495 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1496 bucket_name
, bucket_info
, nullptr,
1499 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1500 << bucket_name
<< dendl
;
1503 bucket
= bucket_info
.bucket
;
1504 bucket_acl
= &_bucket_acl
;
1505 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
,
1508 ldout(s
->cct
, 0) << "failed to read bucket ACL for bucket "
1512 auto _bucket_policy
= get_iam_policy_from_attr(
1513 s
->cct
, store
, bucket_attrs
, bucket_info
.bucket
.tenant
);
1514 bucket_policy
= _bucket_policy
.get_ptr();
1515 buckets
[bucket_name
] = bucket
;
1516 policies
[bucket_name
] = make_pair(bucket_acl
, _bucket_policy
);
1520 bucket_acl
= s
->bucket_acl
.get();
1521 bucket_policy
= s
->iam_policy
.get_ptr();
1525 part
.bucket_acl
= bucket_acl
;
1526 part
.bucket_policy
= bucket_policy
;
1527 part
.bucket
= bucket
;
1528 part
.obj_name
= obj_name
;
1529 part
.size
= entry
.size_bytes
;
1530 part
.etag
= entry
.etag
;
1531 ldout(s
->cct
, 20) << "slo_part: ofs=" << ofs
1532 << " bucket=" << part
.bucket
1533 << " obj=" << part
.obj_name
1534 << " size=" << part
.size
1535 << " etag=" << part
.etag
1538 etag_sum
.Update((const byte
*)entry
.etag
.c_str(),
1539 entry
.etag
.length());
1541 slo_parts
[total_len
] = part
;
1542 total_len
+= part
.size
;
1545 complete_etag(etag_sum
, &lo_etag
);
1547 s
->obj_size
= slo_info
.total_size
;
1548 ldout(s
->cct
, 20) << "s->obj_size=" << s
->obj_size
<< dendl
;
1550 int r
= RGWRados::Object::Read::range_to_ofs(total_len
, ofs
, end
);
1555 total_len
= end
- ofs
+ 1;
1557 r
= iterate_slo_parts(s
->cct
, store
, ofs
, end
, slo_parts
,
1558 get_obj_user_manifest_iterate_cb
, (void *)this);
1566 int RGWGetObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
1568 /* garbage collection related handling */
1569 utime_t start_time
= ceph_clock_now();
1570 if (start_time
> gc_invalidate_time
) {
1571 int r
= store
->defer_gc(s
->obj_ctx
, s
->bucket_info
, obj
);
1573 dout(0) << "WARNING: could not defer gc entry for obj" << dendl
;
1575 gc_invalidate_time
= start_time
;
1576 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1578 return send_response_data(bl
, bl_ofs
, bl_len
);
1581 bool RGWGetObj::prefetch_data()
1583 /* HEAD request, stop prefetch*/
1588 bool prefetch_first_chunk
= true;
1589 range_str
= s
->info
.env
->get("HTTP_RANGE");
1592 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1593 /* error on parsing the range, stop prefetch and will fail in execte() */
1595 range_parsed
= false;
1598 range_parsed
= true;
1600 /* range get goes to shadown objects, stop prefetch */
1601 if (ofs
>= s
->cct
->_conf
->rgw_max_chunk_size
) {
1602 prefetch_first_chunk
= false;
1606 return get_data
&& prefetch_first_chunk
;
1608 void RGWGetObj::pre_exec()
1610 rgw_bucket_object_pre_exec(s
);
1613 static bool object_is_expired(map
<string
, bufferlist
>& attrs
) {
1614 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1615 if (iter
!= attrs
.end()) {
1618 ::decode(delete_at
, iter
->second
);
1619 } catch (buffer::error
& err
) {
1620 dout(0) << "ERROR: " << __func__
<< ": failed to decode " RGW_ATTR_DELETE_AT
" attr" << dendl
;
1624 if (delete_at
<= ceph_clock_now() && !delete_at
.is_zero()) {
1632 void RGWGetObj::execute()
1634 utime_t start_time
= s
->time
;
1636 gc_invalidate_time
= ceph_clock_now();
1637 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1639 bool need_decompress
;
1640 int64_t ofs_x
, end_x
;
1642 RGWGetObj_CB
cb(this);
1643 RGWGetDataCB
* filter
= (RGWGetDataCB
*)&cb
;
1644 boost::optional
<RGWGetObj_Decompress
> decompress
;
1645 std::unique_ptr
<RGWGetDataCB
> decrypt
;
1646 map
<string
, bufferlist
>::iterator attr_iter
;
1648 perfcounter
->inc(l_rgw_get
);
1650 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
1651 RGWRados::Object::Read
read_op(&op_target
);
1653 op_ret
= get_params();
1657 op_ret
= init_common();
1661 read_op
.conds
.mod_ptr
= mod_ptr
;
1662 read_op
.conds
.unmod_ptr
= unmod_ptr
;
1663 read_op
.conds
.high_precision_time
= s
->system_request
; /* system request need to use high precision time */
1664 read_op
.conds
.mod_zone_id
= mod_zone_id
;
1665 read_op
.conds
.mod_pg_ver
= mod_pg_ver
;
1666 read_op
.conds
.if_match
= if_match
;
1667 read_op
.conds
.if_nomatch
= if_nomatch
;
1668 read_op
.params
.attrs
= &attrs
;
1669 read_op
.params
.lastmod
= &lastmod
;
1670 read_op
.params
.obj_size
= &s
->obj_size
;
1672 op_ret
= read_op
.prepare();
1675 version_id
= read_op
.state
.obj
.key
.instance
;
1677 /* STAT ops don't need data, and do no i/o */
1678 if (get_type() == RGW_OP_STAT_OBJ
) {
1682 /* start gettorrent */
1683 if (torrent
.get_flag())
1685 attr_iter
= attrs
.find(RGW_ATTR_CRYPT_MODE
);
1686 if (attr_iter
!= attrs
.end() && attr_iter
->second
.to_str() == "SSE-C-AES256") {
1687 op_ret
= -ERR_INVALID_REQUEST
;
1690 torrent
.init(s
, store
);
1691 op_ret
= torrent
.get_torrent_file(read_op
, total_len
, bl
, obj
);
1694 ldout(s
->cct
, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
1698 op_ret
= send_response_data(bl
, 0, total_len
);
1701 ldout(s
->cct
, 0) << "ERROR: failed to send_response_data ret= " << op_ret
1707 /* end gettorrent */
1709 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1711 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1714 if (need_decompress
) {
1715 s
->obj_size
= cs_info
.orig_size
;
1716 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1717 filter
= &*decompress
;
1720 attr_iter
= attrs
.find(RGW_ATTR_USER_MANIFEST
);
1721 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1722 op_ret
= handle_user_manifest(attr_iter
->second
.c_str());
1724 ldout(s
->cct
, 0) << "ERROR: failed to handle user manifest ret="
1731 attr_iter
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
1732 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1734 op_ret
= handle_slo_manifest(attr_iter
->second
);
1736 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
1743 // for range requests with obj size 0
1744 if (range_str
&& !(s
->obj_size
)) {
1750 op_ret
= read_op
.range_to_ofs(s
->obj_size
, ofs
, end
);
1753 total_len
= (ofs
<= end
? end
+ 1 - ofs
: 0);
1755 /* Check whether the object has expired. Swift API documentation
1756 * stands that we should return 404 Not Found in such case. */
1757 if (need_object_expiration() && object_is_expired(attrs
)) {
1764 /* STAT ops don't need data, and do no i/o */
1765 if (get_type() == RGW_OP_STAT_OBJ
) {
1769 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1770 op_ret
= this->get_decrypt_filter(&decrypt
, filter
,
1771 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
1772 if (decrypt
!= nullptr) {
1773 filter
= decrypt
.get();
1779 if (!get_data
|| ofs
> end
) {
1780 send_response_data(bl
, 0, 0);
1784 perfcounter
->inc(l_rgw_get_b
, end
- ofs
);
1788 filter
->fixup_range(ofs_x
, end_x
);
1789 op_ret
= read_op
.iterate(ofs_x
, end_x
, filter
);
1792 op_ret
= filter
->flush();
1794 perfcounter
->tinc(l_rgw_get_lat
,
1795 (ceph_clock_now() - start_time
));
1800 op_ret
= send_response_data(bl
, 0, 0);
1807 send_response_data_error();
1810 int RGWGetObj::init_common()
1813 /* range parsed error when prefetch*/
1814 if (!range_parsed
) {
1815 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1821 if (parse_time(if_mod
, &mod_time
) < 0)
1823 mod_ptr
= &mod_time
;
1827 if (parse_time(if_unmod
, &unmod_time
) < 0)
1829 unmod_ptr
= &unmod_time
;
1835 int RGWListBuckets::verify_permission()
1837 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1844 int RGWGetUsage::verify_permission()
1846 if (s
->auth
.identity
->is_anonymous()) {
1853 void RGWListBuckets::execute()
1856 bool started
= false;
1857 uint64_t total_count
= 0;
1859 const uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1861 op_ret
= get_params();
1866 if (supports_account_metadata()) {
1867 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, attrs
);
1873 is_truncated
= false;
1875 RGWUserBuckets buckets
;
1876 uint64_t read_count
;
1878 read_count
= min(limit
- total_count
, (uint64_t)max_buckets
);
1880 read_count
= max_buckets
;
1883 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
1884 marker
, end_marker
, read_count
,
1885 should_get_stats(), &is_truncated
,
1888 /* hmm.. something wrong here.. the user was authenticated, so it
1890 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1891 << s
->user
->user_id
<< dendl
;
1895 /* We need to have stats for all our policies - even if a given policy
1896 * isn't actually used in a given account. In such situation its usage
1897 * stats would be simply full of zeros. */
1898 for (const auto& policy
: store
->get_zonegroup().placement_targets
) {
1899 policies_stats
.emplace(policy
.second
.name
,
1900 decltype(policies_stats
)::mapped_type());
1903 std::map
<std::string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1904 for (const auto& kv
: m
) {
1905 const auto& bucket
= kv
.second
;
1907 global_stats
.bytes_used
+= bucket
.size
;
1908 global_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
1909 global_stats
.objects_count
+= bucket
.count
;
1911 /* operator[] still can create a new entry for storage policy seen
1912 * for first time. */
1913 auto& policy_stats
= policies_stats
[bucket
.placement_rule
];
1914 policy_stats
.bytes_used
+= bucket
.size
;
1915 policy_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
1916 policy_stats
.buckets_count
++;
1917 policy_stats
.objects_count
+= bucket
.count
;
1919 global_stats
.buckets_count
+= m
.size();
1920 total_count
+= m
.size();
1922 done
= (m
.size() < read_count
|| (limit
>= 0 && total_count
>= (uint64_t)limit
));
1925 send_response_begin(buckets
.count() > 0);
1930 map
<string
, RGWBucketEnt
>::reverse_iterator riter
= m
.rbegin();
1931 marker
= riter
->first
;
1933 handle_listing_chunk(std::move(buckets
));
1935 } while (is_truncated
&& !done
);
1939 send_response_begin(false);
1941 send_response_end();
1944 void RGWGetUsage::execute()
1946 uint64_t start_epoch
= 0;
1947 uint64_t end_epoch
= (uint64_t)-1;
1948 op_ret
= get_params();
1952 if (!start_date
.empty()) {
1953 op_ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
1955 ldout(store
->ctx(), 0) << "ERROR: failed to parse start date" << dendl
;
1960 if (!end_date
.empty()) {
1961 op_ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
1963 ldout(store
->ctx(), 0) << "ERROR: failed to parse end date" << dendl
;
1968 uint32_t max_entries
= 1000;
1970 bool is_truncated
= true;
1972 RGWUsageIter usage_iter
;
1974 while (is_truncated
) {
1975 op_ret
= store
->read_usage(s
->user
->user_id
, start_epoch
, end_epoch
, max_entries
,
1976 &is_truncated
, usage_iter
, usage
);
1978 if (op_ret
== -ENOENT
) {
1980 is_truncated
= false;
1988 op_ret
= rgw_user_sync_all_stats(store
, s
->user
->user_id
);
1990 ldout(store
->ctx(), 0) << "ERROR: failed to sync user stats: " << dendl
;
1994 op_ret
= rgw_user_get_all_buckets_stats(store
, s
->user
->user_id
, buckets_usage
);
1996 cerr
<< "ERROR: failed to sync user stats: " << std::endl
;
2000 string user_str
= s
->user
->user_id
.to_str();
2001 op_ret
= store
->cls_user_get_header(user_str
, &header
);
2003 ldout(store
->ctx(), 0) << "ERROR: can't read user header: " << dendl
;
2010 int RGWStatAccount::verify_permission()
2012 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
2019 void RGWStatAccount::execute()
2022 bool is_truncated
= false;
2023 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
2026 RGWUserBuckets buckets
;
2028 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
, marker
,
2029 string(), max_buckets
, true, &is_truncated
);
2031 /* hmm.. something wrong here.. the user was authenticated, so it
2033 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
2034 << s
->user
->user_id
<< dendl
;
2037 /* We need to have stats for all our policies - even if a given policy
2038 * isn't actually used in a given account. In such situation its usage
2039 * stats would be simply full of zeros. */
2040 for (const auto& policy
: store
->get_zonegroup().placement_targets
) {
2041 policies_stats
.emplace(policy
.second
.name
,
2042 decltype(policies_stats
)::mapped_type());
2045 std::map
<std::string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2046 for (const auto& kv
: m
) {
2047 const auto& bucket
= kv
.second
;
2049 global_stats
.bytes_used
+= bucket
.size
;
2050 global_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2051 global_stats
.objects_count
+= bucket
.count
;
2053 /* operator[] still can create a new entry for storage policy seen
2054 * for first time. */
2055 auto& policy_stats
= policies_stats
[bucket
.placement_rule
];
2056 policy_stats
.bytes_used
+= bucket
.size
;
2057 policy_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2058 policy_stats
.buckets_count
++;
2059 policy_stats
.objects_count
+= bucket
.count
;
2061 global_stats
.buckets_count
+= m
.size();
2064 } while (is_truncated
);
2067 int RGWGetBucketVersioning::verify_permission()
2069 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketVersioning
);
2072 void RGWGetBucketVersioning::pre_exec()
2074 rgw_bucket_object_pre_exec(s
);
2077 void RGWGetBucketVersioning::execute()
2079 versioned
= s
->bucket_info
.versioned();
2080 versioning_enabled
= s
->bucket_info
.versioning_enabled();
2083 int RGWSetBucketVersioning::verify_permission()
2085 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketVersioning
);
2088 void RGWSetBucketVersioning::pre_exec()
2090 rgw_bucket_object_pre_exec(s
);
2093 void RGWSetBucketVersioning::execute()
2095 op_ret
= get_params();
2099 if (!store
->is_meta_master()) {
2100 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2102 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
2107 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2108 if (enable_versioning
) {
2109 s
->bucket_info
.flags
|= BUCKET_VERSIONED
;
2110 s
->bucket_info
.flags
&= ~BUCKET_VERSIONS_SUSPENDED
;
2112 s
->bucket_info
.flags
|= (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
);
2115 return store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
2120 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2121 << " returned err=" << op_ret
<< dendl
;
2126 int RGWGetBucketWebsite::verify_permission()
2128 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketWebsite
);
2131 void RGWGetBucketWebsite::pre_exec()
2133 rgw_bucket_object_pre_exec(s
);
2136 void RGWGetBucketWebsite::execute()
2138 if (!s
->bucket_info
.has_website
) {
2139 op_ret
= -ERR_NO_SUCH_WEBSITE_CONFIGURATION
;
2143 int RGWSetBucketWebsite::verify_permission()
2145 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketWebsite
);
2148 void RGWSetBucketWebsite::pre_exec()
2150 rgw_bucket_object_pre_exec(s
);
2153 void RGWSetBucketWebsite::execute()
2155 op_ret
= get_params();
2160 if (!store
->is_meta_master()) {
2161 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2163 ldout(s
->cct
, 20) << __func__
<< " forward_request_to_master returned ret=" << op_ret
<< dendl
;
2168 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2169 s
->bucket_info
.has_website
= true;
2170 s
->bucket_info
.website_conf
= website_conf
;
2171 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false,
2172 real_time(), &s
->bucket_attrs
);
2177 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2182 int RGWDeleteBucketWebsite::verify_permission()
2184 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3DeleteBucketWebsite
);
2187 void RGWDeleteBucketWebsite::pre_exec()
2189 rgw_bucket_object_pre_exec(s
);
2192 void RGWDeleteBucketWebsite::execute()
2194 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2195 s
->bucket_info
.has_website
= false;
2196 s
->bucket_info
.website_conf
= RGWBucketWebsiteConf();
2197 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false,
2198 real_time(), &s
->bucket_attrs
);
2202 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2207 int RGWStatBucket::verify_permission()
2209 // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission.
2210 if (!verify_bucket_permission(s
, rgw::IAM::s3ListBucket
)) {
2217 void RGWStatBucket::pre_exec()
2219 rgw_bucket_object_pre_exec(s
);
2222 void RGWStatBucket::execute()
2224 if (!s
->bucket_exists
) {
2225 op_ret
= -ERR_NO_SUCH_BUCKET
;
2229 RGWUserBuckets buckets
;
2230 bucket
.bucket
= s
->bucket
;
2231 buckets
.add(bucket
);
2232 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2233 op_ret
= store
->update_containers_stats(m
);
2238 map
<string
, RGWBucketEnt
>::iterator iter
= m
.find(bucket
.bucket
.name
);
2239 if (iter
!= m
.end()) {
2240 bucket
= iter
->second
;
2247 int RGWListBucket::verify_permission()
2249 op_ret
= get_params();
2253 if (!prefix
.empty())
2254 s
->env
.emplace("s3:prefix", prefix
);
2256 if (!delimiter
.empty())
2257 s
->env
.emplace("s3:delimiter", delimiter
);
2259 s
->env
.emplace("s3:max-keys", std::to_string(max
));
2261 if (!verify_bucket_permission(s
,
2263 rgw::IAM::s3ListBucketVersions
:
2264 rgw::IAM::s3ListBucket
)) {
2271 int RGWListBucket::parse_max_keys()
2273 if (!max_keys
.empty()) {
2275 max
= strtol(max_keys
.c_str(), &endptr
, 10);
2277 while (*endptr
&& isspace(*endptr
)) // ignore white space
2290 void RGWListBucket::pre_exec()
2292 rgw_bucket_object_pre_exec(s
);
2295 void RGWListBucket::execute()
2297 if (!s
->bucket_exists
) {
2298 op_ret
= -ERR_NO_SUCH_BUCKET
;
2302 if (need_container_stats()) {
2303 map
<string
, RGWBucketEnt
> m
;
2304 m
[s
->bucket
.name
] = RGWBucketEnt();
2305 m
.begin()->second
.bucket
= s
->bucket
;
2306 op_ret
= store
->update_containers_stats(m
);
2308 bucket
= m
.begin()->second
;
2312 RGWRados::Bucket
target(store
, s
->bucket_info
);
2313 if (shard_id
>= 0) {
2314 target
.set_shard_id(shard_id
);
2316 RGWRados::Bucket::List
list_op(&target
);
2318 list_op
.params
.prefix
= prefix
;
2319 list_op
.params
.delim
= delimiter
;
2320 list_op
.params
.marker
= marker
;
2321 list_op
.params
.end_marker
= end_marker
;
2322 list_op
.params
.list_versions
= list_versions
;
2324 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2326 next_marker
= list_op
.get_next_marker();
2330 int RGWGetBucketLogging::verify_permission()
2332 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLogging
);
2335 int RGWGetBucketLocation::verify_permission()
2337 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLocation
);
2340 int RGWCreateBucket::verify_permission()
2342 /* This check is mostly needed for S3 that doesn't support account ACL.
2343 * Swift doesn't allow to delegate any permission to an anonymous user,
2344 * so it will become an early exit in such case. */
2345 if (s
->auth
.identity
->is_anonymous()) {
2349 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
2353 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2354 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
2355 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2356 << " requested=" << s
->bucket_tenant
<< ")"
2360 if (s
->user
->max_buckets
< 0) {
2364 if (s
->user
->max_buckets
) {
2365 RGWUserBuckets buckets
;
2367 bool is_truncated
= false;
2368 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2369 marker
, string(), s
->user
->max_buckets
,
2370 false, &is_truncated
);
2375 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2376 return -ERR_TOO_MANY_BUCKETS
;
2383 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2384 RGWRados
*store
, bufferlist
& in_data
,
2385 JSONParser
*jp
, req_info
*forward_info
)
2387 if (!store
->rest_master_conn
) {
2388 ldout(s
->cct
, 0) << "rest connection is invalid" << dendl
;
2391 ldout(s
->cct
, 0) << "sending request to master zonegroup" << dendl
;
2392 bufferlist response
;
2393 string uid_str
= s
->user
->user_id
.to_str();
2394 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2395 int ret
= store
->rest_master_conn
->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2396 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2400 ldout(s
->cct
, 20) << "response: " << response
.c_str() << dendl
;
2401 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2402 ldout(s
->cct
, 0) << "failed parsing response from master zonegroup" << dendl
;
2409 void RGWCreateBucket::pre_exec()
2411 rgw_bucket_object_pre_exec(s
);
2414 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2415 map
<string
, bufferlist
>& out_attrs
,
2416 map
<string
, bufferlist
>& out_rmattrs
)
2418 for (const auto& kv
: orig_attrs
) {
2419 const string
& name
= kv
.first
;
2421 /* Check if the attr is user-defined metadata item. */
2422 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2423 RGW_ATTR_META_PREFIX
) == 0) {
2424 /* For the objects all existing meta attrs have to be removed. */
2425 out_rmattrs
[name
] = kv
.second
;
2426 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2427 out_attrs
[name
] = kv
.second
;
2432 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2433 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2434 * @out_attrs. Place results in @out_attrs.
2436 * NOTE: it's supposed that all special attrs already present in @out_attrs
2437 * will be preserved without any change. Special attributes are those which
2438 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2439 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2440 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2441 const set
<string
>& rmattr_names
,
2442 map
<string
, bufferlist
>& out_attrs
)
2444 for (const auto& kv
: orig_attrs
) {
2445 const string
& name
= kv
.first
;
2447 /* Check if the attr is user-defined metadata item. */
2448 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2449 RGW_ATTR_META_PREFIX
) == 0) {
2450 /* For the buckets all existing meta attrs are preserved,
2451 except those that are listed in rmattr_names. */
2452 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2453 const auto aiter
= out_attrs
.find(name
);
2455 if (aiter
!= std::end(out_attrs
)) {
2456 out_attrs
.erase(aiter
);
2459 /* emplace() won't alter the map if the key is already present.
2460 * This behaviour is fully intensional here. */
2461 out_attrs
.emplace(kv
);
2463 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2464 out_attrs
[name
] = kv
.second
;
2470 static void populate_with_generic_attrs(const req_state
* const s
,
2471 map
<string
, bufferlist
>& out_attrs
)
2473 for (const auto& kv
: s
->generic_attrs
) {
2474 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2475 const string
& val
= kv
.second
;
2477 attrbl
.append(val
.c_str(), val
.size() + 1);
2482 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2483 const std::set
<std::string
>& rmattr_names
,
2484 RGWQuotaInfo
& quota
,
2485 bool * quota_extracted
= nullptr)
2487 bool extracted
= false;
2489 /* Put new limit on max objects. */
2490 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2492 if (std::end(add_attrs
) != iter
) {
2494 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2498 add_attrs
.erase(iter
);
2502 /* Put new limit on bucket (container) size. */
2503 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2504 if (iter
!= add_attrs
.end()) {
2506 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2510 add_attrs
.erase(iter
);
2514 for (const auto& name
: rmattr_names
) {
2515 /* Remove limit on max objects. */
2516 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2517 quota
.max_objects
= -1;
2521 /* Remove limit on max bucket size. */
2522 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2523 quota
.max_size
= -1;
2528 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2529 quota
.check_on_raw
= true;
2530 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2532 if (quota_extracted
) {
2533 *quota_extracted
= extracted
;
2540 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2541 const std::set
<std::string
>& rmattr_names
,
2542 RGWBucketWebsiteConf
& ws_conf
)
2546 /* Let's define a mapping between each custom attribute and the memory where
2547 * attribute's value should be stored. The memory location is expressed by
2548 * a non-const reference. */
2549 const auto mapping
= {
2550 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2551 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2552 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2553 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2554 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2557 for (const auto& kv
: mapping
) {
2558 const char * const key
= kv
.first
;
2559 auto& target
= kv
.second
;
2561 auto iter
= add_attrs
.find(key
);
2563 if (std::end(add_attrs
) != iter
) {
2564 /* The "target" is a reference to ws_conf. */
2565 target
= iter
->second
.c_str();
2566 add_attrs
.erase(iter
);
2569 if (rmattr_names
.count(key
)) {
2570 target
= std::string();
2574 if (! lstval
.empty()) {
2575 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2580 void RGWCreateBucket::execute()
2582 RGWAccessControlPolicy
old_policy(s
->cct
);
2584 buffer::list corsbl
;
2587 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2588 rgw_raw_obj
obj(store
->get_zone_params().domain_root
, bucket_name
);
2589 obj_version objv
, *pobjv
= NULL
;
2591 op_ret
= get_params();
2595 if (!location_constraint
.empty() &&
2596 !store
->has_zonegroup_api(location_constraint
)) {
2597 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2598 << " can't be found." << dendl
;
2599 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2600 s
->err
.message
= "The specified location-constraint is not valid";
2604 if (!store
->get_zonegroup().is_master_zonegroup() && !location_constraint
.empty() &&
2605 store
->get_zonegroup().api_name
!= location_constraint
) {
2606 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2607 << " doesn't match zonegroup" << " (" << store
->get_zonegroup().api_name
<< ")"
2609 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2610 s
->err
.message
= "The specified location-constraint is not valid";
2614 const auto& zonegroup
= store
->get_zonegroup();
2615 if (!placement_rule
.empty() &&
2616 !zonegroup
.placement_targets
.count(placement_rule
)) {
2617 ldout(s
->cct
, 0) << "placement target (" << placement_rule
<< ")"
2618 << " doesn't exist in the placement targets of zonegroup"
2619 << " (" << store
->get_zonegroup().api_name
<< ")" << dendl
;
2620 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2621 s
->err
.message
= "The specified placement target does not exist";
2625 /* we need to make sure we read bucket info, it's not read before for this
2626 * specific request */
2627 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2628 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2629 s
->bucket_info
, NULL
, &s
->bucket_attrs
);
2630 if (op_ret
< 0 && op_ret
!= -ENOENT
)
2632 s
->bucket_exists
= (op_ret
!= -ENOENT
);
2634 s
->bucket_owner
.set_id(s
->user
->user_id
);
2635 s
->bucket_owner
.set_name(s
->user
->display_name
);
2636 if (s
->bucket_exists
) {
2637 int r
= get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
2638 s
->bucket_attrs
, &old_policy
);
2640 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
2647 RGWBucketInfo master_info
;
2648 rgw_bucket
*pmaster_bucket
;
2649 uint32_t *pmaster_num_shards
;
2650 real_time creation_time
;
2652 if (!store
->is_meta_master()) {
2654 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
2659 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
2660 JSONDecoder::decode_json("object_ver", objv
, &jp
);
2661 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
2662 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
2663 ldout(s
->cct
, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
2664 pmaster_bucket
= &master_info
.bucket
;
2665 creation_time
= master_info
.creation_time
;
2666 pmaster_num_shards
= &master_info
.num_shards
;
2669 pmaster_bucket
= NULL
;
2670 pmaster_num_shards
= NULL
;
2673 string zonegroup_id
;
2675 if (s
->system_request
) {
2676 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
2677 if (zonegroup_id
.empty()) {
2678 zonegroup_id
= store
->get_zonegroup().get_id();
2681 zonegroup_id
= store
->get_zonegroup().get_id();
2684 if (s
->bucket_exists
) {
2685 string selected_placement_rule
;
2687 bucket
.tenant
= s
->bucket_tenant
;
2688 bucket
.name
= s
->bucket_name
;
2689 op_ret
= store
->select_bucket_placement(*(s
->user
), zonegroup_id
,
2691 &selected_placement_rule
, nullptr);
2692 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
2698 /* Encode special metadata first as we're using std::map::emplace under
2699 * the hood. This method will add the new items only if the map doesn't
2700 * contain such keys yet. */
2701 policy
.encode(aclbl
);
2702 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
2705 cors_config
.encode(corsbl
);
2706 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
2709 RGWQuotaInfo quota_info
;
2710 const RGWQuotaInfo
* pquota_info
= nullptr;
2711 if (need_metadata_upload()) {
2712 /* It's supposed that following functions WILL NOT change any special
2713 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
2714 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2718 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2719 populate_with_generic_attrs(s
, attrs
);
2721 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
2725 pquota_info
= "a_info
;
2728 /* Web site of Swift API. */
2729 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2730 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2733 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
2734 s
->bucket
.name
= s
->bucket_name
;
2736 /* Handle updates of the metadata for Swift's object versioning. */
2737 if (swift_ver_location
) {
2738 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2739 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2742 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
2743 placement_rule
, s
->bucket_info
.swift_ver_location
,
2745 info
, pobjv
, &ep_objv
, creation_time
,
2746 pmaster_bucket
, pmaster_num_shards
, true);
2747 /* continue if EEXIST and create_bucket will fail below. this way we can
2748 * recover from a partial create by retrying it. */
2749 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
2751 if (op_ret
&& op_ret
!= -EEXIST
)
2754 existed
= (op_ret
== -EEXIST
);
2757 /* bucket already existed, might have raced with another bucket creation, or
2758 * might be partial bucket creation that never completed. Read existing bucket
2759 * info, verify that the reported bucket owner is the current user.
2760 * If all is ok then update the user's list of buckets.
2761 * Otherwise inform client about a name conflict.
2763 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
2767 s
->bucket
= info
.bucket
;
2770 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
2771 info
.creation_time
, false);
2772 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
2773 /* if it exists (or previously existed), don't remove it! */
2774 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2777 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2780 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
2781 op_ret
= -ERR_BUCKET_EXISTS
;
2784 if (need_metadata_upload() && existed
) {
2785 /* OK, it looks we lost race with another request. As it's required to
2786 * handle metadata fusion and upload, the whole operation becomes very
2787 * similar in nature to PutMetadataBucket. However, as the attrs may
2788 * changed in the meantime, we have to refresh. */
2791 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2792 RGWBucketInfo binfo
;
2793 map
<string
, bufferlist
> battrs
;
2795 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2796 binfo
, nullptr, &battrs
);
2799 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
2800 /* New bucket doesn't belong to the account we're operating on. */
2804 s
->bucket_info
= binfo
;
2805 s
->bucket_attrs
= battrs
;
2810 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2814 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2815 populate_with_generic_attrs(s
, attrs
);
2816 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
2821 /* Handle updates of the metadata for Swift's object versioning. */
2822 if (swift_ver_location
) {
2823 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2824 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2827 /* Web site of Swift API. */
2828 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2829 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2831 /* This will also set the quota on the bucket. */
2832 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
2833 &s
->bucket_info
.objv_tracker
);
2834 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
2836 /* Restore the proper return code. */
2838 op_ret
= -ERR_BUCKET_EXISTS
;
2843 int RGWDeleteBucket::verify_permission()
2845 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucket
)) {
2852 void RGWDeleteBucket::pre_exec()
2854 rgw_bucket_object_pre_exec(s
);
2857 void RGWDeleteBucket::execute()
2861 if (s
->bucket_name
.empty())
2864 if (!s
->bucket_exists
) {
2865 ldout(s
->cct
, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
2866 op_ret
= -ERR_NO_SUCH_BUCKET
;
2869 RGWObjVersionTracker ot
;
2870 ot
.read_version
= s
->bucket_info
.ep_objv
;
2872 if (s
->system_request
) {
2873 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
2874 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
2876 ot
.read_version
.tag
= tag
;
2879 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
2881 ldout(s
->cct
, 0) << "failed to parse ver param" << dendl
;
2885 ot
.read_version
.ver
= ver
;
2889 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
2891 ldout(s
->cct
, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
2894 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
2899 if (!store
->is_meta_master()) {
2901 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
2904 if (op_ret
== -ENOENT
) {
2905 /* adjust error, we want to return with NoSuchBucket and not
2907 op_ret
= -ERR_NO_SUCH_BUCKET
;
2913 string prefix
, delimiter
;
2915 if (s
->prot_flags
& RGW_REST_SWIFT
) {
2917 path_args
= s
->info
.args
.get("path");
2918 if (!path_args
.empty()) {
2919 if (!delimiter
.empty() || !prefix
.empty()) {
2928 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
2934 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
2936 if (op_ret
== -ECANCELED
) {
2937 // lost a race, either with mdlog sync or another delete bucket operation.
2938 // in either case, we've already called rgw_unlink_bucket()
2944 op_ret
= rgw_unlink_bucket(store
, s
->bucket_info
.owner
, s
->bucket
.tenant
,
2945 s
->bucket
.name
, false);
2947 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2959 int RGWPutObj::verify_permission()
2961 if (! copy_source
.empty()) {
2963 RGWAccessControlPolicy
cs_acl(s
->cct
);
2964 optional
<Policy
> policy
;
2965 map
<string
, bufferlist
> cs_attrs
;
2966 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
2967 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
2969 rgw_obj
obj(cs_bucket
, cs_object
);
2970 store
->set_atomic(s
->obj_ctx
, obj
);
2971 store
->set_prefetch_data(s
->obj_ctx
, obj
);
2973 /* check source object permissions */
2974 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
,
2975 policy
, cs_bucket
, cs_object
) < 0) {
2979 /* admin request overrides permission checks */
2980 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
2982 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
2983 cs_object
.instance
.empty() ?
2984 rgw::IAM::s3GetObject
:
2985 rgw::IAM::s3GetObjectVersion
,
2986 rgw::IAM::ARN(obj
));
2987 if (e
== Effect::Deny
) {
2989 } else if (e
== Effect::Pass
&&
2990 !cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2994 } else if (!cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
3001 if (s
->iam_policy
) {
3002 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3003 rgw::IAM::s3PutObject
,
3004 rgw_obj(s
->bucket
, s
->object
));
3005 if (e
== Effect::Allow
) {
3007 } else if (e
== Effect::Deny
) {
3012 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3019 void RGWPutObjProcessor_Multipart::get_mp(RGWMPObj
** _mp
){
3023 int RGWPutObjProcessor_Multipart::prepare(RGWRados
*store
, string
*oid_rand
)
3025 string oid
= obj_str
;
3026 upload_id
= s
->info
.args
.get("uploadId");
3028 mp
.init(oid
, upload_id
);
3030 mp
.init(oid
, upload_id
, *oid_rand
);
3033 part_num
= s
->info
.args
.get("partNumber");
3034 if (part_num
.empty()) {
3035 ldout(s
->cct
, 10) << "part number is empty" << dendl
;
3040 uint64_t num
= (uint64_t)strict_strtol(part_num
.c_str(), 10, &err
);
3043 ldout(s
->cct
, 10) << "bad part number: " << part_num
<< ": " << err
<< dendl
;
3047 string upload_prefix
= oid
+ ".";
3050 upload_prefix
.append(upload_id
);
3052 upload_prefix
.append(*oid_rand
);
3056 target_obj
.init(bucket
, oid
);
3058 manifest
.set_prefix(upload_prefix
);
3060 manifest
.set_multipart_part_rule(store
->ctx()->_conf
->rgw_obj_stripe_size
, num
);
3062 int r
= manifest_gen
.create_begin(store
->ctx(), &manifest
, s
->bucket_info
.placement_rule
, bucket
, target_obj
);
3067 cur_obj
= manifest_gen
.get_cur_obj(store
);
3068 rgw_raw_obj_to_obj(bucket
, cur_obj
, &head_obj
);
3069 head_obj
.index_hash_source
= obj_str
;
3071 r
= prepare_init(store
, NULL
);
3079 int RGWPutObjProcessor_Multipart::do_complete(size_t accounted_size
,
3081 real_time
*mtime
, real_time set_mtime
,
3082 map
<string
, bufferlist
>& attrs
,
3083 real_time delete_at
,
3084 const char *if_match
,
3085 const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
)
3087 complete_writing_data();
3089 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, head_obj
);
3090 op_target
.set_versioning_disabled(true);
3091 RGWRados::Object::Write
head_obj_op(&op_target
);
3093 head_obj_op
.meta
.set_mtime
= set_mtime
;
3094 head_obj_op
.meta
.mtime
= mtime
;
3095 head_obj_op
.meta
.owner
= s
->owner
.get_id();
3096 head_obj_op
.meta
.delete_at
= delete_at
;
3097 head_obj_op
.meta
.zones_trace
= zones_trace
;
3098 head_obj_op
.meta
.modify_tail
= true;
3100 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3105 RGWUploadPartInfo info
;
3107 bool sorted_omap
= is_v2_upload_id(upload_id
);
3111 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3113 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3117 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3122 info
.num
= atoi(part_num
.c_str());
3124 info
.size
= obj_len
;
3125 info
.accounted_size
= accounted_size
;
3126 info
.modified
= real_clock::now();
3127 info
.manifest
= manifest
;
3130 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3132 dout(1) << "cannot get compression info" << dendl
;
3138 string multipart_meta_obj
= mp
.get_meta();
3141 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3142 meta_obj
.set_in_extra_data(true);
3144 rgw_raw_obj raw_meta_obj
;
3146 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3148 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3153 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3155 RGWPutObjProcessor
*processor
;
3157 bool multipart
= s
->info
.args
.exists("uploadId");
3159 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3162 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3163 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3164 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3166 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3170 *is_multipart
= multipart
;
3176 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3181 void RGWPutObj::pre_exec()
3183 rgw_bucket_object_pre_exec(s
);
3186 class RGWPutObj_CB
: public RGWGetDataCB
3190 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3191 ~RGWPutObj_CB() override
{}
3193 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3194 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3198 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3201 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3203 bl_aux
.append(bl_tmp
);
3208 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3210 RGWPutObj_CB
cb(this);
3211 RGWGetDataCB
* filter
= &cb
;
3212 boost::optional
<RGWGetObj_Decompress
> decompress
;
3213 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3214 RGWCompressionInfo cs_info
;
3215 map
<string
, bufferlist
> attrs
;
3216 map
<string
, bufferlist
>::iterator attr_iter
;
3220 int64_t new_ofs
, new_end
;
3225 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3226 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3228 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3229 RGWRados::Object::Read
read_op(&op_target
);
3230 read_op
.params
.obj_size
= &obj_size
;
3231 read_op
.params
.attrs
= &attrs
;
3233 ret
= read_op
.prepare();
3237 bool need_decompress
;
3238 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3240 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3244 bool partial_content
= true;
3245 if (need_decompress
)
3247 obj_size
= cs_info
.orig_size
;
3248 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3249 filter
= &*decompress
;
3252 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3253 op_ret
= this->get_decrypt_filter(&decrypt
,
3256 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3257 if (decrypt
!= nullptr) {
3258 filter
= decrypt
.get();
3264 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3268 filter
->fixup_range(new_ofs
, new_end
);
3269 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3272 ret
= filter
->flush();
3274 bl
.claim_append(bl_aux
);
3279 // special handling for compression type = "random" with multipart uploads
3280 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3281 const std::string
& compression_type
)
3283 if (compression_type
!= "random") {
3284 return Compressor::create(s
->cct
, compression_type
);
3287 bool is_multipart
{false};
3288 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3290 if (!is_multipart
) {
3291 return Compressor::create(s
->cct
, compression_type
);
3294 // use a hash of the multipart upload id so all parts use the same plugin
3295 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3296 if (alg
== Compressor::COMP_ALG_NONE
) {
3299 return Compressor::create(s
->cct
, alg
);
3302 void RGWPutObj::execute()
3304 RGWPutObjProcessor
*processor
= NULL
;
3305 RGWPutObjDataProcessor
*filter
= nullptr;
3306 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3307 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3308 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3309 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3310 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3312 bufferlist bl
, aclbl
, bs
;
3314 map
<string
, string
>::iterator iter
;
3319 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3320 s
->bucket_info
.placement_rule
);
3321 CompressorRef plugin
;
3322 boost::optional
<RGWPutObj_Compress
> compressor
;
3324 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3325 perfcounter
->inc(l_rgw_put
);
3327 if (s
->object
.empty()) {
3331 if (!s
->bucket_exists
) {
3332 op_ret
= -ERR_NO_SUCH_BUCKET
;
3336 op_ret
= get_params();
3338 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3342 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3344 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3349 if (supplied_md5_b64
) {
3350 need_calc_md5
= true;
3352 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3353 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3354 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3355 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3356 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3357 op_ret
= -ERR_INVALID_DIGEST
;
3361 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3362 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3365 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3366 we also check sizes at the end anyway */
3367 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3368 user_quota
, bucket_quota
, s
->content_length
);
3370 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3373 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3375 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3380 if (supplied_etag
) {
3381 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3382 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3385 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3387 // no filters by default
3390 /* Handle object versioning of Swift API. */
3392 rgw_obj
obj(s
->bucket
, s
->object
);
3393 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3394 s
->bucket_owner
.get_id(),
3402 op_ret
= processor
->prepare(store
, NULL
);
3404 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3409 if ((! copy_source
.empty()) && !copy_source_range
) {
3410 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3411 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
.name
);
3413 RGWObjState
*astate
;
3414 op_ret
= store
->get_obj_state(static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3415 copy_source_bucket_info
, obj
, &astate
, true, false);
3417 ldout(s
->cct
, 0) << "ERROR: get copy source obj state returned with error" << op_ret
<< dendl
;
3420 if (!astate
->exists
){
3424 lst
= astate
->size
- 1;
3426 lst
= copy_source_range_lst
;
3429 fst
= copy_source_range_fst
;
3431 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3435 if (encrypt
!= nullptr) {
3436 filter
= encrypt
.get();
3438 //no encryption, we can try compression
3439 if (compression_type
!= "none") {
3440 plugin
= get_compressor_plugin(s
, compression_type
);
3442 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3443 << compression_type
<< dendl
;
3445 compressor
.emplace(s
->cct
, plugin
, filter
);
3446 filter
= &*compressor
;
3455 if (copy_source
.empty()) {
3456 len
= get_data(data
);
3458 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3459 op_ret
= get_data(fst
, cur_lst
, data
);
3462 len
= data
.length();
3463 s
->content_length
+= len
;
3471 if (need_calc_md5
) {
3472 hash
.Update((const byte
*)data
.c_str(), data
.length());
3475 /* update torrrent */
3476 torrent
.update(data
);
3478 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3479 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3481 bool need_to_wait
= (ofs
== 0) && multipart
;
3483 bufferlist orig_data
;
3489 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3491 if (!need_to_wait
|| op_ret
!= -EEXIST
) {
3492 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3496 /* need_to_wait == true and op_ret == -EEXIST */
3497 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3499 /* restore original data */
3500 data
.swap(orig_data
);
3502 /* restart processing with different oid suffix */
3504 dispose_processor(processor
);
3505 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3510 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3511 oid_rand
.append(buf
);
3513 op_ret
= processor
->prepare(store
, &oid_rand
);
3515 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3520 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3524 if (encrypt
!= nullptr) {
3525 filter
= encrypt
.get();
3528 compressor
.emplace(s
->cct
, plugin
, filter
);
3529 filter
= &*compressor
;
3532 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3543 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3549 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3550 op_ret
= -ERR_REQUEST_TIMEOUT
;
3555 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3557 op_ret
= do_aws4_auth_completion();
3562 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3563 user_quota
, bucket_quota
, s
->obj_size
);
3565 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3569 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3571 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3577 if (compressor
&& compressor
->is_compressed()) {
3579 RGWCompressionInfo cs_info
;
3580 cs_info
.compression_type
= plugin
->get_type_name();
3581 cs_info
.orig_size
= s
->obj_size
;
3582 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3583 ::encode(cs_info
, tmp
);
3584 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3585 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3586 << " with type=" << cs_info
.compression_type
3587 << ", orig_size=" << cs_info
.orig_size
3588 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3591 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3595 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3596 op_ret
= -ERR_BAD_DIGEST
;
3600 policy
.encode(aclbl
);
3601 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3604 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3606 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3609 complete_etag(hash
, &etag
);
3610 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3614 bufferlist manifest_bl
;
3615 ::encode(*slo_info
, manifest_bl
);
3616 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3618 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3619 complete_etag(hash
, &etag
);
3620 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3623 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3624 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3627 bl
.append(etag
.c_str(), etag
.size() + 1);
3628 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3630 populate_with_generic_attrs(s
, attrs
);
3631 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3635 encode_delete_at_attr(delete_at
, attrs
);
3636 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3638 /* Add a custom metadata to expose the information whether an object
3639 * is an SLO or not. Appending the attribute must be performed AFTER
3640 * processing any input from user in order to prohibit overwriting. */
3642 bufferlist slo_userindicator_bl
;
3643 slo_userindicator_bl
.append("True", 4);
3644 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3647 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3648 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3649 (user_data
.empty() ? nullptr : &user_data
));
3651 /* produce torrent */
3652 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3654 torrent
.init(s
, store
);
3655 torrent
.set_create_date(mtime
);
3656 op_ret
= torrent
.complete();
3659 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3665 dispose_processor(processor
);
3666 perfcounter
->tinc(l_rgw_put_lat
,
3667 (ceph_clock_now() - s
->time
));
3670 int RGWPostObj::verify_permission()
3675 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3677 RGWPutObjProcessor *processor;
3679 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3681 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3686 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3691 void RGWPostObj::pre_exec()
3693 rgw_bucket_object_pre_exec(s
);
3696 void RGWPostObj::execute()
3698 RGWPutObjDataProcessor
*filter
= nullptr;
3699 boost::optional
<RGWPutObj_Compress
> compressor
;
3700 CompressorRef plugin
;
3701 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3703 /* Read in the data from the POST form. */
3704 op_ret
= get_params();
3709 op_ret
= verify_params();
3714 if (s
->iam_policy
) {
3715 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3716 rgw::IAM::s3PutObject
,
3717 rgw_obj(s
->bucket
, s
->object
));
3718 if (e
== Effect::Deny
) {
3721 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3725 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3730 /* Start iteration over data fields. It's necessary as Swift's FormPost
3731 * is capable to handle multiple files in single form. */
3733 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3734 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3735 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3737 ceph::buffer::list bl
, aclbl
;
3740 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3749 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3754 if (supplied_md5_b64
) {
3755 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3756 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3757 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3758 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3759 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3760 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3761 op_ret
= -ERR_INVALID_DIGEST
;
3765 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3766 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3769 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3772 get_current_filename(),
3774 s
->cct
->_conf
->rgw_obj_stripe_size
,
3776 s
->bucket_info
.versioning_enabled());
3777 /* No filters by default. */
3778 filter
= &processor
;
3780 op_ret
= processor
.prepare(store
, nullptr);
3785 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3789 if (encrypt
!= nullptr) {
3790 filter
= encrypt
.get();
3792 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3793 s
->bucket_info
.placement_rule
);
3794 if (compression_type
!= "none") {
3795 plugin
= Compressor::create(s
->cct
, compression_type
);
3797 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3798 << compression_type
<< dendl
;
3800 compressor
.emplace(s
->cct
, plugin
, filter
);
3801 filter
= &*compressor
;
3808 ceph::bufferlist data
;
3809 len
= get_data(data
, again
);
3820 hash
.Update((const byte
*)data
.c_str(), data
.length());
3821 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3825 if (ofs
> max_len
) {
3826 op_ret
= -ERR_TOO_LARGE
;
3833 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3836 if (len
< min_len
) {
3837 op_ret
= -ERR_TOO_SMALL
;
3843 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3844 op_ret
= -ERR_BAD_DIGEST
;
3848 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3849 user_quota
, bucket_quota
, s
->obj_size
);
3854 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3860 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3863 bl
.append(etag
.c_str(), etag
.size() + 1);
3864 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3866 policy
.encode(aclbl
);
3867 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3869 const std::string content_type
= get_current_content_type();
3870 if (! content_type
.empty()) {
3871 ceph::bufferlist ct_bl
;
3872 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3873 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3876 if (compressor
&& compressor
->is_compressed()) {
3877 ceph::bufferlist tmp
;
3878 RGWCompressionInfo cs_info
;
3879 cs_info
.compression_type
= plugin
->get_type_name();
3880 cs_info
.orig_size
= s
->obj_size
;
3881 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3882 ::encode(cs_info
, tmp
);
3883 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3886 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3887 attrs
, (delete_at
? *delete_at
: real_time()));
3888 } while (is_next_file_to_upload());
3892 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3893 const set
<string
>& rmattr_names
,
3894 map
<int, string
>& temp_url_keys
)
3896 map
<string
, bufferlist
>::iterator iter
;
3898 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3899 if (iter
!= add_attrs
.end()) {
3900 temp_url_keys
[0] = iter
->second
.c_str();
3901 add_attrs
.erase(iter
);
3904 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3905 if (iter
!= add_attrs
.end()) {
3906 temp_url_keys
[1] = iter
->second
.c_str();
3907 add_attrs
.erase(iter
);
3910 for (const string
& name
: rmattr_names
) {
3911 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3912 temp_url_keys
[0] = string();
3914 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3915 temp_url_keys
[1] = string();
3920 int RGWPutMetadataAccount::init_processing()
3922 /* First, go to the base class. At the time of writing the method was
3923 * responsible only for initializing the quota. This isn't necessary
3924 * here as we are touching metadata only. I'm putting this call only
3925 * for the future. */
3926 op_ret
= RGWOp::init_processing();
3931 op_ret
= get_params();
3936 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3944 policy
.encode(acl_bl
);
3945 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3948 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3952 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3953 populate_with_generic_attrs(s
, attrs
);
3955 /* Try extract the TempURL-related stuff now to allow verify_permission
3956 * evaluate whether we need FULL_CONTROL or not. */
3957 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3959 /* The same with quota except a client needs to be reseller admin. */
3960 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3961 &new_quota_extracted
);
3969 int RGWPutMetadataAccount::verify_permission()
3971 if (s
->auth
.identity
->is_anonymous()) {
3975 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
3979 /* Altering TempURL keys requires FULL_CONTROL. */
3980 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
3984 /* We are failing this intensionally to allow system user/reseller admin
3985 * override in rgw_process.cc. This is the way to specify a given RGWOp
3986 * expect extra privileges. */
3987 if (new_quota_extracted
) {
3994 void RGWPutMetadataAccount::execute()
3996 /* Params have been extracted earlier. See init_processing(). */
3997 RGWUserInfo new_uinfo
;
3998 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
4004 /* Handle the TempURL-related stuff. */
4005 if (!temp_url_keys
.empty()) {
4006 for (auto& pair
: temp_url_keys
) {
4007 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
4011 /* Handle the quota extracted at the verify_permission step. */
4012 if (new_quota_extracted
) {
4013 new_uinfo
.user_quota
= std::move(new_quota
);
4016 /* We are passing here the current (old) user info to allow the function
4017 * optimize-out some operations. */
4018 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
4019 &acct_op_tracker
, real_time(), false, &attrs
);
4022 int RGWPutMetadataBucket::verify_permission()
4024 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4031 void RGWPutMetadataBucket::pre_exec()
4033 rgw_bucket_object_pre_exec(s
);
4036 void RGWPutMetadataBucket::execute()
4038 op_ret
= get_params();
4043 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
4048 if (!placement_rule
.empty() &&
4049 placement_rule
!= s
->bucket_info
.placement_rule
) {
4054 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
4055 /* Encode special metadata first as we're using std::map::emplace under
4056 * the hood. This method will add the new items only if the map doesn't
4057 * contain such keys yet. */
4059 if (s
->dialect
.compare("swift") == 0) {
4061 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
4062 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
4063 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
4064 policy
= *new_policy
;
4068 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
4073 cors_config
.encode(bl
);
4074 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
4077 /* It's supposed that following functions WILL NOT change any
4078 * special attributes (like RGW_ATTR_ACL) if they are already
4079 * present in attrs. */
4080 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
4081 populate_with_generic_attrs(s
, attrs
);
4083 /* According to the Swift's behaviour and its container_quota
4084 * WSGI middleware implementation: anyone with write permissions
4085 * is able to set the bucket quota. This stays in contrast to
4086 * account quotas that can be set only by clients holding
4087 * reseller admin privileges. */
4088 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
4093 if (swift_ver_location
) {
4094 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
4095 s
->bucket_info
.swift_versioning
= (!swift_ver_location
->empty());
4098 /* Web site of Swift API. */
4099 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
4100 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
4102 /* Setting attributes also stores the provided bucket info. Due
4103 * to this fact, the new quota settings can be serialized with
4105 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
4106 &s
->bucket_info
.objv_tracker
);
4111 int RGWPutMetadataObject::verify_permission()
4113 // This looks to be something specific to Swift. We could add
4114 // operations like swift:PutMetadataObject to the Policy Engine.
4115 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4122 void RGWPutMetadataObject::pre_exec()
4124 rgw_bucket_object_pre_exec(s
);
4127 void RGWPutMetadataObject::execute()
4129 rgw_obj
obj(s
->bucket
, s
->object
);
4130 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4132 store
->set_atomic(s
->obj_ctx
, obj
);
4134 op_ret
= get_params();
4139 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4144 /* check if obj exists, read orig attrs */
4145 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4150 /* Check whether the object has expired. Swift API documentation
4151 * stands that we should return 404 Not Found in such case. */
4152 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4157 /* Filter currently existing attributes. */
4158 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4159 populate_with_generic_attrs(s
, attrs
);
4160 encode_delete_at_attr(delete_at
, attrs
);
4163 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4165 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4170 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4173 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4175 RGWSLOInfo slo_info
;
4176 bufferlist::iterator bliter
= bl
.begin();
4178 ::decode(slo_info
, bliter
);
4179 } catch (buffer::error
& err
) {
4180 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4185 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4186 new RGWBulkDelete::Deleter(store
, s
));
4187 } catch (std::bad_alloc
) {
4191 list
<RGWBulkDelete::acct_path_t
> items
;
4192 for (const auto& iter
: slo_info
.entries
) {
4193 const string
& path_str
= iter
.path
;
4195 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4196 if (boost::string_view::npos
== sep_pos
) {
4200 RGWBulkDelete::acct_path_t path
;
4202 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4203 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4205 items
.push_back(path
);
4208 /* Request removal of the manifest object itself. */
4209 RGWBulkDelete::acct_path_t path
;
4210 path
.bucket_name
= s
->bucket_name
;
4211 path
.obj_key
= s
->object
;
4212 items
.push_back(path
);
4214 int ret
= deleter
->delete_chunk(items
);
4222 int RGWDeleteObj::verify_permission()
4224 if (s
->iam_policy
) {
4225 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4226 s
->object
.instance
.empty() ?
4227 rgw::IAM::s3DeleteObject
:
4228 rgw::IAM::s3DeleteObjectVersion
,
4229 ARN(s
->bucket
, s
->object
.name
));
4230 if (r
== Effect::Allow
)
4232 else if (r
== Effect::Deny
)
4236 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4243 void RGWDeleteObj::pre_exec()
4245 rgw_bucket_object_pre_exec(s
);
4248 void RGWDeleteObj::execute()
4250 if (!s
->bucket_exists
) {
4251 op_ret
= -ERR_NO_SUCH_BUCKET
;
4255 op_ret
= get_params();
4260 rgw_obj
obj(s
->bucket
, s
->object
);
4261 map
<string
, bufferlist
> attrs
;
4264 if (!s
->object
.empty()) {
4265 if (need_object_expiration() || multipart_delete
) {
4266 /* check if obj exists, read orig attrs */
4267 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4273 if (multipart_delete
) {
4274 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4276 if (slo_attr
!= attrs
.end()) {
4277 op_ret
= handle_slo_manifest(slo_attr
->second
);
4279 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4282 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4288 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4289 obj_ctx
->obj
.set_atomic(obj
);
4291 bool ver_restored
= false;
4292 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4293 s
->bucket_info
, obj
, ver_restored
);
4298 if (!ver_restored
) {
4299 /* Swift's versioning mechanism hasn't found any previous version of
4300 * the object that could be restored. This means we should proceed
4301 * with the regular delete path. */
4302 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4303 RGWRados::Object::Delete
del_op(&del_target
);
4305 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4306 &del_op
.params
.marker_version_id
);
4311 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4312 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4313 del_op
.params
.obj_owner
= s
->owner
;
4314 del_op
.params
.unmod_since
= unmod_since
;
4315 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4317 op_ret
= del_op
.delete_obj();
4319 delete_marker
= del_op
.result
.delete_marker
;
4320 version_id
= del_op
.result
.version_id
;
4323 /* Check whether the object has expired. Swift API documentation
4324 * stands that we should return 404 Not Found in such case. */
4325 if (need_object_expiration() && object_is_expired(attrs
)) {
4331 if (op_ret
== -ECANCELED
) {
4334 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4342 bool RGWCopyObj::parse_copy_location(const boost::string_view
& url_src
,
4343 string
& bucket_name
,
4346 boost::string_view name_str
;
4347 boost::string_view params_str
;
4349 size_t pos
= url_src
.find('?');
4350 if (pos
== string::npos
) {
4353 name_str
= url_src
.substr(0, pos
);
4354 params_str
= url_src
.substr(pos
+ 1);
4357 boost::string_view dec_src
{name_str
};
4358 if (dec_src
[0] == '/')
4359 dec_src
.remove_prefix(1);
4361 pos
= dec_src
.find('/');
4362 if (pos
==string::npos
)
4365 boost::string_view bn_view
{dec_src
.substr(0, pos
)};
4366 bucket_name
= std::string
{bn_view
.data(), bn_view
.size()};
4368 boost::string_view kn_view
{dec_src
.substr(pos
+ 1)};
4369 key
.name
= std::string
{kn_view
.data(), kn_view
.size()};
4371 if (key
.name
.empty()) {
4375 if (! params_str
.empty()) {
4377 args
.set(params_str
.to_string());
4380 key
.instance
= args
.get("versionId", NULL
);
4386 int RGWCopyObj::verify_permission()
4388 RGWAccessControlPolicy
src_acl(s
->cct
);
4389 optional
<Policy
> src_policy
;
4390 op_ret
= get_params();
4394 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4398 map
<string
, bufferlist
> src_attrs
;
4400 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4402 if (s
->bucket_instance_id
.empty()) {
4403 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4405 /* will only happen in intra region sync where the source and dest bucket is the same */
4406 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4409 if (op_ret
== -ENOENT
) {
4410 op_ret
= -ERR_NO_SUCH_BUCKET
;
4415 src_bucket
= src_bucket_info
.bucket
;
4417 /* get buckets info (source and dest) */
4418 if (s
->local_source
&& source_zone
.empty()) {
4419 rgw_obj
src_obj(src_bucket
, src_object
);
4420 store
->set_atomic(s
->obj_ctx
, src_obj
);
4421 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4423 /* check source object permissions */
4424 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4425 src_policy
, src_bucket
, src_object
);
4430 /* admin request overrides permission checks */
4431 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4433 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4434 src_object
.instance
.empty() ?
4435 rgw::IAM::s3GetObject
:
4436 rgw::IAM::s3GetObjectVersion
,
4438 if (e
== Effect::Deny
) {
4440 } else if (e
== Effect::Pass
&&
4441 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4445 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4453 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4454 map
<string
, bufferlist
> dest_attrs
;
4456 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4457 or intra region sync */
4458 dest_bucket_info
= src_bucket_info
;
4459 dest_attrs
= src_attrs
;
4461 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4462 dest_bucket_info
, nullptr, &dest_attrs
);
4464 if (op_ret
== -ENOENT
) {
4465 op_ret
= -ERR_NO_SUCH_BUCKET
;
4471 dest_bucket
= dest_bucket_info
.bucket
;
4473 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4474 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4476 /* check dest bucket permissions */
4477 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4478 &dest_bucket_policy
, dest_bucket
);
4483 /* admin request overrides permission checks */
4484 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4485 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4490 op_ret
= init_dest_policy();
4499 int RGWCopyObj::init_common()
4502 if (parse_time(if_mod
, &mod_time
) < 0) {
4506 mod_ptr
= &mod_time
;
4510 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4514 unmod_ptr
= &unmod_time
;
4518 dest_policy
.encode(aclbl
);
4519 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4521 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4525 populate_with_generic_attrs(s
, attrs
);
4530 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4532 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4533 op
->progress_cb(ofs
);
4536 void RGWCopyObj::progress_cb(off_t ofs
)
4538 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4541 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4544 send_partial_response(ofs
);
4549 void RGWCopyObj::pre_exec()
4551 rgw_bucket_object_pre_exec(s
);
4554 void RGWCopyObj::execute()
4556 if (init_common() < 0)
4559 rgw_obj
src_obj(src_bucket
, src_object
);
4560 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4562 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4563 obj_ctx
.obj
.set_atomic(src_obj
);
4564 obj_ctx
.obj
.set_atomic(dst_obj
);
4566 encode_delete_at_attr(delete_at
, attrs
);
4568 bool high_precision_time
= (s
->system_request
);
4570 /* Handle object versioning of Swift API. In case of copying to remote this
4571 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4572 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4573 dest_bucket_info
.owner
,
4580 op_ret
= store
->copy_obj(obj_ctx
,
4594 high_precision_time
,
4599 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4601 (delete_at
? *delete_at
: real_time()),
4602 (version_id
.empty() ? NULL
: &version_id
),
4603 &s
->req_id
, /* use req_id as tag */
4605 copy_obj_progress_cb
, (void *)this
4609 int RGWGetACLs::verify_permission()
4612 if (!s
->object
.empty()) {
4613 perm
= verify_object_permission(s
,
4614 s
->object
.instance
.empty() ?
4615 rgw::IAM::s3GetObjectAcl
:
4616 rgw::IAM::s3GetObjectVersionAcl
);
4618 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetBucketAcl
);
4626 void RGWGetACLs::pre_exec()
4628 rgw_bucket_object_pre_exec(s
);
4631 void RGWGetACLs::execute()
4634 RGWAccessControlPolicy
* const acl
= \
4635 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4636 RGWAccessControlPolicy_S3
* const s3policy
= \
4637 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4638 s3policy
->to_xml(ss
);
4644 int RGWPutACLs::verify_permission()
4647 if (!s
->object
.empty()) {
4648 perm
= verify_object_permission(s
,
4649 s
->object
.instance
.empty() ?
4650 rgw::IAM::s3PutObjectAcl
:
4651 rgw::IAM::s3PutObjectVersionAcl
);
4653 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4661 int RGWGetLC::verify_permission()
4664 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4671 int RGWPutLC::verify_permission()
4674 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4681 int RGWDeleteLC::verify_permission()
4684 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4691 void RGWPutACLs::pre_exec()
4693 rgw_bucket_object_pre_exec(s
);
4696 void RGWGetLC::pre_exec()
4698 rgw_bucket_object_pre_exec(s
);
4701 void RGWPutLC::pre_exec()
4703 rgw_bucket_object_pre_exec(s
);
4706 void RGWDeleteLC::pre_exec()
4708 rgw_bucket_object_pre_exec(s
);
4711 void RGWPutACLs::execute()
4715 RGWAccessControlPolicy_S3
*policy
= NULL
;
4716 RGWACLXMLParser_S3
parser(s
->cct
);
4717 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4719 char *new_data
= NULL
;
4722 op_ret
= 0; /* XXX redundant? */
4724 if (!parser
.init()) {
4730 RGWAccessControlPolicy
* const existing_policy
= \
4731 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
4733 owner
= existing_policy
->get_owner();
4735 op_ret
= get_params();
4737 if (op_ret
== -ERANGE
) {
4738 ldout(s
->cct
, 4) << "The size of request xml data is larger than the max limitation, data size = "
4739 << s
->length
<< dendl
;
4740 op_ret
= -ERR_MALFORMED_XML
;
4741 s
->err
.message
= "The XML you provided was larger than the maximum " +
4742 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
4748 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4750 if (!s
->canned_acl
.empty() && len
) {
4755 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4756 op_ret
= get_policy_from_state(store
, s
, ss
);
4760 new_data
= strdup(ss
.str().c_str());
4763 len
= ss
.str().size();
4766 if (!parser
.parse(data
, len
, 1)) {
4770 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4776 const RGWAccessControlList
& req_acl
= policy
->get_acl();
4777 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
4778 #define ACL_GRANTS_MAX_NUM 100
4779 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
4781 max_num
= ACL_GRANTS_MAX_NUM
;
4784 int grants_num
= req_grant_map
.size();
4785 if (grants_num
> max_num
) {
4786 ldout(s
->cct
, 4) << "An acl can have up to "
4788 << " grants, request acl grants num: "
4789 << grants_num
<< dendl
;
4790 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
4791 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
4792 + std::to_string(max_num
)
4793 + " grants allowed in an acl.";
4797 // forward bucket acl requests to meta master zone
4798 if (s
->object
.empty() && !store
->is_meta_master()) {
4800 // include acl data unless it was generated from a canned_acl
4801 if (s
->canned_acl
.empty()) {
4802 in_data
.append(data
, len
);
4804 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4806 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4811 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4812 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4813 policy
->to_xml(*_dout
);
4817 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4821 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4822 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4823 new_policy
.to_xml(*_dout
);
4827 new_policy
.encode(bl
);
4828 map
<string
, bufferlist
> attrs
;
4830 if (!s
->object
.empty()) {
4831 obj
= rgw_obj(s
->bucket
, s
->object
);
4832 store
->set_atomic(s
->obj_ctx
, obj
);
4833 //if instance is empty, we should modify the latest object
4834 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4836 attrs
= s
->bucket_attrs
;
4837 attrs
[RGW_ATTR_ACL
] = bl
;
4838 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4840 if (op_ret
== -ECANCELED
) {
4841 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4845 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4847 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4848 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4849 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4850 oid
= lc_oid_prefix
;
4852 snprintf(buf
, 32, ".%d", index
);
4857 void RGWPutLC::execute()
4861 RGWLifecycleConfiguration_S3
*config
= NULL
;
4862 RGWLCXMLParser_S3
parser(s
->cct
);
4863 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4865 content_md5
= s
->info
.env
->get("HTTP_CONTENT_MD5");
4866 if (content_md5
== nullptr) {
4867 op_ret
= -ERR_INVALID_REQUEST
;
4868 s
->err
.message
= "Missing required header for this request: Content-MD5";
4869 ldout(s
->cct
, 5) << s
->err
.message
<< dendl
;
4873 std::string content_md5_bin
;
4875 content_md5_bin
= rgw::from_base64(boost::string_view(content_md5
));
4877 s
->err
.message
= "Request header Content-MD5 contains character "
4878 "that is not base64 encoded.";
4879 ldout(s
->cct
, 5) << s
->err
.message
<< dendl
;
4880 op_ret
= -ERR_BAD_DIGEST
;
4884 if (!parser
.init()) {
4889 op_ret
= get_params();
4893 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4896 unsigned char data_hash_res
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
4897 data_hash
.Update(reinterpret_cast<const byte
*>(data
), len
);
4898 data_hash
.Final(data_hash_res
);
4900 if (memcmp(data_hash_res
, content_md5_bin
.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE
) != 0) {
4901 op_ret
= -ERR_BAD_DIGEST
;
4902 s
->err
.message
= "The Content-MD5 you specified did not match what we received.";
4903 ldout(s
->cct
, 5) << s
->err
.message
4904 << " Specified content md5: " << content_md5
4905 << ", calculated content md5: " << data_hash_res
4910 if (!parser
.parse(data
, len
, 1)) {
4911 op_ret
= -ERR_MALFORMED_XML
;
4914 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4916 op_ret
= -ERR_MALFORMED_XML
;
4920 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4921 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4922 config
->to_xml(*_dout
);
4926 op_ret
= config
->rebuild(store
, new_config
);
4930 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4931 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4932 new_config
.to_xml(*_dout
);
4936 new_config
.encode(bl
);
4937 map
<string
, bufferlist
> attrs
;
4938 attrs
= s
->bucket_attrs
;
4939 attrs
[RGW_ATTR_LC
] = bl
;
4940 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4943 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4946 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4947 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4948 rados::cls::lock::Lock
l(lc_index_lock_name
);
4949 utime_t
time(max_lock_secs
, 0);
4950 l
.set_duration(time
);
4951 l
.set_cookie(cookie
);
4952 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4954 op_ret
= l
.lock_exclusive(ctx
, oid
);
4955 if (op_ret
== -EBUSY
) {
4956 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4961 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4964 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4966 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4974 void RGWDeleteLC::execute()
4977 map
<string
, bufferlist
> orig_attrs
, attrs
;
4978 map
<string
, bufferlist
>::iterator iter
;
4980 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4981 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4982 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4986 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4987 const string
& name
= iter
->first
;
4988 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
4989 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
4990 if (attrs
.find(name
) == attrs
.end()) {
4991 attrs
[name
] = iter
->second
;
4995 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4996 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4997 pair
<string
, int> entry(shard_id
, lc_uninitial
);
5000 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
5001 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
5002 rados::cls::lock::Lock
l(lc_index_lock_name
);
5003 utime_t
time(max_lock_secs
, 0);
5004 l
.set_duration(time
);
5006 op_ret
= l
.lock_exclusive(ctx
, oid
);
5007 if (op_ret
== -EBUSY
) {
5008 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
5013 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
5016 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
5018 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
5026 int RGWGetCORS::verify_permission()
5028 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketCORS
);
5031 void RGWGetCORS::execute()
5033 op_ret
= read_bucket_cors();
5038 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5044 int RGWPutCORS::verify_permission()
5046 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5049 void RGWPutCORS::execute()
5053 op_ret
= get_params();
5057 if (!store
->is_meta_master()) {
5058 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
5060 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5065 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5066 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
5067 attrs
[RGW_ATTR_CORS
] = cors_bl
;
5068 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5072 int RGWDeleteCORS::verify_permission()
5074 // No separate delete permission
5075 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5078 void RGWDeleteCORS::execute()
5080 op_ret
= read_bucket_cors();
5086 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5090 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5092 store
->get_bucket_instance_obj(s
->bucket
, obj
);
5093 store
->set_prefetch_data(s
->obj_ctx
, obj
);
5094 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
5095 map
<string
, bufferlist
>::iterator iter
;
5097 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
5101 /* only remove meta attrs */
5102 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
5103 const string
& name
= iter
->first
;
5104 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
5105 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
5106 rmattrs
[name
] = iter
->second
;
5107 } else if (attrs
.find(name
) == attrs
.end()) {
5108 attrs
[name
] = iter
->second
;
5111 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
5112 &s
->bucket_info
.objv_tracker
);
5116 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
5117 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
5120 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
5121 rule
= cc
->host_name_rule(origin
);
5123 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
5127 if (!validate_cors_rule_method(rule
, req_meth
)) {
5131 if (!validate_cors_rule_header(rule
, req_hdrs
)) {
5138 void RGWOptionsCORS::execute()
5140 op_ret
= read_bucket_cors();
5144 origin
= s
->info
.env
->get("HTTP_ORIGIN");
5147 "Preflight request without mandatory Origin header"
5152 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
5155 "Preflight request without mandatory Access-control-request-method header"
5161 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5165 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5166 op_ret
= validate_cors_request(&bucket_cors
);
5168 origin
= req_meth
= NULL
;
5174 int RGWGetRequestPayment::verify_permission()
5176 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketRequestPayment
);
5179 void RGWGetRequestPayment::pre_exec()
5181 rgw_bucket_object_pre_exec(s
);
5184 void RGWGetRequestPayment::execute()
5186 requester_pays
= s
->bucket_info
.requester_pays
;
5189 int RGWSetRequestPayment::verify_permission()
5191 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketRequestPayment
);
5194 void RGWSetRequestPayment::pre_exec()
5196 rgw_bucket_object_pre_exec(s
);
5199 void RGWSetRequestPayment::execute()
5201 op_ret
= get_params();
5206 s
->bucket_info
.requester_pays
= requester_pays
;
5207 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5210 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5211 << " returned err=" << op_ret
<< dendl
;
5216 int RGWInitMultipart::verify_permission()
5218 if (s
->iam_policy
) {
5219 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5220 rgw::IAM::s3PutObject
,
5221 rgw_obj(s
->bucket
, s
->object
));
5222 if (e
== Effect::Allow
) {
5224 } else if (e
== Effect::Deny
) {
5229 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5236 void RGWInitMultipart::pre_exec()
5238 rgw_bucket_object_pre_exec(s
);
5241 void RGWInitMultipart::execute()
5244 map
<string
, bufferlist
> attrs
;
5247 if (get_params() < 0)
5250 if (s
->object
.empty())
5253 policy
.encode(aclbl
);
5254 attrs
[RGW_ATTR_ACL
] = aclbl
;
5256 populate_with_generic_attrs(s
, attrs
);
5258 /* select encryption mode */
5259 op_ret
= prepare_encryption(attrs
);
5263 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5270 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5271 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5272 upload_id
.append(buf
);
5274 string tmp_obj_name
;
5275 RGWMPObj
mp(s
->object
.name
, upload_id
);
5276 tmp_obj_name
= mp
.get_meta();
5278 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5279 // the meta object will be indexed with 0 size, we c
5280 obj
.set_in_extra_data(true);
5281 obj
.index_hash_source
= s
->object
.name
;
5283 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5284 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5286 RGWRados::Object::Write
obj_op(&op_target
);
5288 obj_op
.meta
.owner
= s
->owner
.get_id();
5289 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5290 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5292 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5293 } while (op_ret
== -EEXIST
);
5296 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5298 RGWAccessControlPolicy
*policy
,
5299 map
<string
, bufferlist
>& attrs
)
5301 map
<string
, bufferlist
>::iterator iter
;
5305 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5306 obj
.set_in_extra_data(true);
5308 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5310 if (op_ret
== -ENOENT
) {
5311 return -ERR_NO_SUCH_UPLOAD
;
5317 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5318 string name
= iter
->first
;
5319 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5320 bufferlist
& bl
= iter
->second
;
5321 bufferlist::iterator bli
= bl
.begin();
5323 ::decode(*policy
, bli
);
5324 } catch (buffer::error
& err
) {
5325 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5336 int RGWCompleteMultipart::verify_permission()
5338 if (s
->iam_policy
) {
5339 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5340 rgw::IAM::s3PutObject
,
5341 rgw_obj(s
->bucket
, s
->object
));
5342 if (e
== Effect::Allow
) {
5344 } else if (e
== Effect::Deny
) {
5349 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5356 void RGWCompleteMultipart::pre_exec()
5358 rgw_bucket_object_pre_exec(s
);
5361 void RGWCompleteMultipart::execute()
5363 RGWMultiCompleteUpload
*parts
;
5364 map
<int, string
>::iterator iter
;
5365 RGWMultiXMLParser parser
;
5367 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5368 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5369 map
<string
, bufferlist
> attrs
;
5372 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5373 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5378 RGWObjManifest manifest
;
5379 uint64_t olh_epoch
= 0;
5382 op_ret
= get_params();
5385 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5390 if (!data
|| !len
) {
5391 op_ret
= -ERR_MALFORMED_XML
;
5395 if (!parser
.init()) {
5400 if (!parser
.parse(data
, len
, 1)) {
5401 op_ret
= -ERR_MALFORMED_XML
;
5405 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5406 if (!parts
|| parts
->parts
.empty()) {
5407 op_ret
= -ERR_MALFORMED_XML
;
5411 if ((int)parts
->parts
.size() >
5412 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5417 mp
.init(s
->object
.name
, upload_id
);
5418 meta_oid
= mp
.get_meta();
5420 int total_parts
= 0;
5421 int handled_parts
= 0;
5422 int max_parts
= 1000;
5425 RGWCompressionInfo cs_info
;
5426 bool compressed
= false;
5427 uint64_t accounted_size
= 0;
5429 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5431 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5433 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5435 iter
= parts
->parts
.begin();
5437 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5438 meta_obj
.set_in_extra_data(true);
5439 meta_obj
.index_hash_source
= s
->object
.name
;
5441 /*take a cls lock on meta_obj to prevent racing completions (or retries)
5442 from deleting the parts*/
5444 rgw_raw_obj raw_obj
;
5445 int max_lock_secs_mp
=
5446 s
->cct
->_conf
->get_val
<int64_t>("rgw_mp_lock_max_time");
5447 utime_t
dur(max_lock_secs_mp
, 0);
5449 store
->obj_to_raw((s
->bucket_info
).placement_rule
, meta_obj
, &raw_obj
);
5450 store
->get_obj_data_pool((s
->bucket_info
).placement_rule
,
5451 meta_obj
,&meta_pool
);
5452 store
->open_pool_ctx(meta_pool
, serializer
.ioctx
);
5454 op_ret
= serializer
.try_lock(raw_obj
.oid
, dur
);
5456 dout(0) << "RGWCompleteMultipart::execute() failed to acquire lock " << dendl
;
5457 op_ret
= -ERR_INTERNAL_ERROR
;
5458 s
->err
.message
= "This multipart completion is already in progress";
5462 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5465 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5466 << " ret=" << op_ret
<< dendl
;
5471 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5472 marker
, obj_parts
, &marker
, &truncated
);
5473 if (op_ret
== -ENOENT
) {
5474 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5479 total_parts
+= obj_parts
.size();
5480 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5481 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5482 << " expected: " << parts
->parts
.size() << dendl
;
5483 op_ret
= -ERR_INVALID_PART
;
5487 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5488 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5489 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5490 part_size
< min_part_size
) {
5491 op_ret
= -ERR_TOO_SMALL
;
5495 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5496 if (iter
->first
!= (int)obj_iter
->first
) {
5497 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5498 << iter
->first
<< " next uploaded: "
5499 << obj_iter
->first
<< dendl
;
5500 op_ret
= -ERR_INVALID_PART
;
5503 string part_etag
= rgw_string_unquote(iter
->second
);
5504 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5505 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5506 << " etag: " << iter
->second
<< dendl
;
5507 op_ret
= -ERR_INVALID_PART
;
5511 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5512 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5513 hash
.Update((const byte
*)petag
, sizeof(petag
));
5515 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5517 /* update manifest for part */
5518 string oid
= mp
.get_part(obj_iter
->second
.num
);
5520 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5522 if (obj_part
.manifest
.empty()) {
5523 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5524 << src_obj
<< dendl
;
5525 op_ret
= -ERR_INVALID_PART
;
5528 manifest
.append(obj_part
.manifest
, store
);
5531 if (obj_part
.cs_info
.compression_type
!= "none") {
5532 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5533 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5534 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5535 op_ret
= -ERR_INVALID_PART
;
5538 int64_t new_ofs
; // offset in compression data for new part
5539 if (cs_info
.blocks
.size() > 0)
5540 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5543 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5544 compression_block cb
;
5545 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5546 cb
.new_ofs
= new_ofs
;
5548 cs_info
.blocks
.push_back(cb
);
5549 new_ofs
= cb
.new_ofs
+ cb
.len
;
5552 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5553 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5557 rgw_obj_index_key remove_key
;
5558 src_obj
.key
.get_index_key(&remove_key
);
5560 remove_objs
.push_back(remove_key
);
5562 ofs
+= obj_part
.size
;
5563 accounted_size
+= obj_part
.accounted_size
;
5565 } while (truncated
);
5566 hash
.Final((byte
*)final_etag
);
5568 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5569 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5570 "-%lld", (long long)parts
->parts
.size());
5571 etag
= final_etag_str
;
5572 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5574 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5576 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5579 // write compression attribute to full object
5581 ::encode(cs_info
, tmp
);
5582 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5585 target_obj
.init(s
->bucket
, s
->object
.name
);
5586 if (versioned_object
) {
5587 store
->gen_rand_obj_instance_name(&target_obj
);
5590 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5592 obj_ctx
.obj
.set_atomic(target_obj
);
5594 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5595 RGWRados::Object::Write
obj_op(&op_target
);
5597 obj_op
.meta
.manifest
= &manifest
;
5598 obj_op
.meta
.remove_objs
= &remove_objs
;
5600 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5601 obj_op
.meta
.owner
= s
->owner
.get_id();
5602 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5603 obj_op
.meta
.modify_tail
= true;
5604 obj_op
.meta
.completeMultipart
= true;
5605 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5609 // remove the upload obj
5610 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5611 s
->bucket_info
, meta_obj
, 0);
5613 /* serializer's exclusive lock is released */
5614 serializer
.clear_locked();
5616 ldout(store
->ctx(), 0) << "WARNING: failed to remove object "
5617 << meta_obj
<< dendl
;
5621 int RGWCompleteMultipart::MPSerializer::try_lock(
5622 const std::string
& _oid
,
5627 lock
.set_duration(dur
);
5628 lock
.lock_exclusive(&op
);
5629 int ret
= ioctx
.operate(oid
, &op
);
5636 void RGWCompleteMultipart::complete()
5638 /* release exclusive lock iff not already */
5639 if (unlikely(serializer
.locked
)) {
5640 int r
= serializer
.unlock();
5642 ldout(store
->ctx(), 0) << "WARNING: failed to unlock "
5643 << serializer
.oid
<< dendl
;
5649 int RGWAbortMultipart::verify_permission()
5651 if (s
->iam_policy
) {
5652 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5653 rgw::IAM::s3AbortMultipartUpload
,
5654 rgw_obj(s
->bucket
, s
->object
));
5655 if (e
== Effect::Allow
) {
5657 } else if (e
== Effect::Deny
) {
5662 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5669 void RGWAbortMultipart::pre_exec()
5671 rgw_bucket_object_pre_exec(s
);
5674 void RGWAbortMultipart::execute()
5679 upload_id
= s
->info
.args
.get("uploadId");
5680 map
<string
, bufferlist
> attrs
;
5684 if (upload_id
.empty() || s
->object
.empty())
5687 mp
.init(s
->object
.name
, upload_id
);
5688 meta_oid
= mp
.get_meta();
5690 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5694 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5695 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5698 int RGWListMultipart::verify_permission()
5700 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5706 void RGWListMultipart::pre_exec()
5708 rgw_bucket_object_pre_exec(s
);
5711 void RGWListMultipart::execute()
5713 map
<string
, bufferlist
> xattrs
;
5717 op_ret
= get_params();
5721 mp
.init(s
->object
.name
, upload_id
);
5722 meta_oid
= mp
.get_meta();
5724 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5728 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5729 marker
, parts
, NULL
, &truncated
);
5732 int RGWListBucketMultiparts::verify_permission()
5734 if (!verify_bucket_permission(s
,
5735 rgw::IAM::s3ListBucketMultiPartUploads
))
5741 void RGWListBucketMultiparts::pre_exec()
5743 rgw_bucket_object_pre_exec(s
);
5746 void RGWListBucketMultiparts::execute()
5748 vector
<rgw_bucket_dir_entry
> objs
;
5751 op_ret
= get_params();
5755 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5757 path_args
= s
->info
.args
.get("path");
5758 if (!path_args
.empty()) {
5759 if (!delimiter
.empty() || !prefix
.empty()) {
5767 marker_meta
= marker
.get_meta();
5769 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5770 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5775 if (!objs
.empty()) {
5776 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5777 RGWMultipartUploadEntry entry
;
5778 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5779 rgw_obj_key
key(iter
->key
);
5780 if (!entry
.mp
.from_meta(key
.name
))
5783 uploads
.push_back(entry
);
5785 next_marker
= entry
;
5789 void RGWGetHealthCheck::execute()
5791 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5792 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5793 /* Disabling path specified & existent in the filesystem. */
5794 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5796 op_ret
= 0; /* 200 OK */
5800 int RGWDeleteMultiObj::verify_permission()
5802 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5803 if (!acl_allowed
&& !s
->iam_policy
)
5809 void RGWDeleteMultiObj::pre_exec()
5811 rgw_bucket_object_pre_exec(s
);
5814 void RGWDeleteMultiObj::execute()
5816 RGWMultiDelDelete
*multi_delete
;
5817 vector
<rgw_obj_key
>::iterator iter
;
5818 RGWMultiDelXMLParser parser
;
5819 int num_processed
= 0;
5820 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5822 op_ret
= get_params();
5832 if (!parser
.init()) {
5837 if (!parser
.parse(data
, len
, 1)) {
5842 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5843 if (!multi_delete
) {
5848 if (multi_delete
->is_quiet())
5852 if (multi_delete
->objects
.empty()) {
5856 for (iter
= multi_delete
->objects
.begin();
5857 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5858 ++iter
, num_processed
++) {
5859 rgw_obj
obj(bucket
, *iter
);
5860 if (s
->iam_policy
) {
5861 auto e
= s
->iam_policy
->eval(s
->env
,
5863 iter
->instance
.empty() ?
5864 rgw::IAM::s3DeleteObject
:
5865 rgw::IAM::s3DeleteObjectVersion
,
5867 if ((e
== Effect::Deny
) ||
5868 (e
== Effect::Pass
&& !acl_allowed
)) {
5869 send_partial_response(*iter
, false, "", -EACCES
);
5874 obj_ctx
->obj
.set_atomic(obj
);
5876 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5877 RGWRados::Object::Delete
del_op(&del_target
);
5879 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5880 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5881 del_op
.params
.obj_owner
= s
->owner
;
5883 op_ret
= del_op
.delete_obj();
5884 if (op_ret
== -ENOENT
) {
5888 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5889 del_op
.result
.version_id
, op_ret
);
5892 /* set the return code to zero, errors at this point will be
5893 dumped to the response */
5897 // will likely segfault if begin_response() has not been called
5909 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5910 map
<string
, bufferlist
>& battrs
,
5911 ACLOwner
& bucket_owner
/* out */)
5913 RGWAccessControlPolicy
bacl(store
->ctx());
5914 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5919 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5921 bucket_owner
= bacl
.get_owner();
5923 /* We can use global user_acl because each BulkDelete request is allowed
5924 * to work on entities from a single account only. */
5925 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5926 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5929 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5931 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5933 RGWBucketInfo binfo
;
5934 map
<string
, bufferlist
> battrs
;
5937 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5938 path
.bucket_name
, binfo
, nullptr,
5944 if (!verify_permission(binfo
, battrs
, bowner
)) {
5949 if (!path
.obj_key
.empty()) {
5950 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5951 obj_ctx
.obj
.set_atomic(obj
);
5953 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5954 RGWRados::Object::Delete
del_op(&del_target
);
5956 del_op
.params
.bucket_owner
= binfo
.owner
;
5957 del_op
.params
.versioning_status
= binfo
.versioning_status();
5958 del_op
.params
.obj_owner
= bowner
;
5960 ret
= del_op
.delete_obj();
5965 RGWObjVersionTracker ot
;
5966 ot
.read_version
= binfo
.ep_objv
;
5968 ret
= store
->delete_bucket(binfo
, ot
);
5970 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5971 binfo
.bucket
.name
, false);
5973 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
5981 if (!store
->is_meta_master()) {
5983 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
5986 if (ret
== -ENOENT
) {
5987 /* adjust error, we want to return with NoSuchBucket and not
5989 ret
= -ERR_NO_SUCH_BUCKET
;
6001 if (-ENOENT
== ret
) {
6002 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
6005 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
6008 fail_desc_t failed_item
= {
6012 failures
.push_back(failed_item
);
6017 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
6019 fail_desc_t failed_item
= {
6023 failures
.push_back(failed_item
);
6028 if (-ENOENT
== ret
) {
6029 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
6032 fail_desc_t failed_item
= {
6036 failures
.push_back(failed_item
);
6041 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
6043 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
6044 for (auto path
: paths
) {
6045 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
6046 delete_single(path
);
6052 int RGWBulkDelete::verify_permission()
6057 void RGWBulkDelete::pre_exec()
6059 rgw_bucket_object_pre_exec(s
);
6062 void RGWBulkDelete::execute()
6064 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
6066 bool is_truncated
= false;
6068 list
<RGWBulkDelete::acct_path_t
> items
;
6070 int ret
= get_data(items
, &is_truncated
);
6075 ret
= deleter
->delete_chunk(items
);
6076 } while (!op_ret
&& is_truncated
);
6082 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
6084 int RGWBulkUploadOp::verify_permission()
6086 if (s
->auth
.identity
->is_anonymous()) {
6090 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
6094 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
6095 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
6096 << " (user_id.tenant=" << s
->user
->user_id
.tenant
6097 << " requested=" << s
->bucket_tenant
<< ")"
6102 if (s
->user
->max_buckets
< 0) {
6109 void RGWBulkUploadOp::pre_exec()
6111 rgw_bucket_object_pre_exec(s
);
6114 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
6115 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
6117 /* We need to skip all slashes at the beginning in order to preserve
6118 * compliance with Swift. */
6119 const size_t start_pos
= path
.find_first_not_of('/');
6121 if (boost::string_ref::npos
!= start_pos
) {
6122 /* Seperator is the first slash after the leading ones. */
6123 const size_t sep_pos
= path
.substr(start_pos
).find('/');
6125 if (boost::string_ref::npos
!= sep_pos
) {
6126 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
6127 const auto obj_name
= path
.substr(sep_pos
+ 1);
6129 return std::make_pair(bucket_name
.to_string(),
6130 rgw_obj_key(obj_name
.to_string()));
6132 /* It's guaranteed here that bucket name is at least one character
6133 * long and is different than slash. */
6134 return std::make_pair(path
.substr(start_pos
).to_string(),
6142 std::pair
<std::string
, std::string
>
6143 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
6145 std::string bucket_path
, file_prefix
;
6146 if (! s
->init_state
.url_bucket
.empty()) {
6147 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
6148 if (! s
->object
.empty()) {
6149 std::string
& object_name
= s
->object
.name
;
6151 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
6152 * we can safely examine its last element. */
6153 if (object_name
.back() == '/') {
6154 file_prefix
.append(object_name
);
6156 file_prefix
.append(object_name
).append("/");
6160 return std::make_pair(bucket_path
, file_prefix
);
6163 int RGWBulkUploadOp::handle_dir_verify_permission()
6165 if (s
->user
->max_buckets
> 0) {
6166 RGWUserBuckets buckets
;
6168 bool is_truncated
= false;
6169 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
6170 marker
, std::string(), s
->user
->max_buckets
,
6171 false, &is_truncated
);
6176 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
6177 return -ERR_TOO_MANY_BUCKETS
;
6184 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
6186 /* the request of container or object level will contain bucket name.
6187 * only at account level need to append the bucket name */
6188 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
6192 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
6193 info
.script_uri
.append("/").append(bucket_name
);
6194 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
6195 info
.effective_uri
= "/" + bucket_name
;
6198 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
6200 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
6202 op_ret
= handle_dir_verify_permission();
6207 std::string bucket_name
;
6208 rgw_obj_key object_junk
;
6209 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
6211 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
6212 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
6214 /* we need to make sure we read bucket info, it's not read before for this
6215 * specific request */
6216 RGWBucketInfo binfo
;
6217 std::map
<std::string
, ceph::bufferlist
> battrs
;
6218 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6219 binfo
, NULL
, &battrs
);
6220 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6223 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6225 if (bucket_exists
) {
6226 RGWAccessControlPolicy
old_policy(s
->cct
);
6227 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6228 battrs
, &old_policy
);
6230 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6237 RGWBucketInfo master_info
;
6238 rgw_bucket
*pmaster_bucket
= nullptr;
6239 uint32_t *pmaster_num_shards
= nullptr;
6240 real_time creation_time
;
6241 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6243 if (! store
->is_meta_master()) {
6245 ceph::bufferlist in_data
;
6246 req_info info
= s
->info
;
6247 forward_req_info(s
->cct
, info
, bucket_name
);
6248 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6253 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6254 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6255 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6257 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
6258 << objv
.ver
<< dendl
;
6259 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
6262 pmaster_bucket
= &master_info
.bucket
;
6263 creation_time
= master_info
.creation_time
;
6264 pmaster_num_shards
= &master_info
.num_shards
;
6267 pmaster_bucket
= nullptr;
6268 pmaster_num_shards
= nullptr;
6272 std::string placement_rule
;
6273 if (bucket_exists
) {
6274 std::string selected_placement_rule
;
6276 bucket
.tenant
= s
->bucket_tenant
;
6277 bucket
.name
= s
->bucket_name
;
6278 op_ret
= store
->select_bucket_placement(*(s
->user
),
6279 store
->get_zonegroup().get_id(),
6281 &selected_placement_rule
,
6283 if (selected_placement_rule
!= binfo
.placement_rule
) {
6285 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6290 /* Create metadata: ACLs. */
6291 std::map
<std::string
, ceph::bufferlist
> attrs
;
6292 RGWAccessControlPolicy policy
;
6293 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6294 ceph::bufferlist aclbl
;
6295 policy
.encode(aclbl
);
6296 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6298 RGWQuotaInfo quota_info
;
6299 const RGWQuotaInfo
* pquota_info
= nullptr;
6302 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6303 bucket
.name
= bucket_name
;
6306 RGWBucketInfo out_info
;
6307 op_ret
= store
->create_bucket(*(s
->user
),
6309 store
->get_zonegroup().get_id(),
6310 placement_rule
, binfo
.swift_ver_location
,
6312 out_info
, pobjv
, &ep_objv
, creation_time
,
6313 pmaster_bucket
, pmaster_num_shards
, true);
6314 /* continue if EEXIST and create_bucket will fail below. this way we can
6315 * recover from a partial create by retrying it. */
6316 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6317 << ", bucket=" << bucket
<< dendl
;
6319 if (op_ret
&& op_ret
!= -EEXIST
) {
6323 const bool existed
= (op_ret
== -EEXIST
);
6325 /* bucket already existed, might have raced with another bucket creation, or
6326 * might be partial bucket creation that never completed. Read existing bucket
6327 * info, verify that the reported bucket owner is the current user.
6328 * If all is ok then update the user's list of buckets.
6329 * Otherwise inform client about a name conflict.
6331 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6333 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6336 bucket
= out_info
.bucket
;
6339 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6340 out_info
.creation_time
, false);
6341 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6342 /* if it exists (or previously existed), don't remove it! */
6343 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6344 bucket
.tenant
, bucket
.name
);
6346 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6349 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6350 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6352 op_ret
= -ERR_BUCKET_EXISTS
;
6359 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6361 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6362 ACLOwner
& bucket_owner
/* out */)
6364 RGWAccessControlPolicy
bacl(store
->ctx());
6365 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6367 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6372 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6374 bucket_owner
= bacl
.get_owner();
6376 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6377 rgw::IAM::s3PutObject
, obj
);
6378 if (e
== Effect::Allow
) {
6380 } else if (e
== Effect::Deny
) {
6385 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6386 &bacl
, RGW_PERM_WRITE
);
6389 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6391 AlignedStreamGetter
& body
)
6394 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6397 RGWPutObjDataProcessor
*filter
= nullptr;
6398 boost::optional
<RGWPutObj_Compress
> compressor
;
6400 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6401 op_ret
= -ERR_TOO_LARGE
;
6405 std::string bucket_name
;
6407 std::tie(bucket_name
, object
) = *parse_path(path
);
6409 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6410 RGWBucketInfo binfo
;
6411 std::map
<std::string
, ceph::bufferlist
> battrs
;
6413 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6414 bucket_name
, binfo
, nullptr, &battrs
);
6415 if (op_ret
== -ENOENT
) {
6416 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6418 } else if (op_ret
< 0) {
6422 if (! handle_file_verify_permission(binfo
,
6423 rgw_obj(binfo
.bucket
, object
),
6425 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6430 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6431 user_quota
, bucket_quota
, size
);
6436 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6441 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6446 s
->cct
->_conf
->rgw_obj_stripe_size
,
6448 binfo
.versioning_enabled());
6450 /* No filters by default. */
6451 filter
= &processor
;
6453 op_ret
= processor
.prepare(store
, nullptr);
6455 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6460 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6461 binfo
.placement_rule
);
6462 CompressorRef plugin
;
6463 if (compression_type
!= "none") {
6464 plugin
= Compressor::create(s
->cct
, compression_type
);
6466 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6467 << compression_type
<< dendl
;
6469 compressor
.emplace(s
->cct
, plugin
, filter
);
6470 filter
= &*compressor
;
6474 /* Upload file content. */
6479 ceph::bufferlist data
;
6480 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6482 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6486 } else if (len
> 0) {
6487 hash
.Update((const byte
*)data
.c_str(), data
.length());
6488 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6490 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6501 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6506 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6507 user_quota
, bucket_quota
, size
);
6509 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6514 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6519 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6520 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6522 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6524 /* Create metadata: ETAG. */
6525 std::map
<std::string
, ceph::bufferlist
> attrs
;
6526 std::string etag
= calc_md5
;
6527 ceph::bufferlist etag_bl
;
6528 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6529 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6531 /* Create metadata: ACLs. */
6532 RGWAccessControlPolicy policy
;
6533 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6534 ceph::bufferlist aclbl
;
6535 policy
.encode(aclbl
);
6536 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6538 /* Create metadata: compression info. */
6539 if (compressor
&& compressor
->is_compressed()) {
6540 ceph::bufferlist tmp
;
6541 RGWCompressionInfo cs_info
;
6542 cs_info
.compression_type
= plugin
->get_type_name();
6543 cs_info
.orig_size
= s
->obj_size
;
6544 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6545 ::encode(cs_info
, tmp
);
6546 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6549 /* Complete the transaction. */
6550 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6551 ceph::real_time() /* delete_at */);
6553 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6560 void RGWBulkUploadOp::execute()
6562 ceph::bufferlist
buffer(64 * 1024);
6564 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6566 /* Create an instance of stream-abstracting class. Having this indirection
6567 * allows for easy introduction of decompressors like gzip and bzip2. */
6568 auto stream
= create_stream();
6573 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6574 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6575 std::string bucket_path
, file_prefix
;
6576 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6578 auto status
= rgw::tar::StatusIndicator::create();
6580 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6582 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6586 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6587 * must be tracked to detect out end-of-archive. It occurs when both of
6588 * them are empty (zeroed). Tracing this particular inter-block dependency
6589 * is responsibility of the rgw::tar::StatusIndicator class. */
6590 boost::optional
<rgw::tar::HeaderView
> header
;
6591 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6593 if (! status
.empty() && header
) {
6594 /* This specific block isn't empty (entirely zeroed), so we can parse
6595 * it as a TAR header and dispatch. At the moment we do support only
6596 * regular files and directories. Everything else (symlinks, devices)
6597 * will be ignored but won't cease the whole upload. */
6598 switch (header
->get_filetype()) {
6599 case rgw::tar::FileType::NORMAL_FILE
: {
6600 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6602 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6603 file_prefix
+ header
->get_filename().to_string();
6604 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6605 rgw::tar::BLOCK_SIZE
, *stream
);
6606 op_ret
= handle_file(filename
,
6607 header
->get_filesize(),
6610 /* Only regular files counts. */
6613 failures
.emplace_back(op_ret
, filename
.to_string());
6617 case rgw::tar::FileType::DIRECTORY
: {
6618 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6620 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6621 op_ret
= handle_dir(dirname
);
6622 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6623 failures
.emplace_back(op_ret
, dirname
.to_string());
6628 /* Not recognized. Skip. */
6634 /* In case of any problems with sub-request authorization Swift simply
6635 * terminates whole upload immediately. */
6636 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6638 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6643 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6648 } while (! status
.eof());
6653 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6655 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6656 ceph::bufferlist junk
;
6658 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6661 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6662 ceph::bufferlist
& dst
)
6664 const size_t max_to_read
= std::min(want
, length
- position
);
6665 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6672 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6673 ceph::bufferlist
& dst
)
6675 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6682 int RGWSetAttrs::verify_permission()
6684 // This looks to be part of the RGW-NFS machinery and has no S3 or
6685 // Swift equivalent.
6687 if (!s
->object
.empty()) {
6688 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6690 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6698 void RGWSetAttrs::pre_exec()
6700 rgw_bucket_object_pre_exec(s
);
6703 void RGWSetAttrs::execute()
6705 op_ret
= get_params();
6709 rgw_obj
obj(s
->bucket
, s
->object
);
6711 if (!s
->object
.empty()) {
6712 store
->set_atomic(s
->obj_ctx
, obj
);
6713 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6715 for (auto& iter
: attrs
) {
6716 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6718 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6719 &s
->bucket_info
.objv_tracker
);
6723 void RGWGetObjLayout::pre_exec()
6725 rgw_bucket_object_pre_exec(s
);
6728 void RGWGetObjLayout::execute()
6730 rgw_obj
obj(s
->bucket
, s
->object
);
6731 RGWRados::Object
target(store
,
6733 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6734 rgw_obj(s
->bucket
, s
->object
));
6735 RGWRados::Object::Read
stat_op(&target
);
6737 op_ret
= stat_op
.prepare();
6742 head_obj
= stat_op
.state
.head_obj
;
6744 op_ret
= target
.get_manifest(&manifest
);
6748 int RGWConfigBucketMetaSearch::verify_permission()
6750 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6757 void RGWConfigBucketMetaSearch::pre_exec()
6759 rgw_bucket_object_pre_exec(s
);
6762 void RGWConfigBucketMetaSearch::execute()
6764 op_ret
= get_params();
6766 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6770 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6772 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6774 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6779 int RGWGetBucketMetaSearch::verify_permission()
6781 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6788 void RGWGetBucketMetaSearch::pre_exec()
6790 rgw_bucket_object_pre_exec(s
);
6793 int RGWDelBucketMetaSearch::verify_permission()
6795 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6802 void RGWDelBucketMetaSearch::pre_exec()
6804 rgw_bucket_object_pre_exec(s
);
6807 void RGWDelBucketMetaSearch::execute()
6809 s
->bucket_info
.mdsearch_config
.clear();
6811 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6813 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6819 RGWHandler::~RGWHandler()
6823 int RGWHandler::init(RGWRados
*_store
,
6824 struct req_state
*_s
,
6825 rgw::io::BasicClient
*cio
)
6833 int RGWHandler::do_init_permissions()
6835 int ret
= rgw_build_bucket_policies(store
, s
);
6836 s
->env
= rgw_build_iam_environment(store
, s
);
6839 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6840 if (ret
== -ENODATA
)
6847 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6850 /* already read bucket info */
6853 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6856 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6857 << s
->object
<< " only_bucket=" << only_bucket
6858 << " ret=" << ret
<< dendl
;
6859 if (ret
== -ENODATA
)
6866 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6867 return dialect_handler
->error_handler(err_no
, error_content
);
6870 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6871 // This is the do-nothing error handler
6876 void RGWPutBucketPolicy::send_response()
6879 set_req_state_err(s
, op_ret
);
6885 int RGWPutBucketPolicy::verify_permission()
6887 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6894 int RGWPutBucketPolicy::get_params()
6896 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6897 // At some point when I have more time I want to make a version of
6898 // rgw_rest_read_all_input that doesn't use malloc.
6899 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6900 // And throws exceptions.
6904 void RGWPutBucketPolicy::execute()
6906 op_ret
= get_params();
6911 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6913 if (!store
->is_meta_master()) {
6914 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6916 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6922 const Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6923 op_ret
= retry_raced_bucket_write(store
, s
, [&p
, this] {
6924 auto attrs
= s
->bucket_attrs
;
6925 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6926 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6927 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6928 &s
->bucket_info
.objv_tracker
);
6931 } catch (rgw::IAM::PolicyParseException
& e
) {
6932 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6937 void RGWGetBucketPolicy::send_response()
6940 set_req_state_err(s
, op_ret
);
6943 end_header(s
, this, "application/json");
6944 dump_body(s
, policy
);
6947 int RGWGetBucketPolicy::verify_permission()
6949 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6956 void RGWGetBucketPolicy::execute()
6958 auto attrs
= s
->bucket_attrs
;
6959 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6960 if (aiter
== attrs
.end()) {
6961 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6962 << " bucket_name = " << s
->bucket_name
<< dendl
;
6963 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6964 s
->err
.message
= "The bucket policy does not exist";
6967 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6969 if (policy
.length() == 0) {
6970 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6971 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6972 s
->err
.message
= "The bucket policy does not exist";
6978 void RGWDeleteBucketPolicy::send_response()
6981 set_req_state_err(s
, op_ret
);
6987 int RGWDeleteBucketPolicy::verify_permission()
6989 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
6996 void RGWDeleteBucketPolicy::execute()
6998 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
6999 auto attrs
= s
->bucket_attrs
;
7000 attrs
.erase(RGW_ATTR_IAM_POLICY
);
7001 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
7002 &s
->bucket_info
.objv_tracker
);