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
) {
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 (allow_unordered
&& !delimiter
.empty()) {
2316 "ERROR: unordered bucket listing requested with a delimiter" << dendl
;
2321 if (need_container_stats()) {
2322 map
<string
, RGWBucketEnt
> m
;
2323 m
[s
->bucket
.name
] = RGWBucketEnt();
2324 m
.begin()->second
.bucket
= s
->bucket
;
2325 op_ret
= store
->update_containers_stats(m
);
2327 bucket
= m
.begin()->second
;
2331 RGWRados::Bucket
target(store
, s
->bucket_info
);
2332 if (shard_id
>= 0) {
2333 target
.set_shard_id(shard_id
);
2335 RGWRados::Bucket::List
list_op(&target
);
2337 list_op
.params
.prefix
= prefix
;
2338 list_op
.params
.delim
= delimiter
;
2339 list_op
.params
.marker
= marker
;
2340 list_op
.params
.end_marker
= end_marker
;
2341 list_op
.params
.list_versions
= list_versions
;
2342 list_op
.params
.allow_unordered
= allow_unordered
;
2344 op_ret
= list_op
.list_objects(max
, &objs
, &common_prefixes
, &is_truncated
);
2346 next_marker
= list_op
.get_next_marker();
2350 int RGWGetBucketLogging::verify_permission()
2352 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLogging
);
2355 int RGWGetBucketLocation::verify_permission()
2357 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketLocation
);
2360 int RGWCreateBucket::verify_permission()
2362 /* This check is mostly needed for S3 that doesn't support account ACL.
2363 * Swift doesn't allow to delegate any permission to an anonymous user,
2364 * so it will become an early exit in such case. */
2365 if (s
->auth
.identity
->is_anonymous()) {
2369 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
2373 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
2374 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
2375 << " (user_id.tenant=" << s
->user
->user_id
.tenant
2376 << " requested=" << s
->bucket_tenant
<< ")"
2380 if (s
->user
->max_buckets
< 0) {
2384 if (s
->user
->max_buckets
) {
2385 RGWUserBuckets buckets
;
2387 bool is_truncated
= false;
2388 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
2389 marker
, string(), s
->user
->max_buckets
,
2390 false, &is_truncated
);
2395 if ((int)buckets
.count() >= s
->user
->max_buckets
) {
2396 return -ERR_TOO_MANY_BUCKETS
;
2403 static int forward_request_to_master(struct req_state
*s
, obj_version
*objv
,
2404 RGWRados
*store
, bufferlist
& in_data
,
2405 JSONParser
*jp
, req_info
*forward_info
)
2407 if (!store
->rest_master_conn
) {
2408 ldout(s
->cct
, 0) << "rest connection is invalid" << dendl
;
2411 ldout(s
->cct
, 0) << "sending request to master zonegroup" << dendl
;
2412 bufferlist response
;
2413 string uid_str
= s
->user
->user_id
.to_str();
2414 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
2415 int ret
= store
->rest_master_conn
->forward(uid_str
, (forward_info
? *forward_info
: s
->info
),
2416 objv
, MAX_REST_RESPONSE
, &in_data
, &response
);
2420 ldout(s
->cct
, 20) << "response: " << response
.c_str() << dendl
;
2421 if (jp
&& !jp
->parse(response
.c_str(), response
.length())) {
2422 ldout(s
->cct
, 0) << "failed parsing response from master zonegroup" << dendl
;
2429 void RGWCreateBucket::pre_exec()
2431 rgw_bucket_object_pre_exec(s
);
2434 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2435 map
<string
, bufferlist
>& out_attrs
,
2436 map
<string
, bufferlist
>& out_rmattrs
)
2438 for (const auto& kv
: orig_attrs
) {
2439 const string
& name
= kv
.first
;
2441 /* Check if the attr is user-defined metadata item. */
2442 if (name
.compare(0, sizeof(RGW_ATTR_META_PREFIX
) - 1,
2443 RGW_ATTR_META_PREFIX
) == 0) {
2444 /* For the objects all existing meta attrs have to be removed. */
2445 out_rmattrs
[name
] = kv
.second
;
2446 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2447 out_attrs
[name
] = kv
.second
;
2452 /* Fuse resource metadata basing on original attributes in @orig_attrs, set
2453 * of _custom_ attribute names to remove in @rmattr_names and attributes in
2454 * @out_attrs. Place results in @out_attrs.
2456 * NOTE: it's supposed that all special attrs already present in @out_attrs
2457 * will be preserved without any change. Special attributes are those which
2458 * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
2459 * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
2460 static void prepare_add_del_attrs(const map
<string
, bufferlist
>& orig_attrs
,
2461 const set
<string
>& rmattr_names
,
2462 map
<string
, bufferlist
>& out_attrs
)
2464 for (const auto& kv
: orig_attrs
) {
2465 const string
& name
= kv
.first
;
2467 /* Check if the attr is user-defined metadata item. */
2468 if (name
.compare(0, strlen(RGW_ATTR_META_PREFIX
),
2469 RGW_ATTR_META_PREFIX
) == 0) {
2470 /* For the buckets all existing meta attrs are preserved,
2471 except those that are listed in rmattr_names. */
2472 if (rmattr_names
.find(name
) != std::end(rmattr_names
)) {
2473 const auto aiter
= out_attrs
.find(name
);
2475 if (aiter
!= std::end(out_attrs
)) {
2476 out_attrs
.erase(aiter
);
2479 /* emplace() won't alter the map if the key is already present.
2480 * This behaviour is fully intensional here. */
2481 out_attrs
.emplace(kv
);
2483 } else if (out_attrs
.find(name
) == std::end(out_attrs
)) {
2484 out_attrs
[name
] = kv
.second
;
2490 static void populate_with_generic_attrs(const req_state
* const s
,
2491 map
<string
, bufferlist
>& out_attrs
)
2493 for (const auto& kv
: s
->generic_attrs
) {
2494 bufferlist
& attrbl
= out_attrs
[kv
.first
];
2495 const string
& val
= kv
.second
;
2497 attrbl
.append(val
.c_str(), val
.size() + 1);
2502 static int filter_out_quota_info(std::map
<std::string
, bufferlist
>& add_attrs
,
2503 const std::set
<std::string
>& rmattr_names
,
2504 RGWQuotaInfo
& quota
,
2505 bool * quota_extracted
= nullptr)
2507 bool extracted
= false;
2509 /* Put new limit on max objects. */
2510 auto iter
= add_attrs
.find(RGW_ATTR_QUOTA_NOBJS
);
2512 if (std::end(add_attrs
) != iter
) {
2514 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2518 add_attrs
.erase(iter
);
2522 /* Put new limit on bucket (container) size. */
2523 iter
= add_attrs
.find(RGW_ATTR_QUOTA_MSIZE
);
2524 if (iter
!= add_attrs
.end()) {
2526 static_cast<int64_t>(strict_strtoll(iter
->second
.c_str(), 10, &err
));
2530 add_attrs
.erase(iter
);
2534 for (const auto& name
: rmattr_names
) {
2535 /* Remove limit on max objects. */
2536 if (name
.compare(RGW_ATTR_QUOTA_NOBJS
) == 0) {
2537 quota
.max_objects
= -1;
2541 /* Remove limit on max bucket size. */
2542 if (name
.compare(RGW_ATTR_QUOTA_MSIZE
) == 0) {
2543 quota
.max_size
= -1;
2548 /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */
2549 quota
.check_on_raw
= true;
2550 quota
.enabled
= quota
.max_size
> 0 || quota
.max_objects
> 0;
2552 if (quota_extracted
) {
2553 *quota_extracted
= extracted
;
2560 static void filter_out_website(std::map
<std::string
, ceph::bufferlist
>& add_attrs
,
2561 const std::set
<std::string
>& rmattr_names
,
2562 RGWBucketWebsiteConf
& ws_conf
)
2566 /* Let's define a mapping between each custom attribute and the memory where
2567 * attribute's value should be stored. The memory location is expressed by
2568 * a non-const reference. */
2569 const auto mapping
= {
2570 std::make_pair(RGW_ATTR_WEB_INDEX
, std::ref(ws_conf
.index_doc_suffix
)),
2571 std::make_pair(RGW_ATTR_WEB_ERROR
, std::ref(ws_conf
.error_doc
)),
2572 std::make_pair(RGW_ATTR_WEB_LISTINGS
, std::ref(lstval
)),
2573 std::make_pair(RGW_ATTR_WEB_LIST_CSS
, std::ref(ws_conf
.listing_css_doc
)),
2574 std::make_pair(RGW_ATTR_SUBDIR_MARKER
, std::ref(ws_conf
.subdir_marker
))
2577 for (const auto& kv
: mapping
) {
2578 const char * const key
= kv
.first
;
2579 auto& target
= kv
.second
;
2581 auto iter
= add_attrs
.find(key
);
2583 if (std::end(add_attrs
) != iter
) {
2584 /* The "target" is a reference to ws_conf. */
2585 target
= iter
->second
.c_str();
2586 add_attrs
.erase(iter
);
2589 if (rmattr_names
.count(key
)) {
2590 target
= std::string();
2594 if (! lstval
.empty()) {
2595 ws_conf
.listing_enabled
= boost::algorithm::iequals(lstval
, "true");
2600 void RGWCreateBucket::execute()
2602 RGWAccessControlPolicy
old_policy(s
->cct
);
2604 buffer::list corsbl
;
2607 rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
, bucket_name
);
2608 rgw_raw_obj
obj(store
->get_zone_params().domain_root
, bucket_name
);
2609 obj_version objv
, *pobjv
= NULL
;
2611 op_ret
= get_params();
2615 if (!location_constraint
.empty() &&
2616 !store
->has_zonegroup_api(location_constraint
)) {
2617 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2618 << " can't be found." << dendl
;
2619 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2620 s
->err
.message
= "The specified location-constraint is not valid";
2624 if (!store
->get_zonegroup().is_master_zonegroup() && !location_constraint
.empty() &&
2625 store
->get_zonegroup().api_name
!= location_constraint
) {
2626 ldout(s
->cct
, 0) << "location constraint (" << location_constraint
<< ")"
2627 << " doesn't match zonegroup" << " (" << store
->get_zonegroup().api_name
<< ")"
2629 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2630 s
->err
.message
= "The specified location-constraint is not valid";
2634 const auto& zonegroup
= store
->get_zonegroup();
2635 if (!placement_rule
.empty() &&
2636 !zonegroup
.placement_targets
.count(placement_rule
)) {
2637 ldout(s
->cct
, 0) << "placement target (" << placement_rule
<< ")"
2638 << " doesn't exist in the placement targets of zonegroup"
2639 << " (" << store
->get_zonegroup().api_name
<< ")" << dendl
;
2640 op_ret
= -ERR_INVALID_LOCATION_CONSTRAINT
;
2641 s
->err
.message
= "The specified placement target does not exist";
2645 /* we need to make sure we read bucket info, it's not read before for this
2646 * specific request */
2647 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2648 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2649 s
->bucket_info
, NULL
, &s
->bucket_attrs
);
2650 if (op_ret
< 0 && op_ret
!= -ENOENT
)
2652 s
->bucket_exists
= (op_ret
!= -ENOENT
);
2654 s
->bucket_owner
.set_id(s
->user
->user_id
);
2655 s
->bucket_owner
.set_name(s
->user
->display_name
);
2656 if (s
->bucket_exists
) {
2657 int r
= get_bucket_policy_from_attr(s
->cct
, store
, s
->bucket_info
,
2658 s
->bucket_attrs
, &old_policy
);
2660 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
2667 RGWBucketInfo master_info
;
2668 rgw_bucket
*pmaster_bucket
;
2669 uint32_t *pmaster_num_shards
;
2670 real_time creation_time
;
2672 if (!store
->is_meta_master()) {
2674 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, &jp
);
2679 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
2680 JSONDecoder::decode_json("object_ver", objv
, &jp
);
2681 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
2682 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver=" << objv
.ver
<< dendl
;
2683 ldout(s
->cct
, 20) << "got creation time: << " << master_info
.creation_time
<< dendl
;
2684 pmaster_bucket
= &master_info
.bucket
;
2685 creation_time
= master_info
.creation_time
;
2686 pmaster_num_shards
= &master_info
.num_shards
;
2689 pmaster_bucket
= NULL
;
2690 pmaster_num_shards
= NULL
;
2693 string zonegroup_id
;
2695 if (s
->system_request
) {
2696 zonegroup_id
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"zonegroup");
2697 if (zonegroup_id
.empty()) {
2698 zonegroup_id
= store
->get_zonegroup().get_id();
2701 zonegroup_id
= store
->get_zonegroup().get_id();
2704 if (s
->bucket_exists
) {
2705 string selected_placement_rule
;
2707 bucket
.tenant
= s
->bucket_tenant
;
2708 bucket
.name
= s
->bucket_name
;
2709 op_ret
= store
->select_bucket_placement(*(s
->user
), zonegroup_id
,
2711 &selected_placement_rule
, nullptr);
2712 if (selected_placement_rule
!= s
->bucket_info
.placement_rule
) {
2718 /* Encode special metadata first as we're using std::map::emplace under
2719 * the hood. This method will add the new items only if the map doesn't
2720 * contain such keys yet. */
2721 policy
.encode(aclbl
);
2722 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
2725 cors_config
.encode(corsbl
);
2726 emplace_attr(RGW_ATTR_CORS
, std::move(corsbl
));
2729 RGWQuotaInfo quota_info
;
2730 const RGWQuotaInfo
* pquota_info
= nullptr;
2731 if (need_metadata_upload()) {
2732 /* It's supposed that following functions WILL NOT change any special
2733 * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
2734 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2738 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2739 populate_with_generic_attrs(s
, attrs
);
2741 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, quota_info
);
2745 pquota_info
= "a_info
;
2748 /* Web site of Swift API. */
2749 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2750 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2753 s
->bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
2754 s
->bucket
.name
= s
->bucket_name
;
2756 /* Handle updates of the metadata for Swift's object versioning. */
2757 if (swift_ver_location
) {
2758 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2759 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2762 op_ret
= store
->create_bucket(*(s
->user
), s
->bucket
, zonegroup_id
,
2763 placement_rule
, s
->bucket_info
.swift_ver_location
,
2765 info
, pobjv
, &ep_objv
, creation_time
,
2766 pmaster_bucket
, pmaster_num_shards
, true);
2767 /* continue if EEXIST and create_bucket will fail below. this way we can
2768 * recover from a partial create by retrying it. */
2769 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
<< " bucket=" << s
->bucket
<< dendl
;
2771 if (op_ret
&& op_ret
!= -EEXIST
)
2774 existed
= (op_ret
== -EEXIST
);
2777 /* bucket already existed, might have raced with another bucket creation, or
2778 * might be partial bucket creation that never completed. Read existing bucket
2779 * info, verify that the reported bucket owner is the current user.
2780 * If all is ok then update the user's list of buckets.
2781 * Otherwise inform client about a name conflict.
2783 if (info
.owner
.compare(s
->user
->user_id
) != 0) {
2787 s
->bucket
= info
.bucket
;
2790 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, s
->bucket
,
2791 info
.creation_time
, false);
2792 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
2793 /* if it exists (or previously existed), don't remove it! */
2794 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
, s
->bucket
.tenant
,
2797 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2800 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
2801 op_ret
= -ERR_BUCKET_EXISTS
;
2804 if (need_metadata_upload() && existed
) {
2805 /* OK, it looks we lost race with another request. As it's required to
2806 * handle metadata fusion and upload, the whole operation becomes very
2807 * similar in nature to PutMetadataBucket. However, as the attrs may
2808 * changed in the meantime, we have to refresh. */
2811 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2812 RGWBucketInfo binfo
;
2813 map
<string
, bufferlist
> battrs
;
2815 op_ret
= store
->get_bucket_info(obj_ctx
, s
->bucket_tenant
, s
->bucket_name
,
2816 binfo
, nullptr, &battrs
);
2819 } else if (binfo
.owner
.compare(s
->user
->user_id
) != 0) {
2820 /* New bucket doesn't belong to the account we're operating on. */
2824 s
->bucket_info
= binfo
;
2825 s
->bucket_attrs
= battrs
;
2830 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
2834 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
2835 populate_with_generic_attrs(s
, attrs
);
2836 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
2841 /* Handle updates of the metadata for Swift's object versioning. */
2842 if (swift_ver_location
) {
2843 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
2844 s
->bucket_info
.swift_versioning
= (! swift_ver_location
->empty());
2847 /* Web site of Swift API. */
2848 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
2849 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
2851 /* This will also set the quota on the bucket. */
2852 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
2853 &s
->bucket_info
.objv_tracker
);
2854 } while (op_ret
== -ECANCELED
&& tries
++ < 20);
2856 /* Restore the proper return code. */
2858 op_ret
= -ERR_BUCKET_EXISTS
;
2863 int RGWDeleteBucket::verify_permission()
2865 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucket
)) {
2872 void RGWDeleteBucket::pre_exec()
2874 rgw_bucket_object_pre_exec(s
);
2877 void RGWDeleteBucket::execute()
2881 if (s
->bucket_name
.empty())
2884 if (!s
->bucket_exists
) {
2885 ldout(s
->cct
, 0) << "ERROR: bucket " << s
->bucket_name
<< " not found" << dendl
;
2886 op_ret
= -ERR_NO_SUCH_BUCKET
;
2889 RGWObjVersionTracker ot
;
2890 ot
.read_version
= s
->bucket_info
.ep_objv
;
2892 if (s
->system_request
) {
2893 string tag
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"tag");
2894 string ver_str
= s
->info
.args
.get(RGW_SYS_PARAM_PREFIX
"ver");
2896 ot
.read_version
.tag
= tag
;
2899 ver
= strict_strtol(ver_str
.c_str(), 10, &err
);
2901 ldout(s
->cct
, 0) << "failed to parse ver param" << dendl
;
2905 ot
.read_version
.ver
= ver
;
2909 op_ret
= rgw_bucket_sync_user_stats(store
, s
->user
->user_id
, s
->bucket_info
);
2911 ldout(s
->cct
, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret
<< dendl
;
2914 op_ret
= store
->check_bucket_empty(s
->bucket_info
);
2919 if (!store
->is_meta_master()) {
2921 op_ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
2924 if (op_ret
== -ENOENT
) {
2925 /* adjust error, we want to return with NoSuchBucket and not
2927 op_ret
= -ERR_NO_SUCH_BUCKET
;
2933 string prefix
, delimiter
;
2935 if (s
->prot_flags
& RGW_REST_SWIFT
) {
2937 path_args
= s
->info
.args
.get("path");
2938 if (!path_args
.empty()) {
2939 if (!delimiter
.empty() || !prefix
.empty()) {
2948 op_ret
= abort_bucket_multiparts(store
, s
->cct
, s
->bucket_info
, prefix
, delimiter
);
2954 op_ret
= store
->delete_bucket(s
->bucket_info
, ot
, false);
2956 if (op_ret
== -ECANCELED
) {
2957 // lost a race, either with mdlog sync or another delete bucket operation.
2958 // in either case, we've already called rgw_unlink_bucket()
2964 op_ret
= rgw_unlink_bucket(store
, s
->bucket_info
.owner
, s
->bucket
.tenant
,
2965 s
->bucket
.name
, false);
2967 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret
2979 int RGWPutObj::verify_permission()
2981 if (! copy_source
.empty()) {
2983 RGWAccessControlPolicy
cs_acl(s
->cct
);
2984 optional
<Policy
> policy
;
2985 map
<string
, bufferlist
> cs_attrs
;
2986 rgw_bucket
cs_bucket(copy_source_bucket_info
.bucket
);
2987 rgw_obj_key
cs_object(copy_source_object_name
, copy_source_version_id
);
2989 rgw_obj
obj(cs_bucket
, cs_object
);
2990 store
->set_atomic(s
->obj_ctx
, obj
);
2991 store
->set_prefetch_data(s
->obj_ctx
, obj
);
2993 /* check source object permissions */
2994 if (read_obj_policy(store
, s
, copy_source_bucket_info
, cs_attrs
, &cs_acl
,
2995 policy
, cs_bucket
, cs_object
) < 0) {
2999 /* admin request overrides permission checks */
3000 if (! s
->auth
.identity
->is_admin_of(cs_acl
.get_owner().get_id())) {
3002 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
3003 cs_object
.instance
.empty() ?
3004 rgw::IAM::s3GetObject
:
3005 rgw::IAM::s3GetObjectVersion
,
3006 rgw::IAM::ARN(obj
));
3007 if (e
== Effect::Deny
) {
3009 } else if (e
== Effect::Pass
&&
3010 !cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
3014 } else if (!cs_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
3021 if (s
->iam_policy
) {
3022 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3023 rgw::IAM::s3PutObject
,
3024 rgw_obj(s
->bucket
, s
->object
));
3025 if (e
== Effect::Allow
) {
3027 } else if (e
== Effect::Deny
) {
3032 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3039 void RGWPutObjProcessor_Multipart::get_mp(RGWMPObj
** _mp
){
3043 int RGWPutObjProcessor_Multipart::prepare(RGWRados
*store
, string
*oid_rand
)
3045 string oid
= obj_str
;
3046 upload_id
= s
->info
.args
.get("uploadId");
3048 mp
.init(oid
, upload_id
);
3050 mp
.init(oid
, upload_id
, *oid_rand
);
3053 part_num
= s
->info
.args
.get("partNumber");
3054 if (part_num
.empty()) {
3055 ldout(s
->cct
, 10) << "part number is empty" << dendl
;
3060 uint64_t num
= (uint64_t)strict_strtol(part_num
.c_str(), 10, &err
);
3063 ldout(s
->cct
, 10) << "bad part number: " << part_num
<< ": " << err
<< dendl
;
3067 string upload_prefix
= oid
+ ".";
3070 upload_prefix
.append(upload_id
);
3072 upload_prefix
.append(*oid_rand
);
3076 target_obj
.init(bucket
, oid
);
3078 manifest
.set_prefix(upload_prefix
);
3080 manifest
.set_multipart_part_rule(store
->ctx()->_conf
->rgw_obj_stripe_size
, num
);
3082 int r
= manifest_gen
.create_begin(store
->ctx(), &manifest
, s
->bucket_info
.placement_rule
, bucket
, target_obj
);
3087 cur_obj
= manifest_gen
.get_cur_obj(store
);
3088 rgw_raw_obj_to_obj(bucket
, cur_obj
, &head_obj
);
3089 head_obj
.index_hash_source
= obj_str
;
3091 r
= prepare_init(store
, NULL
);
3099 int RGWPutObjProcessor_Multipart::do_complete(size_t accounted_size
,
3101 real_time
*mtime
, real_time set_mtime
,
3102 map
<string
, bufferlist
>& attrs
,
3103 real_time delete_at
,
3104 const char *if_match
,
3105 const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
)
3107 complete_writing_data();
3109 RGWRados::Object
op_target(store
, s
->bucket_info
, obj_ctx
, head_obj
);
3110 op_target
.set_versioning_disabled(true);
3111 RGWRados::Object::Write
head_obj_op(&op_target
);
3113 head_obj_op
.meta
.set_mtime
= set_mtime
;
3114 head_obj_op
.meta
.mtime
= mtime
;
3115 head_obj_op
.meta
.owner
= s
->owner
.get_id();
3116 head_obj_op
.meta
.delete_at
= delete_at
;
3117 head_obj_op
.meta
.zones_trace
= zones_trace
;
3118 head_obj_op
.meta
.modify_tail
= true;
3120 int r
= head_obj_op
.write_meta(obj_len
, accounted_size
, attrs
);
3125 RGWUploadPartInfo info
;
3127 bool sorted_omap
= is_v2_upload_id(upload_id
);
3131 int part_num_int
= strict_strtol(part_num
.c_str(), 10, &err
);
3133 dout(10) << "bad part number specified: " << part_num
<< dendl
;
3137 snprintf(buf
, sizeof(buf
), "%08d", part_num_int
);
3142 info
.num
= atoi(part_num
.c_str());
3144 info
.size
= obj_len
;
3145 info
.accounted_size
= accounted_size
;
3146 info
.modified
= real_clock::now();
3147 info
.manifest
= manifest
;
3150 r
= rgw_compression_info_from_attrset(attrs
, compressed
, info
.cs_info
);
3152 dout(1) << "cannot get compression info" << dendl
;
3158 string multipart_meta_obj
= mp
.get_meta();
3161 meta_obj
.init_ns(bucket
, multipart_meta_obj
, mp_ns
);
3162 meta_obj
.set_in_extra_data(true);
3164 rgw_raw_obj raw_meta_obj
;
3166 store
->obj_to_raw(s
->bucket_info
.placement_rule
, meta_obj
, &raw_meta_obj
);
3168 r
= store
->omap_set(raw_meta_obj
, p
, bl
);
3173 RGWPutObjProcessor
*RGWPutObj::select_processor(RGWObjectCtx
& obj_ctx
, bool *is_multipart
)
3175 RGWPutObjProcessor
*processor
;
3177 bool multipart
= s
->info
.args
.exists("uploadId");
3179 uint64_t part_size
= s
->cct
->_conf
->rgw_obj_stripe_size
;
3182 processor
= new RGWPutObjProcessor_Atomic(obj_ctx
, s
->bucket_info
, s
->bucket
, s
->object
.name
, part_size
, s
->req_id
, s
->bucket_info
.versioning_enabled());
3183 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_olh_epoch(olh_epoch
);
3184 (static_cast<RGWPutObjProcessor_Atomic
*>(processor
))->set_version_id(version_id
);
3186 processor
= new RGWPutObjProcessor_Multipart(obj_ctx
, s
->bucket_info
, part_size
, s
);
3190 *is_multipart
= multipart
;
3196 void RGWPutObj::dispose_processor(RGWPutObjDataProcessor
*processor
)
3201 void RGWPutObj::pre_exec()
3203 rgw_bucket_object_pre_exec(s
);
3206 class RGWPutObj_CB
: public RGWGetDataCB
3210 RGWPutObj_CB(RGWPutObj
*_op
) : op(_op
) {}
3211 ~RGWPutObj_CB() override
{}
3213 int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) override
{
3214 return op
->get_data_cb(bl
, bl_ofs
, bl_len
);
3218 int RGWPutObj::get_data_cb(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
)
3221 bl
.copy(bl_ofs
, bl_len
, bl_tmp
);
3223 bl_aux
.append(bl_tmp
);
3228 int RGWPutObj::get_data(const off_t fst
, const off_t lst
, bufferlist
& bl
)
3230 RGWPutObj_CB
cb(this);
3231 RGWGetDataCB
* filter
= &cb
;
3232 boost::optional
<RGWGetObj_Decompress
> decompress
;
3233 std::unique_ptr
<RGWGetDataCB
> decrypt
;
3234 RGWCompressionInfo cs_info
;
3235 map
<string
, bufferlist
> attrs
;
3236 map
<string
, bufferlist
>::iterator attr_iter
;
3240 int64_t new_ofs
, new_end
;
3245 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3246 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
);
3248 RGWRados::Object
op_target(store
, copy_source_bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
3249 RGWRados::Object::Read
read_op(&op_target
);
3250 read_op
.params
.obj_size
= &obj_size
;
3251 read_op
.params
.attrs
= &attrs
;
3253 ret
= read_op
.prepare();
3257 bool need_decompress
;
3258 op_ret
= rgw_compression_info_from_attrset(attrs
, need_decompress
, cs_info
);
3260 lderr(s
->cct
) << "ERROR: failed to decode compression info, cannot decompress" << dendl
;
3264 bool partial_content
= true;
3265 if (need_decompress
)
3267 obj_size
= cs_info
.orig_size
;
3268 decompress
.emplace(s
->cct
, &cs_info
, partial_content
, filter
);
3269 filter
= &*decompress
;
3272 attr_iter
= attrs
.find(RGW_ATTR_MANIFEST
);
3273 op_ret
= this->get_decrypt_filter(&decrypt
,
3276 attr_iter
!= attrs
.end() ? &(attr_iter
->second
) : nullptr);
3277 if (decrypt
!= nullptr) {
3278 filter
= decrypt
.get();
3284 ret
= read_op
.range_to_ofs(obj_size
, new_ofs
, new_end
);
3288 filter
->fixup_range(new_ofs
, new_end
);
3289 ret
= read_op
.iterate(new_ofs
, new_end
, filter
);
3292 ret
= filter
->flush();
3294 bl
.claim_append(bl_aux
);
3299 // special handling for compression type = "random" with multipart uploads
3300 static CompressorRef
get_compressor_plugin(const req_state
*s
,
3301 const std::string
& compression_type
)
3303 if (compression_type
!= "random") {
3304 return Compressor::create(s
->cct
, compression_type
);
3307 bool is_multipart
{false};
3308 const auto& upload_id
= s
->info
.args
.get("uploadId", &is_multipart
);
3310 if (!is_multipart
) {
3311 return Compressor::create(s
->cct
, compression_type
);
3314 // use a hash of the multipart upload id so all parts use the same plugin
3315 const auto alg
= std::hash
<std::string
>{}(upload_id
) % Compressor::COMP_ALG_LAST
;
3316 if (alg
== Compressor::COMP_ALG_NONE
) {
3319 return Compressor::create(s
->cct
, alg
);
3322 void RGWPutObj::execute()
3324 RGWPutObjProcessor
*processor
= NULL
;
3325 RGWPutObjDataProcessor
*filter
= nullptr;
3326 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3327 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3328 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3329 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3330 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3332 bufferlist bl
, aclbl
, bs
;
3334 map
<string
, string
>::iterator iter
;
3339 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3340 s
->bucket_info
.placement_rule
);
3341 CompressorRef plugin
;
3342 boost::optional
<RGWPutObj_Compress
> compressor
;
3344 bool need_calc_md5
= (dlo_manifest
== NULL
) && (slo_info
== NULL
);
3345 perfcounter
->inc(l_rgw_put
);
3347 if (s
->object
.empty()) {
3351 if (!s
->bucket_exists
) {
3352 op_ret
= -ERR_NO_SUCH_BUCKET
;
3356 op_ret
= get_params();
3358 ldout(s
->cct
, 20) << "get_params() returned ret=" << op_ret
<< dendl
;
3362 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
3364 ldout(s
->cct
, 20) << "get_system_versioning_params() returned ret="
3369 if (supplied_md5_b64
) {
3370 need_calc_md5
= true;
3372 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3373 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3374 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3375 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3376 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3377 op_ret
= -ERR_INVALID_DIGEST
;
3381 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3382 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3385 if (!chunked_upload
) { /* with chunked upload we don't know how big is the upload.
3386 we also check sizes at the end anyway */
3387 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3388 user_quota
, bucket_quota
, s
->content_length
);
3390 ldout(s
->cct
, 20) << "check_quota() returned ret=" << op_ret
<< dendl
;
3393 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3395 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3400 if (supplied_etag
) {
3401 strncpy(supplied_md5
, supplied_etag
, sizeof(supplied_md5
) - 1);
3402 supplied_md5
[sizeof(supplied_md5
) - 1] = '\0';
3405 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3407 // no filters by default
3410 /* Handle object versioning of Swift API. */
3412 rgw_obj
obj(s
->bucket
, s
->object
);
3413 op_ret
= store
->swift_versioning_copy(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3414 s
->bucket_owner
.get_id(),
3422 op_ret
= processor
->prepare(store
, NULL
);
3424 ldout(s
->cct
, 20) << "processor->prepare() returned ret=" << op_ret
3429 if ((! copy_source
.empty()) && !copy_source_range
) {
3430 rgw_obj_key
obj_key(copy_source_object_name
, copy_source_version_id
);
3431 rgw_obj
obj(copy_source_bucket_info
.bucket
, obj_key
.name
);
3433 RGWObjState
*astate
;
3434 op_ret
= store
->get_obj_state(static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3435 copy_source_bucket_info
, obj
, &astate
, true, false);
3437 ldout(s
->cct
, 0) << "ERROR: get copy source obj state returned with error" << op_ret
<< dendl
;
3440 if (!astate
->exists
){
3444 lst
= astate
->accounted_size
- 1;
3446 lst
= copy_source_range_lst
;
3449 fst
= copy_source_range_fst
;
3451 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3455 if (encrypt
!= nullptr) {
3456 filter
= encrypt
.get();
3458 //no encryption, we can try compression
3459 if (compression_type
!= "none") {
3460 plugin
= get_compressor_plugin(s
, compression_type
);
3462 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3463 << compression_type
<< dendl
;
3465 compressor
.emplace(s
->cct
, plugin
, filter
);
3466 filter
= &*compressor
;
3475 if (copy_source
.empty()) {
3476 len
= get_data(data
);
3478 uint64_t cur_lst
= min(fst
+ s
->cct
->_conf
->rgw_max_chunk_size
- 1, lst
);
3479 op_ret
= get_data(fst
, cur_lst
, data
);
3482 len
= data
.length();
3483 s
->content_length
+= len
;
3491 if (need_calc_md5
) {
3492 hash
.Update((const byte
*)data
.c_str(), data
.length());
3495 /* update torrrent */
3496 torrent
.update(data
);
3498 /* do we need this operation to be synchronous? if we're dealing with an object with immutable
3499 * head, e.g., multipart object we need to make sure we're the first one writing to this object
3501 bool need_to_wait
= (ofs
== 0) && multipart
;
3503 bufferlist orig_data
;
3509 op_ret
= put_data_and_throttle(filter
, data
, ofs
, need_to_wait
);
3511 if (op_ret
!= -EEXIST
) {
3512 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
3516 /* need_to_wait == true and op_ret == -EEXIST */
3517 ldout(s
->cct
, 5) << "NOTICE: processor->throttle_data() returned -EEXIST, need to restart write" << dendl
;
3519 /* restore original data */
3520 data
.swap(orig_data
);
3522 /* restart processing with different oid suffix */
3524 dispose_processor(processor
);
3525 processor
= select_processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
), &multipart
);
3530 gen_rand_alphanumeric(store
->ctx(), buf
, sizeof(buf
) - 1);
3531 oid_rand
.append(buf
);
3533 op_ret
= processor
->prepare(store
, &oid_rand
);
3535 ldout(s
->cct
, 0) << "ERROR: processor->prepare() returned "
3540 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3544 if (encrypt
!= nullptr) {
3545 filter
= encrypt
.get();
3548 compressor
.emplace(s
->cct
, plugin
, filter
);
3549 filter
= &*compressor
;
3552 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3563 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3569 if (!chunked_upload
&& ofs
!= s
->content_length
) {
3570 op_ret
= -ERR_REQUEST_TIMEOUT
;
3575 perfcounter
->inc(l_rgw_put_b
, s
->obj_size
);
3577 op_ret
= do_aws4_auth_completion();
3582 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3583 user_quota
, bucket_quota
, s
->obj_size
);
3585 ldout(s
->cct
, 20) << "second check_quota() returned op_ret=" << op_ret
<< dendl
;
3589 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3591 ldout(s
->cct
, 20) << "check_bucket_shards() returned ret=" << op_ret
<< dendl
;
3597 if (compressor
&& compressor
->is_compressed()) {
3599 RGWCompressionInfo cs_info
;
3600 cs_info
.compression_type
= plugin
->get_type_name();
3601 cs_info
.orig_size
= s
->obj_size
;
3602 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3603 ::encode(cs_info
, tmp
);
3604 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
3605 ldout(s
->cct
, 20) << "storing " << RGW_ATTR_COMPRESSION
3606 << " with type=" << cs_info
.compression_type
3607 << ", orig_size=" << cs_info
.orig_size
3608 << ", blocks=" << cs_info
.blocks
.size() << dendl
;
3611 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3615 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3616 op_ret
= -ERR_BAD_DIGEST
;
3620 policy
.encode(aclbl
);
3621 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3624 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
3626 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
3629 complete_etag(hash
, &etag
);
3630 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3634 bufferlist manifest_bl
;
3635 ::encode(*slo_info
, manifest_bl
);
3636 emplace_attr(RGW_ATTR_SLO_MANIFEST
, std::move(manifest_bl
));
3638 hash
.Update((byte
*)slo_info
->raw_data
, slo_info
->raw_data_len
);
3639 complete_etag(hash
, &etag
);
3640 ldout(s
->cct
, 10) << __func__
<< ": calculated md5 for user manifest: " << etag
<< dendl
;
3643 if (supplied_etag
&& etag
.compare(supplied_etag
) != 0) {
3644 op_ret
= -ERR_UNPROCESSABLE_ENTITY
;
3647 bl
.append(etag
.c_str(), etag
.size() + 1);
3648 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3650 populate_with_generic_attrs(s
, attrs
);
3651 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
3655 encode_delete_at_attr(delete_at
, attrs
);
3656 encode_obj_tags_attr(obj_tags
.get(), attrs
);
3658 /* Add a custom metadata to expose the information whether an object
3659 * is an SLO or not. Appending the attribute must be performed AFTER
3660 * processing any input from user in order to prohibit overwriting. */
3662 bufferlist slo_userindicator_bl
;
3663 slo_userindicator_bl
.append("True", 4);
3664 emplace_attr(RGW_ATTR_SLO_UINDICATOR
, std::move(slo_userindicator_bl
));
3667 op_ret
= processor
->complete(s
->obj_size
, etag
, &mtime
, real_time(), attrs
,
3668 (delete_at
? *delete_at
: real_time()), if_match
, if_nomatch
,
3669 (user_data
.empty() ? nullptr : &user_data
));
3671 /* produce torrent */
3672 if (s
->cct
->_conf
->rgw_torrent_flag
&& (ofs
== torrent
.get_data_len()))
3674 torrent
.init(s
, store
);
3675 torrent
.set_create_date(mtime
);
3676 op_ret
= torrent
.complete();
3679 ldout(s
->cct
, 0) << "ERROR: torrent.handle_data() returned " << op_ret
<< dendl
;
3685 dispose_processor(processor
);
3686 perfcounter
->tinc(l_rgw_put_lat
,
3687 (ceph_clock_now() - s
->time
));
3690 int RGWPostObj::verify_permission()
3695 RGWPutObjProcessor *RGWPostObj::select_processor(RGWObjectCtx& obj_ctx)
3697 RGWPutObjProcessor *processor;
3699 uint64_t part_size = s->cct->_conf->rgw_obj_stripe_size;
3701 processor = new RGWPutObjProcessor_Atomic(obj_ctx, s->bucket_info, s->bucket, s->object.name, part_size, s->req_id, s->bucket_info.versioning_enabled());
3706 void RGWPostObj::dispose_processor(RGWPutObjDataProcessor *processor)
3711 void RGWPostObj::pre_exec()
3713 rgw_bucket_object_pre_exec(s
);
3716 void RGWPostObj::execute()
3718 RGWPutObjDataProcessor
*filter
= nullptr;
3719 boost::optional
<RGWPutObj_Compress
> compressor
;
3720 CompressorRef plugin
;
3721 char supplied_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3723 /* Read in the data from the POST form. */
3724 op_ret
= get_params();
3729 op_ret
= verify_params();
3734 if (s
->iam_policy
) {
3735 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
3736 rgw::IAM::s3PutObject
,
3737 rgw_obj(s
->bucket
, s
->object
));
3738 if (e
== Effect::Deny
) {
3741 } else if (e
== Effect::Pass
&& !verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3745 } else if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
3750 /* Start iteration over data fields. It's necessary as Swift's FormPost
3751 * is capable to handle multiple files in single form. */
3753 std::unique_ptr
<RGWPutObjDataProcessor
> encrypt
;
3754 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
3755 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
3757 ceph::buffer::list bl
, aclbl
;
3760 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(),
3769 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3774 if (supplied_md5_b64
) {
3775 char supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1];
3776 ldout(s
->cct
, 15) << "supplied_md5_b64=" << supplied_md5_b64
<< dendl
;
3777 op_ret
= ceph_unarmor(supplied_md5_bin
, &supplied_md5_bin
[CEPH_CRYPTO_MD5_DIGESTSIZE
+ 1],
3778 supplied_md5_b64
, supplied_md5_b64
+ strlen(supplied_md5_b64
));
3779 ldout(s
->cct
, 15) << "ceph_armor ret=" << op_ret
<< dendl
;
3780 if (op_ret
!= CEPH_CRYPTO_MD5_DIGESTSIZE
) {
3781 op_ret
= -ERR_INVALID_DIGEST
;
3785 buf_to_hex((const unsigned char *)supplied_md5_bin
, CEPH_CRYPTO_MD5_DIGESTSIZE
, supplied_md5
);
3786 ldout(s
->cct
, 15) << "supplied_md5=" << supplied_md5
<< dendl
;
3789 RGWPutObjProcessor_Atomic
processor(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
3792 get_current_filename(),
3794 s
->cct
->_conf
->rgw_obj_stripe_size
,
3796 s
->bucket_info
.versioning_enabled());
3797 processor
.set_olh_epoch(0);
3798 /* No filters by default. */
3799 filter
= &processor
;
3801 op_ret
= processor
.prepare(store
, nullptr);
3806 op_ret
= get_encrypt_filter(&encrypt
, filter
);
3810 if (encrypt
!= nullptr) {
3811 filter
= encrypt
.get();
3813 const auto& compression_type
= store
->get_zone_params().get_compression_type(
3814 s
->bucket_info
.placement_rule
);
3815 if (compression_type
!= "none") {
3816 plugin
= Compressor::create(s
->cct
, compression_type
);
3818 ldout(s
->cct
, 1) << "Cannot load plugin for compression type "
3819 << compression_type
<< dendl
;
3821 compressor
.emplace(s
->cct
, plugin
, filter
);
3822 filter
= &*compressor
;
3829 ceph::bufferlist data
;
3830 len
= get_data(data
, again
);
3841 hash
.Update((const byte
*)data
.c_str(), data
.length());
3842 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
3846 if (ofs
> max_len
) {
3847 op_ret
= -ERR_TOO_LARGE
;
3854 op_ret
= put_data_and_throttle(filter
, flush
, ofs
, false);
3857 if (len
< min_len
) {
3858 op_ret
= -ERR_TOO_SMALL
;
3864 if (supplied_md5_b64
&& strcmp(calc_md5
, supplied_md5
)) {
3865 op_ret
= -ERR_BAD_DIGEST
;
3869 op_ret
= store
->check_quota(s
->bucket_owner
.get_id(), s
->bucket
,
3870 user_quota
, bucket_quota
, s
->obj_size
);
3875 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
3881 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
3884 bl
.append(etag
.c_str(), etag
.size() + 1);
3885 emplace_attr(RGW_ATTR_ETAG
, std::move(bl
));
3887 policy
.encode(aclbl
);
3888 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
3890 const std::string content_type
= get_current_content_type();
3891 if (! content_type
.empty()) {
3892 ceph::bufferlist ct_bl
;
3893 ct_bl
.append(content_type
.c_str(), content_type
.size() + 1);
3894 emplace_attr(RGW_ATTR_CONTENT_TYPE
, std::move(ct_bl
));
3897 if (compressor
&& compressor
->is_compressed()) {
3898 ceph::bufferlist tmp
;
3899 RGWCompressionInfo cs_info
;
3900 cs_info
.compression_type
= plugin
->get_type_name();
3901 cs_info
.orig_size
= s
->obj_size
;
3902 cs_info
.blocks
= move(compressor
->get_compression_blocks());
3903 ::encode(cs_info
, tmp
);
3904 emplace_attr(RGW_ATTR_COMPRESSION
, std::move(tmp
));
3907 op_ret
= processor
.complete(s
->obj_size
, etag
, nullptr, real_time(),
3908 attrs
, (delete_at
? *delete_at
: real_time()));
3909 } while (is_next_file_to_upload());
3913 void RGWPutMetadataAccount::filter_out_temp_url(map
<string
, bufferlist
>& add_attrs
,
3914 const set
<string
>& rmattr_names
,
3915 map
<int, string
>& temp_url_keys
)
3917 map
<string
, bufferlist
>::iterator iter
;
3919 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY1
);
3920 if (iter
!= add_attrs
.end()) {
3921 temp_url_keys
[0] = iter
->second
.c_str();
3922 add_attrs
.erase(iter
);
3925 iter
= add_attrs
.find(RGW_ATTR_TEMPURL_KEY2
);
3926 if (iter
!= add_attrs
.end()) {
3927 temp_url_keys
[1] = iter
->second
.c_str();
3928 add_attrs
.erase(iter
);
3931 for (const string
& name
: rmattr_names
) {
3932 if (name
.compare(RGW_ATTR_TEMPURL_KEY1
) == 0) {
3933 temp_url_keys
[0] = string();
3935 if (name
.compare(RGW_ATTR_TEMPURL_KEY2
) == 0) {
3936 temp_url_keys
[1] = string();
3941 int RGWPutMetadataAccount::init_processing()
3943 /* First, go to the base class. At the time of writing the method was
3944 * responsible only for initializing the quota. This isn't necessary
3945 * here as we are touching metadata only. I'm putting this call only
3946 * for the future. */
3947 op_ret
= RGWOp::init_processing();
3952 op_ret
= get_params();
3957 op_ret
= rgw_get_user_attrs_by_uid(store
, s
->user
->user_id
, orig_attrs
,
3965 policy
.encode(acl_bl
);
3966 attrs
.emplace(RGW_ATTR_ACL
, std::move(acl_bl
));
3969 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
3973 prepare_add_del_attrs(orig_attrs
, rmattr_names
, attrs
);
3974 populate_with_generic_attrs(s
, attrs
);
3976 /* Try extract the TempURL-related stuff now to allow verify_permission
3977 * evaluate whether we need FULL_CONTROL or not. */
3978 filter_out_temp_url(attrs
, rmattr_names
, temp_url_keys
);
3980 /* The same with quota except a client needs to be reseller admin. */
3981 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, new_quota
,
3982 &new_quota_extracted
);
3990 int RGWPutMetadataAccount::verify_permission()
3992 if (s
->auth
.identity
->is_anonymous()) {
3996 if (!verify_user_permission(s
, RGW_PERM_WRITE
)) {
4000 /* Altering TempURL keys requires FULL_CONTROL. */
4001 if (!temp_url_keys
.empty() && s
->perm_mask
!= RGW_PERM_FULL_CONTROL
) {
4005 /* We are failing this intensionally to allow system user/reseller admin
4006 * override in rgw_process.cc. This is the way to specify a given RGWOp
4007 * expect extra privileges. */
4008 if (new_quota_extracted
) {
4015 void RGWPutMetadataAccount::execute()
4017 /* Params have been extracted earlier. See init_processing(). */
4018 RGWUserInfo new_uinfo
;
4019 op_ret
= rgw_get_user_info_by_uid(store
, s
->user
->user_id
, new_uinfo
,
4025 /* Handle the TempURL-related stuff. */
4026 if (!temp_url_keys
.empty()) {
4027 for (auto& pair
: temp_url_keys
) {
4028 new_uinfo
.temp_url_keys
[pair
.first
] = std::move(pair
.second
);
4032 /* Handle the quota extracted at the verify_permission step. */
4033 if (new_quota_extracted
) {
4034 new_uinfo
.user_quota
= std::move(new_quota
);
4037 /* We are passing here the current (old) user info to allow the function
4038 * optimize-out some operations. */
4039 op_ret
= rgw_store_user_info(store
, new_uinfo
, s
->user
,
4040 &acct_op_tracker
, real_time(), false, &attrs
);
4043 int RGWPutMetadataBucket::verify_permission()
4045 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4052 void RGWPutMetadataBucket::pre_exec()
4054 rgw_bucket_object_pre_exec(s
);
4057 void RGWPutMetadataBucket::execute()
4059 op_ret
= get_params();
4064 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
, false);
4069 if (!placement_rule
.empty() &&
4070 placement_rule
!= s
->bucket_info
.placement_rule
) {
4075 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
4076 /* Encode special metadata first as we're using std::map::emplace under
4077 * the hood. This method will add the new items only if the map doesn't
4078 * contain such keys yet. */
4080 if (s
->dialect
.compare("swift") == 0) {
4082 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
4083 auto new_policy
= static_cast<RGWAccessControlPolicy_SWIFT
*>(&policy
);
4084 new_policy
->filter_merge(policy_rw_mask
, old_policy
);
4085 policy
= *new_policy
;
4089 emplace_attr(RGW_ATTR_ACL
, std::move(bl
));
4094 cors_config
.encode(bl
);
4095 emplace_attr(RGW_ATTR_CORS
, std::move(bl
));
4098 /* It's supposed that following functions WILL NOT change any
4099 * special attributes (like RGW_ATTR_ACL) if they are already
4100 * present in attrs. */
4101 prepare_add_del_attrs(s
->bucket_attrs
, rmattr_names
, attrs
);
4102 populate_with_generic_attrs(s
, attrs
);
4104 /* According to the Swift's behaviour and its container_quota
4105 * WSGI middleware implementation: anyone with write permissions
4106 * is able to set the bucket quota. This stays in contrast to
4107 * account quotas that can be set only by clients holding
4108 * reseller admin privileges. */
4109 op_ret
= filter_out_quota_info(attrs
, rmattr_names
, s
->bucket_info
.quota
);
4114 if (swift_ver_location
) {
4115 s
->bucket_info
.swift_ver_location
= *swift_ver_location
;
4116 s
->bucket_info
.swift_versioning
= (!swift_ver_location
->empty());
4119 /* Web site of Swift API. */
4120 filter_out_website(attrs
, rmattr_names
, s
->bucket_info
.website_conf
);
4121 s
->bucket_info
.has_website
= !s
->bucket_info
.website_conf
.is_empty();
4123 /* Setting attributes also stores the provided bucket info. Due
4124 * to this fact, the new quota settings can be serialized with
4126 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
4127 &s
->bucket_info
.objv_tracker
);
4132 int RGWPutMetadataObject::verify_permission()
4134 // This looks to be something specific to Swift. We could add
4135 // operations like swift:PutMetadataObject to the Policy Engine.
4136 if (!verify_object_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4143 void RGWPutMetadataObject::pre_exec()
4145 rgw_bucket_object_pre_exec(s
);
4148 void RGWPutMetadataObject::execute()
4150 rgw_obj
obj(s
->bucket
, s
->object
);
4151 map
<string
, bufferlist
> attrs
, orig_attrs
, rmattrs
;
4153 store
->set_atomic(s
->obj_ctx
, obj
);
4155 op_ret
= get_params();
4160 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4165 /* check if obj exists, read orig attrs */
4166 op_ret
= get_obj_attrs(store
, s
, obj
, orig_attrs
);
4171 /* Check whether the object has expired. Swift API documentation
4172 * stands that we should return 404 Not Found in such case. */
4173 if (need_object_expiration() && object_is_expired(orig_attrs
)) {
4178 /* Filter currently existing attributes. */
4179 prepare_add_del_attrs(orig_attrs
, attrs
, rmattrs
);
4180 populate_with_generic_attrs(s
, attrs
);
4181 encode_delete_at_attr(delete_at
, attrs
);
4184 op_ret
= encode_dlo_manifest_attr(dlo_manifest
, attrs
);
4186 ldout(s
->cct
, 0) << "bad user manifest: " << dlo_manifest
<< dendl
;
4191 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, &rmattrs
);
4194 int RGWDeleteObj::handle_slo_manifest(bufferlist
& bl
)
4196 RGWSLOInfo slo_info
;
4197 bufferlist::iterator bliter
= bl
.begin();
4199 ::decode(slo_info
, bliter
);
4200 } catch (buffer::error
& err
) {
4201 ldout(s
->cct
, 0) << "ERROR: failed to decode slo manifest" << dendl
;
4206 deleter
= std::unique_ptr
<RGWBulkDelete::Deleter
>(\
4207 new RGWBulkDelete::Deleter(store
, s
));
4208 } catch (std::bad_alloc
) {
4212 list
<RGWBulkDelete::acct_path_t
> items
;
4213 for (const auto& iter
: slo_info
.entries
) {
4214 const string
& path_str
= iter
.path
;
4216 const size_t sep_pos
= path_str
.find('/', 1 /* skip first slash */);
4217 if (boost::string_view::npos
== sep_pos
) {
4221 RGWBulkDelete::acct_path_t path
;
4223 path
.bucket_name
= url_decode(path_str
.substr(1, sep_pos
- 1));
4224 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
4226 items
.push_back(path
);
4229 /* Request removal of the manifest object itself. */
4230 RGWBulkDelete::acct_path_t path
;
4231 path
.bucket_name
= s
->bucket_name
;
4232 path
.obj_key
= s
->object
;
4233 items
.push_back(path
);
4235 int ret
= deleter
->delete_chunk(items
);
4243 int RGWDeleteObj::verify_permission()
4245 if (s
->iam_policy
) {
4246 auto r
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
4247 s
->object
.instance
.empty() ?
4248 rgw::IAM::s3DeleteObject
:
4249 rgw::IAM::s3DeleteObjectVersion
,
4250 ARN(s
->bucket
, s
->object
.name
));
4251 if (r
== Effect::Allow
)
4253 else if (r
== Effect::Deny
)
4257 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
4264 void RGWDeleteObj::pre_exec()
4266 rgw_bucket_object_pre_exec(s
);
4269 void RGWDeleteObj::execute()
4271 if (!s
->bucket_exists
) {
4272 op_ret
= -ERR_NO_SUCH_BUCKET
;
4276 op_ret
= get_params();
4281 rgw_obj
obj(s
->bucket
, s
->object
);
4282 map
<string
, bufferlist
> attrs
;
4285 if (!s
->object
.empty()) {
4286 if (need_object_expiration() || multipart_delete
) {
4287 /* check if obj exists, read orig attrs */
4288 op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
4294 if (multipart_delete
) {
4295 const auto slo_attr
= attrs
.find(RGW_ATTR_SLO_MANIFEST
);
4297 if (slo_attr
!= attrs
.end()) {
4298 op_ret
= handle_slo_manifest(slo_attr
->second
);
4300 ldout(s
->cct
, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret
<< dendl
;
4303 op_ret
= -ERR_NOT_SLO_MANIFEST
;
4309 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4310 obj_ctx
->obj
.set_atomic(obj
);
4312 bool ver_restored
= false;
4313 op_ret
= store
->swift_versioning_restore(*obj_ctx
, s
->bucket_owner
.get_id(),
4314 s
->bucket_info
, obj
, ver_restored
);
4319 if (!ver_restored
) {
4320 /* Swift's versioning mechanism hasn't found any previous version of
4321 * the object that could be restored. This means we should proceed
4322 * with the regular delete path. */
4323 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
4324 RGWRados::Object::Delete
del_op(&del_target
);
4326 op_ret
= get_system_versioning_params(s
, &del_op
.params
.olh_epoch
,
4327 &del_op
.params
.marker_version_id
);
4332 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
4333 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
4334 del_op
.params
.obj_owner
= s
->owner
;
4335 del_op
.params
.unmod_since
= unmod_since
;
4336 del_op
.params
.high_precision_time
= s
->system_request
; /* system request uses high precision time */
4338 op_ret
= del_op
.delete_obj();
4340 delete_marker
= del_op
.result
.delete_marker
;
4341 version_id
= del_op
.result
.version_id
;
4344 /* Check whether the object has expired. Swift API documentation
4345 * stands that we should return 404 Not Found in such case. */
4346 if (need_object_expiration() && object_is_expired(attrs
)) {
4352 if (op_ret
== -ECANCELED
) {
4355 if (op_ret
== -ERR_PRECONDITION_FAILED
&& no_precondition_error
) {
4363 bool RGWCopyObj::parse_copy_location(const boost::string_view
& url_src
,
4364 string
& bucket_name
,
4367 boost::string_view name_str
;
4368 boost::string_view params_str
;
4370 size_t pos
= url_src
.find('?');
4371 if (pos
== string::npos
) {
4374 name_str
= url_src
.substr(0, pos
);
4375 params_str
= url_src
.substr(pos
+ 1);
4378 boost::string_view dec_src
{name_str
};
4379 if (dec_src
[0] == '/')
4380 dec_src
.remove_prefix(1);
4382 pos
= dec_src
.find('/');
4383 if (pos
==string::npos
)
4386 boost::string_view bn_view
{dec_src
.substr(0, pos
)};
4387 bucket_name
= std::string
{bn_view
.data(), bn_view
.size()};
4389 boost::string_view kn_view
{dec_src
.substr(pos
+ 1)};
4390 key
.name
= std::string
{kn_view
.data(), kn_view
.size()};
4392 if (key
.name
.empty()) {
4396 if (! params_str
.empty()) {
4398 args
.set(params_str
.to_string());
4401 key
.instance
= args
.get("versionId", NULL
);
4407 int RGWCopyObj::verify_permission()
4409 RGWAccessControlPolicy
src_acl(s
->cct
);
4410 optional
<Policy
> src_policy
;
4411 op_ret
= get_params();
4415 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
4419 map
<string
, bufferlist
> src_attrs
;
4421 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4423 if (s
->bucket_instance_id
.empty()) {
4424 op_ret
= store
->get_bucket_info(obj_ctx
, src_tenant_name
, src_bucket_name
, src_bucket_info
, NULL
, &src_attrs
);
4426 /* will only happen in intra region sync where the source and dest bucket is the same */
4427 op_ret
= store
->get_bucket_instance_info(obj_ctx
, s
->bucket_instance_id
, src_bucket_info
, NULL
, &src_attrs
);
4430 if (op_ret
== -ENOENT
) {
4431 op_ret
= -ERR_NO_SUCH_BUCKET
;
4436 src_bucket
= src_bucket_info
.bucket
;
4438 /* get buckets info (source and dest) */
4439 if (s
->local_source
&& source_zone
.empty()) {
4440 rgw_obj
src_obj(src_bucket
, src_object
);
4441 store
->set_atomic(s
->obj_ctx
, src_obj
);
4442 store
->set_prefetch_data(s
->obj_ctx
, src_obj
);
4444 /* check source object permissions */
4445 op_ret
= read_obj_policy(store
, s
, src_bucket_info
, src_attrs
, &src_acl
,
4446 src_policy
, src_bucket
, src_object
);
4451 /* admin request overrides permission checks */
4452 if (!s
->auth
.identity
->is_admin_of(src_acl
.get_owner().get_id())) {
4454 auto e
= src_policy
->eval(s
->env
, *s
->auth
.identity
,
4455 src_object
.instance
.empty() ?
4456 rgw::IAM::s3GetObject
:
4457 rgw::IAM::s3GetObjectVersion
,
4459 if (e
== Effect::Deny
) {
4461 } else if (e
== Effect::Pass
&&
4462 !src_acl
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4466 } else if (!src_acl
.verify_permission(*s
->auth
.identity
,
4474 RGWAccessControlPolicy
dest_bucket_policy(s
->cct
);
4475 map
<string
, bufferlist
> dest_attrs
;
4477 if (src_bucket_name
.compare(dest_bucket_name
) == 0) { /* will only happen if s->local_source
4478 or intra region sync */
4479 dest_bucket_info
= src_bucket_info
;
4480 dest_attrs
= src_attrs
;
4482 op_ret
= store
->get_bucket_info(obj_ctx
, dest_tenant_name
, dest_bucket_name
,
4483 dest_bucket_info
, nullptr, &dest_attrs
);
4485 if (op_ret
== -ENOENT
) {
4486 op_ret
= -ERR_NO_SUCH_BUCKET
;
4492 dest_bucket
= dest_bucket_info
.bucket
;
4494 rgw_obj
dest_obj(dest_bucket
, dest_object
);
4495 store
->set_atomic(s
->obj_ctx
, dest_obj
);
4497 /* check dest bucket permissions */
4498 op_ret
= read_bucket_policy(store
, s
, dest_bucket_info
, dest_attrs
,
4499 &dest_bucket_policy
, dest_bucket
);
4504 /* admin request overrides permission checks */
4505 if (! s
->auth
.identity
->is_admin_of(dest_policy
.get_owner().get_id()) &&
4506 ! dest_bucket_policy
.verify_permission(*s
->auth
.identity
, s
->perm_mask
,
4511 op_ret
= init_dest_policy();
4520 int RGWCopyObj::init_common()
4523 if (parse_time(if_mod
, &mod_time
) < 0) {
4527 mod_ptr
= &mod_time
;
4531 if (parse_time(if_unmod
, &unmod_time
) < 0) {
4535 unmod_ptr
= &unmod_time
;
4539 dest_policy
.encode(aclbl
);
4540 emplace_attr(RGW_ATTR_ACL
, std::move(aclbl
));
4542 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
4546 populate_with_generic_attrs(s
, attrs
);
4551 static void copy_obj_progress_cb(off_t ofs
, void *param
)
4553 RGWCopyObj
*op
= static_cast<RGWCopyObj
*>(param
);
4554 op
->progress_cb(ofs
);
4557 void RGWCopyObj::progress_cb(off_t ofs
)
4559 if (!s
->cct
->_conf
->rgw_copy_obj_progress
)
4562 if (ofs
- last_ofs
< s
->cct
->_conf
->rgw_copy_obj_progress_every_bytes
)
4565 send_partial_response(ofs
);
4570 void RGWCopyObj::pre_exec()
4572 rgw_bucket_object_pre_exec(s
);
4575 void RGWCopyObj::execute()
4577 if (init_common() < 0)
4580 rgw_obj
src_obj(src_bucket
, src_object
);
4581 rgw_obj
dst_obj(dest_bucket
, dest_object
);
4583 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
4584 obj_ctx
.obj
.set_atomic(src_obj
);
4585 obj_ctx
.obj
.set_atomic(dst_obj
);
4587 encode_delete_at_attr(delete_at
, attrs
);
4589 bool high_precision_time
= (s
->system_request
);
4591 /* Handle object versioning of Swift API. In case of copying to remote this
4592 * should fail gently (op_ret == 0) as the dst_obj will not exist here. */
4593 op_ret
= store
->swift_versioning_copy(obj_ctx
,
4594 dest_bucket_info
.owner
,
4601 op_ret
= store
->copy_obj(obj_ctx
,
4615 high_precision_time
,
4620 attrs
, RGW_OBJ_CATEGORY_MAIN
,
4622 (delete_at
? *delete_at
: real_time()),
4623 (version_id
.empty() ? NULL
: &version_id
),
4624 &s
->req_id
, /* use req_id as tag */
4626 copy_obj_progress_cb
, (void *)this
4630 int RGWGetACLs::verify_permission()
4633 if (!s
->object
.empty()) {
4634 perm
= verify_object_permission(s
,
4635 s
->object
.instance
.empty() ?
4636 rgw::IAM::s3GetObjectAcl
:
4637 rgw::IAM::s3GetObjectVersionAcl
);
4639 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetBucketAcl
);
4647 void RGWGetACLs::pre_exec()
4649 rgw_bucket_object_pre_exec(s
);
4652 void RGWGetACLs::execute()
4655 RGWAccessControlPolicy
* const acl
= \
4656 (!s
->object
.empty() ? s
->object_acl
.get() : s
->bucket_acl
.get());
4657 RGWAccessControlPolicy_S3
* const s3policy
= \
4658 static_cast<RGWAccessControlPolicy_S3
*>(acl
);
4659 s3policy
->to_xml(ss
);
4665 int RGWPutACLs::verify_permission()
4668 if (!s
->object
.empty()) {
4669 perm
= verify_object_permission(s
,
4670 s
->object
.instance
.empty() ?
4671 rgw::IAM::s3PutObjectAcl
:
4672 rgw::IAM::s3PutObjectVersionAcl
);
4674 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutBucketAcl
);
4682 int RGWGetLC::verify_permission()
4685 perm
= verify_bucket_permission(s
, rgw::IAM::s3GetLifecycleConfiguration
);
4692 int RGWPutLC::verify_permission()
4695 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4702 int RGWDeleteLC::verify_permission()
4705 perm
= verify_bucket_permission(s
, rgw::IAM::s3PutLifecycleConfiguration
);
4712 void RGWPutACLs::pre_exec()
4714 rgw_bucket_object_pre_exec(s
);
4717 void RGWGetLC::pre_exec()
4719 rgw_bucket_object_pre_exec(s
);
4722 void RGWPutLC::pre_exec()
4724 rgw_bucket_object_pre_exec(s
);
4727 void RGWDeleteLC::pre_exec()
4729 rgw_bucket_object_pre_exec(s
);
4732 void RGWPutACLs::execute()
4736 RGWAccessControlPolicy_S3
*policy
= NULL
;
4737 RGWACLXMLParser_S3
parser(s
->cct
);
4738 RGWAccessControlPolicy_S3
new_policy(s
->cct
);
4740 char *new_data
= NULL
;
4743 op_ret
= 0; /* XXX redundant? */
4745 if (!parser
.init()) {
4751 RGWAccessControlPolicy
* const existing_policy
= \
4752 (s
->object
.empty() ? s
->bucket_acl
.get() : s
->object_acl
.get());
4754 owner
= existing_policy
->get_owner();
4756 op_ret
= get_params();
4758 if (op_ret
== -ERANGE
) {
4759 ldout(s
->cct
, 4) << "The size of request xml data is larger than the max limitation, data size = "
4760 << s
->length
<< dendl
;
4761 op_ret
= -ERR_MALFORMED_XML
;
4762 s
->err
.message
= "The XML you provided was larger than the maximum " +
4763 std::to_string(s
->cct
->_conf
->rgw_max_put_param_size
) +
4769 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4771 if (!s
->canned_acl
.empty() && len
) {
4776 if (!s
->canned_acl
.empty() || s
->has_acl_header
) {
4777 op_ret
= get_policy_from_state(store
, s
, ss
);
4781 new_data
= strdup(ss
.str().c_str());
4784 len
= ss
.str().size();
4787 if (!parser
.parse(data
, len
, 1)) {
4791 policy
= static_cast<RGWAccessControlPolicy_S3
*>(parser
.find_first("AccessControlPolicy"));
4797 const RGWAccessControlList
& req_acl
= policy
->get_acl();
4798 const multimap
<string
, ACLGrant
>& req_grant_map
= req_acl
.get_grant_map();
4799 #define ACL_GRANTS_MAX_NUM 100
4800 int max_num
= s
->cct
->_conf
->rgw_acl_grants_max_num
;
4802 max_num
= ACL_GRANTS_MAX_NUM
;
4805 int grants_num
= req_grant_map
.size();
4806 if (grants_num
> max_num
) {
4807 ldout(s
->cct
, 4) << "An acl can have up to "
4809 << " grants, request acl grants num: "
4810 << grants_num
<< dendl
;
4811 op_ret
= -ERR_MALFORMED_ACL_ERROR
;
4812 s
->err
.message
= "The request is rejected, because the acl grants number you requested is larger than the maximum "
4813 + std::to_string(max_num
)
4814 + " grants allowed in an acl.";
4818 // forward bucket acl requests to meta master zone
4819 if (s
->object
.empty() && !store
->is_meta_master()) {
4821 // include acl data unless it was generated from a canned_acl
4822 if (s
->canned_acl
.empty()) {
4823 in_data
.append(data
, len
);
4825 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, NULL
);
4827 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
4832 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4833 ldout(s
->cct
, 15) << "Old AccessControlPolicy";
4834 policy
->to_xml(*_dout
);
4838 op_ret
= policy
->rebuild(store
, &owner
, new_policy
);
4842 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4843 ldout(s
->cct
, 15) << "New AccessControlPolicy:";
4844 new_policy
.to_xml(*_dout
);
4848 new_policy
.encode(bl
);
4849 map
<string
, bufferlist
> attrs
;
4851 if (!s
->object
.empty()) {
4852 obj
= rgw_obj(s
->bucket
, s
->object
);
4853 store
->set_atomic(s
->obj_ctx
, obj
);
4854 //if instance is empty, we should modify the latest object
4855 op_ret
= modify_obj_attr(store
, s
, obj
, RGW_ATTR_ACL
, bl
);
4857 attrs
= s
->bucket_attrs
;
4858 attrs
[RGW_ATTR_ACL
] = bl
;
4859 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4861 if (op_ret
== -ECANCELED
) {
4862 op_ret
= 0; /* lost a race, but it's ok because acls are immutable */
4866 static void get_lc_oid(struct req_state
*s
, string
& oid
)
4868 string shard_id
= s
->bucket
.name
+ ':' +s
->bucket
.bucket_id
;
4869 int max_objs
= (s
->cct
->_conf
->rgw_lc_max_objs
> HASH_PRIME
)?HASH_PRIME
:s
->cct
->_conf
->rgw_lc_max_objs
;
4870 int index
= ceph_str_hash_linux(shard_id
.c_str(), shard_id
.size()) % HASH_PRIME
% max_objs
;
4871 oid
= lc_oid_prefix
;
4873 snprintf(buf
, 32, ".%d", index
);
4878 void RGWPutLC::execute()
4882 RGWLifecycleConfiguration_S3
*config
= NULL
;
4883 RGWLCXMLParser_S3
parser(s
->cct
);
4884 RGWLifecycleConfiguration_S3
new_config(s
->cct
);
4886 content_md5
= s
->info
.env
->get("HTTP_CONTENT_MD5");
4887 if (content_md5
== nullptr) {
4888 op_ret
= -ERR_INVALID_REQUEST
;
4889 s
->err
.message
= "Missing required header for this request: Content-MD5";
4890 ldout(s
->cct
, 5) << s
->err
.message
<< dendl
;
4894 std::string content_md5_bin
;
4896 content_md5_bin
= rgw::from_base64(boost::string_view(content_md5
));
4898 s
->err
.message
= "Request header Content-MD5 contains character "
4899 "that is not base64 encoded.";
4900 ldout(s
->cct
, 5) << s
->err
.message
<< dendl
;
4901 op_ret
= -ERR_BAD_DIGEST
;
4905 if (!parser
.init()) {
4910 op_ret
= get_params();
4914 ldout(s
->cct
, 15) << "read len=" << len
<< " data=" << (data
? data
: "") << dendl
;
4917 unsigned char data_hash_res
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
4918 data_hash
.Update(reinterpret_cast<const byte
*>(data
), len
);
4919 data_hash
.Final(data_hash_res
);
4921 if (memcmp(data_hash_res
, content_md5_bin
.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE
) != 0) {
4922 op_ret
= -ERR_BAD_DIGEST
;
4923 s
->err
.message
= "The Content-MD5 you specified did not match what we received.";
4924 ldout(s
->cct
, 5) << s
->err
.message
4925 << " Specified content md5: " << content_md5
4926 << ", calculated content md5: " << data_hash_res
4931 if (!parser
.parse(data
, len
, 1)) {
4932 op_ret
= -ERR_MALFORMED_XML
;
4935 config
= static_cast<RGWLifecycleConfiguration_S3
*>(parser
.find_first("LifecycleConfiguration"));
4937 op_ret
= -ERR_MALFORMED_XML
;
4941 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4942 ldout(s
->cct
, 15) << "Old LifecycleConfiguration:";
4943 config
->to_xml(*_dout
);
4947 op_ret
= config
->rebuild(store
, new_config
);
4951 if (s
->cct
->_conf
->subsys
.should_gather(ceph_subsys_rgw
, 15)) {
4952 ldout(s
->cct
, 15) << "New LifecycleConfiguration:";
4953 new_config
.to_xml(*_dout
);
4957 new_config
.encode(bl
);
4958 map
<string
, bufferlist
> attrs
;
4959 attrs
= s
->bucket_attrs
;
4960 attrs
[RGW_ATTR_LC
] = bl
;
4961 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
4964 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
4967 pair
<string
, int> entry(shard_id
, lc_uninitial
);
4968 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
4969 rados::cls::lock::Lock
l(lc_index_lock_name
);
4970 utime_t
time(max_lock_secs
, 0);
4971 l
.set_duration(time
);
4972 l
.set_cookie(cookie
);
4973 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
4975 op_ret
= l
.lock_exclusive(ctx
, oid
);
4976 if (op_ret
== -EBUSY
) {
4977 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
4982 dout(0) << "RGWLC::RGWPutLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
4985 op_ret
= cls_rgw_lc_set_entry(*ctx
, oid
, entry
);
4987 dout(0) << "RGWLC::RGWPutLC() failed to set entry " << oid
<< op_ret
<< dendl
;
4995 void RGWDeleteLC::execute()
4998 map
<string
, bufferlist
> orig_attrs
, attrs
;
4999 map
<string
, bufferlist
>::iterator iter
;
5001 store
->get_bucket_instance_obj(s
->bucket
, obj
);
5002 store
->set_prefetch_data(s
->obj_ctx
, obj
);
5003 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
5007 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
5008 const string
& name
= iter
->first
;
5009 dout(10) << "DeleteLC : attr: " << name
<< dendl
;
5010 if (name
.compare(0, (sizeof(RGW_ATTR_LC
) - 1), RGW_ATTR_LC
) != 0) {
5011 if (attrs
.find(name
) == attrs
.end()) {
5012 attrs
[name
] = iter
->second
;
5016 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5017 string shard_id
= s
->bucket
.tenant
+ ':' + s
->bucket
.name
+ ':' + s
->bucket
.bucket_id
;
5018 pair
<string
, int> entry(shard_id
, lc_uninitial
);
5021 int max_lock_secs
= s
->cct
->_conf
->rgw_lc_lock_max_time
;
5022 librados::IoCtx
*ctx
= store
->get_lc_pool_ctx();
5023 rados::cls::lock::Lock
l(lc_index_lock_name
);
5024 utime_t
time(max_lock_secs
, 0);
5025 l
.set_duration(time
);
5027 op_ret
= l
.lock_exclusive(ctx
, oid
);
5028 if (op_ret
== -EBUSY
) {
5029 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock on, sleep 5, try again" << oid
<< dendl
;
5034 dout(0) << "RGWLC::RGWDeleteLC() failed to acquire lock " << oid
<< op_ret
<< dendl
;
5037 op_ret
= cls_rgw_lc_rm_entry(*ctx
, oid
, entry
);
5039 dout(0) << "RGWLC::RGWDeleteLC() failed to set entry " << oid
<< op_ret
<< dendl
;
5047 int RGWGetCORS::verify_permission()
5049 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketCORS
);
5052 void RGWGetCORS::execute()
5054 op_ret
= read_bucket_cors();
5059 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5065 int RGWPutCORS::verify_permission()
5067 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5070 void RGWPutCORS::execute()
5074 op_ret
= get_params();
5078 if (!store
->is_meta_master()) {
5079 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
5081 ldout(s
->cct
, 20) << __func__
<< "forward_request_to_master returned ret=" << op_ret
<< dendl
;
5086 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5087 map
<string
, bufferlist
> attrs
= s
->bucket_attrs
;
5088 attrs
[RGW_ATTR_CORS
] = cors_bl
;
5089 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
, &s
->bucket_info
.objv_tracker
);
5093 int RGWDeleteCORS::verify_permission()
5095 // No separate delete permission
5096 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketCORS
);
5099 void RGWDeleteCORS::execute()
5101 op_ret
= read_bucket_cors();
5107 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5111 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
5113 store
->get_bucket_instance_obj(s
->bucket
, obj
);
5114 store
->set_prefetch_data(s
->obj_ctx
, obj
);
5115 map
<string
, bufferlist
> orig_attrs
, attrs
, rmattrs
;
5116 map
<string
, bufferlist
>::iterator iter
;
5118 op_ret
= get_system_obj_attrs(store
, s
, obj
, orig_attrs
, NULL
, &s
->bucket_info
.objv_tracker
);
5122 /* only remove meta attrs */
5123 for (iter
= orig_attrs
.begin(); iter
!= orig_attrs
.end(); ++iter
) {
5124 const string
& name
= iter
->first
;
5125 dout(10) << "DeleteCORS : attr: " << name
<< dendl
;
5126 if (name
.compare(0, (sizeof(RGW_ATTR_CORS
) - 1), RGW_ATTR_CORS
) == 0) {
5127 rmattrs
[name
] = iter
->second
;
5128 } else if (attrs
.find(name
) == attrs
.end()) {
5129 attrs
[name
] = iter
->second
;
5132 return rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
5133 &s
->bucket_info
.objv_tracker
);
5137 void RGWOptionsCORS::get_response_params(string
& hdrs
, string
& exp_hdrs
, unsigned *max_age
) {
5138 get_cors_response_headers(rule
, req_hdrs
, hdrs
, exp_hdrs
, max_age
);
5141 int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration
*cc
) {
5142 rule
= cc
->host_name_rule(origin
);
5144 dout(10) << "There is no cors rule present for " << origin
<< dendl
;
5148 if (!validate_cors_rule_method(rule
, req_meth
)) {
5152 if (!validate_cors_rule_header(rule
, req_hdrs
)) {
5159 void RGWOptionsCORS::execute()
5161 op_ret
= read_bucket_cors();
5165 origin
= s
->info
.env
->get("HTTP_ORIGIN");
5168 "Preflight request without mandatory Origin header"
5173 req_meth
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
5176 "Preflight request without mandatory Access-control-request-method header"
5182 dout(2) << "No CORS configuration set yet for this bucket" << dendl
;
5186 req_hdrs
= s
->info
.env
->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS");
5187 op_ret
= validate_cors_request(&bucket_cors
);
5189 origin
= req_meth
= NULL
;
5195 int RGWGetRequestPayment::verify_permission()
5197 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3GetBucketRequestPayment
);
5200 void RGWGetRequestPayment::pre_exec()
5202 rgw_bucket_object_pre_exec(s
);
5205 void RGWGetRequestPayment::execute()
5207 requester_pays
= s
->bucket_info
.requester_pays
;
5210 int RGWSetRequestPayment::verify_permission()
5212 return verify_bucket_owner_or_policy(s
, rgw::IAM::s3PutBucketRequestPayment
);
5215 void RGWSetRequestPayment::pre_exec()
5217 rgw_bucket_object_pre_exec(s
);
5220 void RGWSetRequestPayment::execute()
5222 op_ret
= get_params();
5227 s
->bucket_info
.requester_pays
= requester_pays
;
5228 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(),
5231 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
5232 << " returned err=" << op_ret
<< dendl
;
5237 int RGWInitMultipart::verify_permission()
5239 if (s
->iam_policy
) {
5240 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5241 rgw::IAM::s3PutObject
,
5242 rgw_obj(s
->bucket
, s
->object
));
5243 if (e
== Effect::Allow
) {
5245 } else if (e
== Effect::Deny
) {
5250 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5257 void RGWInitMultipart::pre_exec()
5259 rgw_bucket_object_pre_exec(s
);
5262 void RGWInitMultipart::execute()
5265 map
<string
, bufferlist
> attrs
;
5268 if (get_params() < 0)
5271 if (s
->object
.empty())
5274 policy
.encode(aclbl
);
5275 attrs
[RGW_ATTR_ACL
] = aclbl
;
5277 populate_with_generic_attrs(s
, attrs
);
5279 /* select encryption mode */
5280 op_ret
= prepare_encryption(attrs
);
5284 op_ret
= rgw_get_request_metadata(s
->cct
, s
->info
, attrs
);
5291 gen_rand_alphanumeric(s
->cct
, buf
, sizeof(buf
) - 1);
5292 upload_id
= MULTIPART_UPLOAD_ID_PREFIX
; /* v2 upload id */
5293 upload_id
.append(buf
);
5295 string tmp_obj_name
;
5296 RGWMPObj
mp(s
->object
.name
, upload_id
);
5297 tmp_obj_name
= mp
.get_meta();
5299 obj
.init_ns(s
->bucket
, tmp_obj_name
, mp_ns
);
5300 // the meta object will be indexed with 0 size, we c
5301 obj
.set_in_extra_data(true);
5302 obj
.index_hash_source
= s
->object
.name
;
5304 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), obj
);
5305 op_target
.set_versioning_disabled(true); /* no versioning for multipart meta */
5307 RGWRados::Object::Write
obj_op(&op_target
);
5309 obj_op
.meta
.owner
= s
->owner
.get_id();
5310 obj_op
.meta
.category
= RGW_OBJ_CATEGORY_MULTIMETA
;
5311 obj_op
.meta
.flags
= PUT_OBJ_CREATE_EXCL
;
5313 op_ret
= obj_op
.write_meta(0, 0, attrs
);
5314 } while (op_ret
== -EEXIST
);
5317 static int get_multipart_info(RGWRados
*store
, struct req_state
*s
,
5319 RGWAccessControlPolicy
*policy
,
5320 map
<string
, bufferlist
>& attrs
)
5322 map
<string
, bufferlist
>::iterator iter
;
5326 obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5327 obj
.set_in_extra_data(true);
5329 int op_ret
= get_obj_attrs(store
, s
, obj
, attrs
);
5331 if (op_ret
== -ENOENT
) {
5332 return -ERR_NO_SUCH_UPLOAD
;
5338 for (iter
= attrs
.begin(); iter
!= attrs
.end(); ++iter
) {
5339 string name
= iter
->first
;
5340 if (name
.compare(RGW_ATTR_ACL
) == 0) {
5341 bufferlist
& bl
= iter
->second
;
5342 bufferlist::iterator bli
= bl
.begin();
5344 ::decode(*policy
, bli
);
5345 } catch (buffer::error
& err
) {
5346 ldout(s
->cct
, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl
;
5357 int RGWCompleteMultipart::verify_permission()
5359 if (s
->iam_policy
) {
5360 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5361 rgw::IAM::s3PutObject
,
5362 rgw_obj(s
->bucket
, s
->object
));
5363 if (e
== Effect::Allow
) {
5365 } else if (e
== Effect::Deny
) {
5370 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5377 void RGWCompleteMultipart::pre_exec()
5379 rgw_bucket_object_pre_exec(s
);
5382 void RGWCompleteMultipart::execute()
5384 RGWMultiCompleteUpload
*parts
;
5385 map
<int, string
>::iterator iter
;
5386 RGWMultiXMLParser parser
;
5388 map
<uint32_t, RGWUploadPartInfo
> obj_parts
;
5389 map
<uint32_t, RGWUploadPartInfo
>::iterator obj_iter
;
5390 map
<string
, bufferlist
> attrs
;
5393 char final_etag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5394 char final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 16];
5399 RGWObjManifest manifest
;
5400 uint64_t olh_epoch
= 0;
5403 op_ret
= get_params();
5406 op_ret
= get_system_versioning_params(s
, &olh_epoch
, &version_id
);
5411 if (!data
|| !len
) {
5412 op_ret
= -ERR_MALFORMED_XML
;
5416 if (!parser
.init()) {
5421 if (!parser
.parse(data
, len
, 1)) {
5422 op_ret
= -ERR_MALFORMED_XML
;
5426 parts
= static_cast<RGWMultiCompleteUpload
*>(parser
.find_first("CompleteMultipartUpload"));
5427 if (!parts
|| parts
->parts
.empty()) {
5428 op_ret
= -ERR_MALFORMED_XML
;
5432 if ((int)parts
->parts
.size() >
5433 s
->cct
->_conf
->rgw_multipart_part_upload_limit
) {
5438 mp
.init(s
->object
.name
, upload_id
);
5439 meta_oid
= mp
.get_meta();
5441 int total_parts
= 0;
5442 int handled_parts
= 0;
5443 int max_parts
= 1000;
5446 RGWCompressionInfo cs_info
;
5447 bool compressed
= false;
5448 uint64_t accounted_size
= 0;
5450 uint64_t min_part_size
= s
->cct
->_conf
->rgw_multipart_min_part_size
;
5452 list
<rgw_obj_index_key
> remove_objs
; /* objects to be removed from index listing */
5454 bool versioned_object
= s
->bucket_info
.versioning_enabled();
5456 iter
= parts
->parts
.begin();
5458 meta_obj
.init_ns(s
->bucket
, meta_oid
, mp_ns
);
5459 meta_obj
.set_in_extra_data(true);
5460 meta_obj
.index_hash_source
= s
->object
.name
;
5462 /*take a cls lock on meta_obj to prevent racing completions (or retries)
5463 from deleting the parts*/
5465 rgw_raw_obj raw_obj
;
5466 int max_lock_secs_mp
=
5467 s
->cct
->_conf
->get_val
<int64_t>("rgw_mp_lock_max_time");
5468 utime_t
dur(max_lock_secs_mp
, 0);
5470 store
->obj_to_raw((s
->bucket_info
).placement_rule
, meta_obj
, &raw_obj
);
5471 store
->get_obj_data_pool((s
->bucket_info
).placement_rule
,
5472 meta_obj
,&meta_pool
);
5473 store
->open_pool_ctx(meta_pool
, serializer
.ioctx
);
5475 op_ret
= serializer
.try_lock(raw_obj
.oid
, dur
);
5477 dout(0) << "RGWCompleteMultipart::execute() failed to acquire lock " << dendl
;
5478 op_ret
= -ERR_INTERNAL_ERROR
;
5479 s
->err
.message
= "This multipart completion is already in progress";
5483 op_ret
= get_obj_attrs(store
, s
, meta_obj
, attrs
);
5486 ldout(s
->cct
, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj
5487 << " ret=" << op_ret
<< dendl
;
5492 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5493 marker
, obj_parts
, &marker
, &truncated
);
5494 if (op_ret
== -ENOENT
) {
5495 op_ret
= -ERR_NO_SUCH_UPLOAD
;
5500 total_parts
+= obj_parts
.size();
5501 if (!truncated
&& total_parts
!= (int)parts
->parts
.size()) {
5502 ldout(s
->cct
, 0) << "NOTICE: total parts mismatch: have: " << total_parts
5503 << " expected: " << parts
->parts
.size() << dendl
;
5504 op_ret
= -ERR_INVALID_PART
;
5508 for (obj_iter
= obj_parts
.begin(); iter
!= parts
->parts
.end() && obj_iter
!= obj_parts
.end(); ++iter
, ++obj_iter
, ++handled_parts
) {
5509 uint64_t part_size
= obj_iter
->second
.accounted_size
;
5510 if (handled_parts
< (int)parts
->parts
.size() - 1 &&
5511 part_size
< min_part_size
) {
5512 op_ret
= -ERR_TOO_SMALL
;
5516 char petag
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
5517 if (iter
->first
!= (int)obj_iter
->first
) {
5518 ldout(s
->cct
, 0) << "NOTICE: parts num mismatch: next requested: "
5519 << iter
->first
<< " next uploaded: "
5520 << obj_iter
->first
<< dendl
;
5521 op_ret
= -ERR_INVALID_PART
;
5524 string part_etag
= rgw_string_unquote(iter
->second
);
5525 if (part_etag
.compare(obj_iter
->second
.etag
) != 0) {
5526 ldout(s
->cct
, 0) << "NOTICE: etag mismatch: part: " << iter
->first
5527 << " etag: " << iter
->second
<< dendl
;
5528 op_ret
= -ERR_INVALID_PART
;
5532 hex_to_buf(obj_iter
->second
.etag
.c_str(), petag
,
5533 CEPH_CRYPTO_MD5_DIGESTSIZE
);
5534 hash
.Update((const byte
*)petag
, sizeof(petag
));
5536 RGWUploadPartInfo
& obj_part
= obj_iter
->second
;
5538 /* update manifest for part */
5539 string oid
= mp
.get_part(obj_iter
->second
.num
);
5541 src_obj
.init_ns(s
->bucket
, oid
, mp_ns
);
5543 if (obj_part
.manifest
.empty()) {
5544 ldout(s
->cct
, 0) << "ERROR: empty manifest for object part: obj="
5545 << src_obj
<< dendl
;
5546 op_ret
= -ERR_INVALID_PART
;
5549 manifest
.append(obj_part
.manifest
, store
);
5552 if (obj_part
.cs_info
.compression_type
!= "none") {
5553 if (compressed
&& cs_info
.compression_type
!= obj_part
.cs_info
.compression_type
) {
5554 ldout(s
->cct
, 0) << "ERROR: compression type was changed during multipart upload ("
5555 << cs_info
.compression_type
<< ">>" << obj_part
.cs_info
.compression_type
<< ")" << dendl
;
5556 op_ret
= -ERR_INVALID_PART
;
5559 int64_t new_ofs
; // offset in compression data for new part
5560 if (cs_info
.blocks
.size() > 0)
5561 new_ofs
= cs_info
.blocks
.back().new_ofs
+ cs_info
.blocks
.back().len
;
5564 for (const auto& block
: obj_part
.cs_info
.blocks
) {
5565 compression_block cb
;
5566 cb
.old_ofs
= block
.old_ofs
+ cs_info
.orig_size
;
5567 cb
.new_ofs
= new_ofs
;
5569 cs_info
.blocks
.push_back(cb
);
5570 new_ofs
= cb
.new_ofs
+ cb
.len
;
5573 cs_info
.compression_type
= obj_part
.cs_info
.compression_type
;
5574 cs_info
.orig_size
+= obj_part
.cs_info
.orig_size
;
5578 rgw_obj_index_key remove_key
;
5579 src_obj
.key
.get_index_key(&remove_key
);
5581 remove_objs
.push_back(remove_key
);
5583 ofs
+= obj_part
.size
;
5584 accounted_size
+= obj_part
.accounted_size
;
5586 } while (truncated
);
5587 hash
.Final((byte
*)final_etag
);
5589 buf_to_hex((unsigned char *)final_etag
, sizeof(final_etag
), final_etag_str
);
5590 snprintf(&final_etag_str
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2], sizeof(final_etag_str
) - CEPH_CRYPTO_MD5_DIGESTSIZE
* 2,
5591 "-%lld", (long long)parts
->parts
.size());
5592 etag
= final_etag_str
;
5593 ldout(s
->cct
, 10) << "calculated etag: " << final_etag_str
<< dendl
;
5595 etag_bl
.append(final_etag_str
, strlen(final_etag_str
) + 1);
5597 attrs
[RGW_ATTR_ETAG
] = etag_bl
;
5600 // write compression attribute to full object
5602 ::encode(cs_info
, tmp
);
5603 attrs
[RGW_ATTR_COMPRESSION
] = tmp
;
5606 target_obj
.init(s
->bucket
, s
->object
.name
);
5607 if (versioned_object
) {
5608 store
->gen_rand_obj_instance_name(&target_obj
);
5611 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5613 obj_ctx
.obj
.set_atomic(target_obj
);
5615 RGWRados::Object
op_target(store
, s
->bucket_info
, *static_cast<RGWObjectCtx
*>(s
->obj_ctx
), target_obj
);
5616 RGWRados::Object::Write
obj_op(&op_target
);
5618 obj_op
.meta
.manifest
= &manifest
;
5619 obj_op
.meta
.remove_objs
= &remove_objs
;
5621 obj_op
.meta
.ptag
= &s
->req_id
; /* use req_id as operation tag */
5622 obj_op
.meta
.owner
= s
->owner
.get_id();
5623 obj_op
.meta
.flags
= PUT_OBJ_CREATE
;
5624 obj_op
.meta
.modify_tail
= true;
5625 obj_op
.meta
.completeMultipart
= true;
5626 obj_op
.meta
.olh_epoch
= olh_epoch
;
5627 op_ret
= obj_op
.write_meta(ofs
, accounted_size
, attrs
);
5631 // remove the upload obj
5632 int r
= store
->delete_obj(*static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
5633 s
->bucket_info
, meta_obj
, 0);
5635 /* serializer's exclusive lock is released */
5636 serializer
.clear_locked();
5638 ldout(store
->ctx(), 0) << "WARNING: failed to remove object "
5639 << meta_obj
<< dendl
;
5643 int RGWCompleteMultipart::MPSerializer::try_lock(
5644 const std::string
& _oid
,
5649 lock
.set_duration(dur
);
5650 lock
.lock_exclusive(&op
);
5651 int ret
= ioctx
.operate(oid
, &op
);
5658 void RGWCompleteMultipart::complete()
5660 /* release exclusive lock iff not already */
5661 if (unlikely(serializer
.locked
)) {
5662 int r
= serializer
.unlock();
5664 ldout(store
->ctx(), 0) << "WARNING: failed to unlock "
5665 << serializer
.oid
<< dendl
;
5671 int RGWAbortMultipart::verify_permission()
5673 if (s
->iam_policy
) {
5674 auto e
= s
->iam_policy
->eval(s
->env
, *s
->auth
.identity
,
5675 rgw::IAM::s3AbortMultipartUpload
,
5676 rgw_obj(s
->bucket
, s
->object
));
5677 if (e
== Effect::Allow
) {
5679 } else if (e
== Effect::Deny
) {
5684 if (!verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
)) {
5691 void RGWAbortMultipart::pre_exec()
5693 rgw_bucket_object_pre_exec(s
);
5696 void RGWAbortMultipart::execute()
5701 upload_id
= s
->info
.args
.get("uploadId");
5702 map
<string
, bufferlist
> attrs
;
5706 if (upload_id
.empty() || s
->object
.empty())
5709 mp
.init(s
->object
.name
, upload_id
);
5710 meta_oid
= mp
.get_meta();
5712 op_ret
= get_multipart_info(store
, s
, meta_oid
, NULL
, attrs
);
5716 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5717 op_ret
= abort_multipart_upload(store
, s
->cct
, obj_ctx
, s
->bucket_info
, mp
);
5720 int RGWListMultipart::verify_permission()
5722 if (!verify_object_permission(s
, rgw::IAM::s3ListMultipartUploadParts
))
5728 void RGWListMultipart::pre_exec()
5730 rgw_bucket_object_pre_exec(s
);
5733 void RGWListMultipart::execute()
5735 map
<string
, bufferlist
> xattrs
;
5739 op_ret
= get_params();
5743 mp
.init(s
->object
.name
, upload_id
);
5744 meta_oid
= mp
.get_meta();
5746 op_ret
= get_multipart_info(store
, s
, meta_oid
, &policy
, xattrs
);
5750 op_ret
= list_multipart_parts(store
, s
, upload_id
, meta_oid
, max_parts
,
5751 marker
, parts
, NULL
, &truncated
);
5754 int RGWListBucketMultiparts::verify_permission()
5756 if (!verify_bucket_permission(s
,
5757 rgw::IAM::s3ListBucketMultipartUploads
))
5763 void RGWListBucketMultiparts::pre_exec()
5765 rgw_bucket_object_pre_exec(s
);
5768 void RGWListBucketMultiparts::execute()
5770 vector
<rgw_bucket_dir_entry
> objs
;
5773 op_ret
= get_params();
5777 if (s
->prot_flags
& RGW_REST_SWIFT
) {
5779 path_args
= s
->info
.args
.get("path");
5780 if (!path_args
.empty()) {
5781 if (!delimiter
.empty() || !prefix
.empty()) {
5789 marker_meta
= marker
.get_meta();
5791 op_ret
= list_bucket_multiparts(store
, s
->bucket_info
, prefix
, marker_meta
, delimiter
,
5792 max_uploads
, &objs
, &common_prefixes
, &is_truncated
);
5797 if (!objs
.empty()) {
5798 vector
<rgw_bucket_dir_entry
>::iterator iter
;
5799 RGWMultipartUploadEntry entry
;
5800 for (iter
= objs
.begin(); iter
!= objs
.end(); ++iter
) {
5801 rgw_obj_key
key(iter
->key
);
5802 if (!entry
.mp
.from_meta(key
.name
))
5805 uploads
.push_back(entry
);
5807 next_marker
= entry
;
5811 void RGWGetHealthCheck::execute()
5813 if (!g_conf
->rgw_healthcheck_disabling_path
.empty() &&
5814 (::access(g_conf
->rgw_healthcheck_disabling_path
.c_str(), F_OK
) == 0)) {
5815 /* Disabling path specified & existent in the filesystem. */
5816 op_ret
= -ERR_SERVICE_UNAVAILABLE
; /* 503 */
5818 op_ret
= 0; /* 200 OK */
5822 int RGWDeleteMultiObj::verify_permission()
5824 acl_allowed
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
5825 if (!acl_allowed
&& !s
->iam_policy
)
5831 void RGWDeleteMultiObj::pre_exec()
5833 rgw_bucket_object_pre_exec(s
);
5836 void RGWDeleteMultiObj::execute()
5838 RGWMultiDelDelete
*multi_delete
;
5839 vector
<rgw_obj_key
>::iterator iter
;
5840 RGWMultiDelXMLParser parser
;
5841 int num_processed
= 0;
5842 RGWObjectCtx
*obj_ctx
= static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5844 op_ret
= get_params();
5854 if (!parser
.init()) {
5859 if (!parser
.parse(data
, len
, 1)) {
5864 multi_delete
= static_cast<RGWMultiDelDelete
*>(parser
.find_first("Delete"));
5865 if (!multi_delete
) {
5870 if (multi_delete
->is_quiet())
5874 if (multi_delete
->objects
.empty()) {
5878 for (iter
= multi_delete
->objects
.begin();
5879 iter
!= multi_delete
->objects
.end() && num_processed
< max_to_delete
;
5880 ++iter
, num_processed
++) {
5881 rgw_obj
obj(bucket
, *iter
);
5882 if (s
->iam_policy
) {
5883 auto e
= s
->iam_policy
->eval(s
->env
,
5885 iter
->instance
.empty() ?
5886 rgw::IAM::s3DeleteObject
:
5887 rgw::IAM::s3DeleteObjectVersion
,
5889 if ((e
== Effect::Deny
) ||
5890 (e
== Effect::Pass
&& !acl_allowed
)) {
5891 send_partial_response(*iter
, false, "", -EACCES
);
5896 obj_ctx
->obj
.set_atomic(obj
);
5898 RGWRados::Object
del_target(store
, s
->bucket_info
, *obj_ctx
, obj
);
5899 RGWRados::Object::Delete
del_op(&del_target
);
5901 del_op
.params
.bucket_owner
= s
->bucket_owner
.get_id();
5902 del_op
.params
.versioning_status
= s
->bucket_info
.versioning_status();
5903 del_op
.params
.obj_owner
= s
->owner
;
5905 op_ret
= del_op
.delete_obj();
5906 if (op_ret
== -ENOENT
) {
5910 send_partial_response(*iter
, del_op
.result
.delete_marker
,
5911 del_op
.result
.version_id
, op_ret
);
5914 /* set the return code to zero, errors at this point will be
5915 dumped to the response */
5919 // will likely segfault if begin_response() has not been called
5931 bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo
& binfo
,
5932 map
<string
, bufferlist
>& battrs
,
5933 ACLOwner
& bucket_owner
/* out */)
5935 RGWAccessControlPolicy
bacl(store
->ctx());
5936 int ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
5941 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
5943 bucket_owner
= bacl
.get_owner();
5945 /* We can use global user_acl because each BulkDelete request is allowed
5946 * to work on entities from a single account only. */
5947 return verify_bucket_permission(s
, binfo
.bucket
, s
->user_acl
.get(),
5948 &bacl
, policy
, rgw::IAM::s3DeleteBucket
);
5951 bool RGWBulkDelete::Deleter::delete_single(const acct_path_t
& path
)
5953 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
5955 RGWBucketInfo binfo
;
5956 map
<string
, bufferlist
> battrs
;
5959 int ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
5960 path
.bucket_name
, binfo
, nullptr,
5966 if (!verify_permission(binfo
, battrs
, bowner
)) {
5971 if (!path
.obj_key
.empty()) {
5972 rgw_obj
obj(binfo
.bucket
, path
.obj_key
);
5973 obj_ctx
.obj
.set_atomic(obj
);
5975 RGWRados::Object
del_target(store
, binfo
, obj_ctx
, obj
);
5976 RGWRados::Object::Delete
del_op(&del_target
);
5978 del_op
.params
.bucket_owner
= binfo
.owner
;
5979 del_op
.params
.versioning_status
= binfo
.versioning_status();
5980 del_op
.params
.obj_owner
= bowner
;
5982 ret
= del_op
.delete_obj();
5987 RGWObjVersionTracker ot
;
5988 ot
.read_version
= binfo
.ep_objv
;
5990 ret
= store
->delete_bucket(binfo
, ot
);
5992 ret
= rgw_unlink_bucket(store
, binfo
.owner
, binfo
.bucket
.tenant
,
5993 binfo
.bucket
.name
, false);
5995 ldout(s
->cct
, 0) << "WARNING: failed to unlink bucket: ret=" << ret
6003 if (!store
->is_meta_master()) {
6005 ret
= forward_request_to_master(s
, &ot
.read_version
, store
, in_data
,
6008 if (ret
== -ENOENT
) {
6009 /* adjust error, we want to return with NoSuchBucket and not
6011 ret
= -ERR_NO_SUCH_BUCKET
;
6023 if (-ENOENT
== ret
) {
6024 ldout(store
->ctx(), 20) << "cannot find bucket = " << path
.bucket_name
<< dendl
;
6027 ldout(store
->ctx(), 20) << "cannot get bucket info, ret = " << ret
6030 fail_desc_t failed_item
= {
6034 failures
.push_back(failed_item
);
6039 ldout(store
->ctx(), 20) << "wrong auth for " << path
<< dendl
;
6041 fail_desc_t failed_item
= {
6045 failures
.push_back(failed_item
);
6050 if (-ENOENT
== ret
) {
6051 ldout(store
->ctx(), 20) << "cannot find entry " << path
<< dendl
;
6054 fail_desc_t failed_item
= {
6058 failures
.push_back(failed_item
);
6063 bool RGWBulkDelete::Deleter::delete_chunk(const std::list
<acct_path_t
>& paths
)
6065 ldout(store
->ctx(), 20) << "in delete_chunk" << dendl
;
6066 for (auto path
: paths
) {
6067 ldout(store
->ctx(), 20) << "bulk deleting path: " << path
<< dendl
;
6068 delete_single(path
);
6074 int RGWBulkDelete::verify_permission()
6079 void RGWBulkDelete::pre_exec()
6081 rgw_bucket_object_pre_exec(s
);
6084 void RGWBulkDelete::execute()
6086 deleter
= std::unique_ptr
<Deleter
>(new Deleter(store
, s
));
6088 bool is_truncated
= false;
6090 list
<RGWBulkDelete::acct_path_t
> items
;
6092 int ret
= get_data(items
, &is_truncated
);
6097 ret
= deleter
->delete_chunk(items
);
6098 } while (!op_ret
&& is_truncated
);
6104 constexpr std::array
<int, 2> RGWBulkUploadOp::terminal_errors
;
6106 int RGWBulkUploadOp::verify_permission()
6108 if (s
->auth
.identity
->is_anonymous()) {
6112 if (! verify_user_permission(s
, RGW_PERM_WRITE
)) {
6116 if (s
->user
->user_id
.tenant
!= s
->bucket_tenant
) {
6117 ldout(s
->cct
, 10) << "user cannot create a bucket in a different tenant"
6118 << " (user_id.tenant=" << s
->user
->user_id
.tenant
6119 << " requested=" << s
->bucket_tenant
<< ")"
6124 if (s
->user
->max_buckets
< 0) {
6131 void RGWBulkUploadOp::pre_exec()
6133 rgw_bucket_object_pre_exec(s
);
6136 boost::optional
<std::pair
<std::string
, rgw_obj_key
>>
6137 RGWBulkUploadOp::parse_path(const boost::string_ref
& path
)
6139 /* We need to skip all slashes at the beginning in order to preserve
6140 * compliance with Swift. */
6141 const size_t start_pos
= path
.find_first_not_of('/');
6143 if (boost::string_ref::npos
!= start_pos
) {
6144 /* Seperator is the first slash after the leading ones. */
6145 const size_t sep_pos
= path
.substr(start_pos
).find('/');
6147 if (boost::string_ref::npos
!= sep_pos
) {
6148 const auto bucket_name
= path
.substr(start_pos
, sep_pos
- start_pos
);
6149 const auto obj_name
= path
.substr(sep_pos
+ 1);
6151 return std::make_pair(bucket_name
.to_string(),
6152 rgw_obj_key(obj_name
.to_string()));
6154 /* It's guaranteed here that bucket name is at least one character
6155 * long and is different than slash. */
6156 return std::make_pair(path
.substr(start_pos
).to_string(),
6164 std::pair
<std::string
, std::string
>
6165 RGWBulkUploadOp::handle_upload_path(struct req_state
*s
)
6167 std::string bucket_path
, file_prefix
;
6168 if (! s
->init_state
.url_bucket
.empty()) {
6169 file_prefix
= bucket_path
= s
->init_state
.url_bucket
+ "/";
6170 if (! s
->object
.empty()) {
6171 std::string
& object_name
= s
->object
.name
;
6173 /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
6174 * we can safely examine its last element. */
6175 if (object_name
.back() == '/') {
6176 file_prefix
.append(object_name
);
6178 file_prefix
.append(object_name
).append("/");
6182 return std::make_pair(bucket_path
, file_prefix
);
6185 int RGWBulkUploadOp::handle_dir_verify_permission()
6187 if (s
->user
->max_buckets
> 0) {
6188 RGWUserBuckets buckets
;
6190 bool is_truncated
= false;
6191 op_ret
= rgw_read_user_buckets(store
, s
->user
->user_id
, buckets
,
6192 marker
, std::string(), s
->user
->max_buckets
,
6193 false, &is_truncated
);
6198 if (buckets
.count() >= static_cast<size_t>(s
->user
->max_buckets
)) {
6199 return -ERR_TOO_MANY_BUCKETS
;
6206 static void forward_req_info(CephContext
*cct
, req_info
& info
, const std::string
& bucket_name
)
6208 /* the request of container or object level will contain bucket name.
6209 * only at account level need to append the bucket name */
6210 if (info
.script_uri
.find(bucket_name
) != std::string::npos
) {
6214 ldout(cct
, 20) << "append the bucket: "<< bucket_name
<< " to req_info" << dendl
;
6215 info
.script_uri
.append("/").append(bucket_name
);
6216 info
.request_uri_aws4
= info
.request_uri
= info
.script_uri
;
6217 info
.effective_uri
= "/" + bucket_name
;
6220 int RGWBulkUploadOp::handle_dir(const boost::string_ref path
)
6222 ldout(s
->cct
, 20) << "bulk upload: got directory=" << path
<< dendl
;
6224 op_ret
= handle_dir_verify_permission();
6229 std::string bucket_name
;
6230 rgw_obj_key object_junk
;
6231 std::tie(bucket_name
, object_junk
) = *parse_path(path
);
6233 rgw_raw_obj
obj(store
->get_zone_params().domain_root
,
6234 rgw_make_bucket_entry_name(s
->bucket_tenant
, bucket_name
));
6236 /* we need to make sure we read bucket info, it's not read before for this
6237 * specific request */
6238 RGWBucketInfo binfo
;
6239 std::map
<std::string
, ceph::bufferlist
> battrs
;
6240 op_ret
= store
->get_bucket_info(*dir_ctx
, s
->bucket_tenant
, bucket_name
,
6241 binfo
, NULL
, &battrs
);
6242 if (op_ret
< 0 && op_ret
!= -ENOENT
) {
6245 const bool bucket_exists
= (op_ret
!= -ENOENT
);
6247 if (bucket_exists
) {
6248 RGWAccessControlPolicy
old_policy(s
->cct
);
6249 int r
= get_bucket_policy_from_attr(s
->cct
, store
, binfo
,
6250 battrs
, &old_policy
);
6252 if (old_policy
.get_owner().get_id().compare(s
->user
->user_id
) != 0) {
6259 RGWBucketInfo master_info
;
6260 rgw_bucket
*pmaster_bucket
= nullptr;
6261 uint32_t *pmaster_num_shards
= nullptr;
6262 real_time creation_time
;
6263 obj_version objv
, ep_objv
, *pobjv
= nullptr;
6265 if (! store
->is_meta_master()) {
6267 ceph::bufferlist in_data
;
6268 req_info info
= s
->info
;
6269 forward_req_info(s
->cct
, info
, bucket_name
);
6270 op_ret
= forward_request_to_master(s
, nullptr, store
, in_data
, &jp
, &info
);
6275 JSONDecoder::decode_json("entry_point_object_ver", ep_objv
, &jp
);
6276 JSONDecoder::decode_json("object_ver", objv
, &jp
);
6277 JSONDecoder::decode_json("bucket_info", master_info
, &jp
);
6279 ldout(s
->cct
, 20) << "parsed: objv.tag=" << objv
.tag
<< " objv.ver="
6280 << objv
.ver
<< dendl
;
6281 ldout(s
->cct
, 20) << "got creation_time="<< master_info
.creation_time
6284 pmaster_bucket
= &master_info
.bucket
;
6285 creation_time
= master_info
.creation_time
;
6286 pmaster_num_shards
= &master_info
.num_shards
;
6289 pmaster_bucket
= nullptr;
6290 pmaster_num_shards
= nullptr;
6294 std::string placement_rule
;
6295 if (bucket_exists
) {
6296 std::string selected_placement_rule
;
6298 bucket
.tenant
= s
->bucket_tenant
;
6299 bucket
.name
= s
->bucket_name
;
6300 op_ret
= store
->select_bucket_placement(*(s
->user
),
6301 store
->get_zonegroup().get_id(),
6303 &selected_placement_rule
,
6305 if (selected_placement_rule
!= binfo
.placement_rule
) {
6307 ldout(s
->cct
, 20) << "bulk upload: non-coherent placement rule" << dendl
;
6312 /* Create metadata: ACLs. */
6313 std::map
<std::string
, ceph::bufferlist
> attrs
;
6314 RGWAccessControlPolicy policy
;
6315 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6316 ceph::bufferlist aclbl
;
6317 policy
.encode(aclbl
);
6318 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6320 RGWQuotaInfo quota_info
;
6321 const RGWQuotaInfo
* pquota_info
= nullptr;
6324 bucket
.tenant
= s
->bucket_tenant
; /* ignored if bucket exists */
6325 bucket
.name
= bucket_name
;
6328 RGWBucketInfo out_info
;
6329 op_ret
= store
->create_bucket(*(s
->user
),
6331 store
->get_zonegroup().get_id(),
6332 placement_rule
, binfo
.swift_ver_location
,
6334 out_info
, pobjv
, &ep_objv
, creation_time
,
6335 pmaster_bucket
, pmaster_num_shards
, true);
6336 /* continue if EEXIST and create_bucket will fail below. this way we can
6337 * recover from a partial create by retrying it. */
6338 ldout(s
->cct
, 20) << "rgw_create_bucket returned ret=" << op_ret
6339 << ", bucket=" << bucket
<< dendl
;
6341 if (op_ret
&& op_ret
!= -EEXIST
) {
6345 const bool existed
= (op_ret
== -EEXIST
);
6347 /* bucket already existed, might have raced with another bucket creation, or
6348 * might be partial bucket creation that never completed. Read existing bucket
6349 * info, verify that the reported bucket owner is the current user.
6350 * If all is ok then update the user's list of buckets.
6351 * Otherwise inform client about a name conflict.
6353 if (out_info
.owner
.compare(s
->user
->user_id
) != 0) {
6355 ldout(s
->cct
, 20) << "bulk upload: conflicting bucket name" << dendl
;
6358 bucket
= out_info
.bucket
;
6361 op_ret
= rgw_link_bucket(store
, s
->user
->user_id
, bucket
,
6362 out_info
.creation_time
, false);
6363 if (op_ret
&& !existed
&& op_ret
!= -EEXIST
) {
6364 /* if it exists (or previously existed), don't remove it! */
6365 op_ret
= rgw_unlink_bucket(store
, s
->user
->user_id
,
6366 bucket
.tenant
, bucket
.name
);
6368 ldout(s
->cct
, 0) << "bulk upload: WARNING: failed to unlink bucket: ret="
6371 } else if (op_ret
== -EEXIST
|| (op_ret
== 0 && existed
)) {
6372 ldout(s
->cct
, 20) << "bulk upload: containers already exists"
6374 op_ret
= -ERR_BUCKET_EXISTS
;
6381 bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo
& binfo
,
6383 std::map
<std::string
, ceph::bufferlist
>& battrs
,
6384 ACLOwner
& bucket_owner
/* out */)
6386 RGWAccessControlPolicy
bacl(store
->ctx());
6387 op_ret
= read_bucket_policy(store
, s
, binfo
, battrs
, &bacl
, binfo
.bucket
);
6389 ldout(s
->cct
, 20) << "bulk upload: cannot read_policy() for bucket"
6394 auto policy
= get_iam_policy_from_attr(s
->cct
, store
, battrs
, binfo
.bucket
.tenant
);
6396 bucket_owner
= bacl
.get_owner();
6398 auto e
= policy
->eval(s
->env
, *s
->auth
.identity
,
6399 rgw::IAM::s3PutObject
, obj
);
6400 if (e
== Effect::Allow
) {
6402 } else if (e
== Effect::Deny
) {
6407 return verify_bucket_permission_no_policy(s
, s
->user_acl
.get(),
6408 &bacl
, RGW_PERM_WRITE
);
6411 int RGWBulkUploadOp::handle_file(const boost::string_ref path
,
6413 AlignedStreamGetter
& body
)
6416 ldout(s
->cct
, 20) << "bulk upload: got file=" << path
<< ", size=" << size
6419 RGWPutObjDataProcessor
*filter
= nullptr;
6420 boost::optional
<RGWPutObj_Compress
> compressor
;
6422 if (size
> static_cast<const size_t>(s
->cct
->_conf
->rgw_max_put_size
)) {
6423 op_ret
= -ERR_TOO_LARGE
;
6427 std::string bucket_name
;
6429 std::tie(bucket_name
, object
) = *parse_path(path
);
6431 auto& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
6432 RGWBucketInfo binfo
;
6433 std::map
<std::string
, ceph::bufferlist
> battrs
;
6435 op_ret
= store
->get_bucket_info(obj_ctx
, s
->user
->user_id
.tenant
,
6436 bucket_name
, binfo
, nullptr, &battrs
);
6437 if (op_ret
== -ENOENT
) {
6438 ldout(s
->cct
, 20) << "bulk upload: non existent directory=" << bucket_name
6440 } else if (op_ret
< 0) {
6444 if (! handle_file_verify_permission(binfo
,
6445 rgw_obj(binfo
.bucket
, object
),
6447 ldout(s
->cct
, 20) << "bulk upload: object creation unauthorized" << dendl
;
6452 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6453 user_quota
, bucket_quota
, size
);
6458 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6463 RGWPutObjProcessor_Atomic
processor(obj_ctx
,
6468 s
->cct
->_conf
->rgw_obj_stripe_size
,
6470 binfo
.versioning_enabled());
6472 /* No filters by default. */
6473 filter
= &processor
;
6475 op_ret
= processor
.prepare(store
, nullptr);
6477 ldout(s
->cct
, 20) << "bulk upload: cannot prepare processor due to ret="
6482 const auto& compression_type
= store
->get_zone_params().get_compression_type(
6483 binfo
.placement_rule
);
6484 CompressorRef plugin
;
6485 if (compression_type
!= "none") {
6486 plugin
= Compressor::create(s
->cct
, compression_type
);
6488 ldout(s
->cct
, 1) << "Cannot load plugin for rgw_compression_type "
6489 << compression_type
<< dendl
;
6491 compressor
.emplace(s
->cct
, plugin
, filter
);
6492 filter
= &*compressor
;
6496 /* Upload file content. */
6501 ceph::bufferlist data
;
6502 len
= body
.get_at_most(s
->cct
->_conf
->rgw_max_chunk_size
, data
);
6504 ldout(s
->cct
, 20) << "bulk upload: body=" << data
.c_str() << dendl
;
6508 } else if (len
> 0) {
6509 hash
.Update((const byte
*)data
.c_str(), data
.length());
6510 op_ret
= put_data_and_throttle(filter
, data
, ofs
, false);
6512 ldout(s
->cct
, 20) << "processor->thottle_data() returned ret="
6523 ldout(s
->cct
, 10) << "bulk upload: real file size different from declared"
6528 op_ret
= store
->check_quota(bowner
.get_id(), binfo
.bucket
,
6529 user_quota
, bucket_quota
, size
);
6531 ldout(s
->cct
, 20) << "bulk upload: quota exceeded for path=" << path
6536 op_ret
= store
->check_bucket_shards(s
->bucket_info
, s
->bucket
, bucket_quota
);
6541 char calc_md5
[CEPH_CRYPTO_MD5_DIGESTSIZE
* 2 + 1];
6542 unsigned char m
[CEPH_CRYPTO_MD5_DIGESTSIZE
];
6544 buf_to_hex(m
, CEPH_CRYPTO_MD5_DIGESTSIZE
, calc_md5
);
6546 /* Create metadata: ETAG. */
6547 std::map
<std::string
, ceph::bufferlist
> attrs
;
6548 std::string etag
= calc_md5
;
6549 ceph::bufferlist etag_bl
;
6550 etag_bl
.append(etag
.c_str(), etag
.size() + 1);
6551 attrs
.emplace(RGW_ATTR_ETAG
, std::move(etag_bl
));
6553 /* Create metadata: ACLs. */
6554 RGWAccessControlPolicy policy
;
6555 policy
.create_default(s
->user
->user_id
, s
->user
->display_name
);
6556 ceph::bufferlist aclbl
;
6557 policy
.encode(aclbl
);
6558 attrs
.emplace(RGW_ATTR_ACL
, std::move(aclbl
));
6560 /* Create metadata: compression info. */
6561 if (compressor
&& compressor
->is_compressed()) {
6562 ceph::bufferlist tmp
;
6563 RGWCompressionInfo cs_info
;
6564 cs_info
.compression_type
= plugin
->get_type_name();
6565 cs_info
.orig_size
= s
->obj_size
;
6566 cs_info
.blocks
= std::move(compressor
->get_compression_blocks());
6567 ::encode(cs_info
, tmp
);
6568 attrs
.emplace(RGW_ATTR_COMPRESSION
, std::move(tmp
));
6571 /* Complete the transaction. */
6572 op_ret
= processor
.complete(size
, etag
, nullptr, ceph::real_time(), attrs
,
6573 ceph::real_time() /* delete_at */);
6575 ldout(s
->cct
, 20) << "bulk upload: processor::complete returned op_ret="
6582 void RGWBulkUploadOp::execute()
6584 ceph::bufferlist
buffer(64 * 1024);
6586 ldout(s
->cct
, 20) << "bulk upload: start" << dendl
;
6588 /* Create an instance of stream-abstracting class. Having this indirection
6589 * allows for easy introduction of decompressors like gzip and bzip2. */
6590 auto stream
= create_stream();
6595 /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See:
6596 * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
6597 std::string bucket_path
, file_prefix
;
6598 std::tie(bucket_path
, file_prefix
) = handle_upload_path(s
);
6600 auto status
= rgw::tar::StatusIndicator::create();
6602 op_ret
= stream
->get_exactly(rgw::tar::BLOCK_SIZE
, buffer
);
6604 ldout(s
->cct
, 2) << "bulk upload: cannot read header" << dendl
;
6608 /* We need to re-interpret the buffer as a TAR block. Exactly two blocks
6609 * must be tracked to detect out end-of-archive. It occurs when both of
6610 * them are empty (zeroed). Tracing this particular inter-block dependency
6611 * is responsibility of the rgw::tar::StatusIndicator class. */
6612 boost::optional
<rgw::tar::HeaderView
> header
;
6613 std::tie(status
, header
) = rgw::tar::interpret_block(status
, buffer
);
6615 if (! status
.empty() && header
) {
6616 /* This specific block isn't empty (entirely zeroed), so we can parse
6617 * it as a TAR header and dispatch. At the moment we do support only
6618 * regular files and directories. Everything else (symlinks, devices)
6619 * will be ignored but won't cease the whole upload. */
6620 switch (header
->get_filetype()) {
6621 case rgw::tar::FileType::NORMAL_FILE
: {
6622 ldout(s
->cct
, 2) << "bulk upload: handling regular file" << dendl
;
6624 boost::string_ref filename
= bucket_path
.empty() ? header
->get_filename() : \
6625 file_prefix
+ header
->get_filename().to_string();
6626 auto body
= AlignedStreamGetter(0, header
->get_filesize(),
6627 rgw::tar::BLOCK_SIZE
, *stream
);
6628 op_ret
= handle_file(filename
,
6629 header
->get_filesize(),
6632 /* Only regular files counts. */
6635 failures
.emplace_back(op_ret
, filename
.to_string());
6639 case rgw::tar::FileType::DIRECTORY
: {
6640 ldout(s
->cct
, 2) << "bulk upload: handling regular directory" << dendl
;
6642 boost::string_ref dirname
= bucket_path
.empty() ? header
->get_filename() : bucket_path
;
6643 op_ret
= handle_dir(dirname
);
6644 if (op_ret
< 0 && op_ret
!= -ERR_BUCKET_EXISTS
) {
6645 failures
.emplace_back(op_ret
, dirname
.to_string());
6650 /* Not recognized. Skip. */
6656 /* In case of any problems with sub-request authorization Swift simply
6657 * terminates whole upload immediately. */
6658 if (boost::algorithm::contains(std::initializer_list
<int>{ op_ret
},
6660 ldout(s
->cct
, 2) << "bulk upload: terminating due to ret=" << op_ret
6665 ldout(s
->cct
, 2) << "bulk upload: an empty block" << dendl
;
6670 } while (! status
.eof());
6675 RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter()
6677 const size_t aligned_legnth
= length
+ (-length
% alignment
);
6678 ceph::bufferlist junk
;
6680 DecoratedStreamGetter::get_exactly(aligned_legnth
- position
, junk
);
6683 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want
,
6684 ceph::bufferlist
& dst
)
6686 const size_t max_to_read
= std::min(want
, length
- position
);
6687 const auto len
= DecoratedStreamGetter::get_at_most(max_to_read
, dst
);
6694 ssize_t
RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want
,
6695 ceph::bufferlist
& dst
)
6697 const auto len
= DecoratedStreamGetter::get_exactly(want
, dst
);
6704 int RGWSetAttrs::verify_permission()
6706 // This looks to be part of the RGW-NFS machinery and has no S3 or
6707 // Swift equivalent.
6709 if (!s
->object
.empty()) {
6710 perm
= verify_object_permission_no_policy(s
, RGW_PERM_WRITE
);
6712 perm
= verify_bucket_permission_no_policy(s
, RGW_PERM_WRITE
);
6720 void RGWSetAttrs::pre_exec()
6722 rgw_bucket_object_pre_exec(s
);
6725 void RGWSetAttrs::execute()
6727 op_ret
= get_params();
6731 rgw_obj
obj(s
->bucket
, s
->object
);
6733 if (!s
->object
.empty()) {
6734 store
->set_atomic(s
->obj_ctx
, obj
);
6735 op_ret
= store
->set_attrs(s
->obj_ctx
, s
->bucket_info
, obj
, attrs
, nullptr);
6737 for (auto& iter
: attrs
) {
6738 s
->bucket_attrs
[iter
.first
] = std::move(iter
.second
);
6740 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, s
->bucket_attrs
,
6741 &s
->bucket_info
.objv_tracker
);
6745 void RGWGetObjLayout::pre_exec()
6747 rgw_bucket_object_pre_exec(s
);
6750 void RGWGetObjLayout::execute()
6752 rgw_obj
obj(s
->bucket
, s
->object
);
6753 RGWRados::Object
target(store
,
6755 *static_cast<RGWObjectCtx
*>(s
->obj_ctx
),
6756 rgw_obj(s
->bucket
, s
->object
));
6757 RGWRados::Object::Read
stat_op(&target
);
6759 op_ret
= stat_op
.prepare();
6764 head_obj
= stat_op
.state
.head_obj
;
6766 op_ret
= target
.get_manifest(&manifest
);
6770 int RGWConfigBucketMetaSearch::verify_permission()
6772 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6779 void RGWConfigBucketMetaSearch::pre_exec()
6781 rgw_bucket_object_pre_exec(s
);
6784 void RGWConfigBucketMetaSearch::execute()
6786 op_ret
= get_params();
6788 ldout(s
->cct
, 20) << "NOTICE: get_params() returned ret=" << op_ret
<< dendl
;
6792 s
->bucket_info
.mdsearch_config
= mdsearch_config
;
6794 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6796 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6801 int RGWGetBucketMetaSearch::verify_permission()
6803 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6810 void RGWGetBucketMetaSearch::pre_exec()
6812 rgw_bucket_object_pre_exec(s
);
6815 int RGWDelBucketMetaSearch::verify_permission()
6817 if (!s
->auth
.identity
->is_owner_of(s
->bucket_owner
.get_id())) {
6824 void RGWDelBucketMetaSearch::pre_exec()
6826 rgw_bucket_object_pre_exec(s
);
6829 void RGWDelBucketMetaSearch::execute()
6831 s
->bucket_info
.mdsearch_config
.clear();
6833 op_ret
= store
->put_bucket_instance_info(s
->bucket_info
, false, real_time(), &s
->bucket_attrs
);
6835 ldout(s
->cct
, 0) << "NOTICE: put_bucket_info on bucket=" << s
->bucket
.name
<< " returned err=" << op_ret
<< dendl
;
6841 RGWHandler::~RGWHandler()
6845 int RGWHandler::init(RGWRados
*_store
,
6846 struct req_state
*_s
,
6847 rgw::io::BasicClient
*cio
)
6855 int RGWHandler::do_init_permissions()
6857 int ret
= rgw_build_bucket_policies(store
, s
);
6858 s
->env
= rgw_build_iam_environment(store
, s
);
6861 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< " ret=" << ret
<< dendl
;
6862 if (ret
== -ENODATA
)
6869 int RGWHandler::do_read_permissions(RGWOp
*op
, bool only_bucket
)
6872 /* already read bucket info */
6875 int ret
= rgw_build_object_policies(store
, s
, op
->prefetch_data());
6878 ldout(s
->cct
, 10) << "read_permissions on " << s
->bucket
<< ":"
6879 << s
->object
<< " only_bucket=" << only_bucket
6880 << " ret=" << ret
<< dendl
;
6881 if (ret
== -ENODATA
)
6888 int RGWOp::error_handler(int err_no
, string
*error_content
) {
6889 return dialect_handler
->error_handler(err_no
, error_content
);
6892 int RGWHandler::error_handler(int err_no
, string
*error_content
) {
6893 // This is the do-nothing error handler
6898 void RGWPutBucketPolicy::send_response()
6901 set_req_state_err(s
, op_ret
);
6907 int RGWPutBucketPolicy::verify_permission()
6909 if (!verify_bucket_permission(s
, rgw::IAM::s3PutBucketPolicy
)) {
6916 int RGWPutBucketPolicy::get_params()
6918 const auto max_size
= s
->cct
->_conf
->rgw_max_put_param_size
;
6919 // At some point when I have more time I want to make a version of
6920 // rgw_rest_read_all_input that doesn't use malloc.
6921 op_ret
= rgw_rest_read_all_input(s
, &data
, &len
, max_size
, false);
6922 // And throws exceptions.
6926 void RGWPutBucketPolicy::execute()
6928 op_ret
= get_params();
6933 bufferlist in_data
= bufferlist::static_from_mem(data
, len
);
6935 if (!store
->is_meta_master()) {
6936 op_ret
= forward_request_to_master(s
, NULL
, store
, in_data
, nullptr);
6938 ldout(s
->cct
, 20) << "forward_request_to_master returned ret=" << op_ret
<< dendl
;
6944 const Policy
p(s
->cct
, s
->bucket_tenant
, in_data
);
6945 op_ret
= retry_raced_bucket_write(store
, s
, [&p
, this] {
6946 auto attrs
= s
->bucket_attrs
;
6947 attrs
[RGW_ATTR_IAM_POLICY
].clear();
6948 attrs
[RGW_ATTR_IAM_POLICY
].append(p
.text
);
6949 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
6950 &s
->bucket_info
.objv_tracker
);
6953 } catch (rgw::IAM::PolicyParseException
& e
) {
6954 ldout(s
->cct
, 20) << "failed to parse policy: " << e
.what() << dendl
;
6959 void RGWGetBucketPolicy::send_response()
6962 set_req_state_err(s
, op_ret
);
6965 end_header(s
, this, "application/json");
6966 dump_body(s
, policy
);
6969 int RGWGetBucketPolicy::verify_permission()
6971 if (!verify_bucket_permission(s
, rgw::IAM::s3GetBucketPolicy
)) {
6978 void RGWGetBucketPolicy::execute()
6980 auto attrs
= s
->bucket_attrs
;
6981 map
<string
, bufferlist
>::iterator aiter
= attrs
.find(RGW_ATTR_IAM_POLICY
);
6982 if (aiter
== attrs
.end()) {
6983 ldout(s
->cct
, 0) << __func__
<< " can't find bucket IAM POLICY attr"
6984 << " bucket_name = " << s
->bucket_name
<< dendl
;
6985 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6986 s
->err
.message
= "The bucket policy does not exist";
6989 policy
= attrs
[RGW_ATTR_IAM_POLICY
];
6991 if (policy
.length() == 0) {
6992 ldout(s
->cct
, 10) << "The bucket policy does not exist, bucket: " << s
->bucket_name
<< dendl
;
6993 op_ret
= -ERR_NO_SUCH_BUCKET_POLICY
;
6994 s
->err
.message
= "The bucket policy does not exist";
7000 void RGWDeleteBucketPolicy::send_response()
7003 set_req_state_err(s
, op_ret
);
7009 int RGWDeleteBucketPolicy::verify_permission()
7011 if (!verify_bucket_permission(s
, rgw::IAM::s3DeleteBucketPolicy
)) {
7018 void RGWDeleteBucketPolicy::execute()
7020 op_ret
= retry_raced_bucket_write(store
, s
, [this] {
7021 auto attrs
= s
->bucket_attrs
;
7022 attrs
.erase(RGW_ATTR_IAM_POLICY
);
7023 op_ret
= rgw_bucket_set_attrs(store
, s
->bucket_info
, attrs
,
7024 &s
->bucket_info
.objv_tracker
);
7029 void RGWGetClusterStat::execute()
7031 op_ret
= this->store
->get_rados_handle()->cluster_stat(stats_op
);