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
);
724 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << obj
725 << " ret=" << op_ret
<< dendl
;
729 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
730 if(tags
!= attrs
.end()){
732 tags_bl
.append(tags
->second
);
734 send_response_data(tags_bl
);
737 int RGWPutObjTags::verify_permission()
739 if (!verify_object_permission(s
,
740 s
->object
.instance
.empty() ?
741 rgw::IAM::s3PutObjectTagging
:
742 rgw::IAM::s3PutObjectVersionTagging
))
747 void RGWPutObjTags::execute()
749 op_ret
= get_params();
753 if (s
->object
.empty()){
754 op_ret
= -EINVAL
; // we only support tagging on existing objects
759 obj
= rgw_obj(s
->bucket
, s
->object
);
760 store
->set_atomic(s
->obj_ctx
, obj
);
761 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_TAGS
, tags_bl
);
762 if (op_ret
== -ECANCELED
){
763 op_ret
= -ERR_TAG_CONFLICT
;
767 void RGWDeleteObjTags::pre_exec()
769 rgw_bucket_object_pre_exec(s
);
773 int RGWDeleteObjTags::verify_permission()
775 if (!s
->object
.empty()) {
776 if (!verify_object_permission(s
,
777 s
->object
.instance
.empty() ?
778 rgw::IAM::s3DeleteObjectTagging
:
779 rgw::IAM::s3DeleteObjectVersionTagging
))
785 void RGWDeleteObjTags::execute()
787 if (s
->object
.empty())
791 obj
= rgw_obj(s
->bucket
, s
->object
);
792 store
->set_atomic(s
->obj_ctx
, obj
);
793 map
<string
, bufferlist
> attrs
;
794 map
<string
, bufferlist
> rmattr
;
796 rmattr
[RGW_ATTR_TAGS
] = bl
;
797 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattr
);
800 int RGWOp::do_aws4_auth_completion()
802 ldout(s
->cct
, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl
;
803 if (s
->auth
.completer
) {
804 if (!s
->auth
.completer
->complete()) {
805 return -ERR_AMZ_CONTENT_SHA256_MISMATCH
;
807 dout(10) << "v4 auth ok -- do_aws4_auth_completion" << dendl
;
810 /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first
811 * call passes, so we disable second one. This is old behaviour, sorry!
812 * Plan for tomorrow: seek and destroy. */
813 s
->auth
.completer
= nullptr;
819 int RGWOp::init_quota()
821 /* no quota enforcement for system requests */
822 if (s
->system_request
)
825 /* init quota related stuff */
826 if (!(s
->user
->op_mask
& RGW_OP_TYPE_MODIFY
)) {
830 /* only interested in object related ops */
831 if (s
->object
.empty()) {
835 RGWUserInfo owner_info
;
838 if (s
->user
->user_id
== s
->bucket_owner
.get_id()) {
841 int r
= rgw_get_user_info_by_uid(store
, s
->bucket_info
.owner
, owner_info
);
847 if (s
->bucket_info
.quota
.enabled
) {
848 bucket_quota
= s
->bucket_info
.quota
;
849 } else if (uinfo
->bucket_quota
.enabled
) {
850 bucket_quota
= uinfo
->bucket_quota
;
852 bucket_quota
= store
->get_bucket_quota();
855 if (uinfo
->user_quota
.enabled
) {
856 user_quota
= uinfo
->user_quota
;
858 user_quota
= store
->get_user_quota();
864 static bool validate_cors_rule_method(RGWCORSRule
*rule
, const char *req_meth
) {
868 dout(5) << "req_meth is null" << dendl
;
872 if (strcmp(req_meth
, "GET") == 0) flags
= RGW_CORS_GET
;
873 else if (strcmp(req_meth
, "POST") == 0) flags
= RGW_CORS_POST
;
874 else if (strcmp(req_meth
, "PUT") == 0) flags
= RGW_CORS_PUT
;
875 else if (strcmp(req_meth
, "DELETE") == 0) flags
= RGW_CORS_DELETE
;
876 else if (strcmp(req_meth
, "HEAD") == 0) flags
= RGW_CORS_HEAD
;
878 if ((rule
->get_allowed_methods() & flags
) == flags
) {
879 dout(10) << "Method " << req_meth
<< " is supported" << dendl
;
881 dout(5) << "Method " << req_meth
<< " is not supported" << dendl
;
888 int RGWOp::read_bucket_cors()
892 map
<string
, bufferlist
>::iterator aiter
= s
->bucket_attrs
.find(RGW_ATTR_CORS
);
893 if (aiter
== s
->bucket_attrs
.end()) {
894 ldout(s
->cct
, 20) << "no CORS configuration attr found" << dendl
;
896 return 0; /* no CORS configuration found */
903 bufferlist::iterator iter
= bl
.begin();
905 bucket_cors
.decode(iter
);
906 } catch (buffer::error
& err
) {
907 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
910 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
911 RGWCORSConfiguration_S3
*s3cors
= static_cast<RGWCORSConfiguration_S3
*>(&bucket_cors
);
912 ldout(s
->cct
, 15) << "Read RGWCORSConfiguration";
913 s3cors
->to_xml(*_dout
);
920 * If any of the header field-names is not a ASCII case-insensitive match for
921 * any of the values in list of headers do not set any additional headers and
922 * terminate this set of steps.
924 static void get_cors_response_headers(RGWCORSRule
*rule
, const char *req_hdrs
, string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
927 get_str_list(req_hdrs
, hl
);
928 for(list
<string
>::iterator it
= hl
.begin(); it
!= hl
.end(); ++it
) {
929 if (!rule
->is_header_allowed((*it
).c_str(), (*it
).length())) {
930 dout(5) << "Header " << (*it
) << " is not registered in this rule" << dendl
;
932 if (hdrs
.length() > 0) hdrs
.append(",");
937 rule
->format_exp_headers(exp_hdrs
);
938 *max_age
= rule
->get_max_age();
942 * Generate the CORS header response
944 * This is described in the CORS standard, section 6.2.
946 bool RGWOp::generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
)
949 const char *orig
= s
->info
.env
->get("HTTP_ORIGIN");
956 op_ret
= read_bucket_cors();
962 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
967 RGWCORSRule
*rule
= bucket_cors
.host_name_rule(orig
);
972 * Set the Allowed-Origin header to a asterisk if this is allowed in the rule
973 * and no Authorization was send by the client
975 * The origin parameter specifies a URI that may access the resource. The browser must enforce this.
976 * For requests without credentials, the server may specify "*" as a wildcard,
977 * thereby allowing any origin to access the resource.
979 const char *authorization
= s
->info
.env
->get("HTTP_AUTHORIZATION");
980 if (!authorization
&& rule
->has_wildcard_origin())
984 const char *req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
986 req_meth
= s
->info
.method
;
992 if (!validate_cors_rule_method(rule
, req_meth
)) {
998 const char *req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
1001 get_cors_response_headers(rule
, req_hdrs
, headers
, exp_headers
, max_age
);
1006 int RGWGetObj::read_user_manifest_part(rgw_bucket
& bucket
,
1007 const rgw_bucket_dir_entry
& ent
,
1008 RGWAccessControlPolicy
* const bucket_acl
,
1009 const optional
<Policy
>& bucket_policy
,
1010 const off_t start_ofs
,
1011 const off_t end_ofs
)
1013 ldout(s
->cct
, 20) << "user manifest obj=" << ent
.key
.name
<< "[" << ent
.key
.instance
<< "]" << dendl
;
1014 RGWGetObj_CB
cb(this);
1015 RGWGetDataCB
* filter
= &cb
;
1016 boost::optional
<RGWGetObj_Decompress
> decompress
;
1018 int64_t cur_ofs
= start_ofs
;
1019 int64_t cur_end
= end_ofs
;
1021 rgw_obj
part(bucket
, ent
.key
);
1023 map
<string
, bufferlist
> attrs
;
1026 RGWObjectCtx
obj_ctx(store
);
1027 RGWAccessControlPolicy
obj_policy(s
->cct
);
1029 ldout(s
->cct
, 20) << "reading obj=" << part
<< " ofs=" << cur_ofs
<< " end=" << cur_end
<< dendl
;
1031 obj_ctx
.obj
.set_atomic(part
);
1032 store
->set_prefetch_data(&obj_ctx
, part
);
1034 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, part
);
1035 RGWRados::Object::Read
read_op(&op_target
);
1037 read_op
.conds
.if_match
= ent
.meta
.etag
.c_str();
1038 read_op
.params
.attrs
= &attrs
;
1039 read_op
.params
.obj_size
= &obj_size
;
1041 op_ret
= read_op
.prepare();
1044 op_ret
= read_op
.range_to_ofs(ent
.meta
.accounted_size
, cur_ofs
, cur_end
);
1047 bool need_decompress
;
1048 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1050 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1054 if (need_decompress
)
1056 if (cs_info
.orig_size
!= ent
.meta
.accounted_size
) {
1057 // hmm.. something wrong, object not as expected, abort!
1058 ldout(s
->cct
, 0) << "ERROR: expected cs_info.orig_size=" << cs_info
.orig_size
<<
1059 ", actual read size=" << ent
.meta
.size
<< dendl
;
1062 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1063 filter
= &*decompress
;
1067 if (obj_size
!= ent
.meta
.size
) {
1068 // hmm.. something wrong, object not as expected, abort!
1069 ldout(s
->cct
, 0) << "ERROR: expected obj_size=" << obj_size
<< ", actual read size=" << ent
.meta
.size
<< dendl
;
1074 op_ret
= rgw_policy_from_attrset(s
->cct
, attrs
, &obj_policy
);
1078 /* We can use global user_acl because LOs cannot have segments
1079 * stored inside different accounts. */
1080 if (s
->system_request
) {
1081 ldout(s
->cct
, 2) << "overriding permissions due to system operation" << dendl
;
1082 } else if (s
->auth
.identity
->is_admin_of(s
->user
->user_id
)) {
1083 ldout(s
->cct
, 2) << "overriding permissions due to admin operation" << dendl
;
1084 } else if (!verify_object_permission(s
, part
, s
->user_acl
.get(), bucket_acl
,
1085 &obj_policy
, bucket_policy
, action
)) {
1089 if (ent
.meta
.size
== 0) {
1093 perfcounter
->inc(l_rgw_get_b
, cur_end
- cur_ofs
);
1094 filter
->fixup_range(cur_ofs
, cur_end
);
1095 op_ret
= read_op
.iterate(cur_ofs
, cur_end
, filter
);
1097 op_ret
= filter
->flush();
1101 static int iterate_user_manifest_parts(CephContext
* const cct
,
1102 RGWRados
* const store
,
1105 RGWBucketInfo
*pbucket_info
,
1106 const string
& obj_prefix
,
1107 RGWAccessControlPolicy
* const bucket_acl
,
1108 const optional
<Policy
>& bucket_policy
,
1109 uint64_t * const ptotal_len
,
1110 uint64_t * const pobj_size
,
1111 string
* const pobj_sum
,
1112 int (*cb
)(rgw_bucket
& bucket
,
1113 const rgw_bucket_dir_entry
& ent
,
1114 RGWAccessControlPolicy
* const bucket_acl
,
1115 const optional
<Policy
>& bucket_policy
,
1119 void * const cb_param
)
1121 rgw_bucket
& bucket
= pbucket_info
->bucket
;
1122 uint64_t obj_ofs
= 0, len_count
= 0;
1123 bool found_start
= false, found_end
= false, handled_end
= false;
1126 vector
<rgw_bucket_dir_entry
> objs
;
1128 utime_t start_time
= ceph_clock_now();
1130 RGWRados::Bucket
target(store
, *pbucket_info
);
1131 RGWRados::Bucket::List
list_op(&target
);
1133 list_op
.params
.prefix
= obj_prefix
;
1134 list_op
.params
.delim
= delim
;
1138 #define MAX_LIST_OBJS 100
1139 int r
= list_op
.list_objects(MAX_LIST_OBJS
, &objs
, NULL
, &is_truncated
);
1144 for (rgw_bucket_dir_entry
& ent
: objs
) {
1145 const uint64_t cur_total_len
= obj_ofs
;
1146 const uint64_t obj_size
= ent
.meta
.accounted_size
;
1147 uint64_t start_ofs
= 0, end_ofs
= obj_size
;
1149 if ((ptotal_len
|| cb
) && !found_start
&& cur_total_len
+ obj_size
> (uint64_t)ofs
) {
1150 start_ofs
= ofs
- obj_ofs
;
1154 obj_ofs
+= obj_size
;
1156 etag_sum
.Update((const byte
*)ent
.meta
.etag
.c_str(),
1157 ent
.meta
.etag
.length());
1160 if ((ptotal_len
|| cb
) && !found_end
&& obj_ofs
> (uint64_t)end
) {
1161 end_ofs
= end
- cur_total_len
+ 1;
1165 perfcounter
->tinc(l_rgw_get_lat
,
1166 (ceph_clock_now() - start_time
));
1168 if (found_start
&& !handled_end
) {
1169 len_count
+= end_ofs
- start_ofs
;
1172 r
= cb(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
, cb_param
);
1179 handled_end
= found_end
;
1180 start_time
= ceph_clock_now();
1182 } while (is_truncated
);
1185 *ptotal_len
= len_count
;
1188 *pobj_size
= obj_ofs
;
1191 complete_etag(etag_sum
, pobj_sum
);
1197 struct rgw_slo_part
{
1198 RGWAccessControlPolicy
*bucket_acl
= nullptr;
1199 Policy
* bucket_policy
= nullptr;
1206 static int iterate_slo_parts(CephContext
*cct
,
1210 map
<uint64_t, rgw_slo_part
>& slo_parts
,
1211 int (*cb
)(rgw_bucket
& bucket
,
1212 const rgw_bucket_dir_entry
& ent
,
1213 RGWAccessControlPolicy
*bucket_acl
,
1214 const optional
<Policy
>& bucket_policy
,
1220 bool found_start
= false, found_end
= false;
1222 if (slo_parts
.empty()) {
1226 utime_t start_time
= ceph_clock_now();
1228 map
<uint64_t, rgw_slo_part
>::iterator iter
= slo_parts
.upper_bound(ofs
);
1229 if (iter
!= slo_parts
.begin()) {
1233 uint64_t obj_ofs
= iter
->first
;
1235 for (; iter
!= slo_parts
.end() && !found_end
; ++iter
) {
1236 rgw_slo_part
& part
= iter
->second
;
1237 rgw_bucket_dir_entry ent
;
1239 ent
.key
.name
= part
.obj_name
;
1240 ent
.meta
.accounted_size
= ent
.meta
.size
= part
.size
;
1241 ent
.meta
.etag
= part
.etag
;
1243 uint64_t cur_total_len
= obj_ofs
;
1244 uint64_t start_ofs
= 0, end_ofs
= ent
.meta
.size
;
1246 if (!found_start
&& cur_total_len
+ ent
.meta
.size
> (uint64_t)ofs
) {
1247 start_ofs
= ofs
- obj_ofs
;
1251 obj_ofs
+= ent
.meta
.size
;
1253 if (!found_end
&& obj_ofs
> (uint64_t)end
) {
1254 end_ofs
= end
- cur_total_len
+ 1;
1258 perfcounter
->tinc(l_rgw_get_lat
,
1259 (ceph_clock_now() - start_time
));
1263 // SLO is a Swift thing, and Swift has no knowledge of S3 Policies.
1264 int r
= cb(part
.bucket
, ent
, part
.bucket_acl
,
1265 (part
.bucket_policy
?
1266 optional
<Policy
>(*part
.bucket_policy
) : none
),
1267 start_ofs
, end_ofs
, cb_param
);
1273 start_time
= ceph_clock_now();
1279 static int get_obj_user_manifest_iterate_cb(rgw_bucket
& bucket
,
1280 const rgw_bucket_dir_entry
& ent
,
1281 RGWAccessControlPolicy
* const bucket_acl
,
1282 const optional
<Policy
>& bucket_policy
,
1283 const off_t start_ofs
,
1284 const off_t end_ofs
,
1287 RGWGetObj
*op
= static_cast<RGWGetObj
*>(param
);
1288 return op
->read_user_manifest_part(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
);
1291 int RGWGetObj::handle_user_manifest(const char *prefix
)
1293 const boost::string_view
prefix_view(prefix
);
1294 ldout(s
->cct
, 2) << "RGWGetObj::handle_user_manifest() prefix="
1295 << prefix_view
<< dendl
;
1297 const size_t pos
= prefix_view
.find('/');
1298 if (pos
== string::npos
) {
1302 const std::string bucket_name
= url_decode(prefix_view
.substr(0, pos
));
1303 const std::string obj_prefix
= url_decode(prefix_view
.substr(pos
+ 1));
1307 RGWAccessControlPolicy
_bucket_acl(s
->cct
);
1308 RGWAccessControlPolicy
*bucket_acl
;
1309 optional
<Policy
> _bucket_policy
;
1310 optional
<Policy
>* bucket_policy
;
1311 RGWBucketInfo bucket_info
;
1312 RGWBucketInfo
*pbucket_info
;
1314 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1315 map
<string
, bufferlist
> bucket_attrs
;
1316 RGWObjectCtx
obj_ctx(store
);
1317 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1318 bucket_name
, bucket_info
, NULL
,
1321 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1322 << bucket_name
<< dendl
;
1325 bucket
= bucket_info
.bucket
;
1326 pbucket_info
= &bucket_info
;
1327 bucket_acl
= &_bucket_acl
;
1328 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
, bucket
);
1330 ldout(s
->cct
, 0) << "failed to read bucket policy" << dendl
;
1333 _bucket_policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
,
1334 bucket_info
.bucket
.tenant
);
1335 bucket_policy
= &_bucket_policy
;
1338 pbucket_info
= &s
->bucket_info
;
1339 bucket_acl
= s
->bucket_acl
.get();
1340 bucket_policy
= &s
->iam_policy
;
1343 /* dry run to find out:
1344 * - total length (of the parts we are going to send to client),
1345 * - overall DLO's content size,
1346 * - md5 sum of overall DLO's content (for etag of Swift API). */
1347 int r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1348 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1349 nullptr, &s
->obj_size
, &lo_etag
,
1350 nullptr /* cb */, nullptr /* cb arg */);
1355 r
= RGWRados::Object::Read::range_to_ofs(s
->obj_size
, ofs
, end
);
1360 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1361 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1362 &total_len
, nullptr, nullptr,
1370 send_response_data(bl
, 0, 0);
1374 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1375 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1376 nullptr, nullptr, nullptr,
1377 get_obj_user_manifest_iterate_cb
, (void *)this);
1384 send_response_data(bl
, 0, 0);
1390 int RGWGetObj::handle_slo_manifest(bufferlist
& bl
)
1392 RGWSLOInfo slo_info
;
1393 bufferlist::iterator bliter
= bl
.begin();
1395 ::decode(slo_info
, bliter
);
1396 } catch (buffer::error
& err
) {
1397 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
1400 ldout(s
->cct
, 2) << "RGWGetObj::handle_slo_manifest()" << dendl
;
1402 vector
<RGWAccessControlPolicy
> allocated_acls
;
1403 map
<string
, pair
<RGWAccessControlPolicy
*, optional
<Policy
>>> policies
;
1404 map
<string
, rgw_bucket
> buckets
;
1406 map
<uint64_t, rgw_slo_part
> slo_parts
;
1411 for (const auto& entry
: slo_info
.entries
) {
1412 const string
& path
= entry
.path
;
1414 /* If the path starts with slashes, strip them all. */
1415 const size_t pos_init
= path
.find_first_not_of('/');
1416 /* According to the documentation of std::string::find following check
1417 * is not necessary as we should get the std::string::npos propagation
1418 * here. This might be true with the accuracy to implementation's bugs.
1419 * See following question on SO:
1420 * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos
1422 if (pos_init
== string::npos
) {
1426 const size_t pos_sep
= path
.find('/', pos_init
);
1427 if (pos_sep
== string::npos
) {
1431 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
1432 string obj_name
= path
.substr(pos_sep
+ 1);
1435 RGWAccessControlPolicy
*bucket_acl
;
1436 Policy
* bucket_policy
;
1438 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1439 const auto& piter
= policies
.find(bucket_name
);
1440 if (piter
!= policies
.end()) {
1441 bucket_acl
= piter
->second
.first
;
1442 bucket_policy
= piter
->second
.second
.get_ptr();
1443 bucket
= buckets
[bucket_name
];
1445 allocated_acls
.push_back(RGWAccessControlPolicy(s
->cct
));
1446 RGWAccessControlPolicy
& _bucket_acl
= allocated_acls
.back();
1448 RGWBucketInfo bucket_info
;
1449 map
<string
, bufferlist
> bucket_attrs
;
1450 RGWObjectCtx
obj_ctx(store
);
1451 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1452 bucket_name
, bucket_info
, nullptr,
1455 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1456 << bucket_name
<< dendl
;
1459 bucket
= bucket_info
.bucket
;
1460 bucket_acl
= &_bucket_acl
;
1461 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
,
1464 ldout(s
->cct
, 0) << "failed to read bucket ACL for bucket "
1468 auto _bucket_policy
= get_iam_policy_from_attr(
1469 s
->cct
, store
, bucket_attrs
, bucket_info
.bucket
.tenant
);
1470 bucket_policy
= _bucket_policy
.get_ptr();
1471 buckets
[bucket_name
] = bucket
;
1472 policies
[bucket_name
] = make_pair(bucket_acl
, _bucket_policy
);
1476 bucket_acl
= s
->bucket_acl
.get();
1477 bucket_policy
= s
->iam_policy
.get_ptr();
1481 part
.bucket_acl
= bucket_acl
;
1482 part
.bucket_policy
= bucket_policy
;
1483 part
.bucket
= bucket
;
1484 part
.obj_name
= obj_name
;
1485 part
.size
= entry
.size_bytes
;
1486 part
.etag
= entry
.etag
;
1487 ldout(s
->cct
, 20) << "slo_part: ofs=" << ofs
1488 << " bucket=" << part
.bucket
1489 << " obj=" << part
.obj_name
1490 << " size=" << part
.size
1491 << " etag=" << part
.etag
1494 etag_sum
.Update((const byte
*)entry
.etag
.c_str(),
1495 entry
.etag
.length());
1497 slo_parts
[total_len
] = part
;
1498 total_len
+= part
.size
;
1501 complete_etag(etag_sum
, &lo_etag
);
1503 s
->obj_size
= slo_info
.total_size
;
1504 ldout(s
->cct
, 20) << "s->obj_size=" << s
->obj_size
<< dendl
;
1506 int r
= RGWRados::Object::Read::range_to_ofs(total_len
, ofs
, end
);
1511 total_len
= end
- ofs
+ 1;
1513 r
= iterate_slo_parts(s
->cct
, store
, ofs
, end
, slo_parts
,
1514 get_obj_user_manifest_iterate_cb
, (void *)this);
1522 int RGWGetObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
1524 /* garbage collection related handling */
1525 utime_t start_time
= ceph_clock_now();
1526 if (start_time
> gc_invalidate_time
) {
1527 int r
= store
->defer_gc(s
->obj_ctx
, s
->bucket_info
, obj
);
1529 dout(0) << "WARNING: could not defer gc entry for obj" << dendl
;
1531 gc_invalidate_time
= start_time
;
1532 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1534 return send_response_data(bl
, bl_ofs
, bl_len
);
1537 bool RGWGetObj::prefetch_data()
1539 /* HEAD request, stop prefetch*/
1544 bool prefetch_first_chunk
= true;
1545 range_str
= s
->info
.env
->get("HTTP_RANGE");
1548 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1549 /* error on parsing the range, stop prefetch and will fail in execte() */
1551 range_parsed
= false;
1554 range_parsed
= true;
1556 /* range get goes to shadown objects, stop prefetch */
1557 if (ofs
>= s
->cct
->_conf
->rgw_max_chunk_size
) {
1558 prefetch_first_chunk
= false;
1562 return get_data
&& prefetch_first_chunk
;
1564 void RGWGetObj::pre_exec()
1566 rgw_bucket_object_pre_exec(s
);
1569 static bool object_is_expired(map
<string
, bufferlist
>& attrs
) {
1570 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1571 if (iter
!= attrs
.end()) {
1574 ::decode(delete_at
, iter
->second
);
1575 } catch (buffer::error
& err
) {
1576 dout(0) << "ERROR: " << __func__
<< ": failed to decode " RGW_ATTR_DELETE_AT
" attr" << dendl
;
1580 if (delete_at
<= ceph_clock_now() && !delete_at
.is_zero()) {
1588 void RGWGetObj::execute()
1590 utime_t start_time
= s
->time
;
1592 gc_invalidate_time
= ceph_clock_now();
1593 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1595 bool need_decompress
;
1596 int64_t ofs_x
, end_x
;
1598 RGWGetObj_CB
cb(this);
1599 RGWGetDataCB
* filter
= (RGWGetDataCB
*)&cb
;
1600 boost::optional
<RGWGetObj_Decompress
> decompress
;
1601 std::unique_ptr
<RGWGetDataCB
> decrypt
;
1602 map
<string
, bufferlist
>::iterator attr_iter
;
1604 perfcounter
->inc(l_rgw_get
);
1606 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
1607 RGWRados::Object::Read
read_op(&op_target
);
1609 op_ret
= get_params();
1613 op_ret
= init_common();
1617 read_op
.conds
.mod_ptr
= mod_ptr
;
1618 read_op
.conds
.unmod_ptr
= unmod_ptr
;
1619 read_op
.conds
.high_precision_time
= s
->system_request
; /* system request need to use high precision time */
1620 read_op
.conds
.mod_zone_id
= mod_zone_id
;
1621 read_op
.conds
.mod_pg_ver
= mod_pg_ver
;
1622 read_op
.conds
.if_match
= if_match
;
1623 read_op
.conds
.if_nomatch
= if_nomatch
;
1624 read_op
.params
.attrs
= &attrs
;
1625 read_op
.params
.lastmod
= &lastmod
;
1626 read_op
.params
.obj_size
= &s
->obj_size
;
1628 op_ret
= read_op
.prepare();
1631 version_id
= read_op
.state
.obj
.key
.instance
;
1633 /* STAT ops don't need data, and do no i/o */
1634 if (get_type() == RGW_OP_STAT_OBJ
) {
1638 /* start gettorrent */
1639 if (torrent
.get_flag())
1641 torrent
.init(s
, store
);
1642 torrent
.get_torrent_file(op_ret
, read_op
, total_len
, bl
, obj
);
1645 ldout(s
->cct
, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
1649 op_ret
= send_response_data(bl
, 0, total_len
);
1652 ldout(s
->cct
, 0) << "ERROR: failed to send_response_data ret= " << op_ret
1658 /* end gettorrent */
1660 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1662 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1665 if (need_decompress
) {
1666 s
->obj_size
= cs_info
.orig_size
;
1667 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1668 filter
= &*decompress
;
1671 attr_iter
= attrs
.find(RGW_ATTR_USER_MANIFEST
);
1672 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1673 op_ret
= handle_user_manifest(attr_iter
->second
.c_str());
1675 ldout(s
->cct
, 0) << "ERROR: failed to handle user manifest ret="
1682 attr_iter
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
1683 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1685 op_ret
= handle_slo_manifest(attr_iter
->second
);
1687 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
1694 // for range requests with obj size 0
1695 if (range_str
&& !(s
->obj_size
)) {
1701 op_ret
= read_op
.range_to_ofs(s
->obj_size
, ofs
, end
);
1704 total_len
= (ofs
<= end
? end
+ 1 - ofs
: 0);
1706 /* Check whether the object has expired. Swift API documentation
1707 * stands that we should return 404 Not Found in such case. */
1708 if (need_object_expiration() && object_is_expired(attrs
)) {
1715 /* STAT ops don't need data, and do no i/o */
1716 if (get_type() == RGW_OP_STAT_OBJ
) {
1720 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1721 op_ret
= this->get_decrypt_filter(&decrypt
, filter
,
1722 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
1723 if (decrypt
!= nullptr) {
1724 filter
= decrypt
.get();
1730 if (!get_data
|| ofs
> end
) {
1731 send_response_data(bl
, 0, 0);
1735 perfcounter
->inc(l_rgw_get_b
, end
- ofs
);
1739 filter
->fixup_range(ofs_x
, end_x
);
1740 op_ret
= read_op
.iterate(ofs_x
, end_x
, filter
);
1743 op_ret
= filter
->flush();
1745 perfcounter
->tinc(l_rgw_get_lat
,
1746 (ceph_clock_now() - start_time
));
1751 op_ret
= send_response_data(bl
, 0, 0);
1758 send_response_data_error();
1761 int RGWGetObj::init_common()
1764 /* range parsed error when prefetch*/
1765 if (!range_parsed
) {
1766 int r
= parse_range(range_str
, ofs
, end
, &partial_content
);
1772 if (parse_time(if_mod
, &mod_time
) < 0)
1774 mod_ptr
= &mod_time
;
1778 if (parse_time(if_unmod
, &unmod_time
) < 0)
1780 unmod_ptr
= &unmod_time
;
1786 int RGWListBuckets::verify_permission()
1788 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1795 int RGWGetUsage::verify_permission()
1797 if (s
->auth
.identity
->is_anonymous()) {
1804 void RGWListBuckets::execute()
1807 bool started
= false;
1808 uint64_t total_count
= 0;
1810 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1812 op_ret
= get_params();
1817 if (supports_account_metadata()) {
1818 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, attrs
);
1824 is_truncated
= false;
1826 RGWUserBuckets buckets
;
1827 uint64_t read_count
;
1829 read_count
= min(limit
- total_count
, (uint64_t)max_buckets
);
1831 read_count
= max_buckets
;
1834 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
1835 marker
, end_marker
, read_count
,
1836 should_get_stats(), &is_truncated
,
1839 /* hmm.. something wrong here.. the user was authenticated, so it
1841 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1842 << s
->user
->user_id
<< dendl
;
1845 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1846 map
<string
, RGWBucketEnt
>::iterator iter
;
1847 for (iter
= m
.begin(); iter
!= m
.end(); ++iter
) {
1848 RGWBucketEnt
& bucket
= iter
->second
;
1849 buckets_size
+= bucket
.size
;
1850 buckets_size_rounded
+= bucket
.size_rounded
;
1851 buckets_objcount
+= bucket
.count
;
1853 buckets_count
+= m
.size();
1854 total_count
+= m
.size();
1856 done
= (m
.size() < read_count
|| (limit
>= 0 && total_count
>= (uint64_t)limit
));
1859 send_response_begin(buckets
.count() > 0);
1864 send_response_data(buckets
);
1866 map
<string
, RGWBucketEnt
>::reverse_iterator riter
= m
.rbegin();
1867 marker
= riter
->first
;
1869 } while (is_truncated
&& !done
);
1873 send_response_begin(false);
1875 send_response_end();
1878 void RGWGetUsage::execute()
1880 uint64_t start_epoch
= 0;
1881 uint64_t end_epoch
= (uint64_t)-1;
1882 op_ret
= get_params();
1886 if (!start_date
.empty()) {
1887 op_ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
1889 ldout(store
->ctx(), 0) << "ERROR: failed to parse start date" << dendl
;
1894 if (!end_date
.empty()) {
1895 op_ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
1897 ldout(store
->ctx(), 0) << "ERROR: failed to parse end date" << dendl
;
1902 uint32_t max_entries
= 1000;
1904 bool is_truncated
= true;
1906 RGWUsageIter usage_iter
;
1908 while (is_truncated
) {
1909 op_ret
= store
->read_usage(s
->user
->user_id
, start_epoch
, end_epoch
, max_entries
,
1910 &is_truncated
, usage_iter
, usage
);
1912 if (op_ret
== -ENOENT
) {
1914 is_truncated
= false;
1922 op_ret
= rgw_user_sync_all_stats(store
, s
->user
->user_id
);
1924 ldout(store
->ctx(), 0) << "ERROR: failed to sync user stats: " << dendl
;
1928 op_ret
= rgw_user_get_all_buckets_stats(store
, s
->user
->user_id
, buckets_usage
);
1930 cerr
<< "ERROR: failed to sync user stats: " << std::endl
;
1934 string user_str
= s
->user
->user_id
.to_str();
1935 op_ret
= store
->cls_user_get_header(user_str
, &header
);
1937 ldout(store
->ctx(), 0) << "ERROR: can't read user header: " << dendl
;
1944 int RGWStatAccount::verify_permission()
1946 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1953 void RGWStatAccount::execute()
1956 bool is_truncated
= false;
1957 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1960 RGWUserBuckets buckets
;
1962 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
, marker
,
1963 string(), max_buckets
, true, &is_truncated
);
1965 /* hmm.. something wrong here.. the user was authenticated, so it
1967 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1968 << s
->user
->user_id
<< dendl
;
1971 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1972 map
<string
, RGWBucketEnt
>::iterator iter
;
1973 for (iter
= m
.begin(); iter
!= m
.end(); ++iter
) {
1974 RGWBucketEnt
& bucket
= iter
->second
;
1975 buckets_size
+= bucket
.size
;
1976 buckets_size_rounded
+= bucket
.size_rounded
;
1977 buckets_objcount
+= bucket
.count
;
1979 marker
= iter
->first
;
1981 buckets_count
+= m
.size();
1984 } while (is_truncated
);
1987 int RGWGetBucketVersioning::verify_permission()
1989 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
1996 void RGWGetBucketVersioning::pre_exec()
1998 rgw_bucket_object_pre_exec(s
);
2001 void RGWGetBucketVersioning::execute()
2003 versioned
= s
->bucket_info
.versioned();
2004 versioning_enabled
= s
->bucket_info
.versioning_enabled();
2007 int RGWSetBucketVersioning::verify_permission()
2009 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2016 void RGWSetBucketVersioning::pre_exec()
2018 rgw_bucket_object_pre_exec(s
);
2021 void RGWSetBucketVersioning::execute()
2023 op_ret
= get_params();
2027 if (!store
->is_meta_master()) {
2028 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2030 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
2035 if (enable_versioning
) {
2036 s
->bucket_info
.flags
|= BUCKET_VERSIONED
;
2037 s
->bucket_info
.flags
&= ~BUCKET_VERSIONS_SUSPENDED
;
2039 s
->bucket_info
.flags
|= (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
);
2042 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
2045 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2046 << " returned err=" << op_ret
<< dendl
;
2051 int RGWGetBucketWebsite::verify_permission()
2053 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2059 void RGWGetBucketWebsite::pre_exec()
2061 rgw_bucket_object_pre_exec(s
);
2064 void RGWGetBucketWebsite::execute()
2066 if (!s
->bucket_info
.has_website
) {
2071 int RGWSetBucketWebsite::verify_permission()
2073 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2079 void RGWSetBucketWebsite::pre_exec()
2081 rgw_bucket_object_pre_exec(s
);
2084 void RGWSetBucketWebsite::execute()
2086 op_ret
= get_params();
2091 if (!store
->is_meta_master()) {
2092 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2094 ldout(s
->cct
, 20) << __func__
<< " forward_request_to_master returned ret=" << op_ret
<< dendl
;
2099 s
->bucket_info
.has_website
= true;
2100 s
->bucket_info
.website_conf
= website_conf
;
2102 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
2104 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2109 int RGWDeleteBucketWebsite::verify_permission()
2111 if (s
->user
->user_id
.compare(s
->bucket_owner
.get_id()) != 0)
2117 void RGWDeleteBucketWebsite::pre_exec()
2119 rgw_bucket_object_pre_exec(s
);
2122 void RGWDeleteBucketWebsite::execute()
2124 s
->bucket_info
.has_website
= false;
2125 s
->bucket_info
.website_conf
= RGWBucketWebsiteConf();
2127 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
2129 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2134 int RGWStatBucket::verify_permission()
2136 // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission.
2137 if (!verify_bucket_permission(s
, rgw::IAM::s3ListBucket
)) {
2144 void RGWStatBucket::pre_exec()
2146 rgw_bucket_object_pre_exec(s
);
2149 void RGWStatBucket::execute()
2151 if (!s
->bucket_exists
) {
2152 op_ret
= -ERR_NO_SUCH_BUCKET
;
2156 RGWUserBuckets buckets
;
2157 bucket
.bucket
= s
->bucket
;
2158 buckets
.add(bucket
);
2159 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2160 op_ret
= store
->update_containers_stats(m
);
2165 map
<string
, RGWBucketEnt
>::iterator iter
= m
.find(bucket
.bucket
.name
);
2166 if (iter
!= m
.end()) {
2167 bucket
= iter
->second
;
2174 int RGWListBucket::verify_permission()
2176 op_ret
= get_params();
2181 if (!verify_bucket_permission(s
,
2183 rgw::IAM::s3ListBucketVersions
:
2184 rgw::IAM::s3ListBucket
)) {
2191 int RGWListBucket::parse_max_keys()
2193 if (!max_keys
.empty()) {
2195 max
= strtol(max_keys
.c_str(), &endptr
, 10);
2197 while (*endptr
&& isspace(*endptr
)) // ignore white space
2210 void RGWListBucket::pre_exec()
2212 rgw_bucket_object_pre_exec(s
);
2215 void RGWListBucket::execute()
2217 if (!s
->bucket_exists
) {
2218 op_ret
= -ERR_NO_SUCH_BUCKET
;
2222 if (need_container_stats()) {
2223 map
<string
, RGWBucketEnt
> m
;
2224 m
[s
->bucket
.name
] = RGWBucketEnt();
2225 m
.begin()->second
.bucket
= s
->bucket
;
2226 op_ret
= store
->update_containers_stats(m
);
2228 bucket
= m
.begin()->second
;
2232 RGWRados::Bucket
target(store
, s
->bucket_info
);
2233 if (shard_id
>= 0) {
2234 target
.set_shard_id(shard_id
);
2236 RGWRados::Bucket::List
list_op(&target
);
2238 list_op
.params
.prefix
= prefix
;
2239 list_op
.params
.delim
= delimiter
;
2240 list_op
.params
.marker
= marker
;
2241 list_op
.params
.end_marker
= end_marker
;
2242 list_op
.params
.list_versions
= list_versions
;
2244 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2246 next_marker
= list_op
.get_next_marker();
2250 int RGWGetBucketLogging::verify_permission()
2252 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2259 int RGWGetBucketLocation::verify_permission()
2261 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
2268 int RGWCreateBucket::verify_permission()
2270 /* This check is mostly needed for S3 that doesn't support account ACL.
2271 * Swift doesn't allow to delegate any permission to an anonymous user,
2272 * so it will become an early exit in such case. */
2273 if (s
->auth
.identity
->is_anonymous()) {
2277 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
2281 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2282 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
2283 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2284 << " requested=" << s
->bucket_tenant
<< ")"
2288 if (s
->user
->max_buckets
< 0) {
2292 if (s
->user
->max_buckets
) {
2293 RGWUserBuckets buckets
;
2295 bool is_truncated
= false;
2296 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2297 marker
, string(), s
->user
->max_buckets
,
2298 false, &is_truncated
);
2303 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2304 return -ERR_TOO_MANY_BUCKETS
;
2311 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2312 RGWRados
*store
, bufferlist
& in_data
,
2313 JSONParser
*jp
, req_info
*forward_info
)
2315 if (!store
->rest_master_conn
) {
2316 ldout(s
->cct
, 0) << "rest connection is invalid" << dendl
;
2319 ldout(s
->cct
, 0) << "sending request to master zonegroup" << dendl
;
2320 bufferlist response
;
2321 string uid_str
= s
->user
->user_id
.to_str();
2322 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2323 int ret
= store
->rest_master_conn
->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2324 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2328 ldout(s
->cct
, 20) << "response: " << response
.c_str() << dendl
;
2329 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2330 ldout(s
->cct
, 0) << "failed parsing response from master zonegroup" << dendl
;
2337 void RGWCreateBucket::pre_exec()
2339 rgw_bucket_object_pre_exec(s
);
2342 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2343 map
<string
, bufferlist
>& out_attrs
,
2344 map
<string
, bufferlist
>& out_rmattrs
)
2346 for (const auto& kv
: orig_attrs
) {
2347 const string
& name
= kv
.first
;
2349 /* Check if the attr is user-defined metadata item. */
2350 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2351 RGW_ATTR_META_PREFIX
) == 0) {
2352 /* For the objects all existing meta attrs have to be removed. */
2353 out_rmattrs
[name
] = kv
.second
;
2354 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2355 out_attrs
[name
] = kv
.second
;
2360 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2361 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2362 * @out_attrs. Place results in @out_attrs.
2364 * NOTE: it's supposed that all special attrs already present in @out_attrs
2365 * will be preserved without any change. Special attributes are those which
2366 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2367 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2368 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2369 const set
<string
>& rmattr_names
,
2370 map
<string
, bufferlist
>& out_attrs
)
2372 for (const auto& kv
: orig_attrs
) {
2373 const string
& name
= kv
.first
;
2375 /* Check if the attr is user-defined metadata item. */
2376 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2377 RGW_ATTR_META_PREFIX
) == 0) {
2378 /* For the buckets all existing meta attrs are preserved,
2379 except those that are listed in rmattr_names. */
2380 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2381 const auto aiter
= out_attrs
.find(name
);
2383 if (aiter
!= std::end(out_attrs
)) {
2384 out_attrs
.erase(aiter
);
2387 /* emplace() won't alter the map if the key is already present.
2388 * This behaviour is fully intensional here. */
2389 out_attrs
.emplace(kv
);
2391 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2392 out_attrs
[name
] = kv
.second
;
2398 static void populate_with_generic_attrs(const req_state
* const s
,
2399 map
<string
, bufferlist
>& out_attrs
)
2401 for (const auto& kv
: s
->generic_attrs
) {
2402 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2403 const string
& val
= kv
.second
;
2405 attrbl
.append(val
.c_str(), val
.size() + 1);
2410 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2411 const std::set
<std::string
>& rmattr_names
,
2412 RGWQuotaInfo
& quota
,
2413 bool * quota_extracted
= nullptr)
2415 bool extracted
= false;
2417 /* Put new limit on max objects. */
2418 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2420 if (std::end(add_attrs
) != iter
) {
2422 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2426 add_attrs
.erase(iter
);
2430 /* Put new limit on bucket (container) size. */
2431 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2432 if (iter
!= add_attrs
.end()) {
2434 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2438 add_attrs
.erase(iter
);
2442 for (const auto& name
: rmattr_names
) {
2443 /* Remove limit on max objects. */
2444 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2445 quota
.max_objects
= -1;
2449 /* Remove limit on max bucket size. */
2450 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2451 quota
.max_size
= -1;
2456 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2457 quota
.check_on_raw
= true;
2458 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2460 if (quota_extracted
) {
2461 *quota_extracted
= extracted
;
2468 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2469 const std::set
<std::string
>& rmattr_names
,
2470 RGWBucketWebsiteConf
& ws_conf
)
2474 /* Let's define a mapping between each custom attribute and the memory where
2475 * attribute's value should be stored. The memory location is expressed by
2476 * a non-const reference. */
2477 const auto mapping
= {
2478 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2479 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2480 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2481 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2482 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2485 for (const auto& kv
: mapping
) {
2486 const char * const key
= kv
.first
;
2487 auto& target
= kv
.second
;
2489 auto iter
= add_attrs
.find(key
);
2491 if (std::end(add_attrs
) != iter
) {
2492 /* The "target" is a reference to ws_conf. */
2493 target
= iter
->second
.c_str();
2494 add_attrs
.erase(iter
);
2497 if (rmattr_names
.count(key
)) {
2498 target
= std::string();
2502 if (! lstval
.empty()) {
2503 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2508 void RGWCreateBucket::execute()
2510 RGWAccessControlPolicy
old_policy(s
->cct
);
2512 buffer::list corsbl
;
2515 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2516 rgw_raw_obj
obj(store
->get_zone_params().domain_root
, bucket_name
);
2517 obj_version objv
, *pobjv
= NULL
;
2519 op_ret
= get_params();
2523 if (!location_constraint
.empty() &&
2524 !store
->has_zonegroup_api(location_constraint
)) {
2525 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2526 << " can't be found." << dendl
;
2527 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2528 s
->err
.message
= "The specified location-constraint is not valid";
2532 if (!store
->get_zonegroup().is_master_zonegroup() && !location_constraint
.empty() &&
2533 store
->get_zonegroup().api_name
!= location_constraint
) {
2534 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2535 << " doesn't match zonegroup" << " (" << store
->get_zonegroup().api_name
<< ")"
2537 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2538 s
->err
.message
= "The specified location-constraint is not valid";
2542 const auto& zonegroup
= store
->get_zonegroup();
2543 if (!placement_rule
.empty() &&
2544 !zonegroup
.placement_targets
.count(placement_rule
)) {
2545 ldout(s
->cct
, 0) << "placement target (" << placement_rule
<< ")"
2546 << " doesn't exist in the placement targets of zonegroup"
2547 << " (" << store
->get_zonegroup().api_name
<< ")" << dendl
;
2548 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2549 s
->err
.message
= "The specified placement target does not exist";
2553 /* we need to make sure we read bucket info, it's not read before for this
2554 * specific request */
2555 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2556 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2557 s
->bucket_info
, NULL
, &s
->bucket_attrs
);
2558 if (op_ret
< 0 && op_ret
!= -ENOENT
)
2560 s
->bucket_exists
= (op_ret
!= -ENOENT
);
2562 s
->bucket_owner
.set_id(s
->user
->user_id
);
2563 s
->bucket_owner
.set_name(s
->user
->display_name
);
2564 if (s
->bucket_exists
) {
2565 int r
= get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
2566 s
->bucket_attrs
, &old_policy
);
2568 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
2575 RGWBucketInfo master_info
;
2576 rgw_bucket
*pmaster_bucket
;
2577 uint32_t *pmaster_num_shards
;
2578 real_time creation_time
;
2580 if (!store
->is_meta_master()) {
2582 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
2587 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
2588 JSONDecoder::decode_json("object_ver", objv
, &jp
);
2589 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
2590 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
2591 ldout(s
->cct
, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
2592 pmaster_bucket
= &master_info
.bucket
;
2593 creation_time
= master_info
.creation_time
;
2594 pmaster_num_shards
= &master_info
.num_shards
;
2597 pmaster_bucket
= NULL
;
2598 pmaster_num_shards
= NULL
;
2601 string zonegroup_id
;
2603 if (s
->system_request
) {
2604 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
2605 if (zonegroup_id
.empty()) {
2606 zonegroup_id
= store
->get_zonegroup().get_id();
2609 zonegroup_id
= store
->get_zonegroup().get_id();
2612 if (s
->bucket_exists
) {
2613 string selected_placement_rule
;
2615 bucket
.tenant
= s
->bucket_tenant
;
2616 bucket
.name
= s
->bucket_name
;
2617 op_ret
= store
->select_bucket_placement(*(s
->user
), zonegroup_id
,
2619 &selected_placement_rule
, nullptr);
2620 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
2626 /* Encode special metadata first as we're using std::map::emplace under
2627 * the hood. This method will add the new items only if the map doesn't
2628 * contain such keys yet. */
2629 policy
.encode(aclbl
);
2630 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
2633 cors_config
.encode(corsbl
);
2634 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
2637 RGWQuotaInfo quota_info
;
2638 const RGWQuotaInfo
* pquota_info
= nullptr;
2639 if (need_metadata_upload()) {
2640 /* It's supposed that following functions WILL NOT change any special
2641 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
2642 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2643 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2644 populate_with_generic_attrs(s
, attrs
);
2646 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
2650 pquota_info
= "a_info
;
2653 /* Web site of Swift API. */
2654 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2655 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2658 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
2659 s
->bucket
.name
= s
->bucket_name
;
2661 /* Handle updates of the metadata for Swift's object versioning. */
2662 if (swift_ver_location
) {
2663 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2664 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2667 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
2668 placement_rule
, s
->bucket_info
.swift_ver_location
,
2670 info
, pobjv
, &ep_objv
, creation_time
,
2671 pmaster_bucket
, pmaster_num_shards
, true);
2672 /* continue if EEXIST and create_bucket will fail below. this way we can
2673 * recover from a partial create by retrying it. */
2674 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
2676 if (op_ret
&& op_ret
!= -EEXIST
)
2679 existed
= (op_ret
== -EEXIST
);
2682 /* bucket already existed, might have raced with another bucket creation, or
2683 * might be partial bucket creation that never completed. Read existing bucket
2684 * info, verify that the reported bucket owner is the current user.
2685 * If all is ok then update the user's list of buckets.
2686 * Otherwise inform client about a name conflict.
2688 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
2692 s
->bucket
= info
.bucket
;
2695 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
2696 info
.creation_time
, false);
2697 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
2698 /* if it exists (or previously existed), don't remove it! */
2699 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2702 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2705 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
2706 op_ret
= -ERR_BUCKET_EXISTS
;
2709 if (need_metadata_upload() && existed
) {
2710 /* OK, it looks we lost race with another request. As it's required to
2711 * handle metadata fusion and upload, the whole operation becomes very
2712 * similar in nature to PutMetadataBucket. However, as the attrs may
2713 * changed in the meantime, we have to refresh. */
2716 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2717 RGWBucketInfo binfo
;
2718 map
<string
, bufferlist
> battrs
;
2720 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2721 binfo
, nullptr, &battrs
);
2724 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
2725 /* New bucket doesn't belong to the account we're operating on. */
2729 s
->bucket_info
= binfo
;
2730 s
->bucket_attrs
= battrs
;
2735 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2736 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2737 populate_with_generic_attrs(s
, attrs
);
2738 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
2743 /* Handle updates of the metadata for Swift's object versioning. */
2744 if (swift_ver_location
) {
2745 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2746 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2749 /* Web site of Swift API. */
2750 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2751 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2753 /* This will also set the quota on the bucket. */
2754 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
2755 &s
->bucket_info
.objv_tracker
);
2756 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
2758 /* Restore the proper return code. */
2760 op_ret
= -ERR_BUCKET_EXISTS
;
2765 int RGWDeleteBucket::verify_permission()
2767 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucket
)) {
2774 void RGWDeleteBucket::pre_exec()
2776 rgw_bucket_object_pre_exec(s
);
2779 void RGWDeleteBucket::execute()
2783 if (s
->bucket_name
.empty())
2786 if (!s
->bucket_exists
) {
2787 ldout(s
->cct
, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
2788 op_ret
= -ERR_NO_SUCH_BUCKET
;
2791 RGWObjVersionTracker ot
;
2792 ot
.read_version
= s
->bucket_info
.ep_objv
;
2794 if (s
->system_request
) {
2795 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
2796 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
2798 ot
.read_version
.tag
= tag
;
2801 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
2803 ldout(s
->cct
, 0) << "failed to parse ver param" << dendl
;
2807 ot
.read_version
.ver
= ver
;
2811 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
2813 ldout(s
->cct
, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
2816 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
2821 if (!store
->is_meta_master()) {
2823 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
2826 if (op_ret
== -ENOENT
) {
2827 /* adjust error, we want to return with NoSuchBucket and not
2829 op_ret
= -ERR_NO_SUCH_BUCKET
;
2835 string prefix
, delimiter
;
2837 if (s
->prot_flags
& RGW_REST_SWIFT
) {
2839 path_args
= s
->info
.args
.get("path");
2840 if (!path_args
.empty()) {
2841 if (!delimiter
.empty() || !prefix
.empty()) {
2850 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
2856 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
2858 if (op_ret
== -ECANCELED
) {
2859 // lost a race, either with mdlog sync or another delete bucket operation.
2860 // in either case, we've already called rgw_unlink_bucket()
2866 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2867 s
->bucket
.name
, false);
2869 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2881 int RGWPutObj::verify_permission()
2885 RGWAccessControlPolicy
cs_acl(s
->cct
);
2886 optional
<Policy
> policy
;
2887 map
<string
, bufferlist
> cs_attrs
;
2888 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
2889 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
2891 rgw_obj
obj(cs_bucket
, cs_object
);
2892 store
->set_atomic(s
->obj_ctx
, obj
);
2893 store
->set_prefetch_data(s
->obj_ctx
, obj
);
2895 /* check source object permissions */
2896 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
, policy
,
2897 cs_bucket
, cs_object
) < 0) {
2901 /* admin request overrides permission checks */
2902 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
2904 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
2905 cs_object
.instance
.empty() ?
2906 rgw::IAM::s3GetObject
:
2907 rgw::IAM::s3GetObjectVersion
,
2908 rgw::IAM::ARN(obj
));
2909 if (e
== Effect::Deny
) {
2911 } else if (e
== Effect::Pass
&&
2912 !cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2916 } else if (!cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
2923 if (s
->iam_policy
) {
2924 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
2925 rgw::IAM::s3PutObject
,
2926 rgw_obj(s
->bucket
, s
->object
));
2927 if (e
== Effect::Allow
) {
2929 } else if (e
== Effect::Deny
) {
2934 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
2941 void RGWPutObjProcessor_Multipart::get_mp(RGWMPObj
** _mp
){
2945 int RGWPutObjProcessor_Multipart::prepare(RGWRados
*store
, string
*oid_rand
)
2947 string oid
= obj_str
;
2948 upload_id
= s
->info
.args
.get("uploadId");
2950 mp
.init(oid
, upload_id
);
2952 mp
.init(oid
, upload_id
, *oid_rand
);
2955 part_num
= s
->info
.args
.get("partNumber");
2956 if (part_num
.empty()) {
2957 ldout(s
->cct
, 10) << "part number is empty" << dendl
;
2962 uint64_t num
= (uint64_t)strict_strtol(part_num
.c_str(), 10, &err
);
2965 ldout(s
->cct
, 10) << "bad part number: " << part_num
<< ": " << err
<< dendl
;
2969 string upload_prefix
= oid
+ ".";
2972 upload_prefix
.append(upload_id
);
2974 upload_prefix
.append(*oid_rand
);
2978 target_obj
.init(bucket
, oid
);
2980 manifest
.set_prefix(upload_prefix
);
2982 manifest
.set_multipart_part_rule(store
->ctx()->_conf
->rgw_obj_stripe_size
, num
);
2984 int r
= manifest_gen
.create_begin(store
->ctx(), &manifest
, s
->bucket_info
.placement_rule
, bucket
, target_obj
);
2989 cur_obj
= manifest_gen
.get_cur_obj(store
);
2990 rgw_raw_obj_to_obj(bucket
, cur_obj
, &head_obj
);
2991 head_obj
.index_hash_source
= obj_str
;
2993 r
= prepare_init(store
, NULL
);
3001 int RGWPutObjProcessor_Multipart::do_complete(size_t accounted_size
,
3003 real_time
*mtime
, real_time set_mtime
,
3004 map
<string
, bufferlist
>& attrs
,
3005 real_time delete_at
,
3006 const char *if_match
,
3007 const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
)
3009 complete_writing_data();
3011 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, head_obj
);
3012 op_target
.set_versioning_disabled(true);
3013 RGWRados::Object::Write
head_obj_op(&op_target
);
3015 head_obj_op
.meta
.set_mtime
= set_mtime
;
3016 head_obj_op
.meta
.mtime
= mtime
;
3017 head_obj_op
.meta
.owner
= s
->owner
.get_id();
3018 head_obj_op
.meta
.delete_at
= delete_at
;
3019 head_obj_op
.meta
.zones_trace
= zones_trace
;
3021 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3026 RGWUploadPartInfo info
;
3028 bool sorted_omap
= is_v2_upload_id(upload_id
);
3032 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3034 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3038 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3043 info
.num
= atoi(part_num
.c_str());
3045 info
.size
= obj_len
;
3046 info
.accounted_size
= accounted_size
;
3047 info
.modified
= real_clock::now();
3048 info
.manifest
= manifest
;
3051 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3053 dout(1) << "cannot get compression info" << dendl
;
3059 string multipart_meta_obj
= mp
.get_meta();
3062 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3063 meta_obj
.set_in_extra_data(true);
3065 rgw_raw_obj raw_meta_obj
;
3067 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3069 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3074 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3076 RGWPutObjProcessor
*processor
;
3078 bool multipart
= s
->info
.args
.exists("uploadId");
3080 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3083 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3084 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3085 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3087 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3091 *is_multipart
= multipart
;
3097 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3102 void RGWPutObj::pre_exec()
3104 rgw_bucket_object_pre_exec(s
);
3107 class RGWPutObj_CB
: public RGWGetDataCB
3111 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3112 ~RGWPutObj_CB() override
{}
3114 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3115 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3119 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3122 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3124 bl_aux
.append(bl_tmp
);
3129 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3131 RGWPutObj_CB
cb(this);
3132 RGWGetDataCB
* filter
= &cb
;
3133 boost::optional
<RGWGetObj_Decompress
> decompress
;
3134 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3135 RGWCompressionInfo cs_info
;
3136 map
<string
, bufferlist
> attrs
;
3137 map
<string
, bufferlist
>::iterator attr_iter
;
3141 int64_t new_ofs
, new_end
;
3146 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3147 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3149 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3150 RGWRados::Object::Read
read_op(&op_target
);
3151 read_op
.params
.obj_size
= &obj_size
;
3152 read_op
.params
.attrs
= &attrs
;
3154 ret
= read_op
.prepare();
3158 bool need_decompress
;
3159 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3161 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3165 bool partial_content
= true;
3166 if (need_decompress
)
3168 obj_size
= cs_info
.orig_size
;
3169 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3170 filter
= &*decompress
;
3173 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3174 op_ret
= this->get_decrypt_filter(&decrypt
,
3177 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3178 if (decrypt
!= nullptr) {
3179 filter
= decrypt
.get();
3185 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3189 filter
->fixup_range(new_ofs
, new_end
);
3190 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3193 ret
= filter
->flush();
3195 bl
.claim_append(bl_aux
);
3200 // special handling for compression type = "random" with multipart uploads
3201 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3202 const std::string
& compression_type
)
3204 if (compression_type
!= "random") {
3205 return Compressor::create(s
->cct
, compression_type
);
3208 bool is_multipart
{false};
3209 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3211 if (!is_multipart
) {
3212 return Compressor::create(s
->cct
, compression_type
);
3215 // use a hash of the multipart upload id so all parts use the same plugin
3216 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3217 if (alg
== Compressor::COMP_ALG_NONE
) {
3220 return Compressor::create(s
->cct
, alg
);
3223 void RGWPutObj::execute()
3225 RGWPutObjProcessor
*processor
= NULL
;
3226 RGWPutObjDataProcessor
*filter
= nullptr;
3227 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3228 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3229 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3230 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3231 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3233 bufferlist bl
, aclbl
, bs
;
3235 map
<string
, string
>::iterator iter
;
3240 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3241 s
->bucket_info
.placement_rule
);
3242 CompressorRef plugin
;
3243 boost::optional
<RGWPutObj_Compress
> compressor
;
3245 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3246 perfcounter
->inc(l_rgw_put
);
3248 if (s
->object
.empty()) {
3252 if (!s
->bucket_exists
) {
3253 op_ret
= -ERR_NO_SUCH_BUCKET
;
3257 op_ret
= get_params();
3259 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3263 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3265 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3270 if (supplied_md5_b64
) {
3271 need_calc_md5
= true;
3273 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3274 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3275 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3276 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3277 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3278 op_ret
= -ERR_INVALID_DIGEST
;
3282 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3283 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3286 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3287 we also check sizes at the end anyway */
3288 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3289 user_quota
, bucket_quota
, s
->content_length
);
3291 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3294 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3296 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3301 if (supplied_etag
) {
3302 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3303 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3306 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3308 // no filters by default
3311 /* Handle object versioning of Swift API. */
3313 rgw_obj
obj(s
->bucket
, s
->object
);
3314 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3315 s
->bucket_owner
.get_id(),
3323 op_ret
= processor
->prepare(store
, NULL
);
3325 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3330 fst
= copy_source_range_fst
;
3331 lst
= copy_source_range_lst
;
3333 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3337 if (encrypt
!= nullptr) {
3338 filter
= encrypt
.get();
3340 //no encryption, we can try compression
3341 if (compression_type
!= "none") {
3342 plugin
= get_compressor_plugin(s
, compression_type
);
3344 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3345 << compression_type
<< dendl
;
3347 compressor
.emplace(s
->cct
, plugin
, filter
);
3348 filter
= &*compressor
;
3358 len
= get_data(data
);
3360 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3361 op_ret
= get_data(fst
, cur_lst
, data
);
3364 len
= data
.length();
3365 s
->content_length
+= len
;
3373 if (need_calc_md5
) {
3374 hash
.Update((const byte
*)data
.c_str(), data
.length());
3377 /* update torrrent */
3378 torrent
.update(data
);
3380 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3381 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3383 bool need_to_wait
= (ofs
== 0) && multipart
;
3385 bufferlist orig_data
;
3391 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3393 if (!need_to_wait
|| op_ret
!= -EEXIST
) {
3394 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3398 /* need_to_wait == true and op_ret == -EEXIST */
3399 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3401 /* restore original data */
3402 data
.swap(orig_data
);
3404 /* restart processing with different oid suffix */
3406 dispose_processor(processor
);
3407 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3412 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3413 oid_rand
.append(buf
);
3415 op_ret
= processor
->prepare(store
, &oid_rand
);
3417 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3422 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3426 if (encrypt
!= nullptr) {
3427 filter
= encrypt
.get();
3430 compressor
.emplace(s
->cct
, plugin
, filter
);
3431 filter
= &*compressor
;
3434 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3445 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3451 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3452 op_ret
= -ERR_REQUEST_TIMEOUT
;
3457 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3459 op_ret
= do_aws4_auth_completion();
3464 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3465 user_quota
, bucket_quota
, s
->obj_size
);
3467 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3471 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3473 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3479 if (compressor
&& compressor
->is_compressed()) {
3481 RGWCompressionInfo cs_info
;
3482 cs_info
.compression_type
= plugin
->get_type_name();
3483 cs_info
.orig_size
= s
->obj_size
;
3484 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3485 ::encode(cs_info
, tmp
);
3486 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3487 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3488 << " with type=" << cs_info
.compression_type
3489 << ", orig_size=" << cs_info
.orig_size
3490 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3493 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3497 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3498 op_ret
= -ERR_BAD_DIGEST
;
3502 policy
.encode(aclbl
);
3503 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3506 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3508 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3511 complete_etag(hash
, &etag
);
3512 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3516 bufferlist manifest_bl
;
3517 ::encode(*slo_info
, manifest_bl
);
3518 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3520 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3521 complete_etag(hash
, &etag
);
3522 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3525 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3526 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3529 bl
.append(etag
.c_str(), etag
.size() + 1);
3530 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3532 populate_with_generic_attrs(s
, attrs
);
3533 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3534 encode_delete_at_attr(delete_at
, attrs
);
3535 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3537 /* Add a custom metadata to expose the information whether an object
3538 * is an SLO or not. Appending the attribute must be performed AFTER
3539 * processing any input from user in order to prohibit overwriting. */
3541 bufferlist slo_userindicator_bl
;
3542 slo_userindicator_bl
.append("True", 4);
3543 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3546 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3547 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3548 (user_data
.empty() ? nullptr : &user_data
));
3550 /* produce torrent */
3551 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3553 torrent
.init(s
, store
);
3554 torrent
.set_create_date(mtime
);
3555 op_ret
= torrent
.complete();
3558 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3564 dispose_processor(processor
);
3565 perfcounter
->tinc(l_rgw_put_lat
,
3566 (ceph_clock_now() - s
->time
));
3569 int RGWPostObj::verify_permission()
3574 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3576 RGWPutObjProcessor *processor;
3578 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3580 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3585 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3590 void RGWPostObj::pre_exec()
3592 rgw_bucket_object_pre_exec(s
);
3595 void RGWPostObj::execute()
3597 RGWPutObjDataProcessor
*filter
= nullptr;
3598 boost::optional
<RGWPutObj_Compress
> compressor
;
3599 CompressorRef plugin
;
3600 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3602 /* Read in the data from the POST form. */
3603 op_ret
= get_params();
3608 op_ret
= verify_params();
3613 if (s
->iam_policy
) {
3614 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3615 rgw::IAM::s3PutObject
,
3616 rgw_obj(s
->bucket
, s
->object
));
3617 if (e
== Effect::Deny
) {
3620 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3624 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3629 /* Start iteration over data fields. It's necessary as Swift's FormPost
3630 * is capable to handle multiple files in single form. */
3632 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3633 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3634 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3636 ceph::buffer::list bl
, aclbl
;
3639 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3648 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3653 if (supplied_md5_b64
) {
3654 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3655 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3656 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3657 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3658 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3659 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3660 op_ret
= -ERR_INVALID_DIGEST
;
3664 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3665 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3668 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3671 get_current_filename(),
3673 s
->cct
->_conf
->rgw_obj_stripe_size
,
3675 s
->bucket_info
.versioning_enabled());
3676 /* No filters by default. */
3677 filter
= &processor
;
3679 op_ret
= processor
.prepare(store
, nullptr);
3684 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3688 if (encrypt
!= nullptr) {
3689 filter
= encrypt
.get();
3691 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3692 s
->bucket_info
.placement_rule
);
3693 if (compression_type
!= "none") {
3694 plugin
= Compressor::create(s
->cct
, compression_type
);
3696 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3697 << compression_type
<< dendl
;
3699 compressor
.emplace(s
->cct
, plugin
, filter
);
3700 filter
= &*compressor
;
3707 ceph::bufferlist data
;
3708 len
= get_data(data
, again
);
3719 hash
.Update((const byte
*)data
.c_str(), data
.length());
3720 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3724 if (ofs
> max_len
) {
3725 op_ret
= -ERR_TOO_LARGE
;
3732 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3735 if (len
< min_len
) {
3736 op_ret
= -ERR_TOO_SMALL
;
3742 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3743 op_ret
= -ERR_BAD_DIGEST
;
3747 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3748 user_quota
, bucket_quota
, s
->obj_size
);
3753 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3759 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3762 bl
.append(etag
.c_str(), etag
.size() + 1);
3763 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3765 policy
.encode(aclbl
);
3766 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3768 const std::string content_type
= get_current_content_type();
3769 if (! content_type
.empty()) {
3770 ceph::bufferlist ct_bl
;
3771 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3772 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3775 if (compressor
&& compressor
->is_compressed()) {
3776 ceph::bufferlist tmp
;
3777 RGWCompressionInfo cs_info
;
3778 cs_info
.compression_type
= plugin
->get_type_name();
3779 cs_info
.orig_size
= s
->obj_size
;
3780 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3781 ::encode(cs_info
, tmp
);
3782 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3785 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3786 attrs
, (delete_at
? *delete_at
: real_time()));
3787 } while (is_next_file_to_upload());
3791 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3792 const set
<string
>& rmattr_names
,
3793 map
<int, string
>& temp_url_keys
)
3795 map
<string
, bufferlist
>::iterator iter
;
3797 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3798 if (iter
!= add_attrs
.end()) {
3799 temp_url_keys
[0] = iter
->second
.c_str();
3800 add_attrs
.erase(iter
);
3803 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3804 if (iter
!= add_attrs
.end()) {
3805 temp_url_keys
[1] = iter
->second
.c_str();
3806 add_attrs
.erase(iter
);
3809 for (const string
& name
: rmattr_names
) {
3810 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3811 temp_url_keys
[0] = string();
3813 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3814 temp_url_keys
[1] = string();
3819 int RGWPutMetadataAccount::init_processing()
3821 /* First, go to the base class. At the time of writing the method was
3822 * responsible only for initializing the quota. This isn't necessary
3823 * here as we are touching metadata only. I'm putting this call only
3824 * for the future. */
3825 op_ret
= RGWOp::init_processing();
3830 op_ret
= get_params();
3835 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3843 policy
.encode(acl_bl
);
3844 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3847 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3848 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3849 populate_with_generic_attrs(s
, attrs
);
3851 /* Try extract the TempURL-related stuff now to allow verify_permission
3852 * evaluate whether we need FULL_CONTROL or not. */
3853 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3855 /* The same with quota except a client needs to be reseller admin. */
3856 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3857 &new_quota_extracted
);
3865 int RGWPutMetadataAccount::verify_permission()
3867 if (s
->auth
.identity
->is_anonymous()) {
3871 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
3875 /* Altering TempURL keys requires FULL_CONTROL. */
3876 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
3880 /* We are failing this intensionally to allow system user/reseller admin
3881 * override in rgw_process.cc. This is the way to specify a given RGWOp
3882 * expect extra privileges. */
3883 if (new_quota_extracted
) {
3890 void RGWPutMetadataAccount::execute()
3892 /* Params have been extracted earlier. See init_processing(). */
3893 RGWUserInfo new_uinfo
;
3894 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
3900 /* Handle the TempURL-related stuff. */
3901 if (!temp_url_keys
.empty()) {
3902 for (auto& pair
: temp_url_keys
) {
3903 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
3907 /* Handle the quota extracted at the verify_permission step. */
3908 if (new_quota_extracted
) {
3909 new_uinfo
.user_quota
= std::move(new_quota
);
3912 /* We are passing here the current (old) user info to allow the function
3913 * optimize-out some operations. */
3914 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
3915 &acct_op_tracker
, real_time(), false, &attrs
);
3918 int RGWPutMetadataBucket::verify_permission()
3920 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3927 void RGWPutMetadataBucket::pre_exec()
3929 rgw_bucket_object_pre_exec(s
);
3932 void RGWPutMetadataBucket::execute()
3934 op_ret
= get_params();
3939 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3941 if (!placement_rule
.empty() &&
3942 placement_rule
!= s
->bucket_info
.placement_rule
) {
3947 /* Encode special metadata first as we're using std::map::emplace under
3948 * the hood. This method will add the new items only if the map doesn't
3949 * contain such keys yet. */
3951 if (s
->dialect
.compare("swift") == 0) {
3953 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
3954 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
3955 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
3956 policy
= *new_policy
;
3960 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
3965 cors_config
.encode(bl
);
3966 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
3969 /* It's supposed that following functions WILL NOT change any special
3970 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
3971 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
3972 populate_with_generic_attrs(s
, attrs
);
3974 /* According to the Swift's behaviour and its container_quota WSGI middleware
3975 * implementation: anyone with write permissions is able to set the bucket
3976 * quota. This stays in contrast to account quotas that can be set only by
3977 * clients holding reseller admin privileges. */
3978 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
3983 if (swift_ver_location
) {
3984 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
3985 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
3988 /* Web site of Swift API. */
3989 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
3990 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
3992 /* Setting attributes also stores the provided bucket info. Due to this
3993 * fact, the new quota settings can be serialized with the same call. */
3994 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
3995 &s
->bucket_info
.objv_tracker
);
3998 int RGWPutMetadataObject::verify_permission()
4000 // This looks to be something specific to Swift. We could add
4001 // operations like swift:PutMetadataObject to the Policy Engine.
4002 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4009 void RGWPutMetadataObject::pre_exec()
4011 rgw_bucket_object_pre_exec(s
);
4014 void RGWPutMetadataObject::execute()
4016 rgw_obj
obj(s
->bucket
, s
->object
);
4017 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4019 store
->set_atomic(s
->obj_ctx
, obj
);
4021 op_ret
= get_params();
4026 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4027 /* check if obj exists, read orig attrs */
4028 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4033 /* Check whether the object has expired. Swift API documentation
4034 * stands that we should return 404 Not Found in such case. */
4035 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4040 /* Filter currently existing attributes. */
4041 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4042 populate_with_generic_attrs(s
, attrs
);
4043 encode_delete_at_attr(delete_at
, attrs
);
4046 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4048 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4053 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4056 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4058 RGWSLOInfo slo_info
;
4059 bufferlist::iterator bliter
= bl
.begin();
4061 ::decode(slo_info
, bliter
);
4062 } catch (buffer::error
& err
) {
4063 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4068 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4069 new RGWBulkDelete::Deleter(store
, s
));
4070 } catch (std::bad_alloc
) {
4074 list
<RGWBulkDelete::acct_path_t
> items
;
4075 for (const auto& iter
: slo_info
.entries
) {
4076 const string
& path_str
= iter
.path
;
4078 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4079 if (boost::string_view::npos
== sep_pos
) {
4083 RGWBulkDelete::acct_path_t path
;
4085 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4086 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4088 items
.push_back(path
);
4091 /* Request removal of the manifest object itself. */
4092 RGWBulkDelete::acct_path_t path
;
4093 path
.bucket_name
= s
->bucket_name
;
4094 path
.obj_key
= s
->object
;
4095 items
.push_back(path
);
4097 int ret
= deleter
->delete_chunk(items
);
4105 int RGWDeleteObj::verify_permission()
4107 if (s
->iam_policy
) {
4108 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4109 s
->object
.instance
.empty() ?
4110 rgw::IAM::s3DeleteObject
:
4111 rgw::IAM::s3DeleteObjectVersion
,
4112 ARN(s
->bucket
, s
->object
.name
));
4113 if (r
== Effect::Allow
)
4115 else if (r
== Effect::Deny
)
4119 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4126 void RGWDeleteObj::pre_exec()
4128 rgw_bucket_object_pre_exec(s
);
4131 void RGWDeleteObj::execute()
4133 if (!s
->bucket_exists
) {
4134 op_ret
= -ERR_NO_SUCH_BUCKET
;
4138 op_ret
= get_params();
4143 rgw_obj
obj(s
->bucket
, s
->object
);
4144 map
<string
, bufferlist
> attrs
;
4147 if (!s
->object
.empty()) {
4148 if (need_object_expiration() || multipart_delete
) {
4149 /* check if obj exists, read orig attrs */
4150 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4156 if (multipart_delete
) {
4157 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4159 if (slo_attr
!= attrs
.end()) {
4160 op_ret
= handle_slo_manifest(slo_attr
->second
);
4162 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4165 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4171 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4172 obj_ctx
->obj
.set_atomic(obj
);
4174 bool ver_restored
= false;
4175 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4176 s
->bucket_info
, obj
, ver_restored
);
4181 if (!ver_restored
) {
4182 /* Swift's versioning mechanism hasn't found any previous version of
4183 * the object that could be restored. This means we should proceed
4184 * with the regular delete path. */
4185 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4186 RGWRados::Object::Delete
del_op(&del_target
);
4188 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4189 &del_op
.params
.marker_version_id
);
4194 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4195 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4196 del_op
.params
.obj_owner
= s
->owner
;
4197 del_op
.params
.unmod_since
= unmod_since
;
4198 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4200 op_ret
= del_op
.delete_obj();
4202 delete_marker
= del_op
.result
.delete_marker
;
4203 version_id
= del_op
.result
.version_id
;
4206 /* Check whether the object has expired. Swift API documentation
4207 * stands that we should return 404 Not Found in such case. */
4208 if (need_object_expiration() && object_is_expired(attrs
)) {
4214 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4223 bool RGWCopyObj::parse_copy_location(const string
& url_src
, string
& bucket_name
, rgw_obj_key
& key
)
4228 size_t pos
= url_src
.find('?');
4229 if (pos
== string::npos
) {
4232 name_str
= url_src
.substr(0, pos
);
4233 params_str
= url_src
.substr(pos
+ 1);
4236 std::string dec_src
= url_decode(name_str
);
4237 const char *src
= dec_src
.c_str();
4239 if (*src
== '/') ++src
;
4243 pos
= str
.find('/');
4244 if (pos
==string::npos
)
4247 bucket_name
= str
.substr(0, pos
);
4248 key
.name
= str
.substr(pos
+ 1);
4250 if (key
.name
.empty()) {
4254 if (!params_str
.empty()) {
4256 args
.set(params_str
);
4259 key
.instance
= args
.get("versionId", NULL
);
4265 int RGWCopyObj::verify_permission()
4267 RGWAccessControlPolicy
src_acl(s
->cct
);
4268 optional
<Policy
> src_policy
;
4269 op_ret
= get_params();
4273 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4277 map
<string
, bufferlist
> src_attrs
;
4279 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4281 if (s
->bucket_instance_id
.empty()) {
4282 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4284 /* will only happen in intra region sync where the source and dest bucket is the same */
4285 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4288 if (op_ret
== -ENOENT
) {
4289 op_ret
= -ERR_NO_SUCH_BUCKET
;
4294 src_bucket
= src_bucket_info
.bucket
;
4296 /* get buckets info (source and dest) */
4297 if (s
->local_source
&& source_zone
.empty()) {
4298 rgw_obj
src_obj(src_bucket
, src_object
);
4299 store
->set_atomic(s
->obj_ctx
, src_obj
);
4300 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4302 /* check source object permissions */
4303 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4304 src_policy
, src_bucket
, src_object
);
4309 /* admin request overrides permission checks */
4310 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4312 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4313 src_object
.instance
.empty() ?
4314 rgw::IAM::s3GetObject
:
4315 rgw::IAM::s3GetObjectVersion
,
4317 if (e
== Effect::Deny
) {
4319 } else if (e
== Effect::Pass
&&
4320 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4324 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4332 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4333 map
<string
, bufferlist
> dest_attrs
;
4335 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4336 or intra region sync */
4337 dest_bucket_info
= src_bucket_info
;
4338 dest_attrs
= src_attrs
;
4340 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4341 dest_bucket_info
, nullptr, &dest_attrs
);
4343 if (op_ret
== -ENOENT
) {
4344 op_ret
= -ERR_NO_SUCH_BUCKET
;
4350 dest_bucket
= dest_bucket_info
.bucket
;
4352 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4353 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4355 /* check dest bucket permissions */
4356 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4357 &dest_bucket_policy
, dest_bucket
);
4362 /* admin request overrides permission checks */
4363 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4364 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4369 op_ret
= init_dest_policy();
4378 int RGWCopyObj::init_common()
4381 if (parse_time(if_mod
, &mod_time
) < 0) {
4385 mod_ptr
= &mod_time
;
4389 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4393 unmod_ptr
= &unmod_time
;
4397 dest_policy
.encode(aclbl
);
4398 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4400 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4401 populate_with_generic_attrs(s
, attrs
);
4406 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4408 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4409 op
->progress_cb(ofs
);
4412 void RGWCopyObj::progress_cb(off_t ofs
)
4414 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4417 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4420 send_partial_response(ofs
);
4425 void RGWCopyObj::pre_exec()
4427 rgw_bucket_object_pre_exec(s
);
4430 void RGWCopyObj::execute()
4432 if (init_common() < 0)
4435 rgw_obj
src_obj(src_bucket
, src_object
);
4436 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4438 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4439 obj_ctx
.obj
.set_atomic(src_obj
);
4440 obj_ctx
.obj
.set_atomic(dst_obj
);
4442 encode_delete_at_attr(delete_at
, attrs
);
4444 bool high_precision_time
= (s
->system_request
);
4446 /* Handle object versioning of Swift API. In case of copying to remote this
4447 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4448 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4449 dest_bucket_info
.owner
,
4456 op_ret
= store
->copy_obj(obj_ctx
,
4470 high_precision_time
,
4475 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4477 (delete_at
? *delete_at
: real_time()),
4478 (version_id
.empty() ? NULL
: &version_id
),
4479 &s
->req_id
, /* use req_id as tag */
4481 copy_obj_progress_cb
, (void *)this
4485 int RGWGetACLs::verify_permission()
4488 if (!s
->object
.empty()) {
4489 perm
= verify_object_permission(s
,
4490 s
->object
.instance
.empty() ?
4491 rgw::IAM::s3GetObjectAcl
:
4492 rgw::IAM::s3GetObjectVersionAcl
);
4494 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetBucketAcl
);
4502 void RGWGetACLs::pre_exec()
4504 rgw_bucket_object_pre_exec(s
);
4507 void RGWGetACLs::execute()
4510 RGWAccessControlPolicy
* const acl
= \
4511 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4512 RGWAccessControlPolicy_S3
* const s3policy
= \
4513 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4514 s3policy
->to_xml(ss
);
4520 int RGWPutACLs::verify_permission()
4523 if (!s
->object
.empty()) {
4524 perm
= verify_object_permission(s
,
4525 s
->object
.instance
.empty() ?
4526 rgw::IAM::s3PutObjectAcl
:
4527 rgw::IAM::s3PutObjectVersionAcl
);
4529 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4537 int RGWGetLC::verify_permission()
4540 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4547 int RGWPutLC::verify_permission()
4550 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4557 int RGWDeleteLC::verify_permission()
4560 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4567 void RGWPutACLs::pre_exec()
4569 rgw_bucket_object_pre_exec(s
);
4572 void RGWGetLC::pre_exec()
4574 rgw_bucket_object_pre_exec(s
);
4577 void RGWPutLC::pre_exec()
4579 rgw_bucket_object_pre_exec(s
);
4582 void RGWDeleteLC::pre_exec()
4584 rgw_bucket_object_pre_exec(s
);
4587 void RGWPutACLs::execute()
4591 RGWAccessControlPolicy_S3
*policy
= NULL
;
4592 RGWACLXMLParser_S3
parser(s
->cct
);
4593 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4595 char *new_data
= NULL
;
4598 op_ret
= 0; /* XXX redundant? */
4600 if (!parser
.init()) {
4606 RGWAccessControlPolicy
* const existing_policy
= \
4607 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
4609 owner
= existing_policy
->get_owner();
4611 op_ret
= get_params();
4613 if (op_ret
== -ERANGE
) {
4614 ldout(s
->cct
, 4) << "The size of request xml data is larger than the max limitation, data size = "
4615 << s
->length
<< dendl
;
4616 op_ret
= -ERR_MALFORMED_XML
;
4617 s
->err
.message
= "The XML you provided was larger than the maximum " +
4618 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
4624 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4626 if (!s
->canned_acl
.empty() && len
) {
4631 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4632 op_ret
= get_policy_from_state(store
, s
, ss
);
4636 new_data
= strdup(ss
.str().c_str());
4639 len
= ss
.str().size();
4642 if (!parser
.parse(data
, len
, 1)) {
4646 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4652 const RGWAccessControlList
& req_acl
= policy
->get_acl();
4653 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
4654 #define ACL_GRANTS_MAX_NUM 100
4655 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
4657 max_num
= ACL_GRANTS_MAX_NUM
;
4660 int grants_num
= req_grant_map
.size();
4661 if (grants_num
> max_num
) {
4662 ldout(s
->cct
, 4) << "An acl can have up to "
4664 << " grants, request acl grants num: "
4665 << grants_num
<< dendl
;
4666 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
4667 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
4668 + std::to_string(max_num
)
4669 + " grants allowed in an acl.";
4673 // forward bucket acl requests to meta master zone
4674 if (s
->object
.empty() && !store
->is_meta_master()) {
4676 // include acl data unless it was generated from a canned_acl
4677 if (s
->canned_acl
.empty()) {
4678 in_data
.append(data
, len
);
4680 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4682 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4687 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4688 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4689 policy
->to_xml(*_dout
);
4693 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4697 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4698 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4699 new_policy
.to_xml(*_dout
);
4703 new_policy
.encode(bl
);
4704 map
<string
, bufferlist
> attrs
;
4706 if (!s
->object
.empty()) {
4707 obj
= rgw_obj(s
->bucket
, s
->object
);
4708 store
->set_atomic(s
->obj_ctx
, obj
);
4709 //if instance is empty, we should modify the latest object
4710 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4712 attrs
= s
->bucket_attrs
;
4713 attrs
[RGW_ATTR_ACL
] = bl
;
4714 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4716 if (op_ret
== -ECANCELED
) {
4717 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4721 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4723 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4724 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4725 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4726 oid
= lc_oid_prefix
;
4728 snprintf(buf
, 32, ".%d", index
);
4733 void RGWPutLC::execute()
4737 RGWLifecycleConfiguration_S3
*config
= NULL
;
4738 RGWLCXMLParser_S3
parser(s
->cct
);
4739 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4741 if (!parser
.init()) {
4746 op_ret
= get_params();
4750 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4752 if (!parser
.parse(data
, len
, 1)) {
4753 op_ret
= -ERR_MALFORMED_XML
;
4756 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4758 op_ret
= -ERR_MALFORMED_XML
;
4762 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4763 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4764 config
->to_xml(*_dout
);
4768 op_ret
= config
->rebuild(store
, new_config
);
4772 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4773 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4774 new_config
.to_xml(*_dout
);
4778 new_config
.encode(bl
);
4779 map
<string
, bufferlist
> attrs
;
4780 attrs
= s
->bucket_attrs
;
4781 attrs
[RGW_ATTR_LC
] = bl
;
4782 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4785 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4788 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4789 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4790 rados::cls::lock::Lock
l(lc_index_lock_name
);
4791 utime_t
time(max_lock_secs
, 0);
4792 l
.set_duration(time
);
4793 l
.set_cookie(cookie
);
4794 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4796 op_ret
= l
.lock_exclusive(ctx
, oid
);
4797 if (op_ret
== -EBUSY
) {
4798 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4803 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4806 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4808 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4816 void RGWDeleteLC::execute()
4819 map
<string
, bufferlist
> orig_attrs
, attrs
;
4820 map
<string
, bufferlist
>::iterator iter
;
4822 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4823 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4824 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4828 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4829 const string
& name
= iter
->first
;
4830 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
4831 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
4832 if (attrs
.find(name
) == attrs
.end()) {
4833 attrs
[name
] = iter
->second
;
4837 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4838 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4839 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4842 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4843 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4844 rados::cls::lock::Lock
l(lc_index_lock_name
);
4845 utime_t
time(max_lock_secs
, 0);
4846 l
.set_duration(time
);
4848 op_ret
= l
.lock_exclusive(ctx
, oid
);
4849 if (op_ret
== -EBUSY
) {
4850 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4855 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4858 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
4860 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4868 int RGWGetCORS::verify_permission()
4870 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4877 void RGWGetCORS::execute()
4879 op_ret
= read_bucket_cors();
4884 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4890 int RGWPutCORS::verify_permission()
4892 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4899 void RGWPutCORS::execute()
4903 op_ret
= get_params();
4907 if (!store
->is_meta_master()) {
4908 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
4910 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4915 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
4916 attrs
[RGW_ATTR_CORS
] = cors_bl
;
4917 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4920 int RGWDeleteCORS::verify_permission()
4922 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4929 void RGWDeleteCORS::execute()
4931 op_ret
= read_bucket_cors();
4938 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4942 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4943 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4944 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
4945 map
<string
, bufferlist
>::iterator iter
;
4947 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4951 /* only remove meta attrs */
4952 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4953 const string
& name
= iter
->first
;
4954 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
4955 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
4956 rmattrs
[name
] = iter
->second
;
4957 } else if (attrs
.find(name
) == attrs
.end()) {
4958 attrs
[name
] = iter
->second
;
4961 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4964 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
4965 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
4968 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
4969 rule
= cc
->host_name_rule(origin
);
4971 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
4975 if (!validate_cors_rule_method(rule
, req_meth
)) {
4981 void RGWOptionsCORS::execute()
4983 op_ret
= read_bucket_cors();
4987 origin
= s
->info
.env
->get("HTTP_ORIGIN");
4990 "Preflight request without mandatory Origin header"
4995 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
4998 "Preflight request without mandatory Access-control-request-method header"
5004 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5008 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5009 op_ret
= validate_cors_request(&bucket_cors
);
5011 origin
= req_meth
= NULL
;
5017 int RGWGetRequestPayment::verify_permission()
5022 void RGWGetRequestPayment::pre_exec()
5024 rgw_bucket_object_pre_exec(s
);
5027 void RGWGetRequestPayment::execute()
5029 requester_pays
= s
->bucket_info
.requester_pays
;
5032 int RGWSetRequestPayment::verify_permission()
5034 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
5041 void RGWSetRequestPayment::pre_exec()
5043 rgw_bucket_object_pre_exec(s
);
5046 void RGWSetRequestPayment::execute()
5048 op_ret
= get_params();
5053 s
->bucket_info
.requester_pays
= requester_pays
;
5054 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5057 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5058 << " returned err=" << op_ret
<< dendl
;
5063 int RGWInitMultipart::verify_permission()
5065 if (s
->iam_policy
) {
5066 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5067 rgw::IAM::s3PutObject
,
5068 rgw_obj(s
->bucket
, s
->object
));
5069 if (e
== Effect::Allow
) {
5071 } else if (e
== Effect::Deny
) {
5076 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5083 void RGWInitMultipart::pre_exec()
5085 rgw_bucket_object_pre_exec(s
);
5088 void RGWInitMultipart::execute()
5091 map
<string
, bufferlist
> attrs
;
5094 if (get_params() < 0)
5097 if (s
->object
.empty())
5100 policy
.encode(aclbl
);
5101 attrs
[RGW_ATTR_ACL
] = aclbl
;
5103 populate_with_generic_attrs(s
, attrs
);
5105 /* select encryption mode */
5106 op_ret
= prepare_encryption(attrs
);
5110 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5114 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5115 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5116 upload_id
.append(buf
);
5118 string tmp_obj_name
;
5119 RGWMPObj
mp(s
->object
.name
, upload_id
);
5120 tmp_obj_name
= mp
.get_meta();
5122 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5123 // the meta object will be indexed with 0 size, we c
5124 obj
.set_in_extra_data(true);
5125 obj
.index_hash_source
= s
->object
.name
;
5127 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5128 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5130 RGWRados::Object::Write
obj_op(&op_target
);
5132 obj_op
.meta
.owner
= s
->owner
.get_id();
5133 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5134 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5136 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5137 } while (op_ret
== -EEXIST
);
5140 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5142 RGWAccessControlPolicy
*policy
,
5143 map
<string
, bufferlist
>& attrs
)
5145 map
<string
, bufferlist
>::iterator iter
;
5149 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5150 obj
.set_in_extra_data(true);
5152 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5154 if (op_ret
== -ENOENT
) {
5155 return -ERR_NO_SUCH_UPLOAD
;
5161 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5162 string name
= iter
->first
;
5163 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5164 bufferlist
& bl
= iter
->second
;
5165 bufferlist::iterator bli
= bl
.begin();
5167 ::decode(*policy
, bli
);
5168 } catch (buffer::error
& err
) {
5169 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5180 int RGWCompleteMultipart::verify_permission()
5182 if (s
->iam_policy
) {
5183 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5184 rgw::IAM::s3PutObject
,
5185 rgw_obj(s
->bucket
, s
->object
));
5186 if (e
== Effect::Allow
) {
5188 } else if (e
== Effect::Deny
) {
5193 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5200 void RGWCompleteMultipart::pre_exec()
5202 rgw_bucket_object_pre_exec(s
);
5205 void RGWCompleteMultipart::execute()
5207 RGWMultiCompleteUpload
*parts
;
5208 map
<int, string
>::iterator iter
;
5209 RGWMultiXMLParser parser
;
5211 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5212 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5213 map
<string
, bufferlist
> attrs
;
5216 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5217 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5222 RGWObjManifest manifest
;
5223 uint64_t olh_epoch
= 0;
5226 op_ret
= get_params();
5229 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5234 if (!data
|| !len
) {
5235 op_ret
= -ERR_MALFORMED_XML
;
5239 if (!parser
.init()) {
5244 if (!parser
.parse(data
, len
, 1)) {
5245 op_ret
= -ERR_MALFORMED_XML
;
5249 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5250 if (!parts
|| parts
->parts
.empty()) {
5251 op_ret
= -ERR_MALFORMED_XML
;
5255 if ((int)parts
->parts
.size() >
5256 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5261 mp
.init(s
->object
.name
, upload_id
);
5262 meta_oid
= mp
.get_meta();
5264 int total_parts
= 0;
5265 int handled_parts
= 0;
5266 int max_parts
= 1000;
5269 RGWCompressionInfo cs_info
;
5270 bool compressed
= false;
5271 uint64_t accounted_size
= 0;
5273 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5275 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5277 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5279 iter
= parts
->parts
.begin();
5281 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5282 meta_obj
.set_in_extra_data(true);
5283 meta_obj
.index_hash_source
= s
->object
.name
;
5285 /*take a cls lock on meta_obj to prevent racing completions (or retries)
5286 from deleting the parts*/
5288 rgw_raw_obj raw_obj
;
5289 librados::ObjectWriteOperation op
;
5290 librados::IoCtx ioctx
;
5291 rados::cls::lock::Lock
l("RGWCompleteMultipart");
5292 int max_lock_secs_mp
= s
->cct
->_conf
->get_val
<int64_t>("rgw_mp_lock_max_time");
5295 store
->obj_to_raw((s
->bucket_info
).placement_rule
, meta_obj
, &raw_obj
);
5296 store
->get_obj_data_pool((s
->bucket_info
).placement_rule
,meta_obj
,&meta_pool
);
5297 store
->open_pool_ctx(meta_pool
, ioctx
);
5299 const string raw_meta_oid
= raw_obj
.oid
;
5300 utime_t
time(max_lock_secs_mp
, 0);
5301 l
.set_duration(time
);
5302 l
.lock_exclusive(&op
);
5303 op_ret
= ioctx
.operate(raw_meta_oid
, &op
);
5306 dout(0) << "RGWCompleteMultipart::execute() failed to acquire lock " << dendl
;
5307 op_ret
= -ERR_INTERNAL_ERROR
;
5308 s
->err
.message
= "This multipart completion is already in progress";
5312 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5315 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5316 << " ret=" << op_ret
<< dendl
;
5321 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5322 marker
, obj_parts
, &marker
, &truncated
);
5323 if (op_ret
== -ENOENT
) {
5324 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5329 total_parts
+= obj_parts
.size();
5330 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5331 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5332 << " expected: " << parts
->parts
.size() << dendl
;
5333 op_ret
= -ERR_INVALID_PART
;
5337 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5338 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5339 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5340 part_size
< min_part_size
) {
5341 op_ret
= -ERR_TOO_SMALL
;
5345 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5346 if (iter
->first
!= (int)obj_iter
->first
) {
5347 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5348 << iter
->first
<< " next uploaded: "
5349 << obj_iter
->first
<< dendl
;
5350 op_ret
= -ERR_INVALID_PART
;
5353 string part_etag
= rgw_string_unquote(iter
->second
);
5354 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5355 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5356 << " etag: " << iter
->second
<< dendl
;
5357 op_ret
= -ERR_INVALID_PART
;
5361 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5362 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5363 hash
.Update((const byte
*)petag
, sizeof(petag
));
5365 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5367 /* update manifest for part */
5368 string oid
= mp
.get_part(obj_iter
->second
.num
);
5370 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5372 if (obj_part
.manifest
.empty()) {
5373 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5374 << src_obj
<< dendl
;
5375 op_ret
= -ERR_INVALID_PART
;
5378 manifest
.append(obj_part
.manifest
, store
);
5381 if (obj_part
.cs_info
.compression_type
!= "none") {
5382 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5383 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5384 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5385 op_ret
= -ERR_INVALID_PART
;
5388 int64_t new_ofs
; // offset in compression data for new part
5389 if (cs_info
.blocks
.size() > 0)
5390 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5393 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5394 compression_block cb
;
5395 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5396 cb
.new_ofs
= new_ofs
;
5398 cs_info
.blocks
.push_back(cb
);
5399 new_ofs
= cb
.new_ofs
+ cb
.len
;
5402 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5403 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5407 rgw_obj_index_key remove_key
;
5408 src_obj
.key
.get_index_key(&remove_key
);
5410 remove_objs
.push_back(remove_key
);
5412 ofs
+= obj_part
.size
;
5413 accounted_size
+= obj_part
.accounted_size
;
5415 } while (truncated
);
5416 hash
.Final((byte
*)final_etag
);
5418 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5419 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5420 "-%lld", (long long)parts
->parts
.size());
5421 etag
= final_etag_str
;
5422 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5424 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5426 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5429 // write compression attribute to full object
5431 ::encode(cs_info
, tmp
);
5432 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5435 target_obj
.init(s
->bucket
, s
->object
.name
);
5436 if (versioned_object
) {
5437 store
->gen_rand_obj_instance_name(&target_obj
);
5440 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5442 obj_ctx
.obj
.set_atomic(target_obj
);
5444 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5445 RGWRados::Object::Write
obj_op(&op_target
);
5447 obj_op
.meta
.manifest
= &manifest
;
5448 obj_op
.meta
.remove_objs
= &remove_objs
;
5450 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5451 obj_op
.meta
.owner
= s
->owner
.get_id();
5452 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5453 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5457 // remove the upload obj
5458 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5459 s
->bucket_info
, meta_obj
, 0);
5461 ldout(store
->ctx(), 0) << "WARNING: failed to remove object " << meta_obj
<< dendl
;
5462 r
= l
.unlock(&ioctx
, raw_meta_oid
);
5464 ldout(store
->ctx(), 0) << "WARNING: failed to unlock " << raw_meta_oid
<< dendl
;
5469 int RGWAbortMultipart::verify_permission()
5471 if (s
->iam_policy
) {
5472 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5473 rgw::IAM::s3AbortMultipartUpload
,
5474 rgw_obj(s
->bucket
, s
->object
));
5475 if (e
== Effect::Allow
) {
5477 } else if (e
== Effect::Deny
) {
5482 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5489 void RGWAbortMultipart::pre_exec()
5491 rgw_bucket_object_pre_exec(s
);
5494 void RGWAbortMultipart::execute()
5499 upload_id
= s
->info
.args
.get("uploadId");
5500 map
<string
, bufferlist
> attrs
;
5504 if (upload_id
.empty() || s
->object
.empty())
5507 mp
.init(s
->object
.name
, upload_id
);
5508 meta_oid
= mp
.get_meta();
5510 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5514 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5515 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5518 int RGWListMultipart::verify_permission()
5520 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5526 void RGWListMultipart::pre_exec()
5528 rgw_bucket_object_pre_exec(s
);
5531 void RGWListMultipart::execute()
5533 map
<string
, bufferlist
> xattrs
;
5537 op_ret
= get_params();
5541 mp
.init(s
->object
.name
, upload_id
);
5542 meta_oid
= mp
.get_meta();
5544 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5548 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5549 marker
, parts
, NULL
, &truncated
);
5552 int RGWListBucketMultiparts::verify_permission()
5554 if (!verify_bucket_permission(s
,
5555 rgw::IAM::s3ListBucketMultiPartUploads
))
5561 void RGWListBucketMultiparts::pre_exec()
5563 rgw_bucket_object_pre_exec(s
);
5566 void RGWListBucketMultiparts::execute()
5568 vector
<rgw_bucket_dir_entry
> objs
;
5571 op_ret
= get_params();
5575 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5577 path_args
= s
->info
.args
.get("path");
5578 if (!path_args
.empty()) {
5579 if (!delimiter
.empty() || !prefix
.empty()) {
5587 marker_meta
= marker
.get_meta();
5589 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5590 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5595 if (!objs
.empty()) {
5596 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5597 RGWMultipartUploadEntry entry
;
5598 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5599 rgw_obj_key
key(iter
->key
);
5600 if (!entry
.mp
.from_meta(key
.name
))
5603 uploads
.push_back(entry
);
5605 next_marker
= entry
;
5609 void RGWGetHealthCheck::execute()
5611 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5612 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5613 /* Disabling path specified & existent in the filesystem. */
5614 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5616 op_ret
= 0; /* 200 OK */
5620 int RGWDeleteMultiObj::verify_permission()
5622 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5623 if (!acl_allowed
&& !s
->iam_policy
)
5629 void RGWDeleteMultiObj::pre_exec()
5631 rgw_bucket_object_pre_exec(s
);
5634 void RGWDeleteMultiObj::execute()
5636 RGWMultiDelDelete
*multi_delete
;
5637 vector
<rgw_obj_key
>::iterator iter
;
5638 RGWMultiDelXMLParser parser
;
5639 int num_processed
= 0;
5640 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5642 op_ret
= get_params();
5652 if (!parser
.init()) {
5657 if (!parser
.parse(data
, len
, 1)) {
5662 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5663 if (!multi_delete
) {
5668 if (multi_delete
->is_quiet())
5672 if (multi_delete
->objects
.empty()) {
5676 for (iter
= multi_delete
->objects
.begin();
5677 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5678 ++iter
, num_processed
++) {
5679 rgw_obj
obj(bucket
, *iter
);
5680 if (s
->iam_policy
) {
5681 auto e
= s
->iam_policy
->eval(s
->env
,
5683 iter
->instance
.empty() ?
5684 rgw::IAM::s3DeleteObject
:
5685 rgw::IAM::s3DeleteObjectVersion
,
5687 if ((e
== Effect::Deny
) ||
5688 (e
== Effect::Pass
&& !acl_allowed
)) {
5689 send_partial_response(*iter
, false, "", -EACCES
);
5694 obj_ctx
->obj
.set_atomic(obj
);
5696 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5697 RGWRados::Object::Delete
del_op(&del_target
);
5699 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5700 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5701 del_op
.params
.obj_owner
= s
->owner
;
5703 op_ret
= del_op
.delete_obj();
5704 if (op_ret
== -ENOENT
) {
5708 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5709 del_op
.result
.version_id
, op_ret
);
5712 /* set the return code to zero, errors at this point will be
5713 dumped to the response */
5717 // will likely segfault if begin_response() has not been called
5729 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5730 map
<string
, bufferlist
>& battrs
,
5731 ACLOwner
& bucket_owner
/* out */)
5733 RGWAccessControlPolicy
bacl(store
->ctx());
5734 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5739 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5741 bucket_owner
= bacl
.get_owner();
5743 /* We can use global user_acl because each BulkDelete request is allowed
5744 * to work on entities from a single account only. */
5745 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5746 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5749 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5751 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5753 RGWBucketInfo binfo
;
5754 map
<string
, bufferlist
> battrs
;
5757 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5758 path
.bucket_name
, binfo
, nullptr,
5764 if (!verify_permission(binfo
, battrs
, bowner
)) {
5769 if (!path
.obj_key
.empty()) {
5770 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5771 obj_ctx
.obj
.set_atomic(obj
);
5773 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5774 RGWRados::Object::Delete
del_op(&del_target
);
5776 del_op
.params
.bucket_owner
= binfo
.owner
;
5777 del_op
.params
.versioning_status
= binfo
.versioning_status();
5778 del_op
.params
.obj_owner
= bowner
;
5780 ret
= del_op
.delete_obj();
5785 RGWObjVersionTracker ot
;
5786 ot
.read_version
= binfo
.ep_objv
;
5788 ret
= store
->delete_bucket(binfo
, ot
);
5790 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5791 binfo
.bucket
.name
, false);
5793 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
5801 if (!store
->is_meta_master()) {
5803 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
5806 if (ret
== -ENOENT
) {
5807 /* adjust error, we want to return with NoSuchBucket and not
5809 ret
= -ERR_NO_SUCH_BUCKET
;
5821 if (-ENOENT
== ret
) {
5822 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
5825 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
5828 fail_desc_t failed_item
= {
5832 failures
.push_back(failed_item
);
5837 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
5839 fail_desc_t failed_item
= {
5843 failures
.push_back(failed_item
);
5848 if (-ENOENT
== ret
) {
5849 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
5852 fail_desc_t failed_item
= {
5856 failures
.push_back(failed_item
);
5861 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
5863 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
5864 for (auto path
: paths
) {
5865 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
5866 delete_single(path
);
5872 int RGWBulkDelete::verify_permission()
5877 void RGWBulkDelete::pre_exec()
5879 rgw_bucket_object_pre_exec(s
);
5882 void RGWBulkDelete::execute()
5884 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
5886 bool is_truncated
= false;
5888 list
<RGWBulkDelete::acct_path_t
> items
;
5890 int ret
= get_data(items
, &is_truncated
);
5895 ret
= deleter
->delete_chunk(items
);
5896 } while (!op_ret
&& is_truncated
);
5902 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
5904 int RGWBulkUploadOp::verify_permission()
5906 if (s
->auth
.identity
->is_anonymous()) {
5910 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
5914 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
5915 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
5916 << " (user_id.tenant=" << s
->user
->user_id
.tenant
5917 << " requested=" << s
->bucket_tenant
<< ")"
5922 if (s
->user
->max_buckets
< 0) {
5929 void RGWBulkUploadOp::pre_exec()
5931 rgw_bucket_object_pre_exec(s
);
5934 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
5935 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
5937 /* We need to skip all slashes at the beginning in order to preserve
5938 * compliance with Swift. */
5939 const size_t start_pos
= path
.find_first_not_of('/');
5941 if (boost::string_ref::npos
!= start_pos
) {
5942 /* Seperator is the first slash after the leading ones. */
5943 const size_t sep_pos
= path
.substr(start_pos
).find('/');
5945 if (boost::string_ref::npos
!= sep_pos
) {
5946 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
5947 const auto obj_name
= path
.substr(sep_pos
+ 1);
5949 return std::make_pair(bucket_name
.to_string(),
5950 rgw_obj_key(obj_name
.to_string()));
5952 /* It's guaranteed here that bucket name is at least one character
5953 * long and is different than slash. */
5954 return std::make_pair(path
.substr(start_pos
).to_string(),
5962 std::pair
<std::string
, std::string
>
5963 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
5965 std::string bucket_path
, file_prefix
;
5966 if (! s
->init_state
.url_bucket
.empty()) {
5967 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
5968 if (! s
->object
.empty()) {
5969 std::string
& object_name
= s
->object
.name
;
5971 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
5972 * we can safely examine its last element. */
5973 if (object_name
.back() == '/') {
5974 file_prefix
.append(object_name
);
5976 file_prefix
.append(object_name
).append("/");
5980 return std::make_pair(bucket_path
, file_prefix
);
5983 int RGWBulkUploadOp::handle_dir_verify_permission()
5985 if (s
->user
->max_buckets
> 0) {
5986 RGWUserBuckets buckets
;
5988 bool is_truncated
= false;
5989 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
5990 marker
, std::string(), s
->user
->max_buckets
,
5991 false, &is_truncated
);
5996 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
5997 return -ERR_TOO_MANY_BUCKETS
;
6004 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
6006 /* the request of container or object level will contain bucket name.
6007 * only at account level need to append the bucket name */
6008 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
6012 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
6013 info
.script_uri
.append("/").append(bucket_name
);
6014 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
6015 info
.effective_uri
= "/" + bucket_name
;
6018 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
6020 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
6022 op_ret
= handle_dir_verify_permission();
6027 std::string bucket_name
;
6028 rgw_obj_key object_junk
;
6029 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
6031 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
6032 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
6034 /* we need to make sure we read bucket info, it's not read before for this
6035 * specific request */
6036 RGWBucketInfo binfo
;
6037 std::map
<std::string
, ceph::bufferlist
> battrs
;
6038 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6039 binfo
, NULL
, &battrs
);
6040 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6043 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6045 if (bucket_exists
) {
6046 RGWAccessControlPolicy
old_policy(s
->cct
);
6047 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6048 battrs
, &old_policy
);
6050 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6057 RGWBucketInfo master_info
;
6058 rgw_bucket
*pmaster_bucket
= nullptr;
6059 uint32_t *pmaster_num_shards
= nullptr;
6060 real_time creation_time
;
6061 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6063 if (! store
->is_meta_master()) {
6065 ceph::bufferlist in_data
;
6066 req_info info
= s
->info
;
6067 forward_req_info(s
->cct
, info
, bucket_name
);
6068 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6073 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6074 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6075 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6077 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
6078 << objv
.ver
<< dendl
;
6079 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
6082 pmaster_bucket
= &master_info
.bucket
;
6083 creation_time
= master_info
.creation_time
;
6084 pmaster_num_shards
= &master_info
.num_shards
;
6087 pmaster_bucket
= nullptr;
6088 pmaster_num_shards
= nullptr;
6092 std::string placement_rule
;
6093 if (bucket_exists
) {
6094 std::string selected_placement_rule
;
6096 bucket
.tenant
= s
->bucket_tenant
;
6097 bucket
.name
= s
->bucket_name
;
6098 op_ret
= store
->select_bucket_placement(*(s
->user
),
6099 store
->get_zonegroup().get_id(),
6101 &selected_placement_rule
,
6103 if (selected_placement_rule
!= binfo
.placement_rule
) {
6105 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6110 /* Create metadata: ACLs. */
6111 std::map
<std::string
, ceph::bufferlist
> attrs
;
6112 RGWAccessControlPolicy policy
;
6113 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6114 ceph::bufferlist aclbl
;
6115 policy
.encode(aclbl
);
6116 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6118 RGWQuotaInfo quota_info
;
6119 const RGWQuotaInfo
* pquota_info
= nullptr;
6122 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6123 bucket
.name
= bucket_name
;
6126 RGWBucketInfo out_info
;
6127 op_ret
= store
->create_bucket(*(s
->user
),
6129 store
->get_zonegroup().get_id(),
6130 placement_rule
, binfo
.swift_ver_location
,
6132 out_info
, pobjv
, &ep_objv
, creation_time
,
6133 pmaster_bucket
, pmaster_num_shards
, true);
6134 /* continue if EEXIST and create_bucket will fail below. this way we can
6135 * recover from a partial create by retrying it. */
6136 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6137 << ", bucket=" << bucket
<< dendl
;
6139 if (op_ret
&& op_ret
!= -EEXIST
) {
6143 const bool existed
= (op_ret
== -EEXIST
);
6145 /* bucket already existed, might have raced with another bucket creation, or
6146 * might be partial bucket creation that never completed. Read existing bucket
6147 * info, verify that the reported bucket owner is the current user.
6148 * If all is ok then update the user's list of buckets.
6149 * Otherwise inform client about a name conflict.
6151 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6153 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6156 bucket
= out_info
.bucket
;
6159 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6160 out_info
.creation_time
, false);
6161 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6162 /* if it exists (or previously existed), don't remove it! */
6163 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6164 bucket
.tenant
, bucket
.name
);
6166 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6169 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6170 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6172 op_ret
= -ERR_BUCKET_EXISTS
;
6179 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6181 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6182 ACLOwner
& bucket_owner
/* out */)
6184 RGWAccessControlPolicy
bacl(store
->ctx());
6185 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6187 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6192 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6194 bucket_owner
= bacl
.get_owner();
6196 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6197 rgw::IAM::s3PutObject
, obj
);
6198 if (e
== Effect::Allow
) {
6200 } else if (e
== Effect::Deny
) {
6205 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6206 &bacl
, RGW_PERM_WRITE
);
6209 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6211 AlignedStreamGetter
& body
)
6214 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6217 RGWPutObjDataProcessor
*filter
= nullptr;
6218 boost::optional
<RGWPutObj_Compress
> compressor
;
6220 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6221 op_ret
= -ERR_TOO_LARGE
;
6225 std::string bucket_name
;
6227 std::tie(bucket_name
, object
) = *parse_path(path
);
6229 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6230 RGWBucketInfo binfo
;
6231 std::map
<std::string
, ceph::bufferlist
> battrs
;
6233 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6234 bucket_name
, binfo
, nullptr, &battrs
);
6235 if (op_ret
== -ENOENT
) {
6236 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6238 } else if (op_ret
< 0) {
6242 if (! handle_file_verify_permission(binfo
,
6243 rgw_obj(binfo
.bucket
, object
),
6245 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6250 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6251 user_quota
, bucket_quota
, size
);
6256 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6261 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6266 s
->cct
->_conf
->rgw_obj_stripe_size
,
6268 binfo
.versioning_enabled());
6270 /* No filters by default. */
6271 filter
= &processor
;
6273 op_ret
= processor
.prepare(store
, nullptr);
6275 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6280 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6281 binfo
.placement_rule
);
6282 CompressorRef plugin
;
6283 if (compression_type
!= "none") {
6284 plugin
= Compressor::create(s
->cct
, compression_type
);
6286 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6287 << compression_type
<< dendl
;
6289 compressor
.emplace(s
->cct
, plugin
, filter
);
6290 filter
= &*compressor
;
6294 /* Upload file content. */
6299 ceph::bufferlist data
;
6300 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6302 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6306 } else if (len
> 0) {
6307 hash
.Update((const byte
*)data
.c_str(), data
.length());
6308 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6310 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6321 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6326 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6327 user_quota
, bucket_quota
, size
);
6329 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6334 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6339 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6340 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6342 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6344 /* Create metadata: ETAG. */
6345 std::map
<std::string
, ceph::bufferlist
> attrs
;
6346 std::string etag
= calc_md5
;
6347 ceph::bufferlist etag_bl
;
6348 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6349 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6351 /* Create metadata: ACLs. */
6352 RGWAccessControlPolicy policy
;
6353 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6354 ceph::bufferlist aclbl
;
6355 policy
.encode(aclbl
);
6356 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6358 /* Create metadata: compression info. */
6359 if (compressor
&& compressor
->is_compressed()) {
6360 ceph::bufferlist tmp
;
6361 RGWCompressionInfo cs_info
;
6362 cs_info
.compression_type
= plugin
->get_type_name();
6363 cs_info
.orig_size
= s
->obj_size
;
6364 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6365 ::encode(cs_info
, tmp
);
6366 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6369 /* Complete the transaction. */
6370 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6371 ceph::real_time() /* delete_at */);
6373 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6380 void RGWBulkUploadOp::execute()
6382 ceph::bufferlist
buffer(64 * 1024);
6384 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6386 /* Create an instance of stream-abstracting class. Having this indirection
6387 * allows for easy introduction of decompressors like gzip and bzip2. */
6388 auto stream
= create_stream();
6393 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6394 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6395 std::string bucket_path
, file_prefix
;
6396 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6398 auto status
= rgw::tar::StatusIndicator::create();
6400 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6402 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6406 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6407 * must be tracked to detect out end-of-archive. It occurs when both of
6408 * them are empty (zeroed). Tracing this particular inter-block dependency
6409 * is responsibility of the rgw::tar::StatusIndicator class. */
6410 boost::optional
<rgw::tar::HeaderView
> header
;
6411 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6413 if (! status
.empty() && header
) {
6414 /* This specific block isn't empty (entirely zeroed), so we can parse
6415 * it as a TAR header and dispatch. At the moment we do support only
6416 * regular files and directories. Everything else (symlinks, devices)
6417 * will be ignored but won't cease the whole upload. */
6418 switch (header
->get_filetype()) {
6419 case rgw::tar::FileType::NORMAL_FILE
: {
6420 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6422 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6423 file_prefix
+ header
->get_filename().to_string();
6424 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6425 rgw::tar::BLOCK_SIZE
, *stream
);
6426 op_ret
= handle_file(filename
,
6427 header
->get_filesize(),
6430 /* Only regular files counts. */
6433 failures
.emplace_back(op_ret
, filename
.to_string());
6437 case rgw::tar::FileType::DIRECTORY
: {
6438 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6440 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6441 op_ret
= handle_dir(dirname
);
6442 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6443 failures
.emplace_back(op_ret
, dirname
.to_string());
6448 /* Not recognized. Skip. */
6454 /* In case of any problems with sub-request authorization Swift simply
6455 * terminates whole upload immediately. */
6456 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6458 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6463 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6468 } while (! status
.eof());
6473 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6475 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6476 ceph::bufferlist junk
;
6478 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6481 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6482 ceph::bufferlist
& dst
)
6484 const size_t max_to_read
= std::min(want
, length
- position
);
6485 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6492 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6493 ceph::bufferlist
& dst
)
6495 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6502 int RGWSetAttrs::verify_permission()
6504 // This looks to be part of the RGW-NFS machinery and has no S3 or
6505 // Swift equivalent.
6507 if (!s
->object
.empty()) {
6508 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6510 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6518 void RGWSetAttrs::pre_exec()
6520 rgw_bucket_object_pre_exec(s
);
6523 void RGWSetAttrs::execute()
6525 op_ret
= get_params();
6529 rgw_obj
obj(s
->bucket
, s
->object
);
6531 if (!s
->object
.empty()) {
6532 store
->set_atomic(s
->obj_ctx
, obj
);
6533 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6535 for (auto& iter
: attrs
) {
6536 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6538 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6539 &s
->bucket_info
.objv_tracker
);
6543 void RGWGetObjLayout::pre_exec()
6545 rgw_bucket_object_pre_exec(s
);
6548 void RGWGetObjLayout::execute()
6550 rgw_obj
obj(s
->bucket
, s
->object
);
6551 RGWRados::Object
target(store
,
6553 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6554 rgw_obj(s
->bucket
, s
->object
));
6555 RGWRados::Object::Read
stat_op(&target
);
6557 op_ret
= stat_op
.prepare();
6562 head_obj
= stat_op
.state
.head_obj
;
6564 op_ret
= target
.get_manifest(&manifest
);
6568 int RGWConfigBucketMetaSearch::verify_permission()
6570 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6577 void RGWConfigBucketMetaSearch::pre_exec()
6579 rgw_bucket_object_pre_exec(s
);
6582 void RGWConfigBucketMetaSearch::execute()
6584 op_ret
= get_params();
6586 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6590 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6592 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6594 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6599 int RGWGetBucketMetaSearch::verify_permission()
6601 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6608 void RGWGetBucketMetaSearch::pre_exec()
6610 rgw_bucket_object_pre_exec(s
);
6613 int RGWDelBucketMetaSearch::verify_permission()
6615 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6622 void RGWDelBucketMetaSearch::pre_exec()
6624 rgw_bucket_object_pre_exec(s
);
6627 void RGWDelBucketMetaSearch::execute()
6629 s
->bucket_info
.mdsearch_config
.clear();
6631 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6633 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6639 RGWHandler::~RGWHandler()
6643 int RGWHandler::init(RGWRados
*_store
,
6644 struct req_state
*_s
,
6645 rgw::io::BasicClient
*cio
)
6653 int RGWHandler::do_init_permissions()
6655 int ret
= rgw_build_bucket_policies(store
, s
);
6656 s
->env
= rgw_build_iam_environment(store
, s
);
6659 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6660 if (ret
== -ENODATA
)
6667 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6670 /* already read bucket info */
6673 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6676 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6677 << s
->object
<< " only_bucket=" << only_bucket
6678 << " ret=" << ret
<< dendl
;
6679 if (ret
== -ENODATA
)
6686 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6687 return dialect_handler
->error_handler(err_no
, error_content
);
6690 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6691 // This is the do-nothing error handler
6696 void RGWPutBucketPolicy::send_response()
6699 set_req_state_err(s
, op_ret
);
6705 int RGWPutBucketPolicy::verify_permission()
6707 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6714 int RGWPutBucketPolicy::get_params()
6716 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6717 // At some point when I have more time I want to make a version of
6718 // rgw_rest_read_all_input that doesn't use malloc.
6719 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6720 // And throws exceptions.
6724 void RGWPutBucketPolicy::execute()
6726 op_ret
= get_params();
6731 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6733 if (!store
->is_meta_master()) {
6734 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6736 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6742 Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6743 auto attrs
= s
->bucket_attrs
;
6744 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6745 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6746 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6747 &s
->bucket_info
.objv_tracker
);
6748 if (op_ret
== -ECANCELED
) {
6749 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */
6751 } catch (rgw::IAM::PolicyParseException
& e
) {
6752 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6757 void RGWGetBucketPolicy::send_response()
6760 set_req_state_err(s
, op_ret
);
6763 end_header(s
, this, "application/json");
6764 dump_body(s
, policy
);
6767 int RGWGetBucketPolicy::verify_permission()
6769 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6776 void RGWGetBucketPolicy::execute()
6778 auto attrs
= s
->bucket_attrs
;
6779 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6780 if (aiter
== attrs
.end()) {
6781 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6782 << " bucket_name = " << s
->bucket_name
<< dendl
;
6783 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6784 s
->err
.message
= "The bucket policy does not exist";
6787 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6789 if (policy
.length() == 0) {
6790 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6791 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6792 s
->err
.message
= "The bucket policy does not exist";
6798 void RGWDeleteBucketPolicy::send_response()
6801 set_req_state_err(s
, op_ret
);
6807 int RGWDeleteBucketPolicy::verify_permission()
6809 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
6816 void RGWDeleteBucketPolicy::execute()
6818 auto attrs
= s
->bucket_attrs
;
6819 attrs
.erase(RGW_ATTR_IAM_POLICY
);
6820 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6821 &s
->bucket_info
.objv_tracker
);
6822 if (op_ret
== -ECANCELED
) {
6823 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */