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
;
3020 head_obj_op
.meta
.modify_tail
= true;
3022 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3027 RGWUploadPartInfo info
;
3029 bool sorted_omap
= is_v2_upload_id(upload_id
);
3033 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3035 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3039 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3044 info
.num
= atoi(part_num
.c_str());
3046 info
.size
= obj_len
;
3047 info
.accounted_size
= accounted_size
;
3048 info
.modified
= real_clock::now();
3049 info
.manifest
= manifest
;
3052 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3054 dout(1) << "cannot get compression info" << dendl
;
3060 string multipart_meta_obj
= mp
.get_meta();
3063 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3064 meta_obj
.set_in_extra_data(true);
3066 rgw_raw_obj raw_meta_obj
;
3068 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3070 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3075 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3077 RGWPutObjProcessor
*processor
;
3079 bool multipart
= s
->info
.args
.exists("uploadId");
3081 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3084 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3085 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3086 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3088 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3092 *is_multipart
= multipart
;
3098 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3103 void RGWPutObj::pre_exec()
3105 rgw_bucket_object_pre_exec(s
);
3108 class RGWPutObj_CB
: public RGWGetDataCB
3112 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3113 ~RGWPutObj_CB() override
{}
3115 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3116 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3120 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3123 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3125 bl_aux
.append(bl_tmp
);
3130 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3132 RGWPutObj_CB
cb(this);
3133 RGWGetDataCB
* filter
= &cb
;
3134 boost::optional
<RGWGetObj_Decompress
> decompress
;
3135 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3136 RGWCompressionInfo cs_info
;
3137 map
<string
, bufferlist
> attrs
;
3138 map
<string
, bufferlist
>::iterator attr_iter
;
3142 int64_t new_ofs
, new_end
;
3147 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3148 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3150 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3151 RGWRados::Object::Read
read_op(&op_target
);
3152 read_op
.params
.obj_size
= &obj_size
;
3153 read_op
.params
.attrs
= &attrs
;
3155 ret
= read_op
.prepare();
3159 bool need_decompress
;
3160 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3162 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3166 bool partial_content
= true;
3167 if (need_decompress
)
3169 obj_size
= cs_info
.orig_size
;
3170 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3171 filter
= &*decompress
;
3174 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3175 op_ret
= this->get_decrypt_filter(&decrypt
,
3178 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3179 if (decrypt
!= nullptr) {
3180 filter
= decrypt
.get();
3186 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3190 filter
->fixup_range(new_ofs
, new_end
);
3191 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3194 ret
= filter
->flush();
3196 bl
.claim_append(bl_aux
);
3201 // special handling for compression type = "random" with multipart uploads
3202 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3203 const std::string
& compression_type
)
3205 if (compression_type
!= "random") {
3206 return Compressor::create(s
->cct
, compression_type
);
3209 bool is_multipart
{false};
3210 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3212 if (!is_multipart
) {
3213 return Compressor::create(s
->cct
, compression_type
);
3216 // use a hash of the multipart upload id so all parts use the same plugin
3217 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3218 if (alg
== Compressor::COMP_ALG_NONE
) {
3221 return Compressor::create(s
->cct
, alg
);
3224 void RGWPutObj::execute()
3226 RGWPutObjProcessor
*processor
= NULL
;
3227 RGWPutObjDataProcessor
*filter
= nullptr;
3228 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3229 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3230 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3231 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3232 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3234 bufferlist bl
, aclbl
, bs
;
3236 map
<string
, string
>::iterator iter
;
3241 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3242 s
->bucket_info
.placement_rule
);
3243 CompressorRef plugin
;
3244 boost::optional
<RGWPutObj_Compress
> compressor
;
3246 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3247 perfcounter
->inc(l_rgw_put
);
3249 if (s
->object
.empty()) {
3253 if (!s
->bucket_exists
) {
3254 op_ret
= -ERR_NO_SUCH_BUCKET
;
3258 op_ret
= get_params();
3260 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3264 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3266 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3271 if (supplied_md5_b64
) {
3272 need_calc_md5
= true;
3274 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3275 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3276 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3277 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3278 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3279 op_ret
= -ERR_INVALID_DIGEST
;
3283 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3284 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3287 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3288 we also check sizes at the end anyway */
3289 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3290 user_quota
, bucket_quota
, s
->content_length
);
3292 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3295 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3297 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3302 if (supplied_etag
) {
3303 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3304 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3307 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3309 // no filters by default
3312 /* Handle object versioning of Swift API. */
3314 rgw_obj
obj(s
->bucket
, s
->object
);
3315 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3316 s
->bucket_owner
.get_id(),
3324 op_ret
= processor
->prepare(store
, NULL
);
3326 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3331 fst
= copy_source_range_fst
;
3332 lst
= copy_source_range_lst
;
3334 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3338 if (encrypt
!= nullptr) {
3339 filter
= encrypt
.get();
3341 //no encryption, we can try compression
3342 if (compression_type
!= "none") {
3343 plugin
= get_compressor_plugin(s
, compression_type
);
3345 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3346 << compression_type
<< dendl
;
3348 compressor
.emplace(s
->cct
, plugin
, filter
);
3349 filter
= &*compressor
;
3359 len
= get_data(data
);
3361 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3362 op_ret
= get_data(fst
, cur_lst
, data
);
3365 len
= data
.length();
3366 s
->content_length
+= len
;
3374 if (need_calc_md5
) {
3375 hash
.Update((const byte
*)data
.c_str(), data
.length());
3378 /* update torrrent */
3379 torrent
.update(data
);
3381 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3382 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3384 bool need_to_wait
= (ofs
== 0) && multipart
;
3386 bufferlist orig_data
;
3392 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3394 if (!need_to_wait
|| op_ret
!= -EEXIST
) {
3395 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3399 /* need_to_wait == true and op_ret == -EEXIST */
3400 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3402 /* restore original data */
3403 data
.swap(orig_data
);
3405 /* restart processing with different oid suffix */
3407 dispose_processor(processor
);
3408 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3413 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3414 oid_rand
.append(buf
);
3416 op_ret
= processor
->prepare(store
, &oid_rand
);
3418 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3423 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3427 if (encrypt
!= nullptr) {
3428 filter
= encrypt
.get();
3431 compressor
.emplace(s
->cct
, plugin
, filter
);
3432 filter
= &*compressor
;
3435 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3446 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3452 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3453 op_ret
= -ERR_REQUEST_TIMEOUT
;
3458 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3460 op_ret
= do_aws4_auth_completion();
3465 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3466 user_quota
, bucket_quota
, s
->obj_size
);
3468 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3472 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3474 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3480 if (compressor
&& compressor
->is_compressed()) {
3482 RGWCompressionInfo cs_info
;
3483 cs_info
.compression_type
= plugin
->get_type_name();
3484 cs_info
.orig_size
= s
->obj_size
;
3485 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3486 ::encode(cs_info
, tmp
);
3487 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3488 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3489 << " with type=" << cs_info
.compression_type
3490 << ", orig_size=" << cs_info
.orig_size
3491 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3494 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3498 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3499 op_ret
= -ERR_BAD_DIGEST
;
3503 policy
.encode(aclbl
);
3504 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3507 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3509 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3512 complete_etag(hash
, &etag
);
3513 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3517 bufferlist manifest_bl
;
3518 ::encode(*slo_info
, manifest_bl
);
3519 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3521 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3522 complete_etag(hash
, &etag
);
3523 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3526 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3527 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3530 bl
.append(etag
.c_str(), etag
.size() + 1);
3531 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3533 populate_with_generic_attrs(s
, attrs
);
3534 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3535 encode_delete_at_attr(delete_at
, attrs
);
3536 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3538 /* Add a custom metadata to expose the information whether an object
3539 * is an SLO or not. Appending the attribute must be performed AFTER
3540 * processing any input from user in order to prohibit overwriting. */
3542 bufferlist slo_userindicator_bl
;
3543 slo_userindicator_bl
.append("True", 4);
3544 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3547 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3548 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3549 (user_data
.empty() ? nullptr : &user_data
));
3551 /* produce torrent */
3552 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3554 torrent
.init(s
, store
);
3555 torrent
.set_create_date(mtime
);
3556 op_ret
= torrent
.complete();
3559 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3565 dispose_processor(processor
);
3566 perfcounter
->tinc(l_rgw_put_lat
,
3567 (ceph_clock_now() - s
->time
));
3570 int RGWPostObj::verify_permission()
3575 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3577 RGWPutObjProcessor *processor;
3579 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3581 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3586 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3591 void RGWPostObj::pre_exec()
3593 rgw_bucket_object_pre_exec(s
);
3596 void RGWPostObj::execute()
3598 RGWPutObjDataProcessor
*filter
= nullptr;
3599 boost::optional
<RGWPutObj_Compress
> compressor
;
3600 CompressorRef plugin
;
3601 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3603 /* Read in the data from the POST form. */
3604 op_ret
= get_params();
3609 op_ret
= verify_params();
3614 if (s
->iam_policy
) {
3615 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3616 rgw::IAM::s3PutObject
,
3617 rgw_obj(s
->bucket
, s
->object
));
3618 if (e
== Effect::Deny
) {
3621 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3625 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3630 /* Start iteration over data fields. It's necessary as Swift's FormPost
3631 * is capable to handle multiple files in single form. */
3633 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3634 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3635 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3637 ceph::buffer::list bl
, aclbl
;
3640 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3649 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3654 if (supplied_md5_b64
) {
3655 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3656 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3657 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3658 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3659 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3660 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3661 op_ret
= -ERR_INVALID_DIGEST
;
3665 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3666 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3669 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3672 get_current_filename(),
3674 s
->cct
->_conf
->rgw_obj_stripe_size
,
3676 s
->bucket_info
.versioning_enabled());
3677 /* No filters by default. */
3678 filter
= &processor
;
3680 op_ret
= processor
.prepare(store
, nullptr);
3685 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3689 if (encrypt
!= nullptr) {
3690 filter
= encrypt
.get();
3692 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3693 s
->bucket_info
.placement_rule
);
3694 if (compression_type
!= "none") {
3695 plugin
= Compressor::create(s
->cct
, compression_type
);
3697 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3698 << compression_type
<< dendl
;
3700 compressor
.emplace(s
->cct
, plugin
, filter
);
3701 filter
= &*compressor
;
3708 ceph::bufferlist data
;
3709 len
= get_data(data
, again
);
3720 hash
.Update((const byte
*)data
.c_str(), data
.length());
3721 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3725 if (ofs
> max_len
) {
3726 op_ret
= -ERR_TOO_LARGE
;
3733 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3736 if (len
< min_len
) {
3737 op_ret
= -ERR_TOO_SMALL
;
3743 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3744 op_ret
= -ERR_BAD_DIGEST
;
3748 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3749 user_quota
, bucket_quota
, s
->obj_size
);
3754 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3760 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3763 bl
.append(etag
.c_str(), etag
.size() + 1);
3764 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3766 policy
.encode(aclbl
);
3767 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3769 const std::string content_type
= get_current_content_type();
3770 if (! content_type
.empty()) {
3771 ceph::bufferlist ct_bl
;
3772 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3773 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3776 if (compressor
&& compressor
->is_compressed()) {
3777 ceph::bufferlist tmp
;
3778 RGWCompressionInfo cs_info
;
3779 cs_info
.compression_type
= plugin
->get_type_name();
3780 cs_info
.orig_size
= s
->obj_size
;
3781 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3782 ::encode(cs_info
, tmp
);
3783 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3786 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3787 attrs
, (delete_at
? *delete_at
: real_time()));
3788 } while (is_next_file_to_upload());
3792 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3793 const set
<string
>& rmattr_names
,
3794 map
<int, string
>& temp_url_keys
)
3796 map
<string
, bufferlist
>::iterator iter
;
3798 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3799 if (iter
!= add_attrs
.end()) {
3800 temp_url_keys
[0] = iter
->second
.c_str();
3801 add_attrs
.erase(iter
);
3804 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3805 if (iter
!= add_attrs
.end()) {
3806 temp_url_keys
[1] = iter
->second
.c_str();
3807 add_attrs
.erase(iter
);
3810 for (const string
& name
: rmattr_names
) {
3811 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3812 temp_url_keys
[0] = string();
3814 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3815 temp_url_keys
[1] = string();
3820 int RGWPutMetadataAccount::init_processing()
3822 /* First, go to the base class. At the time of writing the method was
3823 * responsible only for initializing the quota. This isn't necessary
3824 * here as we are touching metadata only. I'm putting this call only
3825 * for the future. */
3826 op_ret
= RGWOp::init_processing();
3831 op_ret
= get_params();
3836 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3844 policy
.encode(acl_bl
);
3845 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3848 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3849 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3850 populate_with_generic_attrs(s
, attrs
);
3852 /* Try extract the TempURL-related stuff now to allow verify_permission
3853 * evaluate whether we need FULL_CONTROL or not. */
3854 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3856 /* The same with quota except a client needs to be reseller admin. */
3857 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3858 &new_quota_extracted
);
3866 int RGWPutMetadataAccount::verify_permission()
3868 if (s
->auth
.identity
->is_anonymous()) {
3872 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
3876 /* Altering TempURL keys requires FULL_CONTROL. */
3877 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
3881 /* We are failing this intensionally to allow system user/reseller admin
3882 * override in rgw_process.cc. This is the way to specify a given RGWOp
3883 * expect extra privileges. */
3884 if (new_quota_extracted
) {
3891 void RGWPutMetadataAccount::execute()
3893 /* Params have been extracted earlier. See init_processing(). */
3894 RGWUserInfo new_uinfo
;
3895 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
3901 /* Handle the TempURL-related stuff. */
3902 if (!temp_url_keys
.empty()) {
3903 for (auto& pair
: temp_url_keys
) {
3904 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
3908 /* Handle the quota extracted at the verify_permission step. */
3909 if (new_quota_extracted
) {
3910 new_uinfo
.user_quota
= std::move(new_quota
);
3913 /* We are passing here the current (old) user info to allow the function
3914 * optimize-out some operations. */
3915 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
3916 &acct_op_tracker
, real_time(), false, &attrs
);
3919 int RGWPutMetadataBucket::verify_permission()
3921 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3928 void RGWPutMetadataBucket::pre_exec()
3930 rgw_bucket_object_pre_exec(s
);
3933 void RGWPutMetadataBucket::execute()
3935 op_ret
= get_params();
3940 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3942 if (!placement_rule
.empty() &&
3943 placement_rule
!= s
->bucket_info
.placement_rule
) {
3948 /* Encode special metadata first as we're using std::map::emplace under
3949 * the hood. This method will add the new items only if the map doesn't
3950 * contain such keys yet. */
3952 if (s
->dialect
.compare("swift") == 0) {
3954 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
3955 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
3956 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
3957 policy
= *new_policy
;
3961 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
3966 cors_config
.encode(bl
);
3967 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
3970 /* It's supposed that following functions WILL NOT change any special
3971 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
3972 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
3973 populate_with_generic_attrs(s
, attrs
);
3975 /* According to the Swift's behaviour and its container_quota WSGI middleware
3976 * implementation: anyone with write permissions is able to set the bucket
3977 * quota. This stays in contrast to account quotas that can be set only by
3978 * clients holding reseller admin privileges. */
3979 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
3984 if (swift_ver_location
) {
3985 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
3986 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
3989 /* Web site of Swift API. */
3990 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
3991 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
3993 /* Setting attributes also stores the provided bucket info. Due to this
3994 * fact, the new quota settings can be serialized with the same call. */
3995 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
3996 &s
->bucket_info
.objv_tracker
);
3999 int RGWPutMetadataObject::verify_permission()
4001 // This looks to be something specific to Swift. We could add
4002 // operations like swift:PutMetadataObject to the Policy Engine.
4003 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4010 void RGWPutMetadataObject::pre_exec()
4012 rgw_bucket_object_pre_exec(s
);
4015 void RGWPutMetadataObject::execute()
4017 rgw_obj
obj(s
->bucket
, s
->object
);
4018 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4020 store
->set_atomic(s
->obj_ctx
, obj
);
4022 op_ret
= get_params();
4027 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4028 /* check if obj exists, read orig attrs */
4029 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4034 /* Check whether the object has expired. Swift API documentation
4035 * stands that we should return 404 Not Found in such case. */
4036 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4041 /* Filter currently existing attributes. */
4042 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4043 populate_with_generic_attrs(s
, attrs
);
4044 encode_delete_at_attr(delete_at
, attrs
);
4047 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4049 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4054 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4057 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4059 RGWSLOInfo slo_info
;
4060 bufferlist::iterator bliter
= bl
.begin();
4062 ::decode(slo_info
, bliter
);
4063 } catch (buffer::error
& err
) {
4064 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4069 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4070 new RGWBulkDelete::Deleter(store
, s
));
4071 } catch (std::bad_alloc
) {
4075 list
<RGWBulkDelete::acct_path_t
> items
;
4076 for (const auto& iter
: slo_info
.entries
) {
4077 const string
& path_str
= iter
.path
;
4079 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4080 if (boost::string_view::npos
== sep_pos
) {
4084 RGWBulkDelete::acct_path_t path
;
4086 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4087 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4089 items
.push_back(path
);
4092 /* Request removal of the manifest object itself. */
4093 RGWBulkDelete::acct_path_t path
;
4094 path
.bucket_name
= s
->bucket_name
;
4095 path
.obj_key
= s
->object
;
4096 items
.push_back(path
);
4098 int ret
= deleter
->delete_chunk(items
);
4106 int RGWDeleteObj::verify_permission()
4108 if (s
->iam_policy
) {
4109 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4110 s
->object
.instance
.empty() ?
4111 rgw::IAM::s3DeleteObject
:
4112 rgw::IAM::s3DeleteObjectVersion
,
4113 ARN(s
->bucket
, s
->object
.name
));
4114 if (r
== Effect::Allow
)
4116 else if (r
== Effect::Deny
)
4120 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4127 void RGWDeleteObj::pre_exec()
4129 rgw_bucket_object_pre_exec(s
);
4132 void RGWDeleteObj::execute()
4134 if (!s
->bucket_exists
) {
4135 op_ret
= -ERR_NO_SUCH_BUCKET
;
4139 op_ret
= get_params();
4144 rgw_obj
obj(s
->bucket
, s
->object
);
4145 map
<string
, bufferlist
> attrs
;
4148 if (!s
->object
.empty()) {
4149 if (need_object_expiration() || multipart_delete
) {
4150 /* check if obj exists, read orig attrs */
4151 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4157 if (multipart_delete
) {
4158 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4160 if (slo_attr
!= attrs
.end()) {
4161 op_ret
= handle_slo_manifest(slo_attr
->second
);
4163 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4166 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4172 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4173 obj_ctx
->obj
.set_atomic(obj
);
4175 bool ver_restored
= false;
4176 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4177 s
->bucket_info
, obj
, ver_restored
);
4182 if (!ver_restored
) {
4183 /* Swift's versioning mechanism hasn't found any previous version of
4184 * the object that could be restored. This means we should proceed
4185 * with the regular delete path. */
4186 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4187 RGWRados::Object::Delete
del_op(&del_target
);
4189 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4190 &del_op
.params
.marker_version_id
);
4195 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4196 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4197 del_op
.params
.obj_owner
= s
->owner
;
4198 del_op
.params
.unmod_since
= unmod_since
;
4199 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4201 op_ret
= del_op
.delete_obj();
4203 delete_marker
= del_op
.result
.delete_marker
;
4204 version_id
= del_op
.result
.version_id
;
4207 /* Check whether the object has expired. Swift API documentation
4208 * stands that we should return 404 Not Found in such case. */
4209 if (need_object_expiration() && object_is_expired(attrs
)) {
4215 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4224 bool RGWCopyObj::parse_copy_location(const string
& url_src
, string
& bucket_name
, rgw_obj_key
& key
)
4229 size_t pos
= url_src
.find('?');
4230 if (pos
== string::npos
) {
4233 name_str
= url_src
.substr(0, pos
);
4234 params_str
= url_src
.substr(pos
+ 1);
4237 std::string dec_src
= url_decode(name_str
);
4238 const char *src
= dec_src
.c_str();
4240 if (*src
== '/') ++src
;
4244 pos
= str
.find('/');
4245 if (pos
==string::npos
)
4248 bucket_name
= str
.substr(0, pos
);
4249 key
.name
= str
.substr(pos
+ 1);
4251 if (key
.name
.empty()) {
4255 if (!params_str
.empty()) {
4257 args
.set(params_str
);
4260 key
.instance
= args
.get("versionId", NULL
);
4266 int RGWCopyObj::verify_permission()
4268 RGWAccessControlPolicy
src_acl(s
->cct
);
4269 optional
<Policy
> src_policy
;
4270 op_ret
= get_params();
4274 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4278 map
<string
, bufferlist
> src_attrs
;
4280 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4282 if (s
->bucket_instance_id
.empty()) {
4283 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4285 /* will only happen in intra region sync where the source and dest bucket is the same */
4286 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4289 if (op_ret
== -ENOENT
) {
4290 op_ret
= -ERR_NO_SUCH_BUCKET
;
4295 src_bucket
= src_bucket_info
.bucket
;
4297 /* get buckets info (source and dest) */
4298 if (s
->local_source
&& source_zone
.empty()) {
4299 rgw_obj
src_obj(src_bucket
, src_object
);
4300 store
->set_atomic(s
->obj_ctx
, src_obj
);
4301 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4303 /* check source object permissions */
4304 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4305 src_policy
, src_bucket
, src_object
);
4310 /* admin request overrides permission checks */
4311 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4313 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4314 src_object
.instance
.empty() ?
4315 rgw::IAM::s3GetObject
:
4316 rgw::IAM::s3GetObjectVersion
,
4318 if (e
== Effect::Deny
) {
4320 } else if (e
== Effect::Pass
&&
4321 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4325 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4333 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4334 map
<string
, bufferlist
> dest_attrs
;
4336 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4337 or intra region sync */
4338 dest_bucket_info
= src_bucket_info
;
4339 dest_attrs
= src_attrs
;
4341 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4342 dest_bucket_info
, nullptr, &dest_attrs
);
4344 if (op_ret
== -ENOENT
) {
4345 op_ret
= -ERR_NO_SUCH_BUCKET
;
4351 dest_bucket
= dest_bucket_info
.bucket
;
4353 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4354 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4356 /* check dest bucket permissions */
4357 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4358 &dest_bucket_policy
, dest_bucket
);
4363 /* admin request overrides permission checks */
4364 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4365 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4370 op_ret
= init_dest_policy();
4379 int RGWCopyObj::init_common()
4382 if (parse_time(if_mod
, &mod_time
) < 0) {
4386 mod_ptr
= &mod_time
;
4390 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4394 unmod_ptr
= &unmod_time
;
4398 dest_policy
.encode(aclbl
);
4399 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4401 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4402 populate_with_generic_attrs(s
, attrs
);
4407 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4409 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4410 op
->progress_cb(ofs
);
4413 void RGWCopyObj::progress_cb(off_t ofs
)
4415 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4418 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4421 send_partial_response(ofs
);
4426 void RGWCopyObj::pre_exec()
4428 rgw_bucket_object_pre_exec(s
);
4431 void RGWCopyObj::execute()
4433 if (init_common() < 0)
4436 rgw_obj
src_obj(src_bucket
, src_object
);
4437 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4439 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4440 obj_ctx
.obj
.set_atomic(src_obj
);
4441 obj_ctx
.obj
.set_atomic(dst_obj
);
4443 encode_delete_at_attr(delete_at
, attrs
);
4445 bool high_precision_time
= (s
->system_request
);
4447 /* Handle object versioning of Swift API. In case of copying to remote this
4448 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4449 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4450 dest_bucket_info
.owner
,
4457 op_ret
= store
->copy_obj(obj_ctx
,
4471 high_precision_time
,
4476 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4478 (delete_at
? *delete_at
: real_time()),
4479 (version_id
.empty() ? NULL
: &version_id
),
4480 &s
->req_id
, /* use req_id as tag */
4482 copy_obj_progress_cb
, (void *)this
4486 int RGWGetACLs::verify_permission()
4489 if (!s
->object
.empty()) {
4490 perm
= verify_object_permission(s
,
4491 s
->object
.instance
.empty() ?
4492 rgw::IAM::s3GetObjectAcl
:
4493 rgw::IAM::s3GetObjectVersionAcl
);
4495 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetBucketAcl
);
4503 void RGWGetACLs::pre_exec()
4505 rgw_bucket_object_pre_exec(s
);
4508 void RGWGetACLs::execute()
4511 RGWAccessControlPolicy
* const acl
= \
4512 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4513 RGWAccessControlPolicy_S3
* const s3policy
= \
4514 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4515 s3policy
->to_xml(ss
);
4521 int RGWPutACLs::verify_permission()
4524 if (!s
->object
.empty()) {
4525 perm
= verify_object_permission(s
,
4526 s
->object
.instance
.empty() ?
4527 rgw::IAM::s3PutObjectAcl
:
4528 rgw::IAM::s3PutObjectVersionAcl
);
4530 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4538 int RGWGetLC::verify_permission()
4541 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4548 int RGWPutLC::verify_permission()
4551 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4558 int RGWDeleteLC::verify_permission()
4561 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4568 void RGWPutACLs::pre_exec()
4570 rgw_bucket_object_pre_exec(s
);
4573 void RGWGetLC::pre_exec()
4575 rgw_bucket_object_pre_exec(s
);
4578 void RGWPutLC::pre_exec()
4580 rgw_bucket_object_pre_exec(s
);
4583 void RGWDeleteLC::pre_exec()
4585 rgw_bucket_object_pre_exec(s
);
4588 void RGWPutACLs::execute()
4592 RGWAccessControlPolicy_S3
*policy
= NULL
;
4593 RGWACLXMLParser_S3
parser(s
->cct
);
4594 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4596 char *new_data
= NULL
;
4599 op_ret
= 0; /* XXX redundant? */
4601 if (!parser
.init()) {
4607 RGWAccessControlPolicy
* const existing_policy
= \
4608 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
4610 owner
= existing_policy
->get_owner();
4612 op_ret
= get_params();
4614 if (op_ret
== -ERANGE
) {
4615 ldout(s
->cct
, 4) << "The size of request xml data is larger than the max limitation, data size = "
4616 << s
->length
<< dendl
;
4617 op_ret
= -ERR_MALFORMED_XML
;
4618 s
->err
.message
= "The XML you provided was larger than the maximum " +
4619 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
4625 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4627 if (!s
->canned_acl
.empty() && len
) {
4632 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4633 op_ret
= get_policy_from_state(store
, s
, ss
);
4637 new_data
= strdup(ss
.str().c_str());
4640 len
= ss
.str().size();
4643 if (!parser
.parse(data
, len
, 1)) {
4647 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4653 const RGWAccessControlList
& req_acl
= policy
->get_acl();
4654 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
4655 #define ACL_GRANTS_MAX_NUM 100
4656 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
4658 max_num
= ACL_GRANTS_MAX_NUM
;
4661 int grants_num
= req_grant_map
.size();
4662 if (grants_num
> max_num
) {
4663 ldout(s
->cct
, 4) << "An acl can have up to "
4665 << " grants, request acl grants num: "
4666 << grants_num
<< dendl
;
4667 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
4668 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
4669 + std::to_string(max_num
)
4670 + " grants allowed in an acl.";
4674 // forward bucket acl requests to meta master zone
4675 if (s
->object
.empty() && !store
->is_meta_master()) {
4677 // include acl data unless it was generated from a canned_acl
4678 if (s
->canned_acl
.empty()) {
4679 in_data
.append(data
, len
);
4681 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4683 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4688 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4689 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4690 policy
->to_xml(*_dout
);
4694 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4698 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4699 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4700 new_policy
.to_xml(*_dout
);
4704 new_policy
.encode(bl
);
4705 map
<string
, bufferlist
> attrs
;
4707 if (!s
->object
.empty()) {
4708 obj
= rgw_obj(s
->bucket
, s
->object
);
4709 store
->set_atomic(s
->obj_ctx
, obj
);
4710 //if instance is empty, we should modify the latest object
4711 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4713 attrs
= s
->bucket_attrs
;
4714 attrs
[RGW_ATTR_ACL
] = bl
;
4715 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4717 if (op_ret
== -ECANCELED
) {
4718 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4722 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4724 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4725 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4726 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4727 oid
= lc_oid_prefix
;
4729 snprintf(buf
, 32, ".%d", index
);
4734 void RGWPutLC::execute()
4738 RGWLifecycleConfiguration_S3
*config
= NULL
;
4739 RGWLCXMLParser_S3
parser(s
->cct
);
4740 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4742 if (!parser
.init()) {
4747 op_ret
= get_params();
4751 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4753 if (!parser
.parse(data
, len
, 1)) {
4754 op_ret
= -ERR_MALFORMED_XML
;
4757 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4759 op_ret
= -ERR_MALFORMED_XML
;
4763 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4764 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4765 config
->to_xml(*_dout
);
4769 op_ret
= config
->rebuild(store
, new_config
);
4773 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4774 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4775 new_config
.to_xml(*_dout
);
4779 new_config
.encode(bl
);
4780 map
<string
, bufferlist
> attrs
;
4781 attrs
= s
->bucket_attrs
;
4782 attrs
[RGW_ATTR_LC
] = bl
;
4783 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4786 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4789 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4790 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4791 rados::cls::lock::Lock
l(lc_index_lock_name
);
4792 utime_t
time(max_lock_secs
, 0);
4793 l
.set_duration(time
);
4794 l
.set_cookie(cookie
);
4795 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4797 op_ret
= l
.lock_exclusive(ctx
, oid
);
4798 if (op_ret
== -EBUSY
) {
4799 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4804 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4807 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4809 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4817 void RGWDeleteLC::execute()
4820 map
<string
, bufferlist
> orig_attrs
, attrs
;
4821 map
<string
, bufferlist
>::iterator iter
;
4823 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4824 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4825 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4829 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4830 const string
& name
= iter
->first
;
4831 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
4832 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
4833 if (attrs
.find(name
) == attrs
.end()) {
4834 attrs
[name
] = iter
->second
;
4838 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4839 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4840 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4843 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4844 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4845 rados::cls::lock::Lock
l(lc_index_lock_name
);
4846 utime_t
time(max_lock_secs
, 0);
4847 l
.set_duration(time
);
4849 op_ret
= l
.lock_exclusive(ctx
, oid
);
4850 if (op_ret
== -EBUSY
) {
4851 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4856 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4859 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
4861 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4869 int RGWGetCORS::verify_permission()
4871 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4878 void RGWGetCORS::execute()
4880 op_ret
= read_bucket_cors();
4885 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4891 int RGWPutCORS::verify_permission()
4893 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4900 void RGWPutCORS::execute()
4904 op_ret
= get_params();
4908 if (!store
->is_meta_master()) {
4909 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
4911 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4916 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
4917 attrs
[RGW_ATTR_CORS
] = cors_bl
;
4918 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4921 int RGWDeleteCORS::verify_permission()
4923 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
4930 void RGWDeleteCORS::execute()
4932 op_ret
= read_bucket_cors();
4939 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
4943 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4944 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4945 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
4946 map
<string
, bufferlist
>::iterator iter
;
4948 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4952 /* only remove meta attrs */
4953 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4954 const string
& name
= iter
->first
;
4955 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
4956 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
4957 rmattrs
[name
] = iter
->second
;
4958 } else if (attrs
.find(name
) == attrs
.end()) {
4959 attrs
[name
] = iter
->second
;
4962 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4965 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
4966 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
4969 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
4970 rule
= cc
->host_name_rule(origin
);
4972 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
4976 if (!validate_cors_rule_method(rule
, req_meth
)) {
4982 void RGWOptionsCORS::execute()
4984 op_ret
= read_bucket_cors();
4988 origin
= s
->info
.env
->get("HTTP_ORIGIN");
4991 "Preflight request without mandatory Origin header"
4996 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
4999 "Preflight request without mandatory Access-control-request-method header"
5005 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5009 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5010 op_ret
= validate_cors_request(&bucket_cors
);
5012 origin
= req_meth
= NULL
;
5018 int RGWGetRequestPayment::verify_permission()
5023 void RGWGetRequestPayment::pre_exec()
5025 rgw_bucket_object_pre_exec(s
);
5028 void RGWGetRequestPayment::execute()
5030 requester_pays
= s
->bucket_info
.requester_pays
;
5033 int RGWSetRequestPayment::verify_permission()
5035 if (false == s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
5042 void RGWSetRequestPayment::pre_exec()
5044 rgw_bucket_object_pre_exec(s
);
5047 void RGWSetRequestPayment::execute()
5049 op_ret
= get_params();
5054 s
->bucket_info
.requester_pays
= requester_pays
;
5055 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5058 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5059 << " returned err=" << op_ret
<< dendl
;
5064 int RGWInitMultipart::verify_permission()
5066 if (s
->iam_policy
) {
5067 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5068 rgw::IAM::s3PutObject
,
5069 rgw_obj(s
->bucket
, s
->object
));
5070 if (e
== Effect::Allow
) {
5072 } else if (e
== Effect::Deny
) {
5077 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5084 void RGWInitMultipart::pre_exec()
5086 rgw_bucket_object_pre_exec(s
);
5089 void RGWInitMultipart::execute()
5092 map
<string
, bufferlist
> attrs
;
5095 if (get_params() < 0)
5098 if (s
->object
.empty())
5101 policy
.encode(aclbl
);
5102 attrs
[RGW_ATTR_ACL
] = aclbl
;
5104 populate_with_generic_attrs(s
, attrs
);
5106 /* select encryption mode */
5107 op_ret
= prepare_encryption(attrs
);
5111 rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5115 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5116 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5117 upload_id
.append(buf
);
5119 string tmp_obj_name
;
5120 RGWMPObj
mp(s
->object
.name
, upload_id
);
5121 tmp_obj_name
= mp
.get_meta();
5123 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5124 // the meta object will be indexed with 0 size, we c
5125 obj
.set_in_extra_data(true);
5126 obj
.index_hash_source
= s
->object
.name
;
5128 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5129 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5131 RGWRados::Object::Write
obj_op(&op_target
);
5133 obj_op
.meta
.owner
= s
->owner
.get_id();
5134 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5135 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5137 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5138 } while (op_ret
== -EEXIST
);
5141 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5143 RGWAccessControlPolicy
*policy
,
5144 map
<string
, bufferlist
>& attrs
)
5146 map
<string
, bufferlist
>::iterator iter
;
5150 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5151 obj
.set_in_extra_data(true);
5153 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5155 if (op_ret
== -ENOENT
) {
5156 return -ERR_NO_SUCH_UPLOAD
;
5162 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5163 string name
= iter
->first
;
5164 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5165 bufferlist
& bl
= iter
->second
;
5166 bufferlist::iterator bli
= bl
.begin();
5168 ::decode(*policy
, bli
);
5169 } catch (buffer::error
& err
) {
5170 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5181 int RGWCompleteMultipart::verify_permission()
5183 if (s
->iam_policy
) {
5184 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5185 rgw::IAM::s3PutObject
,
5186 rgw_obj(s
->bucket
, s
->object
));
5187 if (e
== Effect::Allow
) {
5189 } else if (e
== Effect::Deny
) {
5194 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5201 void RGWCompleteMultipart::pre_exec()
5203 rgw_bucket_object_pre_exec(s
);
5206 void RGWCompleteMultipart::execute()
5208 RGWMultiCompleteUpload
*parts
;
5209 map
<int, string
>::iterator iter
;
5210 RGWMultiXMLParser parser
;
5212 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5213 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5214 map
<string
, bufferlist
> attrs
;
5217 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5218 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5223 RGWObjManifest manifest
;
5224 uint64_t olh_epoch
= 0;
5227 op_ret
= get_params();
5230 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5235 if (!data
|| !len
) {
5236 op_ret
= -ERR_MALFORMED_XML
;
5240 if (!parser
.init()) {
5245 if (!parser
.parse(data
, len
, 1)) {
5246 op_ret
= -ERR_MALFORMED_XML
;
5250 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5251 if (!parts
|| parts
->parts
.empty()) {
5252 op_ret
= -ERR_MALFORMED_XML
;
5256 if ((int)parts
->parts
.size() >
5257 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5262 mp
.init(s
->object
.name
, upload_id
);
5263 meta_oid
= mp
.get_meta();
5265 int total_parts
= 0;
5266 int handled_parts
= 0;
5267 int max_parts
= 1000;
5270 RGWCompressionInfo cs_info
;
5271 bool compressed
= false;
5272 uint64_t accounted_size
= 0;
5274 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5276 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5278 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5280 iter
= parts
->parts
.begin();
5282 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5283 meta_obj
.set_in_extra_data(true);
5284 meta_obj
.index_hash_source
= s
->object
.name
;
5286 /*take a cls lock on meta_obj to prevent racing completions (or retries)
5287 from deleting the parts*/
5289 rgw_raw_obj raw_obj
;
5290 librados::ObjectWriteOperation op
;
5291 librados::IoCtx ioctx
;
5292 rados::cls::lock::Lock
l("RGWCompleteMultipart");
5293 int max_lock_secs_mp
= s
->cct
->_conf
->get_val
<int64_t>("rgw_mp_lock_max_time");
5296 store
->obj_to_raw((s
->bucket_info
).placement_rule
, meta_obj
, &raw_obj
);
5297 store
->get_obj_data_pool((s
->bucket_info
).placement_rule
,meta_obj
,&meta_pool
);
5298 store
->open_pool_ctx(meta_pool
, ioctx
);
5300 const string raw_meta_oid
= raw_obj
.oid
;
5301 utime_t
time(max_lock_secs_mp
, 0);
5302 l
.set_duration(time
);
5303 l
.lock_exclusive(&op
);
5304 op_ret
= ioctx
.operate(raw_meta_oid
, &op
);
5307 dout(0) << "RGWCompleteMultipart::execute() failed to acquire lock " << dendl
;
5308 op_ret
= -ERR_INTERNAL_ERROR
;
5309 s
->err
.message
= "This multipart completion is already in progress";
5313 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5316 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5317 << " ret=" << op_ret
<< dendl
;
5322 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5323 marker
, obj_parts
, &marker
, &truncated
);
5324 if (op_ret
== -ENOENT
) {
5325 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5330 total_parts
+= obj_parts
.size();
5331 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5332 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5333 << " expected: " << parts
->parts
.size() << dendl
;
5334 op_ret
= -ERR_INVALID_PART
;
5338 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5339 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5340 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5341 part_size
< min_part_size
) {
5342 op_ret
= -ERR_TOO_SMALL
;
5346 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5347 if (iter
->first
!= (int)obj_iter
->first
) {
5348 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5349 << iter
->first
<< " next uploaded: "
5350 << obj_iter
->first
<< dendl
;
5351 op_ret
= -ERR_INVALID_PART
;
5354 string part_etag
= rgw_string_unquote(iter
->second
);
5355 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5356 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5357 << " etag: " << iter
->second
<< dendl
;
5358 op_ret
= -ERR_INVALID_PART
;
5362 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5363 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5364 hash
.Update((const byte
*)petag
, sizeof(petag
));
5366 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5368 /* update manifest for part */
5369 string oid
= mp
.get_part(obj_iter
->second
.num
);
5371 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5373 if (obj_part
.manifest
.empty()) {
5374 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5375 << src_obj
<< dendl
;
5376 op_ret
= -ERR_INVALID_PART
;
5379 manifest
.append(obj_part
.manifest
, store
);
5382 if (obj_part
.cs_info
.compression_type
!= "none") {
5383 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5384 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5385 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5386 op_ret
= -ERR_INVALID_PART
;
5389 int64_t new_ofs
; // offset in compression data for new part
5390 if (cs_info
.blocks
.size() > 0)
5391 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5394 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5395 compression_block cb
;
5396 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5397 cb
.new_ofs
= new_ofs
;
5399 cs_info
.blocks
.push_back(cb
);
5400 new_ofs
= cb
.new_ofs
+ cb
.len
;
5403 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5404 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5408 rgw_obj_index_key remove_key
;
5409 src_obj
.key
.get_index_key(&remove_key
);
5411 remove_objs
.push_back(remove_key
);
5413 ofs
+= obj_part
.size
;
5414 accounted_size
+= obj_part
.accounted_size
;
5416 } while (truncated
);
5417 hash
.Final((byte
*)final_etag
);
5419 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5420 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5421 "-%lld", (long long)parts
->parts
.size());
5422 etag
= final_etag_str
;
5423 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5425 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5427 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5430 // write compression attribute to full object
5432 ::encode(cs_info
, tmp
);
5433 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5436 target_obj
.init(s
->bucket
, s
->object
.name
);
5437 if (versioned_object
) {
5438 store
->gen_rand_obj_instance_name(&target_obj
);
5441 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5443 obj_ctx
.obj
.set_atomic(target_obj
);
5445 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5446 RGWRados::Object::Write
obj_op(&op_target
);
5448 obj_op
.meta
.manifest
= &manifest
;
5449 obj_op
.meta
.remove_objs
= &remove_objs
;
5451 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5452 obj_op
.meta
.owner
= s
->owner
.get_id();
5453 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5454 obj_op
.meta
.modify_tail
= true;
5455 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5459 // remove the upload obj
5460 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5461 s
->bucket_info
, meta_obj
, 0);
5463 ldout(store
->ctx(), 0) << "WARNING: failed to remove object " << meta_obj
<< dendl
;
5464 r
= l
.unlock(&ioctx
, raw_meta_oid
);
5466 ldout(store
->ctx(), 0) << "WARNING: failed to unlock " << raw_meta_oid
<< dendl
;
5471 int RGWAbortMultipart::verify_permission()
5473 if (s
->iam_policy
) {
5474 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5475 rgw::IAM::s3AbortMultipartUpload
,
5476 rgw_obj(s
->bucket
, s
->object
));
5477 if (e
== Effect::Allow
) {
5479 } else if (e
== Effect::Deny
) {
5484 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5491 void RGWAbortMultipart::pre_exec()
5493 rgw_bucket_object_pre_exec(s
);
5496 void RGWAbortMultipart::execute()
5501 upload_id
= s
->info
.args
.get("uploadId");
5502 map
<string
, bufferlist
> attrs
;
5506 if (upload_id
.empty() || s
->object
.empty())
5509 mp
.init(s
->object
.name
, upload_id
);
5510 meta_oid
= mp
.get_meta();
5512 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5516 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5517 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5520 int RGWListMultipart::verify_permission()
5522 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5528 void RGWListMultipart::pre_exec()
5530 rgw_bucket_object_pre_exec(s
);
5533 void RGWListMultipart::execute()
5535 map
<string
, bufferlist
> xattrs
;
5539 op_ret
= get_params();
5543 mp
.init(s
->object
.name
, upload_id
);
5544 meta_oid
= mp
.get_meta();
5546 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5550 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5551 marker
, parts
, NULL
, &truncated
);
5554 int RGWListBucketMultiparts::verify_permission()
5556 if (!verify_bucket_permission(s
,
5557 rgw::IAM::s3ListBucketMultiPartUploads
))
5563 void RGWListBucketMultiparts::pre_exec()
5565 rgw_bucket_object_pre_exec(s
);
5568 void RGWListBucketMultiparts::execute()
5570 vector
<rgw_bucket_dir_entry
> objs
;
5573 op_ret
= get_params();
5577 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5579 path_args
= s
->info
.args
.get("path");
5580 if (!path_args
.empty()) {
5581 if (!delimiter
.empty() || !prefix
.empty()) {
5589 marker_meta
= marker
.get_meta();
5591 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5592 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5597 if (!objs
.empty()) {
5598 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5599 RGWMultipartUploadEntry entry
;
5600 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5601 rgw_obj_key
key(iter
->key
);
5602 if (!entry
.mp
.from_meta(key
.name
))
5605 uploads
.push_back(entry
);
5607 next_marker
= entry
;
5611 void RGWGetHealthCheck::execute()
5613 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5614 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5615 /* Disabling path specified & existent in the filesystem. */
5616 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5618 op_ret
= 0; /* 200 OK */
5622 int RGWDeleteMultiObj::verify_permission()
5624 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5625 if (!acl_allowed
&& !s
->iam_policy
)
5631 void RGWDeleteMultiObj::pre_exec()
5633 rgw_bucket_object_pre_exec(s
);
5636 void RGWDeleteMultiObj::execute()
5638 RGWMultiDelDelete
*multi_delete
;
5639 vector
<rgw_obj_key
>::iterator iter
;
5640 RGWMultiDelXMLParser parser
;
5641 int num_processed
= 0;
5642 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5644 op_ret
= get_params();
5654 if (!parser
.init()) {
5659 if (!parser
.parse(data
, len
, 1)) {
5664 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5665 if (!multi_delete
) {
5670 if (multi_delete
->is_quiet())
5674 if (multi_delete
->objects
.empty()) {
5678 for (iter
= multi_delete
->objects
.begin();
5679 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5680 ++iter
, num_processed
++) {
5681 rgw_obj
obj(bucket
, *iter
);
5682 if (s
->iam_policy
) {
5683 auto e
= s
->iam_policy
->eval(s
->env
,
5685 iter
->instance
.empty() ?
5686 rgw::IAM::s3DeleteObject
:
5687 rgw::IAM::s3DeleteObjectVersion
,
5689 if ((e
== Effect::Deny
) ||
5690 (e
== Effect::Pass
&& !acl_allowed
)) {
5691 send_partial_response(*iter
, false, "", -EACCES
);
5696 obj_ctx
->obj
.set_atomic(obj
);
5698 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5699 RGWRados::Object::Delete
del_op(&del_target
);
5701 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5702 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5703 del_op
.params
.obj_owner
= s
->owner
;
5705 op_ret
= del_op
.delete_obj();
5706 if (op_ret
== -ENOENT
) {
5710 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5711 del_op
.result
.version_id
, op_ret
);
5714 /* set the return code to zero, errors at this point will be
5715 dumped to the response */
5719 // will likely segfault if begin_response() has not been called
5731 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5732 map
<string
, bufferlist
>& battrs
,
5733 ACLOwner
& bucket_owner
/* out */)
5735 RGWAccessControlPolicy
bacl(store
->ctx());
5736 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5741 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5743 bucket_owner
= bacl
.get_owner();
5745 /* We can use global user_acl because each BulkDelete request is allowed
5746 * to work on entities from a single account only. */
5747 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5748 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5751 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5753 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5755 RGWBucketInfo binfo
;
5756 map
<string
, bufferlist
> battrs
;
5759 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5760 path
.bucket_name
, binfo
, nullptr,
5766 if (!verify_permission(binfo
, battrs
, bowner
)) {
5771 if (!path
.obj_key
.empty()) {
5772 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5773 obj_ctx
.obj
.set_atomic(obj
);
5775 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5776 RGWRados::Object::Delete
del_op(&del_target
);
5778 del_op
.params
.bucket_owner
= binfo
.owner
;
5779 del_op
.params
.versioning_status
= binfo
.versioning_status();
5780 del_op
.params
.obj_owner
= bowner
;
5782 ret
= del_op
.delete_obj();
5787 RGWObjVersionTracker ot
;
5788 ot
.read_version
= binfo
.ep_objv
;
5790 ret
= store
->delete_bucket(binfo
, ot
);
5792 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5793 binfo
.bucket
.name
, false);
5795 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
5803 if (!store
->is_meta_master()) {
5805 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
5808 if (ret
== -ENOENT
) {
5809 /* adjust error, we want to return with NoSuchBucket and not
5811 ret
= -ERR_NO_SUCH_BUCKET
;
5823 if (-ENOENT
== ret
) {
5824 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
5827 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
5830 fail_desc_t failed_item
= {
5834 failures
.push_back(failed_item
);
5839 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
5841 fail_desc_t failed_item
= {
5845 failures
.push_back(failed_item
);
5850 if (-ENOENT
== ret
) {
5851 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
5854 fail_desc_t failed_item
= {
5858 failures
.push_back(failed_item
);
5863 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
5865 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
5866 for (auto path
: paths
) {
5867 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
5868 delete_single(path
);
5874 int RGWBulkDelete::verify_permission()
5879 void RGWBulkDelete::pre_exec()
5881 rgw_bucket_object_pre_exec(s
);
5884 void RGWBulkDelete::execute()
5886 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
5888 bool is_truncated
= false;
5890 list
<RGWBulkDelete::acct_path_t
> items
;
5892 int ret
= get_data(items
, &is_truncated
);
5897 ret
= deleter
->delete_chunk(items
);
5898 } while (!op_ret
&& is_truncated
);
5904 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
5906 int RGWBulkUploadOp::verify_permission()
5908 if (s
->auth
.identity
->is_anonymous()) {
5912 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
5916 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
5917 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
5918 << " (user_id.tenant=" << s
->user
->user_id
.tenant
5919 << " requested=" << s
->bucket_tenant
<< ")"
5924 if (s
->user
->max_buckets
< 0) {
5931 void RGWBulkUploadOp::pre_exec()
5933 rgw_bucket_object_pre_exec(s
);
5936 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
5937 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
5939 /* We need to skip all slashes at the beginning in order to preserve
5940 * compliance with Swift. */
5941 const size_t start_pos
= path
.find_first_not_of('/');
5943 if (boost::string_ref::npos
!= start_pos
) {
5944 /* Seperator is the first slash after the leading ones. */
5945 const size_t sep_pos
= path
.substr(start_pos
).find('/');
5947 if (boost::string_ref::npos
!= sep_pos
) {
5948 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
5949 const auto obj_name
= path
.substr(sep_pos
+ 1);
5951 return std::make_pair(bucket_name
.to_string(),
5952 rgw_obj_key(obj_name
.to_string()));
5954 /* It's guaranteed here that bucket name is at least one character
5955 * long and is different than slash. */
5956 return std::make_pair(path
.substr(start_pos
).to_string(),
5964 std::pair
<std::string
, std::string
>
5965 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
5967 std::string bucket_path
, file_prefix
;
5968 if (! s
->init_state
.url_bucket
.empty()) {
5969 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
5970 if (! s
->object
.empty()) {
5971 std::string
& object_name
= s
->object
.name
;
5973 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
5974 * we can safely examine its last element. */
5975 if (object_name
.back() == '/') {
5976 file_prefix
.append(object_name
);
5978 file_prefix
.append(object_name
).append("/");
5982 return std::make_pair(bucket_path
, file_prefix
);
5985 int RGWBulkUploadOp::handle_dir_verify_permission()
5987 if (s
->user
->max_buckets
> 0) {
5988 RGWUserBuckets buckets
;
5990 bool is_truncated
= false;
5991 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
5992 marker
, std::string(), s
->user
->max_buckets
,
5993 false, &is_truncated
);
5998 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
5999 return -ERR_TOO_MANY_BUCKETS
;
6006 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
6008 /* the request of container or object level will contain bucket name.
6009 * only at account level need to append the bucket name */
6010 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
6014 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
6015 info
.script_uri
.append("/").append(bucket_name
);
6016 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
6017 info
.effective_uri
= "/" + bucket_name
;
6020 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
6022 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
6024 op_ret
= handle_dir_verify_permission();
6029 std::string bucket_name
;
6030 rgw_obj_key object_junk
;
6031 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
6033 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
6034 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
6036 /* we need to make sure we read bucket info, it's not read before for this
6037 * specific request */
6038 RGWBucketInfo binfo
;
6039 std::map
<std::string
, ceph::bufferlist
> battrs
;
6040 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6041 binfo
, NULL
, &battrs
);
6042 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6045 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6047 if (bucket_exists
) {
6048 RGWAccessControlPolicy
old_policy(s
->cct
);
6049 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6050 battrs
, &old_policy
);
6052 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6059 RGWBucketInfo master_info
;
6060 rgw_bucket
*pmaster_bucket
= nullptr;
6061 uint32_t *pmaster_num_shards
= nullptr;
6062 real_time creation_time
;
6063 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6065 if (! store
->is_meta_master()) {
6067 ceph::bufferlist in_data
;
6068 req_info info
= s
->info
;
6069 forward_req_info(s
->cct
, info
, bucket_name
);
6070 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6075 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6076 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6077 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6079 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
6080 << objv
.ver
<< dendl
;
6081 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
6084 pmaster_bucket
= &master_info
.bucket
;
6085 creation_time
= master_info
.creation_time
;
6086 pmaster_num_shards
= &master_info
.num_shards
;
6089 pmaster_bucket
= nullptr;
6090 pmaster_num_shards
= nullptr;
6094 std::string placement_rule
;
6095 if (bucket_exists
) {
6096 std::string selected_placement_rule
;
6098 bucket
.tenant
= s
->bucket_tenant
;
6099 bucket
.name
= s
->bucket_name
;
6100 op_ret
= store
->select_bucket_placement(*(s
->user
),
6101 store
->get_zonegroup().get_id(),
6103 &selected_placement_rule
,
6105 if (selected_placement_rule
!= binfo
.placement_rule
) {
6107 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6112 /* Create metadata: ACLs. */
6113 std::map
<std::string
, ceph::bufferlist
> attrs
;
6114 RGWAccessControlPolicy policy
;
6115 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6116 ceph::bufferlist aclbl
;
6117 policy
.encode(aclbl
);
6118 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6120 RGWQuotaInfo quota_info
;
6121 const RGWQuotaInfo
* pquota_info
= nullptr;
6124 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6125 bucket
.name
= bucket_name
;
6128 RGWBucketInfo out_info
;
6129 op_ret
= store
->create_bucket(*(s
->user
),
6131 store
->get_zonegroup().get_id(),
6132 placement_rule
, binfo
.swift_ver_location
,
6134 out_info
, pobjv
, &ep_objv
, creation_time
,
6135 pmaster_bucket
, pmaster_num_shards
, true);
6136 /* continue if EEXIST and create_bucket will fail below. this way we can
6137 * recover from a partial create by retrying it. */
6138 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6139 << ", bucket=" << bucket
<< dendl
;
6141 if (op_ret
&& op_ret
!= -EEXIST
) {
6145 const bool existed
= (op_ret
== -EEXIST
);
6147 /* bucket already existed, might have raced with another bucket creation, or
6148 * might be partial bucket creation that never completed. Read existing bucket
6149 * info, verify that the reported bucket owner is the current user.
6150 * If all is ok then update the user's list of buckets.
6151 * Otherwise inform client about a name conflict.
6153 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6155 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6158 bucket
= out_info
.bucket
;
6161 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6162 out_info
.creation_time
, false);
6163 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6164 /* if it exists (or previously existed), don't remove it! */
6165 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6166 bucket
.tenant
, bucket
.name
);
6168 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6171 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6172 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6174 op_ret
= -ERR_BUCKET_EXISTS
;
6181 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6183 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6184 ACLOwner
& bucket_owner
/* out */)
6186 RGWAccessControlPolicy
bacl(store
->ctx());
6187 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6189 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6194 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6196 bucket_owner
= bacl
.get_owner();
6198 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6199 rgw::IAM::s3PutObject
, obj
);
6200 if (e
== Effect::Allow
) {
6202 } else if (e
== Effect::Deny
) {
6207 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6208 &bacl
, RGW_PERM_WRITE
);
6211 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6213 AlignedStreamGetter
& body
)
6216 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6219 RGWPutObjDataProcessor
*filter
= nullptr;
6220 boost::optional
<RGWPutObj_Compress
> compressor
;
6222 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6223 op_ret
= -ERR_TOO_LARGE
;
6227 std::string bucket_name
;
6229 std::tie(bucket_name
, object
) = *parse_path(path
);
6231 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6232 RGWBucketInfo binfo
;
6233 std::map
<std::string
, ceph::bufferlist
> battrs
;
6235 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6236 bucket_name
, binfo
, nullptr, &battrs
);
6237 if (op_ret
== -ENOENT
) {
6238 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6240 } else if (op_ret
< 0) {
6244 if (! handle_file_verify_permission(binfo
,
6245 rgw_obj(binfo
.bucket
, object
),
6247 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6252 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6253 user_quota
, bucket_quota
, size
);
6258 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6263 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6268 s
->cct
->_conf
->rgw_obj_stripe_size
,
6270 binfo
.versioning_enabled());
6272 /* No filters by default. */
6273 filter
= &processor
;
6275 op_ret
= processor
.prepare(store
, nullptr);
6277 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6282 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6283 binfo
.placement_rule
);
6284 CompressorRef plugin
;
6285 if (compression_type
!= "none") {
6286 plugin
= Compressor::create(s
->cct
, compression_type
);
6288 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6289 << compression_type
<< dendl
;
6291 compressor
.emplace(s
->cct
, plugin
, filter
);
6292 filter
= &*compressor
;
6296 /* Upload file content. */
6301 ceph::bufferlist data
;
6302 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6304 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6308 } else if (len
> 0) {
6309 hash
.Update((const byte
*)data
.c_str(), data
.length());
6310 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6312 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6323 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6328 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6329 user_quota
, bucket_quota
, size
);
6331 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6336 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6341 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6342 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6344 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6346 /* Create metadata: ETAG. */
6347 std::map
<std::string
, ceph::bufferlist
> attrs
;
6348 std::string etag
= calc_md5
;
6349 ceph::bufferlist etag_bl
;
6350 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6351 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6353 /* Create metadata: ACLs. */
6354 RGWAccessControlPolicy policy
;
6355 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6356 ceph::bufferlist aclbl
;
6357 policy
.encode(aclbl
);
6358 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6360 /* Create metadata: compression info. */
6361 if (compressor
&& compressor
->is_compressed()) {
6362 ceph::bufferlist tmp
;
6363 RGWCompressionInfo cs_info
;
6364 cs_info
.compression_type
= plugin
->get_type_name();
6365 cs_info
.orig_size
= s
->obj_size
;
6366 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6367 ::encode(cs_info
, tmp
);
6368 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6371 /* Complete the transaction. */
6372 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6373 ceph::real_time() /* delete_at */);
6375 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6382 void RGWBulkUploadOp::execute()
6384 ceph::bufferlist
buffer(64 * 1024);
6386 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6388 /* Create an instance of stream-abstracting class. Having this indirection
6389 * allows for easy introduction of decompressors like gzip and bzip2. */
6390 auto stream
= create_stream();
6395 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6396 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6397 std::string bucket_path
, file_prefix
;
6398 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6400 auto status
= rgw::tar::StatusIndicator::create();
6402 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6404 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6408 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6409 * must be tracked to detect out end-of-archive. It occurs when both of
6410 * them are empty (zeroed). Tracing this particular inter-block dependency
6411 * is responsibility of the rgw::tar::StatusIndicator class. */
6412 boost::optional
<rgw::tar::HeaderView
> header
;
6413 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6415 if (! status
.empty() && header
) {
6416 /* This specific block isn't empty (entirely zeroed), so we can parse
6417 * it as a TAR header and dispatch. At the moment we do support only
6418 * regular files and directories. Everything else (symlinks, devices)
6419 * will be ignored but won't cease the whole upload. */
6420 switch (header
->get_filetype()) {
6421 case rgw::tar::FileType::NORMAL_FILE
: {
6422 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6424 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6425 file_prefix
+ header
->get_filename().to_string();
6426 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6427 rgw::tar::BLOCK_SIZE
, *stream
);
6428 op_ret
= handle_file(filename
,
6429 header
->get_filesize(),
6432 /* Only regular files counts. */
6435 failures
.emplace_back(op_ret
, filename
.to_string());
6439 case rgw::tar::FileType::DIRECTORY
: {
6440 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6442 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6443 op_ret
= handle_dir(dirname
);
6444 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6445 failures
.emplace_back(op_ret
, dirname
.to_string());
6450 /* Not recognized. Skip. */
6456 /* In case of any problems with sub-request authorization Swift simply
6457 * terminates whole upload immediately. */
6458 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6460 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6465 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6470 } while (! status
.eof());
6475 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6477 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6478 ceph::bufferlist junk
;
6480 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6483 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6484 ceph::bufferlist
& dst
)
6486 const size_t max_to_read
= std::min(want
, length
- position
);
6487 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6494 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6495 ceph::bufferlist
& dst
)
6497 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6504 int RGWSetAttrs::verify_permission()
6506 // This looks to be part of the RGW-NFS machinery and has no S3 or
6507 // Swift equivalent.
6509 if (!s
->object
.empty()) {
6510 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6512 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6520 void RGWSetAttrs::pre_exec()
6522 rgw_bucket_object_pre_exec(s
);
6525 void RGWSetAttrs::execute()
6527 op_ret
= get_params();
6531 rgw_obj
obj(s
->bucket
, s
->object
);
6533 if (!s
->object
.empty()) {
6534 store
->set_atomic(s
->obj_ctx
, obj
);
6535 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6537 for (auto& iter
: attrs
) {
6538 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6540 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6541 &s
->bucket_info
.objv_tracker
);
6545 void RGWGetObjLayout::pre_exec()
6547 rgw_bucket_object_pre_exec(s
);
6550 void RGWGetObjLayout::execute()
6552 rgw_obj
obj(s
->bucket
, s
->object
);
6553 RGWRados::Object
target(store
,
6555 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6556 rgw_obj(s
->bucket
, s
->object
));
6557 RGWRados::Object::Read
stat_op(&target
);
6559 op_ret
= stat_op
.prepare();
6564 head_obj
= stat_op
.state
.head_obj
;
6566 op_ret
= target
.get_manifest(&manifest
);
6570 int RGWConfigBucketMetaSearch::verify_permission()
6572 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6579 void RGWConfigBucketMetaSearch::pre_exec()
6581 rgw_bucket_object_pre_exec(s
);
6584 void RGWConfigBucketMetaSearch::execute()
6586 op_ret
= get_params();
6588 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6592 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6594 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6596 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6601 int RGWGetBucketMetaSearch::verify_permission()
6603 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6610 void RGWGetBucketMetaSearch::pre_exec()
6612 rgw_bucket_object_pre_exec(s
);
6615 int RGWDelBucketMetaSearch::verify_permission()
6617 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6624 void RGWDelBucketMetaSearch::pre_exec()
6626 rgw_bucket_object_pre_exec(s
);
6629 void RGWDelBucketMetaSearch::execute()
6631 s
->bucket_info
.mdsearch_config
.clear();
6633 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6635 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6641 RGWHandler::~RGWHandler()
6645 int RGWHandler::init(RGWRados
*_store
,
6646 struct req_state
*_s
,
6647 rgw::io::BasicClient
*cio
)
6655 int RGWHandler::do_init_permissions()
6657 int ret
= rgw_build_bucket_policies(store
, s
);
6658 s
->env
= rgw_build_iam_environment(store
, s
);
6661 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6662 if (ret
== -ENODATA
)
6669 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6672 /* already read bucket info */
6675 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6678 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6679 << s
->object
<< " only_bucket=" << only_bucket
6680 << " ret=" << ret
<< dendl
;
6681 if (ret
== -ENODATA
)
6688 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6689 return dialect_handler
->error_handler(err_no
, error_content
);
6692 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6693 // This is the do-nothing error handler
6698 void RGWPutBucketPolicy::send_response()
6701 set_req_state_err(s
, op_ret
);
6707 int RGWPutBucketPolicy::verify_permission()
6709 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6716 int RGWPutBucketPolicy::get_params()
6718 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6719 // At some point when I have more time I want to make a version of
6720 // rgw_rest_read_all_input that doesn't use malloc.
6721 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6722 // And throws exceptions.
6726 void RGWPutBucketPolicy::execute()
6728 op_ret
= get_params();
6733 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6735 if (!store
->is_meta_master()) {
6736 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6738 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6744 Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6745 auto attrs
= s
->bucket_attrs
;
6746 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6747 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6748 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6749 &s
->bucket_info
.objv_tracker
);
6750 if (op_ret
== -ECANCELED
) {
6751 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */
6753 } catch (rgw::IAM::PolicyParseException
& e
) {
6754 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6759 void RGWGetBucketPolicy::send_response()
6762 set_req_state_err(s
, op_ret
);
6765 end_header(s
, this, "application/json");
6766 dump_body(s
, policy
);
6769 int RGWGetBucketPolicy::verify_permission()
6771 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6778 void RGWGetBucketPolicy::execute()
6780 auto attrs
= s
->bucket_attrs
;
6781 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6782 if (aiter
== attrs
.end()) {
6783 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6784 << " bucket_name = " << s
->bucket_name
<< dendl
;
6785 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6786 s
->err
.message
= "The bucket policy does not exist";
6789 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6791 if (policy
.length() == 0) {
6792 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6793 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6794 s
->err
.message
= "The bucket policy does not exist";
6800 void RGWDeleteBucketPolicy::send_response()
6803 set_req_state_err(s
, op_ret
);
6809 int RGWDeleteBucketPolicy::verify_permission()
6811 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
6818 void RGWDeleteBucketPolicy::execute()
6820 auto attrs
= s
->bucket_attrs
;
6821 attrs
.erase(RGW_ATTR_IAM_POLICY
);
6822 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6823 &s
->bucket_info
.objv_tracker
);
6824 if (op_ret
== -ECANCELED
) {
6825 op_ret
= 0; /* lost a race, but it's ok because policies are immutable */