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
->local_source
||
499 (s
->op
!= OP_PUT
&& s
->op
!= OP_COPY
) ||
501 return -ERR_PERMANENT_REDIRECT
;
506 /* handle user ACL only for those APIs which support it */
508 map
<string
, bufferlist
> uattrs
;
510 ret
= rgw_get_user_attrs_by_uid(store
, acct_acl_user
.uid
, uattrs
);
512 ret
= get_user_policy_from_attr(s
->cct
, store
, uattrs
, *s
->user_acl
);
514 if (-ENOENT
== ret
) {
515 /* In already existing clusters users won't have ACL. In such case
516 * assuming that only account owner has the rights seems to be
517 * reasonable. That allows to have only one verification logic.
518 * NOTE: there is small compatibility kludge for global, empty tenant:
519 * 1. if we try to reach an existing bucket, its owner is considered
521 * 2. otherwise account owner is identity stored in s->user->user_id. */
522 s
->user_acl
->create_default(acct_acl_user
.uid
,
523 acct_acl_user
.display_name
);
526 ldout(s
->cct
, 0) << "NOTICE: couldn't get user attrs for handling ACL (user_id="
536 s
->iam_policy
= get_iam_policy_from_attr(s
->cct
, store
, s
->bucket_attrs
,
538 } catch (const std::exception
& e
) {
539 // Really this is a can't happen condition. We parse the policy
540 // when it's given to us, so perhaps we should abort or otherwise
541 // raise bloody murder.
542 lderr(s
->cct
) << "Error reading IAM Policy: " << e
.what() << dendl
;
550 * Get the AccessControlPolicy for a bucket or object off of disk.
551 * s: The req_state to draw information from.
552 * only_bucket: If true, reads the bucket ACL rather than the object ACL.
553 * Returns: 0 on success, -ERR# otherwise.
555 int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
560 if (!s
->object
.empty()) {
561 if (!s
->bucket_exists
) {
562 return -ERR_NO_SUCH_BUCKET
;
564 s
->object_acl
= ceph::make_unique
<RGWAccessControlPolicy
>(s
->cct
);
566 rgw_obj
obj(s
->bucket
, s
->object
);
568 store
->set_atomic(s
->obj_ctx
, obj
);
570 store
->set_prefetch_data(s
->obj_ctx
, obj
);
572 ret
= read_obj_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
,
573 s
->object_acl
.get(), s
->iam_policy
, s
->bucket
,
580 rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
583 rgw::IAM::Environment e
;
584 const auto& m
= s
->info
.env
->get_map();
585 auto t
= ceph::real_clock::now();
586 e
.emplace(std::piecewise_construct
,
587 std::forward_as_tuple("aws:CurrentTime"),
588 std::forward_as_tuple(std::to_string(
589 ceph::real_clock::to_time_t(t
))));
590 e
.emplace(std::piecewise_construct
,
591 std::forward_as_tuple("aws:EpochTime"),
592 std::forward_as_tuple(ceph::to_iso_8601(t
)));
593 // TODO: This is fine for now, but once we have STS we'll need to
594 // look and see. Also this won't work with the IdentityApplier
595 // model, since we need to know the actual credential.
596 e
.emplace(std::piecewise_construct
,
597 std::forward_as_tuple("aws:PrincipalType"),
598 std::forward_as_tuple("User"));
600 auto i
= m
.find("HTTP_REFERER");
602 e
.emplace(std::piecewise_construct
,
603 std::forward_as_tuple("aws:Referer"),
604 std::forward_as_tuple(i
->second
));
607 // These seem to be the semantics, judging from rest_rgw_s3.cc
608 i
= m
.find("SERVER_PORT_SECURE");
610 e
.emplace(std::piecewise_construct
,
611 std::forward_as_tuple("aws:SecureTransport"),
612 std::forward_as_tuple("true"));
615 i
= m
.find("HTTP_HOST");
617 e
.emplace(std::piecewise_construct
,
618 std::forward_as_tuple("aws:SourceIp"),
619 std::forward_as_tuple(i
->second
));
622 i
= m
.find("HTTP_USER_AGENT"); {
624 e
.emplace(std::piecewise_construct
,
625 std::forward_as_tuple("aws:UserAgent"),
626 std::forward_as_tuple(i
->second
));
630 // What to do about aws::userid? One can have multiple access
631 // keys so that isn't really suitable. Do we have a durable
632 // identifier that can persist through name changes?
633 e
.emplace(std::piecewise_construct
,
634 std::forward_as_tuple("aws:username"),
635 std::forward_as_tuple(s
->user
->user_id
.id
));
640 void rgw_bucket_object_pre_exec(struct req_state
*s
)
645 dump_bucket_from_state(s
);
648 int RGWGetObj::verify_permission()
650 obj
= rgw_obj(s
->bucket
, s
->object
);
651 store
->set_atomic(s
->obj_ctx
, obj
);
653 store
->set_prefetch_data(s
->obj_ctx
, obj
);
656 if (torrent
.get_flag()) {
657 if (obj
.key
.instance
.empty()) {
658 action
= rgw::IAM::s3GetObjectTorrent
;
660 action
= rgw::IAM::s3GetObjectVersionTorrent
;
663 if (obj
.key
.instance
.empty()) {
664 action
= rgw::IAM::s3GetObject
;
666 action
= rgw::IAM::s3GetObjectVersion
;
670 if (!verify_object_permission(s
, action
)) {
678 int RGWOp::verify_op_mask()
680 uint32_t required_mask
= op_mask();
682 ldout(s
->cct
, 20) << "required_mask= " << required_mask
683 << " user.op_mask=" << s
->user
->op_mask
<< dendl
;
685 if ((s
->user
->op_mask
& required_mask
) != required_mask
) {
689 if (!s
->system_request
&& (required_mask
& RGW_OP_TYPE_MODIFY
) && !store
->zone_is_writeable()) {
690 ldout(s
->cct
, 5) << "NOTICE: modify request to a read-only zone by a non-system user, permission denied" << dendl
;
697 int RGWGetObjTags::verify_permission()
699 if (!verify_object_permission(s
,
700 s
->object
.instance
.empty() ?
701 rgw::IAM::s3GetObjectTagging
:
702 rgw::IAM::s3GetObjectVersionTagging
))
708 void RGWGetObjTags::pre_exec()
710 rgw_bucket_object_pre_exec(s
);
713 void RGWGetObjTags::execute()
716 map
<string
,bufferlist
> attrs
;
718 obj
= rgw_obj(s
->bucket
, s
->object
);
720 store
->set_atomic(s
->obj_ctx
, obj
);
722 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
723 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
724 if(tags
!= attrs
.end()){
726 tags_bl
.append(tags
->second
);
728 send_response_data(tags_bl
);
731 int RGWPutObjTags::verify_permission()
733 if (!verify_object_permission(s
,
734 s
->object
.instance
.empty() ?
735 rgw::IAM::s3PutObjectTagging
:
736 rgw::IAM::s3PutObjectVersionTagging
))
741 void RGWPutObjTags::execute()
743 op_ret
= get_params();
747 if (s
->object
.empty()){
748 op_ret
= -EINVAL
; // we only support tagging on existing objects
753 obj
= rgw_obj(s
->bucket
, s
->object
);
754 store
->set_atomic(s
->obj_ctx
, obj
);
755 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_TAGS
, tags_bl
);
756 if (op_ret
== -ECANCELED
){
757 op_ret
= -ERR_TAG_CONFLICT
;
761 void RGWDeleteObjTags::pre_exec()
763 rgw_bucket_object_pre_exec(s
);
767 int RGWDeleteObjTags::verify_permission()
769 if (!s
->object
.empty()) {
770 if (!verify_object_permission(s
,
771 s
->object
.instance
.empty() ?
772 rgw::IAM::s3DeleteObjectTagging
:
773 rgw::IAM::s3DeleteObjectVersionTagging
))
779 void RGWDeleteObjTags::execute()
781 if (s
->object
.empty())
785 obj
= rgw_obj(s
->bucket
, s
->object
);
786 store
->set_atomic(s
->obj_ctx
, obj
);
787 map
<string
, bufferlist
> attrs
;
788 map
<string
, bufferlist
> rmattr
;
790 rmattr
[RGW_ATTR_TAGS
] = bl
;
791 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattr
);
794 int RGWOp::do_aws4_auth_completion()
796 ldout(s
->cct
, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl
;
797 if (s
->auth
.completer
) {
798 if (!s
->auth
.completer
->complete()) {
799 return -ERR_AMZ_CONTENT_SHA256_MISMATCH
;
801 dout(10) << "v4 auth ok -- do_aws4_auth_completion" << dendl
;
804 /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first
805 * call passes, so we disable second one. This is old behaviour, sorry!
806 * Plan for tomorrow: seek and destroy. */
807 s
->auth
.completer
= nullptr;
813 int RGWOp::init_quota()
815 /* no quota enforcement for system requests */
816 if (s
->system_request
)
819 /* init quota related stuff */
820 if (!(s
->user
->op_mask
& RGW_OP_TYPE_MODIFY
)) {
824 /* only interested in object related ops */
825 if (s
->object
.empty()) {
829 RGWUserInfo owner_info
;
832 if (s
->user
->user_id
== s
->bucket_owner
.get_id()) {
835 int r
= rgw_get_user_info_by_uid(store
, s
->bucket_info
.owner
, owner_info
);
841 if (s
->bucket_info
.quota
.enabled
) {
842 bucket_quota
= s
->bucket_info
.quota
;
843 } else if (uinfo
->bucket_quota
.enabled
) {
844 bucket_quota
= uinfo
->bucket_quota
;
846 bucket_quota
= store
->get_bucket_quota();
849 if (uinfo
->user_quota
.enabled
) {
850 user_quota
= uinfo
->user_quota
;
852 user_quota
= store
->get_user_quota();
858 static bool validate_cors_rule_method(RGWCORSRule
*rule
, const char *req_meth
) {
862 dout(5) << "req_meth is null" << dendl
;
866 if (strcmp(req_meth
, "GET") == 0) flags
= RGW_CORS_GET
;
867 else if (strcmp(req_meth
, "POST") == 0) flags
= RGW_CORS_POST
;
868 else if (strcmp(req_meth
, "PUT") == 0) flags
= RGW_CORS_PUT
;
869 else if (strcmp(req_meth
, "DELETE") == 0) flags
= RGW_CORS_DELETE
;
870 else if (strcmp(req_meth
, "HEAD") == 0) flags
= RGW_CORS_HEAD
;
872 if ((rule
->get_allowed_methods() & flags
) == flags
) {
873 dout(10) << "Method " << req_meth
<< " is supported" << dendl
;
875 dout(5) << "Method " << req_meth
<< " is not supported" << dendl
;
882 int RGWOp::read_bucket_cors()
886 map
<string
, bufferlist
>::iterator aiter
= s
->bucket_attrs
.find(RGW_ATTR_CORS
);
887 if (aiter
== s
->bucket_attrs
.end()) {
888 ldout(s
->cct
, 20) << "no CORS configuration attr found" << dendl
;
890 return 0; /* no CORS configuration found */
897 bufferlist::iterator iter
= bl
.begin();
899 bucket_cors
.decode(iter
);
900 } catch (buffer::error
& err
) {
901 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
904 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
905 RGWCORSConfiguration_S3
*s3cors
= static_cast<RGWCORSConfiguration_S3
*>(&bucket_cors
);
906 ldout(s
->cct
, 15) << "Read RGWCORSConfiguration";
907 s3cors
->to_xml(*_dout
);
914 * If any of the header field-names is not a ASCII case-insensitive match for
915 * any of the values in list of headers do not set any additional headers and
916 * terminate this set of steps.
918 static void get_cors_response_headers(RGWCORSRule
*rule
, const char *req_hdrs
, string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
921 get_str_list(req_hdrs
, hl
);
922 for(list
<string
>::iterator it
= hl
.begin(); it
!= hl
.end(); ++it
) {
923 if (!rule
->is_header_allowed((*it
).c_str(), (*it
).length())) {
924 dout(5) << "Header " << (*it
) << " is not registered in this rule" << dendl
;
926 if (hdrs
.length() > 0) hdrs
.append(",");
931 rule
->format_exp_headers(exp_hdrs
);
932 *max_age
= rule
->get_max_age();
936 * Generate the CORS header response
938 * This is described in the CORS standard, section 6.2.
940 bool RGWOp::generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
)
943 const char *orig
= s
->info
.env
->get("HTTP_ORIGIN");
950 op_ret
= read_bucket_cors();
956 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
961 RGWCORSRule
*rule
= bucket_cors
.host_name_rule(orig
);
966 * Set the Allowed-Origin header to a asterisk if this is allowed in the rule
967 * and no Authorization was send by the client
969 * The origin parameter specifies a URI that may access the resource. The browser must enforce this.
970 * For requests without credentials, the server may specify "*" as a wildcard,
971 * thereby allowing any origin to access the resource.
973 const char *authorization
= s
->info
.env
->get("HTTP_AUTHORIZATION");
974 if (!authorization
&& rule
->has_wildcard_origin())
978 const char *req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
980 req_meth
= s
->info
.method
;
986 if (!validate_cors_rule_method(rule
, req_meth
)) {
992 const char *req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
995 get_cors_response_headers(rule
, req_hdrs
, headers
, exp_headers
, max_age
);
1000 int RGWGetObj::read_user_manifest_part(rgw_bucket
& bucket
,
1001 const rgw_bucket_dir_entry
& ent
,
1002 RGWAccessControlPolicy
* const bucket_acl
,
1003 const optional
<Policy
>& bucket_policy
,
1004 const off_t start_ofs
,
1005 const off_t end_ofs
)
1007 ldout(s
->cct
, 20) << "user manifest obj=" << ent
.key
.name
<< "[" << ent
.key
.instance
<< "]" << dendl
;
1008 RGWGetObj_CB
cb(this);
1009 RGWGetDataCB
* filter
= &cb
;
1010 boost::optional
<RGWGetObj_Decompress
> decompress
;
1012 int64_t cur_ofs
= start_ofs
;
1013 int64_t cur_end
= end_ofs
;
1015 rgw_obj
part(bucket
, ent
.key
);
1017 map
<string
, bufferlist
> attrs
;
1020 RGWObjectCtx
obj_ctx(store
);
1021 RGWAccessControlPolicy
obj_policy(s
->cct
);
1023 ldout(s
->cct
, 20) << "reading obj=" << part
<< " ofs=" << cur_ofs
<< " end=" << cur_end
<< dendl
;
1025 obj_ctx
.obj
.set_atomic(part
);
1026 store
->set_prefetch_data(&obj_ctx
, part
);
1028 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, part
);
1029 RGWRados::Object::Read
read_op(&op_target
);
1031 read_op
.conds
.if_match
= ent
.meta
.etag
.c_str();
1032 read_op
.params
.attrs
= &attrs
;
1033 read_op
.params
.obj_size
= &obj_size
;
1035 op_ret
= read_op
.prepare();
1038 op_ret
= read_op
.range_to_ofs(ent
.meta
.accounted_size
, cur_ofs
, cur_end
);
1041 bool need_decompress
;
1042 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1044 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1048 if (need_decompress
)
1050 if (cs_info
.orig_size
!= ent
.meta
.accounted_size
) {
1051 // hmm.. something wrong, object not as expected, abort!
1052 ldout(s
->cct
, 0) << "ERROR: expected cs_info.orig_size=" << cs_info
.orig_size
<<
1053 ", actual read size=" << ent
.meta
.size
<< dendl
;
1056 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1057 filter
= &*decompress
;
1061 if (obj_size
!= ent
.meta
.size
) {
1062 // hmm.. something wrong, object not as expected, abort!
1063 ldout(s
->cct
, 0) << "ERROR: expected obj_size=" << obj_size
<< ", actual read size=" << ent
.meta
.size
<< dendl
;
1068 op_ret
= rgw_policy_from_attrset(s
->cct
, attrs
, &obj_policy
);
1072 /* We can use global user_acl because LOs cannot have segments
1073 * stored inside different accounts. */
1074 if (s
->system_request
) {
1075 ldout(s
->cct
, 2) << "overriding permissions due to system operation" << dendl
;
1076 } else if (s
->auth
.identity
->is_admin_of(s
->user
->user_id
)) {
1077 ldout(s
->cct
, 2) << "overriding permissions due to admin operation" << dendl
;
1078 } else if (!verify_object_permission(s
, part
, s
->user_acl
.get(), bucket_acl
,
1079 &obj_policy
, bucket_policy
, action
)) {
1083 if (ent
.meta
.size
== 0) {
1087 perfcounter
->inc(l_rgw_get_b
, cur_end
- cur_ofs
);
1088 filter
->fixup_range(cur_ofs
, cur_end
);
1089 op_ret
= read_op
.iterate(cur_ofs
, cur_end
, filter
);
1091 op_ret
= filter
->flush();
1095 static int iterate_user_manifest_parts(CephContext
* const cct
,
1096 RGWRados
* const store
,
1099 RGWBucketInfo
*pbucket_info
,
1100 const string
& obj_prefix
,
1101 RGWAccessControlPolicy
* const bucket_acl
,
1102 const optional
<Policy
>& bucket_policy
,
1103 uint64_t * const ptotal_len
,
1104 uint64_t * const pobj_size
,
1105 string
* const pobj_sum
,
1106 int (*cb
)(rgw_bucket
& bucket
,
1107 const rgw_bucket_dir_entry
& ent
,
1108 RGWAccessControlPolicy
* const bucket_acl
,
1109 const optional
<Policy
>& bucket_policy
,
1113 void * const cb_param
)
1115 rgw_bucket
& bucket
= pbucket_info
->bucket
;
1116 uint64_t obj_ofs
= 0, len_count
= 0;
1117 bool found_start
= false, found_end
= false, handled_end
= false;
1120 vector
<rgw_bucket_dir_entry
> objs
;
1122 utime_t start_time
= ceph_clock_now();
1124 RGWRados::Bucket
target(store
, *pbucket_info
);
1125 RGWRados::Bucket::List
list_op(&target
);
1127 list_op
.params
.prefix
= obj_prefix
;
1128 list_op
.params
.delim
= delim
;
1132 #define MAX_LIST_OBJS 100
1133 int r
= list_op
.list_objects(MAX_LIST_OBJS
, &objs
, NULL
, &is_truncated
);
1138 for (rgw_bucket_dir_entry
& ent
: objs
) {
1139 const uint64_t cur_total_len
= obj_ofs
;
1140 const uint64_t obj_size
= ent
.meta
.accounted_size
;
1141 uint64_t start_ofs
= 0, end_ofs
= obj_size
;
1143 if ((ptotal_len
|| cb
) && !found_start
&& cur_total_len
+ obj_size
> (uint64_t)ofs
) {
1144 start_ofs
= ofs
- obj_ofs
;
1148 obj_ofs
+= obj_size
;
1150 etag_sum
.Update((const byte
*)ent
.meta
.etag
.c_str(),
1151 ent
.meta
.etag
.length());
1154 if ((ptotal_len
|| cb
) && !found_end
&& obj_ofs
> (uint64_t)end
) {
1155 end_ofs
= end
- cur_total_len
+ 1;
1159 perfcounter
->tinc(l_rgw_get_lat
,
1160 (ceph_clock_now() - start_time
));
1162 if (found_start
&& !handled_end
) {
1163 len_count
+= end_ofs
- start_ofs
;
1166 r
= cb(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
, cb_param
);
1173 handled_end
= found_end
;
1174 start_time
= ceph_clock_now();
1176 } while (is_truncated
);
1179 *ptotal_len
= len_count
;
1182 *pobj_size
= obj_ofs
;
1185 complete_etag(etag_sum
, pobj_sum
);
1191 struct rgw_slo_part
{
1192 RGWAccessControlPolicy
*bucket_acl
= nullptr;
1193 Policy
* bucket_policy
= nullptr;
1200 static int iterate_slo_parts(CephContext
*cct
,
1204 map
<uint64_t, rgw_slo_part
>& slo_parts
,
1205 int (*cb
)(rgw_bucket
& bucket
,
1206 const rgw_bucket_dir_entry
& ent
,
1207 RGWAccessControlPolicy
*bucket_acl
,
1208 const optional
<Policy
>& bucket_policy
,
1214 bool found_start
= false, found_end
= false;
1216 if (slo_parts
.empty()) {
1220 utime_t start_time
= ceph_clock_now();
1222 map
<uint64_t, rgw_slo_part
>::iterator iter
= slo_parts
.upper_bound(ofs
);
1223 if (iter
!= slo_parts
.begin()) {
1227 uint64_t obj_ofs
= iter
->first
;
1229 for (; iter
!= slo_parts
.end() && !found_end
; ++iter
) {
1230 rgw_slo_part
& part
= iter
->second
;
1231 rgw_bucket_dir_entry ent
;
1233 ent
.key
.name
= part
.obj_name
;
1234 ent
.meta
.accounted_size
= ent
.meta
.size
= part
.size
;
1235 ent
.meta
.etag
= part
.etag
;
1237 uint64_t cur_total_len
= obj_ofs
;
1238 uint64_t start_ofs
= 0, end_ofs
= ent
.meta
.size
;
1240 if (!found_start
&& cur_total_len
+ ent
.meta
.size
> (uint64_t)ofs
) {
1241 start_ofs
= ofs
- obj_ofs
;
1245 obj_ofs
+= ent
.meta
.size
;
1247 if (!found_end
&& obj_ofs
> (uint64_t)end
) {
1248 end_ofs
= end
- cur_total_len
+ 1;
1252 perfcounter
->tinc(l_rgw_get_lat
,
1253 (ceph_clock_now() - start_time
));
1257 // SLO is a Swift thing, and Swift has no knowledge of S3 Policies.
1258 int r
= cb(part
.bucket
, ent
, part
.bucket_acl
,
1259 (part
.bucket_policy
?
1260 optional
<Policy
>(*part
.bucket_policy
) : none
),
1261 start_ofs
, end_ofs
, cb_param
);
1267 start_time
= ceph_clock_now();
1273 static int get_obj_user_manifest_iterate_cb(rgw_bucket
& bucket
,
1274 const rgw_bucket_dir_entry
& ent
,
1275 RGWAccessControlPolicy
* const bucket_acl
,
1276 const optional
<Policy
>& bucket_policy
,
1277 const off_t start_ofs
,
1278 const off_t end_ofs
,
1281 RGWGetObj
*op
= static_cast<RGWGetObj
*>(param
);
1282 return op
->read_user_manifest_part(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
);
1285 int RGWGetObj::handle_user_manifest(const char *prefix
)
1287 const boost::string_view
prefix_view(prefix
);
1288 ldout(s
->cct
, 2) << "RGWGetObj::handle_user_manifest() prefix="
1289 << prefix_view
<< dendl
;
1291 const size_t pos
= prefix_view
.find('/');
1292 if (pos
== string::npos
) {
1296 const std::string bucket_name
= url_decode(prefix_view
.substr(0, pos
));
1297 const std::string obj_prefix
= url_decode(prefix_view
.substr(pos
+ 1));
1301 RGWAccessControlPolicy
_bucket_acl(s
->cct
);
1302 RGWAccessControlPolicy
*bucket_acl
;
1303 optional
<Policy
> _bucket_policy
;
1304 optional
<Policy
>* bucket_policy
;
1305 RGWBucketInfo bucket_info
;
1306 RGWBucketInfo
*pbucket_info
;
1308 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1309 map
<string
, bufferlist
> bucket_attrs
;
1310 RGWObjectCtx
obj_ctx(store
);
1311 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1312 bucket_name
, bucket_info
, NULL
,
1315 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1316 << bucket_name
<< dendl
;
1319 bucket
= bucket_info
.bucket
;
1320 pbucket_info
= &bucket_info
;
1321 bucket_acl
= &_bucket_acl
;
1322 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
, bucket
);
1324 ldout(s
->cct
, 0) << "failed to read bucket policy" << dendl
;
1327 _bucket_policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
,
1328 bucket_info
.bucket
.tenant
);
1329 bucket_policy
= &_bucket_policy
;
1332 pbucket_info
= &s
->bucket_info
;
1333 bucket_acl
= s
->bucket_acl
.get();
1334 bucket_policy
= &s
->iam_policy
;
1337 /* dry run to find out:
1338 * - total length (of the parts we are going to send to client),
1339 * - overall DLO's content size,
1340 * - md5 sum of overall DLO's content (for etag of Swift API). */
1341 int r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1342 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1343 nullptr, &s
->obj_size
, &lo_etag
,
1344 nullptr /* cb */, nullptr /* cb arg */);
1349 r
= RGWRados::Object::Read::range_to_ofs(s
->obj_size
, ofs
, end
);
1354 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1355 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1356 &total_len
, nullptr, nullptr,
1364 send_response_data(bl
, 0, 0);
1368 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1369 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1370 nullptr, nullptr, nullptr,
1371 get_obj_user_manifest_iterate_cb
, (void *)this);
1378 send_response_data(bl
, 0, 0);
1384 int RGWGetObj::handle_slo_manifest(bufferlist
& bl
)
1386 RGWSLOInfo slo_info
;
1387 bufferlist::iterator bliter
= bl
.begin();
1389 ::decode(slo_info
, bliter
);
1390 } catch (buffer::error
& err
) {
1391 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
1394 ldout(s
->cct
, 2) << "RGWGetObj::handle_slo_manifest()" << dendl
;
1396 vector
<RGWAccessControlPolicy
> allocated_acls
;
1397 map
<string
, pair
<RGWAccessControlPolicy
*, optional
<Policy
>>> policies
;
1398 map
<string
, rgw_bucket
> buckets
;
1400 map
<uint64_t, rgw_slo_part
> slo_parts
;
1405 for (const auto& entry
: slo_info
.entries
) {
1406 const string
& path
= entry
.path
;
1408 /* If the path starts with slashes, strip them all. */
1409 const size_t pos_init
= path
.find_first_not_of('/');
1410 /* According to the documentation of std::string::find following check
1411 * is not necessary as we should get the std::string::npos propagation
1412 * here. This might be true with the accuracy to implementation's bugs.
1413 * See following question on SO:
1414 * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos
1416 if (pos_init
== string::npos
) {
1420 const size_t pos_sep
= path
.find('/', pos_init
);
1421 if (pos_sep
== string::npos
) {
1425 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
1426 string obj_name
= path
.substr(pos_sep
+ 1);
1429 RGWAccessControlPolicy
*bucket_acl
;
1430 Policy
* bucket_policy
;
1432 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1433 const auto& piter
= policies
.find(bucket_name
);
1434 if (piter
!= policies
.end()) {
1435 bucket_acl
= piter
->second
.first
;
1436 bucket_policy
= piter
->second
.second
.get_ptr();
1437 bucket
= buckets
[bucket_name
];
1439 allocated_acls
.push_back(RGWAccessControlPolicy(s
->cct
));
1440 RGWAccessControlPolicy
& _bucket_acl
= allocated_acls
.back();
1442 RGWBucketInfo bucket_info
;
1443 map
<string
, bufferlist
> bucket_attrs
;
1444 RGWObjectCtx
obj_ctx(store
);
1445 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1446 bucket_name
, bucket_info
, nullptr,
1449 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1450 << bucket_name
<< dendl
;
1453 bucket
= bucket_info
.bucket
;
1454 bucket_acl
= &_bucket_acl
;
1455 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
,
1458 ldout(s
->cct
, 0) << "failed to read bucket ACL for bucket "
1462 auto _bucket_policy
= get_iam_policy_from_attr(
1463 s
->cct
, store
, bucket_attrs
, bucket_info
.bucket
.tenant
);
1464 bucket_policy
= _bucket_policy
.get_ptr();
1465 buckets
[bucket_name
] = bucket
;
1466 policies
[bucket_name
] = make_pair(bucket_acl
, _bucket_policy
);
1470 bucket_acl
= s
->bucket_acl
.get();
1471 bucket_policy
= s
->iam_policy
.get_ptr();
1475 part
.bucket_acl
= bucket_acl
;
1476 part
.bucket_policy
= bucket_policy
;
1477 part
.bucket
= bucket
;
1478 part
.obj_name
= obj_name
;
1479 part
.size
= entry
.size_bytes
;
1480 part
.etag
= entry
.etag
;
1481 ldout(s
->cct
, 20) << "slo_part: ofs=" << ofs
1482 << " bucket=" << part
.bucket
1483 << " obj=" << part
.obj_name
1484 << " size=" << part
.size
1485 << " etag=" << part
.etag
1488 etag_sum
.Update((const byte
*)entry
.etag
.c_str(),
1489 entry
.etag
.length());
1491 slo_parts
[total_len
] = part
;
1492 total_len
+= part
.size
;
1495 complete_etag(etag_sum
, &lo_etag
);
1497 s
->obj_size
= slo_info
.total_size
;
1498 ldout(s
->cct
, 20) << "s->obj_size=" << s
->obj_size
<< dendl
;
1500 int r
= RGWRados::Object::Read::range_to_ofs(total_len
, ofs
, end
);
1505 total_len
= end
- ofs
+ 1;
1507 r
= iterate_slo_parts(s
->cct
, store
, ofs
, end
, slo_parts
,
1508 get_obj_user_manifest_iterate_cb
, (void *)this);
1516 int RGWGetObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
1518 /* garbage collection related handling */
1519 utime_t start_time
= ceph_clock_now();
1520 if (start_time
> gc_invalidate_time
) {
1521 int r
= store
->defer_gc(s
->obj_ctx
, s
->bucket_info
, obj
);
1523 dout(0) << "WARNING: could not defer gc entry for obj" << dendl
;
1525 gc_invalidate_time
= start_time
;
1526 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1528 return send_response_data(bl
, bl_ofs
, bl_len
);
1531 bool RGWGetObj::prefetch_data()
1533 /* HEAD request, stop prefetch*/
1538 bool prefetch_first_chunk
= true;
1539 range_str
= s
->info
.env
->get("HTTP_RANGE");
1542 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1543 /* error on parsing the range, stop prefetch and will fail in execte() */
1545 range_parsed
= false;
1548 range_parsed
= true;
1550 /* range get goes to shadown objects, stop prefetch */
1551 if (ofs
>= s
->cct
->_conf
->rgw_max_chunk_size
) {
1552 prefetch_first_chunk
= false;
1556 return get_data
&& prefetch_first_chunk
;
1558 void RGWGetObj::pre_exec()
1560 rgw_bucket_object_pre_exec(s
);
1563 static bool object_is_expired(map
<string
, bufferlist
>& attrs
) {
1564 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1565 if (iter
!= attrs
.end()) {
1568 ::decode(delete_at
, iter
->second
);
1569 } catch (buffer::error
& err
) {
1570 dout(0) << "ERROR: " << __func__
<< ": failed to decode " RGW_ATTR_DELETE_AT
" attr" << dendl
;
1574 if (delete_at
<= ceph_clock_now() && !delete_at
.is_zero()) {
1582 void RGWGetObj::execute()
1584 utime_t start_time
= s
->time
;
1586 gc_invalidate_time
= ceph_clock_now();
1587 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1589 bool need_decompress
;
1590 int64_t ofs_x
, end_x
;
1592 RGWGetObj_CB
cb(this);
1593 RGWGetDataCB
* filter
= (RGWGetDataCB
*)&cb
;
1594 boost::optional
<RGWGetObj_Decompress
> decompress
;
1595 std::unique_ptr
<RGWGetDataCB
> decrypt
;
1596 map
<string
, bufferlist
>::iterator attr_iter
;
1598 perfcounter
->inc(l_rgw_get
);
1600 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
1601 RGWRados::Object::Read
read_op(&op_target
);
1603 op_ret
= get_params();
1607 op_ret
= init_common();
1611 read_op
.conds
.mod_ptr
= mod_ptr
;
1612 read_op
.conds
.unmod_ptr
= unmod_ptr
;
1613 read_op
.conds
.high_precision_time
= s
->system_request
; /* system request need to use high precision time */
1614 read_op
.conds
.mod_zone_id
= mod_zone_id
;
1615 read_op
.conds
.mod_pg_ver
= mod_pg_ver
;
1616 read_op
.conds
.if_match
= if_match
;
1617 read_op
.conds
.if_nomatch
= if_nomatch
;
1618 read_op
.params
.attrs
= &attrs
;
1619 read_op
.params
.lastmod
= &lastmod
;
1620 read_op
.params
.obj_size
= &s
->obj_size
;
1622 op_ret
= read_op
.prepare();
1625 version_id
= read_op
.state
.obj
.key
.instance
;
1627 /* STAT ops don't need data, and do no i/o */
1628 if (get_type() == RGW_OP_STAT_OBJ
) {
1632 /* start gettorrent */
1633 if (torrent
.get_flag())
1635 torrent
.init(s
, store
);
1636 torrent
.get_torrent_file(op_ret
, read_op
, total_len
, bl
, obj
);
1639 ldout(s
->cct
, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
1643 op_ret
= send_response_data(bl
, 0, total_len
);
1646 ldout(s
->cct
, 0) << "ERROR: failed to send_response_data ret= " << op_ret
1652 /* end gettorrent */
1654 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1656 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1659 if (need_decompress
) {
1660 s
->obj_size
= cs_info
.orig_size
;
1661 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1662 filter
= &*decompress
;
1665 attr_iter
= attrs
.find(RGW_ATTR_USER_MANIFEST
);
1666 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1667 op_ret
= handle_user_manifest(attr_iter
->second
.c_str());
1669 ldout(s
->cct
, 0) << "ERROR: failed to handle user manifest ret="
1676 attr_iter
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
1677 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1679 op_ret
= handle_slo_manifest(attr_iter
->second
);
1681 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
1688 // for range requests with obj size 0
1689 if (range_str
&& !(s
->obj_size
)) {
1695 op_ret
= read_op
.range_to_ofs(s
->obj_size
, ofs
, end
);
1698 total_len
= (ofs
<= end
? end
+ 1 - ofs
: 0);
1700 /* Check whether the object has expired. Swift API documentation
1701 * stands that we should return 404 Not Found in such case. */
1702 if (need_object_expiration() && object_is_expired(attrs
)) {
1709 /* STAT ops don't need data, and do no i/o */
1710 if (get_type() == RGW_OP_STAT_OBJ
) {
1714 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1715 op_ret
= this->get_decrypt_filter(&decrypt
, filter
,
1716 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
1717 if (decrypt
!= nullptr) {
1718 filter
= decrypt
.get();
1724 if (!get_data
|| ofs
> end
) {
1725 send_response_data(bl
, 0, 0);
1729 perfcounter
->inc(l_rgw_get_b
, end
- ofs
);
1733 filter
->fixup_range(ofs_x
, end_x
);
1734 op_ret
= read_op
.iterate(ofs_x
, end_x
, filter
);
1737 op_ret
= filter
->flush();
1739 perfcounter
->tinc(l_rgw_get_lat
,
1740 (ceph_clock_now() - start_time
));
1745 op_ret
= send_response_data(bl
, 0, 0);
1752 send_response_data_error();
1755 int RGWGetObj::init_common()
1758 /* range parsed error when prefetch*/
1759 if (!range_parsed
) {
1760 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1766 if (parse_time(if_mod
, &mod_time
) < 0)
1768 mod_ptr
= &mod_time
;
1772 if (parse_time(if_unmod
, &unmod_time
) < 0)
1774 unmod_ptr
= &unmod_time
;
1780 int RGWListBuckets::verify_permission()
1782 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1789 int RGWGetUsage::verify_permission()
1791 if (s
->auth
.identity
->is_anonymous()) {
1798 void RGWListBuckets::execute()
1801 bool started
= false;
1802 uint64_t total_count
= 0;
1804 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1806 op_ret
= get_params();
1811 if (supports_account_metadata()) {
1812 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, attrs
);
1818 is_truncated
= false;
1820 RGWUserBuckets buckets
;
1821 uint64_t read_count
;
1823 read_count
= min(limit
- total_count
, (uint64_t)max_buckets
);
1825 read_count
= max_buckets
;
1828 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
1829 marker
, end_marker
, read_count
,
1830 should_get_stats(), &is_truncated
,
1833 /* hmm.. something wrong here.. the user was authenticated, so it
1835 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1836 << s
->user
->user_id
<< dendl
;
1839 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1840 map
<string
, RGWBucketEnt
>::iterator iter
;
1841 for (iter
= m
.begin(); iter
!= m
.end(); ++iter
) {
1842 RGWBucketEnt
& bucket
= iter
->second
;
1843 buckets_size
+= bucket
.size
;
1844 buckets_size_rounded
+= bucket
.size_rounded
;
1845 buckets_objcount
+= bucket
.count
;
1847 buckets_count
+= m
.size();
1848 total_count
+= m
.size();
1850 done
= (m
.size() < read_count
|| (limit
>= 0 && total_count
>= (uint64_t)limit
));
1853 send_response_begin(buckets
.count() > 0);
1858 send_response_data(buckets
);
1860 map
<string
, RGWBucketEnt
>::reverse_iterator riter
= m
.rbegin();
1861 marker
= riter
->first
;
1863 } while (is_truncated
&& !done
);
1867 send_response_begin(false);
1869 send_response_end();
1872 void RGWGetUsage::execute()
1874 uint64_t start_epoch
= 0;
1875 uint64_t end_epoch
= (uint64_t)-1;
1876 op_ret
= get_params();
1880 if (!start_date
.empty()) {
1881 op_ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
1883 ldout(store
->ctx(), 0) << "ERROR: failed to parse start date" << dendl
;
1888 if (!end_date
.empty()) {
1889 op_ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
1891 ldout(store
->ctx(), 0) << "ERROR: failed to parse end date" << dendl
;
1896 uint32_t max_entries
= 1000;
1898 bool is_truncated
= true;
1900 RGWUsageIter usage_iter
;
1902 while (is_truncated
) {
1903 op_ret
= store
->read_usage(s
->user
->user_id
, start_epoch
, end_epoch
, max_entries
,
1904 &is_truncated
, usage_iter
, usage
);
1906 if (op_ret
== -ENOENT
) {
1908 is_truncated
= false;
1916 op_ret
= rgw_user_sync_all_stats(store
, s
->user
->user_id
);
1918 ldout(store
->ctx(), 0) << "ERROR: failed to sync user stats: " << dendl
;
1922 op_ret
= rgw_user_get_all_buckets_stats(store
, s
->user
->user_id
, buckets_usage
);
1924 cerr
<< "ERROR: failed to sync user stats: " << std::endl
;
1928 string user_str
= s
->user
->user_id
.to_str();
1929 op_ret
= store
->cls_user_get_header(user_str
, &header
);
1931 ldout(store
->ctx(), 0) << "ERROR: can't read user header: " << dendl
;
1938 int RGWStatAccount::verify_permission()
1940 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1947 void RGWStatAccount::execute()
1950 bool is_truncated
= false;
1951 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1954 RGWUserBuckets buckets
;
1956 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
, marker
,
1957 string(), max_buckets
, true, &is_truncated
);
1959 /* hmm.. something wrong here.. the user was authenticated, so it
1961 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1962 << s
->user
->user_id
<< dendl
;
1965 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1966 map
<string
, RGWBucketEnt
>::iterator iter
;
1967 for (iter
= m
.begin(); iter
!= m
.end(); ++iter
) {
1968 RGWBucketEnt
& bucket
= iter
->second
;
1969 buckets_size
+= bucket
.size
;
1970 buckets_size_rounded
+= bucket
.size_rounded
;
1971 buckets_objcount
+= bucket
.count
;
1973 marker
= iter
->first
;
1975 buckets_count
+= m
.size();
1978 } while (is_truncated
);
1981 int RGWGetBucketVersioning::verify_permission()
1983 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
1990 void RGWGetBucketVersioning::pre_exec()
1992 rgw_bucket_object_pre_exec(s
);
1995 void RGWGetBucketVersioning::execute()
1997 versioned
= s
->bucket_info
.versioned();
1998 versioning_enabled
= s
->bucket_info
.versioning_enabled();
2001 int RGWSetBucketVersioning::verify_permission()
2003 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2010 void RGWSetBucketVersioning::pre_exec()
2012 rgw_bucket_object_pre_exec(s
);
2015 void RGWSetBucketVersioning::execute()
2017 op_ret
= get_params();
2021 if (!store
->is_meta_master()) {
2022 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2024 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
2029 if (enable_versioning
) {
2030 s
->bucket_info
.flags
|= BUCKET_VERSIONED
;
2031 s
->bucket_info
.flags
&= ~BUCKET_VERSIONS_SUSPENDED
;
2033 s
->bucket_info
.flags
|= (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
);
2036 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
2039 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2040 << " returned err=" << op_ret
<< dendl
;
2045 int RGWGetBucketWebsite::verify_permission()
2047 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2053 void RGWGetBucketWebsite::pre_exec()
2055 rgw_bucket_object_pre_exec(s
);
2058 void RGWGetBucketWebsite::execute()
2060 if (!s
->bucket_info
.has_website
) {
2065 int RGWSetBucketWebsite::verify_permission()
2067 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2073 void RGWSetBucketWebsite::pre_exec()
2075 rgw_bucket_object_pre_exec(s
);
2078 void RGWSetBucketWebsite::execute()
2080 op_ret
= get_params();
2085 if (!store
->is_meta_master()) {
2086 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2088 ldout(s
->cct
, 20) << __func__
<< " forward_request_to_master returned ret=" << op_ret
<< dendl
;
2093 s
->bucket_info
.has_website
= true;
2094 s
->bucket_info
.website_conf
= website_conf
;
2096 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
2098 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2103 int RGWDeleteBucketWebsite::verify_permission()
2105 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2111 void RGWDeleteBucketWebsite::pre_exec()
2113 rgw_bucket_object_pre_exec(s
);
2116 void RGWDeleteBucketWebsite::execute()
2118 s
->bucket_info
.has_website
= false;
2119 s
->bucket_info
.website_conf
= RGWBucketWebsiteConf();
2121 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
2123 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2128 int RGWStatBucket::verify_permission()
2130 // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission.
2131 if (!verify_bucket_permission(s
, rgw::IAM::s3ListBucket
)) {
2138 void RGWStatBucket::pre_exec()
2140 rgw_bucket_object_pre_exec(s
);
2143 void RGWStatBucket::execute()
2145 if (!s
->bucket_exists
) {
2146 op_ret
= -ERR_NO_SUCH_BUCKET
;
2150 RGWUserBuckets buckets
;
2151 bucket
.bucket
= s
->bucket
;
2152 buckets
.add(bucket
);
2153 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2154 op_ret
= store
->update_containers_stats(m
);
2159 map
<string
, RGWBucketEnt
>::iterator iter
= m
.find(bucket
.bucket
.name
);
2160 if (iter
!= m
.end()) {
2161 bucket
= iter
->second
;
2168 int RGWListBucket::verify_permission()
2170 op_ret
= get_params();
2175 if (!verify_bucket_permission(s
,
2177 rgw::IAM::s3ListBucketVersions
:
2178 rgw::IAM::s3ListBucket
)) {
2185 int RGWListBucket::parse_max_keys()
2187 if (!max_keys
.empty()) {
2189 max
= strtol(max_keys
.c_str(), &endptr
, 10);
2191 while (*endptr
&& isspace(*endptr
)) // ignore white space
2204 void RGWListBucket::pre_exec()
2206 rgw_bucket_object_pre_exec(s
);
2209 void RGWListBucket::execute()
2211 if (!s
->bucket_exists
) {
2212 op_ret
= -ERR_NO_SUCH_BUCKET
;
2216 if (need_container_stats()) {
2217 map
<string
, RGWBucketEnt
> m
;
2218 m
[s
->bucket
.name
] = RGWBucketEnt();
2219 m
.begin()->second
.bucket
= s
->bucket
;
2220 op_ret
= store
->update_containers_stats(m
);
2222 bucket
= m
.begin()->second
;
2226 RGWRados::Bucket
target(store
, s
->bucket_info
);
2227 if (shard_id
>= 0) {
2228 target
.set_shard_id(shard_id
);
2230 RGWRados::Bucket::List
list_op(&target
);
2232 list_op
.params
.prefix
= prefix
;
2233 list_op
.params
.delim
= delimiter
;
2234 list_op
.params
.marker
= marker
;
2235 list_op
.params
.end_marker
= end_marker
;
2236 list_op
.params
.list_versions
= list_versions
;
2238 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2240 next_marker
= list_op
.get_next_marker();
2244 int RGWGetBucketLogging::verify_permission()
2246 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2253 int RGWGetBucketLocation::verify_permission()
2255 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2262 int RGWCreateBucket::verify_permission()
2264 /* This check is mostly needed for S3 that doesn't support account ACL.
2265 * Swift doesn't allow to delegate any permission to an anonymous user,
2266 * so it will become an early exit in such case. */
2267 if (s
->auth
.identity
->is_anonymous()) {
2271 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
2275 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2276 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
2277 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2278 << " requested=" << s
->bucket_tenant
<< ")"
2282 if (s
->user
->max_buckets
< 0) {
2286 if (s
->user
->max_buckets
) {
2287 RGWUserBuckets buckets
;
2289 bool is_truncated
= false;
2290 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2291 marker
, string(), s
->user
->max_buckets
,
2292 false, &is_truncated
);
2297 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2298 return -ERR_TOO_MANY_BUCKETS
;
2305 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2306 RGWRados
*store
, bufferlist
& in_data
,
2307 JSONParser
*jp
, req_info
*forward_info
)
2309 if (!store
->rest_master_conn
) {
2310 ldout(s
->cct
, 0) << "rest connection is invalid" << dendl
;
2313 ldout(s
->cct
, 0) << "sending request to master zonegroup" << dendl
;
2314 bufferlist response
;
2315 string uid_str
= s
->user
->user_id
.to_str();
2316 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2317 int ret
= store
->rest_master_conn
->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2318 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2322 ldout(s
->cct
, 20) << "response: " << response
.c_str() << dendl
;
2323 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2324 ldout(s
->cct
, 0) << "failed parsing response from master zonegroup" << dendl
;
2331 void RGWCreateBucket::pre_exec()
2333 rgw_bucket_object_pre_exec(s
);
2336 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2337 map
<string
, bufferlist
>& out_attrs
,
2338 map
<string
, bufferlist
>& out_rmattrs
)
2340 for (const auto& kv
: orig_attrs
) {
2341 const string
& name
= kv
.first
;
2343 /* Check if the attr is user-defined metadata item. */
2344 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2345 RGW_ATTR_META_PREFIX
) == 0) {
2346 /* For the objects all existing meta attrs have to be removed. */
2347 out_rmattrs
[name
] = kv
.second
;
2348 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2349 out_attrs
[name
] = kv
.second
;
2354 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2355 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2356 * @out_attrs. Place results in @out_attrs.
2358 * NOTE: it's supposed that all special attrs already present in @out_attrs
2359 * will be preserved without any change. Special attributes are those which
2360 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2361 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2362 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2363 const set
<string
>& rmattr_names
,
2364 map
<string
, bufferlist
>& out_attrs
)
2366 for (const auto& kv
: orig_attrs
) {
2367 const string
& name
= kv
.first
;
2369 /* Check if the attr is user-defined metadata item. */
2370 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2371 RGW_ATTR_META_PREFIX
) == 0) {
2372 /* For the buckets all existing meta attrs are preserved,
2373 except those that are listed in rmattr_names. */
2374 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2375 const auto aiter
= out_attrs
.find(name
);
2377 if (aiter
!= std::end(out_attrs
)) {
2378 out_attrs
.erase(aiter
);
2381 /* emplace() won't alter the map if the key is already present.
2382 * This behaviour is fully intensional here. */
2383 out_attrs
.emplace(kv
);
2385 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2386 out_attrs
[name
] = kv
.second
;
2392 static void populate_with_generic_attrs(const req_state
* const s
,
2393 map
<string
, bufferlist
>& out_attrs
)
2395 for (const auto& kv
: s
->generic_attrs
) {
2396 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2397 const string
& val
= kv
.second
;
2399 attrbl
.append(val
.c_str(), val
.size() + 1);
2404 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2405 const std::set
<std::string
>& rmattr_names
,
2406 RGWQuotaInfo
& quota
,
2407 bool * quota_extracted
= nullptr)
2409 bool extracted
= false;
2411 /* Put new limit on max objects. */
2412 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2414 if (std::end(add_attrs
) != iter
) {
2416 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2420 add_attrs
.erase(iter
);
2424 /* Put new limit on bucket (container) size. */
2425 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2426 if (iter
!= add_attrs
.end()) {
2428 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2432 add_attrs
.erase(iter
);
2436 for (const auto& name
: rmattr_names
) {
2437 /* Remove limit on max objects. */
2438 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2439 quota
.max_objects
= -1;
2443 /* Remove limit on max bucket size. */
2444 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2445 quota
.max_size
= -1;
2450 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2451 quota
.check_on_raw
= true;
2452 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2454 if (quota_extracted
) {
2455 *quota_extracted
= extracted
;
2462 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2463 const std::set
<std::string
>& rmattr_names
,
2464 RGWBucketWebsiteConf
& ws_conf
)
2468 /* Let's define a mapping between each custom attribute and the memory where
2469 * attribute's value should be stored. The memory location is expressed by
2470 * a non-const reference. */
2471 const auto mapping
= {
2472 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2473 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2474 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2475 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2476 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2479 for (const auto& kv
: mapping
) {
2480 const char * const key
= kv
.first
;
2481 auto& target
= kv
.second
;
2483 auto iter
= add_attrs
.find(key
);
2485 if (std::end(add_attrs
) != iter
) {
2486 /* The "target" is a reference to ws_conf. */
2487 target
= iter
->second
.c_str();
2488 add_attrs
.erase(iter
);
2491 if (rmattr_names
.count(key
)) {
2492 target
= std::string();
2496 if (! lstval
.empty()) {
2497 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2502 void RGWCreateBucket::execute()
2504 RGWAccessControlPolicy
old_policy(s
->cct
);
2506 buffer::list corsbl
;
2509 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2510 rgw_raw_obj
obj(store
->get_zone_params().domain_root
, bucket_name
);
2511 obj_version objv
, *pobjv
= NULL
;
2513 op_ret
= get_params();
2517 if (!location_constraint
.empty() &&
2518 !store
->has_zonegroup_api(location_constraint
)) {
2519 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2520 << " can't be found." << dendl
;
2521 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2522 s
->err
.message
= "The specified location-constraint is not valid";
2526 if (!store
->get_zonegroup().is_master_zonegroup() &&
2527 store
->get_zonegroup().api_name
!= location_constraint
) {
2528 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2529 << " doesn't match zonegroup" << " (" << store
->get_zonegroup().api_name
<< ")"
2531 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2532 s
->err
.message
= "The specified location-constraint is not valid";
2536 const auto& zonegroup
= store
->get_zonegroup();
2537 if (!placement_rule
.empty() &&
2538 !zonegroup
.placement_targets
.count(placement_rule
)) {
2539 ldout(s
->cct
, 0) << "placement target (" << placement_rule
<< ")"
2540 << " doesn't exist in the placement targets of zonegroup"
2541 << " (" << store
->get_zonegroup().api_name
<< ")" << dendl
;
2542 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2543 s
->err
.message
= "The specified placement target does not exist";
2547 /* we need to make sure we read bucket info, it's not read before for this
2548 * specific request */
2549 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2550 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2551 s
->bucket_info
, NULL
, &s
->bucket_attrs
);
2552 if (op_ret
< 0 && op_ret
!= -ENOENT
)
2554 s
->bucket_exists
= (op_ret
!= -ENOENT
);
2556 s
->bucket_owner
.set_id(s
->user
->user_id
);
2557 s
->bucket_owner
.set_name(s
->user
->display_name
);
2558 if (s
->bucket_exists
) {
2559 int r
= get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
2560 s
->bucket_attrs
, &old_policy
);
2562 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
2569 RGWBucketInfo master_info
;
2570 rgw_bucket
*pmaster_bucket
;
2571 uint32_t *pmaster_num_shards
;
2572 real_time creation_time
;
2574 if (!store
->is_meta_master()) {
2576 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
2581 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
2582 JSONDecoder::decode_json("object_ver", objv
, &jp
);
2583 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
2584 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
2585 ldout(s
->cct
, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
2586 pmaster_bucket
= &master_info
.bucket
;
2587 creation_time
= master_info
.creation_time
;
2588 pmaster_num_shards
= &master_info
.num_shards
;
2591 pmaster_bucket
= NULL
;
2592 pmaster_num_shards
= NULL
;
2595 string zonegroup_id
;
2597 if (s
->system_request
) {
2598 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
2599 if (zonegroup_id
.empty()) {
2600 zonegroup_id
= store
->get_zonegroup().get_id();
2603 zonegroup_id
= store
->get_zonegroup().get_id();
2606 if (s
->bucket_exists
) {
2607 string selected_placement_rule
;
2609 bucket
.tenant
= s
->bucket_tenant
;
2610 bucket
.name
= s
->bucket_name
;
2611 op_ret
= store
->select_bucket_placement(*(s
->user
), zonegroup_id
,
2613 &selected_placement_rule
, nullptr);
2614 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
2620 /* Encode special metadata first as we're using std::map::emplace under
2621 * the hood. This method will add the new items only if the map doesn't
2622 * contain such keys yet. */
2623 policy
.encode(aclbl
);
2624 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
2627 cors_config
.encode(corsbl
);
2628 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
2631 RGWQuotaInfo quota_info
;
2632 const RGWQuotaInfo
* pquota_info
= nullptr;
2633 if (need_metadata_upload()) {
2634 /* It's supposed that following functions WILL NOT change any special
2635 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
2636 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2637 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2638 populate_with_generic_attrs(s
, attrs
);
2640 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
2644 pquota_info
= "a_info
;
2647 /* Web site of Swift API. */
2648 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2649 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2652 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
2653 s
->bucket
.name
= s
->bucket_name
;
2655 /* Handle updates of the metadata for Swift's object versioning. */
2656 if (swift_ver_location
) {
2657 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2658 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2661 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
2662 placement_rule
, s
->bucket_info
.swift_ver_location
,
2664 info
, pobjv
, &ep_objv
, creation_time
,
2665 pmaster_bucket
, pmaster_num_shards
, true);
2666 /* continue if EEXIST and create_bucket will fail below. this way we can
2667 * recover from a partial create by retrying it. */
2668 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
2670 if (op_ret
&& op_ret
!= -EEXIST
)
2673 existed
= (op_ret
== -EEXIST
);
2676 /* bucket already existed, might have raced with another bucket creation, or
2677 * might be partial bucket creation that never completed. Read existing bucket
2678 * info, verify that the reported bucket owner is the current user.
2679 * If all is ok then update the user's list of buckets.
2680 * Otherwise inform client about a name conflict.
2682 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
2686 s
->bucket
= info
.bucket
;
2689 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
2690 info
.creation_time
, false);
2691 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
2692 /* if it exists (or previously existed), don't remove it! */
2693 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2696 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2699 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
2700 op_ret
= -ERR_BUCKET_EXISTS
;
2703 if (need_metadata_upload() && existed
) {
2704 /* OK, it looks we lost race with another request. As it's required to
2705 * handle metadata fusion and upload, the whole operation becomes very
2706 * similar in nature to PutMetadataBucket. However, as the attrs may
2707 * changed in the meantime, we have to refresh. */
2710 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2711 RGWBucketInfo binfo
;
2712 map
<string
, bufferlist
> battrs
;
2714 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2715 binfo
, nullptr, &battrs
);
2718 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
2719 /* New bucket doesn't belong to the account we're operating on. */
2723 s
->bucket_info
= binfo
;
2724 s
->bucket_attrs
= battrs
;
2729 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2730 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2731 populate_with_generic_attrs(s
, attrs
);
2732 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
2737 /* Handle updates of the metadata for Swift's object versioning. */
2738 if (swift_ver_location
) {
2739 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2740 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2743 /* Web site of Swift API. */
2744 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2745 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2747 /* This will also set the quota on the bucket. */
2748 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
2749 &s
->bucket_info
.objv_tracker
);
2750 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
2752 /* Restore the proper return code. */
2754 op_ret
= -ERR_BUCKET_EXISTS
;
2759 int RGWDeleteBucket::verify_permission()
2761 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucket
)) {
2768 void RGWDeleteBucket::pre_exec()
2770 rgw_bucket_object_pre_exec(s
);
2773 void RGWDeleteBucket::execute()
2777 if (s
->bucket_name
.empty())
2780 if (!s
->bucket_exists
) {
2781 ldout(s
->cct
, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
2782 op_ret
= -ERR_NO_SUCH_BUCKET
;
2785 RGWObjVersionTracker ot
;
2786 ot
.read_version
= s
->bucket_info
.ep_objv
;
2788 if (s
->system_request
) {
2789 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
2790 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
2792 ot
.read_version
.tag
= tag
;
2795 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
2797 ldout(s
->cct
, 0) << "failed to parse ver param" << dendl
;
2801 ot
.read_version
.ver
= ver
;
2805 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
2807 ldout(s
->cct
, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
2810 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
2815 if (!store
->is_meta_master()) {
2817 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
2820 if (op_ret
== -ENOENT
) {
2821 /* adjust error, we want to return with NoSuchBucket and not
2823 op_ret
= -ERR_NO_SUCH_BUCKET
;
2829 string prefix
, delimiter
;
2831 if (s
->prot_flags
& RGW_REST_SWIFT
) {
2833 path_args
= s
->info
.args
.get("path");
2834 if (!path_args
.empty()) {
2835 if (!delimiter
.empty() || !prefix
.empty()) {
2844 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
2850 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
2852 if (op_ret
== -ECANCELED
) {
2853 // lost a race, either with mdlog sync or another delete bucket operation.
2854 // in either case, we've already called rgw_unlink_bucket()
2860 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2861 s
->bucket
.name
, false);
2863 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2875 int RGWPutObj::verify_permission()
2879 RGWAccessControlPolicy
cs_acl(s
->cct
);
2880 optional
<Policy
> policy
;
2881 map
<string
, bufferlist
> cs_attrs
;
2882 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
2883 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
2885 rgw_obj
obj(cs_bucket
, cs_object
);
2886 store
->set_atomic(s
->obj_ctx
, obj
);
2887 store
->set_prefetch_data(s
->obj_ctx
, obj
);
2889 /* check source object permissions */
2890 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
, policy
,
2891 cs_bucket
, cs_object
) < 0) {
2895 /* admin request overrides permission checks */
2896 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
2898 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
2899 cs_object
.instance
.empty() ?
2900 rgw::IAM::s3GetObject
:
2901 rgw::IAM::s3GetObjectVersion
,
2902 rgw::IAM::ARN(obj
));
2903 if (e
== Effect::Deny
) {
2905 } else if (e
== Effect::Pass
&&
2906 !cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2910 } else if (!cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2917 if (s
->iam_policy
) {
2918 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
2919 rgw::IAM::s3PutObject
,
2920 rgw_obj(s
->bucket
, s
->object
));
2921 if (e
== Effect::Allow
) {
2923 } else if (e
== Effect::Deny
) {
2928 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
2935 void RGWPutObjProcessor_Multipart::get_mp(RGWMPObj
** _mp
){
2939 int RGWPutObjProcessor_Multipart::prepare(RGWRados
*store
, string
*oid_rand
)
2941 string oid
= obj_str
;
2942 upload_id
= s
->info
.args
.get("uploadId");
2944 mp
.init(oid
, upload_id
);
2946 mp
.init(oid
, upload_id
, *oid_rand
);
2949 part_num
= s
->info
.args
.get("partNumber");
2950 if (part_num
.empty()) {
2951 ldout(s
->cct
, 10) << "part number is empty" << dendl
;
2956 uint64_t num
= (uint64_t)strict_strtol(part_num
.c_str(), 10, &err
);
2959 ldout(s
->cct
, 10) << "bad part number: " << part_num
<< ": " << err
<< dendl
;
2963 string upload_prefix
= oid
+ ".";
2966 upload_prefix
.append(upload_id
);
2968 upload_prefix
.append(*oid_rand
);
2972 target_obj
.init(bucket
, oid
);
2974 manifest
.set_prefix(upload_prefix
);
2976 manifest
.set_multipart_part_rule(store
->ctx()->_conf
->rgw_obj_stripe_size
, num
);
2978 int r
= manifest_gen
.create_begin(store
->ctx(), &manifest
, s
->bucket_info
.placement_rule
, bucket
, target_obj
);
2983 cur_obj
= manifest_gen
.get_cur_obj(store
);
2984 rgw_raw_obj_to_obj(bucket
, cur_obj
, &head_obj
);
2985 head_obj
.index_hash_source
= obj_str
;
2987 r
= prepare_init(store
, NULL
);
2995 int RGWPutObjProcessor_Multipart::do_complete(size_t accounted_size
,
2997 real_time
*mtime
, real_time set_mtime
,
2998 map
<string
, bufferlist
>& attrs
,
2999 real_time delete_at
,
3000 const char *if_match
,
3001 const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
)
3003 complete_writing_data();
3005 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, head_obj
);
3006 op_target
.set_versioning_disabled(true);
3007 RGWRados::Object::Write
head_obj_op(&op_target
);
3009 head_obj_op
.meta
.set_mtime
= set_mtime
;
3010 head_obj_op
.meta
.mtime
= mtime
;
3011 head_obj_op
.meta
.owner
= s
->owner
.get_id();
3012 head_obj_op
.meta
.delete_at
= delete_at
;
3013 head_obj_op
.meta
.zones_trace
= zones_trace
;
3015 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3020 RGWUploadPartInfo info
;
3022 bool sorted_omap
= is_v2_upload_id(upload_id
);
3026 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3028 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3032 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3037 info
.num
= atoi(part_num
.c_str());
3039 info
.size
= obj_len
;
3040 info
.accounted_size
= accounted_size
;
3041 info
.modified
= real_clock::now();
3042 info
.manifest
= manifest
;
3045 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3047 dout(1) << "cannot get compression info" << dendl
;
3053 string multipart_meta_obj
= mp
.get_meta();
3056 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3057 meta_obj
.set_in_extra_data(true);
3059 rgw_raw_obj raw_meta_obj
;
3061 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3063 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3068 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3070 RGWPutObjProcessor
*processor
;
3072 bool multipart
= s
->info
.args
.exists("uploadId");
3074 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3077 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3078 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3079 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3081 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3085 *is_multipart
= multipart
;
3091 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3096 void RGWPutObj::pre_exec()
3098 rgw_bucket_object_pre_exec(s
);
3101 class RGWPutObj_CB
: public RGWGetDataCB
3105 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3106 ~RGWPutObj_CB() override
{}
3108 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3109 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3113 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3116 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3118 bl_aux
.append(bl_tmp
);
3123 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3125 RGWPutObj_CB
cb(this);
3126 RGWGetDataCB
* filter
= &cb
;
3127 boost::optional
<RGWGetObj_Decompress
> decompress
;
3128 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3129 RGWCompressionInfo cs_info
;
3130 map
<string
, bufferlist
> attrs
;
3131 map
<string
, bufferlist
>::iterator attr_iter
;
3135 int64_t new_ofs
, new_end
;
3140 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3141 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3143 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3144 RGWRados::Object::Read
read_op(&op_target
);
3145 read_op
.params
.obj_size
= &obj_size
;
3146 read_op
.params
.attrs
= &attrs
;
3148 ret
= read_op
.prepare();
3152 bool need_decompress
;
3153 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3155 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3159 bool partial_content
= true;
3160 if (need_decompress
)
3162 obj_size
= cs_info
.orig_size
;
3163 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3164 filter
= &*decompress
;
3167 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3168 op_ret
= this->get_decrypt_filter(&decrypt
,
3171 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3172 if (decrypt
!= nullptr) {
3173 filter
= decrypt
.get();
3179 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3183 filter
->fixup_range(new_ofs
, new_end
);
3184 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3187 ret
= filter
->flush();
3189 bl
.claim_append(bl_aux
);
3194 // special handling for compression type = "random" with multipart uploads
3195 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3196 const std::string
& compression_type
)
3198 if (compression_type
!= "random") {
3199 return Compressor::create(s
->cct
, compression_type
);
3202 bool is_multipart
{false};
3203 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3205 if (!is_multipart
) {
3206 return Compressor::create(s
->cct
, compression_type
);
3209 // use a hash of the multipart upload id so all parts use the same plugin
3210 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3211 if (alg
== Compressor::COMP_ALG_NONE
) {
3214 return Compressor::create(s
->cct
, alg
);
3217 void RGWPutObj::execute()
3219 RGWPutObjProcessor
*processor
= NULL
;
3220 RGWPutObjDataProcessor
*filter
= nullptr;
3221 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3222 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3223 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3224 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3225 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3227 bufferlist bl
, aclbl
, bs
;
3229 map
<string
, string
>::iterator iter
;
3234 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3235 s
->bucket_info
.placement_rule
);
3236 CompressorRef plugin
;
3237 boost::optional
<RGWPutObj_Compress
> compressor
;
3239 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3240 perfcounter
->inc(l_rgw_put
);
3242 if (s
->object
.empty()) {
3246 if (!s
->bucket_exists
) {
3247 op_ret
= -ERR_NO_SUCH_BUCKET
;
3251 op_ret
= get_params();
3253 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3257 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3259 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3264 if (supplied_md5_b64
) {
3265 need_calc_md5
= true;
3267 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3268 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3269 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3270 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3271 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3272 op_ret
= -ERR_INVALID_DIGEST
;
3276 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3277 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3280 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3281 we also check sizes at the end anyway */
3282 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3283 user_quota
, bucket_quota
, s
->content_length
);
3285 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3288 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3290 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3295 if (supplied_etag
) {
3296 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3297 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3300 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3302 // no filters by default
3305 /* Handle object versioning of Swift API. */
3307 rgw_obj
obj(s
->bucket
, s
->object
);
3308 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3309 s
->bucket_owner
.get_id(),
3317 op_ret
= processor
->prepare(store
, NULL
);
3319 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3324 fst
= copy_source_range_fst
;
3325 lst
= copy_source_range_lst
;
3327 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3331 if (encrypt
!= nullptr) {
3332 filter
= encrypt
.get();
3334 //no encryption, we can try compression
3335 if (compression_type
!= "none") {
3336 plugin
= get_compressor_plugin(s
, compression_type
);
3338 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3339 << compression_type
<< dendl
;
3341 compressor
.emplace(s
->cct
, plugin
, filter
);
3342 filter
= &*compressor
;
3352 len
= get_data(data
);
3354 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3355 op_ret
= get_data(fst
, cur_lst
, data
);
3358 len
= data
.length();
3359 s
->content_length
+= len
;
3367 if (need_calc_md5
) {
3368 hash
.Update((const byte
*)data
.c_str(), data
.length());
3371 /* update torrrent */
3372 torrent
.update(data
);
3374 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3375 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3377 bool need_to_wait
= (ofs
== 0) && multipart
;
3379 bufferlist orig_data
;
3385 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3387 if (!need_to_wait
|| op_ret
!= -EEXIST
) {
3388 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3392 /* need_to_wait == true and op_ret == -EEXIST */
3393 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3395 /* restore original data */
3396 data
.swap(orig_data
);
3398 /* restart processing with different oid suffix */
3400 dispose_processor(processor
);
3401 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3406 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3407 oid_rand
.append(buf
);
3409 op_ret
= processor
->prepare(store
, &oid_rand
);
3411 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3416 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3420 if (encrypt
!= nullptr) {
3421 filter
= encrypt
.get();
3424 compressor
.emplace(s
->cct
, plugin
, filter
);
3425 filter
= &*compressor
;
3428 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3439 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3445 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3446 op_ret
= -ERR_REQUEST_TIMEOUT
;
3451 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3453 op_ret
= do_aws4_auth_completion();
3458 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3459 user_quota
, bucket_quota
, s
->obj_size
);
3461 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3465 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3467 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3473 if (compressor
&& compressor
->is_compressed()) {
3475 RGWCompressionInfo cs_info
;
3476 cs_info
.compression_type
= plugin
->get_type_name();
3477 cs_info
.orig_size
= s
->obj_size
;
3478 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3479 ::encode(cs_info
, tmp
);
3480 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3481 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3482 << " with type=" << cs_info
.compression_type
3483 << ", orig_size=" << cs_info
.orig_size
3484 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3487 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3491 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3492 op_ret
= -ERR_BAD_DIGEST
;
3496 policy
.encode(aclbl
);
3497 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3500 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3502 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3505 complete_etag(hash
, &etag
);
3506 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3510 bufferlist manifest_bl
;
3511 ::encode(*slo_info
, manifest_bl
);
3512 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3514 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3515 complete_etag(hash
, &etag
);
3516 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3519 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3520 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3523 bl
.append(etag
.c_str(), etag
.size() + 1);
3524 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3526 populate_with_generic_attrs(s
, attrs
);
3527 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3528 encode_delete_at_attr(delete_at
, attrs
);
3529 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3531 /* Add a custom metadata to expose the information whether an object
3532 * is an SLO or not. Appending the attribute must be performed AFTER
3533 * processing any input from user in order to prohibit overwriting. */
3535 bufferlist slo_userindicator_bl
;
3536 slo_userindicator_bl
.append("True", 4);
3537 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3540 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3541 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3542 (user_data
.empty() ? nullptr : &user_data
));
3544 /* produce torrent */
3545 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3547 torrent
.init(s
, store
);
3548 torrent
.set_create_date(mtime
);
3549 op_ret
= torrent
.complete();
3552 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3558 dispose_processor(processor
);
3559 perfcounter
->tinc(l_rgw_put_lat
,
3560 (ceph_clock_now() - s
->time
));
3563 int RGWPostObj::verify_permission()
3568 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3570 RGWPutObjProcessor *processor;
3572 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3574 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3579 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3584 void RGWPostObj::pre_exec()
3586 rgw_bucket_object_pre_exec(s
);
3589 void RGWPostObj::execute()
3591 RGWPutObjDataProcessor
*filter
= nullptr;
3592 boost::optional
<RGWPutObj_Compress
> compressor
;
3593 CompressorRef plugin
;
3594 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3596 /* Read in the data from the POST form. */
3597 op_ret
= get_params();
3602 op_ret
= verify_params();
3607 if (s
->iam_policy
) {
3608 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3609 rgw::IAM::s3PutObject
,
3610 rgw_obj(s
->bucket
, s
->object
));
3611 if (e
== Effect::Deny
) {
3614 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3618 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3623 /* Start iteration over data fields. It's necessary as Swift's FormPost
3624 * is capable to handle multiple files in single form. */
3626 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3627 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3628 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3630 ceph::buffer::list bl
, aclbl
;
3633 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3642 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3647 if (supplied_md5_b64
) {
3648 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3649 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3650 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3651 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3652 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3653 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3654 op_ret
= -ERR_INVALID_DIGEST
;
3658 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3659 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3662 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3665 get_current_filename(),
3667 s
->cct
->_conf
->rgw_obj_stripe_size
,
3669 s
->bucket_info
.versioning_enabled());
3670 /* No filters by default. */
3671 filter
= &processor
;
3673 op_ret
= processor
.prepare(store
, nullptr);
3678 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3682 if (encrypt
!= nullptr) {
3683 filter
= encrypt
.get();
3685 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3686 s
->bucket_info
.placement_rule
);
3687 if (compression_type
!= "none") {
3688 plugin
= Compressor::create(s
->cct
, compression_type
);
3690 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3691 << compression_type
<< dendl
;
3693 compressor
.emplace(s
->cct
, plugin
, filter
);
3694 filter
= &*compressor
;
3701 ceph::bufferlist data
;
3702 len
= get_data(data
, again
);
3713 hash
.Update((const byte
*)data
.c_str(), data
.length());
3714 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3718 if (ofs
> max_len
) {
3719 op_ret
= -ERR_TOO_LARGE
;
3726 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3729 if (len
< min_len
) {
3730 op_ret
= -ERR_TOO_SMALL
;
3736 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3737 op_ret
= -ERR_BAD_DIGEST
;
3741 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3742 user_quota
, bucket_quota
, s
->obj_size
);
3747 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3753 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3756 bl
.append(etag
.c_str(), etag
.size() + 1);
3757 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3759 policy
.encode(aclbl
);
3760 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3762 const std::string content_type
= get_current_content_type();
3763 if (! content_type
.empty()) {
3764 ceph::bufferlist ct_bl
;
3765 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3766 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3769 if (compressor
&& compressor
->is_compressed()) {
3770 ceph::bufferlist tmp
;
3771 RGWCompressionInfo cs_info
;
3772 cs_info
.compression_type
= plugin
->get_type_name();
3773 cs_info
.orig_size
= s
->obj_size
;
3774 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3775 ::encode(cs_info
, tmp
);
3776 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3779 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3780 attrs
, (delete_at
? *delete_at
: real_time()));
3781 } while (is_next_file_to_upload());
3785 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3786 const set
<string
>& rmattr_names
,
3787 map
<int, string
>& temp_url_keys
)
3789 map
<string
, bufferlist
>::iterator iter
;
3791 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3792 if (iter
!= add_attrs
.end()) {
3793 temp_url_keys
[0] = iter
->second
.c_str();
3794 add_attrs
.erase(iter
);
3797 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3798 if (iter
!= add_attrs
.end()) {
3799 temp_url_keys
[1] = iter
->second
.c_str();
3800 add_attrs
.erase(iter
);
3803 for (const string
& name
: rmattr_names
) {
3804 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3805 temp_url_keys
[0] = string();
3807 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3808 temp_url_keys
[1] = string();
3813 int RGWPutMetadataAccount::init_processing()
3815 /* First, go to the base class. At the time of writing the method was
3816 * responsible only for initializing the quota. This isn't necessary
3817 * here as we are touching metadata only. I'm putting this call only
3818 * for the future. */
3819 op_ret
= RGWOp::init_processing();
3824 op_ret
= get_params();
3829 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3837 policy
.encode(acl_bl
);
3838 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3841 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3842 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3843 populate_with_generic_attrs(s
, attrs
);
3845 /* Try extract the TempURL-related stuff now to allow verify_permission
3846 * evaluate whether we need FULL_CONTROL or not. */
3847 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3849 /* The same with quota except a client needs to be reseller admin. */
3850 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3851 &new_quota_extracted
);
3859 int RGWPutMetadataAccount::verify_permission()
3861 if (s
->auth
.identity
->is_anonymous()) {
3865 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
3869 /* Altering TempURL keys requires FULL_CONTROL. */
3870 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
3874 /* We are failing this intensionally to allow system user/reseller admin
3875 * override in rgw_process.cc. This is the way to specify a given RGWOp
3876 * expect extra privileges. */
3877 if (new_quota_extracted
) {
3884 void RGWPutMetadataAccount::execute()
3886 /* Params have been extracted earlier. See init_processing(). */
3887 RGWUserInfo new_uinfo
;
3888 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
3894 /* Handle the TempURL-related stuff. */
3895 if (!temp_url_keys
.empty()) {
3896 for (auto& pair
: temp_url_keys
) {
3897 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
3901 /* Handle the quota extracted at the verify_permission step. */
3902 if (new_quota_extracted
) {
3903 new_uinfo
.user_quota
= std::move(new_quota
);
3906 /* We are passing here the current (old) user info to allow the function
3907 * optimize-out some operations. */
3908 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
3909 &acct_op_tracker
, real_time(), false, &attrs
);
3912 int RGWPutMetadataBucket::verify_permission()
3914 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3921 void RGWPutMetadataBucket::pre_exec()
3923 rgw_bucket_object_pre_exec(s
);
3926 void RGWPutMetadataBucket::execute()
3928 op_ret
= get_params();
3933 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3935 if (!placement_rule
.empty() &&
3936 placement_rule
!= s
->bucket_info
.placement_rule
) {
3941 /* Encode special metadata first as we're using std::map::emplace under
3942 * the hood. This method will add the new items only if the map doesn't
3943 * contain such keys yet. */
3945 if (s
->dialect
.compare("swift") == 0) {
3947 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
3948 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
3949 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
3950 policy
= *new_policy
;
3954 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
3959 cors_config
.encode(bl
);
3960 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
3963 /* It's supposed that following functions WILL NOT change any special
3964 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
3965 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
3966 populate_with_generic_attrs(s
, attrs
);
3968 /* According to the Swift's behaviour and its container_quota WSGI middleware
3969 * implementation: anyone with write permissions is able to set the bucket
3970 * quota. This stays in contrast to account quotas that can be set only by
3971 * clients holding reseller admin privileges. */
3972 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
3977 if (swift_ver_location
) {
3978 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
3979 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
3982 /* Web site of Swift API. */
3983 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
3984 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
3986 /* Setting attributes also stores the provided bucket info. Due to this
3987 * fact, the new quota settings can be serialized with the same call. */
3988 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
3989 &s
->bucket_info
.objv_tracker
);
3992 int RGWPutMetadataObject::verify_permission()
3994 // This looks to be something specific to Swift. We could add
3995 // operations like swift:PutMetadataObject to the Policy Engine.
3996 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4003 void RGWPutMetadataObject::pre_exec()
4005 rgw_bucket_object_pre_exec(s
);
4008 void RGWPutMetadataObject::execute()
4010 rgw_obj
obj(s
->bucket
, s
->object
);
4011 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4013 store
->set_atomic(s
->obj_ctx
, obj
);
4015 op_ret
= get_params();
4020 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4021 /* check if obj exists, read orig attrs */
4022 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4027 /* Check whether the object has expired. Swift API documentation
4028 * stands that we should return 404 Not Found in such case. */
4029 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4034 /* Filter currently existing attributes. */
4035 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4036 populate_with_generic_attrs(s
, attrs
);
4037 encode_delete_at_attr(delete_at
, attrs
);
4040 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4042 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4047 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4050 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4052 RGWSLOInfo slo_info
;
4053 bufferlist::iterator bliter
= bl
.begin();
4055 ::decode(slo_info
, bliter
);
4056 } catch (buffer::error
& err
) {
4057 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4062 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4063 new RGWBulkDelete::Deleter(store
, s
));
4064 } catch (std::bad_alloc
) {
4068 list
<RGWBulkDelete::acct_path_t
> items
;
4069 for (const auto& iter
: slo_info
.entries
) {
4070 const string
& path_str
= iter
.path
;
4072 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4073 if (boost::string_view::npos
== sep_pos
) {
4077 RGWBulkDelete::acct_path_t path
;
4079 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4080 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4082 items
.push_back(path
);
4085 /* Request removal of the manifest object itself. */
4086 RGWBulkDelete::acct_path_t path
;
4087 path
.bucket_name
= s
->bucket_name
;
4088 path
.obj_key
= s
->object
;
4089 items
.push_back(path
);
4091 int ret
= deleter
->delete_chunk(items
);
4099 int RGWDeleteObj::verify_permission()
4101 if (s
->iam_policy
) {
4102 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4103 s
->object
.instance
.empty() ?
4104 rgw::IAM::s3DeleteObject
:
4105 rgw::IAM::s3DeleteObjectVersion
,
4106 ARN(s
->bucket
, s
->object
.name
));
4107 if (r
== Effect::Allow
)
4109 else if (r
== Effect::Deny
)
4113 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4120 void RGWDeleteObj::pre_exec()
4122 rgw_bucket_object_pre_exec(s
);
4125 void RGWDeleteObj::execute()
4127 if (!s
->bucket_exists
) {
4128 op_ret
= -ERR_NO_SUCH_BUCKET
;
4132 op_ret
= get_params();
4137 rgw_obj
obj(s
->bucket
, s
->object
);
4138 map
<string
, bufferlist
> attrs
;
4141 if (!s
->object
.empty()) {
4142 if (need_object_expiration() || multipart_delete
) {
4143 /* check if obj exists, read orig attrs */
4144 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4150 if (multipart_delete
) {
4151 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4153 if (slo_attr
!= attrs
.end()) {
4154 op_ret
= handle_slo_manifest(slo_attr
->second
);
4156 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4159 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4165 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4166 obj_ctx
->obj
.set_atomic(obj
);
4168 bool ver_restored
= false;
4169 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4170 s
->bucket_info
, obj
, ver_restored
);
4175 if (!ver_restored
) {
4176 /* Swift's versioning mechanism hasn't found any previous version of
4177 * the object that could be restored. This means we should proceed
4178 * with the regular delete path. */
4179 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4180 RGWRados::Object::Delete
del_op(&del_target
);
4182 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4183 &del_op
.params
.marker_version_id
);
4188 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4189 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4190 del_op
.params
.obj_owner
= s
->owner
;
4191 del_op
.params
.unmod_since
= unmod_since
;
4192 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4194 op_ret
= del_op
.delete_obj();
4196 delete_marker
= del_op
.result
.delete_marker
;
4197 version_id
= del_op
.result
.version_id
;
4200 /* Check whether the object has expired. Swift API documentation
4201 * stands that we should return 404 Not Found in such case. */
4202 if (need_object_expiration() && object_is_expired(attrs
)) {
4208 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4217 bool RGWCopyObj::parse_copy_location(const string
& url_src
, string
& bucket_name
, rgw_obj_key
& key
)
4222 size_t pos
= url_src
.find('?');
4223 if (pos
== string::npos
) {
4226 name_str
= url_src
.substr(0, pos
);
4227 params_str
= url_src
.substr(pos
+ 1);
4230 std::string dec_src
= url_decode(name_str
);
4231 const char *src
= dec_src
.c_str();
4233 if (*src
== '/') ++src
;
4237 pos
= str
.find('/');
4238 if (pos
==string::npos
)
4241 bucket_name
= str
.substr(0, pos
);
4242 key
.name
= str
.substr(pos
+ 1);
4244 if (key
.name
.empty()) {
4248 if (!params_str
.empty()) {
4250 args
.set(params_str
);
4253 key
.instance
= args
.get("versionId", NULL
);
4259 int RGWCopyObj::verify_permission()
4261 RGWAccessControlPolicy
src_acl(s
->cct
);
4262 optional
<Policy
> src_policy
;
4263 op_ret
= get_params();
4267 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4271 map
<string
, bufferlist
> src_attrs
;
4273 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4275 if (s
->bucket_instance_id
.empty()) {
4276 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4278 /* will only happen in intra region sync where the source and dest bucket is the same */
4279 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4282 if (op_ret
== -ENOENT
) {
4283 op_ret
= -ERR_NO_SUCH_BUCKET
;
4288 src_bucket
= src_bucket_info
.bucket
;
4290 /* get buckets info (source and dest) */
4291 if (s
->local_source
&& source_zone
.empty()) {
4292 rgw_obj
src_obj(src_bucket
, src_object
);
4293 store
->set_atomic(s
->obj_ctx
, src_obj
);
4294 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4296 /* check source object permissions */
4297 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4298 src_policy
, src_bucket
, src_object
);
4303 /* admin request overrides permission checks */
4304 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4306 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4307 src_object
.instance
.empty() ?
4308 rgw::IAM::s3GetObject
:
4309 rgw::IAM::s3GetObjectVersion
,
4311 if (e
== Effect::Deny
) {
4313 } else if (e
== Effect::Pass
&&
4314 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4318 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4326 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4327 map
<string
, bufferlist
> dest_attrs
;
4329 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4330 or intra region sync */
4331 dest_bucket_info
= src_bucket_info
;
4332 dest_attrs
= src_attrs
;
4334 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4335 dest_bucket_info
, nullptr, &dest_attrs
);
4337 if (op_ret
== -ENOENT
) {
4338 op_ret
= -ERR_NO_SUCH_BUCKET
;
4344 dest_bucket
= dest_bucket_info
.bucket
;
4346 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4347 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4349 /* check dest bucket permissions */
4350 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4351 &dest_bucket_policy
, dest_bucket
);
4356 /* admin request overrides permission checks */
4357 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4358 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4363 op_ret
= init_dest_policy();
4372 int RGWCopyObj::init_common()
4375 if (parse_time(if_mod
, &mod_time
) < 0) {
4379 mod_ptr
= &mod_time
;
4383 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4387 unmod_ptr
= &unmod_time
;
4391 dest_policy
.encode(aclbl
);
4392 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4394 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4395 populate_with_generic_attrs(s
, attrs
);
4400 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4402 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4403 op
->progress_cb(ofs
);
4406 void RGWCopyObj::progress_cb(off_t ofs
)
4408 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4411 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4414 send_partial_response(ofs
);
4419 void RGWCopyObj::pre_exec()
4421 rgw_bucket_object_pre_exec(s
);
4424 void RGWCopyObj::execute()
4426 if (init_common() < 0)
4429 rgw_obj
src_obj(src_bucket
, src_object
);
4430 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4432 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4433 obj_ctx
.obj
.set_atomic(src_obj
);
4434 obj_ctx
.obj
.set_atomic(dst_obj
);
4436 encode_delete_at_attr(delete_at
, attrs
);
4438 bool high_precision_time
= (s
->system_request
);
4440 /* Handle object versioning of Swift API. In case of copying to remote this
4441 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4442 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4443 dest_bucket_info
.owner
,
4450 op_ret
= store
->copy_obj(obj_ctx
,
4464 high_precision_time
,
4469 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4471 (delete_at
? *delete_at
: real_time()),
4472 (version_id
.empty() ? NULL
: &version_id
),
4473 &s
->req_id
, /* use req_id as tag */
4475 copy_obj_progress_cb
, (void *)this
4479 int RGWGetACLs::verify_permission()
4482 if (!s
->object
.empty()) {
4483 perm
= verify_object_permission(s
,
4484 s
->object
.instance
.empty() ?
4485 rgw::IAM::s3GetObjectAcl
:
4486 rgw::IAM::s3GetObjectVersionAcl
);
4488 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetObjectAcl
);
4496 void RGWGetACLs::pre_exec()
4498 rgw_bucket_object_pre_exec(s
);
4501 void RGWGetACLs::execute()
4504 RGWAccessControlPolicy
* const acl
= \
4505 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4506 RGWAccessControlPolicy_S3
* const s3policy
= \
4507 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4508 s3policy
->to_xml(ss
);
4514 int RGWPutACLs::verify_permission()
4517 if (!s
->object
.empty()) {
4518 perm
= verify_object_permission(s
,
4519 s
->object
.instance
.empty() ?
4520 rgw::IAM::s3PutObjectAcl
:
4521 rgw::IAM::s3PutObjectVersionAcl
);
4523 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4531 int RGWGetLC::verify_permission()
4534 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4541 int RGWPutLC::verify_permission()
4544 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4551 int RGWDeleteLC::verify_permission()
4554 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4561 void RGWPutACLs::pre_exec()
4563 rgw_bucket_object_pre_exec(s
);
4566 void RGWGetLC::pre_exec()
4568 rgw_bucket_object_pre_exec(s
);
4571 void RGWPutLC::pre_exec()
4573 rgw_bucket_object_pre_exec(s
);
4576 void RGWDeleteLC::pre_exec()
4578 rgw_bucket_object_pre_exec(s
);
4581 void RGWPutACLs::execute()
4585 RGWAccessControlPolicy_S3
*policy
= NULL
;
4586 RGWACLXMLParser_S3
parser(s
->cct
);
4587 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4589 char *new_data
= NULL
;
4592 op_ret
= 0; /* XXX redundant? */
4594 if (!parser
.init()) {
4600 RGWAccessControlPolicy
* const existing_policy
= \
4601 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
4603 owner
= existing_policy
->get_owner();
4605 op_ret
= get_params();
4607 if (op_ret
== -ERANGE
) {
4608 ldout(s
->cct
, 4) << "The size of request xml data is larger than the max limitation, data size = "
4609 << s
->length
<< dendl
;
4610 op_ret
= -ERR_MALFORMED_XML
;
4611 s
->err
.message
= "The XML you provided was larger than the maximum " +
4612 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
4618 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4620 if (!s
->canned_acl
.empty() && len
) {
4625 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4626 op_ret
= get_policy_from_state(store
, s
, ss
);
4630 new_data
= strdup(ss
.str().c_str());
4633 len
= ss
.str().size();
4636 if (!parser
.parse(data
, len
, 1)) {
4640 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4646 const RGWAccessControlList
& req_acl
= policy
->get_acl();
4647 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
4648 #define ACL_GRANTS_MAX_NUM 100
4649 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
4651 max_num
= ACL_GRANTS_MAX_NUM
;
4654 int grants_num
= req_grant_map
.size();
4655 if (grants_num
> max_num
) {
4656 ldout(s
->cct
, 4) << "An acl can have up to "
4658 << " grants, request acl grants num: "
4659 << grants_num
<< dendl
;
4660 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
4661 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
4662 + std::to_string(max_num
)
4663 + " grants allowed in an acl.";
4667 // forward bucket acl requests to meta master zone
4668 if (s
->object
.empty() && !store
->is_meta_master()) {
4670 // include acl data unless it was generated from a canned_acl
4671 if (s
->canned_acl
.empty()) {
4672 in_data
.append(data
, len
);
4674 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4676 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4681 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4682 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4683 policy
->to_xml(*_dout
);
4687 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4691 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4692 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4693 new_policy
.to_xml(*_dout
);
4697 new_policy
.encode(bl
);
4698 map
<string
, bufferlist
> attrs
;
4700 if (!s
->object
.empty()) {
4701 obj
= rgw_obj(s
->bucket
, s
->object
);
4702 store
->set_atomic(s
->obj_ctx
, obj
);
4703 //if instance is empty, we should modify the latest object
4704 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4706 attrs
= s
->bucket_attrs
;
4707 attrs
[RGW_ATTR_ACL
] = bl
;
4708 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4710 if (op_ret
== -ECANCELED
) {
4711 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4715 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4717 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4718 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4719 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4720 oid
= lc_oid_prefix
;
4722 snprintf(buf
, 32, ".%d", index
);
4727 void RGWPutLC::execute()
4731 RGWLifecycleConfiguration_S3
*config
= NULL
;
4732 RGWLCXMLParser_S3
parser(s
->cct
);
4733 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4735 if (!parser
.init()) {
4740 op_ret
= get_params();
4744 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4746 if (!parser
.parse(data
, len
, 1)) {
4747 op_ret
= -ERR_MALFORMED_XML
;
4750 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4752 op_ret
= -ERR_MALFORMED_XML
;
4756 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4757 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4758 config
->to_xml(*_dout
);
4762 op_ret
= config
->rebuild(store
, new_config
);
4766 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4767 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4768 new_config
.to_xml(*_dout
);
4772 new_config
.encode(bl
);
4773 map
<string
, bufferlist
> attrs
;
4774 attrs
= s
->bucket_attrs
;
4775 attrs
[RGW_ATTR_LC
] = bl
;
4776 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4779 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4782 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4783 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4784 rados::cls::lock::Lock
l(lc_index_lock_name
);
4785 utime_t
time(max_lock_secs
, 0);
4786 l
.set_duration(time
);
4787 l
.set_cookie(cookie
);
4788 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4790 op_ret
= l
.lock_exclusive(ctx
, oid
);
4791 if (op_ret
== -EBUSY
) {
4792 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4797 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4800 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4802 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4810 void RGWDeleteLC::execute()
4813 map
<string
, bufferlist
> orig_attrs
, attrs
;
4814 map
<string
, bufferlist
>::iterator iter
;
4816 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4817 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4818 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4822 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4823 const string
& name
= iter
->first
;
4824 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
4825 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
4826 if (attrs
.find(name
) == attrs
.end()) {
4827 attrs
[name
] = iter
->second
;
4831 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4832 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4833 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4836 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4837 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4838 rados::cls::lock::Lock
l(lc_index_lock_name
);
4839 utime_t
time(max_lock_secs
, 0);
4840 l
.set_duration(time
);
4842 op_ret
= l
.lock_exclusive(ctx
, oid
);
4843 if (op_ret
== -EBUSY
) {
4844 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4849 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4852 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
4854 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4862 int RGWGetCORS::verify_permission()
4864 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4871 void RGWGetCORS::execute()
4873 op_ret
= read_bucket_cors();
4878 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4884 int RGWPutCORS::verify_permission()
4886 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4893 void RGWPutCORS::execute()
4897 op_ret
= get_params();
4901 if (!store
->is_meta_master()) {
4902 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
4904 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4909 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
4910 attrs
[RGW_ATTR_CORS
] = cors_bl
;
4911 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4914 int RGWDeleteCORS::verify_permission()
4916 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4923 void RGWDeleteCORS::execute()
4925 op_ret
= read_bucket_cors();
4932 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4936 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4937 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4938 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
4939 map
<string
, bufferlist
>::iterator iter
;
4941 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4945 /* only remove meta attrs */
4946 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4947 const string
& name
= iter
->first
;
4948 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
4949 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
4950 rmattrs
[name
] = iter
->second
;
4951 } else if (attrs
.find(name
) == attrs
.end()) {
4952 attrs
[name
] = iter
->second
;
4955 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4958 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
4959 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
4962 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
4963 rule
= cc
->host_name_rule(origin
);
4965 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
4969 if (!validate_cors_rule_method(rule
, req_meth
)) {
4975 void RGWOptionsCORS::execute()
4977 op_ret
= read_bucket_cors();
4981 origin
= s
->info
.env
->get("HTTP_ORIGIN");
4984 "Preflight request without mandatory Origin header"
4989 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
4992 "Preflight request without mandatory Access-control-request-method header"
4998 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5002 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5003 op_ret
= validate_cors_request(&bucket_cors
);
5005 origin
= req_meth
= NULL
;
5011 int RGWGetRequestPayment::verify_permission()
5016 void RGWGetRequestPayment::pre_exec()
5018 rgw_bucket_object_pre_exec(s
);
5021 void RGWGetRequestPayment::execute()
5023 requester_pays
= s
->bucket_info
.requester_pays
;
5026 int RGWSetRequestPayment::verify_permission()
5028 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
5035 void RGWSetRequestPayment::pre_exec()
5037 rgw_bucket_object_pre_exec(s
);
5040 void RGWSetRequestPayment::execute()
5042 op_ret
= get_params();
5047 s
->bucket_info
.requester_pays
= requester_pays
;
5048 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5051 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5052 << " returned err=" << op_ret
<< dendl
;
5057 int RGWInitMultipart::verify_permission()
5059 if (s
->iam_policy
) {
5060 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5061 rgw::IAM::s3PutObject
,
5062 rgw_obj(s
->bucket
, s
->object
));
5063 if (e
== Effect::Allow
) {
5065 } else if (e
== Effect::Deny
) {
5070 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5077 void RGWInitMultipart::pre_exec()
5079 rgw_bucket_object_pre_exec(s
);
5082 void RGWInitMultipart::execute()
5085 map
<string
, bufferlist
> attrs
;
5088 if (get_params() < 0)
5091 if (s
->object
.empty())
5094 policy
.encode(aclbl
);
5095 attrs
[RGW_ATTR_ACL
] = aclbl
;
5097 populate_with_generic_attrs(s
, attrs
);
5099 /* select encryption mode */
5100 op_ret
= prepare_encryption(attrs
);
5104 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5108 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5109 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5110 upload_id
.append(buf
);
5112 string tmp_obj_name
;
5113 RGWMPObj
mp(s
->object
.name
, upload_id
);
5114 tmp_obj_name
= mp
.get_meta();
5116 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5117 // the meta object will be indexed with 0 size, we c
5118 obj
.set_in_extra_data(true);
5119 obj
.index_hash_source
= s
->object
.name
;
5121 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5122 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5124 RGWRados::Object::Write
obj_op(&op_target
);
5126 obj_op
.meta
.owner
= s
->owner
.get_id();
5127 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5128 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5130 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5131 } while (op_ret
== -EEXIST
);
5134 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5136 RGWAccessControlPolicy
*policy
,
5137 map
<string
, bufferlist
>& attrs
)
5139 map
<string
, bufferlist
>::iterator iter
;
5143 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5144 obj
.set_in_extra_data(true);
5146 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5148 if (op_ret
== -ENOENT
) {
5149 return -ERR_NO_SUCH_UPLOAD
;
5155 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5156 string name
= iter
->first
;
5157 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5158 bufferlist
& bl
= iter
->second
;
5159 bufferlist::iterator bli
= bl
.begin();
5161 ::decode(*policy
, bli
);
5162 } catch (buffer::error
& err
) {
5163 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5174 int RGWCompleteMultipart::verify_permission()
5176 if (s
->iam_policy
) {
5177 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5178 rgw::IAM::s3PutObject
,
5179 rgw_obj(s
->bucket
, s
->object
));
5180 if (e
== Effect::Allow
) {
5182 } else if (e
== Effect::Deny
) {
5187 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5194 void RGWCompleteMultipart::pre_exec()
5196 rgw_bucket_object_pre_exec(s
);
5199 void RGWCompleteMultipart::execute()
5201 RGWMultiCompleteUpload
*parts
;
5202 map
<int, string
>::iterator iter
;
5203 RGWMultiXMLParser parser
;
5205 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5206 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5207 map
<string
, bufferlist
> attrs
;
5210 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5211 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5216 RGWObjManifest manifest
;
5217 uint64_t olh_epoch
= 0;
5220 op_ret
= get_params();
5223 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5228 if (!data
|| !len
) {
5229 op_ret
= -ERR_MALFORMED_XML
;
5233 if (!parser
.init()) {
5238 if (!parser
.parse(data
, len
, 1)) {
5239 op_ret
= -ERR_MALFORMED_XML
;
5243 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5244 if (!parts
|| parts
->parts
.empty()) {
5245 op_ret
= -ERR_MALFORMED_XML
;
5249 if ((int)parts
->parts
.size() >
5250 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5255 mp
.init(s
->object
.name
, upload_id
);
5256 meta_oid
= mp
.get_meta();
5258 int total_parts
= 0;
5259 int handled_parts
= 0;
5260 int max_parts
= 1000;
5263 RGWCompressionInfo cs_info
;
5264 bool compressed
= false;
5265 uint64_t accounted_size
= 0;
5267 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5269 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5271 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5273 iter
= parts
->parts
.begin();
5275 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5276 meta_obj
.set_in_extra_data(true);
5277 meta_obj
.index_hash_source
= s
->object
.name
;
5279 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5282 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5283 << " ret=" << op_ret
<< dendl
;
5288 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5289 marker
, obj_parts
, &marker
, &truncated
);
5290 if (op_ret
== -ENOENT
) {
5291 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5296 total_parts
+= obj_parts
.size();
5297 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5298 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5299 << " expected: " << parts
->parts
.size() << dendl
;
5300 op_ret
= -ERR_INVALID_PART
;
5304 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5305 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5306 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5307 part_size
< min_part_size
) {
5308 op_ret
= -ERR_TOO_SMALL
;
5312 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5313 if (iter
->first
!= (int)obj_iter
->first
) {
5314 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5315 << iter
->first
<< " next uploaded: "
5316 << obj_iter
->first
<< dendl
;
5317 op_ret
= -ERR_INVALID_PART
;
5320 string part_etag
= rgw_string_unquote(iter
->second
);
5321 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5322 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5323 << " etag: " << iter
->second
<< dendl
;
5324 op_ret
= -ERR_INVALID_PART
;
5328 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5329 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5330 hash
.Update((const byte
*)petag
, sizeof(petag
));
5332 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5334 /* update manifest for part */
5335 string oid
= mp
.get_part(obj_iter
->second
.num
);
5337 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5339 if (obj_part
.manifest
.empty()) {
5340 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5341 << src_obj
<< dendl
;
5342 op_ret
= -ERR_INVALID_PART
;
5345 manifest
.append(obj_part
.manifest
, store
);
5348 if (obj_part
.cs_info
.compression_type
!= "none") {
5349 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5350 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5351 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5352 op_ret
= -ERR_INVALID_PART
;
5355 int64_t new_ofs
; // offset in compression data for new part
5356 if (cs_info
.blocks
.size() > 0)
5357 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5360 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5361 compression_block cb
;
5362 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5363 cb
.new_ofs
= new_ofs
;
5365 cs_info
.blocks
.push_back(cb
);
5366 new_ofs
= cb
.new_ofs
+ cb
.len
;
5369 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5370 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5374 rgw_obj_index_key remove_key
;
5375 src_obj
.key
.get_index_key(&remove_key
);
5377 remove_objs
.push_back(remove_key
);
5379 ofs
+= obj_part
.size
;
5380 accounted_size
+= obj_part
.accounted_size
;
5382 } while (truncated
);
5383 hash
.Final((byte
*)final_etag
);
5385 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5386 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5387 "-%lld", (long long)parts
->parts
.size());
5388 etag
= final_etag_str
;
5389 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5391 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5393 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5396 // write compression attribute to full object
5398 ::encode(cs_info
, tmp
);
5399 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5402 target_obj
.init(s
->bucket
, s
->object
.name
);
5403 if (versioned_object
) {
5404 store
->gen_rand_obj_instance_name(&target_obj
);
5407 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5409 obj_ctx
.obj
.set_atomic(target_obj
);
5411 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5412 RGWRados::Object::Write
obj_op(&op_target
);
5414 obj_op
.meta
.manifest
= &manifest
;
5415 obj_op
.meta
.remove_objs
= &remove_objs
;
5417 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5418 obj_op
.meta
.owner
= s
->owner
.get_id();
5419 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5420 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5424 // remove the upload obj
5425 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5426 s
->bucket_info
, meta_obj
, 0);
5428 ldout(store
->ctx(), 0) << "WARNING: failed to remove object " << meta_obj
<< dendl
;
5432 int RGWAbortMultipart::verify_permission()
5434 if (s
->iam_policy
) {
5435 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5436 rgw::IAM::s3AbortMultipartUpload
,
5437 rgw_obj(s
->bucket
, s
->object
));
5438 if (e
== Effect::Allow
) {
5440 } else if (e
== Effect::Deny
) {
5445 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5452 void RGWAbortMultipart::pre_exec()
5454 rgw_bucket_object_pre_exec(s
);
5457 void RGWAbortMultipart::execute()
5462 upload_id
= s
->info
.args
.get("uploadId");
5463 map
<string
, bufferlist
> attrs
;
5467 if (upload_id
.empty() || s
->object
.empty())
5470 mp
.init(s
->object
.name
, upload_id
);
5471 meta_oid
= mp
.get_meta();
5473 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5477 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5478 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5481 int RGWListMultipart::verify_permission()
5483 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5489 void RGWListMultipart::pre_exec()
5491 rgw_bucket_object_pre_exec(s
);
5494 void RGWListMultipart::execute()
5496 map
<string
, bufferlist
> xattrs
;
5500 op_ret
= get_params();
5504 mp
.init(s
->object
.name
, upload_id
);
5505 meta_oid
= mp
.get_meta();
5507 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5511 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5512 marker
, parts
, NULL
, &truncated
);
5515 int RGWListBucketMultiparts::verify_permission()
5517 if (!verify_bucket_permission(s
,
5518 rgw::IAM::s3ListBucketMultiPartUploads
))
5524 void RGWListBucketMultiparts::pre_exec()
5526 rgw_bucket_object_pre_exec(s
);
5529 void RGWListBucketMultiparts::execute()
5531 vector
<rgw_bucket_dir_entry
> objs
;
5534 op_ret
= get_params();
5538 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5540 path_args
= s
->info
.args
.get("path");
5541 if (!path_args
.empty()) {
5542 if (!delimiter
.empty() || !prefix
.empty()) {
5550 marker_meta
= marker
.get_meta();
5552 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5553 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5558 if (!objs
.empty()) {
5559 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5560 RGWMultipartUploadEntry entry
;
5561 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5562 rgw_obj_key
key(iter
->key
);
5563 if (!entry
.mp
.from_meta(key
.name
))
5566 uploads
.push_back(entry
);
5568 next_marker
= entry
;
5572 void RGWGetHealthCheck::execute()
5574 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5575 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5576 /* Disabling path specified & existent in the filesystem. */
5577 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5579 op_ret
= 0; /* 200 OK */
5583 int RGWDeleteMultiObj::verify_permission()
5585 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5586 if (!acl_allowed
&& !s
->iam_policy
)
5592 void RGWDeleteMultiObj::pre_exec()
5594 rgw_bucket_object_pre_exec(s
);
5597 void RGWDeleteMultiObj::execute()
5599 RGWMultiDelDelete
*multi_delete
;
5600 vector
<rgw_obj_key
>::iterator iter
;
5601 RGWMultiDelXMLParser parser
;
5602 int num_processed
= 0;
5603 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5605 op_ret
= get_params();
5615 if (!parser
.init()) {
5620 if (!parser
.parse(data
, len
, 1)) {
5625 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5626 if (!multi_delete
) {
5631 if (multi_delete
->is_quiet())
5635 if (multi_delete
->objects
.empty()) {
5639 for (iter
= multi_delete
->objects
.begin();
5640 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5641 ++iter
, num_processed
++) {
5642 rgw_obj
obj(bucket
, *iter
);
5643 if (s
->iam_policy
) {
5644 auto e
= s
->iam_policy
->eval(s
->env
,
5646 iter
->instance
.empty() ?
5647 rgw::IAM::s3DeleteObject
:
5648 rgw::IAM::s3DeleteObjectVersion
,
5650 if ((e
== Effect::Deny
) ||
5651 (e
== Effect::Pass
&& !acl_allowed
)) {
5652 send_partial_response(*iter
, false, "", -EACCES
);
5657 obj_ctx
->obj
.set_atomic(obj
);
5659 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5660 RGWRados::Object::Delete
del_op(&del_target
);
5662 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5663 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5664 del_op
.params
.obj_owner
= s
->owner
;
5666 op_ret
= del_op
.delete_obj();
5667 if (op_ret
== -ENOENT
) {
5671 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5672 del_op
.result
.version_id
, op_ret
);
5675 /* set the return code to zero, errors at this point will be
5676 dumped to the response */
5680 // will likely segfault if begin_response() has not been called
5692 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5693 map
<string
, bufferlist
>& battrs
,
5694 ACLOwner
& bucket_owner
/* out */)
5696 RGWAccessControlPolicy
bacl(store
->ctx());
5697 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5702 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5704 bucket_owner
= bacl
.get_owner();
5706 /* We can use global user_acl because each BulkDelete request is allowed
5707 * to work on entities from a single account only. */
5708 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5709 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5712 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5714 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5716 RGWBucketInfo binfo
;
5717 map
<string
, bufferlist
> battrs
;
5720 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5721 path
.bucket_name
, binfo
, nullptr,
5727 if (!verify_permission(binfo
, battrs
, bowner
)) {
5732 if (!path
.obj_key
.empty()) {
5733 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5734 obj_ctx
.obj
.set_atomic(obj
);
5736 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5737 RGWRados::Object::Delete
del_op(&del_target
);
5739 del_op
.params
.bucket_owner
= binfo
.owner
;
5740 del_op
.params
.versioning_status
= binfo
.versioning_status();
5741 del_op
.params
.obj_owner
= bowner
;
5743 ret
= del_op
.delete_obj();
5748 RGWObjVersionTracker ot
;
5749 ot
.read_version
= binfo
.ep_objv
;
5751 ret
= store
->delete_bucket(binfo
, ot
);
5753 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5754 binfo
.bucket
.name
, false);
5756 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
5764 if (!store
->is_meta_master()) {
5766 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
5769 if (ret
== -ENOENT
) {
5770 /* adjust error, we want to return with NoSuchBucket and not
5772 ret
= -ERR_NO_SUCH_BUCKET
;
5784 if (-ENOENT
== ret
) {
5785 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
5788 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
5791 fail_desc_t failed_item
= {
5795 failures
.push_back(failed_item
);
5800 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
5802 fail_desc_t failed_item
= {
5806 failures
.push_back(failed_item
);
5811 if (-ENOENT
== ret
) {
5812 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
5815 fail_desc_t failed_item
= {
5819 failures
.push_back(failed_item
);
5824 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
5826 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
5827 for (auto path
: paths
) {
5828 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
5829 delete_single(path
);
5835 int RGWBulkDelete::verify_permission()
5840 void RGWBulkDelete::pre_exec()
5842 rgw_bucket_object_pre_exec(s
);
5845 void RGWBulkDelete::execute()
5847 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
5849 bool is_truncated
= false;
5851 list
<RGWBulkDelete::acct_path_t
> items
;
5853 int ret
= get_data(items
, &is_truncated
);
5858 ret
= deleter
->delete_chunk(items
);
5859 } while (!op_ret
&& is_truncated
);
5865 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
5867 int RGWBulkUploadOp::verify_permission()
5869 if (s
->auth
.identity
->is_anonymous()) {
5873 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
5877 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
5878 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
5879 << " (user_id.tenant=" << s
->user
->user_id
.tenant
5880 << " requested=" << s
->bucket_tenant
<< ")"
5885 if (s
->user
->max_buckets
< 0) {
5892 void RGWBulkUploadOp::pre_exec()
5894 rgw_bucket_object_pre_exec(s
);
5897 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
5898 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
5900 /* We need to skip all slashes at the beginning in order to preserve
5901 * compliance with Swift. */
5902 const size_t start_pos
= path
.find_first_not_of('/');
5904 if (boost::string_ref::npos
!= start_pos
) {
5905 /* Seperator is the first slash after the leading ones. */
5906 const size_t sep_pos
= path
.substr(start_pos
).find('/');
5908 if (boost::string_ref::npos
!= sep_pos
) {
5909 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
5910 const auto obj_name
= path
.substr(sep_pos
+ 1);
5912 return std::make_pair(bucket_name
.to_string(),
5913 rgw_obj_key(obj_name
.to_string()));
5915 /* It's guaranteed here that bucket name is at least one character
5916 * long and is different than slash. */
5917 return std::make_pair(path
.substr(start_pos
).to_string(),
5925 std::pair
<std::string
, std::string
>
5926 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
5928 std::string bucket_path
, file_prefix
;
5929 if (! s
->init_state
.url_bucket
.empty()) {
5930 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
5931 if (! s
->object
.empty()) {
5932 std::string
& object_name
= s
->object
.name
;
5934 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
5935 * we can safely examine its last element. */
5936 if (object_name
.back() == '/') {
5937 file_prefix
.append(object_name
);
5939 file_prefix
.append(object_name
).append("/");
5943 return std::make_pair(bucket_path
, file_prefix
);
5946 int RGWBulkUploadOp::handle_dir_verify_permission()
5948 if (s
->user
->max_buckets
> 0) {
5949 RGWUserBuckets buckets
;
5951 bool is_truncated
= false;
5952 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
5953 marker
, std::string(), s
->user
->max_buckets
,
5954 false, &is_truncated
);
5959 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
5960 return -ERR_TOO_MANY_BUCKETS
;
5967 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
5969 /* the request of container or object level will contain bucket name.
5970 * only at account level need to append the bucket name */
5971 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
5975 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
5976 info
.script_uri
.append("/").append(bucket_name
);
5977 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
5978 info
.effective_uri
= "/" + bucket_name
;
5981 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
5983 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
5985 op_ret
= handle_dir_verify_permission();
5990 std::string bucket_name
;
5991 rgw_obj_key object_junk
;
5992 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
5994 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
5995 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
5997 /* we need to make sure we read bucket info, it's not read before for this
5998 * specific request */
5999 RGWBucketInfo binfo
;
6000 std::map
<std::string
, ceph::bufferlist
> battrs
;
6001 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6002 binfo
, NULL
, &battrs
);
6003 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6006 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6008 if (bucket_exists
) {
6009 RGWAccessControlPolicy
old_policy(s
->cct
);
6010 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6011 battrs
, &old_policy
);
6013 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6020 RGWBucketInfo master_info
;
6021 rgw_bucket
*pmaster_bucket
= nullptr;
6022 uint32_t *pmaster_num_shards
= nullptr;
6023 real_time creation_time
;
6024 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6026 if (! store
->is_meta_master()) {
6028 ceph::bufferlist in_data
;
6029 req_info info
= s
->info
;
6030 forward_req_info(s
->cct
, info
, bucket_name
);
6031 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6036 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6037 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6038 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6040 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
6041 << objv
.ver
<< dendl
;
6042 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
6045 pmaster_bucket
= &master_info
.bucket
;
6046 creation_time
= master_info
.creation_time
;
6047 pmaster_num_shards
= &master_info
.num_shards
;
6050 pmaster_bucket
= nullptr;
6051 pmaster_num_shards
= nullptr;
6055 std::string placement_rule
;
6056 if (bucket_exists
) {
6057 std::string selected_placement_rule
;
6059 bucket
.tenant
= s
->bucket_tenant
;
6060 bucket
.name
= s
->bucket_name
;
6061 op_ret
= store
->select_bucket_placement(*(s
->user
),
6062 store
->get_zonegroup().get_id(),
6064 &selected_placement_rule
,
6066 if (selected_placement_rule
!= binfo
.placement_rule
) {
6068 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6073 /* Create metadata: ACLs. */
6074 std::map
<std::string
, ceph::bufferlist
> attrs
;
6075 RGWAccessControlPolicy policy
;
6076 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6077 ceph::bufferlist aclbl
;
6078 policy
.encode(aclbl
);
6079 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6081 RGWQuotaInfo quota_info
;
6082 const RGWQuotaInfo
* pquota_info
= nullptr;
6085 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6086 bucket
.name
= bucket_name
;
6089 RGWBucketInfo out_info
;
6090 op_ret
= store
->create_bucket(*(s
->user
),
6092 store
->get_zonegroup().get_id(),
6093 placement_rule
, binfo
.swift_ver_location
,
6095 out_info
, pobjv
, &ep_objv
, creation_time
,
6096 pmaster_bucket
, pmaster_num_shards
, true);
6097 /* continue if EEXIST and create_bucket will fail below. this way we can
6098 * recover from a partial create by retrying it. */
6099 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6100 << ", bucket=" << bucket
<< dendl
;
6102 if (op_ret
&& op_ret
!= -EEXIST
) {
6106 const bool existed
= (op_ret
== -EEXIST
);
6108 /* bucket already existed, might have raced with another bucket creation, or
6109 * might be partial bucket creation that never completed. Read existing bucket
6110 * info, verify that the reported bucket owner is the current user.
6111 * If all is ok then update the user's list of buckets.
6112 * Otherwise inform client about a name conflict.
6114 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6116 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6119 bucket
= out_info
.bucket
;
6122 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6123 out_info
.creation_time
, false);
6124 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6125 /* if it exists (or previously existed), don't remove it! */
6126 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6127 bucket
.tenant
, bucket
.name
);
6129 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6132 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6133 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6135 op_ret
= -ERR_BUCKET_EXISTS
;
6142 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6144 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6145 ACLOwner
& bucket_owner
/* out */)
6147 RGWAccessControlPolicy
bacl(store
->ctx());
6148 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6150 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6155 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6157 bucket_owner
= bacl
.get_owner();
6159 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6160 rgw::IAM::s3PutObject
, obj
);
6161 if (e
== Effect::Allow
) {
6163 } else if (e
== Effect::Deny
) {
6168 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6169 &bacl
, RGW_PERM_WRITE
);
6172 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6174 AlignedStreamGetter
& body
)
6177 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6180 RGWPutObjDataProcessor
*filter
= nullptr;
6181 boost::optional
<RGWPutObj_Compress
> compressor
;
6183 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6184 op_ret
= -ERR_TOO_LARGE
;
6188 std::string bucket_name
;
6190 std::tie(bucket_name
, object
) = *parse_path(path
);
6192 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6193 RGWBucketInfo binfo
;
6194 std::map
<std::string
, ceph::bufferlist
> battrs
;
6196 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6197 bucket_name
, binfo
, nullptr, &battrs
);
6198 if (op_ret
== -ENOENT
) {
6199 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6201 } else if (op_ret
< 0) {
6205 if (! handle_file_verify_permission(binfo
,
6206 rgw_obj(binfo
.bucket
, object
),
6208 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6213 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6214 user_quota
, bucket_quota
, size
);
6219 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6224 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6229 s
->cct
->_conf
->rgw_obj_stripe_size
,
6231 binfo
.versioning_enabled());
6233 /* No filters by default. */
6234 filter
= &processor
;
6236 op_ret
= processor
.prepare(store
, nullptr);
6238 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6243 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6244 binfo
.placement_rule
);
6245 CompressorRef plugin
;
6246 if (compression_type
!= "none") {
6247 plugin
= Compressor::create(s
->cct
, compression_type
);
6249 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6250 << compression_type
<< dendl
;
6252 compressor
.emplace(s
->cct
, plugin
, filter
);
6253 filter
= &*compressor
;
6257 /* Upload file content. */
6262 ceph::bufferlist data
;
6263 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6265 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6269 } else if (len
> 0) {
6270 hash
.Update((const byte
*)data
.c_str(), data
.length());
6271 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6273 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6284 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6289 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6290 user_quota
, bucket_quota
, size
);
6292 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6297 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6302 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6303 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6305 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6307 /* Create metadata: ETAG. */
6308 std::map
<std::string
, ceph::bufferlist
> attrs
;
6309 std::string etag
= calc_md5
;
6310 ceph::bufferlist etag_bl
;
6311 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6312 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6314 /* Create metadata: ACLs. */
6315 RGWAccessControlPolicy policy
;
6316 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6317 ceph::bufferlist aclbl
;
6318 policy
.encode(aclbl
);
6319 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6321 /* Create metadata: compression info. */
6322 if (compressor
&& compressor
->is_compressed()) {
6323 ceph::bufferlist tmp
;
6324 RGWCompressionInfo cs_info
;
6325 cs_info
.compression_type
= plugin
->get_type_name();
6326 cs_info
.orig_size
= s
->obj_size
;
6327 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6328 ::encode(cs_info
, tmp
);
6329 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6332 /* Complete the transaction. */
6333 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6334 ceph::real_time() /* delete_at */);
6336 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6343 void RGWBulkUploadOp::execute()
6345 ceph::bufferlist
buffer(64 * 1024);
6347 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6349 /* Create an instance of stream-abstracting class. Having this indirection
6350 * allows for easy introduction of decompressors like gzip and bzip2. */
6351 auto stream
= create_stream();
6356 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6357 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6358 std::string bucket_path
, file_prefix
;
6359 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6361 auto status
= rgw::tar::StatusIndicator::create();
6363 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6365 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6369 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6370 * must be tracked to detect out end-of-archive. It occurs when both of
6371 * them are empty (zeroed). Tracing this particular inter-block dependency
6372 * is responsibility of the rgw::tar::StatusIndicator class. */
6373 boost::optional
<rgw::tar::HeaderView
> header
;
6374 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6376 if (! status
.empty() && header
) {
6377 /* This specific block isn't empty (entirely zeroed), so we can parse
6378 * it as a TAR header and dispatch. At the moment we do support only
6379 * regular files and directories. Everything else (symlinks, devices)
6380 * will be ignored but won't cease the whole upload. */
6381 switch (header
->get_filetype()) {
6382 case rgw::tar::FileType::NORMAL_FILE
: {
6383 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6385 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6386 file_prefix
+ header
->get_filename().to_string();
6387 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6388 rgw::tar::BLOCK_SIZE
, *stream
);
6389 op_ret
= handle_file(filename
,
6390 header
->get_filesize(),
6393 /* Only regular files counts. */
6396 failures
.emplace_back(op_ret
, filename
.to_string());
6400 case rgw::tar::FileType::DIRECTORY
: {
6401 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6403 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6404 op_ret
= handle_dir(dirname
);
6405 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6406 failures
.emplace_back(op_ret
, dirname
.to_string());
6411 /* Not recognized. Skip. */
6417 /* In case of any problems with sub-request authorization Swift simply
6418 * terminates whole upload immediately. */
6419 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6421 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6426 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6431 } while (! status
.eof());
6436 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6438 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6439 ceph::bufferlist junk
;
6441 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6444 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6445 ceph::bufferlist
& dst
)
6447 const size_t max_to_read
= std::min(want
, length
- position
);
6448 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6455 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6456 ceph::bufferlist
& dst
)
6458 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6465 int RGWSetAttrs::verify_permission()
6467 // This looks to be part of the RGW-NFS machinery and has no S3 or
6468 // Swift equivalent.
6470 if (!s
->object
.empty()) {
6471 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6473 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6481 void RGWSetAttrs::pre_exec()
6483 rgw_bucket_object_pre_exec(s
);
6486 void RGWSetAttrs::execute()
6488 op_ret
= get_params();
6492 rgw_obj
obj(s
->bucket
, s
->object
);
6494 if (!s
->object
.empty()) {
6495 store
->set_atomic(s
->obj_ctx
, obj
);
6496 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6498 for (auto& iter
: attrs
) {
6499 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6501 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6502 &s
->bucket_info
.objv_tracker
);
6506 void RGWGetObjLayout::pre_exec()
6508 rgw_bucket_object_pre_exec(s
);
6511 void RGWGetObjLayout::execute()
6513 rgw_obj
obj(s
->bucket
, s
->object
);
6514 RGWRados::Object
target(store
,
6516 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6517 rgw_obj(s
->bucket
, s
->object
));
6518 RGWRados::Object::Read
stat_op(&target
);
6520 op_ret
= stat_op
.prepare();
6525 head_obj
= stat_op
.state
.head_obj
;
6527 op_ret
= target
.get_manifest(&manifest
);
6531 int RGWConfigBucketMetaSearch::verify_permission()
6533 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6540 void RGWConfigBucketMetaSearch::pre_exec()
6542 rgw_bucket_object_pre_exec(s
);
6545 void RGWConfigBucketMetaSearch::execute()
6547 op_ret
= get_params();
6549 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6553 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6555 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6557 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6562 int RGWGetBucketMetaSearch::verify_permission()
6564 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6571 void RGWGetBucketMetaSearch::pre_exec()
6573 rgw_bucket_object_pre_exec(s
);
6576 int RGWDelBucketMetaSearch::verify_permission()
6578 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6585 void RGWDelBucketMetaSearch::pre_exec()
6587 rgw_bucket_object_pre_exec(s
);
6590 void RGWDelBucketMetaSearch::execute()
6592 s
->bucket_info
.mdsearch_config
.clear();
6594 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6596 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6602 RGWHandler::~RGWHandler()
6606 int RGWHandler::init(RGWRados
*_store
,
6607 struct req_state
*_s
,
6608 rgw::io::BasicClient
*cio
)
6616 int RGWHandler::do_init_permissions()
6618 int ret
= rgw_build_bucket_policies(store
, s
);
6619 s
->env
= rgw_build_iam_environment(store
, s
);
6622 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6623 if (ret
== -ENODATA
)
6630 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6633 /* already read bucket info */
6636 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6639 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6640 << s
->object
<< " only_bucket=" << only_bucket
6641 << " ret=" << ret
<< dendl
;
6642 if (ret
== -ENODATA
)
6649 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6650 return dialect_handler
->error_handler(err_no
, error_content
);
6653 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6654 // This is the do-nothing error handler
6659 void RGWPutBucketPolicy::send_response()
6662 set_req_state_err(s
, op_ret
);
6668 int RGWPutBucketPolicy::verify_permission()
6670 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6677 int RGWPutBucketPolicy::get_params()
6679 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6680 // At some point when I have more time I want to make a version of
6681 // rgw_rest_read_all_input that doesn't use malloc.
6682 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6683 // And throws exceptions.
6687 void RGWPutBucketPolicy::execute()
6689 op_ret
= get_params();
6694 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6696 if (!store
->is_meta_master()) {
6697 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6699 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6705 Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6706 auto attrs
= s
->bucket_attrs
;
6707 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6708 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6709 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6710 &s
->bucket_info
.objv_tracker
);
6711 if (op_ret
== -ECANCELED
) {
6712 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */
6714 } catch (rgw::IAM::PolicyParseException
& e
) {
6715 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6720 void RGWGetBucketPolicy::send_response()
6723 set_req_state_err(s
, op_ret
);
6726 end_header(s
, this, "application/json");
6727 dump_body(s
, policy
);
6730 int RGWGetBucketPolicy::verify_permission()
6732 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6739 void RGWGetBucketPolicy::execute()
6741 auto attrs
= s
->bucket_attrs
;
6742 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6743 if (aiter
== attrs
.end()) {
6744 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6745 << " bucket_name = " << s
->bucket_name
<< dendl
;
6746 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6747 s
->err
.message
= "The bucket policy does not exist";
6750 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6752 if (policy
.length() == 0) {
6753 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6754 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6755 s
->err
.message
= "The bucket policy does not exist";
6761 void RGWDeleteBucketPolicy::send_response()
6764 set_req_state_err(s
, op_ret
);
6770 int RGWDeleteBucketPolicy::verify_permission()
6772 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
6779 void RGWDeleteBucketPolicy::execute()
6781 auto attrs
= s
->bucket_attrs
;
6782 attrs
.erase(RGW_ATTR_IAM_POLICY
);
6783 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6784 &s
->bucket_info
.objv_tracker
);
6785 if (op_ret
== -ECANCELED
) {
6786 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */