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 int RGWGetObj::parse_range(void)
86 ignore_invalid_range
= s
->cct
->_conf
->rgw_ignore_get_invalid_range
;
87 partial_content
= false;
89 size_t pos
= rs
.find("bytes=");
90 if (pos
== string::npos
) {
92 while (isspace(rs
[pos
]))
95 while (isalpha(rs
[end
]))
97 if (strncasecmp(rs
.c_str(), "bytes", end
- pos
) != 0)
99 while (isspace(rs
[end
]))
103 rs
= rs
.substr(end
+ 1);
105 rs
= rs
.substr(pos
+ 6); /* size of("bytes=") */
108 if (pos
== string::npos
)
111 partial_content
= true;
113 ofs_str
= rs
.substr(0, pos
);
114 end_str
= rs
.substr(pos
+ 1);
115 if (end_str
.length()) {
116 end
= atoll(end_str
.c_str());
121 if (ofs_str
.length()) {
122 ofs
= atoll(ofs_str
.c_str());
123 } else { // RFC2616 suffix-byte-range-spec
128 if (end
>= 0 && end
< ofs
)
135 if (ignore_invalid_range
) {
136 partial_content
= false;
139 range_parsed
= false; // allow retry
146 static int decode_policy(CephContext
*cct
,
148 RGWAccessControlPolicy
*policy
)
150 bufferlist::iterator iter
= bl
.begin();
152 policy
->decode(iter
);
153 } catch (buffer::error
& err
) {
154 ldout(cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
157 if (cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
158 RGWAccessControlPolicy_S3
*s3policy
= static_cast<RGWAccessControlPolicy_S3
*>(policy
);
159 ldout(cct
, 15) << __func__
<< " Read AccessControlPolicy";
160 s3policy
->to_xml(*_dout
);
167 static int get_user_policy_from_attr(CephContext
* const cct
,
168 RGWRados
* const store
,
169 map
<string
, bufferlist
>& attrs
,
170 RGWAccessControlPolicy
& policy
/* out */)
172 auto aiter
= attrs
.find(RGW_ATTR_ACL
);
173 if (aiter
!= attrs
.end()) {
174 int ret
= decode_policy(cct
, aiter
->second
, &policy
);
185 static int get_bucket_instance_policy_from_attr(CephContext
*cct
,
187 RGWBucketInfo
& bucket_info
,
188 map
<string
, bufferlist
>& bucket_attrs
,
189 RGWAccessControlPolicy
*policy
,
192 map
<string
, bufferlist
>::iterator aiter
= bucket_attrs
.find(RGW_ATTR_ACL
);
194 if (aiter
!= bucket_attrs
.end()) {
195 int ret
= decode_policy(cct
, aiter
->second
, policy
);
199 ldout(cct
, 0) << "WARNING: couldn't find acl header for bucket, generating default" << dendl
;
201 /* object exists, but policy is broken */
202 int r
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
206 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
211 static int get_obj_policy_from_attr(CephContext
*cct
,
213 RGWObjectCtx
& obj_ctx
,
214 RGWBucketInfo
& bucket_info
,
215 map
<string
, bufferlist
>& bucket_attrs
,
216 RGWAccessControlPolicy
*policy
,
222 RGWRados::Object
op_target(store
, bucket_info
, obj_ctx
, obj
);
223 RGWRados::Object::Read
rop(&op_target
);
225 ret
= rop
.get_attr(RGW_ATTR_ACL
, bl
);
227 ret
= decode_policy(cct
, bl
, policy
);
230 } else if (ret
== -ENODATA
) {
231 /* object exists, but policy is broken */
232 ldout(cct
, 0) << "WARNING: couldn't find acl header for object, generating default" << dendl
;
234 ret
= rgw_get_user_info_by_uid(store
, bucket_info
.owner
, uinfo
);
238 policy
->create_default(bucket_info
.owner
, uinfo
.display_name
);
245 * Get the AccessControlPolicy for an object off of disk.
246 * policy: must point to a valid RGWACL, and will be filled upon return.
247 * bucket: name of the bucket containing the object.
248 * object: name of the object to get the ACL for.
249 * Returns: 0 on success, -ERR# otherwise.
251 static int get_bucket_policy_from_attr(CephContext
*cct
,
253 RGWBucketInfo
& bucket_info
,
254 map
<string
, bufferlist
>& bucket_attrs
,
255 RGWAccessControlPolicy
*policy
)
257 rgw_raw_obj instance_obj
;
258 store
->get_bucket_instance_obj(bucket_info
.bucket
, instance_obj
);
259 return get_bucket_instance_policy_from_attr(cct
, store
, bucket_info
, bucket_attrs
,
260 policy
, instance_obj
);
263 static optional
<Policy
> get_iam_policy_from_attr(CephContext
* cct
,
265 map
<string
, bufferlist
>& attrs
,
266 const string
& tenant
) {
267 auto i
= attrs
.find(RGW_ATTR_IAM_POLICY
);
268 if (i
!= attrs
.end()) {
269 return Policy(cct
, tenant
, i
->second
);
275 static int get_obj_attrs(RGWRados
*store
, struct req_state
*s
, rgw_obj
& obj
, 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 return read_op
.prepare();
285 static int modify_obj_attr(RGWRados
*store
, struct req_state
*s
, rgw_obj
& obj
, const char* attr_name
, bufferlist
& attr_val
)
287 map
<string
, bufferlist
> attrs
;
288 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
289 RGWRados::Object::Read
read_op(&op_target
);
291 read_op
.params
.attrs
= &attrs
;
293 int r
= read_op
.prepare();
297 store
->set_atomic(s
->obj_ctx
, read_op
.state
.obj
);
298 attrs
[attr_name
] = attr_val
;
299 return store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, read_op
.state
.obj
, attrs
, NULL
);
302 static int get_system_obj_attrs(RGWRados
*store
, struct req_state
*s
, rgw_raw_obj
& obj
, map
<string
, bufferlist
>& attrs
,
303 uint64_t *obj_size
, RGWObjVersionTracker
*objv_tracker
)
305 RGWRados::SystemObject
src(store
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
306 RGWRados::SystemObject::Read
rop(&src
);
308 rop
.stat_params
.attrs
= &attrs
;
309 rop
.stat_params
.obj_size
= obj_size
;
311 int ret
= rop
.stat(objv_tracker
);
315 static int read_bucket_policy(RGWRados
*store
,
317 RGWBucketInfo
& bucket_info
,
318 map
<string
, bufferlist
>& bucket_attrs
,
319 RGWAccessControlPolicy
*policy
,
322 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
323 ldout(s
->cct
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
<< " is suspended" << dendl
;
324 return -ERR_USER_SUSPENDED
;
327 if (bucket
.name
.empty()) {
331 int ret
= get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, policy
);
332 if (ret
== -ENOENT
) {
333 ret
= -ERR_NO_SUCH_BUCKET
;
339 static int read_obj_policy(RGWRados
*store
,
341 RGWBucketInfo
& bucket_info
,
342 map
<string
, bufferlist
>& bucket_attrs
,
343 RGWAccessControlPolicy
* acl
,
344 optional
<Policy
>& policy
,
349 upload_id
= s
->info
.args
.get("uploadId");
352 if (!s
->system_request
&& bucket_info
.flags
& BUCKET_SUSPENDED
) {
353 ldout(s
->cct
, 0) << "NOTICE: bucket " << bucket_info
.bucket
.name
<< " is suspended" << dendl
;
354 return -ERR_USER_SUSPENDED
;
357 if (!upload_id
.empty()) {
358 /* multipart upload */
359 RGWMPObj
mp(object
.name
, upload_id
);
360 string oid
= mp
.get_meta();
361 obj
.init_ns(bucket
, oid
, mp_ns
);
362 obj
.set_in_extra_data(true);
364 obj
= rgw_obj(bucket
, object
);
366 policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
, bucket
.tenant
);
368 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
369 int ret
= get_obj_policy_from_attr(s
->cct
, store
, *obj_ctx
,
370 bucket_info
, bucket_attrs
, acl
, obj
);
371 if (ret
== -ENOENT
) {
372 /* object does not exist checking the bucket's ACL to make sure
373 that we send a proper error code */
374 RGWAccessControlPolicy
bucket_policy(s
->cct
);
375 ret
= get_bucket_policy_from_attr(s
->cct
, store
, bucket_info
, bucket_attrs
, &bucket_policy
);
380 const rgw_user
& bucket_owner
= bucket_policy
.get_owner().get_id();
381 if (bucket_owner
.compare(s
->user
->user_id
) != 0 &&
382 ! s
->auth
.identity
->is_admin_of(bucket_owner
) &&
383 ! bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
395 * Get the AccessControlPolicy for an user, bucket or object off of disk.
396 * s: The req_state to draw information from.
397 * only_bucket: If true, reads the user and bucket ACLs rather than the object ACL.
398 * Returns: 0 on success, -ERR# otherwise.
400 int rgw_build_bucket_policies(RGWRados
* store
, struct req_state
* s
)
404 RGWUserInfo bucket_owner_info
;
405 RGWObjectCtx
obj_ctx(store
);
407 string bi
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"bucket-instance");
409 ret
= rgw_bucket_parse_bucket_instance(bi
, &s
->bucket_instance_id
, &s
->bucket_instance_shard_id
);
415 if(s
->dialect
.compare("s3") == 0) {
416 s
->bucket_acl
= ceph::make_unique
<RGWAccessControlPolicy_S3
>(s
->cct
);
417 } else if(s
->dialect
.compare("swift") == 0) {
418 /* We aren't allocating the account policy for those operations using
419 * the Swift's infrastructure that don't really need req_state::user.
420 * Typical example here is the implementation of /info. */
421 if (!s
->user
->user_id
.empty()) {
422 s
->user_acl
= ceph::make_unique
<RGWAccessControlPolicy_SWIFTAcct
>(s
->cct
);
424 s
->bucket_acl
= ceph::make_unique
<RGWAccessControlPolicy_SWIFT
>(s
->cct
);
426 s
->bucket_acl
= ceph::make_unique
<RGWAccessControlPolicy
>(s
->cct
);
429 /* check if copy source is within the current domain */
430 if (!s
->src_bucket_name
.empty()) {
431 RGWBucketInfo source_info
;
433 if (s
->bucket_instance_id
.empty()) {
434 ret
= store
->get_bucket_info(obj_ctx
, s
->src_tenant_name
, s
->src_bucket_name
, source_info
, NULL
);
436 ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, source_info
, NULL
, NULL
);
439 string
& zonegroup
= source_info
.zonegroup
;
440 s
->local_source
= store
->get_zonegroup().equals(zonegroup
);
446 std::string display_name
;
449 s
->user
->display_name
,
452 if (!s
->bucket_name
.empty()) {
453 s
->bucket_exists
= true;
454 if (s
->bucket_instance_id
.empty()) {
455 ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
, s
->bucket_info
, NULL
, &s
->bucket_attrs
);
457 ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, s
->bucket_info
, NULL
, &s
->bucket_attrs
);
460 if (ret
!= -ENOENT
) {
462 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_log
);
463 ldout(s
->cct
, 0) << "NOTICE: couldn't get bucket from bucket_name (name=" << bucket_log
<< ")" << dendl
;
466 s
->bucket_exists
= false;
468 s
->bucket
= s
->bucket_info
.bucket
;
470 if (s
->bucket_exists
) {
471 ret
= read_bucket_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
,
472 s
->bucket_acl
.get(), s
->bucket
);
474 s
->bucket_info
.owner
,
475 s
->bucket_acl
->get_owner().get_display_name(),
478 s
->bucket_acl
->create_default(s
->user
->user_id
, s
->user
->display_name
);
479 ret
= -ERR_NO_SUCH_BUCKET
;
482 s
->bucket_owner
= s
->bucket_acl
->get_owner();
484 RGWZoneGroup zonegroup
;
485 int r
= store
->get_zonegroup(s
->bucket_info
.zonegroup
, zonegroup
);
487 if (!zonegroup
.endpoints
.empty()) {
488 s
->zonegroup_endpoint
= zonegroup
.endpoints
.front();
490 // use zonegroup's master zone endpoints
491 auto z
= zonegroup
.zones
.find(zonegroup
.master_zone
);
492 if (z
!= zonegroup
.zones
.end() && !z
->second
.endpoints
.empty()) {
493 s
->zonegroup_endpoint
= z
->second
.endpoints
.front();
496 s
->zonegroup_name
= zonegroup
.get_name();
498 if (r
< 0 && ret
== 0) {
502 if (s
->bucket_exists
&& !store
->get_zonegroup().equals(s
->bucket_info
.zonegroup
)) {
503 ldout(s
->cct
, 0) << "NOTICE: request for data in a different zonegroup (" << s
->bucket_info
.zonegroup
<< " != " << store
->get_zonegroup().get_id() << ")" << dendl
;
504 /* we now need to make sure that the operation actually requires copy source, that is
505 * it's a copy operation
507 if (store
->get_zonegroup().is_master_zonegroup() && s
->system_request
) {
508 /*If this is the master, don't redirect*/
509 } else if (s
->op_type
== RGW_OP_GET_BUCKET_LOCATION
) {
510 /* If op is get bucket location, don't redirect */
511 } else if (!s
->local_source
||
512 (s
->op
!= OP_PUT
&& s
->op
!= OP_COPY
) ||
514 return -ERR_PERMANENT_REDIRECT
;
519 /* handle user ACL only for those APIs which support it */
521 map
<string
, bufferlist
> uattrs
;
523 ret
= rgw_get_user_attrs_by_uid(store
, acct_acl_user
.uid
, uattrs
);
525 ret
= get_user_policy_from_attr(s
->cct
, store
, uattrs
, *s
->user_acl
);
527 if (-ENOENT
== ret
) {
528 /* In already existing clusters users won't have ACL. In such case
529 * assuming that only account owner has the rights seems to be
530 * reasonable. That allows to have only one verification logic.
531 * NOTE: there is small compatibility kludge for global, empty tenant:
532 * 1. if we try to reach an existing bucket, its owner is considered
534 * 2. otherwise account owner is identity stored in s->user->user_id. */
535 s
->user_acl
->create_default(acct_acl_user
.uid
,
536 acct_acl_user
.display_name
);
539 ldout(s
->cct
, 0) << "NOTICE: couldn't get user attrs for handling ACL (user_id="
549 s
->iam_policy
= get_iam_policy_from_attr(s
->cct
, store
, s
->bucket_attrs
,
551 } catch (const std::exception
& e
) {
552 // Really this is a can't happen condition. We parse the policy
553 // when it's given to us, so perhaps we should abort or otherwise
554 // raise bloody murder.
555 lderr(s
->cct
) << "Error reading IAM Policy: " << e
.what() << dendl
;
563 * Get the AccessControlPolicy for a bucket or object off of disk.
564 * s: The req_state to draw information from.
565 * only_bucket: If true, reads the bucket ACL rather than the object ACL.
566 * Returns: 0 on success, -ERR# otherwise.
568 int rgw_build_object_policies(RGWRados
*store
, struct req_state
*s
,
573 if (!s
->object
.empty()) {
574 if (!s
->bucket_exists
) {
575 return -ERR_NO_SUCH_BUCKET
;
577 s
->object_acl
= ceph::make_unique
<RGWAccessControlPolicy
>(s
->cct
);
579 rgw_obj
obj(s
->bucket
, s
->object
);
581 store
->set_atomic(s
->obj_ctx
, obj
);
583 store
->set_prefetch_data(s
->obj_ctx
, obj
);
585 ret
= read_obj_policy(store
, s
, s
->bucket_info
, s
->bucket_attrs
,
586 s
->object_acl
.get(), s
->iam_policy
, s
->bucket
,
593 rgw::IAM::Environment
rgw_build_iam_environment(RGWRados
* store
,
596 rgw::IAM::Environment e
;
597 const auto& m
= s
->info
.env
->get_map();
598 auto t
= ceph::real_clock::now();
599 e
.emplace("aws:CurrentTime", std::to_string(ceph::real_clock::to_time_t(t
)));
600 e
.emplace("aws:EpochTime", ceph::to_iso_8601(t
));
601 // TODO: This is fine for now, but once we have STS we'll need to
602 // look and see. Also this won't work with the IdentityApplier
603 // model, since we need to know the actual credential.
604 e
.emplace("aws:PrincipalType", "User");
606 auto i
= m
.find("HTTP_REFERER");
608 e
.emplace("aws:Referer", i
->second
);
611 // These seem to be the semantics, judging from rest_rgw_s3.cc
612 i
= m
.find("SERVER_PORT_SECURE");
614 e
.emplace("aws:SecureTransport", "true");
617 const auto remote_addr_param
= s
->cct
->_conf
->rgw_remote_addr_param
;
618 if (remote_addr_param
.length()) {
619 i
= m
.find(remote_addr_param
);
621 i
= m
.find("REMOTE_ADDR");
624 const string
* ip
= &(i
->second
);
626 if (remote_addr_param
== "HTTP_X_FORWARDED_FOR") {
627 const auto comma
= ip
->find(',');
628 if (comma
!= string::npos
) {
629 temp
.assign(*ip
, 0, comma
);
633 e
.emplace("aws:SourceIp", *ip
);
636 i
= m
.find("HTTP_USER_AGENT"); {
638 e
.emplace("aws:UserAgent", i
->second
);
642 // What to do about aws::userid? One can have multiple access
643 // keys so that isn't really suitable. Do we have a durable
644 // identifier that can persist through name changes?
645 e
.emplace("aws:username", s
->user
->user_id
.id
);
650 void rgw_bucket_object_pre_exec(struct req_state
*s
)
655 dump_bucket_from_state(s
);
658 // So! Now and then when we try to update bucket information, the
659 // bucket has changed during the course of the operation. (Or we have
660 // a cache consistency problem that Watch/Notify isn't ruling out
663 // When this happens, we need to update the bucket info and try
664 // again. We have, however, to try the right *part* again. We can't
665 // simply re-send, since that will obliterate the previous update.
667 // Thus, callers of this function should include everything that
668 // merges information to be changed into the bucket information as
669 // well as the call to set it.
671 // The called function must return an integer, negative on error. In
672 // general, they should just return op_ret.
675 int retry_raced_bucket_write(RGWRados
* g
, req_state
* s
, const F
& f
) {
677 for (auto i
= 0u; i
< 15u && r
== -ECANCELED
; ++i
) {
678 r
= g
->try_refresh_bucket_info(s
->bucket_info
, nullptr,
689 int RGWGetObj::verify_permission()
691 obj
= rgw_obj(s
->bucket
, s
->object
);
692 store
->set_atomic(s
->obj_ctx
, obj
);
694 store
->set_prefetch_data(s
->obj_ctx
, obj
);
697 if (torrent
.get_flag()) {
698 if (obj
.key
.instance
.empty()) {
699 action
= rgw::IAM::s3GetObjectTorrent
;
701 action
= rgw::IAM::s3GetObjectVersionTorrent
;
704 if (obj
.key
.instance
.empty()) {
705 action
= rgw::IAM::s3GetObject
;
707 action
= rgw::IAM::s3GetObjectVersion
;
711 if (!verify_object_permission(s
, action
)) {
719 int RGWOp::verify_op_mask()
721 uint32_t required_mask
= op_mask();
723 ldout(s
->cct
, 20) << "required_mask= " << required_mask
724 << " user.op_mask=" << s
->user
->op_mask
<< dendl
;
726 if ((s
->user
->op_mask
& required_mask
) != required_mask
) {
730 if (!s
->system_request
&& (required_mask
& RGW_OP_TYPE_MODIFY
) && !store
->zone_is_writeable()) {
731 ldout(s
->cct
, 5) << "NOTICE: modify request to a read-only zone by a non-system user, permission denied" << dendl
;
738 int RGWGetObjTags::verify_permission()
740 if (!verify_object_permission(s
,
741 s
->object
.instance
.empty() ?
742 rgw::IAM::s3GetObjectTagging
:
743 rgw::IAM::s3GetObjectVersionTagging
))
749 void RGWGetObjTags::pre_exec()
751 rgw_bucket_object_pre_exec(s
);
754 void RGWGetObjTags::execute()
757 map
<string
,bufferlist
> attrs
;
759 obj
= rgw_obj(s
->bucket
, s
->object
);
761 store
->set_atomic(s
->obj_ctx
, obj
);
763 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
765 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << obj
766 << " ret=" << op_ret
<< dendl
;
770 auto tags
= attrs
.find(RGW_ATTR_TAGS
);
771 if(tags
!= attrs
.end()){
773 tags_bl
.append(tags
->second
);
775 send_response_data(tags_bl
);
778 int RGWPutObjTags::verify_permission()
780 if (!verify_object_permission(s
,
781 s
->object
.instance
.empty() ?
782 rgw::IAM::s3PutObjectTagging
:
783 rgw::IAM::s3PutObjectVersionTagging
))
788 void RGWPutObjTags::execute()
790 op_ret
= get_params();
794 if (s
->object
.empty()){
795 op_ret
= -EINVAL
; // we only support tagging on existing objects
800 obj
= rgw_obj(s
->bucket
, s
->object
);
801 store
->set_atomic(s
->obj_ctx
, obj
);
802 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_TAGS
, tags_bl
);
803 if (op_ret
== -ECANCELED
){
804 op_ret
= -ERR_TAG_CONFLICT
;
808 void RGWDeleteObjTags::pre_exec()
810 rgw_bucket_object_pre_exec(s
);
814 int RGWDeleteObjTags::verify_permission()
816 if (!s
->object
.empty()) {
817 if (!verify_object_permission(s
,
818 s
->object
.instance
.empty() ?
819 rgw::IAM::s3DeleteObjectTagging
:
820 rgw::IAM::s3DeleteObjectVersionTagging
))
826 void RGWDeleteObjTags::execute()
828 if (s
->object
.empty())
832 obj
= rgw_obj(s
->bucket
, s
->object
);
833 store
->set_atomic(s
->obj_ctx
, obj
);
834 map
<string
, bufferlist
> attrs
;
835 map
<string
, bufferlist
> rmattr
;
837 rmattr
[RGW_ATTR_TAGS
] = bl
;
838 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattr
);
841 int RGWOp::do_aws4_auth_completion()
843 ldout(s
->cct
, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl
;
844 if (s
->auth
.completer
) {
845 if (!s
->auth
.completer
->complete()) {
846 return -ERR_AMZ_CONTENT_SHA256_MISMATCH
;
848 dout(10) << "v4 auth ok -- do_aws4_auth_completion" << dendl
;
851 /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first
852 * call passes, so we disable second one. This is old behaviour, sorry!
853 * Plan for tomorrow: seek and destroy. */
854 s
->auth
.completer
= nullptr;
860 int RGWOp::init_quota()
862 /* no quota enforcement for system requests */
863 if (s
->system_request
)
866 /* init quota related stuff */
867 if (!(s
->user
->op_mask
& RGW_OP_TYPE_MODIFY
)) {
871 /* only interested in object related ops */
872 if (s
->object
.empty()) {
876 RGWUserInfo owner_info
;
879 if (s
->user
->user_id
== s
->bucket_owner
.get_id()) {
882 int r
= rgw_get_user_info_by_uid(store
, s
->bucket_info
.owner
, owner_info
);
888 if (s
->bucket_info
.quota
.enabled
) {
889 bucket_quota
= s
->bucket_info
.quota
;
890 } else if (uinfo
->bucket_quota
.enabled
) {
891 bucket_quota
= uinfo
->bucket_quota
;
893 bucket_quota
= store
->get_bucket_quota();
896 if (uinfo
->user_quota
.enabled
) {
897 user_quota
= uinfo
->user_quota
;
899 user_quota
= store
->get_user_quota();
905 static bool validate_cors_rule_method(RGWCORSRule
*rule
, const char *req_meth
) {
909 dout(5) << "req_meth is null" << dendl
;
913 if (strcmp(req_meth
, "GET") == 0) flags
= RGW_CORS_GET
;
914 else if (strcmp(req_meth
, "POST") == 0) flags
= RGW_CORS_POST
;
915 else if (strcmp(req_meth
, "PUT") == 0) flags
= RGW_CORS_PUT
;
916 else if (strcmp(req_meth
, "DELETE") == 0) flags
= RGW_CORS_DELETE
;
917 else if (strcmp(req_meth
, "HEAD") == 0) flags
= RGW_CORS_HEAD
;
919 if ((rule
->get_allowed_methods() & flags
) == flags
) {
920 dout(10) << "Method " << req_meth
<< " is supported" << dendl
;
922 dout(5) << "Method " << req_meth
<< " is not supported" << dendl
;
929 static bool validate_cors_rule_header(RGWCORSRule
*rule
, const char *req_hdrs
) {
932 get_str_vec(req_hdrs
, hdrs
);
933 for (const auto& hdr
: hdrs
) {
934 if (!rule
->is_header_allowed(hdr
.c_str(), hdr
.length())) {
935 dout(5) << "Header " << hdr
<< " is not registered in this rule" << dendl
;
943 int RGWOp::read_bucket_cors()
947 map
<string
, bufferlist
>::iterator aiter
= s
->bucket_attrs
.find(RGW_ATTR_CORS
);
948 if (aiter
== s
->bucket_attrs
.end()) {
949 ldout(s
->cct
, 20) << "no CORS configuration attr found" << dendl
;
951 return 0; /* no CORS configuration found */
958 bufferlist::iterator iter
= bl
.begin();
960 bucket_cors
.decode(iter
);
961 } catch (buffer::error
& err
) {
962 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
965 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
966 RGWCORSConfiguration_S3
*s3cors
= static_cast<RGWCORSConfiguration_S3
*>(&bucket_cors
);
967 ldout(s
->cct
, 15) << "Read RGWCORSConfiguration";
968 s3cors
->to_xml(*_dout
);
975 * If any of the header field-names is not a ASCII case-insensitive match for
976 * any of the values in list of headers do not set any additional headers and
977 * terminate this set of steps.
979 static void get_cors_response_headers(RGWCORSRule
*rule
, const char *req_hdrs
, string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
982 get_str_list(req_hdrs
, hl
);
983 for(list
<string
>::iterator it
= hl
.begin(); it
!= hl
.end(); ++it
) {
984 if (!rule
->is_header_allowed((*it
).c_str(), (*it
).length())) {
985 dout(5) << "Header " << (*it
) << " is not registered in this rule" << dendl
;
987 if (hdrs
.length() > 0) hdrs
.append(",");
992 rule
->format_exp_headers(exp_hdrs
);
993 *max_age
= rule
->get_max_age();
997 * Generate the CORS header response
999 * This is described in the CORS standard, section 6.2.
1001 bool RGWOp::generate_cors_headers(string
& origin
, string
& method
, string
& headers
, string
& exp_headers
, unsigned *max_age
)
1004 const char *orig
= s
->info
.env
->get("HTTP_ORIGIN");
1011 op_ret
= read_bucket_cors();
1017 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
1022 RGWCORSRule
*rule
= bucket_cors
.host_name_rule(orig
);
1027 * Set the Allowed-Origin header to a asterisk if this is allowed in the rule
1028 * and no Authorization was send by the client
1030 * The origin parameter specifies a URI that may access the resource. The browser must enforce this.
1031 * For requests without credentials, the server may specify "*" as a wildcard,
1032 * thereby allowing any origin to access the resource.
1034 const char *authorization
= s
->info
.env
->get("HTTP_AUTHORIZATION");
1035 if (!authorization
&& rule
->has_wildcard_origin())
1039 const char *req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
1041 req_meth
= s
->info
.method
;
1047 if (!validate_cors_rule_method(rule
, req_meth
)) {
1053 const char *req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
1056 get_cors_response_headers(rule
, req_hdrs
, headers
, exp_headers
, max_age
);
1061 int RGWGetObj::read_user_manifest_part(rgw_bucket
& bucket
,
1062 const rgw_bucket_dir_entry
& ent
,
1063 RGWAccessControlPolicy
* const bucket_acl
,
1064 const optional
<Policy
>& bucket_policy
,
1065 const off_t start_ofs
,
1066 const off_t end_ofs
)
1068 ldout(s
->cct
, 20) << "user manifest obj=" << ent
.key
.name
<< "[" << ent
.key
.instance
<< "]" << dendl
;
1069 RGWGetObj_CB
cb(this);
1070 RGWGetDataCB
* filter
= &cb
;
1071 boost::optional
<RGWGetObj_Decompress
> decompress
;
1073 int64_t cur_ofs
= start_ofs
;
1074 int64_t cur_end
= end_ofs
;
1076 rgw_obj
part(bucket
, ent
.key
);
1078 map
<string
, bufferlist
> attrs
;
1081 RGWObjectCtx
obj_ctx(store
);
1082 RGWAccessControlPolicy
obj_policy(s
->cct
);
1084 ldout(s
->cct
, 20) << "reading obj=" << part
<< " ofs=" << cur_ofs
<< " end=" << cur_end
<< dendl
;
1086 obj_ctx
.obj
.set_atomic(part
);
1087 store
->set_prefetch_data(&obj_ctx
, part
);
1089 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, part
);
1090 RGWRados::Object::Read
read_op(&op_target
);
1092 read_op
.conds
.if_match
= ent
.meta
.etag
.c_str();
1093 read_op
.params
.attrs
= &attrs
;
1094 read_op
.params
.obj_size
= &obj_size
;
1096 op_ret
= read_op
.prepare();
1099 op_ret
= read_op
.range_to_ofs(ent
.meta
.accounted_size
, cur_ofs
, cur_end
);
1102 bool need_decompress
;
1103 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1105 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1109 if (need_decompress
)
1111 if (cs_info
.orig_size
!= ent
.meta
.accounted_size
) {
1112 // hmm.. something wrong, object not as expected, abort!
1113 ldout(s
->cct
, 0) << "ERROR: expected cs_info.orig_size=" << cs_info
.orig_size
<<
1114 ", actual read size=" << ent
.meta
.size
<< dendl
;
1117 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1118 filter
= &*decompress
;
1122 if (obj_size
!= ent
.meta
.size
) {
1123 // hmm.. something wrong, object not as expected, abort!
1124 ldout(s
->cct
, 0) << "ERROR: expected obj_size=" << obj_size
<< ", actual read size=" << ent
.meta
.size
<< dendl
;
1129 op_ret
= rgw_policy_from_attrset(s
->cct
, attrs
, &obj_policy
);
1133 /* We can use global user_acl because LOs cannot have segments
1134 * stored inside different accounts. */
1135 if (s
->system_request
) {
1136 ldout(s
->cct
, 2) << "overriding permissions due to system operation" << dendl
;
1137 } else if (s
->auth
.identity
->is_admin_of(s
->user
->user_id
)) {
1138 ldout(s
->cct
, 2) << "overriding permissions due to admin operation" << dendl
;
1139 } else if (!verify_object_permission(s
, part
, s
->user_acl
.get(), bucket_acl
,
1140 &obj_policy
, bucket_policy
, action
)) {
1144 if (ent
.meta
.size
== 0) {
1148 perfcounter
->inc(l_rgw_get_b
, cur_end
- cur_ofs
);
1149 filter
->fixup_range(cur_ofs
, cur_end
);
1150 op_ret
= read_op
.iterate(cur_ofs
, cur_end
, filter
);
1152 op_ret
= filter
->flush();
1156 static int iterate_user_manifest_parts(CephContext
* const cct
,
1157 RGWRados
* const store
,
1160 RGWBucketInfo
*pbucket_info
,
1161 const string
& obj_prefix
,
1162 RGWAccessControlPolicy
* const bucket_acl
,
1163 const optional
<Policy
>& bucket_policy
,
1164 uint64_t * const ptotal_len
,
1165 uint64_t * const pobj_size
,
1166 string
* const pobj_sum
,
1167 int (*cb
)(rgw_bucket
& bucket
,
1168 const rgw_bucket_dir_entry
& ent
,
1169 RGWAccessControlPolicy
* const bucket_acl
,
1170 const optional
<Policy
>& bucket_policy
,
1174 void * const cb_param
)
1176 rgw_bucket
& bucket
= pbucket_info
->bucket
;
1177 uint64_t obj_ofs
= 0, len_count
= 0;
1178 bool found_start
= false, found_end
= false, handled_end
= false;
1181 vector
<rgw_bucket_dir_entry
> objs
;
1183 utime_t start_time
= ceph_clock_now();
1185 RGWRados::Bucket
target(store
, *pbucket_info
);
1186 RGWRados::Bucket::List
list_op(&target
);
1188 list_op
.params
.prefix
= obj_prefix
;
1189 list_op
.params
.delim
= delim
;
1193 #define MAX_LIST_OBJS 100
1194 int r
= list_op
.list_objects(MAX_LIST_OBJS
, &objs
, NULL
, &is_truncated
);
1199 for (rgw_bucket_dir_entry
& ent
: objs
) {
1200 const uint64_t cur_total_len
= obj_ofs
;
1201 const uint64_t obj_size
= ent
.meta
.accounted_size
;
1202 uint64_t start_ofs
= 0, end_ofs
= obj_size
;
1204 if ((ptotal_len
|| cb
) && !found_start
&& cur_total_len
+ obj_size
> (uint64_t)ofs
) {
1205 start_ofs
= ofs
- obj_ofs
;
1209 obj_ofs
+= obj_size
;
1211 etag_sum
.Update((const byte
*)ent
.meta
.etag
.c_str(),
1212 ent
.meta
.etag
.length());
1215 if ((ptotal_len
|| cb
) && !found_end
&& obj_ofs
> (uint64_t)end
) {
1216 end_ofs
= end
- cur_total_len
+ 1;
1220 perfcounter
->tinc(l_rgw_get_lat
,
1221 (ceph_clock_now() - start_time
));
1223 if (found_start
&& !handled_end
) {
1224 len_count
+= end_ofs
- start_ofs
;
1227 r
= cb(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
, cb_param
);
1234 handled_end
= found_end
;
1235 start_time
= ceph_clock_now();
1237 } while (is_truncated
);
1240 *ptotal_len
= len_count
;
1243 *pobj_size
= obj_ofs
;
1246 complete_etag(etag_sum
, pobj_sum
);
1252 struct rgw_slo_part
{
1253 RGWAccessControlPolicy
*bucket_acl
= nullptr;
1254 Policy
* bucket_policy
= nullptr;
1261 static int iterate_slo_parts(CephContext
*cct
,
1265 map
<uint64_t, rgw_slo_part
>& slo_parts
,
1266 int (*cb
)(rgw_bucket
& bucket
,
1267 const rgw_bucket_dir_entry
& ent
,
1268 RGWAccessControlPolicy
*bucket_acl
,
1269 const optional
<Policy
>& bucket_policy
,
1275 bool found_start
= false, found_end
= false;
1277 if (slo_parts
.empty()) {
1281 utime_t start_time
= ceph_clock_now();
1283 map
<uint64_t, rgw_slo_part
>::iterator iter
= slo_parts
.upper_bound(ofs
);
1284 if (iter
!= slo_parts
.begin()) {
1288 uint64_t obj_ofs
= iter
->first
;
1290 for (; iter
!= slo_parts
.end() && !found_end
; ++iter
) {
1291 rgw_slo_part
& part
= iter
->second
;
1292 rgw_bucket_dir_entry ent
;
1294 ent
.key
.name
= part
.obj_name
;
1295 ent
.meta
.accounted_size
= ent
.meta
.size
= part
.size
;
1296 ent
.meta
.etag
= part
.etag
;
1298 uint64_t cur_total_len
= obj_ofs
;
1299 uint64_t start_ofs
= 0, end_ofs
= ent
.meta
.size
;
1301 if (!found_start
&& cur_total_len
+ ent
.meta
.size
> (uint64_t)ofs
) {
1302 start_ofs
= ofs
- obj_ofs
;
1306 obj_ofs
+= ent
.meta
.size
;
1308 if (!found_end
&& obj_ofs
> (uint64_t)end
) {
1309 end_ofs
= end
- cur_total_len
+ 1;
1313 perfcounter
->tinc(l_rgw_get_lat
,
1314 (ceph_clock_now() - start_time
));
1318 // SLO is a Swift thing, and Swift has no knowledge of S3 Policies.
1319 int r
= cb(part
.bucket
, ent
, part
.bucket_acl
,
1320 (part
.bucket_policy
?
1321 optional
<Policy
>(*part
.bucket_policy
) : none
),
1322 start_ofs
, end_ofs
, cb_param
);
1328 start_time
= ceph_clock_now();
1334 static int get_obj_user_manifest_iterate_cb(rgw_bucket
& bucket
,
1335 const rgw_bucket_dir_entry
& ent
,
1336 RGWAccessControlPolicy
* const bucket_acl
,
1337 const optional
<Policy
>& bucket_policy
,
1338 const off_t start_ofs
,
1339 const off_t end_ofs
,
1342 RGWGetObj
*op
= static_cast<RGWGetObj
*>(param
);
1343 return op
->read_user_manifest_part(bucket
, ent
, bucket_acl
, bucket_policy
, start_ofs
, end_ofs
);
1346 int RGWGetObj::handle_user_manifest(const char *prefix
)
1348 const boost::string_view
prefix_view(prefix
);
1349 ldout(s
->cct
, 2) << "RGWGetObj::handle_user_manifest() prefix="
1350 << prefix_view
<< dendl
;
1352 const size_t pos
= prefix_view
.find('/');
1353 if (pos
== string::npos
) {
1357 const std::string bucket_name
= url_decode(prefix_view
.substr(0, pos
));
1358 const std::string obj_prefix
= url_decode(prefix_view
.substr(pos
+ 1));
1362 RGWAccessControlPolicy
_bucket_acl(s
->cct
);
1363 RGWAccessControlPolicy
*bucket_acl
;
1364 optional
<Policy
> _bucket_policy
;
1365 optional
<Policy
>* bucket_policy
;
1366 RGWBucketInfo bucket_info
;
1367 RGWBucketInfo
*pbucket_info
;
1369 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1370 map
<string
, bufferlist
> bucket_attrs
;
1371 RGWObjectCtx
obj_ctx(store
);
1372 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1373 bucket_name
, bucket_info
, NULL
,
1376 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1377 << bucket_name
<< dendl
;
1380 bucket
= bucket_info
.bucket
;
1381 pbucket_info
= &bucket_info
;
1382 bucket_acl
= &_bucket_acl
;
1383 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
, bucket
);
1385 ldout(s
->cct
, 0) << "failed to read bucket policy" << dendl
;
1388 _bucket_policy
= get_iam_policy_from_attr(s
->cct
, store
, bucket_attrs
,
1389 bucket_info
.bucket
.tenant
);
1390 bucket_policy
= &_bucket_policy
;
1393 pbucket_info
= &s
->bucket_info
;
1394 bucket_acl
= s
->bucket_acl
.get();
1395 bucket_policy
= &s
->iam_policy
;
1398 /* dry run to find out:
1399 * - total length (of the parts we are going to send to client),
1400 * - overall DLO's content size,
1401 * - md5 sum of overall DLO's content (for etag of Swift API). */
1402 int r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1403 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1404 nullptr, &s
->obj_size
, &lo_etag
,
1405 nullptr /* cb */, nullptr /* cb arg */);
1410 r
= RGWRados::Object::Read::range_to_ofs(s
->obj_size
, ofs
, end
);
1415 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1416 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1417 &total_len
, nullptr, nullptr,
1425 send_response_data(bl
, 0, 0);
1429 r
= iterate_user_manifest_parts(s
->cct
, store
, ofs
, end
,
1430 pbucket_info
, obj_prefix
, bucket_acl
, *bucket_policy
,
1431 nullptr, nullptr, nullptr,
1432 get_obj_user_manifest_iterate_cb
, (void *)this);
1439 send_response_data(bl
, 0, 0);
1445 int RGWGetObj::handle_slo_manifest(bufferlist
& bl
)
1447 RGWSLOInfo slo_info
;
1448 bufferlist::iterator bliter
= bl
.begin();
1450 ::decode(slo_info
, bliter
);
1451 } catch (buffer::error
& err
) {
1452 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
1455 ldout(s
->cct
, 2) << "RGWGetObj::handle_slo_manifest()" << dendl
;
1457 vector
<RGWAccessControlPolicy
> allocated_acls
;
1458 map
<string
, pair
<RGWAccessControlPolicy
*, optional
<Policy
>>> policies
;
1459 map
<string
, rgw_bucket
> buckets
;
1461 map
<uint64_t, rgw_slo_part
> slo_parts
;
1466 for (const auto& entry
: slo_info
.entries
) {
1467 const string
& path
= entry
.path
;
1469 /* If the path starts with slashes, strip them all. */
1470 const size_t pos_init
= path
.find_first_not_of('/');
1471 /* According to the documentation of std::string::find following check
1472 * is not necessary as we should get the std::string::npos propagation
1473 * here. This might be true with the accuracy to implementation's bugs.
1474 * See following question on SO:
1475 * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos
1477 if (pos_init
== string::npos
) {
1481 const size_t pos_sep
= path
.find('/', pos_init
);
1482 if (pos_sep
== string::npos
) {
1486 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
1487 string obj_name
= path
.substr(pos_sep
+ 1);
1490 RGWAccessControlPolicy
*bucket_acl
;
1491 Policy
* bucket_policy
;
1493 if (bucket_name
.compare(s
->bucket
.name
) != 0) {
1494 const auto& piter
= policies
.find(bucket_name
);
1495 if (piter
!= policies
.end()) {
1496 bucket_acl
= piter
->second
.first
;
1497 bucket_policy
= piter
->second
.second
.get_ptr();
1498 bucket
= buckets
[bucket_name
];
1500 allocated_acls
.push_back(RGWAccessControlPolicy(s
->cct
));
1501 RGWAccessControlPolicy
& _bucket_acl
= allocated_acls
.back();
1503 RGWBucketInfo bucket_info
;
1504 map
<string
, bufferlist
> bucket_attrs
;
1505 RGWObjectCtx
obj_ctx(store
);
1506 int r
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
1507 bucket_name
, bucket_info
, nullptr,
1510 ldout(s
->cct
, 0) << "could not get bucket info for bucket="
1511 << bucket_name
<< dendl
;
1514 bucket
= bucket_info
.bucket
;
1515 bucket_acl
= &_bucket_acl
;
1516 r
= read_bucket_policy(store
, s
, bucket_info
, bucket_attrs
, bucket_acl
,
1519 ldout(s
->cct
, 0) << "failed to read bucket ACL for bucket "
1523 auto _bucket_policy
= get_iam_policy_from_attr(
1524 s
->cct
, store
, bucket_attrs
, bucket_info
.bucket
.tenant
);
1525 bucket_policy
= _bucket_policy
.get_ptr();
1526 buckets
[bucket_name
] = bucket
;
1527 policies
[bucket_name
] = make_pair(bucket_acl
, _bucket_policy
);
1531 bucket_acl
= s
->bucket_acl
.get();
1532 bucket_policy
= s
->iam_policy
.get_ptr();
1536 part
.bucket_acl
= bucket_acl
;
1537 part
.bucket_policy
= bucket_policy
;
1538 part
.bucket
= bucket
;
1539 part
.obj_name
= obj_name
;
1540 part
.size
= entry
.size_bytes
;
1541 part
.etag
= entry
.etag
;
1542 ldout(s
->cct
, 20) << "slo_part: ofs=" << ofs
1543 << " bucket=" << part
.bucket
1544 << " obj=" << part
.obj_name
1545 << " size=" << part
.size
1546 << " etag=" << part
.etag
1549 etag_sum
.Update((const byte
*)entry
.etag
.c_str(),
1550 entry
.etag
.length());
1552 slo_parts
[total_len
] = part
;
1553 total_len
+= part
.size
;
1556 complete_etag(etag_sum
, &lo_etag
);
1558 s
->obj_size
= slo_info
.total_size
;
1559 ldout(s
->cct
, 20) << "s->obj_size=" << s
->obj_size
<< dendl
;
1561 int r
= RGWRados::Object::Read::range_to_ofs(total_len
, ofs
, end
);
1566 total_len
= end
- ofs
+ 1;
1568 r
= iterate_slo_parts(s
->cct
, store
, ofs
, end
, slo_parts
,
1569 get_obj_user_manifest_iterate_cb
, (void *)this);
1577 int RGWGetObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
1579 /* garbage collection related handling */
1580 utime_t start_time
= ceph_clock_now();
1581 if (start_time
> gc_invalidate_time
) {
1582 int r
= store
->defer_gc(s
->obj_ctx
, s
->bucket_info
, obj
);
1584 dout(0) << "WARNING: could not defer gc entry for obj" << dendl
;
1586 gc_invalidate_time
= start_time
;
1587 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1589 return send_response_data(bl
, bl_ofs
, bl_len
);
1592 bool RGWGetObj::prefetch_data()
1594 /* HEAD request, stop prefetch*/
1599 bool prefetch_first_chunk
= true;
1600 range_str
= s
->info
.env
->get("HTTP_RANGE");
1603 int r
= parse_range();
1604 /* error on parsing the range, stop prefetch and will fail in execute() */
1606 return false; /* range_parsed==false */
1608 /* range get goes to shadow objects, stop prefetch */
1609 if (ofs
>= s
->cct
->_conf
->rgw_max_chunk_size
) {
1610 prefetch_first_chunk
= false;
1614 return get_data
&& prefetch_first_chunk
;
1617 void RGWGetObj::pre_exec()
1619 rgw_bucket_object_pre_exec(s
);
1622 static bool object_is_expired(map
<string
, bufferlist
>& attrs
) {
1623 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1624 if (iter
!= attrs
.end()) {
1627 ::decode(delete_at
, iter
->second
);
1628 } catch (buffer::error
& err
) {
1629 dout(0) << "ERROR: " << __func__
<< ": failed to decode " RGW_ATTR_DELETE_AT
" attr" << dendl
;
1633 if (delete_at
<= ceph_clock_now() && !delete_at
.is_zero()) {
1641 void RGWGetObj::execute()
1643 utime_t start_time
= s
->time
;
1645 gc_invalidate_time
= ceph_clock_now();
1646 gc_invalidate_time
+= (s
->cct
->_conf
->rgw_gc_obj_min_wait
/ 2);
1648 bool need_decompress
;
1649 int64_t ofs_x
, end_x
;
1651 RGWGetObj_CB
cb(this);
1652 RGWGetDataCB
* filter
= (RGWGetDataCB
*)&cb
;
1653 boost::optional
<RGWGetObj_Decompress
> decompress
;
1654 std::unique_ptr
<RGWGetDataCB
> decrypt
;
1655 map
<string
, bufferlist
>::iterator attr_iter
;
1657 perfcounter
->inc(l_rgw_get
);
1659 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
1660 RGWRados::Object::Read
read_op(&op_target
);
1662 op_ret
= get_params();
1666 op_ret
= init_common();
1670 read_op
.conds
.mod_ptr
= mod_ptr
;
1671 read_op
.conds
.unmod_ptr
= unmod_ptr
;
1672 read_op
.conds
.high_precision_time
= s
->system_request
; /* system request need to use high precision time */
1673 read_op
.conds
.mod_zone_id
= mod_zone_id
;
1674 read_op
.conds
.mod_pg_ver
= mod_pg_ver
;
1675 read_op
.conds
.if_match
= if_match
;
1676 read_op
.conds
.if_nomatch
= if_nomatch
;
1677 read_op
.params
.attrs
= &attrs
;
1678 read_op
.params
.lastmod
= &lastmod
;
1679 read_op
.params
.obj_size
= &s
->obj_size
;
1681 op_ret
= read_op
.prepare();
1684 version_id
= read_op
.state
.obj
.key
.instance
;
1686 /* STAT ops don't need data, and do no i/o */
1687 if (get_type() == RGW_OP_STAT_OBJ
) {
1691 /* start gettorrent */
1692 if (torrent
.get_flag())
1694 attr_iter
= attrs
.find(RGW_ATTR_CRYPT_MODE
);
1695 if (attr_iter
!= attrs
.end() && attr_iter
->second
.to_str() == "SSE-C-AES256") {
1696 ldout(s
->cct
, 0) << "ERROR: torrents are not supported for objects "
1697 "encrypted with SSE-C" << dendl
;
1701 torrent
.init(s
, store
);
1702 op_ret
= torrent
.get_torrent_file(read_op
, total_len
, bl
, obj
);
1705 ldout(s
->cct
, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret
1709 op_ret
= send_response_data(bl
, 0, total_len
);
1712 ldout(s
->cct
, 0) << "ERROR: failed to send_response_data ret= " << op_ret
1718 /* end gettorrent */
1720 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
1722 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
1725 if (need_decompress
) {
1726 s
->obj_size
= cs_info
.orig_size
;
1727 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
1728 filter
= &*decompress
;
1731 attr_iter
= attrs
.find(RGW_ATTR_USER_MANIFEST
);
1732 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1733 op_ret
= handle_user_manifest(attr_iter
->second
.c_str());
1735 ldout(s
->cct
, 0) << "ERROR: failed to handle user manifest ret="
1742 attr_iter
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
1743 if (attr_iter
!= attrs
.end() && !skip_manifest
) {
1745 op_ret
= handle_slo_manifest(attr_iter
->second
);
1747 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
1754 // for range requests with obj size 0
1755 if (range_str
&& !(s
->obj_size
)) {
1761 op_ret
= read_op
.range_to_ofs(s
->obj_size
, ofs
, end
);
1764 total_len
= (ofs
<= end
? end
+ 1 - ofs
: 0);
1766 /* Check whether the object has expired. Swift API documentation
1767 * stands that we should return 404 Not Found in such case. */
1768 if (need_object_expiration() && object_is_expired(attrs
)) {
1775 /* STAT ops don't need data, and do no i/o */
1776 if (get_type() == RGW_OP_STAT_OBJ
) {
1780 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
1781 op_ret
= this->get_decrypt_filter(&decrypt
, filter
,
1782 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
1783 if (decrypt
!= nullptr) {
1784 filter
= decrypt
.get();
1790 if (!get_data
|| ofs
> end
) {
1791 send_response_data(bl
, 0, 0);
1795 perfcounter
->inc(l_rgw_get_b
, end
- ofs
);
1799 filter
->fixup_range(ofs_x
, end_x
);
1800 op_ret
= read_op
.iterate(ofs_x
, end_x
, filter
);
1803 op_ret
= filter
->flush();
1805 perfcounter
->tinc(l_rgw_get_lat
,
1806 (ceph_clock_now() - start_time
));
1811 op_ret
= send_response_data(bl
, 0, 0);
1818 send_response_data_error();
1821 int RGWGetObj::init_common()
1824 /* range parsed error when prefetch */
1825 if (!range_parsed
) {
1826 int r
= parse_range();
1832 if (parse_time(if_mod
, &mod_time
) < 0)
1834 mod_ptr
= &mod_time
;
1838 if (parse_time(if_unmod
, &unmod_time
) < 0)
1840 unmod_ptr
= &unmod_time
;
1846 int RGWListBuckets::verify_permission()
1848 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
1855 int RGWGetUsage::verify_permission()
1857 if (s
->auth
.identity
->is_anonymous()) {
1864 void RGWListBuckets::execute()
1867 bool started
= false;
1868 uint64_t total_count
= 0;
1870 const uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
1872 op_ret
= get_params();
1877 if (supports_account_metadata()) {
1878 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, attrs
);
1884 is_truncated
= false;
1886 RGWUserBuckets buckets
;
1887 uint64_t read_count
;
1889 read_count
= min(limit
- total_count
, (uint64_t)max_buckets
);
1891 read_count
= max_buckets
;
1894 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
1895 marker
, end_marker
, read_count
,
1896 should_get_stats(), &is_truncated
,
1899 /* hmm.. something wrong here.. the user was authenticated, so it
1901 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
1902 << s
->user
->user_id
<< dendl
;
1906 /* We need to have stats for all our policies - even if a given policy
1907 * isn't actually used in a given account. In such situation its usage
1908 * stats would be simply full of zeros. */
1909 for (const auto& policy
: store
->get_zonegroup().placement_targets
) {
1910 policies_stats
.emplace(policy
.second
.name
,
1911 decltype(policies_stats
)::mapped_type());
1914 std::map
<std::string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
1915 for (const auto& kv
: m
) {
1916 const auto& bucket
= kv
.second
;
1918 global_stats
.bytes_used
+= bucket
.size
;
1919 global_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
1920 global_stats
.objects_count
+= bucket
.count
;
1922 /* operator[] still can create a new entry for storage policy seen
1923 * for first time. */
1924 auto& policy_stats
= policies_stats
[bucket
.placement_rule
];
1925 policy_stats
.bytes_used
+= bucket
.size
;
1926 policy_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
1927 policy_stats
.buckets_count
++;
1928 policy_stats
.objects_count
+= bucket
.count
;
1930 global_stats
.buckets_count
+= m
.size();
1931 total_count
+= m
.size();
1933 done
= (m
.size() < read_count
|| (limit
>= 0 && total_count
>= (uint64_t)limit
));
1936 send_response_begin(buckets
.count() > 0);
1941 map
<string
, RGWBucketEnt
>::reverse_iterator riter
= m
.rbegin();
1942 marker
= riter
->first
;
1944 handle_listing_chunk(std::move(buckets
));
1946 } while (is_truncated
&& !done
);
1950 send_response_begin(false);
1952 send_response_end();
1955 void RGWGetUsage::execute()
1957 uint64_t start_epoch
= 0;
1958 uint64_t end_epoch
= (uint64_t)-1;
1959 op_ret
= get_params();
1963 if (!start_date
.empty()) {
1964 op_ret
= utime_t::parse_date(start_date
, &start_epoch
, NULL
);
1966 ldout(store
->ctx(), 0) << "ERROR: failed to parse start date" << dendl
;
1971 if (!end_date
.empty()) {
1972 op_ret
= utime_t::parse_date(end_date
, &end_epoch
, NULL
);
1974 ldout(store
->ctx(), 0) << "ERROR: failed to parse end date" << dendl
;
1979 uint32_t max_entries
= 1000;
1981 bool is_truncated
= true;
1983 RGWUsageIter usage_iter
;
1985 while (is_truncated
) {
1986 op_ret
= store
->read_usage(s
->user
->user_id
, start_epoch
, end_epoch
, max_entries
,
1987 &is_truncated
, usage_iter
, usage
);
1989 if (op_ret
== -ENOENT
) {
1991 is_truncated
= false;
1999 op_ret
= rgw_user_sync_all_stats(store
, s
->user
->user_id
);
2001 ldout(store
->ctx(), 0) << "ERROR: failed to sync user stats: " << dendl
;
2005 op_ret
= rgw_user_get_all_buckets_stats(store
, s
->user
->user_id
, buckets_usage
);
2007 cerr
<< "ERROR: failed to sync user stats: " << std::endl
;
2011 string user_str
= s
->user
->user_id
.to_str();
2012 op_ret
= store
->cls_user_get_header(user_str
, &header
);
2014 ldout(store
->ctx(), 0) << "ERROR: can't read user header: " << dendl
;
2021 int RGWStatAccount::verify_permission()
2023 if (!verify_user_permission(s
, RGW_PERM_READ
)) {
2030 void RGWStatAccount::execute()
2033 bool is_truncated
= false;
2034 uint64_t max_buckets
= s
->cct
->_conf
->rgw_list_buckets_max_chunk
;
2037 RGWUserBuckets buckets
;
2039 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
, marker
,
2040 string(), max_buckets
, true, &is_truncated
);
2042 /* hmm.. something wrong here.. the user was authenticated, so it
2044 ldout(s
->cct
, 10) << "WARNING: failed on rgw_get_user_buckets uid="
2045 << s
->user
->user_id
<< dendl
;
2048 /* We need to have stats for all our policies - even if a given policy
2049 * isn't actually used in a given account. In such situation its usage
2050 * stats would be simply full of zeros. */
2051 for (const auto& policy
: store
->get_zonegroup().placement_targets
) {
2052 policies_stats
.emplace(policy
.second
.name
,
2053 decltype(policies_stats
)::mapped_type());
2056 std::map
<std::string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2057 for (const auto& kv
: m
) {
2058 const auto& bucket
= kv
.second
;
2060 global_stats
.bytes_used
+= bucket
.size
;
2061 global_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2062 global_stats
.objects_count
+= bucket
.count
;
2064 /* operator[] still can create a new entry for storage policy seen
2065 * for first time. */
2066 auto& policy_stats
= policies_stats
[bucket
.placement_rule
];
2067 policy_stats
.bytes_used
+= bucket
.size
;
2068 policy_stats
.bytes_used_rounded
+= bucket
.size_rounded
;
2069 policy_stats
.buckets_count
++;
2070 policy_stats
.objects_count
+= bucket
.count
;
2072 global_stats
.buckets_count
+= m
.size();
2075 } while (is_truncated
);
2078 int RGWGetBucketVersioning::verify_permission()
2080 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketVersioning
);
2083 void RGWGetBucketVersioning::pre_exec()
2085 rgw_bucket_object_pre_exec(s
);
2088 void RGWGetBucketVersioning::execute()
2090 versioned
= s
->bucket_info
.versioned();
2091 versioning_enabled
= s
->bucket_info
.versioning_enabled();
2094 int RGWSetBucketVersioning::verify_permission()
2096 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketVersioning
);
2099 void RGWSetBucketVersioning::pre_exec()
2101 rgw_bucket_object_pre_exec(s
);
2104 void RGWSetBucketVersioning::execute()
2106 op_ret
= get_params();
2110 if (!store
->is_meta_master()) {
2111 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2113 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
2118 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2119 if (enable_versioning
) {
2120 s
->bucket_info
.flags
|= BUCKET_VERSIONED
;
2121 s
->bucket_info
.flags
&= ~BUCKET_VERSIONS_SUSPENDED
;
2123 s
->bucket_info
.flags
|= (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
);
2126 return store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
2131 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
2132 << " returned err=" << op_ret
<< dendl
;
2137 int RGWGetBucketWebsite::verify_permission()
2139 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketWebsite
);
2142 void RGWGetBucketWebsite::pre_exec()
2144 rgw_bucket_object_pre_exec(s
);
2147 void RGWGetBucketWebsite::execute()
2149 if (!s
->bucket_info
.has_website
) {
2150 op_ret
= -ERR_NO_SUCH_WEBSITE_CONFIGURATION
;
2154 int RGWSetBucketWebsite::verify_permission()
2156 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketWebsite
);
2159 void RGWSetBucketWebsite::pre_exec()
2161 rgw_bucket_object_pre_exec(s
);
2164 void RGWSetBucketWebsite::execute()
2166 op_ret
= get_params();
2171 if (!store
->is_meta_master()) {
2172 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
2174 ldout(s
->cct
, 20) << __func__
<< " forward_request_to_master returned ret=" << op_ret
<< dendl
;
2179 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2180 s
->bucket_info
.has_website
= true;
2181 s
->bucket_info
.website_conf
= website_conf
;
2182 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false,
2183 real_time(), &s
->bucket_attrs
);
2188 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2193 int RGWDeleteBucketWebsite::verify_permission()
2195 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3DeleteBucketWebsite
);
2198 void RGWDeleteBucketWebsite::pre_exec()
2200 rgw_bucket_object_pre_exec(s
);
2203 void RGWDeleteBucketWebsite::execute()
2205 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
2206 s
->bucket_info
.has_website
= false;
2207 s
->bucket_info
.website_conf
= RGWBucketWebsiteConf();
2208 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false,
2209 real_time(), &s
->bucket_attrs
);
2213 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
2218 int RGWStatBucket::verify_permission()
2220 // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission.
2221 if (!verify_bucket_permission(s
, rgw::IAM::s3ListBucket
)) {
2228 void RGWStatBucket::pre_exec()
2230 rgw_bucket_object_pre_exec(s
);
2233 void RGWStatBucket::execute()
2235 if (!s
->bucket_exists
) {
2236 op_ret
= -ERR_NO_SUCH_BUCKET
;
2240 RGWUserBuckets buckets
;
2241 bucket
.bucket
= s
->bucket
;
2242 buckets
.add(bucket
);
2243 map
<string
, RGWBucketEnt
>& m
= buckets
.get_buckets();
2244 op_ret
= store
->update_containers_stats(m
);
2249 map
<string
, RGWBucketEnt
>::iterator iter
= m
.find(bucket
.bucket
.name
);
2250 if (iter
!= m
.end()) {
2251 bucket
= iter
->second
;
2258 int RGWListBucket::verify_permission()
2260 op_ret
= get_params();
2264 if (!prefix
.empty())
2265 s
->env
.emplace("s3:prefix", prefix
);
2267 if (!delimiter
.empty())
2268 s
->env
.emplace("s3:delimiter", delimiter
);
2270 s
->env
.emplace("s3:max-keys", std::to_string(max
));
2272 if (!verify_bucket_permission(s
,
2274 rgw::IAM::s3ListBucketVersions
:
2275 rgw::IAM::s3ListBucket
)) {
2282 int RGWListBucket::parse_max_keys()
2284 if (!max_keys
.empty()) {
2286 max
= strtol(max_keys
.c_str(), &endptr
, 10);
2288 if (endptr
== max_keys
.c_str()) return -EINVAL
;
2289 while (*endptr
&& isspace(*endptr
)) // ignore white space
2302 void RGWListBucket::pre_exec()
2304 rgw_bucket_object_pre_exec(s
);
2307 void RGWListBucket::execute()
2309 if (!s
->bucket_exists
) {
2310 op_ret
= -ERR_NO_SUCH_BUCKET
;
2314 if (need_container_stats()) {
2315 map
<string
, RGWBucketEnt
> m
;
2316 m
[s
->bucket
.name
] = RGWBucketEnt();
2317 m
.begin()->second
.bucket
= s
->bucket
;
2318 op_ret
= store
->update_containers_stats(m
);
2320 bucket
= m
.begin()->second
;
2324 RGWRados::Bucket
target(store
, s
->bucket_info
);
2325 if (shard_id
>= 0) {
2326 target
.set_shard_id(shard_id
);
2328 RGWRados::Bucket::List
list_op(&target
);
2330 list_op
.params
.prefix
= prefix
;
2331 list_op
.params
.delim
= delimiter
;
2332 list_op
.params
.marker
= marker
;
2333 list_op
.params
.end_marker
= end_marker
;
2334 list_op
.params
.list_versions
= list_versions
;
2336 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2338 next_marker
= list_op
.get_next_marker();
2342 int RGWGetBucketLogging::verify_permission()
2344 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLogging
);
2347 int RGWGetBucketLocation::verify_permission()
2349 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLocation
);
2352 int RGWCreateBucket::verify_permission()
2354 /* This check is mostly needed for S3 that doesn't support account ACL.
2355 * Swift doesn't allow to delegate any permission to an anonymous user,
2356 * so it will become an early exit in such case. */
2357 if (s
->auth
.identity
->is_anonymous()) {
2361 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
2365 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2366 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
2367 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2368 << " requested=" << s
->bucket_tenant
<< ")"
2372 if (s
->user
->max_buckets
< 0) {
2376 if (s
->user
->max_buckets
) {
2377 RGWUserBuckets buckets
;
2379 bool is_truncated
= false;
2380 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2381 marker
, string(), s
->user
->max_buckets
,
2382 false, &is_truncated
);
2387 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2388 return -ERR_TOO_MANY_BUCKETS
;
2395 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2396 RGWRados
*store
, bufferlist
& in_data
,
2397 JSONParser
*jp
, req_info
*forward_info
)
2399 if (!store
->rest_master_conn
) {
2400 ldout(s
->cct
, 0) << "rest connection is invalid" << dendl
;
2403 ldout(s
->cct
, 0) << "sending request to master zonegroup" << dendl
;
2404 bufferlist response
;
2405 string uid_str
= s
->user
->user_id
.to_str();
2406 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2407 int ret
= store
->rest_master_conn
->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2408 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2412 ldout(s
->cct
, 20) << "response: " << response
.c_str() << dendl
;
2413 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2414 ldout(s
->cct
, 0) << "failed parsing response from master zonegroup" << dendl
;
2421 void RGWCreateBucket::pre_exec()
2423 rgw_bucket_object_pre_exec(s
);
2426 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2427 map
<string
, bufferlist
>& out_attrs
,
2428 map
<string
, bufferlist
>& out_rmattrs
)
2430 for (const auto& kv
: orig_attrs
) {
2431 const string
& name
= kv
.first
;
2433 /* Check if the attr is user-defined metadata item. */
2434 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2435 RGW_ATTR_META_PREFIX
) == 0) {
2436 /* For the objects all existing meta attrs have to be removed. */
2437 out_rmattrs
[name
] = kv
.second
;
2438 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2439 out_attrs
[name
] = kv
.second
;
2444 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2445 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2446 * @out_attrs. Place results in @out_attrs.
2448 * NOTE: it's supposed that all special attrs already present in @out_attrs
2449 * will be preserved without any change. Special attributes are those which
2450 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2451 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2452 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2453 const set
<string
>& rmattr_names
,
2454 map
<string
, bufferlist
>& out_attrs
)
2456 for (const auto& kv
: orig_attrs
) {
2457 const string
& name
= kv
.first
;
2459 /* Check if the attr is user-defined metadata item. */
2460 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2461 RGW_ATTR_META_PREFIX
) == 0) {
2462 /* For the buckets all existing meta attrs are preserved,
2463 except those that are listed in rmattr_names. */
2464 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2465 const auto aiter
= out_attrs
.find(name
);
2467 if (aiter
!= std::end(out_attrs
)) {
2468 out_attrs
.erase(aiter
);
2471 /* emplace() won't alter the map if the key is already present.
2472 * This behaviour is fully intensional here. */
2473 out_attrs
.emplace(kv
);
2475 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2476 out_attrs
[name
] = kv
.second
;
2482 static void populate_with_generic_attrs(const req_state
* const s
,
2483 map
<string
, bufferlist
>& out_attrs
)
2485 for (const auto& kv
: s
->generic_attrs
) {
2486 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2487 const string
& val
= kv
.second
;
2489 attrbl
.append(val
.c_str(), val
.size() + 1);
2494 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2495 const std::set
<std::string
>& rmattr_names
,
2496 RGWQuotaInfo
& quota
,
2497 bool * quota_extracted
= nullptr)
2499 bool extracted
= false;
2501 /* Put new limit on max objects. */
2502 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2504 if (std::end(add_attrs
) != iter
) {
2506 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2510 add_attrs
.erase(iter
);
2514 /* Put new limit on bucket (container) size. */
2515 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2516 if (iter
!= add_attrs
.end()) {
2518 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2522 add_attrs
.erase(iter
);
2526 for (const auto& name
: rmattr_names
) {
2527 /* Remove limit on max objects. */
2528 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2529 quota
.max_objects
= -1;
2533 /* Remove limit on max bucket size. */
2534 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2535 quota
.max_size
= -1;
2540 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2541 quota
.check_on_raw
= true;
2542 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2544 if (quota_extracted
) {
2545 *quota_extracted
= extracted
;
2552 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2553 const std::set
<std::string
>& rmattr_names
,
2554 RGWBucketWebsiteConf
& ws_conf
)
2558 /* Let's define a mapping between each custom attribute and the memory where
2559 * attribute's value should be stored. The memory location is expressed by
2560 * a non-const reference. */
2561 const auto mapping
= {
2562 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2563 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2564 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2565 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2566 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2569 for (const auto& kv
: mapping
) {
2570 const char * const key
= kv
.first
;
2571 auto& target
= kv
.second
;
2573 auto iter
= add_attrs
.find(key
);
2575 if (std::end(add_attrs
) != iter
) {
2576 /* The "target" is a reference to ws_conf. */
2577 target
= iter
->second
.c_str();
2578 add_attrs
.erase(iter
);
2581 if (rmattr_names
.count(key
)) {
2582 target
= std::string();
2586 if (! lstval
.empty()) {
2587 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2592 void RGWCreateBucket::execute()
2594 RGWAccessControlPolicy
old_policy(s
->cct
);
2596 buffer::list corsbl
;
2599 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2600 rgw_raw_obj
obj(store
->get_zone_params().domain_root
, bucket_name
);
2601 obj_version objv
, *pobjv
= NULL
;
2603 op_ret
= get_params();
2607 if (!location_constraint
.empty() &&
2608 !store
->has_zonegroup_api(location_constraint
)) {
2609 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2610 << " can't be found." << dendl
;
2611 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2612 s
->err
.message
= "The specified location-constraint is not valid";
2616 if (!store
->get_zonegroup().is_master_zonegroup() && !location_constraint
.empty() &&
2617 store
->get_zonegroup().api_name
!= location_constraint
) {
2618 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2619 << " doesn't match zonegroup" << " (" << store
->get_zonegroup().api_name
<< ")"
2621 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2622 s
->err
.message
= "The specified location-constraint is not valid";
2626 const auto& zonegroup
= store
->get_zonegroup();
2627 if (!placement_rule
.empty() &&
2628 !zonegroup
.placement_targets
.count(placement_rule
)) {
2629 ldout(s
->cct
, 0) << "placement target (" << placement_rule
<< ")"
2630 << " doesn't exist in the placement targets of zonegroup"
2631 << " (" << store
->get_zonegroup().api_name
<< ")" << dendl
;
2632 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2633 s
->err
.message
= "The specified placement target does not exist";
2637 /* we need to make sure we read bucket info, it's not read before for this
2638 * specific request */
2639 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2640 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2641 s
->bucket_info
, NULL
, &s
->bucket_attrs
);
2642 if (op_ret
< 0 && op_ret
!= -ENOENT
)
2644 s
->bucket_exists
= (op_ret
!= -ENOENT
);
2646 s
->bucket_owner
.set_id(s
->user
->user_id
);
2647 s
->bucket_owner
.set_name(s
->user
->display_name
);
2648 if (s
->bucket_exists
) {
2649 int r
= get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
2650 s
->bucket_attrs
, &old_policy
);
2652 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
2659 RGWBucketInfo master_info
;
2660 rgw_bucket
*pmaster_bucket
;
2661 uint32_t *pmaster_num_shards
;
2662 real_time creation_time
;
2664 if (!store
->is_meta_master()) {
2666 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
2671 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
2672 JSONDecoder::decode_json("object_ver", objv
, &jp
);
2673 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
2674 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
2675 ldout(s
->cct
, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
2676 pmaster_bucket
= &master_info
.bucket
;
2677 creation_time
= master_info
.creation_time
;
2678 pmaster_num_shards
= &master_info
.num_shards
;
2681 pmaster_bucket
= NULL
;
2682 pmaster_num_shards
= NULL
;
2685 string zonegroup_id
;
2687 if (s
->system_request
) {
2688 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
2689 if (zonegroup_id
.empty()) {
2690 zonegroup_id
= store
->get_zonegroup().get_id();
2693 zonegroup_id
= store
->get_zonegroup().get_id();
2696 if (s
->bucket_exists
) {
2697 string selected_placement_rule
;
2699 bucket
.tenant
= s
->bucket_tenant
;
2700 bucket
.name
= s
->bucket_name
;
2701 op_ret
= store
->select_bucket_placement(*(s
->user
), zonegroup_id
,
2703 &selected_placement_rule
, nullptr);
2704 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
2710 /* Encode special metadata first as we're using std::map::emplace under
2711 * the hood. This method will add the new items only if the map doesn't
2712 * contain such keys yet. */
2713 policy
.encode(aclbl
);
2714 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
2717 cors_config
.encode(corsbl
);
2718 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
2721 RGWQuotaInfo quota_info
;
2722 const RGWQuotaInfo
* pquota_info
= nullptr;
2723 if (need_metadata_upload()) {
2724 /* It's supposed that following functions WILL NOT change any special
2725 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
2726 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2730 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2731 populate_with_generic_attrs(s
, attrs
);
2733 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
2737 pquota_info
= "a_info
;
2740 /* Web site of Swift API. */
2741 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2742 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2745 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
2746 s
->bucket
.name
= s
->bucket_name
;
2748 /* Handle updates of the metadata for Swift's object versioning. */
2749 if (swift_ver_location
) {
2750 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2751 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2754 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
2755 placement_rule
, s
->bucket_info
.swift_ver_location
,
2757 info
, pobjv
, &ep_objv
, creation_time
,
2758 pmaster_bucket
, pmaster_num_shards
, true);
2759 /* continue if EEXIST and create_bucket will fail below. this way we can
2760 * recover from a partial create by retrying it. */
2761 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
2763 if (op_ret
&& op_ret
!= -EEXIST
)
2766 existed
= (op_ret
== -EEXIST
);
2769 /* bucket already existed, might have raced with another bucket creation, or
2770 * might be partial bucket creation that never completed. Read existing bucket
2771 * info, verify that the reported bucket owner is the current user.
2772 * If all is ok then update the user's list of buckets.
2773 * Otherwise inform client about a name conflict.
2775 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
2779 s
->bucket
= info
.bucket
;
2782 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
2783 info
.creation_time
, false);
2784 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
2785 /* if it exists (or previously existed), don't remove it! */
2786 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2789 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2792 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
2793 op_ret
= -ERR_BUCKET_EXISTS
;
2796 if (need_metadata_upload() && existed
) {
2797 /* OK, it looks we lost race with another request. As it's required to
2798 * handle metadata fusion and upload, the whole operation becomes very
2799 * similar in nature to PutMetadataBucket. However, as the attrs may
2800 * changed in the meantime, we have to refresh. */
2803 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2804 RGWBucketInfo binfo
;
2805 map
<string
, bufferlist
> battrs
;
2807 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2808 binfo
, nullptr, &battrs
);
2811 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
2812 /* New bucket doesn't belong to the account we're operating on. */
2816 s
->bucket_info
= binfo
;
2817 s
->bucket_attrs
= battrs
;
2822 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2826 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2827 populate_with_generic_attrs(s
, attrs
);
2828 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
2833 /* Handle updates of the metadata for Swift's object versioning. */
2834 if (swift_ver_location
) {
2835 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2836 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2839 /* Web site of Swift API. */
2840 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2841 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2843 /* This will also set the quota on the bucket. */
2844 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
2845 &s
->bucket_info
.objv_tracker
);
2846 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
2848 /* Restore the proper return code. */
2850 op_ret
= -ERR_BUCKET_EXISTS
;
2855 int RGWDeleteBucket::verify_permission()
2857 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucket
)) {
2864 void RGWDeleteBucket::pre_exec()
2866 rgw_bucket_object_pre_exec(s
);
2869 void RGWDeleteBucket::execute()
2873 if (s
->bucket_name
.empty())
2876 if (!s
->bucket_exists
) {
2877 ldout(s
->cct
, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
2878 op_ret
= -ERR_NO_SUCH_BUCKET
;
2881 RGWObjVersionTracker ot
;
2882 ot
.read_version
= s
->bucket_info
.ep_objv
;
2884 if (s
->system_request
) {
2885 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
2886 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
2888 ot
.read_version
.tag
= tag
;
2891 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
2893 ldout(s
->cct
, 0) << "failed to parse ver param" << dendl
;
2897 ot
.read_version
.ver
= ver
;
2901 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
2903 ldout(s
->cct
, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
2906 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
2911 if (!store
->is_meta_master()) {
2913 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
2916 if (op_ret
== -ENOENT
) {
2917 /* adjust error, we want to return with NoSuchBucket and not
2919 op_ret
= -ERR_NO_SUCH_BUCKET
;
2925 string prefix
, delimiter
;
2927 if (s
->prot_flags
& RGW_REST_SWIFT
) {
2929 path_args
= s
->info
.args
.get("path");
2930 if (!path_args
.empty()) {
2931 if (!delimiter
.empty() || !prefix
.empty()) {
2940 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
2946 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
2948 if (op_ret
== -ECANCELED
) {
2949 // lost a race, either with mdlog sync or another delete bucket operation.
2950 // in either case, we've already called rgw_unlink_bucket()
2956 op_ret
= rgw_unlink_bucket(store
, s
->bucket_info
.owner
, s
->bucket
.tenant
,
2957 s
->bucket
.name
, false);
2959 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2971 int RGWPutObj::verify_permission()
2973 if (! copy_source
.empty()) {
2975 RGWAccessControlPolicy
cs_acl(s
->cct
);
2976 optional
<Policy
> policy
;
2977 map
<string
, bufferlist
> cs_attrs
;
2978 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
2979 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
2981 rgw_obj
obj(cs_bucket
, cs_object
);
2982 store
->set_atomic(s
->obj_ctx
, obj
);
2983 store
->set_prefetch_data(s
->obj_ctx
, obj
);
2985 /* check source object permissions */
2986 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
,
2987 policy
, cs_bucket
, cs_object
) < 0) {
2991 /* admin request overrides permission checks */
2992 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
2994 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
2995 cs_object
.instance
.empty() ?
2996 rgw::IAM::s3GetObject
:
2997 rgw::IAM::s3GetObjectVersion
,
2998 rgw::IAM::ARN(obj
));
2999 if (e
== Effect::Deny
) {
3001 } else if (e
== Effect::Pass
&&
3002 !cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
3006 } else if (!cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
3013 if (s
->iam_policy
) {
3014 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3015 rgw::IAM::s3PutObject
,
3016 rgw_obj(s
->bucket
, s
->object
));
3017 if (e
== Effect::Allow
) {
3019 } else if (e
== Effect::Deny
) {
3024 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3031 void RGWPutObjProcessor_Multipart::get_mp(RGWMPObj
** _mp
){
3035 int RGWPutObjProcessor_Multipart::prepare(RGWRados
*store
, string
*oid_rand
)
3037 string oid
= obj_str
;
3038 upload_id
= s
->info
.args
.get("uploadId");
3040 mp
.init(oid
, upload_id
);
3042 mp
.init(oid
, upload_id
, *oid_rand
);
3045 part_num
= s
->info
.args
.get("partNumber");
3046 if (part_num
.empty()) {
3047 ldout(s
->cct
, 10) << "part number is empty" << dendl
;
3052 uint64_t num
= (uint64_t)strict_strtol(part_num
.c_str(), 10, &err
);
3055 ldout(s
->cct
, 10) << "bad part number: " << part_num
<< ": " << err
<< dendl
;
3059 string upload_prefix
= oid
+ ".";
3062 upload_prefix
.append(upload_id
);
3064 upload_prefix
.append(*oid_rand
);
3068 target_obj
.init(bucket
, oid
);
3070 manifest
.set_prefix(upload_prefix
);
3072 manifest
.set_multipart_part_rule(store
->ctx()->_conf
->rgw_obj_stripe_size
, num
);
3074 int r
= manifest_gen
.create_begin(store
->ctx(), &manifest
, s
->bucket_info
.placement_rule
, bucket
, target_obj
);
3079 cur_obj
= manifest_gen
.get_cur_obj(store
);
3080 rgw_raw_obj_to_obj(bucket
, cur_obj
, &head_obj
);
3081 head_obj
.index_hash_source
= obj_str
;
3083 r
= prepare_init(store
, NULL
);
3091 int RGWPutObjProcessor_Multipart::do_complete(size_t accounted_size
,
3093 real_time
*mtime
, real_time set_mtime
,
3094 map
<string
, bufferlist
>& attrs
,
3095 real_time delete_at
,
3096 const char *if_match
,
3097 const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
)
3099 complete_writing_data();
3101 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, head_obj
);
3102 op_target
.set_versioning_disabled(true);
3103 RGWRados::Object::Write
head_obj_op(&op_target
);
3105 head_obj_op
.meta
.set_mtime
= set_mtime
;
3106 head_obj_op
.meta
.mtime
= mtime
;
3107 head_obj_op
.meta
.owner
= s
->owner
.get_id();
3108 head_obj_op
.meta
.delete_at
= delete_at
;
3109 head_obj_op
.meta
.zones_trace
= zones_trace
;
3110 head_obj_op
.meta
.modify_tail
= true;
3112 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3117 RGWUploadPartInfo info
;
3119 bool sorted_omap
= is_v2_upload_id(upload_id
);
3123 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3125 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3129 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3134 info
.num
= atoi(part_num
.c_str());
3136 info
.size
= obj_len
;
3137 info
.accounted_size
= accounted_size
;
3138 info
.modified
= real_clock::now();
3139 info
.manifest
= manifest
;
3142 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3144 dout(1) << "cannot get compression info" << dendl
;
3150 string multipart_meta_obj
= mp
.get_meta();
3153 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3154 meta_obj
.set_in_extra_data(true);
3156 rgw_raw_obj raw_meta_obj
;
3158 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3160 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3165 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3167 RGWPutObjProcessor
*processor
;
3169 bool multipart
= s
->info
.args
.exists("uploadId");
3171 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3174 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3175 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3176 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3178 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3182 *is_multipart
= multipart
;
3188 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3193 void RGWPutObj::pre_exec()
3195 rgw_bucket_object_pre_exec(s
);
3198 class RGWPutObj_CB
: public RGWGetDataCB
3202 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3203 ~RGWPutObj_CB() override
{}
3205 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3206 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3210 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3213 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3215 bl_aux
.append(bl_tmp
);
3220 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3222 RGWPutObj_CB
cb(this);
3223 RGWGetDataCB
* filter
= &cb
;
3224 boost::optional
<RGWGetObj_Decompress
> decompress
;
3225 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3226 RGWCompressionInfo cs_info
;
3227 map
<string
, bufferlist
> attrs
;
3228 map
<string
, bufferlist
>::iterator attr_iter
;
3232 int64_t new_ofs
, new_end
;
3237 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3238 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3240 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3241 RGWRados::Object::Read
read_op(&op_target
);
3242 read_op
.params
.obj_size
= &obj_size
;
3243 read_op
.params
.attrs
= &attrs
;
3245 ret
= read_op
.prepare();
3249 bool need_decompress
;
3250 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3252 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3256 bool partial_content
= true;
3257 if (need_decompress
)
3259 obj_size
= cs_info
.orig_size
;
3260 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3261 filter
= &*decompress
;
3264 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3265 op_ret
= this->get_decrypt_filter(&decrypt
,
3268 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3269 if (decrypt
!= nullptr) {
3270 filter
= decrypt
.get();
3276 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3280 filter
->fixup_range(new_ofs
, new_end
);
3281 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3284 ret
= filter
->flush();
3286 bl
.claim_append(bl_aux
);
3291 // special handling for compression type = "random" with multipart uploads
3292 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3293 const std::string
& compression_type
)
3295 if (compression_type
!= "random") {
3296 return Compressor::create(s
->cct
, compression_type
);
3299 bool is_multipart
{false};
3300 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3302 if (!is_multipart
) {
3303 return Compressor::create(s
->cct
, compression_type
);
3306 // use a hash of the multipart upload id so all parts use the same plugin
3307 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3308 if (alg
== Compressor::COMP_ALG_NONE
) {
3311 return Compressor::create(s
->cct
, alg
);
3314 void RGWPutObj::execute()
3316 RGWPutObjProcessor
*processor
= NULL
;
3317 RGWPutObjDataProcessor
*filter
= nullptr;
3318 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3319 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3320 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3321 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3322 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3324 bufferlist bl
, aclbl
, bs
;
3326 map
<string
, string
>::iterator iter
;
3331 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3332 s
->bucket_info
.placement_rule
);
3333 CompressorRef plugin
;
3334 boost::optional
<RGWPutObj_Compress
> compressor
;
3336 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3337 perfcounter
->inc(l_rgw_put
);
3339 if (s
->object
.empty()) {
3343 if (!s
->bucket_exists
) {
3344 op_ret
= -ERR_NO_SUCH_BUCKET
;
3348 op_ret
= get_params();
3350 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3354 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3356 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3361 if (supplied_md5_b64
) {
3362 need_calc_md5
= true;
3364 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3365 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3366 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3367 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3368 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3369 op_ret
= -ERR_INVALID_DIGEST
;
3373 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3374 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3377 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3378 we also check sizes at the end anyway */
3379 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3380 user_quota
, bucket_quota
, s
->content_length
);
3382 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3385 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3387 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3392 if (supplied_etag
) {
3393 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3394 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3397 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3399 // no filters by default
3402 /* Handle object versioning of Swift API. */
3404 rgw_obj
obj(s
->bucket
, s
->object
);
3405 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3406 s
->bucket_owner
.get_id(),
3414 op_ret
= processor
->prepare(store
, NULL
);
3416 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3421 if ((! copy_source
.empty()) && !copy_source_range
) {
3422 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3423 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
.name
);
3425 RGWObjState
*astate
;
3426 op_ret
= store
->get_obj_state(static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3427 copy_source_bucket_info
, obj
, &astate
, true, false);
3429 ldout(s
->cct
, 0) << "ERROR: get copy source obj state returned with error" << op_ret
<< dendl
;
3432 if (!astate
->exists
){
3436 lst
= astate
->accounted_size
- 1;
3438 lst
= copy_source_range_lst
;
3441 fst
= copy_source_range_fst
;
3443 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3447 if (encrypt
!= nullptr) {
3448 filter
= encrypt
.get();
3450 //no encryption, we can try compression
3451 if (compression_type
!= "none") {
3452 plugin
= get_compressor_plugin(s
, compression_type
);
3454 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3455 << compression_type
<< dendl
;
3457 compressor
.emplace(s
->cct
, plugin
, filter
);
3458 filter
= &*compressor
;
3467 if (copy_source
.empty()) {
3468 len
= get_data(data
);
3470 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3471 op_ret
= get_data(fst
, cur_lst
, data
);
3474 len
= data
.length();
3475 s
->content_length
+= len
;
3483 if (need_calc_md5
) {
3484 hash
.Update((const byte
*)data
.c_str(), data
.length());
3487 /* update torrrent */
3488 torrent
.update(data
);
3490 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3491 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3493 bool need_to_wait
= (ofs
== 0) && multipart
;
3495 bufferlist orig_data
;
3501 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3503 if (!need_to_wait
|| op_ret
!= -EEXIST
) {
3504 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3508 /* need_to_wait == true and op_ret == -EEXIST */
3509 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3511 /* restore original data */
3512 data
.swap(orig_data
);
3514 /* restart processing with different oid suffix */
3516 dispose_processor(processor
);
3517 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3522 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3523 oid_rand
.append(buf
);
3525 op_ret
= processor
->prepare(store
, &oid_rand
);
3527 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3532 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3536 if (encrypt
!= nullptr) {
3537 filter
= encrypt
.get();
3540 compressor
.emplace(s
->cct
, plugin
, filter
);
3541 filter
= &*compressor
;
3544 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3555 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3561 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3562 op_ret
= -ERR_REQUEST_TIMEOUT
;
3567 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3569 op_ret
= do_aws4_auth_completion();
3574 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3575 user_quota
, bucket_quota
, s
->obj_size
);
3577 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3581 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3583 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3589 if (compressor
&& compressor
->is_compressed()) {
3591 RGWCompressionInfo cs_info
;
3592 cs_info
.compression_type
= plugin
->get_type_name();
3593 cs_info
.orig_size
= s
->obj_size
;
3594 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3595 ::encode(cs_info
, tmp
);
3596 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3597 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3598 << " with type=" << cs_info
.compression_type
3599 << ", orig_size=" << cs_info
.orig_size
3600 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3603 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3607 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3608 op_ret
= -ERR_BAD_DIGEST
;
3612 policy
.encode(aclbl
);
3613 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3616 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3618 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3621 complete_etag(hash
, &etag
);
3622 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3626 bufferlist manifest_bl
;
3627 ::encode(*slo_info
, manifest_bl
);
3628 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3630 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3631 complete_etag(hash
, &etag
);
3632 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3635 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3636 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3639 bl
.append(etag
.c_str(), etag
.size() + 1);
3640 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3642 populate_with_generic_attrs(s
, attrs
);
3643 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3647 encode_delete_at_attr(delete_at
, attrs
);
3648 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3650 /* Add a custom metadata to expose the information whether an object
3651 * is an SLO or not. Appending the attribute must be performed AFTER
3652 * processing any input from user in order to prohibit overwriting. */
3654 bufferlist slo_userindicator_bl
;
3655 slo_userindicator_bl
.append("True", 4);
3656 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3659 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3660 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3661 (user_data
.empty() ? nullptr : &user_data
));
3663 /* produce torrent */
3664 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3666 torrent
.init(s
, store
);
3667 torrent
.set_create_date(mtime
);
3668 op_ret
= torrent
.complete();
3671 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3677 dispose_processor(processor
);
3678 perfcounter
->tinc(l_rgw_put_lat
,
3679 (ceph_clock_now() - s
->time
));
3682 int RGWPostObj::verify_permission()
3687 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3689 RGWPutObjProcessor *processor;
3691 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3693 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3698 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3703 void RGWPostObj::pre_exec()
3705 rgw_bucket_object_pre_exec(s
);
3708 void RGWPostObj::execute()
3710 RGWPutObjDataProcessor
*filter
= nullptr;
3711 boost::optional
<RGWPutObj_Compress
> compressor
;
3712 CompressorRef plugin
;
3713 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3715 /* Read in the data from the POST form. */
3716 op_ret
= get_params();
3721 op_ret
= verify_params();
3726 if (s
->iam_policy
) {
3727 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3728 rgw::IAM::s3PutObject
,
3729 rgw_obj(s
->bucket
, s
->object
));
3730 if (e
== Effect::Deny
) {
3733 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3737 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3742 /* Start iteration over data fields. It's necessary as Swift's FormPost
3743 * is capable to handle multiple files in single form. */
3745 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3746 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3747 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3749 ceph::buffer::list bl
, aclbl
;
3752 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3761 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3766 if (supplied_md5_b64
) {
3767 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3768 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3769 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3770 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3771 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3772 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3773 op_ret
= -ERR_INVALID_DIGEST
;
3777 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3778 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3781 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3784 get_current_filename(),
3786 s
->cct
->_conf
->rgw_obj_stripe_size
,
3788 s
->bucket_info
.versioning_enabled());
3789 /* No filters by default. */
3790 filter
= &processor
;
3792 op_ret
= processor
.prepare(store
, nullptr);
3797 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3801 if (encrypt
!= nullptr) {
3802 filter
= encrypt
.get();
3804 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3805 s
->bucket_info
.placement_rule
);
3806 if (compression_type
!= "none") {
3807 plugin
= Compressor::create(s
->cct
, compression_type
);
3809 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3810 << compression_type
<< dendl
;
3812 compressor
.emplace(s
->cct
, plugin
, filter
);
3813 filter
= &*compressor
;
3820 ceph::bufferlist data
;
3821 len
= get_data(data
, again
);
3832 hash
.Update((const byte
*)data
.c_str(), data
.length());
3833 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3837 if (ofs
> max_len
) {
3838 op_ret
= -ERR_TOO_LARGE
;
3845 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3848 if (len
< min_len
) {
3849 op_ret
= -ERR_TOO_SMALL
;
3855 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3856 op_ret
= -ERR_BAD_DIGEST
;
3860 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3861 user_quota
, bucket_quota
, s
->obj_size
);
3866 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3872 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3875 bl
.append(etag
.c_str(), etag
.size() + 1);
3876 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3878 policy
.encode(aclbl
);
3879 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3881 const std::string content_type
= get_current_content_type();
3882 if (! content_type
.empty()) {
3883 ceph::bufferlist ct_bl
;
3884 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3885 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3888 if (compressor
&& compressor
->is_compressed()) {
3889 ceph::bufferlist tmp
;
3890 RGWCompressionInfo cs_info
;
3891 cs_info
.compression_type
= plugin
->get_type_name();
3892 cs_info
.orig_size
= s
->obj_size
;
3893 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3894 ::encode(cs_info
, tmp
);
3895 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3898 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3899 attrs
, (delete_at
? *delete_at
: real_time()));
3900 } while (is_next_file_to_upload());
3904 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3905 const set
<string
>& rmattr_names
,
3906 map
<int, string
>& temp_url_keys
)
3908 map
<string
, bufferlist
>::iterator iter
;
3910 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3911 if (iter
!= add_attrs
.end()) {
3912 temp_url_keys
[0] = iter
->second
.c_str();
3913 add_attrs
.erase(iter
);
3916 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3917 if (iter
!= add_attrs
.end()) {
3918 temp_url_keys
[1] = iter
->second
.c_str();
3919 add_attrs
.erase(iter
);
3922 for (const string
& name
: rmattr_names
) {
3923 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3924 temp_url_keys
[0] = string();
3926 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3927 temp_url_keys
[1] = string();
3932 int RGWPutMetadataAccount::init_processing()
3934 /* First, go to the base class. At the time of writing the method was
3935 * responsible only for initializing the quota. This isn't necessary
3936 * here as we are touching metadata only. I'm putting this call only
3937 * for the future. */
3938 op_ret
= RGWOp::init_processing();
3943 op_ret
= get_params();
3948 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3956 policy
.encode(acl_bl
);
3957 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3960 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3964 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3965 populate_with_generic_attrs(s
, attrs
);
3967 /* Try extract the TempURL-related stuff now to allow verify_permission
3968 * evaluate whether we need FULL_CONTROL or not. */
3969 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3971 /* The same with quota except a client needs to be reseller admin. */
3972 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3973 &new_quota_extracted
);
3981 int RGWPutMetadataAccount::verify_permission()
3983 if (s
->auth
.identity
->is_anonymous()) {
3987 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
3991 /* Altering TempURL keys requires FULL_CONTROL. */
3992 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
3996 /* We are failing this intensionally to allow system user/reseller admin
3997 * override in rgw_process.cc. This is the way to specify a given RGWOp
3998 * expect extra privileges. */
3999 if (new_quota_extracted
) {
4006 void RGWPutMetadataAccount::execute()
4008 /* Params have been extracted earlier. See init_processing(). */
4009 RGWUserInfo new_uinfo
;
4010 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
4016 /* Handle the TempURL-related stuff. */
4017 if (!temp_url_keys
.empty()) {
4018 for (auto& pair
: temp_url_keys
) {
4019 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
4023 /* Handle the quota extracted at the verify_permission step. */
4024 if (new_quota_extracted
) {
4025 new_uinfo
.user_quota
= std::move(new_quota
);
4028 /* We are passing here the current (old) user info to allow the function
4029 * optimize-out some operations. */
4030 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
4031 &acct_op_tracker
, real_time(), false, &attrs
);
4034 int RGWPutMetadataBucket::verify_permission()
4036 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4043 void RGWPutMetadataBucket::pre_exec()
4045 rgw_bucket_object_pre_exec(s
);
4048 void RGWPutMetadataBucket::execute()
4050 op_ret
= get_params();
4055 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
4060 if (!placement_rule
.empty() &&
4061 placement_rule
!= s
->bucket_info
.placement_rule
) {
4066 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
4067 /* Encode special metadata first as we're using std::map::emplace under
4068 * the hood. This method will add the new items only if the map doesn't
4069 * contain such keys yet. */
4071 if (s
->dialect
.compare("swift") == 0) {
4073 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
4074 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
4075 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
4076 policy
= *new_policy
;
4080 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
4085 cors_config
.encode(bl
);
4086 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
4089 /* It's supposed that following functions WILL NOT change any
4090 * special attributes (like RGW_ATTR_ACL) if they are already
4091 * present in attrs. */
4092 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
4093 populate_with_generic_attrs(s
, attrs
);
4095 /* According to the Swift's behaviour and its container_quota
4096 * WSGI middleware implementation: anyone with write permissions
4097 * is able to set the bucket quota. This stays in contrast to
4098 * account quotas that can be set only by clients holding
4099 * reseller admin privileges. */
4100 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
4105 if (swift_ver_location
) {
4106 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
4107 s
->bucket_info
.swift_versioning
= (!swift_ver_location
->empty());
4110 /* Web site of Swift API. */
4111 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
4112 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
4114 /* Setting attributes also stores the provided bucket info. Due
4115 * to this fact, the new quota settings can be serialized with
4117 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
4118 &s
->bucket_info
.objv_tracker
);
4123 int RGWPutMetadataObject::verify_permission()
4125 // This looks to be something specific to Swift. We could add
4126 // operations like swift:PutMetadataObject to the Policy Engine.
4127 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4134 void RGWPutMetadataObject::pre_exec()
4136 rgw_bucket_object_pre_exec(s
);
4139 void RGWPutMetadataObject::execute()
4141 rgw_obj
obj(s
->bucket
, s
->object
);
4142 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4144 store
->set_atomic(s
->obj_ctx
, obj
);
4146 op_ret
= get_params();
4151 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4156 /* check if obj exists, read orig attrs */
4157 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4162 /* Check whether the object has expired. Swift API documentation
4163 * stands that we should return 404 Not Found in such case. */
4164 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4169 /* Filter currently existing attributes. */
4170 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4171 populate_with_generic_attrs(s
, attrs
);
4172 encode_delete_at_attr(delete_at
, attrs
);
4175 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4177 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4182 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4185 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4187 RGWSLOInfo slo_info
;
4188 bufferlist::iterator bliter
= bl
.begin();
4190 ::decode(slo_info
, bliter
);
4191 } catch (buffer::error
& err
) {
4192 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4197 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4198 new RGWBulkDelete::Deleter(store
, s
));
4199 } catch (std::bad_alloc
) {
4203 list
<RGWBulkDelete::acct_path_t
> items
;
4204 for (const auto& iter
: slo_info
.entries
) {
4205 const string
& path_str
= iter
.path
;
4207 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4208 if (boost::string_view::npos
== sep_pos
) {
4212 RGWBulkDelete::acct_path_t path
;
4214 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4215 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4217 items
.push_back(path
);
4220 /* Request removal of the manifest object itself. */
4221 RGWBulkDelete::acct_path_t path
;
4222 path
.bucket_name
= s
->bucket_name
;
4223 path
.obj_key
= s
->object
;
4224 items
.push_back(path
);
4226 int ret
= deleter
->delete_chunk(items
);
4234 int RGWDeleteObj::verify_permission()
4236 if (s
->iam_policy
) {
4237 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4238 s
->object
.instance
.empty() ?
4239 rgw::IAM::s3DeleteObject
:
4240 rgw::IAM::s3DeleteObjectVersion
,
4241 ARN(s
->bucket
, s
->object
.name
));
4242 if (r
== Effect::Allow
)
4244 else if (r
== Effect::Deny
)
4248 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4255 void RGWDeleteObj::pre_exec()
4257 rgw_bucket_object_pre_exec(s
);
4260 void RGWDeleteObj::execute()
4262 if (!s
->bucket_exists
) {
4263 op_ret
= -ERR_NO_SUCH_BUCKET
;
4267 op_ret
= get_params();
4272 rgw_obj
obj(s
->bucket
, s
->object
);
4273 map
<string
, bufferlist
> attrs
;
4276 if (!s
->object
.empty()) {
4277 if (need_object_expiration() || multipart_delete
) {
4278 /* check if obj exists, read orig attrs */
4279 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4285 if (multipart_delete
) {
4286 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4288 if (slo_attr
!= attrs
.end()) {
4289 op_ret
= handle_slo_manifest(slo_attr
->second
);
4291 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4294 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4300 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4301 obj_ctx
->obj
.set_atomic(obj
);
4303 bool ver_restored
= false;
4304 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4305 s
->bucket_info
, obj
, ver_restored
);
4310 if (!ver_restored
) {
4311 /* Swift's versioning mechanism hasn't found any previous version of
4312 * the object that could be restored. This means we should proceed
4313 * with the regular delete path. */
4314 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4315 RGWRados::Object::Delete
del_op(&del_target
);
4317 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4318 &del_op
.params
.marker_version_id
);
4323 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4324 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4325 del_op
.params
.obj_owner
= s
->owner
;
4326 del_op
.params
.unmod_since
= unmod_since
;
4327 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4329 op_ret
= del_op
.delete_obj();
4331 delete_marker
= del_op
.result
.delete_marker
;
4332 version_id
= del_op
.result
.version_id
;
4335 /* Check whether the object has expired. Swift API documentation
4336 * stands that we should return 404 Not Found in such case. */
4337 if (need_object_expiration() && object_is_expired(attrs
)) {
4343 if (op_ret
== -ECANCELED
) {
4346 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4354 bool RGWCopyObj::parse_copy_location(const boost::string_view
& url_src
,
4355 string
& bucket_name
,
4358 boost::string_view name_str
;
4359 boost::string_view params_str
;
4361 size_t pos
= url_src
.find('?');
4362 if (pos
== string::npos
) {
4365 name_str
= url_src
.substr(0, pos
);
4366 params_str
= url_src
.substr(pos
+ 1);
4369 boost::string_view dec_src
{name_str
};
4370 if (dec_src
[0] == '/')
4371 dec_src
.remove_prefix(1);
4373 pos
= dec_src
.find('/');
4374 if (pos
==string::npos
)
4377 boost::string_view bn_view
{dec_src
.substr(0, pos
)};
4378 bucket_name
= std::string
{bn_view
.data(), bn_view
.size()};
4380 boost::string_view kn_view
{dec_src
.substr(pos
+ 1)};
4381 key
.name
= std::string
{kn_view
.data(), kn_view
.size()};
4383 if (key
.name
.empty()) {
4387 if (! params_str
.empty()) {
4389 args
.set(params_str
.to_string());
4392 key
.instance
= args
.get("versionId", NULL
);
4398 int RGWCopyObj::verify_permission()
4400 RGWAccessControlPolicy
src_acl(s
->cct
);
4401 optional
<Policy
> src_policy
;
4402 op_ret
= get_params();
4406 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4410 map
<string
, bufferlist
> src_attrs
;
4412 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4414 if (s
->bucket_instance_id
.empty()) {
4415 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4417 /* will only happen in intra region sync where the source and dest bucket is the same */
4418 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4421 if (op_ret
== -ENOENT
) {
4422 op_ret
= -ERR_NO_SUCH_BUCKET
;
4427 src_bucket
= src_bucket_info
.bucket
;
4429 /* get buckets info (source and dest) */
4430 if (s
->local_source
&& source_zone
.empty()) {
4431 rgw_obj
src_obj(src_bucket
, src_object
);
4432 store
->set_atomic(s
->obj_ctx
, src_obj
);
4433 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4435 /* check source object permissions */
4436 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4437 src_policy
, src_bucket
, src_object
);
4442 /* admin request overrides permission checks */
4443 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4445 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4446 src_object
.instance
.empty() ?
4447 rgw::IAM::s3GetObject
:
4448 rgw::IAM::s3GetObjectVersion
,
4450 if (e
== Effect::Deny
) {
4452 } else if (e
== Effect::Pass
&&
4453 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4457 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4465 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4466 map
<string
, bufferlist
> dest_attrs
;
4468 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4469 or intra region sync */
4470 dest_bucket_info
= src_bucket_info
;
4471 dest_attrs
= src_attrs
;
4473 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4474 dest_bucket_info
, nullptr, &dest_attrs
);
4476 if (op_ret
== -ENOENT
) {
4477 op_ret
= -ERR_NO_SUCH_BUCKET
;
4483 dest_bucket
= dest_bucket_info
.bucket
;
4485 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4486 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4488 /* check dest bucket permissions */
4489 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4490 &dest_bucket_policy
, dest_bucket
);
4495 /* admin request overrides permission checks */
4496 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4497 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4502 op_ret
= init_dest_policy();
4511 int RGWCopyObj::init_common()
4514 if (parse_time(if_mod
, &mod_time
) < 0) {
4518 mod_ptr
= &mod_time
;
4522 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4526 unmod_ptr
= &unmod_time
;
4530 dest_policy
.encode(aclbl
);
4531 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4533 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4537 populate_with_generic_attrs(s
, attrs
);
4542 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4544 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4545 op
->progress_cb(ofs
);
4548 void RGWCopyObj::progress_cb(off_t ofs
)
4550 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4553 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4556 send_partial_response(ofs
);
4561 void RGWCopyObj::pre_exec()
4563 rgw_bucket_object_pre_exec(s
);
4566 void RGWCopyObj::execute()
4568 if (init_common() < 0)
4571 rgw_obj
src_obj(src_bucket
, src_object
);
4572 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4574 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4575 obj_ctx
.obj
.set_atomic(src_obj
);
4576 obj_ctx
.obj
.set_atomic(dst_obj
);
4578 encode_delete_at_attr(delete_at
, attrs
);
4580 bool high_precision_time
= (s
->system_request
);
4582 /* Handle object versioning of Swift API. In case of copying to remote this
4583 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4584 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4585 dest_bucket_info
.owner
,
4592 op_ret
= store
->copy_obj(obj_ctx
,
4606 high_precision_time
,
4611 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4613 (delete_at
? *delete_at
: real_time()),
4614 (version_id
.empty() ? NULL
: &version_id
),
4615 &s
->req_id
, /* use req_id as tag */
4617 copy_obj_progress_cb
, (void *)this
4621 int RGWGetACLs::verify_permission()
4624 if (!s
->object
.empty()) {
4625 perm
= verify_object_permission(s
,
4626 s
->object
.instance
.empty() ?
4627 rgw::IAM::s3GetObjectAcl
:
4628 rgw::IAM::s3GetObjectVersionAcl
);
4630 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetBucketAcl
);
4638 void RGWGetACLs::pre_exec()
4640 rgw_bucket_object_pre_exec(s
);
4643 void RGWGetACLs::execute()
4646 RGWAccessControlPolicy
* const acl
= \
4647 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4648 RGWAccessControlPolicy_S3
* const s3policy
= \
4649 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4650 s3policy
->to_xml(ss
);
4656 int RGWPutACLs::verify_permission()
4659 if (!s
->object
.empty()) {
4660 perm
= verify_object_permission(s
,
4661 s
->object
.instance
.empty() ?
4662 rgw::IAM::s3PutObjectAcl
:
4663 rgw::IAM::s3PutObjectVersionAcl
);
4665 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4673 int RGWGetLC::verify_permission()
4676 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4683 int RGWPutLC::verify_permission()
4686 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4693 int RGWDeleteLC::verify_permission()
4696 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4703 void RGWPutACLs::pre_exec()
4705 rgw_bucket_object_pre_exec(s
);
4708 void RGWGetLC::pre_exec()
4710 rgw_bucket_object_pre_exec(s
);
4713 void RGWPutLC::pre_exec()
4715 rgw_bucket_object_pre_exec(s
);
4718 void RGWDeleteLC::pre_exec()
4720 rgw_bucket_object_pre_exec(s
);
4723 void RGWPutACLs::execute()
4727 RGWAccessControlPolicy_S3
*policy
= NULL
;
4728 RGWACLXMLParser_S3
parser(s
->cct
);
4729 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4731 char *new_data
= NULL
;
4734 op_ret
= 0; /* XXX redundant? */
4736 if (!parser
.init()) {
4742 RGWAccessControlPolicy
* const existing_policy
= \
4743 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
4745 owner
= existing_policy
->get_owner();
4747 op_ret
= get_params();
4749 if (op_ret
== -ERANGE
) {
4750 ldout(s
->cct
, 4) << "The size of request xml data is larger than the max limitation, data size = "
4751 << s
->length
<< dendl
;
4752 op_ret
= -ERR_MALFORMED_XML
;
4753 s
->err
.message
= "The XML you provided was larger than the maximum " +
4754 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
4760 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4762 if (!s
->canned_acl
.empty() && len
) {
4767 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4768 op_ret
= get_policy_from_state(store
, s
, ss
);
4772 new_data
= strdup(ss
.str().c_str());
4775 len
= ss
.str().size();
4778 if (!parser
.parse(data
, len
, 1)) {
4782 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4788 const RGWAccessControlList
& req_acl
= policy
->get_acl();
4789 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
4790 #define ACL_GRANTS_MAX_NUM 100
4791 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
4793 max_num
= ACL_GRANTS_MAX_NUM
;
4796 int grants_num
= req_grant_map
.size();
4797 if (grants_num
> max_num
) {
4798 ldout(s
->cct
, 4) << "An acl can have up to "
4800 << " grants, request acl grants num: "
4801 << grants_num
<< dendl
;
4802 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
4803 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
4804 + std::to_string(max_num
)
4805 + " grants allowed in an acl.";
4809 // forward bucket acl requests to meta master zone
4810 if (s
->object
.empty() && !store
->is_meta_master()) {
4812 // include acl data unless it was generated from a canned_acl
4813 if (s
->canned_acl
.empty()) {
4814 in_data
.append(data
, len
);
4816 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4818 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4823 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4824 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4825 policy
->to_xml(*_dout
);
4829 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4833 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4834 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4835 new_policy
.to_xml(*_dout
);
4839 new_policy
.encode(bl
);
4840 map
<string
, bufferlist
> attrs
;
4842 if (!s
->object
.empty()) {
4843 obj
= rgw_obj(s
->bucket
, s
->object
);
4844 store
->set_atomic(s
->obj_ctx
, obj
);
4845 //if instance is empty, we should modify the latest object
4846 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4848 attrs
= s
->bucket_attrs
;
4849 attrs
[RGW_ATTR_ACL
] = bl
;
4850 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4852 if (op_ret
== -ECANCELED
) {
4853 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4857 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4859 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4860 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4861 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4862 oid
= lc_oid_prefix
;
4864 snprintf(buf
, 32, ".%d", index
);
4869 void RGWPutLC::execute()
4873 RGWLifecycleConfiguration_S3
*config
= NULL
;
4874 RGWLCXMLParser_S3
parser(s
->cct
);
4875 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4877 content_md5
= s
->info
.env
->get("HTTP_CONTENT_MD5");
4878 if (content_md5
== nullptr) {
4879 op_ret
= -ERR_INVALID_REQUEST
;
4880 s
->err
.message
= "Missing required header for this request: Content-MD5";
4881 ldout(s
->cct
, 5) << s
->err
.message
<< dendl
;
4885 std::string content_md5_bin
;
4887 content_md5_bin
= rgw::from_base64(boost::string_view(content_md5
));
4889 s
->err
.message
= "Request header Content-MD5 contains character "
4890 "that is not base64 encoded.";
4891 ldout(s
->cct
, 5) << s
->err
.message
<< dendl
;
4892 op_ret
= -ERR_BAD_DIGEST
;
4896 if (!parser
.init()) {
4901 op_ret
= get_params();
4905 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4908 unsigned char data_hash_res
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
4909 data_hash
.Update(reinterpret_cast<const byte
*>(data
), len
);
4910 data_hash
.Final(data_hash_res
);
4912 if (memcmp(data_hash_res
, content_md5_bin
.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE
) != 0) {
4913 op_ret
= -ERR_BAD_DIGEST
;
4914 s
->err
.message
= "The Content-MD5 you specified did not match what we received.";
4915 ldout(s
->cct
, 5) << s
->err
.message
4916 << " Specified content md5: " << content_md5
4917 << ", calculated content md5: " << data_hash_res
4922 if (!parser
.parse(data
, len
, 1)) {
4923 op_ret
= -ERR_MALFORMED_XML
;
4926 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4928 op_ret
= -ERR_MALFORMED_XML
;
4932 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4933 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4934 config
->to_xml(*_dout
);
4938 op_ret
= config
->rebuild(store
, new_config
);
4942 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4943 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4944 new_config
.to_xml(*_dout
);
4948 new_config
.encode(bl
);
4949 map
<string
, bufferlist
> attrs
;
4950 attrs
= s
->bucket_attrs
;
4951 attrs
[RGW_ATTR_LC
] = bl
;
4952 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4955 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4958 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4959 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4960 rados::cls::lock::Lock
l(lc_index_lock_name
);
4961 utime_t
time(max_lock_secs
, 0);
4962 l
.set_duration(time
);
4963 l
.set_cookie(cookie
);
4964 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4966 op_ret
= l
.lock_exclusive(ctx
, oid
);
4967 if (op_ret
== -EBUSY
) {
4968 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4973 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4976 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4978 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4986 void RGWDeleteLC::execute()
4989 map
<string
, bufferlist
> orig_attrs
, attrs
;
4990 map
<string
, bufferlist
>::iterator iter
;
4992 store
->get_bucket_instance_obj(s
->bucket
, obj
);
4993 store
->set_prefetch_data(s
->obj_ctx
, obj
);
4994 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
4998 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
4999 const string
& name
= iter
->first
;
5000 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
5001 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
5002 if (attrs
.find(name
) == attrs
.end()) {
5003 attrs
[name
] = iter
->second
;
5007 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5008 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
5009 pair
<string
, int> entry(shard_id
, lc_uninitial
);
5012 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
5013 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
5014 rados::cls::lock::Lock
l(lc_index_lock_name
);
5015 utime_t
time(max_lock_secs
, 0);
5016 l
.set_duration(time
);
5018 op_ret
= l
.lock_exclusive(ctx
, oid
);
5019 if (op_ret
== -EBUSY
) {
5020 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
5025 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
5028 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
5030 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
5038 int RGWGetCORS::verify_permission()
5040 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketCORS
);
5043 void RGWGetCORS::execute()
5045 op_ret
= read_bucket_cors();
5050 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5056 int RGWPutCORS::verify_permission()
5058 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5061 void RGWPutCORS::execute()
5065 op_ret
= get_params();
5069 if (!store
->is_meta_master()) {
5070 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
5072 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5077 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5078 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
5079 attrs
[RGW_ATTR_CORS
] = cors_bl
;
5080 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5084 int RGWDeleteCORS::verify_permission()
5086 // No separate delete permission
5087 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5090 void RGWDeleteCORS::execute()
5092 op_ret
= read_bucket_cors();
5098 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5102 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5104 store
->get_bucket_instance_obj(s
->bucket
, obj
);
5105 store
->set_prefetch_data(s
->obj_ctx
, obj
);
5106 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
5107 map
<string
, bufferlist
>::iterator iter
;
5109 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
5113 /* only remove meta attrs */
5114 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
5115 const string
& name
= iter
->first
;
5116 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
5117 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
5118 rmattrs
[name
] = iter
->second
;
5119 } else if (attrs
.find(name
) == attrs
.end()) {
5120 attrs
[name
] = iter
->second
;
5123 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
5124 &s
->bucket_info
.objv_tracker
);
5128 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
5129 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
5132 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
5133 rule
= cc
->host_name_rule(origin
);
5135 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
5139 if (!validate_cors_rule_method(rule
, req_meth
)) {
5143 if (!validate_cors_rule_header(rule
, req_hdrs
)) {
5150 void RGWOptionsCORS::execute()
5152 op_ret
= read_bucket_cors();
5156 origin
= s
->info
.env
->get("HTTP_ORIGIN");
5159 "Preflight request without mandatory Origin header"
5164 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
5167 "Preflight request without mandatory Access-control-request-method header"
5173 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5177 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5178 op_ret
= validate_cors_request(&bucket_cors
);
5180 origin
= req_meth
= NULL
;
5186 int RGWGetRequestPayment::verify_permission()
5188 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketRequestPayment
);
5191 void RGWGetRequestPayment::pre_exec()
5193 rgw_bucket_object_pre_exec(s
);
5196 void RGWGetRequestPayment::execute()
5198 requester_pays
= s
->bucket_info
.requester_pays
;
5201 int RGWSetRequestPayment::verify_permission()
5203 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketRequestPayment
);
5206 void RGWSetRequestPayment::pre_exec()
5208 rgw_bucket_object_pre_exec(s
);
5211 void RGWSetRequestPayment::execute()
5213 op_ret
= get_params();
5218 s
->bucket_info
.requester_pays
= requester_pays
;
5219 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5222 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5223 << " returned err=" << op_ret
<< dendl
;
5228 int RGWInitMultipart::verify_permission()
5230 if (s
->iam_policy
) {
5231 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5232 rgw::IAM::s3PutObject
,
5233 rgw_obj(s
->bucket
, s
->object
));
5234 if (e
== Effect::Allow
) {
5236 } else if (e
== Effect::Deny
) {
5241 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5248 void RGWInitMultipart::pre_exec()
5250 rgw_bucket_object_pre_exec(s
);
5253 void RGWInitMultipart::execute()
5256 map
<string
, bufferlist
> attrs
;
5259 if (get_params() < 0)
5262 if (s
->object
.empty())
5265 policy
.encode(aclbl
);
5266 attrs
[RGW_ATTR_ACL
] = aclbl
;
5268 populate_with_generic_attrs(s
, attrs
);
5270 /* select encryption mode */
5271 op_ret
= prepare_encryption(attrs
);
5275 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5282 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5283 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5284 upload_id
.append(buf
);
5286 string tmp_obj_name
;
5287 RGWMPObj
mp(s
->object
.name
, upload_id
);
5288 tmp_obj_name
= mp
.get_meta();
5290 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5291 // the meta object will be indexed with 0 size, we c
5292 obj
.set_in_extra_data(true);
5293 obj
.index_hash_source
= s
->object
.name
;
5295 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5296 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5298 RGWRados::Object::Write
obj_op(&op_target
);
5300 obj_op
.meta
.owner
= s
->owner
.get_id();
5301 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5302 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5304 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5305 } while (op_ret
== -EEXIST
);
5308 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5310 RGWAccessControlPolicy
*policy
,
5311 map
<string
, bufferlist
>& attrs
)
5313 map
<string
, bufferlist
>::iterator iter
;
5317 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5318 obj
.set_in_extra_data(true);
5320 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5322 if (op_ret
== -ENOENT
) {
5323 return -ERR_NO_SUCH_UPLOAD
;
5329 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5330 string name
= iter
->first
;
5331 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5332 bufferlist
& bl
= iter
->second
;
5333 bufferlist::iterator bli
= bl
.begin();
5335 ::decode(*policy
, bli
);
5336 } catch (buffer::error
& err
) {
5337 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5348 int RGWCompleteMultipart::verify_permission()
5350 if (s
->iam_policy
) {
5351 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5352 rgw::IAM::s3PutObject
,
5353 rgw_obj(s
->bucket
, s
->object
));
5354 if (e
== Effect::Allow
) {
5356 } else if (e
== Effect::Deny
) {
5361 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5368 void RGWCompleteMultipart::pre_exec()
5370 rgw_bucket_object_pre_exec(s
);
5373 void RGWCompleteMultipart::execute()
5375 RGWMultiCompleteUpload
*parts
;
5376 map
<int, string
>::iterator iter
;
5377 RGWMultiXMLParser parser
;
5379 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5380 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5381 map
<string
, bufferlist
> attrs
;
5384 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5385 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5390 RGWObjManifest manifest
;
5391 uint64_t olh_epoch
= 0;
5394 op_ret
= get_params();
5397 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5402 if (!data
|| !len
) {
5403 op_ret
= -ERR_MALFORMED_XML
;
5407 if (!parser
.init()) {
5412 if (!parser
.parse(data
, len
, 1)) {
5413 op_ret
= -ERR_MALFORMED_XML
;
5417 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5418 if (!parts
|| parts
->parts
.empty()) {
5419 op_ret
= -ERR_MALFORMED_XML
;
5423 if ((int)parts
->parts
.size() >
5424 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5429 mp
.init(s
->object
.name
, upload_id
);
5430 meta_oid
= mp
.get_meta();
5432 int total_parts
= 0;
5433 int handled_parts
= 0;
5434 int max_parts
= 1000;
5437 RGWCompressionInfo cs_info
;
5438 bool compressed
= false;
5439 uint64_t accounted_size
= 0;
5441 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5443 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5445 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5447 iter
= parts
->parts
.begin();
5449 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5450 meta_obj
.set_in_extra_data(true);
5451 meta_obj
.index_hash_source
= s
->object
.name
;
5453 /*take a cls lock on meta_obj to prevent racing completions (or retries)
5454 from deleting the parts*/
5456 rgw_raw_obj raw_obj
;
5457 int max_lock_secs_mp
=
5458 s
->cct
->_conf
->get_val
<int64_t>("rgw_mp_lock_max_time");
5459 utime_t
dur(max_lock_secs_mp
, 0);
5461 store
->obj_to_raw((s
->bucket_info
).placement_rule
, meta_obj
, &raw_obj
);
5462 store
->get_obj_data_pool((s
->bucket_info
).placement_rule
,
5463 meta_obj
,&meta_pool
);
5464 store
->open_pool_ctx(meta_pool
, serializer
.ioctx
);
5466 op_ret
= serializer
.try_lock(raw_obj
.oid
, dur
);
5468 dout(0) << "RGWCompleteMultipart::execute() failed to acquire lock " << dendl
;
5469 op_ret
= -ERR_INTERNAL_ERROR
;
5470 s
->err
.message
= "This multipart completion is already in progress";
5474 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5477 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5478 << " ret=" << op_ret
<< dendl
;
5483 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5484 marker
, obj_parts
, &marker
, &truncated
);
5485 if (op_ret
== -ENOENT
) {
5486 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5491 total_parts
+= obj_parts
.size();
5492 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5493 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5494 << " expected: " << parts
->parts
.size() << dendl
;
5495 op_ret
= -ERR_INVALID_PART
;
5499 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5500 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5501 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5502 part_size
< min_part_size
) {
5503 op_ret
= -ERR_TOO_SMALL
;
5507 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5508 if (iter
->first
!= (int)obj_iter
->first
) {
5509 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5510 << iter
->first
<< " next uploaded: "
5511 << obj_iter
->first
<< dendl
;
5512 op_ret
= -ERR_INVALID_PART
;
5515 string part_etag
= rgw_string_unquote(iter
->second
);
5516 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5517 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5518 << " etag: " << iter
->second
<< dendl
;
5519 op_ret
= -ERR_INVALID_PART
;
5523 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5524 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5525 hash
.Update((const byte
*)petag
, sizeof(petag
));
5527 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5529 /* update manifest for part */
5530 string oid
= mp
.get_part(obj_iter
->second
.num
);
5532 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5534 if (obj_part
.manifest
.empty()) {
5535 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5536 << src_obj
<< dendl
;
5537 op_ret
= -ERR_INVALID_PART
;
5540 manifest
.append(obj_part
.manifest
, store
);
5543 if (obj_part
.cs_info
.compression_type
!= "none") {
5544 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5545 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5546 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5547 op_ret
= -ERR_INVALID_PART
;
5550 int64_t new_ofs
; // offset in compression data for new part
5551 if (cs_info
.blocks
.size() > 0)
5552 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5555 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5556 compression_block cb
;
5557 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5558 cb
.new_ofs
= new_ofs
;
5560 cs_info
.blocks
.push_back(cb
);
5561 new_ofs
= cb
.new_ofs
+ cb
.len
;
5564 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5565 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5569 rgw_obj_index_key remove_key
;
5570 src_obj
.key
.get_index_key(&remove_key
);
5572 remove_objs
.push_back(remove_key
);
5574 ofs
+= obj_part
.size
;
5575 accounted_size
+= obj_part
.accounted_size
;
5577 } while (truncated
);
5578 hash
.Final((byte
*)final_etag
);
5580 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5581 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5582 "-%lld", (long long)parts
->parts
.size());
5583 etag
= final_etag_str
;
5584 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5586 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5588 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5591 // write compression attribute to full object
5593 ::encode(cs_info
, tmp
);
5594 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5597 target_obj
.init(s
->bucket
, s
->object
.name
);
5598 if (versioned_object
) {
5599 store
->gen_rand_obj_instance_name(&target_obj
);
5602 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5604 obj_ctx
.obj
.set_atomic(target_obj
);
5606 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5607 RGWRados::Object::Write
obj_op(&op_target
);
5609 obj_op
.meta
.manifest
= &manifest
;
5610 obj_op
.meta
.remove_objs
= &remove_objs
;
5612 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5613 obj_op
.meta
.owner
= s
->owner
.get_id();
5614 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5615 obj_op
.meta
.modify_tail
= true;
5616 obj_op
.meta
.completeMultipart
= true;
5617 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5621 // remove the upload obj
5622 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5623 s
->bucket_info
, meta_obj
, 0);
5625 /* serializer's exclusive lock is released */
5626 serializer
.clear_locked();
5628 ldout(store
->ctx(), 0) << "WARNING: failed to remove object "
5629 << meta_obj
<< dendl
;
5633 int RGWCompleteMultipart::MPSerializer::try_lock(
5634 const std::string
& _oid
,
5639 lock
.set_duration(dur
);
5640 lock
.lock_exclusive(&op
);
5641 int ret
= ioctx
.operate(oid
, &op
);
5648 void RGWCompleteMultipart::complete()
5650 /* release exclusive lock iff not already */
5651 if (unlikely(serializer
.locked
)) {
5652 int r
= serializer
.unlock();
5654 ldout(store
->ctx(), 0) << "WARNING: failed to unlock "
5655 << serializer
.oid
<< dendl
;
5661 int RGWAbortMultipart::verify_permission()
5663 if (s
->iam_policy
) {
5664 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5665 rgw::IAM::s3AbortMultipartUpload
,
5666 rgw_obj(s
->bucket
, s
->object
));
5667 if (e
== Effect::Allow
) {
5669 } else if (e
== Effect::Deny
) {
5674 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5681 void RGWAbortMultipart::pre_exec()
5683 rgw_bucket_object_pre_exec(s
);
5686 void RGWAbortMultipart::execute()
5691 upload_id
= s
->info
.args
.get("uploadId");
5692 map
<string
, bufferlist
> attrs
;
5696 if (upload_id
.empty() || s
->object
.empty())
5699 mp
.init(s
->object
.name
, upload_id
);
5700 meta_oid
= mp
.get_meta();
5702 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5706 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5707 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5710 int RGWListMultipart::verify_permission()
5712 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5718 void RGWListMultipart::pre_exec()
5720 rgw_bucket_object_pre_exec(s
);
5723 void RGWListMultipart::execute()
5725 map
<string
, bufferlist
> xattrs
;
5729 op_ret
= get_params();
5733 mp
.init(s
->object
.name
, upload_id
);
5734 meta_oid
= mp
.get_meta();
5736 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5740 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5741 marker
, parts
, NULL
, &truncated
);
5744 int RGWListBucketMultiparts::verify_permission()
5746 if (!verify_bucket_permission(s
,
5747 rgw::IAM::s3ListBucketMultipartUploads
))
5753 void RGWListBucketMultiparts::pre_exec()
5755 rgw_bucket_object_pre_exec(s
);
5758 void RGWListBucketMultiparts::execute()
5760 vector
<rgw_bucket_dir_entry
> objs
;
5763 op_ret
= get_params();
5767 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5769 path_args
= s
->info
.args
.get("path");
5770 if (!path_args
.empty()) {
5771 if (!delimiter
.empty() || !prefix
.empty()) {
5779 marker_meta
= marker
.get_meta();
5781 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5782 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5787 if (!objs
.empty()) {
5788 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5789 RGWMultipartUploadEntry entry
;
5790 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5791 rgw_obj_key
key(iter
->key
);
5792 if (!entry
.mp
.from_meta(key
.name
))
5795 uploads
.push_back(entry
);
5797 next_marker
= entry
;
5801 void RGWGetHealthCheck::execute()
5803 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5804 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5805 /* Disabling path specified & existent in the filesystem. */
5806 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5808 op_ret
= 0; /* 200 OK */
5812 int RGWDeleteMultiObj::verify_permission()
5814 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5815 if (!acl_allowed
&& !s
->iam_policy
)
5821 void RGWDeleteMultiObj::pre_exec()
5823 rgw_bucket_object_pre_exec(s
);
5826 void RGWDeleteMultiObj::execute()
5828 RGWMultiDelDelete
*multi_delete
;
5829 vector
<rgw_obj_key
>::iterator iter
;
5830 RGWMultiDelXMLParser parser
;
5831 int num_processed
= 0;
5832 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5834 op_ret
= get_params();
5844 if (!parser
.init()) {
5849 if (!parser
.parse(data
, len
, 1)) {
5854 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5855 if (!multi_delete
) {
5860 if (multi_delete
->is_quiet())
5864 if (multi_delete
->objects
.empty()) {
5868 for (iter
= multi_delete
->objects
.begin();
5869 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5870 ++iter
, num_processed
++) {
5871 rgw_obj
obj(bucket
, *iter
);
5872 if (s
->iam_policy
) {
5873 auto e
= s
->iam_policy
->eval(s
->env
,
5875 iter
->instance
.empty() ?
5876 rgw::IAM::s3DeleteObject
:
5877 rgw::IAM::s3DeleteObjectVersion
,
5879 if ((e
== Effect::Deny
) ||
5880 (e
== Effect::Pass
&& !acl_allowed
)) {
5881 send_partial_response(*iter
, false, "", -EACCES
);
5886 obj_ctx
->obj
.set_atomic(obj
);
5888 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5889 RGWRados::Object::Delete
del_op(&del_target
);
5891 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5892 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5893 del_op
.params
.obj_owner
= s
->owner
;
5895 op_ret
= del_op
.delete_obj();
5896 if (op_ret
== -ENOENT
) {
5900 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5901 del_op
.result
.version_id
, op_ret
);
5904 /* set the return code to zero, errors at this point will be
5905 dumped to the response */
5909 // will likely segfault if begin_response() has not been called
5921 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5922 map
<string
, bufferlist
>& battrs
,
5923 ACLOwner
& bucket_owner
/* out */)
5925 RGWAccessControlPolicy
bacl(store
->ctx());
5926 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5931 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5933 bucket_owner
= bacl
.get_owner();
5935 /* We can use global user_acl because each BulkDelete request is allowed
5936 * to work on entities from a single account only. */
5937 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5938 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5941 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5943 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5945 RGWBucketInfo binfo
;
5946 map
<string
, bufferlist
> battrs
;
5949 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5950 path
.bucket_name
, binfo
, nullptr,
5956 if (!verify_permission(binfo
, battrs
, bowner
)) {
5961 if (!path
.obj_key
.empty()) {
5962 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5963 obj_ctx
.obj
.set_atomic(obj
);
5965 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5966 RGWRados::Object::Delete
del_op(&del_target
);
5968 del_op
.params
.bucket_owner
= binfo
.owner
;
5969 del_op
.params
.versioning_status
= binfo
.versioning_status();
5970 del_op
.params
.obj_owner
= bowner
;
5972 ret
= del_op
.delete_obj();
5977 RGWObjVersionTracker ot
;
5978 ot
.read_version
= binfo
.ep_objv
;
5980 ret
= store
->delete_bucket(binfo
, ot
);
5982 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5983 binfo
.bucket
.name
, false);
5985 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
5993 if (!store
->is_meta_master()) {
5995 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
5998 if (ret
== -ENOENT
) {
5999 /* adjust error, we want to return with NoSuchBucket and not
6001 ret
= -ERR_NO_SUCH_BUCKET
;
6013 if (-ENOENT
== ret
) {
6014 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
6017 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
6020 fail_desc_t failed_item
= {
6024 failures
.push_back(failed_item
);
6029 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
6031 fail_desc_t failed_item
= {
6035 failures
.push_back(failed_item
);
6040 if (-ENOENT
== ret
) {
6041 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
6044 fail_desc_t failed_item
= {
6048 failures
.push_back(failed_item
);
6053 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
6055 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
6056 for (auto path
: paths
) {
6057 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
6058 delete_single(path
);
6064 int RGWBulkDelete::verify_permission()
6069 void RGWBulkDelete::pre_exec()
6071 rgw_bucket_object_pre_exec(s
);
6074 void RGWBulkDelete::execute()
6076 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
6078 bool is_truncated
= false;
6080 list
<RGWBulkDelete::acct_path_t
> items
;
6082 int ret
= get_data(items
, &is_truncated
);
6087 ret
= deleter
->delete_chunk(items
);
6088 } while (!op_ret
&& is_truncated
);
6094 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
6096 int RGWBulkUploadOp::verify_permission()
6098 if (s
->auth
.identity
->is_anonymous()) {
6102 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
6106 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
6107 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
6108 << " (user_id.tenant=" << s
->user
->user_id
.tenant
6109 << " requested=" << s
->bucket_tenant
<< ")"
6114 if (s
->user
->max_buckets
< 0) {
6121 void RGWBulkUploadOp::pre_exec()
6123 rgw_bucket_object_pre_exec(s
);
6126 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
6127 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
6129 /* We need to skip all slashes at the beginning in order to preserve
6130 * compliance with Swift. */
6131 const size_t start_pos
= path
.find_first_not_of('/');
6133 if (boost::string_ref::npos
!= start_pos
) {
6134 /* Seperator is the first slash after the leading ones. */
6135 const size_t sep_pos
= path
.substr(start_pos
).find('/');
6137 if (boost::string_ref::npos
!= sep_pos
) {
6138 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
6139 const auto obj_name
= path
.substr(sep_pos
+ 1);
6141 return std::make_pair(bucket_name
.to_string(),
6142 rgw_obj_key(obj_name
.to_string()));
6144 /* It's guaranteed here that bucket name is at least one character
6145 * long and is different than slash. */
6146 return std::make_pair(path
.substr(start_pos
).to_string(),
6154 std::pair
<std::string
, std::string
>
6155 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
6157 std::string bucket_path
, file_prefix
;
6158 if (! s
->init_state
.url_bucket
.empty()) {
6159 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
6160 if (! s
->object
.empty()) {
6161 std::string
& object_name
= s
->object
.name
;
6163 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
6164 * we can safely examine its last element. */
6165 if (object_name
.back() == '/') {
6166 file_prefix
.append(object_name
);
6168 file_prefix
.append(object_name
).append("/");
6172 return std::make_pair(bucket_path
, file_prefix
);
6175 int RGWBulkUploadOp::handle_dir_verify_permission()
6177 if (s
->user
->max_buckets
> 0) {
6178 RGWUserBuckets buckets
;
6180 bool is_truncated
= false;
6181 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
6182 marker
, std::string(), s
->user
->max_buckets
,
6183 false, &is_truncated
);
6188 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
6189 return -ERR_TOO_MANY_BUCKETS
;
6196 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
6198 /* the request of container or object level will contain bucket name.
6199 * only at account level need to append the bucket name */
6200 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
6204 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
6205 info
.script_uri
.append("/").append(bucket_name
);
6206 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
6207 info
.effective_uri
= "/" + bucket_name
;
6210 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
6212 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
6214 op_ret
= handle_dir_verify_permission();
6219 std::string bucket_name
;
6220 rgw_obj_key object_junk
;
6221 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
6223 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
6224 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
6226 /* we need to make sure we read bucket info, it's not read before for this
6227 * specific request */
6228 RGWBucketInfo binfo
;
6229 std::map
<std::string
, ceph::bufferlist
> battrs
;
6230 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6231 binfo
, NULL
, &battrs
);
6232 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6235 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6237 if (bucket_exists
) {
6238 RGWAccessControlPolicy
old_policy(s
->cct
);
6239 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6240 battrs
, &old_policy
);
6242 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6249 RGWBucketInfo master_info
;
6250 rgw_bucket
*pmaster_bucket
= nullptr;
6251 uint32_t *pmaster_num_shards
= nullptr;
6252 real_time creation_time
;
6253 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6255 if (! store
->is_meta_master()) {
6257 ceph::bufferlist in_data
;
6258 req_info info
= s
->info
;
6259 forward_req_info(s
->cct
, info
, bucket_name
);
6260 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6265 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6266 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6267 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6269 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
6270 << objv
.ver
<< dendl
;
6271 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
6274 pmaster_bucket
= &master_info
.bucket
;
6275 creation_time
= master_info
.creation_time
;
6276 pmaster_num_shards
= &master_info
.num_shards
;
6279 pmaster_bucket
= nullptr;
6280 pmaster_num_shards
= nullptr;
6284 std::string placement_rule
;
6285 if (bucket_exists
) {
6286 std::string selected_placement_rule
;
6288 bucket
.tenant
= s
->bucket_tenant
;
6289 bucket
.name
= s
->bucket_name
;
6290 op_ret
= store
->select_bucket_placement(*(s
->user
),
6291 store
->get_zonegroup().get_id(),
6293 &selected_placement_rule
,
6295 if (selected_placement_rule
!= binfo
.placement_rule
) {
6297 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6302 /* Create metadata: ACLs. */
6303 std::map
<std::string
, ceph::bufferlist
> attrs
;
6304 RGWAccessControlPolicy policy
;
6305 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6306 ceph::bufferlist aclbl
;
6307 policy
.encode(aclbl
);
6308 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6310 RGWQuotaInfo quota_info
;
6311 const RGWQuotaInfo
* pquota_info
= nullptr;
6314 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6315 bucket
.name
= bucket_name
;
6318 RGWBucketInfo out_info
;
6319 op_ret
= store
->create_bucket(*(s
->user
),
6321 store
->get_zonegroup().get_id(),
6322 placement_rule
, binfo
.swift_ver_location
,
6324 out_info
, pobjv
, &ep_objv
, creation_time
,
6325 pmaster_bucket
, pmaster_num_shards
, true);
6326 /* continue if EEXIST and create_bucket will fail below. this way we can
6327 * recover from a partial create by retrying it. */
6328 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6329 << ", bucket=" << bucket
<< dendl
;
6331 if (op_ret
&& op_ret
!= -EEXIST
) {
6335 const bool existed
= (op_ret
== -EEXIST
);
6337 /* bucket already existed, might have raced with another bucket creation, or
6338 * might be partial bucket creation that never completed. Read existing bucket
6339 * info, verify that the reported bucket owner is the current user.
6340 * If all is ok then update the user's list of buckets.
6341 * Otherwise inform client about a name conflict.
6343 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6345 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6348 bucket
= out_info
.bucket
;
6351 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6352 out_info
.creation_time
, false);
6353 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6354 /* if it exists (or previously existed), don't remove it! */
6355 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6356 bucket
.tenant
, bucket
.name
);
6358 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6361 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6362 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6364 op_ret
= -ERR_BUCKET_EXISTS
;
6371 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6373 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6374 ACLOwner
& bucket_owner
/* out */)
6376 RGWAccessControlPolicy
bacl(store
->ctx());
6377 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6379 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6384 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6386 bucket_owner
= bacl
.get_owner();
6388 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6389 rgw::IAM::s3PutObject
, obj
);
6390 if (e
== Effect::Allow
) {
6392 } else if (e
== Effect::Deny
) {
6397 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6398 &bacl
, RGW_PERM_WRITE
);
6401 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6403 AlignedStreamGetter
& body
)
6406 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6409 RGWPutObjDataProcessor
*filter
= nullptr;
6410 boost::optional
<RGWPutObj_Compress
> compressor
;
6412 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6413 op_ret
= -ERR_TOO_LARGE
;
6417 std::string bucket_name
;
6419 std::tie(bucket_name
, object
) = *parse_path(path
);
6421 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6422 RGWBucketInfo binfo
;
6423 std::map
<std::string
, ceph::bufferlist
> battrs
;
6425 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6426 bucket_name
, binfo
, nullptr, &battrs
);
6427 if (op_ret
== -ENOENT
) {
6428 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6430 } else if (op_ret
< 0) {
6434 if (! handle_file_verify_permission(binfo
,
6435 rgw_obj(binfo
.bucket
, object
),
6437 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6442 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6443 user_quota
, bucket_quota
, size
);
6448 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6453 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6458 s
->cct
->_conf
->rgw_obj_stripe_size
,
6460 binfo
.versioning_enabled());
6462 /* No filters by default. */
6463 filter
= &processor
;
6465 op_ret
= processor
.prepare(store
, nullptr);
6467 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6472 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6473 binfo
.placement_rule
);
6474 CompressorRef plugin
;
6475 if (compression_type
!= "none") {
6476 plugin
= Compressor::create(s
->cct
, compression_type
);
6478 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6479 << compression_type
<< dendl
;
6481 compressor
.emplace(s
->cct
, plugin
, filter
);
6482 filter
= &*compressor
;
6486 /* Upload file content. */
6491 ceph::bufferlist data
;
6492 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6494 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6498 } else if (len
> 0) {
6499 hash
.Update((const byte
*)data
.c_str(), data
.length());
6500 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6502 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6513 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6518 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6519 user_quota
, bucket_quota
, size
);
6521 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6526 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6531 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6532 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6534 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6536 /* Create metadata: ETAG. */
6537 std::map
<std::string
, ceph::bufferlist
> attrs
;
6538 std::string etag
= calc_md5
;
6539 ceph::bufferlist etag_bl
;
6540 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6541 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6543 /* Create metadata: ACLs. */
6544 RGWAccessControlPolicy policy
;
6545 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6546 ceph::bufferlist aclbl
;
6547 policy
.encode(aclbl
);
6548 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6550 /* Create metadata: compression info. */
6551 if (compressor
&& compressor
->is_compressed()) {
6552 ceph::bufferlist tmp
;
6553 RGWCompressionInfo cs_info
;
6554 cs_info
.compression_type
= plugin
->get_type_name();
6555 cs_info
.orig_size
= s
->obj_size
;
6556 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6557 ::encode(cs_info
, tmp
);
6558 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6561 /* Complete the transaction. */
6562 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6563 ceph::real_time() /* delete_at */);
6565 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6572 void RGWBulkUploadOp::execute()
6574 ceph::bufferlist
buffer(64 * 1024);
6576 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6578 /* Create an instance of stream-abstracting class. Having this indirection
6579 * allows for easy introduction of decompressors like gzip and bzip2. */
6580 auto stream
= create_stream();
6585 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6586 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6587 std::string bucket_path
, file_prefix
;
6588 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6590 auto status
= rgw::tar::StatusIndicator::create();
6592 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6594 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6598 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6599 * must be tracked to detect out end-of-archive. It occurs when both of
6600 * them are empty (zeroed). Tracing this particular inter-block dependency
6601 * is responsibility of the rgw::tar::StatusIndicator class. */
6602 boost::optional
<rgw::tar::HeaderView
> header
;
6603 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6605 if (! status
.empty() && header
) {
6606 /* This specific block isn't empty (entirely zeroed), so we can parse
6607 * it as a TAR header and dispatch. At the moment we do support only
6608 * regular files and directories. Everything else (symlinks, devices)
6609 * will be ignored but won't cease the whole upload. */
6610 switch (header
->get_filetype()) {
6611 case rgw::tar::FileType::NORMAL_FILE
: {
6612 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6614 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6615 file_prefix
+ header
->get_filename().to_string();
6616 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6617 rgw::tar::BLOCK_SIZE
, *stream
);
6618 op_ret
= handle_file(filename
,
6619 header
->get_filesize(),
6622 /* Only regular files counts. */
6625 failures
.emplace_back(op_ret
, filename
.to_string());
6629 case rgw::tar::FileType::DIRECTORY
: {
6630 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6632 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6633 op_ret
= handle_dir(dirname
);
6634 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6635 failures
.emplace_back(op_ret
, dirname
.to_string());
6640 /* Not recognized. Skip. */
6646 /* In case of any problems with sub-request authorization Swift simply
6647 * terminates whole upload immediately. */
6648 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6650 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6655 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6660 } while (! status
.eof());
6665 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6667 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6668 ceph::bufferlist junk
;
6670 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6673 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6674 ceph::bufferlist
& dst
)
6676 const size_t max_to_read
= std::min(want
, length
- position
);
6677 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6684 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6685 ceph::bufferlist
& dst
)
6687 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6694 int RGWSetAttrs::verify_permission()
6696 // This looks to be part of the RGW-NFS machinery and has no S3 or
6697 // Swift equivalent.
6699 if (!s
->object
.empty()) {
6700 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6702 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6710 void RGWSetAttrs::pre_exec()
6712 rgw_bucket_object_pre_exec(s
);
6715 void RGWSetAttrs::execute()
6717 op_ret
= get_params();
6721 rgw_obj
obj(s
->bucket
, s
->object
);
6723 if (!s
->object
.empty()) {
6724 store
->set_atomic(s
->obj_ctx
, obj
);
6725 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6727 for (auto& iter
: attrs
) {
6728 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6730 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6731 &s
->bucket_info
.objv_tracker
);
6735 void RGWGetObjLayout::pre_exec()
6737 rgw_bucket_object_pre_exec(s
);
6740 void RGWGetObjLayout::execute()
6742 rgw_obj
obj(s
->bucket
, s
->object
);
6743 RGWRados::Object
target(store
,
6745 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6746 rgw_obj(s
->bucket
, s
->object
));
6747 RGWRados::Object::Read
stat_op(&target
);
6749 op_ret
= stat_op
.prepare();
6754 head_obj
= stat_op
.state
.head_obj
;
6756 op_ret
= target
.get_manifest(&manifest
);
6760 int RGWConfigBucketMetaSearch::verify_permission()
6762 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6769 void RGWConfigBucketMetaSearch::pre_exec()
6771 rgw_bucket_object_pre_exec(s
);
6774 void RGWConfigBucketMetaSearch::execute()
6776 op_ret
= get_params();
6778 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6782 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6784 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6786 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6791 int RGWGetBucketMetaSearch::verify_permission()
6793 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6800 void RGWGetBucketMetaSearch::pre_exec()
6802 rgw_bucket_object_pre_exec(s
);
6805 int RGWDelBucketMetaSearch::verify_permission()
6807 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6814 void RGWDelBucketMetaSearch::pre_exec()
6816 rgw_bucket_object_pre_exec(s
);
6819 void RGWDelBucketMetaSearch::execute()
6821 s
->bucket_info
.mdsearch_config
.clear();
6823 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6825 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6831 RGWHandler::~RGWHandler()
6835 int RGWHandler::init(RGWRados
*_store
,
6836 struct req_state
*_s
,
6837 rgw::io::BasicClient
*cio
)
6845 int RGWHandler::do_init_permissions()
6847 int ret
= rgw_build_bucket_policies(store
, s
);
6848 s
->env
= rgw_build_iam_environment(store
, s
);
6851 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6852 if (ret
== -ENODATA
)
6859 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6862 /* already read bucket info */
6865 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6868 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6869 << s
->object
<< " only_bucket=" << only_bucket
6870 << " ret=" << ret
<< dendl
;
6871 if (ret
== -ENODATA
)
6878 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6879 return dialect_handler
->error_handler(err_no
, error_content
);
6882 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6883 // This is the do-nothing error handler
6888 void RGWPutBucketPolicy::send_response()
6891 set_req_state_err(s
, op_ret
);
6897 int RGWPutBucketPolicy::verify_permission()
6899 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6906 int RGWPutBucketPolicy::get_params()
6908 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6909 // At some point when I have more time I want to make a version of
6910 // rgw_rest_read_all_input that doesn't use malloc.
6911 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6912 // And throws exceptions.
6916 void RGWPutBucketPolicy::execute()
6918 op_ret
= get_params();
6923 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6925 if (!store
->is_meta_master()) {
6926 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6928 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6934 const Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6935 op_ret
= retry_raced_bucket_write(store
, s
, [&p
, this] {
6936 auto attrs
= s
->bucket_attrs
;
6937 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6938 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6939 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6940 &s
->bucket_info
.objv_tracker
);
6943 } catch (rgw::IAM::PolicyParseException
& e
) {
6944 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6949 void RGWGetBucketPolicy::send_response()
6952 set_req_state_err(s
, op_ret
);
6955 end_header(s
, this, "application/json");
6956 dump_body(s
, policy
);
6959 int RGWGetBucketPolicy::verify_permission()
6961 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6968 void RGWGetBucketPolicy::execute()
6970 auto attrs
= s
->bucket_attrs
;
6971 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6972 if (aiter
== attrs
.end()) {
6973 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6974 << " bucket_name = " << s
->bucket_name
<< dendl
;
6975 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6976 s
->err
.message
= "The bucket policy does not exist";
6979 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6981 if (policy
.length() == 0) {
6982 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6983 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6984 s
->err
.message
= "The bucket policy does not exist";
6990 void RGWDeleteBucketPolicy::send_response()
6993 set_req_state_err(s
, op_ret
);
6999 int RGWDeleteBucketPolicy::verify_permission()
7001 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
7008 void RGWDeleteBucketPolicy::execute()
7010 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
7011 auto attrs
= s
->bucket_attrs
;
7012 attrs
.erase(RGW_ATTR_IAM_POLICY
);
7013 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
7014 &s
->bucket_info
.objv_tracker
);
7019 void RGWGetClusterStat::execute()
7021 op_ret
= this->store
->get_rados_handle()->cluster_stat(stats_op
);