]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
7c673cae FG |
3 | |
4 | #include <errno.h> | |
5 | #include <stdlib.h> | |
31f18b77 | 6 | #include <system_error> |
7c673cae FG |
7 | #include <unistd.h> |
8 | ||
9 | #include <sstream> | |
f67539c2 | 10 | #include <string_view> |
7c673cae FG |
11 | |
12 | #include <boost/algorithm/string/predicate.hpp> | |
13 | #include <boost/optional.hpp> | |
31f18b77 | 14 | #include <boost/utility/in_place_factory.hpp> |
7c673cae | 15 | |
11fdf7f2 | 16 | #include "include/scope_guard.h" |
7c673cae FG |
17 | #include "common/Clock.h" |
18 | #include "common/armor.h" | |
31f18b77 | 19 | #include "common/errno.h" |
7c673cae FG |
20 | #include "common/mime.h" |
21 | #include "common/utf8.h" | |
22 | #include "common/ceph_json.h" | |
11fdf7f2 | 23 | #include "common/static_ptr.h" |
7c673cae FG |
24 | |
25 | #include "rgw_rados.h" | |
11fdf7f2 | 26 | #include "rgw_zone.h" |
7c673cae FG |
27 | #include "rgw_op.h" |
28 | #include "rgw_rest.h" | |
29 | #include "rgw_acl.h" | |
30 | #include "rgw_acl_s3.h" | |
31 | #include "rgw_acl_swift.h" | |
11fdf7f2 | 32 | #include "rgw_aio_throttle.h" |
7c673cae FG |
33 | #include "rgw_user.h" |
34 | #include "rgw_bucket.h" | |
35 | #include "rgw_log.h" | |
36 | #include "rgw_multi.h" | |
37 | #include "rgw_multi_del.h" | |
38 | #include "rgw_cors.h" | |
39 | #include "rgw_cors_s3.h" | |
40 | #include "rgw_rest_conn.h" | |
41 | #include "rgw_rest_s3.h" | |
42 | #include "rgw_tar.h" | |
43 | #include "rgw_client_io.h" | |
44 | #include "rgw_compression.h" | |
45 | #include "rgw_role.h" | |
224ce89b | 46 | #include "rgw_tag_s3.h" |
11fdf7f2 TL |
47 | #include "rgw_putobj_processor.h" |
48 | #include "rgw_crypt.h" | |
49 | #include "rgw_perf_counters.h" | |
eafe8130 TL |
50 | #include "rgw_notify.h" |
51 | #include "rgw_notify_event_type.h" | |
f67539c2 | 52 | #include "rgw_sal_rados.h" |
11fdf7f2 TL |
53 | |
54 | #include "services/svc_zone.h" | |
55 | #include "services/svc_quota.h" | |
56 | #include "services/svc_sys_obj.h" | |
57 | ||
7c673cae FG |
58 | #include "cls/lock/cls_lock_client.h" |
59 | #include "cls/rgw/cls_rgw_client.h" | |
60 | ||
61 | ||
11fdf7f2 | 62 | #include "include/ceph_assert.h" |
7c673cae FG |
63 | |
64 | #include "compressor/Compressor.h" | |
65 | ||
11fdf7f2 TL |
66 | #ifdef WITH_LTTNG |
67 | #define TRACEPOINT_DEFINE | |
68 | #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
69 | #include "tracing/rgw_op.h" | |
70 | #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
71 | #undef TRACEPOINT_DEFINE | |
72 | #else | |
73 | #define tracepoint(...) | |
74 | #endif | |
7c673cae FG |
75 | |
76 | #define dout_context g_ceph_context | |
77 | #define dout_subsys ceph_subsys_rgw | |
78 | ||
7c673cae FG |
79 | using namespace librados; |
80 | using ceph::crypto::MD5; | |
31f18b77 FG |
81 | using boost::optional; |
82 | using boost::none; | |
7c673cae | 83 | |
eafe8130 | 84 | using rgw::ARN; |
31f18b77 FG |
85 | using rgw::IAM::Effect; |
86 | using rgw::IAM::Policy; | |
87 | ||
7c673cae FG |
88 | static string mp_ns = RGW_OBJ_NS_MULTIPART; |
89 | static string shadow_ns = RGW_OBJ_NS_SHADOW; | |
90 | ||
91 | static void forward_req_info(CephContext *cct, req_info& info, const std::string& bucket_name); | |
7c673cae FG |
92 | |
93 | static MultipartMetaFilter mp_filter; | |
94 | ||
11fdf7f2 TL |
95 | // this probably should belong in the rgw_iam_policy_keywords, I'll get it to it |
96 | // at some point | |
97 | static constexpr auto S3_EXISTING_OBJTAG = "s3:ExistingObjectTag"; | |
98 | ||
28e407b8 | 99 | int RGWGetObj::parse_range(void) |
7c673cae FG |
100 | { |
101 | int r = -ERANGE; | |
28e407b8 | 102 | string rs(range_str); |
7c673cae FG |
103 | string ofs_str; |
104 | string end_str; | |
105 | ||
28e407b8 AA |
106 | ignore_invalid_range = s->cct->_conf->rgw_ignore_get_invalid_range; |
107 | partial_content = false; | |
7c673cae | 108 | |
28e407b8 | 109 | size_t pos = rs.find("bytes="); |
7c673cae FG |
110 | if (pos == string::npos) { |
111 | pos = 0; | |
28e407b8 | 112 | while (isspace(rs[pos])) |
7c673cae FG |
113 | pos++; |
114 | int end = pos; | |
28e407b8 | 115 | while (isalpha(rs[end])) |
7c673cae | 116 | end++; |
28e407b8 | 117 | if (strncasecmp(rs.c_str(), "bytes", end - pos) != 0) |
7c673cae | 118 | return 0; |
28e407b8 | 119 | while (isspace(rs[end])) |
7c673cae | 120 | end++; |
28e407b8 | 121 | if (rs[end] != '=') |
7c673cae | 122 | return 0; |
28e407b8 | 123 | rs = rs.substr(end + 1); |
7c673cae | 124 | } else { |
28e407b8 | 125 | rs = rs.substr(pos + 6); /* size of("bytes=") */ |
7c673cae | 126 | } |
28e407b8 | 127 | pos = rs.find('-'); |
7c673cae FG |
128 | if (pos == string::npos) |
129 | goto done; | |
130 | ||
28e407b8 | 131 | partial_content = true; |
7c673cae | 132 | |
28e407b8 AA |
133 | ofs_str = rs.substr(0, pos); |
134 | end_str = rs.substr(pos + 1); | |
7c673cae FG |
135 | if (end_str.length()) { |
136 | end = atoll(end_str.c_str()); | |
137 | if (end < 0) | |
138 | goto done; | |
139 | } | |
140 | ||
141 | if (ofs_str.length()) { | |
142 | ofs = atoll(ofs_str.c_str()); | |
143 | } else { // RFC2616 suffix-byte-range-spec | |
144 | ofs = -end; | |
145 | end = -1; | |
146 | } | |
147 | ||
148 | if (end >= 0 && end < ofs) | |
149 | goto done; | |
150 | ||
28e407b8 AA |
151 | range_parsed = true; |
152 | return 0; | |
153 | ||
7c673cae | 154 | done: |
28e407b8 AA |
155 | if (ignore_invalid_range) { |
156 | partial_content = false; | |
157 | ofs = 0; | |
158 | end = -1; | |
159 | range_parsed = false; // allow retry | |
160 | r = 0; | |
161 | } | |
162 | ||
7c673cae FG |
163 | return r; |
164 | } | |
165 | ||
b3b6e05e TL |
166 | static int decode_policy(const DoutPrefixProvider *dpp, |
167 | CephContext *cct, | |
7c673cae FG |
168 | bufferlist& bl, |
169 | RGWAccessControlPolicy *policy) | |
170 | { | |
11fdf7f2 | 171 | auto iter = bl.cbegin(); |
7c673cae FG |
172 | try { |
173 | policy->decode(iter); | |
174 | } catch (buffer::error& err) { | |
b3b6e05e | 175 | ldpp_dout(dpp, 0) << "ERROR: could not decode policy, caught buffer::error" << dendl; |
7c673cae FG |
176 | return -EIO; |
177 | } | |
11fdf7f2 | 178 | if (cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) { |
b3b6e05e | 179 | ldpp_dout(dpp, 15) << __func__ << " Read AccessControlPolicy"; |
11fdf7f2 | 180 | RGWAccessControlPolicy_S3 *s3policy = static_cast<RGWAccessControlPolicy_S3 *>(policy); |
7c673cae FG |
181 | s3policy->to_xml(*_dout); |
182 | *_dout << dendl; | |
183 | } | |
184 | return 0; | |
185 | } | |
186 | ||
187 | ||
b3b6e05e TL |
188 | static int get_user_policy_from_attr(const DoutPrefixProvider *dpp, |
189 | CephContext * const cct, | |
9f95a23c | 190 | rgw::sal::RGWRadosStore * const store, |
31f18b77 FG |
191 | map<string, bufferlist>& attrs, |
192 | RGWAccessControlPolicy& policy /* out */) | |
7c673cae FG |
193 | { |
194 | auto aiter = attrs.find(RGW_ATTR_ACL); | |
195 | if (aiter != attrs.end()) { | |
b3b6e05e | 196 | int ret = decode_policy(dpp, cct, aiter->second, &policy); |
7c673cae FG |
197 | if (ret < 0) { |
198 | return ret; | |
199 | } | |
200 | } else { | |
201 | return -ENOENT; | |
202 | } | |
203 | ||
204 | return 0; | |
205 | } | |
206 | ||
9f95a23c TL |
207 | /** |
208 | * Get the AccessControlPolicy for an object off of disk. | |
209 | * policy: must point to a valid RGWACL, and will be filled upon return. | |
210 | * bucket: name of the bucket containing the object. | |
211 | * object: name of the object to get the ACL for. | |
212 | * Returns: 0 on success, -ERR# otherwise. | |
213 | */ | |
b3b6e05e TL |
214 | int rgw_op_get_bucket_policy_from_attr(const DoutPrefixProvider *dpp, |
215 | CephContext *cct, | |
f67539c2 | 216 | rgw::sal::RGWStore *store, |
9f95a23c TL |
217 | RGWBucketInfo& bucket_info, |
218 | map<string, bufferlist>& bucket_attrs, | |
f67539c2 TL |
219 | RGWAccessControlPolicy *policy, |
220 | optional_yield y) | |
7c673cae FG |
221 | { |
222 | map<string, bufferlist>::iterator aiter = bucket_attrs.find(RGW_ATTR_ACL); | |
223 | ||
224 | if (aiter != bucket_attrs.end()) { | |
b3b6e05e | 225 | int ret = decode_policy(dpp, cct, aiter->second, policy); |
7c673cae FG |
226 | if (ret < 0) |
227 | return ret; | |
228 | } else { | |
b3b6e05e | 229 | ldpp_dout(dpp, 0) << "WARNING: couldn't find acl header for bucket, generating default" << dendl; |
f67539c2 | 230 | std::unique_ptr<rgw::sal::RGWUser> user = store->get_user(bucket_info.owner); |
7c673cae | 231 | /* object exists, but policy is broken */ |
b3b6e05e | 232 | int r = user->load_by_id(dpp, y); |
7c673cae FG |
233 | if (r < 0) |
234 | return r; | |
235 | ||
f67539c2 | 236 | policy->create_default(bucket_info.owner, user->get_display_name()); |
7c673cae FG |
237 | } |
238 | return 0; | |
239 | } | |
240 | ||
b3b6e05e TL |
241 | static int get_obj_policy_from_attr(const DoutPrefixProvider *dpp, |
242 | CephContext *cct, | |
f67539c2 | 243 | rgw::sal::RGWStore *store, |
31f18b77 FG |
244 | RGWObjectCtx& obj_ctx, |
245 | RGWBucketInfo& bucket_info, | |
246 | map<string, bufferlist>& bucket_attrs, | |
247 | RGWAccessControlPolicy *policy, | |
11fdf7f2 | 248 | string *storage_class, |
f67539c2 | 249 | rgw::sal::RGWObject* obj, |
9f95a23c | 250 | optional_yield y) |
7c673cae FG |
251 | { |
252 | bufferlist bl; | |
253 | int ret = 0; | |
254 | ||
f67539c2 | 255 | std::unique_ptr<rgw::sal::RGWObject::ReadOp> rop = obj->get_read_op(&obj_ctx); |
7c673cae | 256 | |
b3b6e05e | 257 | ret = rop->get_attr(dpp, RGW_ATTR_ACL, bl, y); |
7c673cae | 258 | if (ret >= 0) { |
b3b6e05e | 259 | ret = decode_policy(dpp, cct, bl, policy); |
7c673cae FG |
260 | if (ret < 0) |
261 | return ret; | |
262 | } else if (ret == -ENODATA) { | |
263 | /* object exists, but policy is broken */ | |
b3b6e05e | 264 | ldpp_dout(dpp, 0) << "WARNING: couldn't find acl header for object, generating default" << dendl; |
f67539c2 | 265 | std::unique_ptr<rgw::sal::RGWUser> user = store->get_user(bucket_info.owner); |
b3b6e05e | 266 | ret = user->load_by_id(dpp, y); |
7c673cae FG |
267 | if (ret < 0) |
268 | return ret; | |
269 | ||
f67539c2 | 270 | policy->create_default(bucket_info.owner, user->get_display_name()); |
7c673cae | 271 | } |
11fdf7f2 TL |
272 | |
273 | if (storage_class) { | |
274 | bufferlist scbl; | |
b3b6e05e | 275 | int r = rop->get_attr(dpp, RGW_ATTR_STORAGE_CLASS, scbl, y); |
11fdf7f2 TL |
276 | if (r >= 0) { |
277 | *storage_class = scbl.to_str(); | |
278 | } else { | |
279 | storage_class->clear(); | |
280 | } | |
281 | } | |
282 | ||
7c673cae FG |
283 | return ret; |
284 | } | |
285 | ||
286 | ||
11fdf7f2 | 287 | static boost::optional<Policy> get_iam_policy_from_attr(CephContext* cct, |
11fdf7f2 TL |
288 | map<string, bufferlist>& attrs, |
289 | const string& tenant) { | |
31f18b77 FG |
290 | auto i = attrs.find(RGW_ATTR_IAM_POLICY); |
291 | if (i != attrs.end()) { | |
292 | return Policy(cct, tenant, i->second); | |
293 | } else { | |
294 | return none; | |
295 | } | |
7c673cae FG |
296 | } |
297 | ||
9f95a23c TL |
298 | static boost::optional<PublicAccessBlockConfiguration> |
299 | get_public_access_conf_from_attr(const map<string, bufferlist>& attrs) | |
300 | { | |
301 | if (auto aiter = attrs.find(RGW_ATTR_PUBLIC_ACCESS); | |
302 | aiter != attrs.end()) { | |
303 | bufferlist::const_iterator iter{&aiter->second}; | |
304 | PublicAccessBlockConfiguration access_conf; | |
305 | try { | |
306 | access_conf.decode(iter); | |
307 | } catch (const buffer::error& e) { | |
308 | return boost::none; | |
309 | } | |
310 | return access_conf; | |
311 | } | |
312 | return boost::none; | |
313 | } | |
314 | ||
11fdf7f2 | 315 | vector<Policy> get_iam_user_policy_from_attr(CephContext* cct, |
9f95a23c | 316 | rgw::sal::RGWRadosStore* store, |
11fdf7f2 TL |
317 | map<string, bufferlist>& attrs, |
318 | const string& tenant) { | |
319 | vector<Policy> policies; | |
320 | if (auto it = attrs.find(RGW_ATTR_USER_POLICY); it != attrs.end()) { | |
321 | bufferlist out_bl = attrs[RGW_ATTR_USER_POLICY]; | |
322 | map<string, string> policy_map; | |
323 | decode(policy_map, out_bl); | |
324 | for (auto& it : policy_map) { | |
325 | bufferlist bl = bufferlist::static_from_string(it.second); | |
326 | Policy p(cct, tenant, bl); | |
327 | policies.push_back(std::move(p)); | |
328 | } | |
329 | } | |
330 | return policies; | |
331 | } | |
332 | ||
b3b6e05e TL |
333 | static int get_obj_head(const DoutPrefixProvider *dpp, |
334 | struct req_state *s, | |
f67539c2 TL |
335 | rgw::sal::RGWObject* obj, |
336 | bufferlist *pbl) | |
7c673cae | 337 | { |
f67539c2 TL |
338 | std::unique_ptr<rgw::sal::RGWObject::ReadOp> read_op = obj->get_read_op(s->obj_ctx); |
339 | obj->set_prefetch_data(s->obj_ctx); | |
7c673cae | 340 | |
b3b6e05e | 341 | int ret = read_op->prepare(s->yield, dpp); |
11fdf7f2 TL |
342 | if (ret < 0) { |
343 | return ret; | |
344 | } | |
345 | ||
346 | if (!pbl) { | |
347 | return 0; | |
348 | } | |
349 | ||
b3b6e05e | 350 | ret = read_op->read(0, s->cct->_conf->rgw_max_chunk_size, *pbl, s->yield, dpp); |
11fdf7f2 TL |
351 | |
352 | return 0; | |
353 | } | |
354 | ||
355 | struct multipart_upload_info | |
356 | { | |
357 | rgw_placement_rule dest_placement; | |
358 | ||
359 | void encode(bufferlist& bl) const { | |
360 | ENCODE_START(1, 1, bl); | |
361 | encode(dest_placement, bl); | |
362 | ENCODE_FINISH(bl); | |
363 | } | |
364 | ||
365 | void decode(bufferlist::const_iterator& bl) { | |
366 | DECODE_START(1, bl); | |
367 | decode(dest_placement, bl); | |
368 | DECODE_FINISH(bl); | |
369 | } | |
370 | }; | |
371 | WRITE_CLASS_ENCODER(multipart_upload_info) | |
372 | ||
b3b6e05e | 373 | static int get_multipart_info(const DoutPrefixProvider *dpp, struct req_state *s, |
f67539c2 | 374 | rgw::sal::RGWObject* obj, |
11fdf7f2 TL |
375 | multipart_upload_info *upload_info) |
376 | { | |
377 | bufferlist header; | |
378 | ||
379 | bufferlist headbl; | |
380 | bufferlist *pheadbl = (upload_info ? &headbl : nullptr); | |
381 | ||
b3b6e05e | 382 | int op_ret = get_obj_head(dpp, s, obj, pheadbl); |
11fdf7f2 TL |
383 | if (op_ret < 0) { |
384 | if (op_ret == -ENOENT) { | |
385 | return -ERR_NO_SUCH_UPLOAD; | |
386 | } | |
387 | return op_ret; | |
388 | } | |
389 | ||
390 | if (upload_info && headbl.length() > 0) { | |
391 | auto hiter = headbl.cbegin(); | |
392 | try { | |
393 | decode(*upload_info, hiter); | |
394 | } catch (buffer::error& err) { | |
395 | ldpp_dout(s, 0) << "ERROR: failed to decode multipart upload info" << dendl; | |
396 | return -EIO; | |
397 | } | |
398 | } | |
399 | ||
11fdf7f2 TL |
400 | return 0; |
401 | } | |
402 | ||
b3b6e05e | 403 | static int get_multipart_info(const DoutPrefixProvider *dpp, struct req_state *s, |
11fdf7f2 | 404 | const string& meta_oid, |
11fdf7f2 TL |
405 | multipart_upload_info *upload_info) |
406 | { | |
407 | map<string, bufferlist>::iterator iter; | |
408 | bufferlist header; | |
409 | ||
f67539c2 TL |
410 | std::unique_ptr<rgw::sal::RGWObject> meta_obj; |
411 | meta_obj = s->bucket->get_object(rgw_obj_key(meta_oid, string(), mp_ns)); | |
412 | meta_obj->set_in_extra_data(true); | |
9f95a23c | 413 | |
b3b6e05e | 414 | return get_multipart_info(dpp, s, meta_obj.get(), upload_info); |
7c673cae FG |
415 | } |
416 | ||
b3b6e05e TL |
417 | static int read_bucket_policy(const DoutPrefixProvider *dpp, |
418 | rgw::sal::RGWStore *store, | |
7c673cae FG |
419 | struct req_state *s, |
420 | RGWBucketInfo& bucket_info, | |
421 | map<string, bufferlist>& bucket_attrs, | |
422 | RGWAccessControlPolicy *policy, | |
f67539c2 TL |
423 | rgw_bucket& bucket, |
424 | optional_yield y) | |
7c673cae FG |
425 | { |
426 | if (!s->system_request && bucket_info.flags & BUCKET_SUSPENDED) { | |
b3b6e05e | 427 | ldpp_dout(dpp, 0) << "NOTICE: bucket " << bucket_info.bucket.name |
11fdf7f2 | 428 | << " is suspended" << dendl; |
7c673cae FG |
429 | return -ERR_USER_SUSPENDED; |
430 | } | |
431 | ||
432 | if (bucket.name.empty()) { | |
433 | return 0; | |
434 | } | |
435 | ||
b3b6e05e | 436 | int ret = rgw_op_get_bucket_policy_from_attr(dpp, s->cct, store, bucket_info, bucket_attrs, policy, y); |
7c673cae FG |
437 | if (ret == -ENOENT) { |
438 | ret = -ERR_NO_SUCH_BUCKET; | |
439 | } | |
440 | ||
441 | return ret; | |
442 | } | |
443 | ||
b3b6e05e TL |
444 | static int read_obj_policy(const DoutPrefixProvider *dpp, |
445 | rgw::sal::RGWStore *store, | |
7c673cae FG |
446 | struct req_state *s, |
447 | RGWBucketInfo& bucket_info, | |
448 | map<string, bufferlist>& bucket_attrs, | |
31f18b77 | 449 | RGWAccessControlPolicy* acl, |
11fdf7f2 TL |
450 | string *storage_class, |
451 | boost::optional<Policy>& policy, | |
f67539c2 TL |
452 | rgw::sal::RGWBucket* bucket, |
453 | rgw::sal::RGWObject* object, | |
454 | optional_yield y, | |
455 | bool copy_src=false) | |
7c673cae FG |
456 | { |
457 | string upload_id; | |
458 | upload_id = s->info.args.get("uploadId"); | |
f67539c2 | 459 | std::unique_ptr<rgw::sal::RGWObject> mpobj; |
7c673cae FG |
460 | rgw_obj obj; |
461 | ||
462 | if (!s->system_request && bucket_info.flags & BUCKET_SUSPENDED) { | |
b3b6e05e | 463 | ldpp_dout(dpp, 0) << "NOTICE: bucket " << bucket_info.bucket.name |
11fdf7f2 | 464 | << " is suspended" << dendl; |
7c673cae FG |
465 | return -ERR_USER_SUSPENDED; |
466 | } | |
467 | ||
f67539c2 TL |
468 | // when getting policy info for copy-source obj, upload_id makes no sense. |
469 | // 'copy_src' is used to make this function backward compatible. | |
470 | if (!upload_id.empty() && !copy_src) { | |
7c673cae | 471 | /* multipart upload */ |
f67539c2 | 472 | RGWMPObj mp(object->get_name(), upload_id); |
7c673cae | 473 | string oid = mp.get_meta(); |
f67539c2 TL |
474 | mpobj = bucket->get_object(rgw_obj_key(oid, string(), mp_ns)); |
475 | mpobj->set_in_extra_data(true); | |
476 | object = mpobj.get(); | |
7c673cae | 477 | } |
f67539c2 | 478 | policy = get_iam_policy_from_attr(s->cct, bucket_attrs, bucket->get_tenant()); |
31f18b77 | 479 | |
7c673cae | 480 | RGWObjectCtx *obj_ctx = static_cast<RGWObjectCtx *>(s->obj_ctx); |
b3b6e05e | 481 | int ret = get_obj_policy_from_attr(dpp, s->cct, store, *obj_ctx, |
f67539c2 | 482 | bucket_info, bucket_attrs, acl, storage_class, object, s->yield); |
7c673cae FG |
483 | if (ret == -ENOENT) { |
484 | /* object does not exist checking the bucket's ACL to make sure | |
485 | that we send a proper error code */ | |
486 | RGWAccessControlPolicy bucket_policy(s->cct); | |
b3b6e05e | 487 | ret = rgw_op_get_bucket_policy_from_attr(dpp, s->cct, store, bucket_info, bucket_attrs, &bucket_policy, y); |
7c673cae FG |
488 | if (ret < 0) { |
489 | return ret; | |
490 | } | |
7c673cae | 491 | const rgw_user& bucket_owner = bucket_policy.get_owner().get_id(); |
9f95a23c | 492 | if (bucket_owner.compare(s->user->get_id()) != 0 && |
81eedcae | 493 | ! s->auth.identity->is_admin_of(bucket_owner)) { |
522d829b TL |
494 | auto r = eval_identity_or_session_policies(s->iam_user_policies, s->env, |
495 | *s->auth.identity, rgw::IAM::s3ListBucket, | |
496 | ARN(bucket->get_key())); | |
497 | if (r == Effect::Allow) | |
498 | return -ENOENT; | |
499 | if (r == Effect::Deny) | |
500 | return -EACCES; | |
81eedcae | 501 | if (policy) { |
522d829b TL |
502 | r = policy->eval(s->env, *s->auth.identity, rgw::IAM::s3ListBucket, ARN(bucket->get_key())); |
503 | if (r == Effect::Allow) | |
504 | return -ENOENT; | |
505 | if (r == Effect::Deny) | |
506 | return -EACCES; | |
507 | } | |
508 | if (! s->session_policies.empty()) { | |
509 | r = eval_identity_or_session_policies(s->session_policies, s->env, | |
510 | *s->auth.identity, rgw::IAM::s3ListBucket, | |
511 | ARN(bucket->get_key())); | |
81eedcae TL |
512 | if (r == Effect::Allow) |
513 | return -ENOENT; | |
514 | if (r == Effect::Deny) | |
515 | return -EACCES; | |
516 | } | |
517 | if (! bucket_policy.verify_permission(s, *s->auth.identity, s->perm_mask, RGW_PERM_READ)) | |
518 | ret = -EACCES; | |
519 | else | |
520 | ret = -ENOENT; | |
7c673cae FG |
521 | } else { |
522 | ret = -ENOENT; | |
523 | } | |
524 | } | |
525 | ||
526 | return ret; | |
527 | } | |
528 | ||
529 | /** | |
530 | * Get the AccessControlPolicy for an user, bucket or object off of disk. | |
531 | * s: The req_state to draw information from. | |
532 | * only_bucket: If true, reads the user and bucket ACLs rather than the object ACL. | |
533 | * Returns: 0 on success, -ERR# otherwise. | |
534 | */ | |
b3b6e05e | 535 | int rgw_build_bucket_policies(const DoutPrefixProvider *dpp, rgw::sal::RGWRadosStore* store, struct req_state* s, optional_yield y) |
7c673cae FG |
536 | { |
537 | int ret = 0; | |
9f95a23c | 538 | auto obj_ctx = store->svc()->sysobj->init_obj_ctx(); |
7c673cae FG |
539 | |
540 | string bi = s->info.args.get(RGW_SYS_PARAM_PREFIX "bucket-instance"); | |
541 | if (!bi.empty()) { | |
522d829b TL |
542 | // note: overwrites s->bucket_name, may include a tenant/ |
543 | ret = rgw_bucket_parse_bucket_instance(bi, &s->bucket_name, &s->bucket_instance_id, &s->bucket_instance_shard_id); | |
7c673cae FG |
544 | if (ret < 0) { |
545 | return ret; | |
546 | } | |
547 | } | |
548 | ||
549 | if(s->dialect.compare("s3") == 0) { | |
11fdf7f2 | 550 | s->bucket_acl = std::make_unique<RGWAccessControlPolicy_S3>(s->cct); |
7c673cae FG |
551 | } else if(s->dialect.compare("swift") == 0) { |
552 | /* We aren't allocating the account policy for those operations using | |
553 | * the Swift's infrastructure that don't really need req_state::user. | |
554 | * Typical example here is the implementation of /info. */ | |
9f95a23c | 555 | if (!s->user->get_id().empty()) { |
11fdf7f2 | 556 | s->user_acl = std::make_unique<RGWAccessControlPolicy_SWIFTAcct>(s->cct); |
7c673cae | 557 | } |
11fdf7f2 | 558 | s->bucket_acl = std::make_unique<RGWAccessControlPolicy_SWIFT>(s->cct); |
7c673cae | 559 | } else { |
11fdf7f2 | 560 | s->bucket_acl = std::make_unique<RGWAccessControlPolicy>(s->cct); |
7c673cae FG |
561 | } |
562 | ||
563 | /* check if copy source is within the current domain */ | |
564 | if (!s->src_bucket_name.empty()) { | |
f67539c2 | 565 | std::unique_ptr<rgw::sal::RGWBucket> src_bucket; |
b3b6e05e | 566 | ret = store->get_bucket(dpp, nullptr, s->src_tenant_name, s->src_bucket_name, &src_bucket, y); |
f67539c2 | 567 | if (ret == 0) { |
b3b6e05e | 568 | ret = src_bucket->load_by_name(dpp, s->src_tenant_name, s->src_bucket_name, |
f67539c2 | 569 | s->bucket_instance_id, &obj_ctx, s->yield); |
7c673cae FG |
570 | } |
571 | if (ret == 0) { | |
f67539c2 TL |
572 | string& zonegroup = src_bucket->get_info().zonegroup; |
573 | s->local_source = store->get_zonegroup().equals(zonegroup); | |
7c673cae FG |
574 | } |
575 | } | |
576 | ||
577 | struct { | |
578 | rgw_user uid; | |
579 | std::string display_name; | |
580 | } acct_acl_user = { | |
9f95a23c TL |
581 | s->user->get_id(), |
582 | s->user->get_display_name(), | |
7c673cae FG |
583 | }; |
584 | ||
585 | if (!s->bucket_name.empty()) { | |
586 | s->bucket_exists = true; | |
9f95a23c | 587 | |
b3b6e05e | 588 | ret = store->get_bucket(dpp, s->user.get(), rgw_bucket(rgw_bucket_key(s->bucket_tenant, s->bucket_name, s->bucket_instance_id)), &s->bucket, y); |
7c673cae FG |
589 | if (ret < 0) { |
590 | if (ret != -ENOENT) { | |
f67539c2 TL |
591 | string bucket_log; |
592 | bucket_log = rgw_make_bucket_entry_name(s->bucket_tenant, s->bucket_name); | |
b3b6e05e | 593 | ldpp_dout(dpp, 0) << "NOTICE: couldn't get bucket from bucket_name (name=" |
f67539c2 TL |
594 | << bucket_log << ")" << dendl; |
595 | return ret; | |
7c673cae FG |
596 | } |
597 | s->bucket_exists = false; | |
9f95a23c | 598 | return -ERR_NO_SUCH_BUCKET; |
7c673cae | 599 | } |
b3b6e05e TL |
600 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
601 | s->object->set_bucket(s->bucket.get()); | |
602 | } | |
603 | ||
f67539c2 TL |
604 | s->bucket_mtime = s->bucket->get_modification_time(); |
605 | s->bucket_attrs = s->bucket->get_attrs(); | |
b3b6e05e | 606 | ret = read_bucket_policy(dpp, store, s, s->bucket->get_info(), |
f67539c2 TL |
607 | s->bucket->get_attrs(), |
608 | s->bucket_acl.get(), s->bucket->get_key(), y); | |
609 | acct_acl_user = { | |
610 | s->bucket->get_info().owner, | |
611 | s->bucket_acl->get_owner().get_display_name(), | |
612 | }; | |
613 | ||
7c673cae FG |
614 | s->bucket_owner = s->bucket_acl->get_owner(); |
615 | ||
616 | RGWZoneGroup zonegroup; | |
f67539c2 | 617 | int r = store->get_zonegroup(s->bucket->get_info().zonegroup, zonegroup); |
7c673cae FG |
618 | if (!r) { |
619 | if (!zonegroup.endpoints.empty()) { | |
620 | s->zonegroup_endpoint = zonegroup.endpoints.front(); | |
621 | } else { | |
622 | // use zonegroup's master zone endpoints | |
623 | auto z = zonegroup.zones.find(zonegroup.master_zone); | |
624 | if (z != zonegroup.zones.end() && !z->second.endpoints.empty()) { | |
625 | s->zonegroup_endpoint = z->second.endpoints.front(); | |
626 | } | |
627 | } | |
628 | s->zonegroup_name = zonegroup.get_name(); | |
629 | } | |
630 | if (r < 0 && ret == 0) { | |
631 | ret = r; | |
632 | } | |
633 | ||
f67539c2 | 634 | if (!store->get_zonegroup().equals(s->bucket->get_info().zonegroup)) { |
b3b6e05e | 635 | ldpp_dout(dpp, 0) << "NOTICE: request for data in a different zonegroup (" |
f67539c2 TL |
636 | << s->bucket->get_info().zonegroup << " != " |
637 | << store->get_zonegroup().get_id() << ")" << dendl; | |
7c673cae FG |
638 | /* we now need to make sure that the operation actually requires copy source, that is |
639 | * it's a copy operation | |
640 | */ | |
f67539c2 | 641 | if (store->get_zonegroup().is_master_zonegroup() && s->system_request) { |
7c673cae | 642 | /*If this is the master, don't redirect*/ |
3efd9988 FG |
643 | } else if (s->op_type == RGW_OP_GET_BUCKET_LOCATION ) { |
644 | /* If op is get bucket location, don't redirect */ | |
7c673cae FG |
645 | } else if (!s->local_source || |
646 | (s->op != OP_PUT && s->op != OP_COPY) || | |
f67539c2 | 647 | rgw::sal::RGWObject::empty(s->object.get())) { |
7c673cae FG |
648 | return -ERR_PERMANENT_REDIRECT; |
649 | } | |
650 | } | |
11fdf7f2 | 651 | |
f67539c2 TL |
652 | /* init dest placement */ |
653 | s->dest_placement.storage_class = s->info.storage_class; | |
654 | s->dest_placement.inherit_from(s->bucket->get_placement_rule()); | |
11fdf7f2 | 655 | |
f67539c2 | 656 | if (!store->svc()->zone->get_zone_params().valid_placement(s->dest_placement)) { |
b3b6e05e | 657 | ldpp_dout(dpp, 0) << "NOTICE: invalid dest placement: " << s->dest_placement.to_str() << dendl; |
f67539c2 | 658 | return -EINVAL; |
11fdf7f2 | 659 | } |
9f95a23c | 660 | |
f67539c2 | 661 | s->bucket_access_conf = get_public_access_conf_from_attr(s->bucket->get_attrs()); |
7c673cae FG |
662 | } |
663 | ||
664 | /* handle user ACL only for those APIs which support it */ | |
665 | if (s->user_acl) { | |
666 | map<string, bufferlist> uattrs; | |
b3b6e05e | 667 | ret = store->ctl()->user->get_attrs_by_uid(dpp, acct_acl_user.uid, &uattrs, s->yield); |
7c673cae | 668 | if (!ret) { |
b3b6e05e | 669 | ret = get_user_policy_from_attr(dpp, s->cct, store, uattrs, *s->user_acl); |
7c673cae FG |
670 | } |
671 | if (-ENOENT == ret) { | |
672 | /* In already existing clusters users won't have ACL. In such case | |
673 | * assuming that only account owner has the rights seems to be | |
674 | * reasonable. That allows to have only one verification logic. | |
675 | * NOTE: there is small compatibility kludge for global, empty tenant: | |
676 | * 1. if we try to reach an existing bucket, its owner is considered | |
677 | * as account owner. | |
678 | * 2. otherwise account owner is identity stored in s->user->user_id. */ | |
679 | s->user_acl->create_default(acct_acl_user.uid, | |
680 | acct_acl_user.display_name); | |
681 | ret = 0; | |
11fdf7f2 | 682 | } else if (ret < 0) { |
b3b6e05e | 683 | ldpp_dout(dpp, 0) << "NOTICE: couldn't get user attrs for handling ACL " |
9f95a23c | 684 | "(user_id=" << s->user->get_id() << ", ret=" << ret << ")" << dendl; |
7c673cae FG |
685 | return ret; |
686 | } | |
687 | } | |
11fdf7f2 TL |
688 | // We don't need user policies in case of STS token returned by AssumeRole, |
689 | // hence the check for user type | |
9f95a23c | 690 | if (! s->user->get_id().empty() && s->auth.identity->get_identity_type() != TYPE_ROLE) { |
11fdf7f2 TL |
691 | try { |
692 | map<string, bufferlist> uattrs; | |
b3b6e05e | 693 | if (ret = store->ctl()->user->get_attrs_by_uid(dpp, s->user->get_id(), &uattrs, s->yield); ! ret) { |
9f95a23c | 694 | auto user_policies = get_iam_user_policy_from_attr(s->cct, store, uattrs, s->user->get_tenant()); |
f67539c2 TL |
695 | s->iam_user_policies.insert(s->iam_user_policies.end(), |
696 | std::make_move_iterator(user_policies.begin()), | |
697 | std::make_move_iterator(user_policies.end())); | |
11fdf7f2 TL |
698 | } else { |
699 | if (ret == -ENOENT) | |
700 | ret = 0; | |
701 | else ret = -EACCES; | |
702 | } | |
703 | } catch (const std::exception& e) { | |
b3b6e05e | 704 | ldpp_dout(dpp, -1) << "Error reading IAM User Policy: " << e.what() << dendl; |
11fdf7f2 TL |
705 | ret = -EACCES; |
706 | } | |
707 | } | |
7c673cae | 708 | |
31f18b77 | 709 | try { |
f67539c2 | 710 | s->iam_policy = get_iam_policy_from_attr(s->cct, s->bucket_attrs, s->bucket_tenant); |
31f18b77 FG |
711 | } catch (const std::exception& e) { |
712 | // Really this is a can't happen condition. We parse the policy | |
713 | // when it's given to us, so perhaps we should abort or otherwise | |
714 | // raise bloody murder. | |
b3b6e05e | 715 | ldpp_dout(dpp, 0) << "Error reading IAM Policy: " << e.what() << dendl; |
31f18b77 FG |
716 | ret = -EACCES; |
717 | } | |
7c673cae | 718 | |
9f95a23c | 719 | bool success = store->svc()->zone->get_redirect_zone_endpoint(&s->redirect_zone_endpoint); |
11fdf7f2 | 720 | if (success) { |
b3b6e05e | 721 | ldpp_dout(dpp, 20) << "redirect_zone_endpoint=" << s->redirect_zone_endpoint << dendl; |
11fdf7f2 TL |
722 | } |
723 | ||
7c673cae FG |
724 | return ret; |
725 | } | |
726 | ||
727 | /** | |
728 | * Get the AccessControlPolicy for a bucket or object off of disk. | |
729 | * s: The req_state to draw information from. | |
730 | * only_bucket: If true, reads the bucket ACL rather than the object ACL. | |
731 | * Returns: 0 on success, -ERR# otherwise. | |
732 | */ | |
b3b6e05e | 733 | int rgw_build_object_policies(const DoutPrefixProvider *dpp, rgw::sal::RGWRadosStore *store, struct req_state *s, |
f67539c2 | 734 | bool prefetch_data, optional_yield y) |
7c673cae FG |
735 | { |
736 | int ret = 0; | |
737 | ||
f67539c2 | 738 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
7c673cae FG |
739 | if (!s->bucket_exists) { |
740 | return -ERR_NO_SUCH_BUCKET; | |
741 | } | |
11fdf7f2 | 742 | s->object_acl = std::make_unique<RGWAccessControlPolicy>(s->cct); |
f67539c2 TL |
743 | |
744 | s->object->set_bucket(s->bucket.get()); | |
7c673cae | 745 | |
f67539c2 | 746 | s->object->set_atomic(s->obj_ctx); |
7c673cae | 747 | if (prefetch_data) { |
f67539c2 | 748 | s->object->set_prefetch_data(s->obj_ctx); |
7c673cae | 749 | } |
b3b6e05e | 750 | ret = read_obj_policy(dpp, store, s, s->bucket->get_info(), s->bucket_attrs, |
f67539c2 TL |
751 | s->object_acl.get(), nullptr, s->iam_policy, s->bucket.get(), |
752 | s->object.get(), y); | |
7c673cae FG |
753 | } |
754 | ||
755 | return ret; | |
756 | } | |
757 | ||
11fdf7f2 TL |
758 | void rgw_add_to_iam_environment(rgw::IAM::Environment& e, std::string_view key, std::string_view val){ |
759 | // This variant just adds non empty key pairs to IAM env., values can be empty | |
760 | // in certain cases like tagging | |
761 | if (!key.empty()) | |
762 | e.emplace(key,val); | |
763 | } | |
764 | ||
765 | static int rgw_iam_add_tags_from_bl(struct req_state* s, bufferlist& bl){ | |
9f95a23c | 766 | RGWObjTags& tagset = s->tagset; |
11fdf7f2 TL |
767 | try { |
768 | auto bliter = bl.cbegin(); | |
769 | tagset.decode(bliter); | |
770 | } catch (buffer::error& err) { | |
771 | ldpp_dout(s, 0) << "ERROR: caught buffer::error, couldn't decode TagSet" << dendl; | |
772 | return -EIO; | |
773 | } | |
774 | ||
775 | for (const auto& tag: tagset.get_tags()){ | |
776 | rgw_add_to_iam_environment(s->env, "s3:ExistingObjectTag/" + tag.first, tag.second); | |
777 | } | |
778 | return 0; | |
779 | } | |
780 | ||
b3b6e05e | 781 | static int rgw_iam_add_existing_objtags(const DoutPrefixProvider *dpp, rgw::sal::RGWRadosStore* store, struct req_state* s, std::uint64_t action) { |
f67539c2 | 782 | s->object->set_atomic(s->obj_ctx); |
b3b6e05e | 783 | int op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, dpp); |
11fdf7f2 TL |
784 | if (op_ret < 0) |
785 | return op_ret; | |
f67539c2 | 786 | rgw::sal::RGWAttrs attrs = s->object->get_attrs(); |
11fdf7f2 TL |
787 | auto tags = attrs.find(RGW_ATTR_TAGS); |
788 | if (tags != attrs.end()){ | |
789 | return rgw_iam_add_tags_from_bl(s, tags->second); | |
790 | } | |
791 | return 0; | |
792 | } | |
793 | ||
794 | static void rgw_add_grant_to_iam_environment(rgw::IAM::Environment& e, struct req_state *s){ | |
795 | ||
796 | using header_pair_t = std::pair <const char*, const char*>; | |
797 | static const std::initializer_list <header_pair_t> acl_header_conditionals { | |
798 | {"HTTP_X_AMZ_GRANT_READ", "s3:x-amz-grant-read"}, | |
799 | {"HTTP_X_AMZ_GRANT_WRITE", "s3:x-amz-grant-write"}, | |
800 | {"HTTP_X_AMZ_GRANT_READ_ACP", "s3:x-amz-grant-read-acp"}, | |
801 | {"HTTP_X_AMZ_GRANT_WRITE_ACP", "s3:x-amz-grant-write-acp"}, | |
802 | {"HTTP_X_AMZ_GRANT_FULL_CONTROL", "s3:x-amz-grant-full-control"} | |
803 | }; | |
804 | ||
805 | if (s->has_acl_header){ | |
806 | for (const auto& c: acl_header_conditionals){ | |
807 | auto hdr = s->info.env->get(c.first); | |
808 | if(hdr) { | |
809 | e[c.second] = hdr; | |
810 | } | |
811 | } | |
812 | } | |
813 | } | |
814 | ||
9f95a23c | 815 | void rgw_build_iam_environment(rgw::sal::RGWRadosStore* store, |
11fdf7f2 | 816 | struct req_state* s) |
31f18b77 | 817 | { |
31f18b77 FG |
818 | const auto& m = s->info.env->get_map(); |
819 | auto t = ceph::real_clock::now(); | |
11fdf7f2 TL |
820 | s->env.emplace("aws:CurrentTime", std::to_string(ceph::real_clock::to_time_t(t))); |
821 | s->env.emplace("aws:EpochTime", ceph::to_iso_8601(t)); | |
31f18b77 FG |
822 | // TODO: This is fine for now, but once we have STS we'll need to |
823 | // look and see. Also this won't work with the IdentityApplier | |
824 | // model, since we need to know the actual credential. | |
11fdf7f2 | 825 | s->env.emplace("aws:PrincipalType", "User"); |
31f18b77 FG |
826 | |
827 | auto i = m.find("HTTP_REFERER"); | |
828 | if (i != m.end()) { | |
11fdf7f2 | 829 | s->env.emplace("aws:Referer", i->second); |
31f18b77 FG |
830 | } |
831 | ||
f64942e4 | 832 | if (rgw_transport_is_secure(s->cct, *s->info.env)) { |
11fdf7f2 | 833 | s->env.emplace("aws:SecureTransport", "true"); |
31f18b77 FG |
834 | } |
835 | ||
b32b8144 FG |
836 | const auto remote_addr_param = s->cct->_conf->rgw_remote_addr_param; |
837 | if (remote_addr_param.length()) { | |
838 | i = m.find(remote_addr_param); | |
839 | } else { | |
840 | i = m.find("REMOTE_ADDR"); | |
841 | } | |
31f18b77 | 842 | if (i != m.end()) { |
b32b8144 FG |
843 | const string* ip = &(i->second); |
844 | string temp; | |
845 | if (remote_addr_param == "HTTP_X_FORWARDED_FOR") { | |
846 | const auto comma = ip->find(','); | |
847 | if (comma != string::npos) { | |
848 | temp.assign(*ip, 0, comma); | |
849 | ip = &temp; | |
850 | } | |
851 | } | |
11fdf7f2 | 852 | s->env.emplace("aws:SourceIp", *ip); |
31f18b77 FG |
853 | } |
854 | ||
855 | i = m.find("HTTP_USER_AGENT"); { | |
856 | if (i != m.end()) | |
11fdf7f2 | 857 | s->env.emplace("aws:UserAgent", i->second); |
31f18b77 FG |
858 | } |
859 | ||
860 | if (s->user) { | |
861 | // What to do about aws::userid? One can have multiple access | |
862 | // keys so that isn't really suitable. Do we have a durable | |
863 | // identifier that can persist through name changes? | |
9f95a23c | 864 | s->env.emplace("aws:username", s->user->get_id().id); |
11fdf7f2 TL |
865 | } |
866 | ||
867 | i = m.find("HTTP_X_AMZ_SECURITY_TOKEN"); | |
868 | if (i != m.end()) { | |
869 | s->env.emplace("sts:authentication", "true"); | |
870 | } else { | |
871 | s->env.emplace("sts:authentication", "false"); | |
31f18b77 | 872 | } |
31f18b77 FG |
873 | } |
874 | ||
875 | void rgw_bucket_object_pre_exec(struct req_state *s) | |
7c673cae FG |
876 | { |
877 | if (s->expect_cont) | |
878 | dump_continue(s); | |
879 | ||
880 | dump_bucket_from_state(s); | |
881 | } | |
882 | ||
b32b8144 FG |
883 | // So! Now and then when we try to update bucket information, the |
884 | // bucket has changed during the course of the operation. (Or we have | |
885 | // a cache consistency problem that Watch/Notify isn't ruling out | |
886 | // completely.) | |
887 | // | |
888 | // When this happens, we need to update the bucket info and try | |
889 | // again. We have, however, to try the right *part* again. We can't | |
890 | // simply re-send, since that will obliterate the previous update. | |
891 | // | |
892 | // Thus, callers of this function should include everything that | |
893 | // merges information to be changed into the bucket information as | |
894 | // well as the call to set it. | |
895 | // | |
896 | // The called function must return an integer, negative on error. In | |
897 | // general, they should just return op_ret. | |
898 | namespace { | |
899 | template<typename F> | |
b3b6e05e | 900 | int retry_raced_bucket_write(const DoutPrefixProvider *dpp, rgw::sal::RGWBucket* b, const F& f) { |
b32b8144 FG |
901 | auto r = f(); |
902 | for (auto i = 0u; i < 15u && r == -ECANCELED; ++i) { | |
b3b6e05e | 903 | r = b->try_refresh_info(dpp, nullptr); |
b32b8144 FG |
904 | if (r >= 0) { |
905 | r = f(); | |
906 | } | |
907 | } | |
908 | return r; | |
909 | } | |
910 | } | |
911 | ||
912 | ||
f67539c2 | 913 | int RGWGetObj::verify_permission(optional_yield y) |
7c673cae | 914 | { |
f67539c2 TL |
915 | s->object->set_atomic(s->obj_ctx); |
916 | ||
917 | if (prefetch_data()) { | |
918 | s->object->set_prefetch_data(s->obj_ctx); | |
7c673cae FG |
919 | } |
920 | ||
31f18b77 | 921 | if (torrent.get_flag()) { |
f67539c2 | 922 | if (s->object->get_instance().empty()) { |
31f18b77 FG |
923 | action = rgw::IAM::s3GetObjectTorrent; |
924 | } else { | |
925 | action = rgw::IAM::s3GetObjectVersionTorrent; | |
926 | } | |
927 | } else { | |
f67539c2 | 928 | if (s->object->get_instance().empty()) { |
31f18b77 FG |
929 | action = rgw::IAM::s3GetObject; |
930 | } else { | |
931 | action = rgw::IAM::s3GetObjectVersion; | |
932 | } | |
11fdf7f2 | 933 | if (s->iam_policy && s->iam_policy->has_partial_conditional(S3_EXISTING_OBJTAG)) |
b3b6e05e | 934 | rgw_iam_add_existing_objtags(this, store, s, action); |
11fdf7f2 TL |
935 | if (! s->iam_user_policies.empty()) { |
936 | for (auto& user_policy : s->iam_user_policies) { | |
937 | if (user_policy.has_partial_conditional(S3_EXISTING_OBJTAG)) | |
b3b6e05e | 938 | rgw_iam_add_existing_objtags(this, store, s, action); |
11fdf7f2 TL |
939 | } |
940 | } | |
31f18b77 FG |
941 | } |
942 | ||
11fdf7f2 | 943 | if (!verify_object_permission(this, s, action)) { |
7c673cae FG |
944 | return -EACCES; |
945 | } | |
946 | ||
f67539c2 | 947 | if (s->bucket->get_info().obj_lock_enabled()) { |
eafe8130 TL |
948 | get_retention = verify_object_permission(this, s, rgw::IAM::s3GetObjectRetention); |
949 | get_legal_hold = verify_object_permission(this, s, rgw::IAM::s3GetObjectLegalHold); | |
950 | } | |
951 | ||
7c673cae FG |
952 | return 0; |
953 | } | |
954 | ||
7c673cae FG |
955 | int RGWOp::verify_op_mask() |
956 | { | |
957 | uint32_t required_mask = op_mask(); | |
958 | ||
11fdf7f2 | 959 | ldpp_dout(this, 20) << "required_mask= " << required_mask |
9f95a23c | 960 | << " user.op_mask=" << s->user->get_info().op_mask << dendl; |
7c673cae | 961 | |
9f95a23c | 962 | if ((s->user->get_info().op_mask & required_mask) != required_mask) { |
7c673cae FG |
963 | return -EPERM; |
964 | } | |
965 | ||
9f95a23c | 966 | if (!s->system_request && (required_mask & RGW_OP_TYPE_MODIFY) && !store->svc()->zone->zone_is_writeable()) { |
11fdf7f2 TL |
967 | ldpp_dout(this, 5) << "NOTICE: modify request to a read-only zone by a " |
968 | "non-system user, permission denied" << dendl; | |
7c673cae FG |
969 | return -EPERM; |
970 | } | |
971 | ||
972 | return 0; | |
973 | } | |
974 | ||
f67539c2 | 975 | int RGWGetObjTags::verify_permission(optional_yield y) |
224ce89b | 976 | { |
f67539c2 | 977 | auto iam_action = s->object->get_instance().empty()? |
11fdf7f2 TL |
978 | rgw::IAM::s3GetObjectTagging: |
979 | rgw::IAM::s3GetObjectVersionTagging; | |
980 | // TODO since we are parsing the bl now anyway, we probably change | |
981 | // the send_response function to accept RGWObjTag instead of a bl | |
982 | if (s->iam_policy && s->iam_policy->has_partial_conditional(S3_EXISTING_OBJTAG)){ | |
b3b6e05e | 983 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
984 | } |
985 | if (! s->iam_user_policies.empty()) { | |
986 | for (auto& user_policy : s->iam_user_policies) { | |
987 | if (user_policy.has_partial_conditional(S3_EXISTING_OBJTAG)) { | |
b3b6e05e | 988 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
989 | } |
990 | } | |
991 | } | |
992 | if (!verify_object_permission(this, s,iam_action)) | |
224ce89b WB |
993 | return -EACCES; |
994 | ||
995 | return 0; | |
996 | } | |
997 | ||
998 | void RGWGetObjTags::pre_exec() | |
999 | { | |
1000 | rgw_bucket_object_pre_exec(s); | |
1001 | } | |
1002 | ||
f67539c2 | 1003 | void RGWGetObjTags::execute(optional_yield y) |
224ce89b | 1004 | { |
f67539c2 | 1005 | rgw::sal::RGWAttrs attrs; |
224ce89b | 1006 | |
f67539c2 | 1007 | s->object->set_atomic(s->obj_ctx); |
224ce89b | 1008 | |
b3b6e05e | 1009 | op_ret = s->object->get_obj_attrs(s->obj_ctx, y, this); |
b5b8bbf5 | 1010 | if (op_ret < 0) { |
f67539c2 | 1011 | ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << s->object |
11fdf7f2 | 1012 | << " ret=" << op_ret << dendl; |
b5b8bbf5 FG |
1013 | return; |
1014 | } | |
1015 | ||
f67539c2 | 1016 | attrs = s->object->get_attrs(); |
224ce89b WB |
1017 | auto tags = attrs.find(RGW_ATTR_TAGS); |
1018 | if(tags != attrs.end()){ | |
1019 | has_tags = true; | |
1020 | tags_bl.append(tags->second); | |
1021 | } | |
1022 | send_response_data(tags_bl); | |
1023 | } | |
1024 | ||
f67539c2 | 1025 | int RGWPutObjTags::verify_permission(optional_yield y) |
224ce89b | 1026 | { |
f67539c2 | 1027 | auto iam_action = s->object->get_instance().empty() ? |
11fdf7f2 TL |
1028 | rgw::IAM::s3PutObjectTagging: |
1029 | rgw::IAM::s3PutObjectVersionTagging; | |
1030 | ||
1031 | if(s->iam_policy && s->iam_policy->has_partial_conditional(S3_EXISTING_OBJTAG)){ | |
b3b6e05e | 1032 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
1033 | } |
1034 | if (! s->iam_user_policies.empty()) { | |
1035 | for (auto& user_policy : s->iam_user_policies) { | |
1036 | if (user_policy.has_partial_conditional(S3_EXISTING_OBJTAG)) { | |
b3b6e05e | 1037 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
1038 | } |
1039 | } | |
1040 | } | |
1041 | if (!verify_object_permission(this, s,iam_action)) | |
224ce89b WB |
1042 | return -EACCES; |
1043 | return 0; | |
1044 | } | |
1045 | ||
f67539c2 | 1046 | void RGWPutObjTags::execute(optional_yield y) |
224ce89b | 1047 | { |
f67539c2 | 1048 | op_ret = get_params(y); |
224ce89b WB |
1049 | if (op_ret < 0) |
1050 | return; | |
1051 | ||
f67539c2 | 1052 | if (rgw::sal::RGWObject::empty(s->object.get())){ |
224ce89b WB |
1053 | op_ret= -EINVAL; // we only support tagging on existing objects |
1054 | return; | |
1055 | } | |
1056 | ||
f67539c2 | 1057 | s->object->set_atomic(s->obj_ctx); |
b3b6e05e | 1058 | op_ret = s->object->modify_obj_attrs(s->obj_ctx, RGW_ATTR_TAGS, tags_bl, y, this); |
224ce89b WB |
1059 | if (op_ret == -ECANCELED){ |
1060 | op_ret = -ERR_TAG_CONFLICT; | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | void RGWDeleteObjTags::pre_exec() | |
1065 | { | |
1066 | rgw_bucket_object_pre_exec(s); | |
1067 | } | |
1068 | ||
1069 | ||
f67539c2 | 1070 | int RGWDeleteObjTags::verify_permission(optional_yield y) |
224ce89b | 1071 | { |
f67539c2 TL |
1072 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
1073 | auto iam_action = s->object->get_instance().empty() ? | |
11fdf7f2 TL |
1074 | rgw::IAM::s3DeleteObjectTagging: |
1075 | rgw::IAM::s3DeleteObjectVersionTagging; | |
1076 | ||
1077 | if (s->iam_policy && s->iam_policy->has_partial_conditional(S3_EXISTING_OBJTAG)){ | |
b3b6e05e | 1078 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
1079 | } |
1080 | if (! s->iam_user_policies.empty()) { | |
1081 | for (auto& user_policy : s->iam_user_policies) { | |
1082 | if (user_policy.has_partial_conditional(S3_EXISTING_OBJTAG)) { | |
b3b6e05e | 1083 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
1084 | } |
1085 | } | |
1086 | } | |
1087 | if (!verify_object_permission(this, s, iam_action)) | |
224ce89b WB |
1088 | return -EACCES; |
1089 | } | |
1090 | return 0; | |
1091 | } | |
1092 | ||
f67539c2 | 1093 | void RGWDeleteObjTags::execute(optional_yield y) |
224ce89b | 1094 | { |
f67539c2 | 1095 | if (rgw::sal::RGWObject::empty(s->object.get())) |
224ce89b WB |
1096 | return; |
1097 | ||
b3b6e05e | 1098 | op_ret = s->object->delete_obj_attrs(this, s->obj_ctx, RGW_ATTR_TAGS, y); |
9f95a23c TL |
1099 | } |
1100 | ||
f67539c2 | 1101 | int RGWGetBucketTags::verify_permission(optional_yield y) |
9f95a23c TL |
1102 | { |
1103 | ||
1104 | if (!verify_bucket_permission(this, s, rgw::IAM::s3GetBucketTagging)) { | |
1105 | return -EACCES; | |
1106 | } | |
1107 | ||
1108 | return 0; | |
1109 | } | |
1110 | ||
1111 | void RGWGetBucketTags::pre_exec() | |
1112 | { | |
1113 | rgw_bucket_object_pre_exec(s); | |
1114 | } | |
1115 | ||
f67539c2 | 1116 | void RGWGetBucketTags::execute(optional_yield y) |
9f95a23c TL |
1117 | { |
1118 | auto iter = s->bucket_attrs.find(RGW_ATTR_TAGS); | |
1119 | if (iter != s->bucket_attrs.end()) { | |
1120 | has_tags = true; | |
1121 | tags_bl.append(iter->second); | |
1122 | } else { | |
1123 | op_ret = -ERR_NO_SUCH_TAG_SET; | |
1124 | } | |
1125 | send_response_data(tags_bl); | |
1126 | } | |
1127 | ||
f67539c2 | 1128 | int RGWPutBucketTags::verify_permission(optional_yield y) { |
9f95a23c TL |
1129 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketTagging); |
1130 | } | |
1131 | ||
f67539c2 TL |
1132 | void RGWPutBucketTags::execute(optional_yield y) |
1133 | { | |
9f95a23c | 1134 | |
b3b6e05e | 1135 | op_ret = get_params(this, y); |
9f95a23c TL |
1136 | if (op_ret < 0) |
1137 | return; | |
1138 | ||
b3b6e05e | 1139 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
1140 | if (op_ret < 0) { |
1141 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
9f95a23c TL |
1142 | } |
1143 | ||
b3b6e05e | 1144 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this, y] { |
f67539c2 | 1145 | rgw::sal::RGWAttrs attrs = s->bucket->get_attrs(); |
9f95a23c | 1146 | attrs[RGW_ATTR_TAGS] = tags_bl; |
b3b6e05e | 1147 | return s->bucket->set_instance_attrs(this, attrs, y); |
9f95a23c TL |
1148 | }); |
1149 | ||
1150 | } | |
1151 | ||
1152 | void RGWDeleteBucketTags::pre_exec() | |
1153 | { | |
1154 | rgw_bucket_object_pre_exec(s); | |
1155 | } | |
1156 | ||
f67539c2 | 1157 | int RGWDeleteBucketTags::verify_permission(optional_yield y) |
9f95a23c TL |
1158 | { |
1159 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketTagging); | |
1160 | } | |
1161 | ||
f67539c2 | 1162 | void RGWDeleteBucketTags::execute(optional_yield y) |
9f95a23c | 1163 | { |
f67539c2 | 1164 | bufferlist in_data; |
b3b6e05e | 1165 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
1166 | if (op_ret < 0) { |
1167 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
1168 | return; | |
9f95a23c TL |
1169 | } |
1170 | ||
b3b6e05e | 1171 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this, y] { |
f67539c2 | 1172 | rgw::sal::RGWAttrs attrs = s->bucket->get_attrs(); |
9f95a23c | 1173 | attrs.erase(RGW_ATTR_TAGS); |
b3b6e05e | 1174 | op_ret = s->bucket->set_instance_attrs(this, attrs, y); |
9f95a23c TL |
1175 | if (op_ret < 0) { |
1176 | ldpp_dout(this, 0) << "RGWDeleteBucketTags() failed to remove RGW_ATTR_TAGS on bucket=" | |
f67539c2 | 1177 | << s->bucket->get_name() |
9f95a23c TL |
1178 | << " returned err= " << op_ret << dendl; |
1179 | } | |
1180 | return op_ret; | |
1181 | }); | |
1182 | } | |
1183 | ||
f67539c2 | 1184 | int RGWGetBucketReplication::verify_permission(optional_yield y) |
9f95a23c TL |
1185 | { |
1186 | if (!verify_bucket_permission(this, s, rgw::IAM::s3GetReplicationConfiguration)) { | |
1187 | return -EACCES; | |
1188 | } | |
1189 | ||
1190 | return 0; | |
1191 | } | |
1192 | ||
1193 | void RGWGetBucketReplication::pre_exec() | |
1194 | { | |
1195 | rgw_bucket_object_pre_exec(s); | |
1196 | } | |
1197 | ||
f67539c2 | 1198 | void RGWGetBucketReplication::execute(optional_yield y) |
9f95a23c TL |
1199 | { |
1200 | send_response_data(); | |
1201 | } | |
1202 | ||
f67539c2 | 1203 | int RGWPutBucketReplication::verify_permission(optional_yield y) { |
9f95a23c TL |
1204 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutReplicationConfiguration); |
1205 | } | |
1206 | ||
f67539c2 | 1207 | void RGWPutBucketReplication::execute(optional_yield y) { |
9f95a23c | 1208 | |
f67539c2 | 1209 | op_ret = get_params(y); |
9f95a23c TL |
1210 | if (op_ret < 0) |
1211 | return; | |
1212 | ||
b3b6e05e | 1213 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
1214 | if (op_ret < 0) { |
1215 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
1216 | return; | |
9f95a23c TL |
1217 | } |
1218 | ||
b3b6e05e | 1219 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 | 1220 | auto sync_policy = (s->bucket->get_info().sync_policy ? *s->bucket->get_info().sync_policy : rgw_sync_policy_info()); |
9f95a23c TL |
1221 | |
1222 | for (auto& group : sync_policy_groups) { | |
1223 | sync_policy.groups[group.id] = group; | |
1224 | } | |
1225 | ||
f67539c2 | 1226 | s->bucket->get_info().set_sync_policy(std::move(sync_policy)); |
9f95a23c | 1227 | |
b3b6e05e | 1228 | int ret = s->bucket->put_instance_info(this, false, real_time()); |
9f95a23c | 1229 | if (ret < 0) { |
f67539c2 | 1230 | ldpp_dout(this, 0) << "ERROR: put_bucket_instance_info (bucket=" << s->bucket << ") returned ret=" << ret << dendl; |
9f95a23c TL |
1231 | return ret; |
1232 | } | |
1233 | ||
1234 | return 0; | |
1235 | }); | |
1236 | } | |
1237 | ||
1238 | void RGWDeleteBucketReplication::pre_exec() | |
1239 | { | |
1240 | rgw_bucket_object_pre_exec(s); | |
1241 | } | |
1242 | ||
f67539c2 | 1243 | int RGWDeleteBucketReplication::verify_permission(optional_yield y) |
9f95a23c TL |
1244 | { |
1245 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3DeleteReplicationConfiguration); | |
1246 | } | |
1247 | ||
f67539c2 | 1248 | void RGWDeleteBucketReplication::execute(optional_yield y) |
9f95a23c | 1249 | { |
f67539c2 | 1250 | bufferlist in_data; |
b3b6e05e | 1251 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
1252 | if (op_ret < 0) { |
1253 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
1254 | return; | |
9f95a23c TL |
1255 | } |
1256 | ||
b3b6e05e | 1257 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 | 1258 | if (!s->bucket->get_info().sync_policy) { |
9f95a23c TL |
1259 | return 0; |
1260 | } | |
1261 | ||
f67539c2 | 1262 | rgw_sync_policy_info sync_policy = *s->bucket->get_info().sync_policy; |
9f95a23c TL |
1263 | |
1264 | update_sync_policy(&sync_policy); | |
1265 | ||
f67539c2 | 1266 | s->bucket->get_info().set_sync_policy(std::move(sync_policy)); |
9f95a23c | 1267 | |
b3b6e05e | 1268 | int ret = s->bucket->put_instance_info(this, false, real_time()); |
9f95a23c | 1269 | if (ret < 0) { |
f67539c2 | 1270 | ldpp_dout(this, 0) << "ERROR: put_bucket_instance_info (bucket=" << s->bucket << ") returned ret=" << ret << dendl; |
9f95a23c TL |
1271 | return ret; |
1272 | } | |
1273 | ||
1274 | return 0; | |
1275 | }); | |
224ce89b WB |
1276 | } |
1277 | ||
7c673cae FG |
1278 | int RGWOp::do_aws4_auth_completion() |
1279 | { | |
11fdf7f2 | 1280 | ldpp_dout(this, 5) << "NOTICE: call to do_aws4_auth_completion" << dendl; |
31f18b77 FG |
1281 | if (s->auth.completer) { |
1282 | if (!s->auth.completer->complete()) { | |
1283 | return -ERR_AMZ_CONTENT_SHA256_MISMATCH; | |
1284 | } else { | |
11fdf7f2 | 1285 | ldpp_dout(this, 10) << "v4 auth ok -- do_aws4_auth_completion" << dendl; |
7c673cae | 1286 | } |
31f18b77 FG |
1287 | |
1288 | /* TODO(rzarzynski): yes, we're really called twice on PUTs. Only first | |
1289 | * call passes, so we disable second one. This is old behaviour, sorry! | |
1290 | * Plan for tomorrow: seek and destroy. */ | |
1291 | s->auth.completer = nullptr; | |
7c673cae FG |
1292 | } |
1293 | ||
1294 | return 0; | |
1295 | } | |
1296 | ||
1297 | int RGWOp::init_quota() | |
1298 | { | |
1299 | /* no quota enforcement for system requests */ | |
1300 | if (s->system_request) | |
1301 | return 0; | |
1302 | ||
1303 | /* init quota related stuff */ | |
9f95a23c | 1304 | if (!(s->user->get_info().op_mask & RGW_OP_TYPE_MODIFY)) { |
7c673cae FG |
1305 | return 0; |
1306 | } | |
1307 | ||
1308 | /* only interested in object related ops */ | |
f67539c2 TL |
1309 | if (rgw::sal::RGWBucket::empty(s->bucket.get()) |
1310 | || rgw::sal::RGWObject::empty(s->object.get())) { | |
7c673cae FG |
1311 | return 0; |
1312 | } | |
1313 | ||
f67539c2 TL |
1314 | rgw::sal::RGWRadosUser owner_user(store, s->bucket->get_info().owner); |
1315 | rgw::sal::RGWUser* user; | |
7c673cae | 1316 | |
9f95a23c | 1317 | if (s->user->get_id() == s->bucket_owner.get_id()) { |
f67539c2 | 1318 | user = s->user.get(); |
7c673cae | 1319 | } else { |
b3b6e05e | 1320 | int r = owner_user.load_by_id(this, s->yield); |
7c673cae FG |
1321 | if (r < 0) |
1322 | return r; | |
9f95a23c | 1323 | user = &owner_user; |
7c673cae FG |
1324 | } |
1325 | ||
f67539c2 TL |
1326 | if (s->bucket->get_info().quota.enabled) { |
1327 | bucket_quota = s->bucket->get_info().quota; | |
9f95a23c TL |
1328 | } else if (user->get_info().bucket_quota.enabled) { |
1329 | bucket_quota = user->get_info().bucket_quota; | |
7c673cae | 1330 | } else { |
9f95a23c | 1331 | bucket_quota = store->svc()->quota->get_bucket_quota(); |
7c673cae FG |
1332 | } |
1333 | ||
9f95a23c TL |
1334 | if (user->get_info().user_quota.enabled) { |
1335 | user_quota = user->get_info().user_quota; | |
7c673cae | 1336 | } else { |
9f95a23c | 1337 | user_quota = store->svc()->quota->get_user_quota(); |
7c673cae FG |
1338 | } |
1339 | ||
1340 | return 0; | |
1341 | } | |
1342 | ||
1343 | static bool validate_cors_rule_method(RGWCORSRule *rule, const char *req_meth) { | |
1344 | uint8_t flags = 0; | |
1345 | ||
1346 | if (!req_meth) { | |
1347 | dout(5) << "req_meth is null" << dendl; | |
1348 | return false; | |
1349 | } | |
1350 | ||
1351 | if (strcmp(req_meth, "GET") == 0) flags = RGW_CORS_GET; | |
1352 | else if (strcmp(req_meth, "POST") == 0) flags = RGW_CORS_POST; | |
1353 | else if (strcmp(req_meth, "PUT") == 0) flags = RGW_CORS_PUT; | |
1354 | else if (strcmp(req_meth, "DELETE") == 0) flags = RGW_CORS_DELETE; | |
1355 | else if (strcmp(req_meth, "HEAD") == 0) flags = RGW_CORS_HEAD; | |
1356 | ||
1adf2230 | 1357 | if (rule->get_allowed_methods() & flags) { |
7c673cae FG |
1358 | dout(10) << "Method " << req_meth << " is supported" << dendl; |
1359 | } else { | |
1360 | dout(5) << "Method " << req_meth << " is not supported" << dendl; | |
1361 | return false; | |
1362 | } | |
1363 | ||
1364 | return true; | |
1365 | } | |
1366 | ||
b32b8144 FG |
1367 | static bool validate_cors_rule_header(RGWCORSRule *rule, const char *req_hdrs) { |
1368 | if (req_hdrs) { | |
1369 | vector<string> hdrs; | |
1370 | get_str_vec(req_hdrs, hdrs); | |
1371 | for (const auto& hdr : hdrs) { | |
1372 | if (!rule->is_header_allowed(hdr.c_str(), hdr.length())) { | |
1373 | dout(5) << "Header " << hdr << " is not registered in this rule" << dendl; | |
1374 | return false; | |
1375 | } | |
1376 | } | |
1377 | } | |
1378 | return true; | |
1379 | } | |
1380 | ||
7c673cae FG |
1381 | int RGWOp::read_bucket_cors() |
1382 | { | |
1383 | bufferlist bl; | |
1384 | ||
1385 | map<string, bufferlist>::iterator aiter = s->bucket_attrs.find(RGW_ATTR_CORS); | |
1386 | if (aiter == s->bucket_attrs.end()) { | |
11fdf7f2 | 1387 | ldpp_dout(this, 20) << "no CORS configuration attr found" << dendl; |
7c673cae FG |
1388 | cors_exist = false; |
1389 | return 0; /* no CORS configuration found */ | |
1390 | } | |
1391 | ||
1392 | cors_exist = true; | |
1393 | ||
1394 | bl = aiter->second; | |
1395 | ||
11fdf7f2 | 1396 | auto iter = bl.cbegin(); |
7c673cae FG |
1397 | try { |
1398 | bucket_cors.decode(iter); | |
1399 | } catch (buffer::error& err) { | |
f67539c2 | 1400 | ldpp_dout(this, 0) << "ERROR: could not decode CORS, caught buffer::error" << dendl; |
7c673cae FG |
1401 | return -EIO; |
1402 | } | |
11fdf7f2 | 1403 | if (s->cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) { |
7c673cae | 1404 | RGWCORSConfiguration_S3 *s3cors = static_cast<RGWCORSConfiguration_S3 *>(&bucket_cors); |
11fdf7f2 | 1405 | ldpp_dout(this, 15) << "Read RGWCORSConfiguration"; |
7c673cae FG |
1406 | s3cors->to_xml(*_dout); |
1407 | *_dout << dendl; | |
1408 | } | |
1409 | return 0; | |
1410 | } | |
1411 | ||
1412 | /** CORS 6.2.6. | |
1413 | * If any of the header field-names is not a ASCII case-insensitive match for | |
1414 | * any of the values in list of headers do not set any additional headers and | |
1415 | * terminate this set of steps. | |
1416 | * */ | |
1417 | static void get_cors_response_headers(RGWCORSRule *rule, const char *req_hdrs, string& hdrs, string& exp_hdrs, unsigned *max_age) { | |
1418 | if (req_hdrs) { | |
1419 | list<string> hl; | |
1420 | get_str_list(req_hdrs, hl); | |
1421 | for(list<string>::iterator it = hl.begin(); it != hl.end(); ++it) { | |
1422 | if (!rule->is_header_allowed((*it).c_str(), (*it).length())) { | |
1423 | dout(5) << "Header " << (*it) << " is not registered in this rule" << dendl; | |
1424 | } else { | |
1425 | if (hdrs.length() > 0) hdrs.append(","); | |
1426 | hdrs.append((*it)); | |
1427 | } | |
1428 | } | |
1429 | } | |
1430 | rule->format_exp_headers(exp_hdrs); | |
1431 | *max_age = rule->get_max_age(); | |
1432 | } | |
1433 | ||
1434 | /** | |
1435 | * Generate the CORS header response | |
1436 | * | |
1437 | * This is described in the CORS standard, section 6.2. | |
1438 | */ | |
1439 | bool RGWOp::generate_cors_headers(string& origin, string& method, string& headers, string& exp_headers, unsigned *max_age) | |
1440 | { | |
1441 | /* CORS 6.2.1. */ | |
1442 | const char *orig = s->info.env->get("HTTP_ORIGIN"); | |
1443 | if (!orig) { | |
1444 | return false; | |
1445 | } | |
1446 | ||
1447 | /* Custom: */ | |
1448 | origin = orig; | |
9f95a23c TL |
1449 | int temp_op_ret = read_bucket_cors(); |
1450 | if (temp_op_ret < 0) { | |
1451 | op_ret = temp_op_ret; | |
7c673cae FG |
1452 | return false; |
1453 | } | |
1454 | ||
1455 | if (!cors_exist) { | |
11fdf7f2 | 1456 | ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl; |
7c673cae FG |
1457 | return false; |
1458 | } | |
1459 | ||
1460 | /* CORS 6.2.2. */ | |
1461 | RGWCORSRule *rule = bucket_cors.host_name_rule(orig); | |
1462 | if (!rule) | |
1463 | return false; | |
1464 | ||
1465 | /* | |
1466 | * Set the Allowed-Origin header to a asterisk if this is allowed in the rule | |
1467 | * and no Authorization was send by the client | |
1468 | * | |
1469 | * The origin parameter specifies a URI that may access the resource. The browser must enforce this. | |
1470 | * For requests without credentials, the server may specify "*" as a wildcard, | |
1471 | * thereby allowing any origin to access the resource. | |
1472 | */ | |
1473 | const char *authorization = s->info.env->get("HTTP_AUTHORIZATION"); | |
1474 | if (!authorization && rule->has_wildcard_origin()) | |
1475 | origin = "*"; | |
1476 | ||
1477 | /* CORS 6.2.3. */ | |
1478 | const char *req_meth = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD"); | |
1479 | if (!req_meth) { | |
1480 | req_meth = s->info.method; | |
1481 | } | |
1482 | ||
1483 | if (req_meth) { | |
1484 | method = req_meth; | |
1485 | /* CORS 6.2.5. */ | |
1486 | if (!validate_cors_rule_method(rule, req_meth)) { | |
1487 | return false; | |
1488 | } | |
1489 | } | |
1490 | ||
1491 | /* CORS 6.2.4. */ | |
1492 | const char *req_hdrs = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS"); | |
1493 | ||
1494 | /* CORS 6.2.6. */ | |
1495 | get_cors_response_headers(rule, req_hdrs, headers, exp_headers, max_age); | |
1496 | ||
1497 | return true; | |
1498 | } | |
1499 | ||
f67539c2 | 1500 | int RGWGetObj::read_user_manifest_part(rgw::sal::RGWBucket* bucket, |
7c673cae | 1501 | const rgw_bucket_dir_entry& ent, |
31f18b77 | 1502 | RGWAccessControlPolicy * const bucket_acl, |
11fdf7f2 | 1503 | const boost::optional<Policy>& bucket_policy, |
7c673cae | 1504 | const off_t start_ofs, |
11fdf7f2 TL |
1505 | const off_t end_ofs, |
1506 | bool swift_slo) | |
7c673cae | 1507 | { |
11fdf7f2 TL |
1508 | ldpp_dout(this, 20) << "user manifest obj=" << ent.key.name |
1509 | << "[" << ent.key.instance << "]" << dendl; | |
7c673cae | 1510 | RGWGetObj_CB cb(this); |
11fdf7f2 | 1511 | RGWGetObj_Filter* filter = &cb; |
7c673cae FG |
1512 | boost::optional<RGWGetObj_Decompress> decompress; |
1513 | ||
1514 | int64_t cur_ofs = start_ofs; | |
1515 | int64_t cur_end = end_ofs; | |
1516 | ||
f67539c2 | 1517 | std::unique_ptr<rgw::sal::RGWObject> part = bucket->get_object(ent.key); |
7c673cae | 1518 | |
7c673cae FG |
1519 | RGWObjectCtx obj_ctx(store); |
1520 | RGWAccessControlPolicy obj_policy(s->cct); | |
1521 | ||
11fdf7f2 TL |
1522 | ldpp_dout(this, 20) << "reading obj=" << part << " ofs=" << cur_ofs |
1523 | << " end=" << cur_end << dendl; | |
7c673cae | 1524 | |
f67539c2 TL |
1525 | part->set_atomic(&obj_ctx); |
1526 | part->set_prefetch_data(&obj_ctx); | |
7c673cae | 1527 | |
f67539c2 | 1528 | std::unique_ptr<rgw::sal::RGWObject::ReadOp> read_op = part->get_read_op(&obj_ctx); |
7c673cae | 1529 | |
11fdf7f2 TL |
1530 | if (!swift_slo) { |
1531 | /* SLO etag is optional */ | |
f67539c2 | 1532 | read_op->params.if_match = ent.meta.etag.c_str(); |
11fdf7f2 | 1533 | } |
7c673cae | 1534 | |
b3b6e05e | 1535 | op_ret = read_op->prepare(s->yield, this); |
7c673cae FG |
1536 | if (op_ret < 0) |
1537 | return op_ret; | |
f67539c2 | 1538 | op_ret = part->range_to_ofs(ent.meta.accounted_size, cur_ofs, cur_end); |
7c673cae FG |
1539 | if (op_ret < 0) |
1540 | return op_ret; | |
1541 | bool need_decompress; | |
f67539c2 | 1542 | op_ret = rgw_compression_info_from_attrset(part->get_attrs(), need_decompress, cs_info); |
7c673cae | 1543 | if (op_ret < 0) { |
11fdf7f2 TL |
1544 | ldpp_dout(this, 0) << "ERROR: failed to decode compression info" << dendl; |
1545 | return -EIO; | |
7c673cae FG |
1546 | } |
1547 | ||
1548 | if (need_decompress) | |
1549 | { | |
224ce89b | 1550 | if (cs_info.orig_size != ent.meta.accounted_size) { |
7c673cae | 1551 | // hmm.. something wrong, object not as expected, abort! |
11fdf7f2 TL |
1552 | ldpp_dout(this, 0) << "ERROR: expected cs_info.orig_size=" << cs_info.orig_size |
1553 | << ", actual read size=" << ent.meta.size << dendl; | |
7c673cae FG |
1554 | return -EIO; |
1555 | } | |
1556 | decompress.emplace(s->cct, &cs_info, partial_content, filter); | |
1557 | filter = &*decompress; | |
1558 | } | |
1559 | else | |
1560 | { | |
f67539c2 | 1561 | if (part->get_obj_size() != ent.meta.size) { |
7c673cae | 1562 | // hmm.. something wrong, object not as expected, abort! |
f67539c2 | 1563 | ldpp_dout(this, 0) << "ERROR: expected obj_size=" << part->get_obj_size() |
11fdf7f2 | 1564 | << ", actual read size=" << ent.meta.size << dendl; |
7c673cae FG |
1565 | return -EIO; |
1566 | } | |
1567 | } | |
1568 | ||
b3b6e05e | 1569 | op_ret = rgw_policy_from_attrset(s, s->cct, part->get_attrs(), &obj_policy); |
7c673cae FG |
1570 | if (op_ret < 0) |
1571 | return op_ret; | |
1572 | ||
1573 | /* We can use global user_acl because LOs cannot have segments | |
1574 | * stored inside different accounts. */ | |
1575 | if (s->system_request) { | |
11fdf7f2 | 1576 | ldpp_dout(this, 2) << "overriding permissions due to system operation" << dendl; |
9f95a23c | 1577 | } else if (s->auth.identity->is_admin_of(s->user->get_id())) { |
11fdf7f2 | 1578 | ldpp_dout(this, 2) << "overriding permissions due to admin operation" << dendl; |
f67539c2 TL |
1579 | } else if (!verify_object_permission(this, s, part->get_obj(), s->user_acl.get(), |
1580 | bucket_acl, &obj_policy, bucket_policy, | |
522d829b | 1581 | s->iam_user_policies, s->session_policies, action)) { |
7c673cae FG |
1582 | return -EPERM; |
1583 | } | |
7c673cae FG |
1584 | if (ent.meta.size == 0) { |
1585 | return 0; | |
1586 | } | |
1587 | ||
1588 | perfcounter->inc(l_rgw_get_b, cur_end - cur_ofs); | |
1589 | filter->fixup_range(cur_ofs, cur_end); | |
b3b6e05e | 1590 | op_ret = read_op->iterate(this, cur_ofs, cur_end, filter, s->yield); |
7c673cae FG |
1591 | if (op_ret >= 0) |
1592 | op_ret = filter->flush(); | |
1593 | return op_ret; | |
1594 | } | |
1595 | ||
b3b6e05e TL |
1596 | static int iterate_user_manifest_parts(const DoutPrefixProvider *dpp, |
1597 | CephContext * const cct, | |
f67539c2 | 1598 | rgw::sal::RGWStore* const store, |
7c673cae FG |
1599 | const off_t ofs, |
1600 | const off_t end, | |
f67539c2 | 1601 | rgw::sal::RGWBucket* bucket, |
7c673cae | 1602 | const string& obj_prefix, |
31f18b77 | 1603 | RGWAccessControlPolicy * const bucket_acl, |
11fdf7f2 | 1604 | const boost::optional<Policy>& bucket_policy, |
7c673cae FG |
1605 | uint64_t * const ptotal_len, |
1606 | uint64_t * const pobj_size, | |
1607 | string * const pobj_sum, | |
f67539c2 | 1608 | int (*cb)(rgw::sal::RGWBucket* bucket, |
7c673cae | 1609 | const rgw_bucket_dir_entry& ent, |
31f18b77 | 1610 | RGWAccessControlPolicy * const bucket_acl, |
11fdf7f2 | 1611 | const boost::optional<Policy>& bucket_policy, |
7c673cae FG |
1612 | off_t start_ofs, |
1613 | off_t end_ofs, | |
11fdf7f2 TL |
1614 | void *param, |
1615 | bool swift_slo), | |
f67539c2 TL |
1616 | void * const cb_param, |
1617 | optional_yield y) | |
7c673cae | 1618 | { |
7c673cae FG |
1619 | uint64_t obj_ofs = 0, len_count = 0; |
1620 | bool found_start = false, found_end = false, handled_end = false; | |
1621 | string delim; | |
7c673cae FG |
1622 | |
1623 | utime_t start_time = ceph_clock_now(); | |
1624 | ||
f67539c2 TL |
1625 | rgw::sal::RGWBucket::ListParams params; |
1626 | params.prefix = obj_prefix; | |
1627 | params.delim = delim; | |
7c673cae | 1628 | |
f67539c2 | 1629 | rgw::sal::RGWBucket::ListResults results; |
7c673cae FG |
1630 | MD5 etag_sum; |
1631 | do { | |
f67539c2 | 1632 | static constexpr auto MAX_LIST_OBJS = 100u; |
b3b6e05e | 1633 | int r = bucket->list(dpp, params, MAX_LIST_OBJS, results, y); |
7c673cae FG |
1634 | if (r < 0) { |
1635 | return r; | |
1636 | } | |
1637 | ||
f67539c2 | 1638 | for (rgw_bucket_dir_entry& ent : results.objs) { |
224ce89b WB |
1639 | const uint64_t cur_total_len = obj_ofs; |
1640 | const uint64_t obj_size = ent.meta.accounted_size; | |
1641 | uint64_t start_ofs = 0, end_ofs = obj_size; | |
7c673cae | 1642 | |
224ce89b | 1643 | if ((ptotal_len || cb) && !found_start && cur_total_len + obj_size > (uint64_t)ofs) { |
7c673cae FG |
1644 | start_ofs = ofs - obj_ofs; |
1645 | found_start = true; | |
1646 | } | |
1647 | ||
224ce89b | 1648 | obj_ofs += obj_size; |
7c673cae | 1649 | if (pobj_sum) { |
11fdf7f2 | 1650 | etag_sum.Update((const unsigned char *)ent.meta.etag.c_str(), |
7c673cae FG |
1651 | ent.meta.etag.length()); |
1652 | } | |
1653 | ||
31f18b77 | 1654 | if ((ptotal_len || cb) && !found_end && obj_ofs > (uint64_t)end) { |
7c673cae FG |
1655 | end_ofs = end - cur_total_len + 1; |
1656 | found_end = true; | |
1657 | } | |
1658 | ||
1659 | perfcounter->tinc(l_rgw_get_lat, | |
1660 | (ceph_clock_now() - start_time)); | |
1661 | ||
1662 | if (found_start && !handled_end) { | |
1663 | len_count += end_ofs - start_ofs; | |
1664 | ||
1665 | if (cb) { | |
11fdf7f2 TL |
1666 | r = cb(bucket, ent, bucket_acl, bucket_policy, start_ofs, end_ofs, |
1667 | cb_param, false /* swift_slo */); | |
7c673cae FG |
1668 | if (r < 0) { |
1669 | return r; | |
1670 | } | |
1671 | } | |
1672 | } | |
1673 | ||
1674 | handled_end = found_end; | |
1675 | start_time = ceph_clock_now(); | |
1676 | } | |
f67539c2 | 1677 | } while (results.is_truncated); |
7c673cae FG |
1678 | |
1679 | if (ptotal_len) { | |
1680 | *ptotal_len = len_count; | |
1681 | } | |
1682 | if (pobj_size) { | |
1683 | *pobj_size = obj_ofs; | |
1684 | } | |
1685 | if (pobj_sum) { | |
1686 | complete_etag(etag_sum, pobj_sum); | |
1687 | } | |
1688 | ||
1689 | return 0; | |
1690 | } | |
1691 | ||
1692 | struct rgw_slo_part { | |
31f18b77 FG |
1693 | RGWAccessControlPolicy *bucket_acl = nullptr; |
1694 | Policy* bucket_policy = nullptr; | |
f67539c2 | 1695 | rgw::sal::RGWBucket* bucket; |
7c673cae | 1696 | string obj_name; |
31f18b77 | 1697 | uint64_t size = 0; |
7c673cae | 1698 | string etag; |
7c673cae FG |
1699 | }; |
1700 | ||
1701 | static int iterate_slo_parts(CephContext *cct, | |
f67539c2 | 1702 | rgw::sal::RGWStore*store, |
7c673cae FG |
1703 | off_t ofs, |
1704 | off_t end, | |
1705 | map<uint64_t, rgw_slo_part>& slo_parts, | |
f67539c2 | 1706 | int (*cb)(rgw::sal::RGWBucket* bucket, |
7c673cae | 1707 | const rgw_bucket_dir_entry& ent, |
31f18b77 | 1708 | RGWAccessControlPolicy *bucket_acl, |
11fdf7f2 | 1709 | const boost::optional<Policy>& bucket_policy, |
7c673cae FG |
1710 | off_t start_ofs, |
1711 | off_t end_ofs, | |
11fdf7f2 TL |
1712 | void *param, |
1713 | bool swift_slo), | |
7c673cae FG |
1714 | void *cb_param) |
1715 | { | |
1716 | bool found_start = false, found_end = false; | |
1717 | ||
1718 | if (slo_parts.empty()) { | |
1719 | return 0; | |
1720 | } | |
1721 | ||
1722 | utime_t start_time = ceph_clock_now(); | |
1723 | ||
1724 | map<uint64_t, rgw_slo_part>::iterator iter = slo_parts.upper_bound(ofs); | |
1725 | if (iter != slo_parts.begin()) { | |
1726 | --iter; | |
1727 | } | |
1728 | ||
1729 | uint64_t obj_ofs = iter->first; | |
1730 | ||
1731 | for (; iter != slo_parts.end() && !found_end; ++iter) { | |
1732 | rgw_slo_part& part = iter->second; | |
1733 | rgw_bucket_dir_entry ent; | |
1734 | ||
1735 | ent.key.name = part.obj_name; | |
224ce89b | 1736 | ent.meta.accounted_size = ent.meta.size = part.size; |
7c673cae FG |
1737 | ent.meta.etag = part.etag; |
1738 | ||
1739 | uint64_t cur_total_len = obj_ofs; | |
eafe8130 | 1740 | uint64_t start_ofs = 0, end_ofs = ent.meta.size - 1; |
7c673cae FG |
1741 | |
1742 | if (!found_start && cur_total_len + ent.meta.size > (uint64_t)ofs) { | |
1743 | start_ofs = ofs - obj_ofs; | |
1744 | found_start = true; | |
1745 | } | |
1746 | ||
1747 | obj_ofs += ent.meta.size; | |
1748 | ||
1749 | if (!found_end && obj_ofs > (uint64_t)end) { | |
eafe8130 | 1750 | end_ofs = end - cur_total_len; |
7c673cae FG |
1751 | found_end = true; |
1752 | } | |
1753 | ||
1754 | perfcounter->tinc(l_rgw_get_lat, | |
1755 | (ceph_clock_now() - start_time)); | |
1756 | ||
1757 | if (found_start) { | |
1758 | if (cb) { | |
eafe8130 TL |
1759 | dout(20) << "iterate_slo_parts()" |
1760 | << " obj=" << part.obj_name | |
1761 | << " start_ofs=" << start_ofs | |
1762 | << " end_ofs=" << end_ofs | |
1763 | << dendl; | |
1764 | ||
31f18b77 FG |
1765 | // SLO is a Swift thing, and Swift has no knowledge of S3 Policies. |
1766 | int r = cb(part.bucket, ent, part.bucket_acl, | |
1767 | (part.bucket_policy ? | |
11fdf7f2 TL |
1768 | boost::optional<Policy>(*part.bucket_policy) : none), |
1769 | start_ofs, end_ofs, cb_param, true /* swift_slo */); | |
31f18b77 | 1770 | if (r < 0) |
7c673cae FG |
1771 | return r; |
1772 | } | |
1773 | } | |
1774 | ||
1775 | start_time = ceph_clock_now(); | |
1776 | } | |
1777 | ||
1778 | return 0; | |
1779 | } | |
1780 | ||
f67539c2 | 1781 | static int get_obj_user_manifest_iterate_cb(rgw::sal::RGWBucket* bucket, |
7c673cae | 1782 | const rgw_bucket_dir_entry& ent, |
31f18b77 | 1783 | RGWAccessControlPolicy * const bucket_acl, |
11fdf7f2 | 1784 | const boost::optional<Policy>& bucket_policy, |
7c673cae FG |
1785 | const off_t start_ofs, |
1786 | const off_t end_ofs, | |
11fdf7f2 TL |
1787 | void * const param, |
1788 | bool swift_slo = false) | |
7c673cae FG |
1789 | { |
1790 | RGWGetObj *op = static_cast<RGWGetObj *>(param); | |
11fdf7f2 TL |
1791 | return op->read_user_manifest_part( |
1792 | bucket, ent, bucket_acl, bucket_policy, start_ofs, end_ofs, swift_slo); | |
7c673cae FG |
1793 | } |
1794 | ||
f67539c2 | 1795 | int RGWGetObj::handle_user_manifest(const char *prefix, optional_yield y) |
7c673cae | 1796 | { |
f67539c2 | 1797 | const std::string_view prefix_view(prefix); |
11fdf7f2 | 1798 | ldpp_dout(this, 2) << "RGWGetObj::handle_user_manifest() prefix=" |
31f18b77 | 1799 | << prefix_view << dendl; |
7c673cae | 1800 | |
31f18b77 FG |
1801 | const size_t pos = prefix_view.find('/'); |
1802 | if (pos == string::npos) { | |
7c673cae | 1803 | return -EINVAL; |
31f18b77 | 1804 | } |
7c673cae | 1805 | |
31f18b77 FG |
1806 | const std::string bucket_name = url_decode(prefix_view.substr(0, pos)); |
1807 | const std::string obj_prefix = url_decode(prefix_view.substr(pos + 1)); | |
7c673cae | 1808 | |
31f18b77 FG |
1809 | RGWAccessControlPolicy _bucket_acl(s->cct); |
1810 | RGWAccessControlPolicy *bucket_acl; | |
11fdf7f2 TL |
1811 | boost::optional<Policy> _bucket_policy; |
1812 | boost::optional<Policy>* bucket_policy; | |
7c673cae | 1813 | RGWBucketInfo bucket_info; |
f67539c2 TL |
1814 | std::unique_ptr<rgw::sal::RGWBucket> ubucket; |
1815 | rgw::sal::RGWBucket *pbucket = NULL; | |
1816 | int r = 0; | |
7c673cae | 1817 | |
f67539c2 | 1818 | if (bucket_name.compare(s->bucket->get_name()) != 0) { |
7c673cae | 1819 | map<string, bufferlist> bucket_attrs; |
b3b6e05e | 1820 | r = store->get_bucket(this, s->user.get(), s->user->get_tenant(), bucket_name, &ubucket, y); |
7c673cae | 1821 | if (r < 0) { |
11fdf7f2 | 1822 | ldpp_dout(this, 0) << "could not get bucket info for bucket=" |
7c673cae FG |
1823 | << bucket_name << dendl; |
1824 | return r; | |
1825 | } | |
31f18b77 | 1826 | bucket_acl = &_bucket_acl; |
b3b6e05e | 1827 | r = read_bucket_policy(this, store, s, ubucket->get_info(), bucket_attrs, bucket_acl, ubucket->get_key(), y); |
7c673cae | 1828 | if (r < 0) { |
11fdf7f2 | 1829 | ldpp_dout(this, 0) << "failed to read bucket policy" << dendl; |
7c673cae FG |
1830 | return r; |
1831 | } | |
f67539c2 | 1832 | _bucket_policy = get_iam_policy_from_attr(s->cct, bucket_attrs, s->user->get_tenant()); |
31f18b77 | 1833 | bucket_policy = &_bucket_policy; |
f67539c2 | 1834 | pbucket = ubucket.get(); |
7c673cae | 1835 | } else { |
f67539c2 | 1836 | pbucket = s->bucket.get(); |
c07f9fc5 | 1837 | bucket_acl = s->bucket_acl.get(); |
31f18b77 | 1838 | bucket_policy = &s->iam_policy; |
7c673cae FG |
1839 | } |
1840 | ||
1841 | /* dry run to find out: | |
1842 | * - total length (of the parts we are going to send to client), | |
1843 | * - overall DLO's content size, | |
1844 | * - md5 sum of overall DLO's content (for etag of Swift API). */ | |
b3b6e05e | 1845 | r = iterate_user_manifest_parts(this, s->cct, store, ofs, end, |
f67539c2 | 1846 | pbucket, obj_prefix, bucket_acl, *bucket_policy, |
31f18b77 | 1847 | nullptr, &s->obj_size, &lo_etag, |
f67539c2 | 1848 | nullptr /* cb */, nullptr /* cb arg */, y); |
7c673cae FG |
1849 | if (r < 0) { |
1850 | return r; | |
1851 | } | |
f67539c2 | 1852 | s->object->set_obj_size(s->obj_size); |
7c673cae | 1853 | |
31f18b77 FG |
1854 | r = RGWRados::Object::Read::range_to_ofs(s->obj_size, ofs, end); |
1855 | if (r < 0) { | |
1856 | return r; | |
1857 | } | |
1858 | ||
b3b6e05e | 1859 | r = iterate_user_manifest_parts(this, s->cct, store, ofs, end, |
f67539c2 | 1860 | pbucket, obj_prefix, bucket_acl, *bucket_policy, |
31f18b77 | 1861 | &total_len, nullptr, nullptr, |
f67539c2 | 1862 | nullptr, nullptr, y); |
31f18b77 FG |
1863 | if (r < 0) { |
1864 | return r; | |
1865 | } | |
1866 | ||
7c673cae FG |
1867 | if (!get_data) { |
1868 | bufferlist bl; | |
1869 | send_response_data(bl, 0, 0); | |
1870 | return 0; | |
1871 | } | |
1872 | ||
b3b6e05e | 1873 | r = iterate_user_manifest_parts(this, s->cct, store, ofs, end, |
f67539c2 | 1874 | pbucket, obj_prefix, bucket_acl, *bucket_policy, |
7c673cae | 1875 | nullptr, nullptr, nullptr, |
f67539c2 | 1876 | get_obj_user_manifest_iterate_cb, (void *)this, y); |
7c673cae FG |
1877 | if (r < 0) { |
1878 | return r; | |
1879 | } | |
1880 | ||
1881 | if (!total_len) { | |
1882 | bufferlist bl; | |
1883 | send_response_data(bl, 0, 0); | |
1884 | } | |
1885 | ||
f67539c2 | 1886 | return r; |
7c673cae FG |
1887 | } |
1888 | ||
f67539c2 | 1889 | int RGWGetObj::handle_slo_manifest(bufferlist& bl, optional_yield y) |
7c673cae FG |
1890 | { |
1891 | RGWSLOInfo slo_info; | |
11fdf7f2 | 1892 | auto bliter = bl.cbegin(); |
7c673cae | 1893 | try { |
11fdf7f2 | 1894 | decode(slo_info, bliter); |
7c673cae | 1895 | } catch (buffer::error& err) { |
11fdf7f2 | 1896 | ldpp_dout(this, 0) << "ERROR: failed to decode slo manifest" << dendl; |
7c673cae FG |
1897 | return -EIO; |
1898 | } | |
11fdf7f2 | 1899 | ldpp_dout(this, 2) << "RGWGetObj::handle_slo_manifest()" << dendl; |
7c673cae | 1900 | |
31f18b77 | 1901 | vector<RGWAccessControlPolicy> allocated_acls; |
11fdf7f2 | 1902 | map<string, pair<RGWAccessControlPolicy *, boost::optional<Policy>>> policies; |
f67539c2 | 1903 | map<string, std::unique_ptr<rgw::sal::RGWBucket>> buckets; |
7c673cae FG |
1904 | |
1905 | map<uint64_t, rgw_slo_part> slo_parts; | |
1906 | ||
1907 | MD5 etag_sum; | |
1908 | total_len = 0; | |
1909 | ||
1910 | for (const auto& entry : slo_info.entries) { | |
1911 | const string& path = entry.path; | |
1912 | ||
1913 | /* If the path starts with slashes, strip them all. */ | |
1914 | const size_t pos_init = path.find_first_not_of('/'); | |
1915 | /* According to the documentation of std::string::find following check | |
1916 | * is not necessary as we should get the std::string::npos propagation | |
1917 | * here. This might be true with the accuracy to implementation's bugs. | |
1918 | * See following question on SO: | |
1919 | * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos | |
1920 | */ | |
1921 | if (pos_init == string::npos) { | |
1922 | return -EINVAL; | |
1923 | } | |
1924 | ||
1925 | const size_t pos_sep = path.find('/', pos_init); | |
1926 | if (pos_sep == string::npos) { | |
1927 | return -EINVAL; | |
1928 | } | |
1929 | ||
1930 | string bucket_name = path.substr(pos_init, pos_sep - pos_init); | |
1931 | string obj_name = path.substr(pos_sep + 1); | |
1932 | ||
f67539c2 | 1933 | rgw::sal::RGWBucket* bucket; |
31f18b77 FG |
1934 | RGWAccessControlPolicy *bucket_acl; |
1935 | Policy* bucket_policy; | |
7c673cae | 1936 | |
f67539c2 | 1937 | if (bucket_name.compare(s->bucket->get_name()) != 0) { |
7c673cae FG |
1938 | const auto& piter = policies.find(bucket_name); |
1939 | if (piter != policies.end()) { | |
31f18b77 FG |
1940 | bucket_acl = piter->second.first; |
1941 | bucket_policy = piter->second.second.get_ptr(); | |
f67539c2 | 1942 | bucket = buckets[bucket_name].get(); |
7c673cae | 1943 | } else { |
31f18b77 FG |
1944 | allocated_acls.push_back(RGWAccessControlPolicy(s->cct)); |
1945 | RGWAccessControlPolicy& _bucket_acl = allocated_acls.back(); | |
7c673cae | 1946 | |
f67539c2 | 1947 | std::unique_ptr<rgw::sal::RGWBucket> tmp_bucket; |
9f95a23c | 1948 | auto obj_ctx = store->svc()->sysobj->init_obj_ctx(); |
b3b6e05e | 1949 | int r = store->get_bucket(this, s->user.get(), s->user->get_tenant(), bucket_name, &tmp_bucket, y); |
7c673cae | 1950 | if (r < 0) { |
11fdf7f2 | 1951 | ldpp_dout(this, 0) << "could not get bucket info for bucket=" |
7c673cae FG |
1952 | << bucket_name << dendl; |
1953 | return r; | |
1954 | } | |
f67539c2 | 1955 | bucket = tmp_bucket.get(); |
31f18b77 | 1956 | bucket_acl = &_bucket_acl; |
b3b6e05e | 1957 | r = read_bucket_policy(this, store, s, tmp_bucket->get_info(), tmp_bucket->get_attrs(), bucket_acl, |
f67539c2 | 1958 | tmp_bucket->get_key(), y); |
7c673cae | 1959 | if (r < 0) { |
11fdf7f2 | 1960 | ldpp_dout(this, 0) << "failed to read bucket ACL for bucket " |
7c673cae FG |
1961 | << bucket << dendl; |
1962 | return r; | |
31f18b77 FG |
1963 | } |
1964 | auto _bucket_policy = get_iam_policy_from_attr( | |
f67539c2 | 1965 | s->cct, tmp_bucket->get_attrs(), tmp_bucket->get_tenant()); |
31f18b77 | 1966 | bucket_policy = _bucket_policy.get_ptr(); |
f67539c2 | 1967 | buckets[bucket_name].swap(tmp_bucket); |
31f18b77 | 1968 | policies[bucket_name] = make_pair(bucket_acl, _bucket_policy); |
7c673cae FG |
1969 | } |
1970 | } else { | |
f67539c2 | 1971 | bucket = s->bucket.get(); |
c07f9fc5 | 1972 | bucket_acl = s->bucket_acl.get(); |
31f18b77 | 1973 | bucket_policy = s->iam_policy.get_ptr(); |
7c673cae FG |
1974 | } |
1975 | ||
1976 | rgw_slo_part part; | |
31f18b77 | 1977 | part.bucket_acl = bucket_acl; |
7c673cae FG |
1978 | part.bucket_policy = bucket_policy; |
1979 | part.bucket = bucket; | |
1980 | part.obj_name = obj_name; | |
1981 | part.size = entry.size_bytes; | |
1982 | part.etag = entry.etag; | |
eafe8130 | 1983 | ldpp_dout(this, 20) << "slo_part: bucket=" << part.bucket |
7c673cae FG |
1984 | << " obj=" << part.obj_name |
1985 | << " size=" << part.size | |
1986 | << " etag=" << part.etag | |
1987 | << dendl; | |
1988 | ||
11fdf7f2 | 1989 | etag_sum.Update((const unsigned char *)entry.etag.c_str(), |
7c673cae FG |
1990 | entry.etag.length()); |
1991 | ||
1992 | slo_parts[total_len] = part; | |
1993 | total_len += part.size; | |
11fdf7f2 | 1994 | } /* foreach entry */ |
7c673cae FG |
1995 | |
1996 | complete_etag(etag_sum, &lo_etag); | |
1997 | ||
1998 | s->obj_size = slo_info.total_size; | |
f67539c2 | 1999 | s->object->set_obj_size(slo_info.total_size); |
11fdf7f2 | 2000 | ldpp_dout(this, 20) << "s->obj_size=" << s->obj_size << dendl; |
7c673cae | 2001 | |
31f18b77 FG |
2002 | int r = RGWRados::Object::Read::range_to_ofs(total_len, ofs, end); |
2003 | if (r < 0) { | |
2004 | return r; | |
7c673cae FG |
2005 | } |
2006 | ||
2007 | total_len = end - ofs + 1; | |
eafe8130 TL |
2008 | ldpp_dout(this, 20) << "Requested: ofs=" << ofs |
2009 | << " end=" << end | |
2010 | << " total=" << total_len | |
2011 | << dendl; | |
7c673cae | 2012 | |
31f18b77 | 2013 | r = iterate_slo_parts(s->cct, store, ofs, end, slo_parts, |
7c673cae FG |
2014 | get_obj_user_manifest_iterate_cb, (void *)this); |
2015 | if (r < 0) { | |
2016 | return r; | |
2017 | } | |
2018 | ||
2019 | return 0; | |
2020 | } | |
2021 | ||
2022 | int RGWGetObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len) | |
2023 | { | |
f91f0fd5 TL |
2024 | /* garbage collection related handling: |
2025 | * defer_gc disabled for https://tracker.ceph.com/issues/47866 */ | |
7c673cae FG |
2026 | return send_response_data(bl, bl_ofs, bl_len); |
2027 | } | |
2028 | ||
2029 | bool RGWGetObj::prefetch_data() | |
2030 | { | |
2031 | /* HEAD request, stop prefetch*/ | |
f6b5b4d7 | 2032 | if (!get_data || s->info.env->exists("HTTP_X_RGW_AUTH")) { |
7c673cae FG |
2033 | return false; |
2034 | } | |
2035 | ||
7c673cae | 2036 | range_str = s->info.env->get("HTTP_RANGE"); |
1911f103 | 2037 | // TODO: add range prefetch |
28e407b8 | 2038 | if (range_str) { |
1911f103 TL |
2039 | parse_range(); |
2040 | return false; | |
7c673cae FG |
2041 | } |
2042 | ||
1911f103 | 2043 | return get_data; |
7c673cae | 2044 | } |
28e407b8 | 2045 | |
7c673cae FG |
2046 | void RGWGetObj::pre_exec() |
2047 | { | |
2048 | rgw_bucket_object_pre_exec(s); | |
2049 | } | |
2050 | ||
9f95a23c TL |
2051 | static inline void rgw_cond_decode_objtags( |
2052 | struct req_state *s, | |
2053 | const std::map<std::string, buffer::list> &attrs) | |
2054 | { | |
2055 | const auto& tags = attrs.find(RGW_ATTR_TAGS); | |
2056 | if (tags != attrs.end()) { | |
2057 | try { | |
2058 | bufferlist::const_iterator iter{&tags->second}; | |
2059 | s->tagset.decode(iter); | |
2060 | } catch (buffer::error& err) { | |
b3b6e05e | 2061 | ldpp_dout(s, 0) |
9f95a23c TL |
2062 | << "ERROR: caught buffer::error, couldn't decode TagSet" << dendl; |
2063 | } | |
2064 | } | |
2065 | } | |
2066 | ||
f67539c2 | 2067 | void RGWGetObj::execute(optional_yield y) |
7c673cae | 2068 | { |
7c673cae FG |
2069 | bufferlist bl; |
2070 | gc_invalidate_time = ceph_clock_now(); | |
2071 | gc_invalidate_time += (s->cct->_conf->rgw_gc_obj_min_wait / 2); | |
2072 | ||
2073 | bool need_decompress; | |
2074 | int64_t ofs_x, end_x; | |
2075 | ||
2076 | RGWGetObj_CB cb(this); | |
11fdf7f2 | 2077 | RGWGetObj_Filter* filter = (RGWGetObj_Filter *)&cb; |
7c673cae | 2078 | boost::optional<RGWGetObj_Decompress> decompress; |
11fdf7f2 | 2079 | std::unique_ptr<RGWGetObj_Filter> decrypt; |
7c673cae FG |
2080 | map<string, bufferlist>::iterator attr_iter; |
2081 | ||
2082 | perfcounter->inc(l_rgw_get); | |
2083 | ||
f67539c2 | 2084 | std::unique_ptr<rgw::sal::RGWObject::ReadOp> read_op(s->object->get_read_op(s->obj_ctx)); |
7c673cae | 2085 | |
f67539c2 | 2086 | op_ret = get_params(y); |
7c673cae FG |
2087 | if (op_ret < 0) |
2088 | goto done_err; | |
2089 | ||
2090 | op_ret = init_common(); | |
2091 | if (op_ret < 0) | |
2092 | goto done_err; | |
2093 | ||
f67539c2 TL |
2094 | read_op->params.mod_ptr = mod_ptr; |
2095 | read_op->params.unmod_ptr = unmod_ptr; | |
2096 | read_op->params.high_precision_time = s->system_request; /* system request need to use high precision time */ | |
2097 | read_op->params.mod_zone_id = mod_zone_id; | |
2098 | read_op->params.mod_pg_ver = mod_pg_ver; | |
2099 | read_op->params.if_match = if_match; | |
2100 | read_op->params.if_nomatch = if_nomatch; | |
2101 | read_op->params.lastmod = &lastmod; | |
2102 | ||
b3b6e05e | 2103 | op_ret = read_op->prepare(s->yield, this); |
7c673cae FG |
2104 | if (op_ret < 0) |
2105 | goto done_err; | |
f67539c2 TL |
2106 | version_id = s->object->get_instance(); |
2107 | s->obj_size = s->object->get_obj_size(); | |
2108 | attrs = s->object->get_attrs(); | |
7c673cae FG |
2109 | |
2110 | /* STAT ops don't need data, and do no i/o */ | |
2111 | if (get_type() == RGW_OP_STAT_OBJ) { | |
2112 | return; | |
2113 | } | |
f6b5b4d7 TL |
2114 | if (s->info.env->exists("HTTP_X_RGW_AUTH")) { |
2115 | op_ret = 0; | |
2116 | goto done_err; | |
2117 | } | |
7c673cae FG |
2118 | /* start gettorrent */ |
2119 | if (torrent.get_flag()) | |
2120 | { | |
3efd9988 FG |
2121 | attr_iter = attrs.find(RGW_ATTR_CRYPT_MODE); |
2122 | if (attr_iter != attrs.end() && attr_iter->second.to_str() == "SSE-C-AES256") { | |
11fdf7f2 | 2123 | ldpp_dout(this, 0) << "ERROR: torrents are not supported for objects " |
28e407b8 AA |
2124 | "encrypted with SSE-C" << dendl; |
2125 | op_ret = -EINVAL; | |
3efd9988 FG |
2126 | goto done_err; |
2127 | } | |
7c673cae | 2128 | torrent.init(s, store); |
f67539c2 TL |
2129 | rgw_obj obj = s->object->get_obj(); |
2130 | op_ret = torrent.get_torrent_file(s->object.get(), total_len, bl, obj); | |
7c673cae FG |
2131 | if (op_ret < 0) |
2132 | { | |
11fdf7f2 | 2133 | ldpp_dout(this, 0) << "ERROR: failed to get_torrent_file ret= " << op_ret |
7c673cae FG |
2134 | << dendl; |
2135 | goto done_err; | |
2136 | } | |
2137 | op_ret = send_response_data(bl, 0, total_len); | |
2138 | if (op_ret < 0) | |
2139 | { | |
11fdf7f2 | 2140 | ldpp_dout(this, 0) << "ERROR: failed to send_response_data ret= " << op_ret << dendl; |
7c673cae FG |
2141 | goto done_err; |
2142 | } | |
2143 | return; | |
2144 | } | |
2145 | /* end gettorrent */ | |
2146 | ||
2147 | op_ret = rgw_compression_info_from_attrset(attrs, need_decompress, cs_info); | |
2148 | if (op_ret < 0) { | |
b3b6e05e | 2149 | ldpp_dout(this, 0) << "ERROR: failed to decode compression info, cannot decompress" << dendl; |
7c673cae FG |
2150 | goto done_err; |
2151 | } | |
2152 | if (need_decompress) { | |
2153 | s->obj_size = cs_info.orig_size; | |
f67539c2 | 2154 | s->object->set_obj_size(cs_info.orig_size); |
7c673cae FG |
2155 | decompress.emplace(s->cct, &cs_info, partial_content, filter); |
2156 | filter = &*decompress; | |
2157 | } | |
7c673cae FG |
2158 | |
2159 | attr_iter = attrs.find(RGW_ATTR_USER_MANIFEST); | |
2160 | if (attr_iter != attrs.end() && !skip_manifest) { | |
f67539c2 | 2161 | op_ret = handle_user_manifest(attr_iter->second.c_str(), y); |
7c673cae | 2162 | if (op_ret < 0) { |
11fdf7f2 | 2163 | ldpp_dout(this, 0) << "ERROR: failed to handle user manifest ret=" |
7c673cae FG |
2164 | << op_ret << dendl; |
2165 | goto done_err; | |
2166 | } | |
2167 | return; | |
2168 | } | |
2169 | ||
2170 | attr_iter = attrs.find(RGW_ATTR_SLO_MANIFEST); | |
2171 | if (attr_iter != attrs.end() && !skip_manifest) { | |
2172 | is_slo = true; | |
f67539c2 | 2173 | op_ret = handle_slo_manifest(attr_iter->second, y); |
7c673cae | 2174 | if (op_ret < 0) { |
11fdf7f2 | 2175 | ldpp_dout(this, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret |
7c673cae FG |
2176 | << dendl; |
2177 | goto done_err; | |
2178 | } | |
2179 | return; | |
2180 | } | |
2181 | ||
31f18b77 FG |
2182 | // for range requests with obj size 0 |
2183 | if (range_str && !(s->obj_size)) { | |
2184 | total_len = 0; | |
2185 | op_ret = -ERANGE; | |
2186 | goto done_err; | |
2187 | } | |
2188 | ||
f67539c2 | 2189 | op_ret = s->object->range_to_ofs(s->obj_size, ofs, end); |
31f18b77 FG |
2190 | if (op_ret < 0) |
2191 | goto done_err; | |
2192 | total_len = (ofs <= end ? end + 1 - ofs : 0); | |
2193 | ||
7c673cae FG |
2194 | /* Check whether the object has expired. Swift API documentation |
2195 | * stands that we should return 404 Not Found in such case. */ | |
f67539c2 | 2196 | if (need_object_expiration() && s->object->is_expired()) { |
7c673cae FG |
2197 | op_ret = -ENOENT; |
2198 | goto done_err; | |
2199 | } | |
2200 | ||
9f95a23c TL |
2201 | /* Decode S3 objtags, if any */ |
2202 | rgw_cond_decode_objtags(s, attrs); | |
2203 | ||
7c673cae FG |
2204 | start = ofs; |
2205 | ||
7c673cae FG |
2206 | attr_iter = attrs.find(RGW_ATTR_MANIFEST); |
2207 | op_ret = this->get_decrypt_filter(&decrypt, filter, | |
2208 | attr_iter != attrs.end() ? &(attr_iter->second) : nullptr); | |
2209 | if (decrypt != nullptr) { | |
2210 | filter = decrypt.get(); | |
2211 | } | |
2212 | if (op_ret < 0) { | |
2213 | goto done_err; | |
2214 | } | |
2215 | ||
2216 | if (!get_data || ofs > end) { | |
2217 | send_response_data(bl, 0, 0); | |
2218 | return; | |
2219 | } | |
2220 | ||
2221 | perfcounter->inc(l_rgw_get_b, end - ofs); | |
2222 | ||
2223 | ofs_x = ofs; | |
2224 | end_x = end; | |
2225 | filter->fixup_range(ofs_x, end_x); | |
b3b6e05e | 2226 | op_ret = read_op->iterate(this, ofs_x, end_x, filter, s->yield); |
7c673cae FG |
2227 | |
2228 | if (op_ret >= 0) | |
2229 | op_ret = filter->flush(); | |
2230 | ||
11fdf7f2 | 2231 | perfcounter->tinc(l_rgw_get_lat, s->time_elapsed()); |
7c673cae FG |
2232 | if (op_ret < 0) { |
2233 | goto done_err; | |
2234 | } | |
2235 | ||
2236 | op_ret = send_response_data(bl, 0, 0); | |
2237 | if (op_ret < 0) { | |
2238 | goto done_err; | |
2239 | } | |
2240 | return; | |
2241 | ||
2242 | done_err: | |
f67539c2 | 2243 | send_response_data_error(y); |
7c673cae FG |
2244 | } |
2245 | ||
2246 | int RGWGetObj::init_common() | |
2247 | { | |
2248 | if (range_str) { | |
28e407b8 | 2249 | /* range parsed error when prefetch */ |
7c673cae | 2250 | if (!range_parsed) { |
28e407b8 | 2251 | int r = parse_range(); |
7c673cae FG |
2252 | if (r < 0) |
2253 | return r; | |
2254 | } | |
2255 | } | |
2256 | if (if_mod) { | |
2257 | if (parse_time(if_mod, &mod_time) < 0) | |
2258 | return -EINVAL; | |
2259 | mod_ptr = &mod_time; | |
2260 | } | |
2261 | ||
2262 | if (if_unmod) { | |
2263 | if (parse_time(if_unmod, &unmod_time) < 0) | |
2264 | return -EINVAL; | |
2265 | unmod_ptr = &unmod_time; | |
2266 | } | |
2267 | ||
2268 | return 0; | |
2269 | } | |
2270 | ||
f67539c2 | 2271 | int RGWListBuckets::verify_permission(optional_yield y) |
7c673cae | 2272 | { |
eafe8130 TL |
2273 | rgw::Partition partition = rgw::Partition::aws; |
2274 | rgw::Service service = rgw::Service::s3; | |
11fdf7f2 | 2275 | |
f67539c2 TL |
2276 | string tenant; |
2277 | if (s->auth.identity->get_identity_type() == TYPE_ROLE) { | |
2278 | tenant = s->auth.identity->get_role_tenant(); | |
2279 | } else { | |
2280 | tenant = s->user->get_tenant(); | |
2281 | } | |
2282 | ||
2283 | if (!verify_user_permission(this, s, ARN(partition, service, "", tenant, "*"), rgw::IAM::s3ListAllMyBuckets)) { | |
7c673cae FG |
2284 | return -EACCES; |
2285 | } | |
2286 | ||
2287 | return 0; | |
2288 | } | |
2289 | ||
f67539c2 | 2290 | int RGWGetUsage::verify_permission(optional_yield y) |
7c673cae FG |
2291 | { |
2292 | if (s->auth.identity->is_anonymous()) { | |
2293 | return -EACCES; | |
2294 | } | |
2295 | ||
2296 | return 0; | |
2297 | } | |
2298 | ||
f67539c2 | 2299 | void RGWListBuckets::execute(optional_yield y) |
7c673cae FG |
2300 | { |
2301 | bool done; | |
2302 | bool started = false; | |
2303 | uint64_t total_count = 0; | |
2304 | ||
3efd9988 | 2305 | const uint64_t max_buckets = s->cct->_conf->rgw_list_buckets_max_chunk; |
7c673cae | 2306 | |
f67539c2 | 2307 | op_ret = get_params(y); |
7c673cae FG |
2308 | if (op_ret < 0) { |
2309 | goto send_end; | |
2310 | } | |
2311 | ||
2312 | if (supports_account_metadata()) { | |
b3b6e05e | 2313 | op_ret = store->ctl()->user->get_attrs_by_uid(this, s->user->get_id(), &attrs, s->yield); |
7c673cae FG |
2314 | if (op_ret < 0) { |
2315 | goto send_end; | |
2316 | } | |
2317 | } | |
2318 | ||
2319 | is_truncated = false; | |
2320 | do { | |
9f95a23c | 2321 | rgw::sal::RGWBucketList buckets; |
7c673cae FG |
2322 | uint64_t read_count; |
2323 | if (limit >= 0) { | |
11fdf7f2 | 2324 | read_count = min(limit - total_count, max_buckets); |
7c673cae FG |
2325 | } else { |
2326 | read_count = max_buckets; | |
2327 | } | |
2328 | ||
b3b6e05e | 2329 | op_ret = s->user->list_buckets(this, marker, end_marker, read_count, should_get_stats(), buckets, y); |
9f95a23c | 2330 | |
7c673cae FG |
2331 | if (op_ret < 0) { |
2332 | /* hmm.. something wrong here.. the user was authenticated, so it | |
2333 | should exist */ | |
11fdf7f2 | 2334 | ldpp_dout(this, 10) << "WARNING: failed on rgw_get_user_buckets uid=" |
9f95a23c | 2335 | << s->user->get_id() << dendl; |
7c673cae FG |
2336 | break; |
2337 | } | |
3efd9988 FG |
2338 | |
2339 | /* We need to have stats for all our policies - even if a given policy | |
2340 | * isn't actually used in a given account. In such situation its usage | |
2341 | * stats would be simply full of zeros. */ | |
f67539c2 | 2342 | for (const auto& policy : store->get_zonegroup().placement_targets) { |
3efd9988 FG |
2343 | policies_stats.emplace(policy.second.name, |
2344 | decltype(policies_stats)::mapped_type()); | |
2345 | } | |
2346 | ||
f67539c2 | 2347 | std::map<std::string, std::unique_ptr<rgw::sal::RGWBucket>>& m = buckets.get_buckets(); |
3efd9988 FG |
2348 | for (const auto& kv : m) { |
2349 | const auto& bucket = kv.second; | |
2350 | ||
9f95a23c TL |
2351 | global_stats.bytes_used += bucket->get_size(); |
2352 | global_stats.bytes_used_rounded += bucket->get_size_rounded(); | |
2353 | global_stats.objects_count += bucket->get_count(); | |
3efd9988 FG |
2354 | |
2355 | /* operator[] still can create a new entry for storage policy seen | |
2356 | * for first time. */ | |
9f95a23c TL |
2357 | auto& policy_stats = policies_stats[bucket->get_placement_rule().to_str()]; |
2358 | policy_stats.bytes_used += bucket->get_size(); | |
2359 | policy_stats.bytes_used_rounded += bucket->get_size_rounded(); | |
3efd9988 | 2360 | policy_stats.buckets_count++; |
9f95a23c | 2361 | policy_stats.objects_count += bucket->get_count(); |
7c673cae | 2362 | } |
3efd9988 | 2363 | global_stats.buckets_count += m.size(); |
7c673cae FG |
2364 | total_count += m.size(); |
2365 | ||
2366 | done = (m.size() < read_count || (limit >= 0 && total_count >= (uint64_t)limit)); | |
2367 | ||
2368 | if (!started) { | |
2369 | send_response_begin(buckets.count() > 0); | |
2370 | started = true; | |
2371 | } | |
2372 | ||
9f95a23c TL |
2373 | if (read_count > 0 && |
2374 | !m.empty()) { | |
f67539c2 | 2375 | auto riter = m.rbegin(); |
7c673cae | 2376 | marker = riter->first; |
3efd9988 FG |
2377 | |
2378 | handle_listing_chunk(std::move(buckets)); | |
7c673cae FG |
2379 | } |
2380 | } while (is_truncated && !done); | |
2381 | ||
2382 | send_end: | |
2383 | if (!started) { | |
2384 | send_response_begin(false); | |
2385 | } | |
2386 | send_response_end(); | |
2387 | } | |
2388 | ||
f67539c2 | 2389 | void RGWGetUsage::execute(optional_yield y) |
7c673cae FG |
2390 | { |
2391 | uint64_t start_epoch = 0; | |
2392 | uint64_t end_epoch = (uint64_t)-1; | |
f67539c2 | 2393 | op_ret = get_params(y); |
7c673cae FG |
2394 | if (op_ret < 0) |
2395 | return; | |
2396 | ||
2397 | if (!start_date.empty()) { | |
2398 | op_ret = utime_t::parse_date(start_date, &start_epoch, NULL); | |
2399 | if (op_ret < 0) { | |
11fdf7f2 | 2400 | ldpp_dout(this, 0) << "ERROR: failed to parse start date" << dendl; |
7c673cae FG |
2401 | return; |
2402 | } | |
2403 | } | |
2404 | ||
2405 | if (!end_date.empty()) { | |
2406 | op_ret = utime_t::parse_date(end_date, &end_epoch, NULL); | |
2407 | if (op_ret < 0) { | |
11fdf7f2 | 2408 | ldpp_dout(this, 0) << "ERROR: failed to parse end date" << dendl; |
7c673cae FG |
2409 | return; |
2410 | } | |
2411 | } | |
2412 | ||
2413 | uint32_t max_entries = 1000; | |
2414 | ||
2415 | bool is_truncated = true; | |
2416 | ||
2417 | RGWUsageIter usage_iter; | |
2418 | ||
f67539c2 | 2419 | while (s->bucket && is_truncated) { |
b3b6e05e | 2420 | op_ret = s->bucket->read_usage(this, start_epoch, end_epoch, max_entries, &is_truncated, |
f67539c2 | 2421 | usage_iter, usage); |
7c673cae FG |
2422 | if (op_ret == -ENOENT) { |
2423 | op_ret = 0; | |
2424 | is_truncated = false; | |
2425 | } | |
2426 | ||
2427 | if (op_ret < 0) { | |
2428 | return; | |
2429 | } | |
2430 | } | |
2431 | ||
b3b6e05e | 2432 | op_ret = rgw_user_sync_all_stats(this, store, s->user->get_id(), y); |
7c673cae | 2433 | if (op_ret < 0) { |
11fdf7f2 | 2434 | ldpp_dout(this, 0) << "ERROR: failed to sync user stats" << dendl; |
c07f9fc5 FG |
2435 | return; |
2436 | } | |
2437 | ||
b3b6e05e | 2438 | op_ret = rgw_user_get_all_buckets_stats(this, store, s->user->get_id(), buckets_usage, y); |
c07f9fc5 | 2439 | if (op_ret < 0) { |
11fdf7f2 TL |
2440 | ldpp_dout(this, 0) << "ERROR: failed to get user's buckets stats" << dendl; |
2441 | return; | |
7c673cae | 2442 | } |
c07f9fc5 | 2443 | |
b3b6e05e | 2444 | op_ret = store->ctl()->user->read_stats(this, s->user->get_id(), &stats, y); |
7c673cae | 2445 | if (op_ret < 0) { |
11fdf7f2 | 2446 | ldpp_dout(this, 0) << "ERROR: can't read user header" << dendl; |
c07f9fc5 | 2447 | return; |
7c673cae FG |
2448 | } |
2449 | ||
2450 | return; | |
2451 | } | |
2452 | ||
f67539c2 | 2453 | int RGWStatAccount::verify_permission(optional_yield y) |
7c673cae | 2454 | { |
11fdf7f2 | 2455 | if (!verify_user_permission_no_policy(this, s, RGW_PERM_READ)) { |
7c673cae FG |
2456 | return -EACCES; |
2457 | } | |
2458 | ||
2459 | return 0; | |
2460 | } | |
2461 | ||
f67539c2 | 2462 | void RGWStatAccount::execute(optional_yield y) |
7c673cae FG |
2463 | { |
2464 | string marker; | |
9f95a23c | 2465 | rgw::sal::RGWBucketList buckets; |
7c673cae | 2466 | uint64_t max_buckets = s->cct->_conf->rgw_list_buckets_max_chunk; |
f6b5b4d7 | 2467 | const string *lastmarker; |
7c673cae FG |
2468 | |
2469 | do { | |
7c673cae | 2470 | |
f6b5b4d7 | 2471 | lastmarker = nullptr; |
b3b6e05e | 2472 | op_ret = rgw_read_user_buckets(this, store, s->user->get_id(), buckets, marker, |
f67539c2 | 2473 | string(), max_buckets, true, y); |
7c673cae FG |
2474 | if (op_ret < 0) { |
2475 | /* hmm.. something wrong here.. the user was authenticated, so it | |
2476 | should exist */ | |
f6b5b4d7 TL |
2477 | ldpp_dout(this, 10) << "WARNING: failed on rgw_read_user_buckets uid=" |
2478 | << s->user->get_id() << " ret=" << op_ret << dendl; | |
7c673cae FG |
2479 | break; |
2480 | } else { | |
3efd9988 FG |
2481 | /* We need to have stats for all our policies - even if a given policy |
2482 | * isn't actually used in a given account. In such situation its usage | |
2483 | * stats would be simply full of zeros. */ | |
f67539c2 | 2484 | for (const auto& policy : store->get_zonegroup().placement_targets) { |
3efd9988 FG |
2485 | policies_stats.emplace(policy.second.name, |
2486 | decltype(policies_stats)::mapped_type()); | |
2487 | } | |
2488 | ||
f67539c2 | 2489 | std::map<std::string, std::unique_ptr<rgw::sal::RGWBucket>>& m = buckets.get_buckets(); |
3efd9988 FG |
2490 | for (const auto& kv : m) { |
2491 | const auto& bucket = kv.second; | |
f6b5b4d7 | 2492 | lastmarker = &kv.first; |
3efd9988 | 2493 | |
9f95a23c TL |
2494 | global_stats.bytes_used += bucket->get_size(); |
2495 | global_stats.bytes_used_rounded += bucket->get_size_rounded(); | |
2496 | global_stats.objects_count += bucket->get_count(); | |
3efd9988 FG |
2497 | |
2498 | /* operator[] still can create a new entry for storage policy seen | |
2499 | * for first time. */ | |
9f95a23c TL |
2500 | auto& policy_stats = policies_stats[bucket->get_placement_rule().to_str()]; |
2501 | policy_stats.bytes_used += bucket->get_size(); | |
2502 | policy_stats.bytes_used_rounded += bucket->get_size_rounded(); | |
3efd9988 | 2503 | policy_stats.buckets_count++; |
9f95a23c | 2504 | policy_stats.objects_count += bucket->get_count(); |
7c673cae | 2505 | } |
3efd9988 | 2506 | global_stats.buckets_count += m.size(); |
7c673cae FG |
2507 | |
2508 | } | |
f6b5b4d7 | 2509 | if (!lastmarker) { |
b3b6e05e | 2510 | ldpp_dout(this, -1) << "ERROR: rgw_read_user_buckets, stasis at marker=" |
f6b5b4d7 TL |
2511 | << marker << " uid=" << s->user->get_id() << dendl; |
2512 | break; | |
2513 | } | |
2514 | marker = *lastmarker; | |
9f95a23c | 2515 | } while (buckets.is_truncated()); |
7c673cae FG |
2516 | } |
2517 | ||
f67539c2 | 2518 | int RGWGetBucketVersioning::verify_permission(optional_yield y) |
7c673cae | 2519 | { |
b32b8144 | 2520 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketVersioning); |
7c673cae FG |
2521 | } |
2522 | ||
2523 | void RGWGetBucketVersioning::pre_exec() | |
2524 | { | |
2525 | rgw_bucket_object_pre_exec(s); | |
2526 | } | |
2527 | ||
f67539c2 | 2528 | void RGWGetBucketVersioning::execute(optional_yield y) |
7c673cae | 2529 | { |
f67539c2 TL |
2530 | if (! s->bucket_exists) { |
2531 | op_ret = -ERR_NO_SUCH_BUCKET; | |
2532 | return; | |
2533 | } | |
2534 | ||
2535 | versioned = s->bucket->versioned(); | |
2536 | versioning_enabled = s->bucket->versioning_enabled(); | |
2537 | mfa_enabled = s->bucket->get_info().mfa_enabled(); | |
7c673cae FG |
2538 | } |
2539 | ||
f67539c2 | 2540 | int RGWSetBucketVersioning::verify_permission(optional_yield y) |
7c673cae | 2541 | { |
b32b8144 | 2542 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketVersioning); |
7c673cae FG |
2543 | } |
2544 | ||
2545 | void RGWSetBucketVersioning::pre_exec() | |
2546 | { | |
2547 | rgw_bucket_object_pre_exec(s); | |
2548 | } | |
2549 | ||
f67539c2 | 2550 | void RGWSetBucketVersioning::execute(optional_yield y) |
7c673cae | 2551 | { |
f67539c2 | 2552 | op_ret = get_params(y); |
7c673cae FG |
2553 | if (op_ret < 0) |
2554 | return; | |
2555 | ||
f67539c2 TL |
2556 | if (! s->bucket_exists) { |
2557 | op_ret = -ERR_NO_SUCH_BUCKET; | |
2558 | return; | |
2559 | } | |
2560 | ||
2561 | if (s->bucket->get_info().obj_lock_enabled() && versioning_status != VersioningEnabled) { | |
522d829b TL |
2562 | s->err.message = "bucket versioning cannot be disabled on buckets with object lock enabled"; |
2563 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
2564 | op_ret = -ERR_INVALID_BUCKET_STATE; |
2565 | return; | |
2566 | } | |
2567 | ||
f67539c2 | 2568 | bool cur_mfa_status = s->bucket->get_info().mfa_enabled(); |
11fdf7f2 TL |
2569 | |
2570 | mfa_set_status &= (mfa_status != cur_mfa_status); | |
2571 | ||
2572 | if (mfa_set_status && | |
2573 | !s->mfa_verified) { | |
2574 | op_ret = -ERR_MFA_REQUIRED; | |
2575 | return; | |
2576 | } | |
92f5a8d4 TL |
2577 | //if mfa is enabled for bucket, make sure mfa code is validated in case versioned status gets changed |
2578 | if (cur_mfa_status) { | |
2579 | bool req_versioning_status = false; | |
2580 | //if requested versioning status is not the same as the one set for the bucket, return error | |
2581 | if (versioning_status == VersioningEnabled) { | |
f67539c2 | 2582 | req_versioning_status = (s->bucket->get_info().flags & BUCKET_VERSIONS_SUSPENDED) != 0; |
92f5a8d4 | 2583 | } else if (versioning_status == VersioningSuspended) { |
f67539c2 | 2584 | req_versioning_status = (s->bucket->get_info().flags & BUCKET_VERSIONS_SUSPENDED) == 0; |
92f5a8d4 TL |
2585 | } |
2586 | if (req_versioning_status && !s->mfa_verified) { | |
2587 | op_ret = -ERR_MFA_REQUIRED; | |
2588 | return; | |
2589 | } | |
2590 | } | |
11fdf7f2 | 2591 | |
b3b6e05e | 2592 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
2593 | if (op_ret < 0) { |
2594 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
2595 | return; | |
7c673cae FG |
2596 | } |
2597 | ||
11fdf7f2 TL |
2598 | bool modified = mfa_set_status; |
2599 | ||
b3b6e05e | 2600 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [&] { |
11fdf7f2 TL |
2601 | if (mfa_set_status) { |
2602 | if (mfa_status) { | |
f67539c2 | 2603 | s->bucket->get_info().flags |= BUCKET_MFA_ENABLED; |
11fdf7f2 | 2604 | } else { |
f67539c2 | 2605 | s->bucket->get_info().flags &= ~BUCKET_MFA_ENABLED; |
11fdf7f2 TL |
2606 | } |
2607 | } | |
2608 | ||
2609 | if (versioning_status == VersioningEnabled) { | |
f67539c2 TL |
2610 | s->bucket->get_info().flags |= BUCKET_VERSIONED; |
2611 | s->bucket->get_info().flags &= ~BUCKET_VERSIONS_SUSPENDED; | |
11fdf7f2 TL |
2612 | modified = true; |
2613 | } else if (versioning_status == VersioningSuspended) { | |
f67539c2 | 2614 | s->bucket->get_info().flags |= (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED); |
11fdf7f2 TL |
2615 | modified = true; |
2616 | } else { | |
2617 | return op_ret; | |
b32b8144 | 2618 | } |
f67539c2 | 2619 | s->bucket->set_attrs(rgw::sal::RGWAttrs(s->bucket_attrs)); |
b3b6e05e | 2620 | return s->bucket->put_instance_info(this, false, real_time()); |
b32b8144 | 2621 | }); |
7c673cae | 2622 | |
11fdf7f2 TL |
2623 | if (!modified) { |
2624 | return; | |
2625 | } | |
2626 | ||
7c673cae | 2627 | if (op_ret < 0) { |
f67539c2 | 2628 | ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket->get_name() |
7c673cae FG |
2629 | << " returned err=" << op_ret << dendl; |
2630 | return; | |
2631 | } | |
2632 | } | |
2633 | ||
f67539c2 | 2634 | int RGWGetBucketWebsite::verify_permission(optional_yield y) |
7c673cae | 2635 | { |
b32b8144 | 2636 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketWebsite); |
7c673cae FG |
2637 | } |
2638 | ||
2639 | void RGWGetBucketWebsite::pre_exec() | |
2640 | { | |
2641 | rgw_bucket_object_pre_exec(s); | |
2642 | } | |
2643 | ||
f67539c2 | 2644 | void RGWGetBucketWebsite::execute(optional_yield y) |
7c673cae | 2645 | { |
f67539c2 | 2646 | if (!s->bucket->get_info().has_website) { |
b32b8144 | 2647 | op_ret = -ERR_NO_SUCH_WEBSITE_CONFIGURATION; |
7c673cae FG |
2648 | } |
2649 | } | |
2650 | ||
f67539c2 | 2651 | int RGWSetBucketWebsite::verify_permission(optional_yield y) |
7c673cae | 2652 | { |
b32b8144 | 2653 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketWebsite); |
7c673cae FG |
2654 | } |
2655 | ||
2656 | void RGWSetBucketWebsite::pre_exec() | |
2657 | { | |
2658 | rgw_bucket_object_pre_exec(s); | |
2659 | } | |
2660 | ||
f67539c2 | 2661 | void RGWSetBucketWebsite::execute(optional_yield y) |
7c673cae | 2662 | { |
f67539c2 | 2663 | op_ret = get_params(y); |
7c673cae FG |
2664 | |
2665 | if (op_ret < 0) | |
2666 | return; | |
2667 | ||
522d829b TL |
2668 | if (!s->bucket_exists) { |
2669 | op_ret = -ERR_NO_SUCH_BUCKET; | |
2670 | return; | |
2671 | } | |
2672 | ||
b3b6e05e | 2673 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
2674 | if (op_ret < 0) { |
2675 | ldpp_dout(this, 0) << " forward_request_to_master returned ret=" << op_ret << dendl; | |
2676 | return; | |
31f18b77 FG |
2677 | } |
2678 | ||
b3b6e05e | 2679 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 TL |
2680 | s->bucket->get_info().has_website = true; |
2681 | s->bucket->get_info().website_conf = website_conf; | |
b3b6e05e | 2682 | op_ret = s->bucket->put_instance_info(this, false, real_time()); |
b32b8144 FG |
2683 | return op_ret; |
2684 | }); | |
7c673cae | 2685 | |
7c673cae | 2686 | if (op_ret < 0) { |
f67539c2 | 2687 | ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket->get_name() |
11fdf7f2 | 2688 | << " returned err=" << op_ret << dendl; |
7c673cae FG |
2689 | return; |
2690 | } | |
2691 | } | |
2692 | ||
f67539c2 | 2693 | int RGWDeleteBucketWebsite::verify_permission(optional_yield y) |
7c673cae | 2694 | { |
b32b8144 | 2695 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3DeleteBucketWebsite); |
7c673cae FG |
2696 | } |
2697 | ||
2698 | void RGWDeleteBucketWebsite::pre_exec() | |
2699 | { | |
2700 | rgw_bucket_object_pre_exec(s); | |
2701 | } | |
2702 | ||
f67539c2 | 2703 | void RGWDeleteBucketWebsite::execute(optional_yield y) |
7c673cae | 2704 | { |
522d829b TL |
2705 | if (!s->bucket_exists) { |
2706 | op_ret = -ERR_NO_SUCH_BUCKET; | |
2707 | return; | |
2708 | } | |
2709 | ||
f67539c2 | 2710 | bufferlist in_data; |
494da23a | 2711 | |
b3b6e05e | 2712 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
2713 | if (op_ret < 0) { |
2714 | ldpp_dout(this, 0) << "NOTICE: forward_to_master failed on bucket=" << s->bucket->get_name() | |
2715 | << "returned err=" << op_ret << dendl; | |
2716 | return; | |
494da23a | 2717 | } |
b3b6e05e | 2718 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 TL |
2719 | s->bucket->get_info().has_website = false; |
2720 | s->bucket->get_info().website_conf = RGWBucketWebsiteConf(); | |
b3b6e05e | 2721 | op_ret = s->bucket->put_instance_info(this, false, real_time()); |
b32b8144 FG |
2722 | return op_ret; |
2723 | }); | |
7c673cae | 2724 | if (op_ret < 0) { |
f67539c2 | 2725 | ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket |
11fdf7f2 | 2726 | << " returned err=" << op_ret << dendl; |
7c673cae FG |
2727 | return; |
2728 | } | |
2729 | } | |
2730 | ||
f67539c2 | 2731 | int RGWStatBucket::verify_permission(optional_yield y) |
7c673cae | 2732 | { |
31f18b77 | 2733 | // This (a HEAD request on a bucket) is governed by the s3:ListBucket permission. |
11fdf7f2 | 2734 | if (!verify_bucket_permission(this, s, rgw::IAM::s3ListBucket)) { |
7c673cae FG |
2735 | return -EACCES; |
2736 | } | |
2737 | ||
2738 | return 0; | |
2739 | } | |
2740 | ||
2741 | void RGWStatBucket::pre_exec() | |
2742 | { | |
2743 | rgw_bucket_object_pre_exec(s); | |
2744 | } | |
2745 | ||
f67539c2 | 2746 | void RGWStatBucket::execute(optional_yield y) |
7c673cae FG |
2747 | { |
2748 | if (!s->bucket_exists) { | |
2749 | op_ret = -ERR_NO_SUCH_BUCKET; | |
2750 | return; | |
2751 | } | |
2752 | ||
b3b6e05e | 2753 | op_ret = store->get_bucket(this, s->user.get(), s->bucket->get_key(), &bucket, y); |
f67539c2 TL |
2754 | if (op_ret) { |
2755 | return; | |
2756 | } | |
b3b6e05e | 2757 | op_ret = bucket->update_container_stats(s); |
7c673cae FG |
2758 | } |
2759 | ||
f67539c2 | 2760 | int RGWListBucket::verify_permission(optional_yield y) |
7c673cae | 2761 | { |
f67539c2 | 2762 | op_ret = get_params(y); |
31f18b77 FG |
2763 | if (op_ret < 0) { |
2764 | return op_ret; | |
2765 | } | |
b32b8144 FG |
2766 | if (!prefix.empty()) |
2767 | s->env.emplace("s3:prefix", prefix); | |
2768 | ||
2769 | if (!delimiter.empty()) | |
2770 | s->env.emplace("s3:delimiter", delimiter); | |
2771 | ||
2772 | s->env.emplace("s3:max-keys", std::to_string(max)); | |
31f18b77 | 2773 | |
11fdf7f2 TL |
2774 | if (!verify_bucket_permission(this, |
2775 | s, | |
31f18b77 FG |
2776 | list_versions ? |
2777 | rgw::IAM::s3ListBucketVersions : | |
2778 | rgw::IAM::s3ListBucket)) { | |
7c673cae FG |
2779 | return -EACCES; |
2780 | } | |
2781 | ||
2782 | return 0; | |
2783 | } | |
2784 | ||
2785 | int RGWListBucket::parse_max_keys() | |
2786 | { | |
f64942e4 AA |
2787 | // Bound max value of max-keys to configured value for security |
2788 | // Bound min value of max-keys to '0' | |
2789 | // Some S3 clients explicitly send max-keys=0 to detect if the bucket is | |
2790 | // empty without listing any items. | |
2791 | return parse_value_and_bound(max_keys, max, 0, | |
11fdf7f2 | 2792 | g_conf().get_val<uint64_t>("rgw_max_listing_results"), |
f64942e4 | 2793 | default_max); |
7c673cae FG |
2794 | } |
2795 | ||
2796 | void RGWListBucket::pre_exec() | |
2797 | { | |
2798 | rgw_bucket_object_pre_exec(s); | |
2799 | } | |
2800 | ||
f67539c2 | 2801 | void RGWListBucket::execute(optional_yield y) |
7c673cae FG |
2802 | { |
2803 | if (!s->bucket_exists) { | |
2804 | op_ret = -ERR_NO_SUCH_BUCKET; | |
2805 | return; | |
2806 | } | |
2807 | ||
1adf2230 | 2808 | if (allow_unordered && !delimiter.empty()) { |
11fdf7f2 | 2809 | ldpp_dout(this, 0) << |
1adf2230 AA |
2810 | "ERROR: unordered bucket listing requested with a delimiter" << dendl; |
2811 | op_ret = -EINVAL; | |
2812 | return; | |
2813 | } | |
2814 | ||
7c673cae | 2815 | if (need_container_stats()) { |
b3b6e05e | 2816 | op_ret = s->bucket->update_container_stats(s); |
7c673cae FG |
2817 | } |
2818 | ||
f67539c2 TL |
2819 | rgw::sal::RGWBucket::ListParams params; |
2820 | params.prefix = prefix; | |
2821 | params.delim = delimiter; | |
2822 | params.marker = marker; | |
2823 | params.end_marker = end_marker; | |
2824 | params.list_versions = list_versions; | |
2825 | params.allow_unordered = allow_unordered; | |
2826 | params.shard_id = shard_id; | |
7c673cae | 2827 | |
f67539c2 | 2828 | rgw::sal::RGWBucket::ListResults results; |
7c673cae | 2829 | |
b3b6e05e | 2830 | op_ret = s->bucket->list(this, params, max, results, y); |
31f18b77 | 2831 | if (op_ret >= 0) { |
f67539c2 TL |
2832 | next_marker = results.next_marker; |
2833 | is_truncated = results.is_truncated; | |
2834 | objs = std::move(results.objs); | |
2835 | common_prefixes = std::move(results.common_prefixes); | |
7c673cae FG |
2836 | } |
2837 | } | |
2838 | ||
f67539c2 | 2839 | int RGWGetBucketLogging::verify_permission(optional_yield y) |
7c673cae | 2840 | { |
b32b8144 | 2841 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketLogging); |
7c673cae FG |
2842 | } |
2843 | ||
f67539c2 | 2844 | int RGWGetBucketLocation::verify_permission(optional_yield y) |
7c673cae | 2845 | { |
b32b8144 | 2846 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketLocation); |
7c673cae FG |
2847 | } |
2848 | ||
f67539c2 | 2849 | int RGWCreateBucket::verify_permission(optional_yield y) |
7c673cae FG |
2850 | { |
2851 | /* This check is mostly needed for S3 that doesn't support account ACL. | |
2852 | * Swift doesn't allow to delegate any permission to an anonymous user, | |
2853 | * so it will become an early exit in such case. */ | |
2854 | if (s->auth.identity->is_anonymous()) { | |
2855 | return -EACCES; | |
2856 | } | |
2857 | ||
11fdf7f2 TL |
2858 | rgw_bucket bucket; |
2859 | bucket.name = s->bucket_name; | |
2860 | bucket.tenant = s->bucket_tenant; | |
2861 | ARN arn = ARN(bucket); | |
2862 | if (!verify_user_permission(this, s, arn, rgw::IAM::s3CreateBucket)) { | |
7c673cae FG |
2863 | return -EACCES; |
2864 | } | |
2865 | ||
9f95a23c | 2866 | if (s->user->get_tenant() != s->bucket_tenant) { |
f67539c2 TL |
2867 | //AssumeRole is meant for cross account access |
2868 | if (s->auth.identity->get_identity_type() != TYPE_ROLE) { | |
2869 | ldpp_dout(this, 10) << "user cannot create a bucket in a different tenant" | |
2870 | << " (user_id.tenant=" << s->user->get_tenant() | |
2871 | << " requested=" << s->bucket_tenant << ")" | |
2872 | << dendl; | |
2873 | return -EACCES; | |
2874 | } | |
7c673cae | 2875 | } |
f67539c2 | 2876 | |
9f95a23c | 2877 | if (s->user->get_max_buckets() < 0) { |
7c673cae FG |
2878 | return -EPERM; |
2879 | } | |
2880 | ||
9f95a23c TL |
2881 | if (s->user->get_max_buckets()) { |
2882 | rgw::sal::RGWBucketList buckets; | |
7c673cae | 2883 | string marker; |
b3b6e05e | 2884 | op_ret = rgw_read_user_buckets(this, store, s->user->get_id(), buckets, |
9f95a23c | 2885 | marker, string(), s->user->get_max_buckets(), |
f67539c2 | 2886 | false, y); |
7c673cae FG |
2887 | if (op_ret < 0) { |
2888 | return op_ret; | |
2889 | } | |
2890 | ||
9f95a23c | 2891 | if ((int)buckets.count() >= s->user->get_max_buckets()) { |
7c673cae FG |
2892 | return -ERR_TOO_MANY_BUCKETS; |
2893 | } | |
2894 | } | |
2895 | ||
2896 | return 0; | |
2897 | } | |
2898 | ||
7c673cae FG |
2899 | void RGWCreateBucket::pre_exec() |
2900 | { | |
2901 | rgw_bucket_object_pre_exec(s); | |
2902 | } | |
2903 | ||
2904 | static void prepare_add_del_attrs(const map<string, bufferlist>& orig_attrs, | |
2905 | map<string, bufferlist>& out_attrs, | |
2906 | map<string, bufferlist>& out_rmattrs) | |
2907 | { | |
2908 | for (const auto& kv : orig_attrs) { | |
2909 | const string& name = kv.first; | |
2910 | ||
2911 | /* Check if the attr is user-defined metadata item. */ | |
2912 | if (name.compare(0, sizeof(RGW_ATTR_META_PREFIX) - 1, | |
2913 | RGW_ATTR_META_PREFIX) == 0) { | |
2914 | /* For the objects all existing meta attrs have to be removed. */ | |
2915 | out_rmattrs[name] = kv.second; | |
2916 | } else if (out_attrs.find(name) == std::end(out_attrs)) { | |
2917 | out_attrs[name] = kv.second; | |
2918 | } | |
2919 | } | |
2920 | } | |
2921 | ||
2922 | /* Fuse resource metadata basing on original attributes in @orig_attrs, set | |
2923 | * of _custom_ attribute names to remove in @rmattr_names and attributes in | |
2924 | * @out_attrs. Place results in @out_attrs. | |
2925 | * | |
2926 | * NOTE: it's supposed that all special attrs already present in @out_attrs | |
2927 | * will be preserved without any change. Special attributes are those which | |
2928 | * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones | |
2929 | * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */ | |
2930 | static void prepare_add_del_attrs(const map<string, bufferlist>& orig_attrs, | |
2931 | const set<string>& rmattr_names, | |
2932 | map<string, bufferlist>& out_attrs) | |
2933 | { | |
2934 | for (const auto& kv : orig_attrs) { | |
2935 | const string& name = kv.first; | |
2936 | ||
2937 | /* Check if the attr is user-defined metadata item. */ | |
2938 | if (name.compare(0, strlen(RGW_ATTR_META_PREFIX), | |
2939 | RGW_ATTR_META_PREFIX) == 0) { | |
2940 | /* For the buckets all existing meta attrs are preserved, | |
2941 | except those that are listed in rmattr_names. */ | |
2942 | if (rmattr_names.find(name) != std::end(rmattr_names)) { | |
2943 | const auto aiter = out_attrs.find(name); | |
2944 | ||
2945 | if (aiter != std::end(out_attrs)) { | |
2946 | out_attrs.erase(aiter); | |
2947 | } | |
2948 | } else { | |
2949 | /* emplace() won't alter the map if the key is already present. | |
2950 | * This behaviour is fully intensional here. */ | |
2951 | out_attrs.emplace(kv); | |
2952 | } | |
2953 | } else if (out_attrs.find(name) == std::end(out_attrs)) { | |
2954 | out_attrs[name] = kv.second; | |
2955 | } | |
2956 | } | |
2957 | } | |
2958 | ||
2959 | ||
2960 | static void populate_with_generic_attrs(const req_state * const s, | |
2961 | map<string, bufferlist>& out_attrs) | |
2962 | { | |
2963 | for (const auto& kv : s->generic_attrs) { | |
2964 | bufferlist& attrbl = out_attrs[kv.first]; | |
2965 | const string& val = kv.second; | |
2966 | attrbl.clear(); | |
2967 | attrbl.append(val.c_str(), val.size() + 1); | |
2968 | } | |
2969 | } | |
2970 | ||
2971 | ||
2972 | static int filter_out_quota_info(std::map<std::string, bufferlist>& add_attrs, | |
2973 | const std::set<std::string>& rmattr_names, | |
2974 | RGWQuotaInfo& quota, | |
2975 | bool * quota_extracted = nullptr) | |
2976 | { | |
2977 | bool extracted = false; | |
2978 | ||
2979 | /* Put new limit on max objects. */ | |
2980 | auto iter = add_attrs.find(RGW_ATTR_QUOTA_NOBJS); | |
2981 | std::string err; | |
2982 | if (std::end(add_attrs) != iter) { | |
2983 | quota.max_objects = | |
2984 | static_cast<int64_t>(strict_strtoll(iter->second.c_str(), 10, &err)); | |
2985 | if (!err.empty()) { | |
2986 | return -EINVAL; | |
2987 | } | |
2988 | add_attrs.erase(iter); | |
2989 | extracted = true; | |
2990 | } | |
2991 | ||
2992 | /* Put new limit on bucket (container) size. */ | |
2993 | iter = add_attrs.find(RGW_ATTR_QUOTA_MSIZE); | |
2994 | if (iter != add_attrs.end()) { | |
2995 | quota.max_size = | |
2996 | static_cast<int64_t>(strict_strtoll(iter->second.c_str(), 10, &err)); | |
2997 | if (!err.empty()) { | |
2998 | return -EINVAL; | |
2999 | } | |
3000 | add_attrs.erase(iter); | |
3001 | extracted = true; | |
3002 | } | |
3003 | ||
3004 | for (const auto& name : rmattr_names) { | |
3005 | /* Remove limit on max objects. */ | |
3006 | if (name.compare(RGW_ATTR_QUOTA_NOBJS) == 0) { | |
3007 | quota.max_objects = -1; | |
3008 | extracted = true; | |
3009 | } | |
3010 | ||
3011 | /* Remove limit on max bucket size. */ | |
3012 | if (name.compare(RGW_ATTR_QUOTA_MSIZE) == 0) { | |
3013 | quota.max_size = -1; | |
3014 | extracted = true; | |
3015 | } | |
3016 | } | |
3017 | ||
3018 | /* Swift requries checking on raw usage instead of the 4 KiB rounded one. */ | |
3019 | quota.check_on_raw = true; | |
3020 | quota.enabled = quota.max_size > 0 || quota.max_objects > 0; | |
3021 | ||
3022 | if (quota_extracted) { | |
3023 | *quota_extracted = extracted; | |
3024 | } | |
3025 | ||
3026 | return 0; | |
3027 | } | |
3028 | ||
3029 | ||
3030 | static void filter_out_website(std::map<std::string, ceph::bufferlist>& add_attrs, | |
3031 | const std::set<std::string>& rmattr_names, | |
3032 | RGWBucketWebsiteConf& ws_conf) | |
3033 | { | |
3034 | std::string lstval; | |
3035 | ||
3036 | /* Let's define a mapping between each custom attribute and the memory where | |
3037 | * attribute's value should be stored. The memory location is expressed by | |
3038 | * a non-const reference. */ | |
3039 | const auto mapping = { | |
3040 | std::make_pair(RGW_ATTR_WEB_INDEX, std::ref(ws_conf.index_doc_suffix)), | |
3041 | std::make_pair(RGW_ATTR_WEB_ERROR, std::ref(ws_conf.error_doc)), | |
3042 | std::make_pair(RGW_ATTR_WEB_LISTINGS, std::ref(lstval)), | |
3043 | std::make_pair(RGW_ATTR_WEB_LIST_CSS, std::ref(ws_conf.listing_css_doc)), | |
3044 | std::make_pair(RGW_ATTR_SUBDIR_MARKER, std::ref(ws_conf.subdir_marker)) | |
3045 | }; | |
3046 | ||
3047 | for (const auto& kv : mapping) { | |
3048 | const char * const key = kv.first; | |
3049 | auto& target = kv.second; | |
3050 | ||
3051 | auto iter = add_attrs.find(key); | |
3052 | ||
3053 | if (std::end(add_attrs) != iter) { | |
3054 | /* The "target" is a reference to ws_conf. */ | |
3055 | target = iter->second.c_str(); | |
3056 | add_attrs.erase(iter); | |
3057 | } | |
3058 | ||
3059 | if (rmattr_names.count(key)) { | |
3060 | target = std::string(); | |
3061 | } | |
3062 | } | |
3063 | ||
3064 | if (! lstval.empty()) { | |
3065 | ws_conf.listing_enabled = boost::algorithm::iequals(lstval, "true"); | |
3066 | } | |
3067 | } | |
3068 | ||
3069 | ||
f67539c2 | 3070 | void RGWCreateBucket::execute(optional_yield y) |
7c673cae | 3071 | { |
7c673cae FG |
3072 | buffer::list aclbl; |
3073 | buffer::list corsbl; | |
9f95a23c TL |
3074 | string bucket_name = rgw_make_bucket_entry_name(s->bucket_tenant, s->bucket_name); |
3075 | rgw_raw_obj obj(store->svc()->zone->get_zone_params().domain_root, bucket_name); | |
7c673cae | 3076 | |
f67539c2 | 3077 | op_ret = get_params(y); |
7c673cae FG |
3078 | if (op_ret < 0) |
3079 | return; | |
3080 | ||
11fdf7f2 TL |
3081 | if (!relaxed_region_enforcement && |
3082 | !location_constraint.empty() && | |
9f95a23c | 3083 | !store->svc()->zone->has_zonegroup_api(location_constraint)) { |
11fdf7f2 | 3084 | ldpp_dout(this, 0) << "location constraint (" << location_constraint << ")" |
31f18b77 FG |
3085 | << " can't be found." << dendl; |
3086 | op_ret = -ERR_INVALID_LOCATION_CONSTRAINT; | |
3087 | s->err.message = "The specified location-constraint is not valid"; | |
3088 | return; | |
3089 | } | |
3090 | ||
f67539c2 TL |
3091 | if (!relaxed_region_enforcement && !store->get_zonegroup().is_master_zonegroup() && !location_constraint.empty() && |
3092 | store->get_zonegroup().api_name != location_constraint) { | |
11fdf7f2 | 3093 | ldpp_dout(this, 0) << "location constraint (" << location_constraint << ")" |
f67539c2 | 3094 | << " doesn't match zonegroup" << " (" << store->get_zonegroup().api_name << ")" |
31f18b77 FG |
3095 | << dendl; |
3096 | op_ret = -ERR_INVALID_LOCATION_CONSTRAINT; | |
3097 | s->err.message = "The specified location-constraint is not valid"; | |
7c673cae FG |
3098 | return; |
3099 | } | |
3100 | ||
f67539c2 | 3101 | const auto& zonegroup = store->get_zonegroup(); |
11fdf7f2 TL |
3102 | if (!placement_rule.name.empty() && |
3103 | !zonegroup.placement_targets.count(placement_rule.name)) { | |
3104 | ldpp_dout(this, 0) << "placement target (" << placement_rule.name << ")" | |
c07f9fc5 | 3105 | << " doesn't exist in the placement targets of zonegroup" |
f67539c2 | 3106 | << " (" << store->get_zonegroup().api_name << ")" << dendl; |
c07f9fc5 FG |
3107 | op_ret = -ERR_INVALID_LOCATION_CONSTRAINT; |
3108 | s->err.message = "The specified placement target does not exist"; | |
3109 | return; | |
3110 | } | |
3111 | ||
7c673cae FG |
3112 | /* we need to make sure we read bucket info, it's not read before for this |
3113 | * specific request */ | |
b3b6e05e | 3114 | op_ret = store->get_bucket(this, s->user.get(), s->bucket_tenant, s->bucket_name, &s->bucket, y); |
7c673cae FG |
3115 | if (op_ret < 0 && op_ret != -ENOENT) |
3116 | return; | |
3117 | s->bucket_exists = (op_ret != -ENOENT); | |
3118 | ||
7c673cae | 3119 | if (s->bucket_exists) { |
f67539c2 TL |
3120 | if (!s->system_request && |
3121 | store->svc()->zone->get_zonegroup().get_id() != s->bucket->get_info().zonegroup) { | |
3122 | op_ret = -EEXIST; | |
7c673cae FG |
3123 | return; |
3124 | } | |
f67539c2 TL |
3125 | /* Initialize info from req_state */ |
3126 | info = s->bucket->get_info(); | |
7c673cae FG |
3127 | } |
3128 | ||
f67539c2 TL |
3129 | s->bucket_owner.set_id(s->user->get_id()); /* XXX dang use s->bucket->owner */ |
3130 | s->bucket_owner.set_name(s->user->get_display_name()); | |
3131 | ||
7c673cae FG |
3132 | string zonegroup_id; |
3133 | ||
3134 | if (s->system_request) { | |
3135 | zonegroup_id = s->info.args.get(RGW_SYS_PARAM_PREFIX "zonegroup"); | |
3136 | if (zonegroup_id.empty()) { | |
f67539c2 | 3137 | zonegroup_id = store->get_zonegroup().get_id(); |
7c673cae FG |
3138 | } |
3139 | } else { | |
f67539c2 | 3140 | zonegroup_id = store->get_zonegroup().get_id(); |
7c673cae FG |
3141 | } |
3142 | ||
3143 | /* Encode special metadata first as we're using std::map::emplace under | |
3144 | * the hood. This method will add the new items only if the map doesn't | |
3145 | * contain such keys yet. */ | |
3146 | policy.encode(aclbl); | |
3147 | emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); | |
3148 | ||
3149 | if (has_cors) { | |
3150 | cors_config.encode(corsbl); | |
3151 | emplace_attr(RGW_ATTR_CORS, std::move(corsbl)); | |
3152 | } | |
3153 | ||
3154 | RGWQuotaInfo quota_info; | |
3155 | const RGWQuotaInfo * pquota_info = nullptr; | |
3156 | if (need_metadata_upload()) { | |
3157 | /* It's supposed that following functions WILL NOT change any special | |
3158 | * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */ | |
b3b6e05e | 3159 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs, false); |
3efd9988 FG |
3160 | if (op_ret < 0) { |
3161 | return; | |
3162 | } | |
7c673cae FG |
3163 | prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); |
3164 | populate_with_generic_attrs(s, attrs); | |
3165 | ||
3166 | op_ret = filter_out_quota_info(attrs, rmattr_names, quota_info); | |
3167 | if (op_ret < 0) { | |
3168 | return; | |
3169 | } else { | |
3170 | pquota_info = "a_info; | |
3171 | } | |
3172 | ||
3173 | /* Web site of Swift API. */ | |
f67539c2 TL |
3174 | filter_out_website(attrs, rmattr_names, info.website_conf); |
3175 | info.has_website = !info.website_conf.is_empty(); | |
7c673cae FG |
3176 | } |
3177 | ||
f67539c2 TL |
3178 | rgw_bucket tmp_bucket; |
3179 | tmp_bucket.tenant = s->bucket_tenant; /* ignored if bucket exists */ | |
3180 | tmp_bucket.name = s->bucket_name; | |
7c673cae FG |
3181 | |
3182 | /* Handle updates of the metadata for Swift's object versioning. */ | |
3183 | if (swift_ver_location) { | |
f67539c2 TL |
3184 | info.swift_ver_location = *swift_ver_location; |
3185 | info.swift_versioning = (! swift_ver_location->empty()); | |
eafe8130 TL |
3186 | } |
3187 | ||
f67539c2 TL |
3188 | /* We're replacing bucket with the newly created one */ |
3189 | ldpp_dout(this, 10) << "user=" << s->user << " bucket=" << tmp_bucket << dendl; | |
b3b6e05e | 3190 | op_ret = store->create_bucket(this, *s->user, tmp_bucket, zonegroup_id, |
f67539c2 TL |
3191 | placement_rule, |
3192 | info.swift_ver_location, | |
3193 | pquota_info, policy, attrs, info, ep_objv, | |
3194 | true, obj_lock_enabled, &s->bucket_exists, s->info, | |
3195 | &s->bucket, y); | |
7c673cae | 3196 | |
7c673cae FG |
3197 | /* continue if EEXIST and create_bucket will fail below. this way we can |
3198 | * recover from a partial create by retrying it. */ | |
f67539c2 | 3199 | ldpp_dout(this, 20) << "rgw_create_bucket returned ret=" << op_ret << " bucket=" << s->bucket.get() << dendl; |
7c673cae | 3200 | |
f67539c2 | 3201 | if (op_ret) |
7c673cae FG |
3202 | return; |
3203 | ||
f67539c2 | 3204 | const bool existed = s->bucket_exists; |
7c673cae FG |
3205 | if (existed) { |
3206 | /* bucket already existed, might have raced with another bucket creation, or | |
3207 | * might be partial bucket creation that never completed. Read existing bucket | |
3208 | * info, verify that the reported bucket owner is the current user. | |
3209 | * If all is ok then update the user's list of buckets. | |
3210 | * Otherwise inform client about a name conflict. | |
3211 | */ | |
f67539c2 | 3212 | if (s->bucket->get_info().owner.compare(s->user->get_id()) != 0) { |
7c673cae FG |
3213 | op_ret = -EEXIST; |
3214 | return; | |
3215 | } | |
7c673cae FG |
3216 | } |
3217 | ||
f67539c2 | 3218 | op_ret = store->ctl()->bucket->link_bucket(s->user->get_id(), s->bucket->get_key(), |
b3b6e05e | 3219 | s->bucket->get_creation_time(), y, s, false); |
7c673cae FG |
3220 | if (op_ret && !existed && op_ret != -EEXIST) { |
3221 | /* if it exists (or previously existed), don't remove it! */ | |
b3b6e05e | 3222 | op_ret = store->ctl()->bucket->unlink_bucket(s->user->get_id(), s->bucket->get_key(), y, this); |
7c673cae | 3223 | if (op_ret < 0) { |
11fdf7f2 | 3224 | ldpp_dout(this, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret |
7c673cae FG |
3225 | << dendl; |
3226 | } | |
3227 | } else if (op_ret == -EEXIST || (op_ret == 0 && existed)) { | |
3228 | op_ret = -ERR_BUCKET_EXISTS; | |
3229 | } | |
3230 | ||
3231 | if (need_metadata_upload() && existed) { | |
3232 | /* OK, it looks we lost race with another request. As it's required to | |
3233 | * handle metadata fusion and upload, the whole operation becomes very | |
3234 | * similar in nature to PutMetadataBucket. However, as the attrs may | |
3235 | * changed in the meantime, we have to refresh. */ | |
3236 | short tries = 0; | |
3237 | do { | |
7c673cae FG |
3238 | map<string, bufferlist> battrs; |
3239 | ||
b3b6e05e | 3240 | op_ret = s->bucket->get_bucket_info(this, y); |
7c673cae FG |
3241 | if (op_ret < 0) { |
3242 | return; | |
f67539c2 | 3243 | } else if (!s->bucket->is_owner(s->user.get())) { |
7c673cae FG |
3244 | /* New bucket doesn't belong to the account we're operating on. */ |
3245 | op_ret = -EEXIST; | |
3246 | return; | |
3247 | } else { | |
f67539c2 | 3248 | s->bucket_attrs = s->bucket->get_attrs(); |
7c673cae FG |
3249 | } |
3250 | ||
3251 | attrs.clear(); | |
3252 | ||
b3b6e05e | 3253 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs, false); |
3efd9988 FG |
3254 | if (op_ret < 0) { |
3255 | return; | |
3256 | } | |
7c673cae FG |
3257 | prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); |
3258 | populate_with_generic_attrs(s, attrs); | |
f67539c2 | 3259 | op_ret = filter_out_quota_info(attrs, rmattr_names, s->bucket->get_info().quota); |
7c673cae FG |
3260 | if (op_ret < 0) { |
3261 | return; | |
3262 | } | |
3263 | ||
3264 | /* Handle updates of the metadata for Swift's object versioning. */ | |
3265 | if (swift_ver_location) { | |
f67539c2 TL |
3266 | s->bucket->get_info().swift_ver_location = *swift_ver_location; |
3267 | s->bucket->get_info().swift_versioning = (! swift_ver_location->empty()); | |
7c673cae FG |
3268 | } |
3269 | ||
3270 | /* Web site of Swift API. */ | |
f67539c2 TL |
3271 | filter_out_website(attrs, rmattr_names, s->bucket->get_info().website_conf); |
3272 | s->bucket->get_info().has_website = !s->bucket->get_info().website_conf.is_empty(); | |
7c673cae FG |
3273 | |
3274 | /* This will also set the quota on the bucket. */ | |
f67539c2 TL |
3275 | op_ret = store->ctl()->bucket->set_bucket_instance_attrs(s->bucket->get_info(), attrs, |
3276 | &s->bucket->get_info().objv_tracker, | |
b3b6e05e | 3277 | y, this); |
7c673cae FG |
3278 | } while (op_ret == -ECANCELED && tries++ < 20); |
3279 | ||
3280 | /* Restore the proper return code. */ | |
3281 | if (op_ret >= 0) { | |
3282 | op_ret = -ERR_BUCKET_EXISTS; | |
3283 | } | |
3284 | } | |
3285 | } | |
3286 | ||
f67539c2 | 3287 | int RGWDeleteBucket::verify_permission(optional_yield y) |
7c673cae | 3288 | { |
11fdf7f2 | 3289 | if (!verify_bucket_permission(this, s, rgw::IAM::s3DeleteBucket)) { |
7c673cae FG |
3290 | return -EACCES; |
3291 | } | |
3292 | ||
3293 | return 0; | |
3294 | } | |
3295 | ||
3296 | void RGWDeleteBucket::pre_exec() | |
3297 | { | |
3298 | rgw_bucket_object_pre_exec(s); | |
3299 | } | |
3300 | ||
f67539c2 | 3301 | void RGWDeleteBucket::execute(optional_yield y) |
7c673cae | 3302 | { |
11fdf7f2 TL |
3303 | if (s->bucket_name.empty()) { |
3304 | op_ret = -EINVAL; | |
7c673cae | 3305 | return; |
11fdf7f2 | 3306 | } |
7c673cae FG |
3307 | |
3308 | if (!s->bucket_exists) { | |
11fdf7f2 | 3309 | ldpp_dout(this, 0) << "ERROR: bucket " << s->bucket_name << " not found" << dendl; |
7c673cae FG |
3310 | op_ret = -ERR_NO_SUCH_BUCKET; |
3311 | return; | |
3312 | } | |
3313 | RGWObjVersionTracker ot; | |
f67539c2 | 3314 | ot.read_version = s->bucket->get_version(); |
7c673cae FG |
3315 | |
3316 | if (s->system_request) { | |
3317 | string tag = s->info.args.get(RGW_SYS_PARAM_PREFIX "tag"); | |
3318 | string ver_str = s->info.args.get(RGW_SYS_PARAM_PREFIX "ver"); | |
3319 | if (!tag.empty()) { | |
3320 | ot.read_version.tag = tag; | |
3321 | uint64_t ver; | |
3322 | string err; | |
3323 | ver = strict_strtol(ver_str.c_str(), 10, &err); | |
3324 | if (!err.empty()) { | |
11fdf7f2 | 3325 | ldpp_dout(this, 0) << "failed to parse ver param" << dendl; |
7c673cae FG |
3326 | op_ret = -EINVAL; |
3327 | return; | |
3328 | } | |
3329 | ot.read_version.ver = ver; | |
3330 | } | |
3331 | } | |
3332 | ||
b3b6e05e | 3333 | op_ret = s->bucket->sync_user_stats(this, y); |
7c673cae | 3334 | if ( op_ret < 0) { |
11fdf7f2 | 3335 | ldpp_dout(this, 1) << "WARNING: failed to sync user stats before bucket delete: op_ret= " << op_ret << dendl; |
7c673cae | 3336 | } |
f67539c2 | 3337 | |
b3b6e05e | 3338 | op_ret = s->bucket->check_empty(this, y); |
7c673cae FG |
3339 | if (op_ret < 0) { |
3340 | return; | |
3341 | } | |
3342 | ||
f67539c2 | 3343 | bufferlist in_data; |
b3b6e05e | 3344 | op_ret = store->forward_request_to_master(this, s->user.get(), &ot.read_version, in_data, nullptr, s->info, y); |
f67539c2 TL |
3345 | if (op_ret < 0) { |
3346 | if (op_ret == -ENOENT) { | |
3347 | /* adjust error, we want to return with NoSuchBucket and not | |
3348 | * NoSuchKey */ | |
3349 | op_ret = -ERR_NO_SUCH_BUCKET; | |
7c673cae | 3350 | } |
f67539c2 | 3351 | return; |
7c673cae FG |
3352 | } |
3353 | ||
224ce89b WB |
3354 | string prefix, delimiter; |
3355 | ||
3356 | if (s->prot_flags & RGW_REST_SWIFT) { | |
3357 | string path_args; | |
3358 | path_args = s->info.args.get("path"); | |
3359 | if (!path_args.empty()) { | |
3360 | if (!delimiter.empty() || !prefix.empty()) { | |
3361 | op_ret = -EINVAL; | |
3362 | return; | |
3363 | } | |
3364 | prefix = path_args; | |
3365 | delimiter="/"; | |
3366 | } | |
3367 | } | |
3368 | ||
b3b6e05e | 3369 | op_ret = s->bucket->remove_bucket(this, false, prefix, delimiter, false, nullptr, y); |
f67539c2 TL |
3370 | if (op_ret < 0 && op_ret == -ECANCELED) { |
3371 | // lost a race, either with mdlog sync or another delete bucket operation. | |
3372 | // in either case, we've already called ctl.bucket->unlink_bucket() | |
3373 | op_ret = 0; | |
224ce89b | 3374 | } |
f67539c2 TL |
3375 | return; |
3376 | } | |
224ce89b | 3377 | |
f67539c2 TL |
3378 | int RGWPutObj::init_processing(optional_yield y) { |
3379 | copy_source = url_decode(s->info.env->get("HTTP_X_AMZ_COPY_SOURCE", "")); | |
3380 | copy_source_range = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE_RANGE"); | |
3381 | size_t pos; | |
3382 | int ret; | |
3383 | ||
3384 | /* handle x-amz-copy-source */ | |
3385 | std::string_view cs_view(copy_source); | |
3386 | if (! cs_view.empty()) { | |
3387 | if (cs_view[0] == '/') | |
3388 | cs_view.remove_prefix(1); | |
3389 | copy_source_bucket_name = std::string(cs_view); | |
3390 | pos = copy_source_bucket_name.find("/"); | |
3391 | if (pos == std::string::npos) { | |
3392 | ret = -EINVAL; | |
3393 | ldpp_dout(this, 5) << "x-amz-copy-source bad format" << dendl; | |
3394 | return ret; | |
3395 | } | |
3396 | copy_source_object_name = | |
3397 | copy_source_bucket_name.substr(pos + 1, copy_source_bucket_name.size()); | |
3398 | copy_source_bucket_name = copy_source_bucket_name.substr(0, pos); | |
3399 | #define VERSION_ID_STR "?versionId=" | |
3400 | pos = copy_source_object_name.find(VERSION_ID_STR); | |
3401 | if (pos == std::string::npos) { | |
3402 | copy_source_object_name = url_decode(copy_source_object_name); | |
3403 | } else { | |
3404 | copy_source_version_id = | |
3405 | copy_source_object_name.substr(pos + sizeof(VERSION_ID_STR) - 1); | |
3406 | copy_source_object_name = | |
3407 | url_decode(copy_source_object_name.substr(0, pos)); | |
3408 | } | |
3409 | pos = copy_source_bucket_name.find(":"); | |
3410 | if (pos == std::string::npos) { | |
3411 | // if tenant is not specified in x-amz-copy-source, use tenant of the requester | |
3412 | copy_source_tenant_name = s->user->get_tenant(); | |
3413 | } else { | |
3414 | copy_source_tenant_name = copy_source_bucket_name.substr(0, pos); | |
3415 | copy_source_bucket_name = copy_source_bucket_name.substr(pos + 1, copy_source_bucket_name.size()); | |
3416 | if (copy_source_bucket_name.empty()) { | |
3417 | ret = -EINVAL; | |
3418 | ldpp_dout(this, 5) << "source bucket name is empty" << dendl; | |
3419 | return ret; | |
3420 | } | |
3421 | } | |
3422 | std::unique_ptr<rgw::sal::RGWBucket> bucket; | |
b3b6e05e | 3423 | ret = store->get_bucket(this, s->user.get(), copy_source_tenant_name, copy_source_bucket_name, |
f67539c2 TL |
3424 | &bucket, y); |
3425 | if (ret < 0) { | |
3426 | ldpp_dout(this, 5) << __func__ << "(): get_bucket() returned ret=" << ret << dendl; | |
3427 | return ret; | |
3428 | } | |
7c673cae | 3429 | |
b3b6e05e | 3430 | ret = bucket->get_bucket_info(this, y); |
f67539c2 TL |
3431 | if (ret < 0) { |
3432 | ldpp_dout(this, 5) << __func__ << "(): get_bucket_info() returned ret=" << ret << dendl; | |
3433 | return ret; | |
3434 | } | |
3435 | copy_source_bucket_info = bucket->get_info(); | |
7c673cae | 3436 | |
f67539c2 TL |
3437 | /* handle x-amz-copy-source-range */ |
3438 | if (copy_source_range) { | |
3439 | string range = copy_source_range; | |
3440 | pos = range.find("bytes="); | |
3441 | if (pos == std::string::npos || pos != 0) { | |
3442 | ret = -EINVAL; | |
3443 | ldpp_dout(this, 5) << "x-amz-copy-source-range bad format" << dendl; | |
3444 | return ret; | |
3445 | } | |
3446 | /* 6 is the length of "bytes=" */ | |
3447 | range = range.substr(pos + 6); | |
3448 | pos = range.find("-"); | |
3449 | if (pos == std::string::npos) { | |
3450 | ret = -EINVAL; | |
3451 | ldpp_dout(this, 5) << "x-amz-copy-source-range bad format" << dendl; | |
3452 | return ret; | |
3453 | } | |
3454 | string first = range.substr(0, pos); | |
3455 | string last = range.substr(pos + 1); | |
3456 | if (first.find_first_not_of("0123456789") != std::string::npos || | |
3457 | last.find_first_not_of("0123456789") != std::string::npos) { | |
3458 | ldpp_dout(this, 5) << "x-amz-copy-source-range bad format not an integer" << dendl; | |
3459 | ret = -EINVAL; | |
3460 | return ret; | |
3461 | } | |
3462 | copy_source_range_fst = strtoull(first.c_str(), NULL, 10); | |
3463 | copy_source_range_lst = strtoull(last.c_str(), NULL, 10); | |
3464 | if (copy_source_range_fst > copy_source_range_lst) { | |
3465 | ret = -ERANGE; | |
3466 | ldpp_dout(this, 5) << "x-amz-copy-source-range bad format first number bigger than second" << dendl; | |
3467 | return ret; | |
3468 | } | |
7c673cae | 3469 | } |
f67539c2 TL |
3470 | |
3471 | } /* copy_source */ | |
3472 | return RGWOp::init_processing(y); | |
7c673cae FG |
3473 | } |
3474 | ||
f67539c2 | 3475 | int RGWPutObj::verify_permission(optional_yield y) |
7c673cae | 3476 | { |
3a9019d9 | 3477 | if (! copy_source.empty()) { |
7c673cae | 3478 | |
31f18b77 | 3479 | RGWAccessControlPolicy cs_acl(s->cct); |
11fdf7f2 | 3480 | boost::optional<Policy> policy; |
7c673cae | 3481 | map<string, bufferlist> cs_attrs; |
f67539c2 TL |
3482 | std::unique_ptr<rgw::sal::RGWBucket> cs_bucket; |
3483 | int ret = store->get_bucket(NULL, copy_source_bucket_info, &cs_bucket); | |
3484 | if (ret < 0) | |
3485 | return ret; | |
3486 | ||
3487 | std::unique_ptr<rgw::sal::RGWObject> cs_object = | |
3488 | cs_bucket->get_object(rgw_obj_key(copy_source_object_name, copy_source_version_id)); | |
7c673cae | 3489 | |
f67539c2 TL |
3490 | cs_object->set_atomic(s->obj_ctx); |
3491 | cs_object->set_prefetch_data(s->obj_ctx); | |
7c673cae FG |
3492 | |
3493 | /* check source object permissions */ | |
b3b6e05e | 3494 | if (read_obj_policy(this, store, s, copy_source_bucket_info, cs_attrs, &cs_acl, nullptr, |
f67539c2 | 3495 | policy, cs_bucket.get(), cs_object.get(), y, true) < 0) { |
7c673cae FG |
3496 | return -EACCES; |
3497 | } | |
3498 | ||
3499 | /* admin request overrides permission checks */ | |
31f18b77 | 3500 | if (! s->auth.identity->is_admin_of(cs_acl.get_owner().get_id())) { |
11fdf7f2 TL |
3501 | if (policy || ! s->iam_user_policies.empty()) { |
3502 | auto usr_policy_res = Effect::Pass; | |
3503 | for (auto& user_policy : s->iam_user_policies) { | |
3504 | if (usr_policy_res = user_policy.eval(s->env, *s->auth.identity, | |
f67539c2 | 3505 | cs_object->get_instance().empty() ? |
11fdf7f2 TL |
3506 | rgw::IAM::s3GetObject : |
3507 | rgw::IAM::s3GetObjectVersion, | |
f67539c2 | 3508 | rgw::ARN(cs_object->get_obj())); usr_policy_res == Effect::Deny) |
11fdf7f2 TL |
3509 | return -EACCES; |
3510 | else if (usr_policy_res == Effect::Allow) | |
3511 | break; | |
3512 | } | |
3513 | rgw::IAM::Effect e = Effect::Pass; | |
3514 | if (policy) { | |
3515 | e = policy->eval(s->env, *s->auth.identity, | |
f67539c2 | 3516 | cs_object->get_instance().empty() ? |
31f18b77 FG |
3517 | rgw::IAM::s3GetObject : |
3518 | rgw::IAM::s3GetObjectVersion, | |
f67539c2 | 3519 | rgw::ARN(cs_object->get_obj())); |
11fdf7f2 | 3520 | } |
31f18b77 FG |
3521 | if (e == Effect::Deny) { |
3522 | return -EACCES; | |
11fdf7f2 TL |
3523 | } else if (usr_policy_res == Effect::Pass && e == Effect::Pass && |
3524 | !cs_acl.verify_permission(this, *s->auth.identity, s->perm_mask, | |
31f18b77 FG |
3525 | RGW_PERM_READ)) { |
3526 | return -EACCES; | |
3527 | } | |
11fdf7f2 | 3528 | } else if (!cs_acl.verify_permission(this, *s->auth.identity, s->perm_mask, |
31f18b77 FG |
3529 | RGW_PERM_READ)) { |
3530 | return -EACCES; | |
3531 | } | |
7c673cae | 3532 | } |
31f18b77 | 3533 | } |
7c673cae | 3534 | |
9f95a23c TL |
3535 | if (s->bucket_access_conf && s->bucket_access_conf->block_public_acls()) { |
3536 | if (s->canned_acl.compare("public-read") || | |
3537 | s->canned_acl.compare("public-read-write") || | |
3538 | s->canned_acl.compare("authenticated-read")) | |
3539 | return -EACCES; | |
3540 | } | |
3541 | ||
f67539c2 | 3542 | auto op_ret = get_params(y); |
11fdf7f2 TL |
3543 | if (op_ret < 0) { |
3544 | ldpp_dout(this, 20) << "get_params() returned ret=" << op_ret << dendl; | |
3545 | return op_ret; | |
7c673cae FG |
3546 | } |
3547 | ||
11fdf7f2 TL |
3548 | if (s->iam_policy || ! s->iam_user_policies.empty()) { |
3549 | rgw_add_grant_to_iam_environment(s->env, s); | |
7c673cae | 3550 | |
11fdf7f2 | 3551 | rgw_add_to_iam_environment(s->env, "s3:x-amz-acl", s->canned_acl); |
7c673cae | 3552 | |
11fdf7f2 TL |
3553 | if (obj_tags != nullptr && obj_tags->count() > 0){ |
3554 | auto tags = obj_tags->get_tags(); | |
3555 | for (const auto& kv: tags){ | |
3556 | rgw_add_to_iam_environment(s->env, "s3:RequestObjectTag/"+kv.first, kv.second); | |
3557 | } | |
7c673cae | 3558 | } |
7c673cae | 3559 | |
11fdf7f2 TL |
3560 | constexpr auto encrypt_attr = "x-amz-server-side-encryption"; |
3561 | constexpr auto s3_encrypt_attr = "s3:x-amz-server-side-encryption"; | |
3562 | auto enc_header = s->info.x_meta_map.find(encrypt_attr); | |
3563 | if (enc_header != s->info.x_meta_map.end()){ | |
3564 | rgw_add_to_iam_environment(s->env, s3_encrypt_attr, enc_header->second); | |
3565 | } | |
7c673cae | 3566 | |
11fdf7f2 TL |
3567 | constexpr auto kms_attr = "x-amz-server-side-encryption-aws-kms-key-id"; |
3568 | constexpr auto s3_kms_attr = "s3:x-amz-server-side-encryption-aws-kms-key-id"; | |
3569 | auto kms_header = s->info.x_meta_map.find(kms_attr); | |
3570 | if (kms_header != s->info.x_meta_map.end()){ | |
3571 | rgw_add_to_iam_environment(s->env, s3_kms_attr, kms_header->second); | |
3572 | } | |
7c673cae | 3573 | |
f67539c2 TL |
3574 | /* Object needs a bucket from this point */ |
3575 | s->object->set_bucket(s->bucket.get()); | |
3576 | ||
522d829b | 3577 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, |
11fdf7f2 TL |
3578 | boost::none, |
3579 | rgw::IAM::s3PutObject, | |
f67539c2 | 3580 | s->object->get_obj()); |
522d829b | 3581 | if (identity_policy_res == Effect::Deny) |
11fdf7f2 | 3582 | return -EACCES; |
7c673cae | 3583 | |
11fdf7f2 | 3584 | rgw::IAM::Effect e = Effect::Pass; |
522d829b | 3585 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
3586 | if (s->iam_policy) { |
3587 | e = s->iam_policy->eval(s->env, *s->auth.identity, | |
3588 | rgw::IAM::s3PutObject, | |
522d829b TL |
3589 | s->object->get_obj(), |
3590 | princ_type); | |
11fdf7f2 | 3591 | } |
522d829b TL |
3592 | if (e == Effect::Deny) { |
3593 | return -EACCES; | |
3594 | } | |
3595 | ||
3596 | if (!s->session_policies.empty()) { | |
3597 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
3598 | boost::none, | |
3599 | rgw::IAM::s3PutObject, | |
3600 | s->object->get_obj()); | |
3601 | if (session_policy_res == Effect::Deny) { | |
3602 | return -EACCES; | |
3603 | } | |
3604 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
3605 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
3606 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
3607 | (session_policy_res == Effect::Allow && e == Effect::Allow)) | |
3608 | return 0; | |
3609 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
3610 | //Intersection of session policy and identity policy plus bucket policy | |
3611 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || e == Effect::Allow) | |
3612 | return 0; | |
3613 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
3614 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) | |
3615 | return 0; | |
3616 | } | |
11fdf7f2 | 3617 | return -EACCES; |
522d829b TL |
3618 | } |
3619 | if (e == Effect::Allow || identity_policy_res == Effect::Allow) { | |
11fdf7f2 TL |
3620 | return 0; |
3621 | } | |
7c673cae FG |
3622 | } |
3623 | ||
11fdf7f2 TL |
3624 | if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
3625 | return -EACCES; | |
7c673cae FG |
3626 | } |
3627 | ||
11fdf7f2 | 3628 | return 0; |
7c673cae FG |
3629 | } |
3630 | ||
7c673cae FG |
3631 | |
3632 | void RGWPutObj::pre_exec() | |
3633 | { | |
3634 | rgw_bucket_object_pre_exec(s); | |
3635 | } | |
3636 | ||
11fdf7f2 | 3637 | class RGWPutObj_CB : public RGWGetObj_Filter |
7c673cae FG |
3638 | { |
3639 | RGWPutObj *op; | |
3640 | public: | |
11fdf7f2 | 3641 | explicit RGWPutObj_CB(RGWPutObj *_op) : op(_op) {} |
7c673cae FG |
3642 | ~RGWPutObj_CB() override {} |
3643 | ||
3644 | int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) override { | |
3645 | return op->get_data_cb(bl, bl_ofs, bl_len); | |
3646 | } | |
3647 | }; | |
3648 | ||
3649 | int RGWPutObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len) | |
3650 | { | |
3651 | bufferlist bl_tmp; | |
9f95a23c | 3652 | bl.begin(bl_ofs).copy(bl_len, bl_tmp); |
7c673cae FG |
3653 | |
3654 | bl_aux.append(bl_tmp); | |
3655 | ||
3656 | return bl_len; | |
3657 | } | |
3658 | ||
3659 | int RGWPutObj::get_data(const off_t fst, const off_t lst, bufferlist& bl) | |
3660 | { | |
3661 | RGWPutObj_CB cb(this); | |
11fdf7f2 | 3662 | RGWGetObj_Filter* filter = &cb; |
7c673cae | 3663 | boost::optional<RGWGetObj_Decompress> decompress; |
11fdf7f2 | 3664 | std::unique_ptr<RGWGetObj_Filter> decrypt; |
7c673cae FG |
3665 | RGWCompressionInfo cs_info; |
3666 | map<string, bufferlist> attrs; | |
7c673cae FG |
3667 | int ret = 0; |
3668 | ||
3669 | uint64_t obj_size; | |
3670 | int64_t new_ofs, new_end; | |
3671 | ||
3672 | new_ofs = fst; | |
3673 | new_end = lst; | |
3674 | ||
f67539c2 TL |
3675 | std::unique_ptr<rgw::sal::RGWBucket> bucket; |
3676 | ret = store->get_bucket(nullptr, copy_source_bucket_info, &bucket); | |
3677 | if (ret < 0) | |
3678 | return ret; | |
7c673cae | 3679 | |
f67539c2 TL |
3680 | std::unique_ptr<rgw::sal::RGWObject> obj = bucket->get_object(rgw_obj_key(copy_source_object_name, copy_source_version_id)); |
3681 | std::unique_ptr<rgw::sal::RGWObject::ReadOp> read_op(obj->get_read_op(s->obj_ctx)); | |
7c673cae | 3682 | |
b3b6e05e | 3683 | ret = read_op->prepare(s->yield, this); |
7c673cae FG |
3684 | if (ret < 0) |
3685 | return ret; | |
3686 | ||
f67539c2 TL |
3687 | obj_size = obj->get_obj_size(); |
3688 | ||
7c673cae | 3689 | bool need_decompress; |
f67539c2 | 3690 | op_ret = rgw_compression_info_from_attrset(obj->get_attrs(), need_decompress, cs_info); |
7c673cae | 3691 | if (op_ret < 0) { |
b3b6e05e | 3692 | ldpp_dout(this, 0) << "ERROR: failed to decode compression info" << dendl; |
11fdf7f2 | 3693 | return -EIO; |
7c673cae FG |
3694 | } |
3695 | ||
3696 | bool partial_content = true; | |
3697 | if (need_decompress) | |
3698 | { | |
3699 | obj_size = cs_info.orig_size; | |
3700 | decompress.emplace(s->cct, &cs_info, partial_content, filter); | |
3701 | filter = &*decompress; | |
3702 | } | |
3703 | ||
f67539c2 | 3704 | auto attr_iter = obj->get_attrs().find(RGW_ATTR_MANIFEST); |
7c673cae FG |
3705 | op_ret = this->get_decrypt_filter(&decrypt, |
3706 | filter, | |
f67539c2 TL |
3707 | obj->get_attrs(), |
3708 | attr_iter != obj->get_attrs().end() ? &(attr_iter->second) : nullptr); | |
7c673cae FG |
3709 | if (decrypt != nullptr) { |
3710 | filter = decrypt.get(); | |
3711 | } | |
3712 | if (op_ret < 0) { | |
f67539c2 | 3713 | return op_ret; |
7c673cae FG |
3714 | } |
3715 | ||
f67539c2 | 3716 | ret = obj->range_to_ofs(obj_size, new_ofs, new_end); |
7c673cae FG |
3717 | if (ret < 0) |
3718 | return ret; | |
3719 | ||
3720 | filter->fixup_range(new_ofs, new_end); | |
b3b6e05e | 3721 | ret = read_op->iterate(this, new_ofs, new_end, filter, s->yield); |
7c673cae FG |
3722 | |
3723 | if (ret >= 0) | |
3724 | ret = filter->flush(); | |
3725 | ||
3726 | bl.claim_append(bl_aux); | |
3727 | ||
3728 | return ret; | |
3729 | } | |
3730 | ||
3731 | // special handling for compression type = "random" with multipart uploads | |
3732 | static CompressorRef get_compressor_plugin(const req_state *s, | |
3733 | const std::string& compression_type) | |
3734 | { | |
3735 | if (compression_type != "random") { | |
3736 | return Compressor::create(s->cct, compression_type); | |
3737 | } | |
3738 | ||
3739 | bool is_multipart{false}; | |
3740 | const auto& upload_id = s->info.args.get("uploadId", &is_multipart); | |
3741 | ||
3742 | if (!is_multipart) { | |
3743 | return Compressor::create(s->cct, compression_type); | |
3744 | } | |
3745 | ||
3746 | // use a hash of the multipart upload id so all parts use the same plugin | |
3747 | const auto alg = std::hash<std::string>{}(upload_id) % Compressor::COMP_ALG_LAST; | |
3748 | if (alg == Compressor::COMP_ALG_NONE) { | |
3749 | return nullptr; | |
3750 | } | |
3751 | return Compressor::create(s->cct, alg); | |
3752 | } | |
3753 | ||
f67539c2 | 3754 | void RGWPutObj::execute(optional_yield y) |
7c673cae | 3755 | { |
7c673cae FG |
3756 | char supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1]; |
3757 | char supplied_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; | |
3758 | char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; | |
3759 | unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE]; | |
3760 | MD5 hash; | |
3761 | bufferlist bl, aclbl, bs; | |
3762 | int len; | |
7c673cae FG |
3763 | |
3764 | off_t fst; | |
3765 | off_t lst; | |
7c673cae FG |
3766 | |
3767 | bool need_calc_md5 = (dlo_manifest == NULL) && (slo_info == NULL); | |
3768 | perfcounter->inc(l_rgw_put); | |
11fdf7f2 TL |
3769 | // report latency on return |
3770 | auto put_lat = make_scope_guard([&] { | |
3771 | perfcounter->tinc(l_rgw_put_lat, s->time_elapsed()); | |
3772 | }); | |
3773 | ||
7c673cae | 3774 | op_ret = -EINVAL; |
f67539c2 | 3775 | if (rgw::sal::RGWObject::empty(s->object.get())) { |
11fdf7f2 | 3776 | return; |
7c673cae FG |
3777 | } |
3778 | ||
3779 | if (!s->bucket_exists) { | |
3780 | op_ret = -ERR_NO_SUCH_BUCKET; | |
3781 | return; | |
3782 | } | |
3783 | ||
f67539c2 TL |
3784 | /* Object needs a bucket from this point */ |
3785 | s->object->set_bucket(s->bucket.get()); | |
7c673cae FG |
3786 | |
3787 | op_ret = get_system_versioning_params(s, &olh_epoch, &version_id); | |
3788 | if (op_ret < 0) { | |
11fdf7f2 | 3789 | ldpp_dout(this, 20) << "get_system_versioning_params() returned ret=" |
7c673cae | 3790 | << op_ret << dendl; |
11fdf7f2 | 3791 | return; |
7c673cae FG |
3792 | } |
3793 | ||
3794 | if (supplied_md5_b64) { | |
3795 | need_calc_md5 = true; | |
3796 | ||
11fdf7f2 | 3797 | ldpp_dout(this, 15) << "supplied_md5_b64=" << supplied_md5_b64 << dendl; |
7c673cae FG |
3798 | op_ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1], |
3799 | supplied_md5_b64, supplied_md5_b64 + strlen(supplied_md5_b64)); | |
11fdf7f2 | 3800 | ldpp_dout(this, 15) << "ceph_armor ret=" << op_ret << dendl; |
7c673cae FG |
3801 | if (op_ret != CEPH_CRYPTO_MD5_DIGESTSIZE) { |
3802 | op_ret = -ERR_INVALID_DIGEST; | |
11fdf7f2 | 3803 | return; |
7c673cae FG |
3804 | } |
3805 | ||
3806 | buf_to_hex((const unsigned char *)supplied_md5_bin, CEPH_CRYPTO_MD5_DIGESTSIZE, supplied_md5); | |
11fdf7f2 | 3807 | ldpp_dout(this, 15) << "supplied_md5=" << supplied_md5 << dendl; |
7c673cae FG |
3808 | } |
3809 | ||
3810 | if (!chunked_upload) { /* with chunked upload we don't know how big is the upload. | |
3811 | we also check sizes at the end anyway */ | |
f67539c2 | 3812 | op_ret = s->bucket->check_quota(user_quota, bucket_quota, s->content_length, y); |
7c673cae | 3813 | if (op_ret < 0) { |
11fdf7f2 TL |
3814 | ldpp_dout(this, 20) << "check_quota() returned ret=" << op_ret << dendl; |
3815 | return; | |
7c673cae FG |
3816 | } |
3817 | } | |
3818 | ||
3819 | if (supplied_etag) { | |
3820 | strncpy(supplied_md5, supplied_etag, sizeof(supplied_md5) - 1); | |
3821 | supplied_md5[sizeof(supplied_md5) - 1] = '\0'; | |
3822 | } | |
3823 | ||
11fdf7f2 TL |
3824 | const bool multipart = !multipart_upload_id.empty(); |
3825 | auto& obj_ctx = *static_cast<RGWObjectCtx*>(s->obj_ctx); | |
7c673cae FG |
3826 | |
3827 | /* Handle object versioning of Swift API. */ | |
3828 | if (! multipart) { | |
f67539c2 | 3829 | op_ret = s->object->swift_versioning_copy(s->obj_ctx, this, s->yield); |
7c673cae | 3830 | if (op_ret < 0) { |
11fdf7f2 | 3831 | return; |
7c673cae FG |
3832 | } |
3833 | } | |
3834 | ||
f67539c2 | 3835 | // make reservation for notification if needed |
b3b6e05e | 3836 | rgw::notify::reservation_t res(this, store, s, s->object.get()); |
f67539c2 | 3837 | const auto event_type = rgw::notify::ObjectCreatedPut; |
b3b6e05e | 3838 | op_ret = rgw::notify::publish_reserve(this, event_type, res, obj_tags.get()); |
f67539c2 TL |
3839 | if (op_ret < 0) { |
3840 | return; | |
3841 | } | |
3842 | ||
11fdf7f2 | 3843 | // create the object processor |
9f95a23c TL |
3844 | auto aio = rgw::make_throttle(s->cct->_conf->rgw_put_obj_min_window_size, |
3845 | s->yield); | |
11fdf7f2 TL |
3846 | using namespace rgw::putobj; |
3847 | constexpr auto max_processor_size = std::max({sizeof(MultipartObjectProcessor), | |
3848 | sizeof(AtomicObjectProcessor), | |
3849 | sizeof(AppendObjectProcessor)}); | |
3850 | ceph::static_ptr<ObjectProcessor, max_processor_size> processor; | |
3851 | ||
3852 | rgw_placement_rule *pdest_placement; | |
3853 | ||
eafe8130 | 3854 | multipart_upload_info upload_info; |
11fdf7f2 | 3855 | if (multipart) { |
f67539c2 | 3856 | RGWMPObj mp(s->object->get_name(), multipart_upload_id); |
11fdf7f2 | 3857 | |
b3b6e05e | 3858 | op_ret = get_multipart_info(this, s, mp.get_meta(), &upload_info); |
11fdf7f2 TL |
3859 | if (op_ret < 0) { |
3860 | if (op_ret != -ENOENT) { | |
3861 | ldpp_dout(this, 0) << "ERROR: get_multipart_info returned " << op_ret << ": " << cpp_strerror(-op_ret) << dendl; | |
3862 | } else {// -ENOENT: raced with upload complete/cancel, no need to spam log | |
3863 | ldpp_dout(this, 20) << "failed to get multipart info (returned " << op_ret << ": " << cpp_strerror(-op_ret) << "): probably raced with upload complete / cancel" << dendl; | |
3864 | } | |
3865 | return; | |
3866 | } | |
3867 | pdest_placement = &upload_info.dest_placement; | |
3868 | ldpp_dout(this, 20) << "dest_placement for part=" << upload_info.dest_placement << dendl; | |
3869 | processor.emplace<MultipartObjectProcessor>( | |
f67539c2 TL |
3870 | &*aio, store, s->bucket.get(), pdest_placement, |
3871 | s->owner.get_id(), obj_ctx, s->object->clone(), | |
9f95a23c TL |
3872 | multipart_upload_id, multipart_part_num, multipart_part_str, |
3873 | this, s->yield); | |
11fdf7f2 | 3874 | } else if(append) { |
f67539c2 | 3875 | if (s->bucket->versioned()) { |
11fdf7f2 TL |
3876 | op_ret = -ERR_INVALID_BUCKET_STATE; |
3877 | return; | |
3878 | } | |
3879 | pdest_placement = &s->dest_placement; | |
3880 | processor.emplace<AppendObjectProcessor>( | |
f67539c2 TL |
3881 | &*aio, store, s->bucket.get(), pdest_placement, s->bucket_owner.get_id(), |
3882 | obj_ctx, s->object->clone(), | |
9f95a23c | 3883 | s->req_id, position, &cur_accounted_size, this, s->yield); |
11fdf7f2 | 3884 | } else { |
f67539c2 | 3885 | if (s->bucket->versioning_enabled()) { |
11fdf7f2 | 3886 | if (!version_id.empty()) { |
f67539c2 | 3887 | s->object->set_instance(version_id); |
11fdf7f2 | 3888 | } else { |
f67539c2 TL |
3889 | s->object->gen_rand_obj_instance_name(); |
3890 | version_id = s->object->get_instance(); | |
11fdf7f2 TL |
3891 | } |
3892 | } | |
3893 | pdest_placement = &s->dest_placement; | |
3894 | processor.emplace<AtomicObjectProcessor>( | |
f67539c2 TL |
3895 | &*aio, store, s->bucket.get(), pdest_placement, |
3896 | s->bucket_owner.get_id(), obj_ctx, s->object->clone(), | |
3897 | olh_epoch, s->req_id, this, s->yield); | |
11fdf7f2 TL |
3898 | } |
3899 | ||
9f95a23c | 3900 | op_ret = processor->prepare(s->yield); |
7c673cae | 3901 | if (op_ret < 0) { |
11fdf7f2 | 3902 | ldpp_dout(this, 20) << "processor->prepare() returned ret=" << op_ret |
7c673cae | 3903 | << dendl; |
11fdf7f2 | 3904 | return; |
7c673cae FG |
3905 | } |
3906 | ||
3a9019d9 | 3907 | if ((! copy_source.empty()) && !copy_source_range) { |
f67539c2 TL |
3908 | rgw::sal::RGWRadosObject obj(store, rgw_obj_key(copy_source_object_name, copy_source_version_id)); |
3909 | rgw::sal::RGWRadosBucket bucket(store, copy_source_bucket_info); | |
3a9019d9 FG |
3910 | |
3911 | RGWObjState *astate; | |
b3b6e05e | 3912 | op_ret = obj.get_obj_state(this, &obj_ctx, bucket, &astate, s->yield); |
3a9019d9 | 3913 | if (op_ret < 0) { |
11fdf7f2 TL |
3914 | ldpp_dout(this, 0) << "ERROR: get copy source obj state returned with error" << op_ret << dendl; |
3915 | return; | |
3a9019d9 FG |
3916 | } |
3917 | if (!astate->exists){ | |
3918 | op_ret = -ENOENT; | |
11fdf7f2 | 3919 | return; |
3a9019d9 | 3920 | } |
28e407b8 | 3921 | lst = astate->accounted_size - 1; |
3a9019d9 FG |
3922 | } else { |
3923 | lst = copy_source_range_lst; | |
3924 | } | |
3925 | ||
7c673cae | 3926 | fst = copy_source_range_fst; |
7c673cae | 3927 | |
11fdf7f2 TL |
3928 | // no filters by default |
3929 | DataProcessor *filter = processor.get(); | |
3930 | ||
9f95a23c | 3931 | const auto& compression_type = store->svc()->zone->get_zone_params().get_compression_type(*pdest_placement); |
11fdf7f2 TL |
3932 | CompressorRef plugin; |
3933 | boost::optional<RGWPutObj_Compress> compressor; | |
3934 | ||
3935 | std::unique_ptr<DataProcessor> encrypt; | |
eafe8130 TL |
3936 | |
3937 | if (!append) { // compression and encryption only apply to full object uploads | |
3938 | op_ret = get_encrypt_filter(&encrypt, filter); | |
3939 | if (op_ret < 0) { | |
3940 | return; | |
3941 | } | |
3942 | if (encrypt != nullptr) { | |
3943 | filter = &*encrypt; | |
3944 | } else if (compression_type != "none") { | |
3945 | plugin = get_compressor_plugin(s, compression_type); | |
3946 | if (!plugin) { | |
3947 | ldpp_dout(this, 1) << "Cannot load plugin for compression type " | |
3948 | << compression_type << dendl; | |
3949 | } else { | |
3950 | compressor.emplace(s->cct, plugin, filter); | |
3951 | filter = &*compressor; | |
3952 | } | |
7c673cae FG |
3953 | } |
3954 | } | |
11fdf7f2 | 3955 | tracepoint(rgw_op, before_data_transfer, s->req_id.c_str()); |
7c673cae | 3956 | do { |
31f18b77 | 3957 | bufferlist data; |
7c673cae FG |
3958 | if (fst > lst) |
3959 | break; | |
3a9019d9 | 3960 | if (copy_source.empty()) { |
31f18b77 | 3961 | len = get_data(data); |
7c673cae FG |
3962 | } else { |
3963 | uint64_t cur_lst = min(fst + s->cct->_conf->rgw_max_chunk_size - 1, lst); | |
31f18b77 | 3964 | op_ret = get_data(fst, cur_lst, data); |
7c673cae | 3965 | if (op_ret < 0) |
11fdf7f2 | 3966 | return; |
31f18b77 | 3967 | len = data.length(); |
7c673cae FG |
3968 | s->content_length += len; |
3969 | fst += len; | |
3970 | } | |
3971 | if (len < 0) { | |
3972 | op_ret = len; | |
11fdf7f2 TL |
3973 | ldpp_dout(this, 20) << "get_data() returned ret=" << op_ret << dendl; |
3974 | return; | |
3975 | } else if (len == 0) { | |
3976 | break; | |
7c673cae FG |
3977 | } |
3978 | ||
7c673cae | 3979 | if (need_calc_md5) { |
11fdf7f2 | 3980 | hash.Update((const unsigned char *)data.c_str(), data.length()); |
7c673cae FG |
3981 | } |
3982 | ||
31f18b77 FG |
3983 | /* update torrrent */ |
3984 | torrent.update(data); | |
7c673cae | 3985 | |
11fdf7f2 | 3986 | op_ret = filter->process(std::move(data), ofs); |
7c673cae | 3987 | if (op_ret < 0) { |
11fdf7f2 TL |
3988 | ldpp_dout(this, 20) << "processor->process() returned ret=" |
3989 | << op_ret << dendl; | |
3990 | return; | |
7c673cae FG |
3991 | } |
3992 | ||
3993 | ofs += len; | |
3994 | } while (len > 0); | |
11fdf7f2 | 3995 | tracepoint(rgw_op, after_data_transfer, s->req_id.c_str(), ofs); |
7c673cae | 3996 | |
11fdf7f2 TL |
3997 | // flush any data in filters |
3998 | op_ret = filter->process({}, ofs); | |
3999 | if (op_ret < 0) { | |
4000 | return; | |
7c673cae FG |
4001 | } |
4002 | ||
31f18b77 | 4003 | if (!chunked_upload && ofs != s->content_length) { |
7c673cae | 4004 | op_ret = -ERR_REQUEST_TIMEOUT; |
11fdf7f2 | 4005 | return; |
7c673cae FG |
4006 | } |
4007 | s->obj_size = ofs; | |
f67539c2 | 4008 | s->object->set_obj_size(ofs); |
7c673cae FG |
4009 | |
4010 | perfcounter->inc(l_rgw_put_b, s->obj_size); | |
4011 | ||
31f18b77 FG |
4012 | op_ret = do_aws4_auth_completion(); |
4013 | if (op_ret < 0) { | |
11fdf7f2 | 4014 | return; |
7c673cae | 4015 | } |
31f18b77 | 4016 | |
f67539c2 | 4017 | op_ret = s->bucket->check_quota(user_quota, bucket_quota, s->obj_size, y); |
7c673cae | 4018 | if (op_ret < 0) { |
11fdf7f2 TL |
4019 | ldpp_dout(this, 20) << "second check_quota() returned op_ret=" << op_ret << dendl; |
4020 | return; | |
7c673cae FG |
4021 | } |
4022 | ||
4023 | hash.Final(m); | |
4024 | ||
4025 | if (compressor && compressor->is_compressed()) { | |
4026 | bufferlist tmp; | |
4027 | RGWCompressionInfo cs_info; | |
4028 | cs_info.compression_type = plugin->get_type_name(); | |
4029 | cs_info.orig_size = s->obj_size; | |
f67539c2 | 4030 | cs_info.compressor_message = compressor->get_compressor_message(); |
7c673cae | 4031 | cs_info.blocks = move(compressor->get_compression_blocks()); |
11fdf7f2 | 4032 | encode(cs_info, tmp); |
7c673cae | 4033 | attrs[RGW_ATTR_COMPRESSION] = tmp; |
11fdf7f2 | 4034 | ldpp_dout(this, 20) << "storing " << RGW_ATTR_COMPRESSION |
7c673cae FG |
4035 | << " with type=" << cs_info.compression_type |
4036 | << ", orig_size=" << cs_info.orig_size | |
4037 | << ", blocks=" << cs_info.blocks.size() << dendl; | |
4038 | } | |
4039 | ||
4040 | buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5); | |
4041 | ||
4042 | etag = calc_md5; | |
4043 | ||
4044 | if (supplied_md5_b64 && strcmp(calc_md5, supplied_md5)) { | |
4045 | op_ret = -ERR_BAD_DIGEST; | |
11fdf7f2 | 4046 | return; |
7c673cae FG |
4047 | } |
4048 | ||
4049 | policy.encode(aclbl); | |
4050 | emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); | |
4051 | ||
4052 | if (dlo_manifest) { | |
4053 | op_ret = encode_dlo_manifest_attr(dlo_manifest, attrs); | |
4054 | if (op_ret < 0) { | |
11fdf7f2 TL |
4055 | ldpp_dout(this, 0) << "bad user manifest: " << dlo_manifest << dendl; |
4056 | return; | |
7c673cae | 4057 | } |
7c673cae FG |
4058 | } |
4059 | ||
4060 | if (slo_info) { | |
4061 | bufferlist manifest_bl; | |
11fdf7f2 | 4062 | encode(*slo_info, manifest_bl); |
7c673cae | 4063 | emplace_attr(RGW_ATTR_SLO_MANIFEST, std::move(manifest_bl)); |
7c673cae FG |
4064 | } |
4065 | ||
4066 | if (supplied_etag && etag.compare(supplied_etag) != 0) { | |
4067 | op_ret = -ERR_UNPROCESSABLE_ENTITY; | |
11fdf7f2 | 4068 | return; |
7c673cae | 4069 | } |
11fdf7f2 | 4070 | bl.append(etag.c_str(), etag.size()); |
7c673cae FG |
4071 | emplace_attr(RGW_ATTR_ETAG, std::move(bl)); |
4072 | ||
4073 | populate_with_generic_attrs(s, attrs); | |
b3b6e05e | 4074 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs); |
3efd9988 | 4075 | if (op_ret < 0) { |
11fdf7f2 | 4076 | return; |
3efd9988 | 4077 | } |
7c673cae | 4078 | encode_delete_at_attr(delete_at, attrs); |
224ce89b | 4079 | encode_obj_tags_attr(obj_tags.get(), attrs); |
9f95a23c | 4080 | rgw_cond_decode_objtags(s, attrs); |
7c673cae FG |
4081 | |
4082 | /* Add a custom metadata to expose the information whether an object | |
4083 | * is an SLO or not. Appending the attribute must be performed AFTER | |
4084 | * processing any input from user in order to prohibit overwriting. */ | |
4085 | if (slo_info) { | |
4086 | bufferlist slo_userindicator_bl; | |
31f18b77 | 4087 | slo_userindicator_bl.append("True", 4); |
7c673cae FG |
4088 | emplace_attr(RGW_ATTR_SLO_UINDICATOR, std::move(slo_userindicator_bl)); |
4089 | } | |
eafe8130 TL |
4090 | if (obj_legal_hold) { |
4091 | bufferlist obj_legal_hold_bl; | |
4092 | obj_legal_hold->encode(obj_legal_hold_bl); | |
4093 | emplace_attr(RGW_ATTR_OBJECT_LEGAL_HOLD, std::move(obj_legal_hold_bl)); | |
4094 | } | |
4095 | if (obj_retention) { | |
4096 | bufferlist obj_retention_bl; | |
4097 | obj_retention->encode(obj_retention_bl); | |
4098 | emplace_attr(RGW_ATTR_OBJECT_RETENTION, std::move(obj_retention_bl)); | |
4099 | } | |
7c673cae | 4100 | |
11fdf7f2 | 4101 | tracepoint(rgw_op, processor_complete_enter, s->req_id.c_str()); |
7c673cae FG |
4102 | op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, |
4103 | (delete_at ? *delete_at : real_time()), if_match, if_nomatch, | |
9f95a23c TL |
4104 | (user_data.empty() ? nullptr : &user_data), nullptr, nullptr, |
4105 | s->yield); | |
11fdf7f2 | 4106 | tracepoint(rgw_op, processor_complete_exit, s->req_id.c_str()); |
7c673cae FG |
4107 | |
4108 | /* produce torrent */ | |
4109 | if (s->cct->_conf->rgw_torrent_flag && (ofs == torrent.get_data_len())) | |
4110 | { | |
4111 | torrent.init(s, store); | |
4112 | torrent.set_create_date(mtime); | |
f67539c2 | 4113 | op_ret = torrent.complete(y); |
7c673cae FG |
4114 | if (0 != op_ret) |
4115 | { | |
11fdf7f2 TL |
4116 | ldpp_dout(this, 0) << "ERROR: torrent.handle_data() returned " << op_ret << dendl; |
4117 | return; | |
7c673cae FG |
4118 | } |
4119 | } | |
eafe8130 TL |
4120 | |
4121 | // send request to notification manager | |
b3b6e05e | 4122 | const auto ret = rgw::notify::publish_commit(s->object.get(), s->obj_size, mtime, etag, event_type, res, this); |
eafe8130 | 4123 | if (ret < 0) { |
f67539c2 TL |
4124 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
4125 | // too late to rollback operation, hence op_ret is not set here | |
eafe8130 | 4126 | } |
7c673cae FG |
4127 | } |
4128 | ||
f67539c2 | 4129 | int RGWPostObj::verify_permission(optional_yield y) |
7c673cae | 4130 | { |
11fdf7f2 | 4131 | return 0; |
7c673cae | 4132 | } |
11fdf7f2 | 4133 | |
7c673cae FG |
4134 | void RGWPostObj::pre_exec() |
4135 | { | |
4136 | rgw_bucket_object_pre_exec(s); | |
4137 | } | |
4138 | ||
f67539c2 | 4139 | void RGWPostObj::execute(optional_yield y) |
7c673cae | 4140 | { |
7c673cae FG |
4141 | boost::optional<RGWPutObj_Compress> compressor; |
4142 | CompressorRef plugin; | |
224ce89b | 4143 | char supplied_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; |
7c673cae FG |
4144 | |
4145 | /* Read in the data from the POST form. */ | |
f67539c2 | 4146 | op_ret = get_params(y); |
7c673cae FG |
4147 | if (op_ret < 0) { |
4148 | return; | |
4149 | } | |
4150 | ||
4151 | op_ret = verify_params(); | |
4152 | if (op_ret < 0) { | |
4153 | return; | |
4154 | } | |
4155 | ||
522d829b TL |
4156 | if (s->iam_policy || ! s->iam_user_policies.empty() || !s->session_policies.empty()) { |
4157 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, | |
11fdf7f2 TL |
4158 | boost::none, |
4159 | rgw::IAM::s3PutObject, | |
f67539c2 | 4160 | s->object->get_obj()); |
522d829b | 4161 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
4162 | op_ret = -EACCES; |
4163 | return; | |
4164 | } | |
4165 | ||
4166 | rgw::IAM::Effect e = Effect::Pass; | |
522d829b | 4167 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
4168 | if (s->iam_policy) { |
4169 | e = s->iam_policy->eval(s->env, *s->auth.identity, | |
31f18b77 | 4170 | rgw::IAM::s3PutObject, |
522d829b TL |
4171 | s->object->get_obj(), |
4172 | princ_type); | |
11fdf7f2 | 4173 | } |
31f18b77 FG |
4174 | if (e == Effect::Deny) { |
4175 | op_ret = -EACCES; | |
4176 | return; | |
522d829b TL |
4177 | } |
4178 | ||
4179 | if (!s->session_policies.empty()) { | |
4180 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
4181 | boost::none, | |
4182 | rgw::IAM::s3PutObject, | |
4183 | s->object->get_obj()); | |
4184 | if (session_policy_res == Effect::Deny) { | |
4185 | op_ret = -EACCES; | |
4186 | return; | |
4187 | } | |
4188 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
4189 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
4190 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
4191 | (session_policy_res == Effect::Allow && e == Effect::Allow)) { | |
4192 | op_ret = 0; | |
4193 | return; | |
4194 | } | |
4195 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
4196 | //Intersection of session policy and identity policy plus bucket policy | |
4197 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || e == Effect::Allow) { | |
4198 | op_ret = 0; | |
4199 | return; | |
4200 | } | |
4201 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
4202 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
4203 | op_ret = 0; | |
4204 | return; | |
4205 | } | |
4206 | } | |
4207 | op_ret = -EACCES; | |
4208 | return; | |
4209 | } | |
4210 | if (identity_policy_res == Effect::Pass && e == Effect::Pass && !verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { | |
31f18b77 FG |
4211 | op_ret = -EACCES; |
4212 | return; | |
4213 | } | |
11fdf7f2 | 4214 | } else if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae FG |
4215 | op_ret = -EACCES; |
4216 | return; | |
4217 | } | |
4218 | ||
f67539c2 | 4219 | // make reservation for notification if needed |
b3b6e05e | 4220 | rgw::notify::reservation_t res(this, store, s, s->object.get()); |
f67539c2 | 4221 | const auto event_type = rgw::notify::ObjectCreatedPost; |
b3b6e05e | 4222 | op_ret = rgw::notify::publish_reserve(this, event_type, res, nullptr); |
f67539c2 TL |
4223 | if (op_ret < 0) { |
4224 | return; | |
4225 | } | |
4226 | ||
4227 | /* Start iteration over data fields. It's necessary as Swift's FormPost | |
7c673cae FG |
4228 | * is capable to handle multiple files in single form. */ |
4229 | do { | |
7c673cae FG |
4230 | char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; |
4231 | unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE]; | |
4232 | MD5 hash; | |
4233 | ceph::buffer::list bl, aclbl; | |
4234 | int len = 0; | |
4235 | ||
f67539c2 | 4236 | op_ret = s->bucket->check_quota(user_quota, bucket_quota, s->content_length, y); |
7c673cae FG |
4237 | if (op_ret < 0) { |
4238 | return; | |
4239 | } | |
4240 | ||
224ce89b WB |
4241 | if (supplied_md5_b64) { |
4242 | char supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1]; | |
11fdf7f2 | 4243 | ldpp_dout(this, 15) << "supplied_md5_b64=" << supplied_md5_b64 << dendl; |
224ce89b WB |
4244 | op_ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1], |
4245 | supplied_md5_b64, supplied_md5_b64 + strlen(supplied_md5_b64)); | |
11fdf7f2 | 4246 | ldpp_dout(this, 15) << "ceph_armor ret=" << op_ret << dendl; |
224ce89b WB |
4247 | if (op_ret != CEPH_CRYPTO_MD5_DIGESTSIZE) { |
4248 | op_ret = -ERR_INVALID_DIGEST; | |
4249 | return; | |
4250 | } | |
4251 | ||
4252 | buf_to_hex((const unsigned char *)supplied_md5_bin, CEPH_CRYPTO_MD5_DIGESTSIZE, supplied_md5); | |
11fdf7f2 TL |
4253 | ldpp_dout(this, 15) << "supplied_md5=" << supplied_md5 << dendl; |
4254 | } | |
4255 | ||
f67539c2 TL |
4256 | std::unique_ptr<rgw::sal::RGWObject> obj = |
4257 | s->bucket->get_object(rgw_obj_key(get_current_filename())); | |
4258 | if (s->bucket->versioning_enabled()) { | |
4259 | obj->gen_rand_obj_instance_name(); | |
11fdf7f2 | 4260 | } |
7c673cae | 4261 | |
9f95a23c TL |
4262 | auto aio = rgw::make_throttle(s->cct->_conf->rgw_put_obj_min_window_size, |
4263 | s->yield); | |
11fdf7f2 TL |
4264 | |
4265 | using namespace rgw::putobj; | |
f67539c2 | 4266 | AtomicObjectProcessor processor(&*aio, store, s->bucket.get(), |
11fdf7f2 TL |
4267 | &s->dest_placement, |
4268 | s->bucket_owner.get_id(), | |
4269 | *static_cast<RGWObjectCtx*>(s->obj_ctx), | |
f67539c2 | 4270 | std::move(obj), 0, s->req_id, this, s->yield); |
9f95a23c | 4271 | op_ret = processor.prepare(s->yield); |
7c673cae FG |
4272 | if (op_ret < 0) { |
4273 | return; | |
4274 | } | |
4275 | ||
11fdf7f2 TL |
4276 | /* No filters by default. */ |
4277 | DataProcessor *filter = &processor; | |
4278 | ||
4279 | std::unique_ptr<DataProcessor> encrypt; | |
7c673cae FG |
4280 | op_ret = get_encrypt_filter(&encrypt, filter); |
4281 | if (op_ret < 0) { | |
4282 | return; | |
4283 | } | |
4284 | if (encrypt != nullptr) { | |
4285 | filter = encrypt.get(); | |
4286 | } else { | |
9f95a23c | 4287 | const auto& compression_type = store->svc()->zone->get_zone_params().get_compression_type( |
11fdf7f2 | 4288 | s->dest_placement); |
7c673cae FG |
4289 | if (compression_type != "none") { |
4290 | plugin = Compressor::create(s->cct, compression_type); | |
4291 | if (!plugin) { | |
11fdf7f2 | 4292 | ldpp_dout(this, 1) << "Cannot load plugin for compression type " |
7c673cae FG |
4293 | << compression_type << dendl; |
4294 | } else { | |
4295 | compressor.emplace(s->cct, plugin, filter); | |
4296 | filter = &*compressor; | |
4297 | } | |
4298 | } | |
4299 | } | |
4300 | ||
4301 | bool again; | |
4302 | do { | |
4303 | ceph::bufferlist data; | |
4304 | len = get_data(data, again); | |
4305 | ||
4306 | if (len < 0) { | |
4307 | op_ret = len; | |
4308 | return; | |
4309 | } | |
4310 | ||
4311 | if (!len) { | |
4312 | break; | |
4313 | } | |
4314 | ||
11fdf7f2 TL |
4315 | hash.Update((const unsigned char *)data.c_str(), data.length()); |
4316 | op_ret = filter->process(std::move(data), ofs); | |
7c673cae FG |
4317 | |
4318 | ofs += len; | |
4319 | ||
4320 | if (ofs > max_len) { | |
4321 | op_ret = -ERR_TOO_LARGE; | |
4322 | return; | |
4323 | } | |
4324 | } while (again); | |
4325 | ||
11fdf7f2 TL |
4326 | // flush |
4327 | op_ret = filter->process({}, ofs); | |
4328 | if (op_ret < 0) { | |
4329 | return; | |
7c673cae FG |
4330 | } |
4331 | ||
4332 | if (len < min_len) { | |
4333 | op_ret = -ERR_TOO_SMALL; | |
4334 | return; | |
4335 | } | |
4336 | ||
4337 | s->obj_size = ofs; | |
f67539c2 | 4338 | s->object->set_obj_size(ofs); |
7c673cae | 4339 | |
224ce89b | 4340 | |
f67539c2 | 4341 | op_ret = s->bucket->check_quota(user_quota, bucket_quota, s->obj_size, y); |
7c673cae FG |
4342 | if (op_ret < 0) { |
4343 | return; | |
4344 | } | |
4345 | ||
4346 | hash.Final(m); | |
4347 | buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5); | |
4348 | ||
4349 | etag = calc_md5; | |
11fdf7f2 TL |
4350 | |
4351 | if (supplied_md5_b64 && strcmp(calc_md5, supplied_md5)) { | |
4352 | op_ret = -ERR_BAD_DIGEST; | |
4353 | return; | |
4354 | } | |
4355 | ||
4356 | bl.append(etag.c_str(), etag.size()); | |
7c673cae FG |
4357 | emplace_attr(RGW_ATTR_ETAG, std::move(bl)); |
4358 | ||
4359 | policy.encode(aclbl); | |
4360 | emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); | |
4361 | ||
4362 | const std::string content_type = get_current_content_type(); | |
4363 | if (! content_type.empty()) { | |
4364 | ceph::bufferlist ct_bl; | |
4365 | ct_bl.append(content_type.c_str(), content_type.size() + 1); | |
4366 | emplace_attr(RGW_ATTR_CONTENT_TYPE, std::move(ct_bl)); | |
4367 | } | |
4368 | ||
4369 | if (compressor && compressor->is_compressed()) { | |
4370 | ceph::bufferlist tmp; | |
4371 | RGWCompressionInfo cs_info; | |
4372 | cs_info.compression_type = plugin->get_type_name(); | |
4373 | cs_info.orig_size = s->obj_size; | |
f67539c2 | 4374 | cs_info.compressor_message = compressor->get_compressor_message(); |
7c673cae | 4375 | cs_info.blocks = move(compressor->get_compression_blocks()); |
11fdf7f2 | 4376 | encode(cs_info, tmp); |
7c673cae FG |
4377 | emplace_attr(RGW_ATTR_COMPRESSION, std::move(tmp)); |
4378 | } | |
4379 | ||
11fdf7f2 TL |
4380 | op_ret = processor.complete(s->obj_size, etag, nullptr, real_time(), attrs, |
4381 | (delete_at ? *delete_at : real_time()), | |
9f95a23c TL |
4382 | nullptr, nullptr, nullptr, nullptr, nullptr, |
4383 | s->yield); | |
11fdf7f2 TL |
4384 | if (op_ret < 0) { |
4385 | return; | |
4386 | } | |
7c673cae | 4387 | } while (is_next_file_to_upload()); |
eafe8130 | 4388 | |
f67539c2 | 4389 | // send request to notification manager |
b3b6e05e | 4390 | const auto ret = rgw::notify::publish_commit(s->object.get(), ofs, ceph::real_clock::now(), etag, event_type, res, this); |
eafe8130 | 4391 | if (ret < 0) { |
f67539c2 TL |
4392 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
4393 | // too late to rollback operation, hence op_ret is not set here | |
eafe8130 | 4394 | } |
7c673cae FG |
4395 | } |
4396 | ||
4397 | ||
4398 | void RGWPutMetadataAccount::filter_out_temp_url(map<string, bufferlist>& add_attrs, | |
4399 | const set<string>& rmattr_names, | |
4400 | map<int, string>& temp_url_keys) | |
4401 | { | |
4402 | map<string, bufferlist>::iterator iter; | |
4403 | ||
4404 | iter = add_attrs.find(RGW_ATTR_TEMPURL_KEY1); | |
4405 | if (iter != add_attrs.end()) { | |
4406 | temp_url_keys[0] = iter->second.c_str(); | |
4407 | add_attrs.erase(iter); | |
4408 | } | |
4409 | ||
4410 | iter = add_attrs.find(RGW_ATTR_TEMPURL_KEY2); | |
4411 | if (iter != add_attrs.end()) { | |
4412 | temp_url_keys[1] = iter->second.c_str(); | |
4413 | add_attrs.erase(iter); | |
4414 | } | |
4415 | ||
4416 | for (const string& name : rmattr_names) { | |
4417 | if (name.compare(RGW_ATTR_TEMPURL_KEY1) == 0) { | |
4418 | temp_url_keys[0] = string(); | |
4419 | } | |
4420 | if (name.compare(RGW_ATTR_TEMPURL_KEY2) == 0) { | |
4421 | temp_url_keys[1] = string(); | |
4422 | } | |
4423 | } | |
4424 | } | |
4425 | ||
f67539c2 | 4426 | int RGWPutMetadataAccount::init_processing(optional_yield y) |
7c673cae FG |
4427 | { |
4428 | /* First, go to the base class. At the time of writing the method was | |
4429 | * responsible only for initializing the quota. This isn't necessary | |
4430 | * here as we are touching metadata only. I'm putting this call only | |
4431 | * for the future. */ | |
f67539c2 | 4432 | op_ret = RGWOp::init_processing(y); |
7c673cae FG |
4433 | if (op_ret < 0) { |
4434 | return op_ret; | |
4435 | } | |
4436 | ||
f67539c2 | 4437 | op_ret = get_params(y); |
7c673cae FG |
4438 | if (op_ret < 0) { |
4439 | return op_ret; | |
4440 | } | |
4441 | ||
b3b6e05e | 4442 | op_ret = store->ctl()->user->get_attrs_by_uid(this, s->user->get_id(), &orig_attrs, |
9f95a23c TL |
4443 | s->yield, |
4444 | &acct_op_tracker); | |
7c673cae FG |
4445 | if (op_ret < 0) { |
4446 | return op_ret; | |
4447 | } | |
4448 | ||
4449 | if (has_policy) { | |
4450 | bufferlist acl_bl; | |
4451 | policy.encode(acl_bl); | |
4452 | attrs.emplace(RGW_ATTR_ACL, std::move(acl_bl)); | |
4453 | } | |
4454 | ||
b3b6e05e | 4455 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs, false); |
3efd9988 FG |
4456 | if (op_ret < 0) { |
4457 | return op_ret; | |
4458 | } | |
7c673cae FG |
4459 | prepare_add_del_attrs(orig_attrs, rmattr_names, attrs); |
4460 | populate_with_generic_attrs(s, attrs); | |
4461 | ||
4462 | /* Try extract the TempURL-related stuff now to allow verify_permission | |
4463 | * evaluate whether we need FULL_CONTROL or not. */ | |
4464 | filter_out_temp_url(attrs, rmattr_names, temp_url_keys); | |
4465 | ||
4466 | /* The same with quota except a client needs to be reseller admin. */ | |
4467 | op_ret = filter_out_quota_info(attrs, rmattr_names, new_quota, | |
4468 | &new_quota_extracted); | |
4469 | if (op_ret < 0) { | |
4470 | return op_ret; | |
4471 | } | |
4472 | ||
4473 | return 0; | |
4474 | } | |
4475 | ||
f67539c2 | 4476 | int RGWPutMetadataAccount::verify_permission(optional_yield y) |
7c673cae FG |
4477 | { |
4478 | if (s->auth.identity->is_anonymous()) { | |
4479 | return -EACCES; | |
4480 | } | |
4481 | ||
11fdf7f2 | 4482 | if (!verify_user_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae FG |
4483 | return -EACCES; |
4484 | } | |
4485 | ||
4486 | /* Altering TempURL keys requires FULL_CONTROL. */ | |
4487 | if (!temp_url_keys.empty() && s->perm_mask != RGW_PERM_FULL_CONTROL) { | |
4488 | return -EPERM; | |
4489 | } | |
4490 | ||
4491 | /* We are failing this intensionally to allow system user/reseller admin | |
4492 | * override in rgw_process.cc. This is the way to specify a given RGWOp | |
4493 | * expect extra privileges. */ | |
4494 | if (new_quota_extracted) { | |
4495 | return -EACCES; | |
4496 | } | |
4497 | ||
4498 | return 0; | |
4499 | } | |
4500 | ||
f67539c2 | 4501 | void RGWPutMetadataAccount::execute(optional_yield y) |
7c673cae FG |
4502 | { |
4503 | /* Params have been extracted earlier. See init_processing(). */ | |
4504 | RGWUserInfo new_uinfo; | |
b3b6e05e | 4505 | op_ret = store->ctl()->user->get_info_by_uid(this, s->user->get_id(), &new_uinfo, s->yield, |
9f95a23c TL |
4506 | RGWUserCtl::GetParams() |
4507 | .set_objv_tracker(&acct_op_tracker)); | |
7c673cae FG |
4508 | if (op_ret < 0) { |
4509 | return; | |
4510 | } | |
4511 | ||
4512 | /* Handle the TempURL-related stuff. */ | |
4513 | if (!temp_url_keys.empty()) { | |
4514 | for (auto& pair : temp_url_keys) { | |
4515 | new_uinfo.temp_url_keys[pair.first] = std::move(pair.second); | |
4516 | } | |
4517 | } | |
4518 | ||
4519 | /* Handle the quota extracted at the verify_permission step. */ | |
4520 | if (new_quota_extracted) { | |
4521 | new_uinfo.user_quota = std::move(new_quota); | |
4522 | } | |
4523 | ||
4524 | /* We are passing here the current (old) user info to allow the function | |
4525 | * optimize-out some operations. */ | |
b3b6e05e | 4526 | op_ret = store->ctl()->user->store_info(this, new_uinfo, s->yield, |
9f95a23c TL |
4527 | RGWUserCtl::PutParams() |
4528 | .set_old_info(&s->user->get_info()) | |
4529 | .set_objv_tracker(&acct_op_tracker) | |
4530 | .set_attrs(&attrs)); | |
7c673cae FG |
4531 | } |
4532 | ||
f67539c2 | 4533 | int RGWPutMetadataBucket::verify_permission(optional_yield y) |
7c673cae | 4534 | { |
11fdf7f2 | 4535 | if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae FG |
4536 | return -EACCES; |
4537 | } | |
4538 | ||
4539 | return 0; | |
4540 | } | |
4541 | ||
4542 | void RGWPutMetadataBucket::pre_exec() | |
4543 | { | |
4544 | rgw_bucket_object_pre_exec(s); | |
4545 | } | |
4546 | ||
f67539c2 | 4547 | void RGWPutMetadataBucket::execute(optional_yield y) |
7c673cae | 4548 | { |
f67539c2 | 4549 | op_ret = get_params(y); |
7c673cae FG |
4550 | if (op_ret < 0) { |
4551 | return; | |
4552 | } | |
4553 | ||
b3b6e05e | 4554 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs, false); |
3efd9988 FG |
4555 | if (op_ret < 0) { |
4556 | return; | |
4557 | } | |
7c673cae FG |
4558 | |
4559 | if (!placement_rule.empty() && | |
f67539c2 | 4560 | placement_rule != s->bucket->get_placement_rule()) { |
7c673cae FG |
4561 | op_ret = -EEXIST; |
4562 | return; | |
4563 | } | |
4564 | ||
b3b6e05e | 4565 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
b32b8144 FG |
4566 | /* Encode special metadata first as we're using std::map::emplace under |
4567 | * the hood. This method will add the new items only if the map doesn't | |
4568 | * contain such keys yet. */ | |
4569 | if (has_policy) { | |
4570 | if (s->dialect.compare("swift") == 0) { | |
4571 | auto old_policy = \ | |
4572 | static_cast<RGWAccessControlPolicy_SWIFT*>(s->bucket_acl.get()); | |
4573 | auto new_policy = static_cast<RGWAccessControlPolicy_SWIFT*>(&policy); | |
4574 | new_policy->filter_merge(policy_rw_mask, old_policy); | |
4575 | policy = *new_policy; | |
4576 | } | |
4577 | buffer::list bl; | |
4578 | policy.encode(bl); | |
4579 | emplace_attr(RGW_ATTR_ACL, std::move(bl)); | |
4580 | } | |
7c673cae | 4581 | |
b32b8144 FG |
4582 | if (has_cors) { |
4583 | buffer::list bl; | |
4584 | cors_config.encode(bl); | |
4585 | emplace_attr(RGW_ATTR_CORS, std::move(bl)); | |
4586 | } | |
7c673cae | 4587 | |
b32b8144 FG |
4588 | /* It's supposed that following functions WILL NOT change any |
4589 | * special attributes (like RGW_ATTR_ACL) if they are already | |
4590 | * present in attrs. */ | |
4591 | prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); | |
4592 | populate_with_generic_attrs(s, attrs); | |
7c673cae | 4593 | |
b32b8144 FG |
4594 | /* According to the Swift's behaviour and its container_quota |
4595 | * WSGI middleware implementation: anyone with write permissions | |
4596 | * is able to set the bucket quota. This stays in contrast to | |
4597 | * account quotas that can be set only by clients holding | |
4598 | * reseller admin privileges. */ | |
f67539c2 | 4599 | op_ret = filter_out_quota_info(attrs, rmattr_names, s->bucket->get_info().quota); |
b32b8144 FG |
4600 | if (op_ret < 0) { |
4601 | return op_ret; | |
4602 | } | |
7c673cae | 4603 | |
b32b8144 | 4604 | if (swift_ver_location) { |
f67539c2 TL |
4605 | s->bucket->get_info().swift_ver_location = *swift_ver_location; |
4606 | s->bucket->get_info().swift_versioning = (!swift_ver_location->empty()); | |
b32b8144 | 4607 | } |
7c673cae | 4608 | |
b32b8144 | 4609 | /* Web site of Swift API. */ |
f67539c2 TL |
4610 | filter_out_website(attrs, rmattr_names, s->bucket->get_info().website_conf); |
4611 | s->bucket->get_info().has_website = !s->bucket->get_info().website_conf.is_empty(); | |
7c673cae | 4612 | |
b32b8144 FG |
4613 | /* Setting attributes also stores the provided bucket info. Due |
4614 | * to this fact, the new quota settings can be serialized with | |
4615 | * the same call. */ | |
b3b6e05e | 4616 | op_ret = s->bucket->set_instance_attrs(this, attrs, s->yield); |
b32b8144 FG |
4617 | return op_ret; |
4618 | }); | |
7c673cae FG |
4619 | } |
4620 | ||
f67539c2 | 4621 | int RGWPutMetadataObject::verify_permission(optional_yield y) |
7c673cae | 4622 | { |
31f18b77 FG |
4623 | // This looks to be something specific to Swift. We could add |
4624 | // operations like swift:PutMetadataObject to the Policy Engine. | |
11fdf7f2 | 4625 | if (!verify_object_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae FG |
4626 | return -EACCES; |
4627 | } | |
4628 | ||
4629 | return 0; | |
4630 | } | |
4631 | ||
4632 | void RGWPutMetadataObject::pre_exec() | |
4633 | { | |
4634 | rgw_bucket_object_pre_exec(s); | |
4635 | } | |
4636 | ||
f67539c2 | 4637 | void RGWPutMetadataObject::execute(optional_yield y) |
7c673cae | 4638 | { |
eafe8130 | 4639 | rgw_obj target_obj; |
f67539c2 | 4640 | rgw::sal::RGWAttrs attrs, rmattrs; |
7c673cae | 4641 | |
f67539c2 | 4642 | s->object->set_atomic(s->obj_ctx); |
7c673cae | 4643 | |
f67539c2 | 4644 | op_ret = get_params(y); |
7c673cae FG |
4645 | if (op_ret < 0) { |
4646 | return; | |
4647 | } | |
4648 | ||
b3b6e05e | 4649 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs); |
3efd9988 FG |
4650 | if (op_ret < 0) { |
4651 | return; | |
4652 | } | |
4653 | ||
7c673cae | 4654 | /* check if obj exists, read orig attrs */ |
b3b6e05e | 4655 | op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, s, &target_obj); |
7c673cae FG |
4656 | if (op_ret < 0) { |
4657 | return; | |
4658 | } | |
4659 | ||
4660 | /* Check whether the object has expired. Swift API documentation | |
4661 | * stands that we should return 404 Not Found in such case. */ | |
f67539c2 | 4662 | if (need_object_expiration() && s->object->is_expired()) { |
7c673cae FG |
4663 | op_ret = -ENOENT; |
4664 | return; | |
4665 | } | |
4666 | ||
4667 | /* Filter currently existing attributes. */ | |
f67539c2 | 4668 | prepare_add_del_attrs(s->object->get_attrs(), attrs, rmattrs); |
7c673cae FG |
4669 | populate_with_generic_attrs(s, attrs); |
4670 | encode_delete_at_attr(delete_at, attrs); | |
4671 | ||
4672 | if (dlo_manifest) { | |
4673 | op_ret = encode_dlo_manifest_attr(dlo_manifest, attrs); | |
4674 | if (op_ret < 0) { | |
11fdf7f2 | 4675 | ldpp_dout(this, 0) << "bad user manifest: " << dlo_manifest << dendl; |
7c673cae FG |
4676 | return; |
4677 | } | |
4678 | } | |
4679 | ||
b3b6e05e | 4680 | op_ret = s->object->set_obj_attrs(this, s->obj_ctx, &attrs, &rmattrs, s->yield, &target_obj); |
7c673cae FG |
4681 | } |
4682 | ||
f67539c2 | 4683 | int RGWDeleteObj::handle_slo_manifest(bufferlist& bl, optional_yield y) |
7c673cae FG |
4684 | { |
4685 | RGWSLOInfo slo_info; | |
11fdf7f2 | 4686 | auto bliter = bl.cbegin(); |
7c673cae | 4687 | try { |
11fdf7f2 | 4688 | decode(slo_info, bliter); |
7c673cae | 4689 | } catch (buffer::error& err) { |
11fdf7f2 | 4690 | ldpp_dout(this, 0) << "ERROR: failed to decode slo manifest" << dendl; |
7c673cae FG |
4691 | return -EIO; |
4692 | } | |
4693 | ||
4694 | try { | |
4695 | deleter = std::unique_ptr<RGWBulkDelete::Deleter>(\ | |
11fdf7f2 TL |
4696 | new RGWBulkDelete::Deleter(this, store, s)); |
4697 | } catch (const std::bad_alloc&) { | |
7c673cae FG |
4698 | return -ENOMEM; |
4699 | } | |
4700 | ||
4701 | list<RGWBulkDelete::acct_path_t> items; | |
4702 | for (const auto& iter : slo_info.entries) { | |
4703 | const string& path_str = iter.path; | |
4704 | ||
4705 | const size_t sep_pos = path_str.find('/', 1 /* skip first slash */); | |
f67539c2 | 4706 | if (std::string_view::npos == sep_pos) { |
7c673cae FG |
4707 | return -EINVAL; |
4708 | } | |
4709 | ||
4710 | RGWBulkDelete::acct_path_t path; | |
4711 | ||
31f18b77 FG |
4712 | path.bucket_name = url_decode(path_str.substr(1, sep_pos - 1)); |
4713 | path.obj_key = url_decode(path_str.substr(sep_pos + 1)); | |
7c673cae FG |
4714 | |
4715 | items.push_back(path); | |
4716 | } | |
4717 | ||
4718 | /* Request removal of the manifest object itself. */ | |
4719 | RGWBulkDelete::acct_path_t path; | |
4720 | path.bucket_name = s->bucket_name; | |
f67539c2 | 4721 | path.obj_key = s->object->get_key(); |
7c673cae FG |
4722 | items.push_back(path); |
4723 | ||
f67539c2 | 4724 | int ret = deleter->delete_chunk(items, y); |
7c673cae FG |
4725 | if (ret < 0) { |
4726 | return ret; | |
4727 | } | |
4728 | ||
4729 | return 0; | |
4730 | } | |
4731 | ||
f67539c2 | 4732 | int RGWDeleteObj::verify_permission(optional_yield y) |
7c673cae | 4733 | { |
f67539c2 | 4734 | int op_ret = get_params(y); |
eafe8130 TL |
4735 | if (op_ret) { |
4736 | return op_ret; | |
4737 | } | |
522d829b | 4738 | if (s->iam_policy || ! s->iam_user_policies.empty() || ! s->session_policies.empty()) { |
f67539c2 | 4739 | if (s->bucket->get_info().obj_lock_enabled() && bypass_governance_mode) { |
522d829b | 4740 | auto r = eval_identity_or_session_policies(s->iam_user_policies, s->env, boost::none, |
f67539c2 | 4741 | rgw::IAM::s3BypassGovernanceRetention, ARN(s->bucket->get_key(), s->object->get_name())); |
eafe8130 TL |
4742 | if (r == Effect::Deny) { |
4743 | bypass_perm = false; | |
4744 | } else if (r == Effect::Pass && s->iam_policy) { | |
4745 | r = s->iam_policy->eval(s->env, *s->auth.identity, rgw::IAM::s3BypassGovernanceRetention, | |
f67539c2 | 4746 | ARN(s->bucket->get_key(), s->object->get_name())); |
eafe8130 TL |
4747 | if (r == Effect::Deny) { |
4748 | bypass_perm = false; | |
4749 | } | |
522d829b TL |
4750 | } else if (r == Effect::Pass && !s->session_policies.empty()) { |
4751 | r = eval_identity_or_session_policies(s->session_policies, s->env, boost::none, | |
4752 | rgw::IAM::s3BypassGovernanceRetention, ARN(s->bucket->get_key(), s->object->get_name())); | |
4753 | if (r == Effect::Deny) { | |
4754 | bypass_perm = false; | |
4755 | } | |
eafe8130 TL |
4756 | } |
4757 | } | |
522d829b | 4758 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, |
11fdf7f2 | 4759 | boost::none, |
f67539c2 | 4760 | s->object->get_instance().empty() ? |
11fdf7f2 TL |
4761 | rgw::IAM::s3DeleteObject : |
4762 | rgw::IAM::s3DeleteObjectVersion, | |
f67539c2 | 4763 | ARN(s->bucket->get_key(), s->object->get_name())); |
522d829b | 4764 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
4765 | return -EACCES; |
4766 | } | |
4767 | ||
4768 | rgw::IAM::Effect r = Effect::Pass; | |
522d829b | 4769 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
4770 | if (s->iam_policy) { |
4771 | r = s->iam_policy->eval(s->env, *s->auth.identity, | |
f67539c2 | 4772 | s->object->get_instance().empty() ? |
31f18b77 FG |
4773 | rgw::IAM::s3DeleteObject : |
4774 | rgw::IAM::s3DeleteObjectVersion, | |
522d829b TL |
4775 | ARN(s->bucket->get_key(), s->object->get_name()), |
4776 | princ_type); | |
11fdf7f2 | 4777 | } |
522d829b TL |
4778 | if (r == Effect::Deny) |
4779 | return -EACCES; | |
4780 | ||
4781 | if (!s->session_policies.empty()) { | |
4782 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
4783 | boost::none, | |
4784 | s->object->get_instance().empty() ? | |
4785 | rgw::IAM::s3DeleteObject : | |
4786 | rgw::IAM::s3DeleteObjectVersion, | |
4787 | ARN(s->bucket->get_key(), s->object->get_name())); | |
4788 | if (session_policy_res == Effect::Deny) { | |
4789 | return -EACCES; | |
4790 | } | |
4791 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
4792 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
4793 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
4794 | (session_policy_res == Effect::Allow && r == Effect::Allow)) { | |
4795 | return 0; | |
4796 | } | |
4797 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
4798 | //Intersection of session policy and identity policy plus bucket policy | |
4799 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || r == Effect::Allow) { | |
4800 | return 0; | |
4801 | } | |
4802 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
4803 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
4804 | return 0; | |
4805 | } | |
4806 | } | |
a8e16298 | 4807 | return -EACCES; |
522d829b TL |
4808 | } |
4809 | if (r == Effect::Allow || identity_policy_res == Effect::Allow) | |
11fdf7f2 | 4810 | return 0; |
31f18b77 FG |
4811 | } |
4812 | ||
11fdf7f2 | 4813 | if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae FG |
4814 | return -EACCES; |
4815 | } | |
4816 | ||
f67539c2 TL |
4817 | if (s->bucket->get_info().mfa_enabled() && |
4818 | !s->object->get_instance().empty() && | |
11fdf7f2 TL |
4819 | !s->mfa_verified) { |
4820 | ldpp_dout(this, 5) << "NOTICE: object delete request with a versioned object, mfa auth not provided" << dendl; | |
4821 | return -ERR_MFA_REQUIRED; | |
4822 | } | |
4823 | ||
7c673cae FG |
4824 | return 0; |
4825 | } | |
4826 | ||
4827 | void RGWDeleteObj::pre_exec() | |
4828 | { | |
4829 | rgw_bucket_object_pre_exec(s); | |
4830 | } | |
4831 | ||
f67539c2 | 4832 | void RGWDeleteObj::execute(optional_yield y) |
7c673cae FG |
4833 | { |
4834 | if (!s->bucket_exists) { | |
4835 | op_ret = -ERR_NO_SUCH_BUCKET; | |
4836 | return; | |
4837 | } | |
f67539c2 | 4838 | s->object->set_bucket(s->bucket.get()); |
7c673cae | 4839 | |
f67539c2 | 4840 | rgw::sal::RGWAttrs attrs; |
7c673cae | 4841 | |
f67539c2 | 4842 | bool check_obj_lock = s->object->have_instance() && s->bucket->get_info().obj_lock_enabled(); |
7c673cae | 4843 | |
f67539c2 | 4844 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
b3b6e05e | 4845 | op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, this); |
f67539c2 TL |
4846 | if (op_ret < 0) { |
4847 | if (need_object_expiration() || multipart_delete) { | |
7c673cae FG |
4848 | return; |
4849 | } | |
7c673cae | 4850 | |
f67539c2 TL |
4851 | if (check_obj_lock) { |
4852 | /* check if obj exists, read orig attrs */ | |
eafe8130 TL |
4853 | if (op_ret == -ENOENT) { |
4854 | /* object maybe delete_marker, skip check_obj_lock*/ | |
4855 | check_obj_lock = false; | |
4856 | } else { | |
4857 | return; | |
4858 | } | |
4859 | } | |
f67539c2 TL |
4860 | } else { |
4861 | attrs = s->object->get_attrs(); | |
eafe8130 TL |
4862 | } |
4863 | ||
9f95a23c TL |
4864 | // ignore return value from get_obj_attrs in all other cases |
4865 | op_ret = 0; | |
4866 | ||
eafe8130 | 4867 | if (check_obj_lock) { |
f67539c2 TL |
4868 | int object_lock_response = verify_object_lock(this, attrs, bypass_perm, bypass_governance_mode); |
4869 | if (object_lock_response != 0) { | |
4870 | op_ret = object_lock_response; | |
522d829b TL |
4871 | if (op_ret == -EACCES) { |
4872 | s->err.message = "forbidden by object lock"; | |
4873 | } | |
f67539c2 | 4874 | return; |
eafe8130 TL |
4875 | } |
4876 | } | |
4877 | ||
7c673cae FG |
4878 | if (multipart_delete) { |
4879 | const auto slo_attr = attrs.find(RGW_ATTR_SLO_MANIFEST); | |
4880 | ||
4881 | if (slo_attr != attrs.end()) { | |
f67539c2 | 4882 | op_ret = handle_slo_manifest(slo_attr->second, y); |
7c673cae | 4883 | if (op_ret < 0) { |
11fdf7f2 | 4884 | ldpp_dout(this, 0) << "ERROR: failed to handle slo manifest ret=" << op_ret << dendl; |
7c673cae FG |
4885 | } |
4886 | } else { | |
4887 | op_ret = -ERR_NOT_SLO_MANIFEST; | |
4888 | } | |
4889 | ||
4890 | return; | |
4891 | } | |
4892 | ||
f67539c2 | 4893 | // make reservation for notification if needed |
b3b6e05e | 4894 | rgw::notify::reservation_t res(this, store, s, s->object.get()); |
f67539c2 TL |
4895 | const auto versioned_object = s->bucket->versioning_enabled(); |
4896 | const auto event_type = versioned_object && s->object->get_instance().empty() ? | |
4897 | rgw::notify::ObjectRemovedDeleteMarkerCreated : rgw::notify::ObjectRemovedDelete; | |
b3b6e05e | 4898 | op_ret = rgw::notify::publish_reserve(this, event_type, res, nullptr); |
f67539c2 TL |
4899 | if (op_ret < 0) { |
4900 | return; | |
4901 | } | |
4902 | ||
7c673cae | 4903 | RGWObjectCtx *obj_ctx = static_cast<RGWObjectCtx *>(s->obj_ctx); |
f67539c2 | 4904 | s->object->set_atomic(s->obj_ctx); |
7c673cae FG |
4905 | |
4906 | bool ver_restored = false; | |
f67539c2 | 4907 | op_ret = s->object->swift_versioning_restore(s->obj_ctx, ver_restored, this); |
7c673cae FG |
4908 | if (op_ret < 0) { |
4909 | return; | |
4910 | } | |
4911 | ||
4912 | if (!ver_restored) { | |
f67539c2 TL |
4913 | uint64_t epoch = 0; |
4914 | ||
7c673cae FG |
4915 | /* Swift's versioning mechanism hasn't found any previous version of |
4916 | * the object that could be restored. This means we should proceed | |
4917 | * with the regular delete path. */ | |
f67539c2 | 4918 | op_ret = get_system_versioning_params(s, &epoch, &version_id); |
7c673cae | 4919 | if (op_ret < 0) { |
f67539c2 | 4920 | return; |
7c673cae FG |
4921 | } |
4922 | ||
b3b6e05e | 4923 | op_ret = s->object->delete_object(this, obj_ctx, s->owner, s->bucket_owner, unmod_since, |
f67539c2 | 4924 | s->system_request, epoch, version_id, s->yield); |
7c673cae | 4925 | if (op_ret >= 0) { |
f67539c2 | 4926 | delete_marker = s->object->get_delete_marker(); |
7c673cae FG |
4927 | } |
4928 | ||
4929 | /* Check whether the object has expired. Swift API documentation | |
4930 | * stands that we should return 404 Not Found in such case. */ | |
f67539c2 | 4931 | if (need_object_expiration() && s->object->is_expired()) { |
7c673cae FG |
4932 | op_ret = -ENOENT; |
4933 | return; | |
4934 | } | |
4935 | } | |
4936 | ||
94b18763 FG |
4937 | if (op_ret == -ECANCELED) { |
4938 | op_ret = 0; | |
4939 | } | |
7c673cae FG |
4940 | if (op_ret == -ERR_PRECONDITION_FAILED && no_precondition_error) { |
4941 | op_ret = 0; | |
4942 | } | |
9f95a23c | 4943 | |
f67539c2 | 4944 | const auto obj_state = obj_ctx->get_state(s->object->get_obj()); |
e306af50 | 4945 | |
f67539c2 | 4946 | // send request to notification manager |
b3b6e05e | 4947 | const auto ret = rgw::notify::publish_commit(s->object.get(), obj_state->size, obj_state->mtime, attrs[RGW_ATTR_ETAG].to_str(), event_type, res, this); |
e306af50 | 4948 | if (ret < 0) { |
f67539c2 TL |
4949 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
4950 | // too late to rollback operation, hence op_ret is not set here | |
e306af50 | 4951 | } |
7c673cae FG |
4952 | } else { |
4953 | op_ret = -EINVAL; | |
4954 | } | |
4955 | } | |
4956 | ||
f67539c2 | 4957 | bool RGWCopyObj::parse_copy_location(const std::string_view& url_src, |
3a9019d9 | 4958 | string& bucket_name, |
b3b6e05e TL |
4959 | rgw_obj_key& key, |
4960 | req_state* s) | |
7c673cae | 4961 | { |
f67539c2 TL |
4962 | std::string_view name_str; |
4963 | std::string_view params_str; | |
7c673cae | 4964 | |
494da23a | 4965 | // search for ? before url-decoding so we don't accidentally match %3F |
7c673cae FG |
4966 | size_t pos = url_src.find('?'); |
4967 | if (pos == string::npos) { | |
4968 | name_str = url_src; | |
4969 | } else { | |
4970 | name_str = url_src.substr(0, pos); | |
4971 | params_str = url_src.substr(pos + 1); | |
4972 | } | |
4973 | ||
f67539c2 | 4974 | std::string_view dec_src{name_str}; |
3a9019d9 FG |
4975 | if (dec_src[0] == '/') |
4976 | dec_src.remove_prefix(1); | |
7c673cae | 4977 | |
3a9019d9 | 4978 | pos = dec_src.find('/'); |
494da23a | 4979 | if (pos == string::npos) |
7c673cae FG |
4980 | return false; |
4981 | ||
494da23a TL |
4982 | bucket_name = url_decode(dec_src.substr(0, pos)); |
4983 | key.name = url_decode(dec_src.substr(pos + 1)); | |
7c673cae FG |
4984 | |
4985 | if (key.name.empty()) { | |
4986 | return false; | |
4987 | } | |
4988 | ||
3a9019d9 | 4989 | if (! params_str.empty()) { |
7c673cae | 4990 | RGWHTTPArgs args; |
f67539c2 | 4991 | args.set(std::string(params_str)); |
b3b6e05e | 4992 | args.parse(s); |
7c673cae FG |
4993 | |
4994 | key.instance = args.get("versionId", NULL); | |
4995 | } | |
4996 | ||
4997 | return true; | |
4998 | } | |
4999 | ||
f67539c2 | 5000 | int RGWCopyObj::verify_permission(optional_yield y) |
7c673cae | 5001 | { |
31f18b77 | 5002 | RGWAccessControlPolicy src_acl(s->cct); |
11fdf7f2 | 5003 | boost::optional<Policy> src_policy; |
f67539c2 | 5004 | op_ret = get_params(y); |
7c673cae FG |
5005 | if (op_ret < 0) |
5006 | return op_ret; | |
5007 | ||
5008 | op_ret = get_system_versioning_params(s, &olh_epoch, &version_id); | |
5009 | if (op_ret < 0) { | |
5010 | return op_ret; | |
5011 | } | |
7c673cae | 5012 | |
f67539c2 TL |
5013 | /* This is a bit of a hack; create an empty bucket, then load it below. */ |
5014 | op_ret = store->get_bucket(s->user.get(), RGWBucketInfo(), &src_bucket); | |
7c673cae FG |
5015 | if (op_ret < 0) { |
5016 | if (op_ret == -ENOENT) { | |
5017 | op_ret = -ERR_NO_SUCH_BUCKET; | |
5018 | } | |
5019 | return op_ret; | |
5020 | } | |
5021 | ||
b3b6e05e | 5022 | op_ret = src_bucket->load_by_name(this, src_tenant_name, src_bucket_name, s->bucket_instance_id, |
f67539c2 TL |
5023 | s->sysobj_ctx, s->yield); |
5024 | if (op_ret < 0) { | |
5025 | if (op_ret == -ENOENT) { | |
5026 | op_ret = -ERR_NO_SUCH_BUCKET; | |
5027 | } | |
5028 | return op_ret; | |
5029 | } | |
7c673cae | 5030 | |
f67539c2 | 5031 | src_object->set_bucket(src_bucket.get()); |
7c673cae FG |
5032 | /* get buckets info (source and dest) */ |
5033 | if (s->local_source && source_zone.empty()) { | |
f67539c2 TL |
5034 | src_object->set_atomic(s->obj_ctx); |
5035 | src_object->set_prefetch_data(s->obj_ctx); | |
7c673cae | 5036 | |
11fdf7f2 TL |
5037 | rgw_placement_rule src_placement; |
5038 | ||
7c673cae | 5039 | /* check source object permissions */ |
b3b6e05e | 5040 | op_ret = read_obj_policy(this, store, s, src_bucket->get_info(), src_bucket->get_attrs(), &src_acl, &src_placement.storage_class, |
f67539c2 | 5041 | src_policy, src_bucket.get(), src_object.get(), y); |
7c673cae FG |
5042 | if (op_ret < 0) { |
5043 | return op_ret; | |
5044 | } | |
5045 | ||
11fdf7f2 TL |
5046 | /* follow up on previous checks that required reading source object head */ |
5047 | if (need_to_check_storage_class) { | |
f67539c2 | 5048 | src_placement.inherit_from(src_bucket->get_placement_rule()); |
11fdf7f2 TL |
5049 | |
5050 | op_ret = check_storage_class(src_placement); | |
5051 | if (op_ret < 0) { | |
5052 | return op_ret; | |
5053 | } | |
5054 | } | |
5055 | ||
7c673cae | 5056 | /* admin request overrides permission checks */ |
31f18b77 FG |
5057 | if (!s->auth.identity->is_admin_of(src_acl.get_owner().get_id())) { |
5058 | if (src_policy) { | |
5059 | auto e = src_policy->eval(s->env, *s->auth.identity, | |
f67539c2 | 5060 | src_object->get_instance().empty() ? |
31f18b77 FG |
5061 | rgw::IAM::s3GetObject : |
5062 | rgw::IAM::s3GetObjectVersion, | |
f67539c2 | 5063 | ARN(src_object->get_obj())); |
31f18b77 FG |
5064 | if (e == Effect::Deny) { |
5065 | return -EACCES; | |
5066 | } else if (e == Effect::Pass && | |
11fdf7f2 | 5067 | !src_acl.verify_permission(this, *s->auth.identity, s->perm_mask, |
31f18b77 FG |
5068 | RGW_PERM_READ)) { |
5069 | return -EACCES; | |
5070 | } | |
11fdf7f2 | 5071 | } else if (!src_acl.verify_permission(this, *s->auth.identity, |
31f18b77 FG |
5072 | s->perm_mask, |
5073 | RGW_PERM_READ)) { | |
5074 | return -EACCES; | |
5075 | } | |
7c673cae FG |
5076 | } |
5077 | } | |
5078 | ||
5079 | RGWAccessControlPolicy dest_bucket_policy(s->cct); | |
7c673cae FG |
5080 | |
5081 | if (src_bucket_name.compare(dest_bucket_name) == 0) { /* will only happen if s->local_source | |
5082 | or intra region sync */ | |
f67539c2 | 5083 | dest_bucket = src_bucket->clone(); |
7c673cae | 5084 | } else { |
f67539c2 TL |
5085 | op_ret = store->get_bucket(s->user.get(), RGWBucketInfo(), &dest_bucket); |
5086 | if (op_ret < 0) { | |
5087 | if (op_ret == -ENOENT) { | |
5088 | op_ret = -ERR_NO_SUCH_BUCKET; | |
5089 | } | |
5090 | return op_ret; | |
5091 | } | |
b3b6e05e | 5092 | op_ret = dest_bucket->load_by_name(this, dest_tenant_name, dest_bucket_name, std::string(), |
f67539c2 | 5093 | s->sysobj_ctx, s->yield); |
7c673cae FG |
5094 | if (op_ret < 0) { |
5095 | if (op_ret == -ENOENT) { | |
5096 | op_ret = -ERR_NO_SUCH_BUCKET; | |
5097 | } | |
5098 | return op_ret; | |
5099 | } | |
5100 | } | |
5101 | ||
f67539c2 TL |
5102 | dest_object = store->get_object(rgw_obj_key(dest_obj_name)); |
5103 | dest_object->set_bucket(dest_bucket.get()); | |
5104 | dest_object->set_atomic(s->obj_ctx); | |
7c673cae FG |
5105 | |
5106 | /* check dest bucket permissions */ | |
b3b6e05e | 5107 | op_ret = read_bucket_policy(this, store, s, dest_bucket->get_info(), |
f67539c2 TL |
5108 | dest_bucket->get_attrs(), |
5109 | &dest_bucket_policy, dest_bucket->get_key(), y); | |
7c673cae FG |
5110 | if (op_ret < 0) { |
5111 | return op_ret; | |
5112 | } | |
f67539c2 | 5113 | auto dest_iam_policy = get_iam_policy_from_attr(s->cct, dest_bucket->get_attrs(), dest_bucket->get_tenant()); |
7c673cae | 5114 | /* admin request overrides permission checks */ |
11fdf7f2 TL |
5115 | if (! s->auth.identity->is_admin_of(dest_policy.get_owner().get_id())){ |
5116 | if (dest_iam_policy != boost::none) { | |
5117 | rgw_add_to_iam_environment(s->env, "s3:x-amz-copy-source", copy_source); | |
494da23a TL |
5118 | if (md_directive) |
5119 | rgw_add_to_iam_environment(s->env, "s3:x-amz-metadata-directive", | |
5120 | *md_directive); | |
11fdf7f2 TL |
5121 | |
5122 | auto e = dest_iam_policy->eval(s->env, *s->auth.identity, | |
5123 | rgw::IAM::s3PutObject, | |
f67539c2 | 5124 | ARN(dest_object->get_obj())); |
11fdf7f2 TL |
5125 | if (e == Effect::Deny) { |
5126 | return -EACCES; | |
5127 | } else if (e == Effect::Pass && | |
5128 | ! dest_bucket_policy.verify_permission(this, | |
5129 | *s->auth.identity, | |
5130 | s->perm_mask, | |
5131 | RGW_PERM_WRITE)){ | |
5132 | return -EACCES; | |
5133 | } | |
92f5a8d4 TL |
5134 | } else if (! dest_bucket_policy.verify_permission(this, *s->auth.identity, s->perm_mask, |
5135 | RGW_PERM_WRITE)) { | |
5136 | return -EACCES; | |
11fdf7f2 | 5137 | } |
92f5a8d4 | 5138 | |
7c673cae FG |
5139 | } |
5140 | ||
5141 | op_ret = init_dest_policy(); | |
5142 | if (op_ret < 0) { | |
5143 | return op_ret; | |
5144 | } | |
5145 | ||
5146 | return 0; | |
5147 | } | |
5148 | ||
5149 | ||
5150 | int RGWCopyObj::init_common() | |
5151 | { | |
5152 | if (if_mod) { | |
5153 | if (parse_time(if_mod, &mod_time) < 0) { | |
5154 | op_ret = -EINVAL; | |
5155 | return op_ret; | |
5156 | } | |
5157 | mod_ptr = &mod_time; | |
5158 | } | |
5159 | ||
5160 | if (if_unmod) { | |
5161 | if (parse_time(if_unmod, &unmod_time) < 0) { | |
5162 | op_ret = -EINVAL; | |
5163 | return op_ret; | |
5164 | } | |
5165 | unmod_ptr = &unmod_time; | |
5166 | } | |
5167 | ||
5168 | bufferlist aclbl; | |
5169 | dest_policy.encode(aclbl); | |
5170 | emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); | |
5171 | ||
b3b6e05e | 5172 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs); |
3efd9988 FG |
5173 | if (op_ret < 0) { |
5174 | return op_ret; | |
5175 | } | |
7c673cae FG |
5176 | populate_with_generic_attrs(s, attrs); |
5177 | ||
5178 | return 0; | |
5179 | } | |
5180 | ||
5181 | static void copy_obj_progress_cb(off_t ofs, void *param) | |
5182 | { | |
5183 | RGWCopyObj *op = static_cast<RGWCopyObj *>(param); | |
5184 | op->progress_cb(ofs); | |
5185 | } | |
5186 | ||
5187 | void RGWCopyObj::progress_cb(off_t ofs) | |
5188 | { | |
5189 | if (!s->cct->_conf->rgw_copy_obj_progress) | |
5190 | return; | |
5191 | ||
5192 | if (ofs - last_ofs < s->cct->_conf->rgw_copy_obj_progress_every_bytes) | |
5193 | return; | |
5194 | ||
5195 | send_partial_response(ofs); | |
5196 | ||
5197 | last_ofs = ofs; | |
5198 | } | |
5199 | ||
5200 | void RGWCopyObj::pre_exec() | |
5201 | { | |
5202 | rgw_bucket_object_pre_exec(s); | |
5203 | } | |
5204 | ||
f67539c2 | 5205 | void RGWCopyObj::execute(optional_yield y) |
7c673cae FG |
5206 | { |
5207 | if (init_common() < 0) | |
5208 | return; | |
5209 | ||
f67539c2 TL |
5210 | if (! s->object->get_bucket()) { |
5211 | s->bucket = src_object->get_bucket()->clone(); | |
5212 | s->object->set_bucket(s->bucket.get()); | |
5213 | } | |
5214 | ||
5215 | // make reservation for notification if needed | |
b3b6e05e | 5216 | rgw::notify::reservation_t res(this, store, s, s->object.get()); |
f67539c2 | 5217 | const auto event_type = rgw::notify::ObjectCreatedCopy; |
b3b6e05e | 5218 | op_ret = rgw::notify::publish_reserve(this, event_type, res, nullptr); |
f67539c2 TL |
5219 | if (op_ret < 0) { |
5220 | return; | |
5221 | } | |
7c673cae | 5222 | |
11fdf7f2 | 5223 | if ( ! version_id.empty()) { |
f67539c2 TL |
5224 | dest_object->set_instance(version_id); |
5225 | } else if (dest_bucket->versioning_enabled()) { | |
5226 | dest_object->gen_rand_obj_instance_name(); | |
11fdf7f2 TL |
5227 | } |
5228 | ||
f67539c2 TL |
5229 | src_object->set_atomic(s->obj_ctx); |
5230 | dest_object->set_atomic(s->obj_ctx); | |
7c673cae FG |
5231 | |
5232 | encode_delete_at_attr(delete_at, attrs); | |
5233 | ||
f6b5b4d7 TL |
5234 | if (!s->system_request) { // no quota enforcement for system requests |
5235 | // get src object size (cached in obj_ctx from verify_permission()) | |
5236 | RGWObjState* astate = nullptr; | |
b3b6e05e | 5237 | op_ret = src_object->get_obj_state(this, s->obj_ctx, *src_bucket, &astate, |
f67539c2 | 5238 | s->yield, true); |
f6b5b4d7 TL |
5239 | if (op_ret < 0) { |
5240 | return; | |
5241 | } | |
5242 | // enforce quota against the destination bucket owner | |
f67539c2 TL |
5243 | op_ret = dest_bucket->check_quota(user_quota, bucket_quota, |
5244 | astate->accounted_size, y); | |
f6b5b4d7 TL |
5245 | if (op_ret < 0) { |
5246 | return; | |
5247 | } | |
5248 | } | |
5249 | ||
7c673cae FG |
5250 | bool high_precision_time = (s->system_request); |
5251 | ||
5252 | /* Handle object versioning of Swift API. In case of copying to remote this | |
5253 | * should fail gently (op_ret == 0) as the dst_obj will not exist here. */ | |
f67539c2 | 5254 | op_ret = dest_object->swift_versioning_copy(s->obj_ctx, this, s->yield); |
7c673cae FG |
5255 | if (op_ret < 0) { |
5256 | return; | |
5257 | } | |
5258 | ||
f67539c2 TL |
5259 | RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx); |
5260 | op_ret = src_object->copy_object(obj_ctx, | |
5261 | s->user.get(), | |
9f95a23c TL |
5262 | &s->info, |
5263 | source_zone, | |
f67539c2 TL |
5264 | dest_object.get(), |
5265 | dest_bucket.get(), | |
5266 | src_bucket.get(), | |
9f95a23c TL |
5267 | s->dest_placement, |
5268 | &src_mtime, | |
5269 | &mtime, | |
5270 | mod_ptr, | |
5271 | unmod_ptr, | |
5272 | high_precision_time, | |
5273 | if_match, | |
5274 | if_nomatch, | |
5275 | attrs_mod, | |
5276 | copy_if_newer, | |
f67539c2 TL |
5277 | attrs, |
5278 | RGWObjCategory::Main, | |
9f95a23c | 5279 | olh_epoch, |
f67539c2 | 5280 | delete_at, |
9f95a23c TL |
5281 | (version_id.empty() ? NULL : &version_id), |
5282 | &s->req_id, /* use req_id as tag */ | |
5283 | &etag, | |
5284 | copy_obj_progress_cb, (void *)this, | |
5285 | this, | |
5286 | s->yield); | |
5287 | ||
f67539c2 | 5288 | // send request to notification manager |
b3b6e05e | 5289 | const auto ret = rgw::notify::publish_commit(s->object.get(), s->obj_size, mtime, etag, event_type, res, this); |
eafe8130 | 5290 | if (ret < 0) { |
f67539c2 TL |
5291 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
5292 | // too late to rollback operation, hence op_ret is not set here | |
eafe8130 | 5293 | } |
7c673cae FG |
5294 | } |
5295 | ||
f67539c2 | 5296 | int RGWGetACLs::verify_permission(optional_yield y) |
7c673cae FG |
5297 | { |
5298 | bool perm; | |
f67539c2 TL |
5299 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
5300 | auto iam_action = s->object->get_instance().empty() ? | |
11fdf7f2 TL |
5301 | rgw::IAM::s3GetObjectAcl : |
5302 | rgw::IAM::s3GetObjectVersionAcl; | |
5303 | ||
5304 | if (s->iam_policy && s->iam_policy->has_partial_conditional(S3_EXISTING_OBJTAG)){ | |
b3b6e05e | 5305 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
5306 | } |
5307 | if (! s->iam_user_policies.empty()) { | |
5308 | for (auto& user_policy : s->iam_user_policies) { | |
5309 | if (user_policy.has_partial_conditional(S3_EXISTING_OBJTAG)) { | |
b3b6e05e | 5310 | rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 TL |
5311 | } |
5312 | } | |
5313 | } | |
5314 | perm = verify_object_permission(this, s, iam_action); | |
7c673cae | 5315 | } else { |
a8e16298 TL |
5316 | if (!s->bucket_exists) { |
5317 | return -ERR_NO_SUCH_BUCKET; | |
5318 | } | |
11fdf7f2 | 5319 | perm = verify_bucket_permission(this, s, rgw::IAM::s3GetBucketAcl); |
7c673cae FG |
5320 | } |
5321 | if (!perm) | |
5322 | return -EACCES; | |
5323 | ||
5324 | return 0; | |
5325 | } | |
5326 | ||
5327 | void RGWGetACLs::pre_exec() | |
5328 | { | |
5329 | rgw_bucket_object_pre_exec(s); | |
5330 | } | |
5331 | ||
f67539c2 | 5332 | void RGWGetACLs::execute(optional_yield y) |
7c673cae FG |
5333 | { |
5334 | stringstream ss; | |
c07f9fc5 | 5335 | RGWAccessControlPolicy* const acl = \ |
f67539c2 | 5336 | (!rgw::sal::RGWObject::empty(s->object.get()) ? s->object_acl.get() : s->bucket_acl.get()); |
c07f9fc5 FG |
5337 | RGWAccessControlPolicy_S3* const s3policy = \ |
5338 | static_cast<RGWAccessControlPolicy_S3*>(acl); | |
7c673cae FG |
5339 | s3policy->to_xml(ss); |
5340 | acls = ss.str(); | |
5341 | } | |
5342 | ||
5343 | ||
5344 | ||
f67539c2 | 5345 | int RGWPutACLs::verify_permission(optional_yield y) |
7c673cae FG |
5346 | { |
5347 | bool perm; | |
11fdf7f2 TL |
5348 | |
5349 | rgw_add_to_iam_environment(s->env, "s3:x-amz-acl", s->canned_acl); | |
5350 | ||
5351 | rgw_add_grant_to_iam_environment(s->env, s); | |
f67539c2 TL |
5352 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
5353 | auto iam_action = s->object->get_instance().empty() ? rgw::IAM::s3PutObjectAcl : rgw::IAM::s3PutObjectVersionAcl; | |
b3b6e05e | 5354 | op_ret = rgw_iam_add_existing_objtags(this, store, s, iam_action); |
11fdf7f2 | 5355 | perm = verify_object_permission(this, s, iam_action); |
7c673cae | 5356 | } else { |
11fdf7f2 | 5357 | perm = verify_bucket_permission(this, s, rgw::IAM::s3PutBucketAcl); |
7c673cae FG |
5358 | } |
5359 | if (!perm) | |
5360 | return -EACCES; | |
5361 | ||
5362 | return 0; | |
5363 | } | |
5364 | ||
f67539c2 | 5365 | int RGWGetLC::verify_permission(optional_yield y) |
7c673cae FG |
5366 | { |
5367 | bool perm; | |
11fdf7f2 | 5368 | perm = verify_bucket_permission(this, s, rgw::IAM::s3GetLifecycleConfiguration); |
7c673cae FG |
5369 | if (!perm) |
5370 | return -EACCES; | |
5371 | ||
5372 | return 0; | |
5373 | } | |
5374 | ||
f67539c2 | 5375 | int RGWPutLC::verify_permission(optional_yield y) |
7c673cae FG |
5376 | { |
5377 | bool perm; | |
11fdf7f2 | 5378 | perm = verify_bucket_permission(this, s, rgw::IAM::s3PutLifecycleConfiguration); |
7c673cae FG |
5379 | if (!perm) |
5380 | return -EACCES; | |
5381 | ||
5382 | return 0; | |
5383 | } | |
5384 | ||
f67539c2 | 5385 | int RGWDeleteLC::verify_permission(optional_yield y) |
7c673cae FG |
5386 | { |
5387 | bool perm; | |
11fdf7f2 | 5388 | perm = verify_bucket_permission(this, s, rgw::IAM::s3PutLifecycleConfiguration); |
7c673cae FG |
5389 | if (!perm) |
5390 | return -EACCES; | |
5391 | ||
5392 | return 0; | |
5393 | } | |
5394 | ||
5395 | void RGWPutACLs::pre_exec() | |
5396 | { | |
5397 | rgw_bucket_object_pre_exec(s); | |
5398 | } | |
5399 | ||
5400 | void RGWGetLC::pre_exec() | |
5401 | { | |
5402 | rgw_bucket_object_pre_exec(s); | |
5403 | } | |
5404 | ||
5405 | void RGWPutLC::pre_exec() | |
5406 | { | |
5407 | rgw_bucket_object_pre_exec(s); | |
5408 | } | |
5409 | ||
5410 | void RGWDeleteLC::pre_exec() | |
5411 | { | |
5412 | rgw_bucket_object_pre_exec(s); | |
5413 | } | |
5414 | ||
f67539c2 | 5415 | void RGWPutACLs::execute(optional_yield y) |
7c673cae FG |
5416 | { |
5417 | bufferlist bl; | |
5418 | ||
5419 | RGWAccessControlPolicy_S3 *policy = NULL; | |
5420 | RGWACLXMLParser_S3 parser(s->cct); | |
5421 | RGWAccessControlPolicy_S3 new_policy(s->cct); | |
5422 | stringstream ss; | |
7c673cae FG |
5423 | |
5424 | op_ret = 0; /* XXX redundant? */ | |
5425 | ||
5426 | if (!parser.init()) { | |
5427 | op_ret = -EINVAL; | |
5428 | return; | |
5429 | } | |
5430 | ||
5431 | ||
c07f9fc5 | 5432 | RGWAccessControlPolicy* const existing_policy = \ |
f67539c2 | 5433 | (rgw::sal::RGWObject::empty(s->object.get()) ? s->bucket_acl.get() : s->object_acl.get()); |
7c673cae FG |
5434 | |
5435 | owner = existing_policy->get_owner(); | |
5436 | ||
f67539c2 | 5437 | op_ret = get_params(y); |
c07f9fc5 FG |
5438 | if (op_ret < 0) { |
5439 | if (op_ret == -ERANGE) { | |
11fdf7f2 | 5440 | ldpp_dout(this, 4) << "The size of request xml data is larger than the max limitation, data size = " |
c07f9fc5 FG |
5441 | << s->length << dendl; |
5442 | op_ret = -ERR_MALFORMED_XML; | |
5443 | s->err.message = "The XML you provided was larger than the maximum " + | |
5444 | std::to_string(s->cct->_conf->rgw_max_put_param_size) + | |
5445 | " bytes allowed."; | |
5446 | } | |
7c673cae | 5447 | return; |
c07f9fc5 | 5448 | } |
7c673cae | 5449 | |
11fdf7f2 TL |
5450 | char* buf = data.c_str(); |
5451 | ldpp_dout(this, 15) << "read len=" << data.length() << " data=" << (buf ? buf : "") << dendl; | |
7c673cae | 5452 | |
11fdf7f2 | 5453 | if (!s->canned_acl.empty() && data.length() > 0) { |
7c673cae FG |
5454 | op_ret = -EINVAL; |
5455 | return; | |
5456 | } | |
5457 | ||
5458 | if (!s->canned_acl.empty() || s->has_acl_header) { | |
5459 | op_ret = get_policy_from_state(store, s, ss); | |
5460 | if (op_ret < 0) | |
5461 | return; | |
5462 | ||
11fdf7f2 TL |
5463 | data.clear(); |
5464 | data.append(ss.str()); | |
7c673cae FG |
5465 | } |
5466 | ||
11fdf7f2 | 5467 | if (!parser.parse(data.c_str(), data.length(), 1)) { |
7c673cae FG |
5468 | op_ret = -EINVAL; |
5469 | return; | |
5470 | } | |
5471 | policy = static_cast<RGWAccessControlPolicy_S3 *>(parser.find_first("AccessControlPolicy")); | |
5472 | if (!policy) { | |
5473 | op_ret = -EINVAL; | |
5474 | return; | |
5475 | } | |
5476 | ||
c07f9fc5 FG |
5477 | const RGWAccessControlList& req_acl = policy->get_acl(); |
5478 | const multimap<string, ACLGrant>& req_grant_map = req_acl.get_grant_map(); | |
5479 | #define ACL_GRANTS_MAX_NUM 100 | |
5480 | int max_num = s->cct->_conf->rgw_acl_grants_max_num; | |
5481 | if (max_num < 0) { | |
5482 | max_num = ACL_GRANTS_MAX_NUM; | |
5483 | } | |
5484 | ||
5485 | int grants_num = req_grant_map.size(); | |
5486 | if (grants_num > max_num) { | |
11fdf7f2 TL |
5487 | ldpp_dout(this, 4) << "An acl can have up to " << max_num |
5488 | << " grants, request acl grants num: " << grants_num << dendl; | |
9f95a23c | 5489 | op_ret = -ERR_LIMIT_EXCEEDED; |
c07f9fc5 FG |
5490 | s->err.message = "The request is rejected, because the acl grants number you requested is larger than the maximum " |
5491 | + std::to_string(max_num) | |
5492 | + " grants allowed in an acl."; | |
5493 | return; | |
5494 | } | |
5495 | ||
7c673cae | 5496 | // forward bucket acl requests to meta master zone |
f67539c2 | 5497 | if ((rgw::sal::RGWObject::empty(s->object.get()))) { |
7c673cae FG |
5498 | bufferlist in_data; |
5499 | // include acl data unless it was generated from a canned_acl | |
5500 | if (s->canned_acl.empty()) { | |
11fdf7f2 | 5501 | in_data.append(data); |
7c673cae | 5502 | } |
b3b6e05e | 5503 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
7c673cae | 5504 | if (op_ret < 0) { |
11fdf7f2 | 5505 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; |
7c673cae FG |
5506 | return; |
5507 | } | |
5508 | } | |
5509 | ||
11fdf7f2 TL |
5510 | if (s->cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) { |
5511 | ldpp_dout(this, 15) << "Old AccessControlPolicy"; | |
7c673cae FG |
5512 | policy->to_xml(*_dout); |
5513 | *_dout << dendl; | |
5514 | } | |
5515 | ||
b3b6e05e | 5516 | op_ret = policy->rebuild(this, store->ctl()->user, &owner, new_policy, s->err.message); |
7c673cae FG |
5517 | if (op_ret < 0) |
5518 | return; | |
5519 | ||
11fdf7f2 TL |
5520 | if (s->cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) { |
5521 | ldpp_dout(this, 15) << "New AccessControlPolicy:"; | |
7c673cae FG |
5522 | new_policy.to_xml(*_dout); |
5523 | *_dout << dendl; | |
5524 | } | |
5525 | ||
9f95a23c TL |
5526 | if (s->bucket_access_conf && |
5527 | s->bucket_access_conf->block_public_acls() && | |
b3b6e05e | 5528 | new_policy.is_public(this)) { |
9f95a23c TL |
5529 | op_ret = -EACCES; |
5530 | return; | |
5531 | } | |
7c673cae | 5532 | new_policy.encode(bl); |
f67539c2 TL |
5533 | map<string, bufferlist> attrs; |
5534 | ||
5535 | if (!rgw::sal::RGWObject::empty(s->object.get())) { | |
5536 | s->object->set_atomic(s->obj_ctx); | |
7c673cae | 5537 | //if instance is empty, we should modify the latest object |
b3b6e05e | 5538 | op_ret = s->object->modify_obj_attrs(s->obj_ctx, RGW_ATTR_ACL, bl, s->yield, this); |
7c673cae | 5539 | } else { |
9f95a23c | 5540 | map<string,bufferlist> attrs = s->bucket_attrs; |
7c673cae | 5541 | attrs[RGW_ATTR_ACL] = bl; |
f67539c2 TL |
5542 | op_ret = store->ctl()->bucket->set_bucket_instance_attrs(s->bucket->get_info(), attrs, |
5543 | &s->bucket->get_info().objv_tracker, | |
b3b6e05e | 5544 | s->yield, this); |
7c673cae FG |
5545 | } |
5546 | if (op_ret == -ECANCELED) { | |
5547 | op_ret = 0; /* lost a race, but it's ok because acls are immutable */ | |
5548 | } | |
5549 | } | |
5550 | ||
f67539c2 | 5551 | void RGWPutLC::execute(optional_yield y) |
7c673cae FG |
5552 | { |
5553 | bufferlist bl; | |
5554 | ||
11fdf7f2 TL |
5555 | RGWLifecycleConfiguration_S3 config(s->cct); |
5556 | RGWXMLParser parser; | |
7c673cae FG |
5557 | RGWLifecycleConfiguration_S3 new_config(s->cct); |
5558 | ||
b32b8144 FG |
5559 | content_md5 = s->info.env->get("HTTP_CONTENT_MD5"); |
5560 | if (content_md5 == nullptr) { | |
5561 | op_ret = -ERR_INVALID_REQUEST; | |
5562 | s->err.message = "Missing required header for this request: Content-MD5"; | |
11fdf7f2 | 5563 | ldpp_dout(this, 5) << s->err.message << dendl; |
b32b8144 FG |
5564 | return; |
5565 | } | |
5566 | ||
5567 | std::string content_md5_bin; | |
5568 | try { | |
f67539c2 | 5569 | content_md5_bin = rgw::from_base64(std::string_view(content_md5)); |
b32b8144 FG |
5570 | } catch (...) { |
5571 | s->err.message = "Request header Content-MD5 contains character " | |
5572 | "that is not base64 encoded."; | |
11fdf7f2 | 5573 | ldpp_dout(this, 5) << s->err.message << dendl; |
b32b8144 FG |
5574 | op_ret = -ERR_BAD_DIGEST; |
5575 | return; | |
5576 | } | |
5577 | ||
7c673cae FG |
5578 | if (!parser.init()) { |
5579 | op_ret = -EINVAL; | |
5580 | return; | |
5581 | } | |
5582 | ||
f67539c2 | 5583 | op_ret = get_params(y); |
7c673cae FG |
5584 | if (op_ret < 0) |
5585 | return; | |
5586 | ||
11fdf7f2 TL |
5587 | char* buf = data.c_str(); |
5588 | ldpp_dout(this, 15) << "read len=" << data.length() << " data=" << (buf ? buf : "") << dendl; | |
7c673cae | 5589 | |
b32b8144 FG |
5590 | MD5 data_hash; |
5591 | unsigned char data_hash_res[CEPH_CRYPTO_MD5_DIGESTSIZE]; | |
11fdf7f2 | 5592 | data_hash.Update(reinterpret_cast<const unsigned char*>(buf), data.length()); |
b32b8144 FG |
5593 | data_hash.Final(data_hash_res); |
5594 | ||
5595 | if (memcmp(data_hash_res, content_md5_bin.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE) != 0) { | |
5596 | op_ret = -ERR_BAD_DIGEST; | |
5597 | s->err.message = "The Content-MD5 you specified did not match what we received."; | |
11fdf7f2 | 5598 | ldpp_dout(this, 5) << s->err.message |
b32b8144 FG |
5599 | << " Specified content md5: " << content_md5 |
5600 | << ", calculated content md5: " << data_hash_res | |
5601 | << dendl; | |
5602 | return; | |
5603 | } | |
5604 | ||
11fdf7f2 | 5605 | if (!parser.parse(buf, data.length(), 1)) { |
7c673cae FG |
5606 | op_ret = -ERR_MALFORMED_XML; |
5607 | return; | |
5608 | } | |
11fdf7f2 TL |
5609 | |
5610 | try { | |
5611 | RGWXMLDecoder::decode_xml("LifecycleConfiguration", config, &parser); | |
5612 | } catch (RGWXMLDecoder::err& err) { | |
5613 | ldpp_dout(this, 5) << "Bad lifecycle configuration: " << err << dendl; | |
7c673cae FG |
5614 | op_ret = -ERR_MALFORMED_XML; |
5615 | return; | |
5616 | } | |
5617 | ||
f67539c2 | 5618 | op_ret = config.rebuild(new_config); |
7c673cae FG |
5619 | if (op_ret < 0) |
5620 | return; | |
5621 | ||
11fdf7f2 TL |
5622 | if (s->cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) { |
5623 | XMLFormatter xf; | |
5624 | new_config.dump_xml(&xf); | |
5625 | stringstream ss; | |
5626 | xf.flush(ss); | |
5627 | ldpp_dout(this, 15) << "New LifecycleConfiguration:" << ss.str() << dendl; | |
7c673cae | 5628 | } |
11fdf7f2 | 5629 | |
b3b6e05e | 5630 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, data, nullptr, s->info, y); |
f67539c2 TL |
5631 | if (op_ret < 0) { |
5632 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
5633 | return; | |
494da23a TL |
5634 | } |
5635 | ||
f67539c2 | 5636 | op_ret = store->get_rgwlc()->set_bucket_config(s->bucket->get_info(), s->bucket_attrs, &new_config); |
11fdf7f2 | 5637 | if (op_ret < 0) { |
7c673cae | 5638 | return; |
11fdf7f2 | 5639 | } |
7c673cae FG |
5640 | return; |
5641 | } | |
5642 | ||
f67539c2 | 5643 | void RGWDeleteLC::execute(optional_yield y) |
7c673cae | 5644 | { |
f67539c2 | 5645 | bufferlist data; |
b3b6e05e | 5646 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, data, nullptr, s->info, y); |
f67539c2 TL |
5647 | if (op_ret < 0) { |
5648 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
5649 | return; | |
494da23a | 5650 | } |
11fdf7f2 | 5651 | |
f67539c2 | 5652 | op_ret = store->get_rgwlc()->remove_bucket_config(s->bucket->get_info(), s->bucket_attrs); |
11fdf7f2 TL |
5653 | if (op_ret < 0) { |
5654 | return; | |
5655 | } | |
7c673cae FG |
5656 | return; |
5657 | } | |
5658 | ||
f67539c2 | 5659 | int RGWGetCORS::verify_permission(optional_yield y) |
7c673cae | 5660 | { |
b32b8144 | 5661 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketCORS); |
7c673cae FG |
5662 | } |
5663 | ||
f67539c2 | 5664 | void RGWGetCORS::execute(optional_yield y) |
7c673cae FG |
5665 | { |
5666 | op_ret = read_bucket_cors(); | |
5667 | if (op_ret < 0) | |
5668 | return ; | |
5669 | ||
5670 | if (!cors_exist) { | |
11fdf7f2 TL |
5671 | ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl; |
5672 | op_ret = -ERR_NO_CORS_FOUND; | |
7c673cae FG |
5673 | return; |
5674 | } | |
5675 | } | |
5676 | ||
f67539c2 | 5677 | int RGWPutCORS::verify_permission(optional_yield y) |
7c673cae | 5678 | { |
b32b8144 | 5679 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketCORS); |
7c673cae FG |
5680 | } |
5681 | ||
f67539c2 | 5682 | void RGWPutCORS::execute(optional_yield y) |
7c673cae FG |
5683 | { |
5684 | rgw_raw_obj obj; | |
5685 | ||
f67539c2 | 5686 | op_ret = get_params(y); |
7c673cae FG |
5687 | if (op_ret < 0) |
5688 | return; | |
5689 | ||
b3b6e05e | 5690 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
5691 | if (op_ret < 0) { |
5692 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
5693 | return; | |
31f18b77 FG |
5694 | } |
5695 | ||
b3b6e05e | 5696 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 | 5697 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
b32b8144 | 5698 | attrs[RGW_ATTR_CORS] = cors_bl; |
b3b6e05e | 5699 | return s->bucket->set_instance_attrs(this, attrs, s->yield); |
b32b8144 | 5700 | }); |
7c673cae FG |
5701 | } |
5702 | ||
f67539c2 | 5703 | int RGWDeleteCORS::verify_permission(optional_yield y) |
7c673cae | 5704 | { |
b32b8144 FG |
5705 | // No separate delete permission |
5706 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketCORS); | |
7c673cae FG |
5707 | } |
5708 | ||
f67539c2 | 5709 | void RGWDeleteCORS::execute(optional_yield y) |
7c673cae | 5710 | { |
f67539c2 | 5711 | bufferlist data; |
b3b6e05e | 5712 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, data, nullptr, s->info, y); |
f67539c2 TL |
5713 | if (op_ret < 0) { |
5714 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
5715 | return; | |
494da23a TL |
5716 | } |
5717 | ||
b3b6e05e | 5718 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
11fdf7f2 | 5719 | op_ret = read_bucket_cors(); |
b32b8144 FG |
5720 | if (op_ret < 0) |
5721 | return op_ret; | |
5722 | ||
11fdf7f2 TL |
5723 | if (!cors_exist) { |
5724 | ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl; | |
5725 | op_ret = -ENOENT; | |
5726 | return op_ret; | |
b32b8144 | 5727 | } |
11fdf7f2 | 5728 | |
f67539c2 | 5729 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
11fdf7f2 | 5730 | attrs.erase(RGW_ATTR_CORS); |
b3b6e05e | 5731 | op_ret = s->bucket->set_instance_attrs(this, attrs, s->yield); |
11fdf7f2 | 5732 | if (op_ret < 0) { |
f67539c2 | 5733 | ldpp_dout(this, 0) << "RGWLC::RGWDeleteCORS() failed to set attrs on bucket=" << s->bucket->get_name() |
11fdf7f2 TL |
5734 | << " returned err=" << op_ret << dendl; |
5735 | } | |
5736 | return op_ret; | |
b32b8144 | 5737 | }); |
7c673cae FG |
5738 | } |
5739 | ||
5740 | void RGWOptionsCORS::get_response_params(string& hdrs, string& exp_hdrs, unsigned *max_age) { | |
5741 | get_cors_response_headers(rule, req_hdrs, hdrs, exp_hdrs, max_age); | |
5742 | } | |
5743 | ||
5744 | int RGWOptionsCORS::validate_cors_request(RGWCORSConfiguration *cc) { | |
5745 | rule = cc->host_name_rule(origin); | |
5746 | if (!rule) { | |
11fdf7f2 | 5747 | ldpp_dout(this, 10) << "There is no cors rule present for " << origin << dendl; |
7c673cae FG |
5748 | return -ENOENT; |
5749 | } | |
5750 | ||
5751 | if (!validate_cors_rule_method(rule, req_meth)) { | |
5752 | return -ENOENT; | |
5753 | } | |
b32b8144 FG |
5754 | |
5755 | if (!validate_cors_rule_header(rule, req_hdrs)) { | |
5756 | return -ENOENT; | |
5757 | } | |
5758 | ||
7c673cae FG |
5759 | return 0; |
5760 | } | |
5761 | ||
f67539c2 | 5762 | void RGWOptionsCORS::execute(optional_yield y) |
7c673cae FG |
5763 | { |
5764 | op_ret = read_bucket_cors(); | |
5765 | if (op_ret < 0) | |
5766 | return; | |
5767 | ||
5768 | origin = s->info.env->get("HTTP_ORIGIN"); | |
5769 | if (!origin) { | |
11fdf7f2 | 5770 | ldpp_dout(this, 0) << "Missing mandatory Origin header" << dendl; |
7c673cae FG |
5771 | op_ret = -EINVAL; |
5772 | return; | |
5773 | } | |
5774 | req_meth = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD"); | |
5775 | if (!req_meth) { | |
11fdf7f2 | 5776 | ldpp_dout(this, 0) << "Missing mandatory Access-control-request-method header" << dendl; |
7c673cae FG |
5777 | op_ret = -EINVAL; |
5778 | return; | |
5779 | } | |
5780 | if (!cors_exist) { | |
11fdf7f2 | 5781 | ldpp_dout(this, 2) << "No CORS configuration set yet for this bucket" << dendl; |
7c673cae FG |
5782 | op_ret = -ENOENT; |
5783 | return; | |
5784 | } | |
5785 | req_hdrs = s->info.env->get("HTTP_ACCESS_CONTROL_REQUEST_HEADERS"); | |
5786 | op_ret = validate_cors_request(&bucket_cors); | |
5787 | if (!rule) { | |
5788 | origin = req_meth = NULL; | |
5789 | return; | |
5790 | } | |
5791 | return; | |
5792 | } | |
5793 | ||
f67539c2 | 5794 | int RGWGetRequestPayment::verify_permission(optional_yield y) |
7c673cae | 5795 | { |
b32b8144 | 5796 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketRequestPayment); |
7c673cae FG |
5797 | } |
5798 | ||
5799 | void RGWGetRequestPayment::pre_exec() | |
5800 | { | |
5801 | rgw_bucket_object_pre_exec(s); | |
5802 | } | |
5803 | ||
f67539c2 | 5804 | void RGWGetRequestPayment::execute(optional_yield y) |
7c673cae | 5805 | { |
f67539c2 | 5806 | requester_pays = s->bucket->get_info().requester_pays; |
7c673cae FG |
5807 | } |
5808 | ||
f67539c2 | 5809 | int RGWSetRequestPayment::verify_permission(optional_yield y) |
7c673cae | 5810 | { |
b32b8144 | 5811 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketRequestPayment); |
7c673cae FG |
5812 | } |
5813 | ||
5814 | void RGWSetRequestPayment::pre_exec() | |
5815 | { | |
5816 | rgw_bucket_object_pre_exec(s); | |
5817 | } | |
5818 | ||
f67539c2 | 5819 | void RGWSetRequestPayment::execute(optional_yield y) |
7c673cae | 5820 | { |
494da23a | 5821 | |
b3b6e05e | 5822 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, in_data, nullptr, s->info, y); |
f67539c2 TL |
5823 | if (op_ret < 0) { |
5824 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
5825 | return; | |
494da23a TL |
5826 | } |
5827 | ||
f67539c2 | 5828 | op_ret = get_params(y); |
7c673cae FG |
5829 | |
5830 | if (op_ret < 0) | |
5831 | return; | |
5832 | ||
f67539c2 | 5833 | s->bucket->get_info().requester_pays = requester_pays; |
b3b6e05e | 5834 | op_ret = s->bucket->put_instance_info(this, false, real_time()); |
7c673cae | 5835 | if (op_ret < 0) { |
f67539c2 | 5836 | ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket->get_name() |
7c673cae FG |
5837 | << " returned err=" << op_ret << dendl; |
5838 | return; | |
5839 | } | |
f67539c2 | 5840 | s->bucket_attrs = s->bucket->get_attrs(); |
7c673cae FG |
5841 | } |
5842 | ||
f67539c2 | 5843 | int RGWInitMultipart::verify_permission(optional_yield y) |
7c673cae | 5844 | { |
522d829b TL |
5845 | if (s->iam_policy || ! s->iam_user_policies.empty() || !s->session_policies.empty()) { |
5846 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, | |
11fdf7f2 TL |
5847 | boost::none, |
5848 | rgw::IAM::s3PutObject, | |
f67539c2 | 5849 | s->object->get_obj()); |
522d829b | 5850 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
5851 | return -EACCES; |
5852 | } | |
5853 | ||
5854 | rgw::IAM::Effect e = Effect::Pass; | |
522d829b | 5855 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
5856 | if (s->iam_policy) { |
5857 | e = s->iam_policy->eval(s->env, *s->auth.identity, | |
31f18b77 | 5858 | rgw::IAM::s3PutObject, |
522d829b TL |
5859 | s->object->get_obj(), |
5860 | princ_type); | |
11fdf7f2 | 5861 | } |
522d829b | 5862 | if (e == Effect::Deny) { |
31f18b77 | 5863 | return -EACCES; |
522d829b TL |
5864 | } |
5865 | ||
5866 | if (!s->session_policies.empty()) { | |
5867 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
5868 | boost::none, | |
5869 | rgw::IAM::s3PutObject, | |
5870 | s->object->get_obj()); | |
5871 | if (session_policy_res == Effect::Deny) { | |
5872 | return -EACCES; | |
5873 | } | |
5874 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
5875 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
5876 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
5877 | (session_policy_res == Effect::Allow && e == Effect::Allow)) { | |
5878 | return 0; | |
5879 | } | |
5880 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
5881 | //Intersection of session policy and identity policy plus bucket policy | |
5882 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || e == Effect::Allow) { | |
5883 | return 0; | |
5884 | } | |
5885 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
5886 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
5887 | return 0; | |
5888 | } | |
5889 | } | |
5890 | return -EACCES; | |
5891 | } | |
5892 | if (e == Effect::Allow || identity_policy_res == Effect::Allow) { | |
11fdf7f2 | 5893 | return 0; |
31f18b77 FG |
5894 | } |
5895 | } | |
5896 | ||
11fdf7f2 | 5897 | if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae | 5898 | return -EACCES; |
31f18b77 | 5899 | } |
7c673cae FG |
5900 | |
5901 | return 0; | |
5902 | } | |
5903 | ||
5904 | void RGWInitMultipart::pre_exec() | |
5905 | { | |
5906 | rgw_bucket_object_pre_exec(s); | |
5907 | } | |
5908 | ||
f67539c2 | 5909 | void RGWInitMultipart::execute(optional_yield y) |
7c673cae FG |
5910 | { |
5911 | bufferlist aclbl; | |
f67539c2 | 5912 | rgw::sal::RGWAttrs attrs; |
7c673cae | 5913 | |
f67539c2 | 5914 | if (get_params(y) < 0) |
7c673cae FG |
5915 | return; |
5916 | ||
f67539c2 | 5917 | if (rgw::sal::RGWObject::empty(s->object.get())) |
7c673cae FG |
5918 | return; |
5919 | ||
5920 | policy.encode(aclbl); | |
5921 | attrs[RGW_ATTR_ACL] = aclbl; | |
5922 | ||
5923 | populate_with_generic_attrs(s, attrs); | |
5924 | ||
5925 | /* select encryption mode */ | |
5926 | op_ret = prepare_encryption(attrs); | |
5927 | if (op_ret != 0) | |
5928 | return; | |
5929 | ||
b3b6e05e | 5930 | op_ret = rgw_get_request_metadata(this, s->cct, s->info, attrs); |
3efd9988 FG |
5931 | if (op_ret < 0) { |
5932 | return; | |
5933 | } | |
7c673cae | 5934 | |
f67539c2 | 5935 | // make reservation for notification if needed |
b3b6e05e | 5936 | rgw::notify::reservation_t res(this, store, s, s->object.get()); |
f67539c2 | 5937 | const auto event_type = rgw::notify::ObjectCreatedPost; |
b3b6e05e | 5938 | op_ret = rgw::notify::publish_reserve(this, event_type, res, nullptr); |
f67539c2 TL |
5939 | if (op_ret < 0) { |
5940 | return; | |
5941 | } | |
5942 | ||
7c673cae FG |
5943 | do { |
5944 | char buf[33]; | |
f67539c2 | 5945 | std::unique_ptr<rgw::sal::RGWObject> obj; |
7c673cae FG |
5946 | gen_rand_alphanumeric(s->cct, buf, sizeof(buf) - 1); |
5947 | upload_id = MULTIPART_UPLOAD_ID_PREFIX; /* v2 upload id */ | |
5948 | upload_id.append(buf); | |
5949 | ||
5950 | string tmp_obj_name; | |
f67539c2 | 5951 | RGWMPObj mp(s->object->get_name(), upload_id); |
7c673cae FG |
5952 | tmp_obj_name = mp.get_meta(); |
5953 | ||
f67539c2 | 5954 | obj = s->bucket->get_object(rgw_obj_key(tmp_obj_name, string(), mp_ns)); |
7c673cae | 5955 | // the meta object will be indexed with 0 size, we c |
f67539c2 TL |
5956 | obj->set_in_extra_data(true); |
5957 | obj->set_hash_source(s->object->get_name()); | |
7c673cae | 5958 | |
f67539c2 | 5959 | std::unique_ptr<rgw::sal::RGWObject::WriteOp> obj_op = obj->get_write_op(s->obj_ctx); |
7c673cae | 5960 | |
f67539c2 TL |
5961 | obj_op->params.versioning_disabled = true; /* no versioning for multipart meta */ |
5962 | obj_op->params.owner = s->owner; | |
5963 | obj_op->params.category = RGWObjCategory::MultiMeta; | |
5964 | obj_op->params.flags = PUT_OBJ_CREATE_EXCL; | |
5965 | obj_op->params.mtime = &mtime; | |
5966 | obj_op->params.attrs = &attrs; | |
7c673cae | 5967 | |
11fdf7f2 TL |
5968 | multipart_upload_info upload_info; |
5969 | upload_info.dest_placement = s->dest_placement; | |
7c673cae | 5970 | |
11fdf7f2 TL |
5971 | bufferlist bl; |
5972 | encode(upload_info, bl); | |
f67539c2 | 5973 | obj_op->params.data = &bl; |
7c673cae | 5974 | |
f67539c2 TL |
5975 | op_ret = obj_op->prepare(s->yield); |
5976 | ||
b3b6e05e | 5977 | op_ret = obj_op->write_meta(this, bl.length(), 0, s->yield); |
11fdf7f2 | 5978 | } while (op_ret == -EEXIST); |
eafe8130 | 5979 | |
f67539c2 | 5980 | // send request to notification manager |
b3b6e05e | 5981 | const auto ret = rgw::notify::publish_commit(s->object.get(), s->obj_size, ceph::real_clock::now(), attrs[RGW_ATTR_ETAG].to_str(), event_type, res, this); |
eafe8130 | 5982 | if (ret < 0) { |
f67539c2 TL |
5983 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
5984 | // too late to rollback operation, hence op_ret is not set here | |
eafe8130 | 5985 | } |
7c673cae FG |
5986 | } |
5987 | ||
f67539c2 | 5988 | int RGWCompleteMultipart::verify_permission(optional_yield y) |
7c673cae | 5989 | { |
522d829b TL |
5990 | if (s->iam_policy || ! s->iam_user_policies.empty() || ! s->session_policies.empty()) { |
5991 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, | |
11fdf7f2 TL |
5992 | boost::none, |
5993 | rgw::IAM::s3PutObject, | |
f67539c2 | 5994 | s->object->get_obj()); |
522d829b | 5995 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
5996 | return -EACCES; |
5997 | } | |
5998 | ||
5999 | rgw::IAM::Effect e = Effect::Pass; | |
522d829b | 6000 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
6001 | if (s->iam_policy) { |
6002 | e = s->iam_policy->eval(s->env, *s->auth.identity, | |
31f18b77 | 6003 | rgw::IAM::s3PutObject, |
522d829b TL |
6004 | s->object->get_obj(), |
6005 | princ_type); | |
11fdf7f2 | 6006 | } |
522d829b | 6007 | if (e == Effect::Deny) { |
31f18b77 | 6008 | return -EACCES; |
522d829b TL |
6009 | } |
6010 | ||
6011 | if (!s->session_policies.empty()) { | |
6012 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
6013 | boost::none, | |
6014 | rgw::IAM::s3PutObject, | |
6015 | s->object->get_obj()); | |
6016 | if (session_policy_res == Effect::Deny) { | |
6017 | return -EACCES; | |
6018 | } | |
6019 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
6020 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
6021 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
6022 | (session_policy_res == Effect::Allow && e == Effect::Allow)) { | |
6023 | return 0; | |
6024 | } | |
6025 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
6026 | //Intersection of session policy and identity policy plus bucket policy | |
6027 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || e == Effect::Allow) { | |
6028 | return 0; | |
6029 | } | |
6030 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
6031 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
6032 | return 0; | |
6033 | } | |
6034 | } | |
6035 | return -EACCES; | |
6036 | } | |
6037 | if (e == Effect::Allow || identity_policy_res == Effect::Allow) { | |
11fdf7f2 | 6038 | return 0; |
31f18b77 FG |
6039 | } |
6040 | } | |
6041 | ||
11fdf7f2 | 6042 | if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae | 6043 | return -EACCES; |
31f18b77 | 6044 | } |
7c673cae FG |
6045 | |
6046 | return 0; | |
6047 | } | |
6048 | ||
6049 | void RGWCompleteMultipart::pre_exec() | |
6050 | { | |
6051 | rgw_bucket_object_pre_exec(s); | |
6052 | } | |
6053 | ||
f67539c2 | 6054 | void RGWCompleteMultipart::execute(optional_yield y) |
7c673cae FG |
6055 | { |
6056 | RGWMultiCompleteUpload *parts; | |
6057 | map<int, string>::iterator iter; | |
6058 | RGWMultiXMLParser parser; | |
6059 | string meta_oid; | |
6060 | map<uint32_t, RGWUploadPartInfo> obj_parts; | |
6061 | map<uint32_t, RGWUploadPartInfo>::iterator obj_iter; | |
f67539c2 | 6062 | rgw::sal::RGWAttrs attrs; |
7c673cae FG |
6063 | off_t ofs = 0; |
6064 | MD5 hash; | |
6065 | char final_etag[CEPH_CRYPTO_MD5_DIGESTSIZE]; | |
6066 | char final_etag_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 16]; | |
6067 | bufferlist etag_bl; | |
f67539c2 TL |
6068 | std::unique_ptr<rgw::sal::RGWObject> meta_obj; |
6069 | std::unique_ptr<rgw::sal::RGWObject> target_obj; | |
7c673cae FG |
6070 | RGWMPObj mp; |
6071 | RGWObjManifest manifest; | |
6072 | uint64_t olh_epoch = 0; | |
7c673cae | 6073 | |
f67539c2 | 6074 | op_ret = get_params(y); |
7c673cae FG |
6075 | if (op_ret < 0) |
6076 | return; | |
6077 | op_ret = get_system_versioning_params(s, &olh_epoch, &version_id); | |
6078 | if (op_ret < 0) { | |
6079 | return; | |
6080 | } | |
6081 | ||
11fdf7f2 | 6082 | if (!data.length()) { |
7c673cae FG |
6083 | op_ret = -ERR_MALFORMED_XML; |
6084 | return; | |
6085 | } | |
6086 | ||
6087 | if (!parser.init()) { | |
6088 | op_ret = -EIO; | |
6089 | return; | |
6090 | } | |
6091 | ||
11fdf7f2 | 6092 | if (!parser.parse(data.c_str(), data.length(), 1)) { |
7c673cae FG |
6093 | op_ret = -ERR_MALFORMED_XML; |
6094 | return; | |
6095 | } | |
6096 | ||
6097 | parts = static_cast<RGWMultiCompleteUpload *>(parser.find_first("CompleteMultipartUpload")); | |
6098 | if (!parts || parts->parts.empty()) { | |
6099 | op_ret = -ERR_MALFORMED_XML; | |
6100 | return; | |
6101 | } | |
6102 | ||
6103 | if ((int)parts->parts.size() > | |
6104 | s->cct->_conf->rgw_multipart_part_upload_limit) { | |
6105 | op_ret = -ERANGE; | |
6106 | return; | |
6107 | } | |
6108 | ||
f67539c2 TL |
6109 | mp.init(s->object->get_name(), upload_id); |
6110 | ||
7c673cae FG |
6111 | meta_oid = mp.get_meta(); |
6112 | ||
6113 | int total_parts = 0; | |
6114 | int handled_parts = 0; | |
6115 | int max_parts = 1000; | |
6116 | int marker = 0; | |
6117 | bool truncated; | |
6118 | RGWCompressionInfo cs_info; | |
6119 | bool compressed = false; | |
6120 | uint64_t accounted_size = 0; | |
6121 | ||
6122 | uint64_t min_part_size = s->cct->_conf->rgw_multipart_min_part_size; | |
6123 | ||
6124 | list<rgw_obj_index_key> remove_objs; /* objects to be removed from index listing */ | |
6125 | ||
f67539c2 | 6126 | bool versioned_object = s->bucket->versioning_enabled(); |
7c673cae FG |
6127 | |
6128 | iter = parts->parts.begin(); | |
6129 | ||
f67539c2 TL |
6130 | meta_obj = s->bucket->get_object(rgw_obj_key(meta_oid, string(), mp_ns)); |
6131 | meta_obj->set_in_extra_data(true); | |
6132 | meta_obj->set_hash_source(s->object->get_name()); | |
7c673cae | 6133 | |
d2e6a577 FG |
6134 | /*take a cls lock on meta_obj to prevent racing completions (or retries) |
6135 | from deleting the parts*/ | |
3efd9988 | 6136 | int max_lock_secs_mp = |
11fdf7f2 | 6137 | s->cct->_conf.get_val<int64_t>("rgw_mp_lock_max_time"); |
3efd9988 | 6138 | utime_t dur(max_lock_secs_mp, 0); |
d2e6a577 | 6139 | |
b3b6e05e TL |
6140 | serializer = meta_obj->get_serializer(this, "RGWCompleteMultipart"); |
6141 | op_ret = serializer->try_lock(this, dur, y); | |
d2e6a577 | 6142 | if (op_ret < 0) { |
11fdf7f2 | 6143 | ldpp_dout(this, 0) << "failed to acquire lock" << dendl; |
d2e6a577 FG |
6144 | op_ret = -ERR_INTERNAL_ERROR; |
6145 | s->err.message = "This multipart completion is already in progress"; | |
6146 | return; | |
6147 | } | |
6148 | ||
b3b6e05e | 6149 | op_ret = meta_obj->get_obj_attrs(s->obj_ctx, s->yield, this); |
7c673cae | 6150 | if (op_ret < 0) { |
11fdf7f2 | 6151 | ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << meta_obj |
7c673cae FG |
6152 | << " ret=" << op_ret << dendl; |
6153 | return; | |
6154 | } | |
f67539c2 | 6155 | attrs = meta_obj->get_attrs(); |
7c673cae | 6156 | |
522d829b TL |
6157 | // make reservation for notification if needed |
6158 | rgw::notify::reservation_t res(this, store, s, meta_obj.get(), &s->object->get_name()); | |
6159 | const auto event_type = rgw::notify::ObjectCreatedCompleteMultipartUpload; | |
6160 | op_ret = rgw::notify::publish_reserve(this, event_type, res, nullptr); | |
6161 | if (op_ret < 0) { | |
6162 | return; | |
6163 | } | |
6164 | ||
7c673cae | 6165 | do { |
b3b6e05e | 6166 | op_ret = list_multipart_parts(this, store, s, upload_id, meta_oid, max_parts, |
7c673cae FG |
6167 | marker, obj_parts, &marker, &truncated); |
6168 | if (op_ret == -ENOENT) { | |
6169 | op_ret = -ERR_NO_SUCH_UPLOAD; | |
6170 | } | |
6171 | if (op_ret < 0) | |
6172 | return; | |
6173 | ||
6174 | total_parts += obj_parts.size(); | |
6175 | if (!truncated && total_parts != (int)parts->parts.size()) { | |
11fdf7f2 | 6176 | ldpp_dout(this, 0) << "NOTICE: total parts mismatch: have: " << total_parts |
7c673cae FG |
6177 | << " expected: " << parts->parts.size() << dendl; |
6178 | op_ret = -ERR_INVALID_PART; | |
6179 | return; | |
6180 | } | |
6181 | ||
6182 | for (obj_iter = obj_parts.begin(); iter != parts->parts.end() && obj_iter != obj_parts.end(); ++iter, ++obj_iter, ++handled_parts) { | |
6183 | uint64_t part_size = obj_iter->second.accounted_size; | |
6184 | if (handled_parts < (int)parts->parts.size() - 1 && | |
6185 | part_size < min_part_size) { | |
6186 | op_ret = -ERR_TOO_SMALL; | |
6187 | return; | |
6188 | } | |
6189 | ||
6190 | char petag[CEPH_CRYPTO_MD5_DIGESTSIZE]; | |
6191 | if (iter->first != (int)obj_iter->first) { | |
11fdf7f2 | 6192 | ldpp_dout(this, 0) << "NOTICE: parts num mismatch: next requested: " |
7c673cae FG |
6193 | << iter->first << " next uploaded: " |
6194 | << obj_iter->first << dendl; | |
6195 | op_ret = -ERR_INVALID_PART; | |
6196 | return; | |
6197 | } | |
6198 | string part_etag = rgw_string_unquote(iter->second); | |
6199 | if (part_etag.compare(obj_iter->second.etag) != 0) { | |
11fdf7f2 | 6200 | ldpp_dout(this, 0) << "NOTICE: etag mismatch: part: " << iter->first |
7c673cae FG |
6201 | << " etag: " << iter->second << dendl; |
6202 | op_ret = -ERR_INVALID_PART; | |
6203 | return; | |
6204 | } | |
6205 | ||
6206 | hex_to_buf(obj_iter->second.etag.c_str(), petag, | |
6207 | CEPH_CRYPTO_MD5_DIGESTSIZE); | |
11fdf7f2 | 6208 | hash.Update((const unsigned char *)petag, sizeof(petag)); |
7c673cae FG |
6209 | |
6210 | RGWUploadPartInfo& obj_part = obj_iter->second; | |
6211 | ||
6212 | /* update manifest for part */ | |
6213 | string oid = mp.get_part(obj_iter->second.num); | |
6214 | rgw_obj src_obj; | |
f67539c2 | 6215 | src_obj.init_ns(s->bucket->get_key(), oid, mp_ns); |
7c673cae FG |
6216 | |
6217 | if (obj_part.manifest.empty()) { | |
11fdf7f2 | 6218 | ldpp_dout(this, 0) << "ERROR: empty manifest for object part: obj=" |
7c673cae FG |
6219 | << src_obj << dendl; |
6220 | op_ret = -ERR_INVALID_PART; | |
6221 | return; | |
6222 | } else { | |
b3b6e05e | 6223 | manifest.append(this, obj_part.manifest, store->svc()->zone); |
7c673cae FG |
6224 | } |
6225 | ||
11fdf7f2 | 6226 | bool part_compressed = (obj_part.cs_info.compression_type != "none"); |
9f95a23c | 6227 | if ((handled_parts > 0) && |
11fdf7f2 TL |
6228 | ((part_compressed != compressed) || |
6229 | (cs_info.compression_type != obj_part.cs_info.compression_type))) { | |
6230 | ldpp_dout(this, 0) << "ERROR: compression type was changed during multipart upload (" | |
7c673cae FG |
6231 | << cs_info.compression_type << ">>" << obj_part.cs_info.compression_type << ")" << dendl; |
6232 | op_ret = -ERR_INVALID_PART; | |
11fdf7f2 TL |
6233 | return; |
6234 | } | |
6235 | ||
6236 | if (part_compressed) { | |
224ce89b | 6237 | int64_t new_ofs; // offset in compression data for new part |
7c673cae FG |
6238 | if (cs_info.blocks.size() > 0) |
6239 | new_ofs = cs_info.blocks.back().new_ofs + cs_info.blocks.back().len; | |
6240 | else | |
6241 | new_ofs = 0; | |
6242 | for (const auto& block : obj_part.cs_info.blocks) { | |
6243 | compression_block cb; | |
6244 | cb.old_ofs = block.old_ofs + cs_info.orig_size; | |
6245 | cb.new_ofs = new_ofs; | |
6246 | cb.len = block.len; | |
6247 | cs_info.blocks.push_back(cb); | |
6248 | new_ofs = cb.new_ofs + cb.len; | |
6249 | } | |
6250 | if (!compressed) | |
6251 | cs_info.compression_type = obj_part.cs_info.compression_type; | |
6252 | cs_info.orig_size += obj_part.cs_info.orig_size; | |
6253 | compressed = true; | |
6254 | } | |
6255 | ||
6256 | rgw_obj_index_key remove_key; | |
6257 | src_obj.key.get_index_key(&remove_key); | |
6258 | ||
6259 | remove_objs.push_back(remove_key); | |
6260 | ||
6261 | ofs += obj_part.size; | |
6262 | accounted_size += obj_part.accounted_size; | |
6263 | } | |
6264 | } while (truncated); | |
b3b6e05e | 6265 | |
11fdf7f2 | 6266 | hash.Final((unsigned char *)final_etag); |
7c673cae FG |
6267 | |
6268 | buf_to_hex((unsigned char *)final_etag, sizeof(final_etag), final_etag_str); | |
6269 | snprintf(&final_etag_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2], sizeof(final_etag_str) - CEPH_CRYPTO_MD5_DIGESTSIZE * 2, | |
6270 | "-%lld", (long long)parts->parts.size()); | |
6271 | etag = final_etag_str; | |
11fdf7f2 | 6272 | ldpp_dout(this, 10) << "calculated etag: " << final_etag_str << dendl; |
7c673cae | 6273 | |
11fdf7f2 | 6274 | etag_bl.append(final_etag_str, strlen(final_etag_str)); |
7c673cae FG |
6275 | |
6276 | attrs[RGW_ATTR_ETAG] = etag_bl; | |
6277 | ||
6278 | if (compressed) { | |
6279 | // write compression attribute to full object | |
6280 | bufferlist tmp; | |
11fdf7f2 | 6281 | encode(cs_info, tmp); |
7c673cae FG |
6282 | attrs[RGW_ATTR_COMPRESSION] = tmp; |
6283 | } | |
6284 | ||
f67539c2 | 6285 | target_obj = s->bucket->get_object(rgw_obj_key(s->object->get_name())); |
7c673cae | 6286 | if (versioned_object) { |
11fdf7f2 | 6287 | if (!version_id.empty()) { |
f67539c2 | 6288 | target_obj->set_instance(version_id); |
11fdf7f2 | 6289 | } else { |
f67539c2 TL |
6290 | target_obj->gen_rand_obj_instance_name(); |
6291 | version_id = target_obj->get_instance(); | |
11fdf7f2 | 6292 | } |
7c673cae FG |
6293 | } |
6294 | ||
6295 | RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx); | |
6296 | ||
f67539c2 | 6297 | target_obj->set_atomic(&obj_ctx); |
7c673cae | 6298 | |
f67539c2 | 6299 | std::unique_ptr<rgw::sal::RGWObject::WriteOp> obj_op = target_obj->get_write_op(&obj_ctx); |
7c673cae | 6300 | |
f67539c2 TL |
6301 | obj_op->params.manifest = &manifest; |
6302 | obj_op->params.remove_objs = &remove_objs; | |
7c673cae | 6303 | |
f67539c2 TL |
6304 | obj_op->params.ptag = &s->req_id; /* use req_id as operation tag */ |
6305 | obj_op->params.owner = s->owner; | |
6306 | obj_op->params.flags = PUT_OBJ_CREATE; | |
6307 | obj_op->params.modify_tail = true; | |
6308 | obj_op->params.completeMultipart = true; | |
6309 | obj_op->params.olh_epoch = olh_epoch; | |
6310 | obj_op->params.attrs = &attrs; | |
b3b6e05e | 6311 | |
f67539c2 | 6312 | op_ret = obj_op->prepare(s->yield); |
b3b6e05e | 6313 | if (op_ret < 0) { |
f67539c2 | 6314 | return; |
b3b6e05e | 6315 | } |
f67539c2 | 6316 | |
b3b6e05e TL |
6317 | op_ret = obj_op->write_meta(this, ofs, accounted_size, s->yield); |
6318 | if (op_ret < 0) { | |
7c673cae | 6319 | return; |
b3b6e05e | 6320 | } |
7c673cae | 6321 | |
b3b6e05e | 6322 | // remove the upload meta object |
f67539c2 | 6323 | string version_id; |
b3b6e05e TL |
6324 | |
6325 | // remove the upload meta object ; the meta object is not versioned | |
6326 | // when the bucket is, as that would add an unneeded delete marker | |
6327 | int r = meta_obj->delete_object(this, s->obj_ctx, ACLOwner(), ACLOwner(), ceph::real_time(), false, 0, | |
6328 | version_id, null_yield, true /* prevent versioning*/ ); | |
3efd9988 FG |
6329 | if (r >= 0) { |
6330 | /* serializer's exclusive lock is released */ | |
f67539c2 | 6331 | serializer->clear_locked(); |
3efd9988 | 6332 | } else { |
11fdf7f2 | 6333 | ldpp_dout(this, 0) << "WARNING: failed to remove object " << meta_obj << dendl; |
3efd9988 | 6334 | } |
e306af50 | 6335 | |
f67539c2 | 6336 | // send request to notification manager |
b3b6e05e | 6337 | const auto ret = rgw::notify::publish_commit(s->object.get(), ofs, ceph::real_clock::now(), final_etag_str, event_type, res, this); |
eafe8130 | 6338 | if (ret < 0) { |
f67539c2 TL |
6339 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
6340 | // too late to rollback operation, hence op_ret is not set here | |
eafe8130 | 6341 | } |
b3b6e05e | 6342 | } // RGWCompleteMultipart::execute |
3efd9988 | 6343 | |
3efd9988 FG |
6344 | void RGWCompleteMultipart::complete() |
6345 | { | |
6346 | /* release exclusive lock iff not already */ | |
f67539c2 TL |
6347 | if (unlikely(serializer && serializer->locked)) { |
6348 | int r = serializer->unlock(); | |
d2e6a577 | 6349 | if (r < 0) { |
f67539c2 | 6350 | ldpp_dout(this, 0) << "WARNING: failed to unlock " << serializer->oid << dendl; |
d2e6a577 | 6351 | } |
7c673cae | 6352 | } |
3efd9988 | 6353 | send_response(); |
7c673cae FG |
6354 | } |
6355 | ||
f67539c2 | 6356 | int RGWAbortMultipart::verify_permission(optional_yield y) |
7c673cae | 6357 | { |
522d829b TL |
6358 | if (s->iam_policy || ! s->iam_user_policies.empty() || !s->session_policies.empty()) { |
6359 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, | |
11fdf7f2 TL |
6360 | boost::none, |
6361 | rgw::IAM::s3AbortMultipartUpload, | |
f67539c2 | 6362 | s->object->get_obj()); |
522d829b | 6363 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
6364 | return -EACCES; |
6365 | } | |
6366 | ||
6367 | rgw::IAM::Effect e = Effect::Pass; | |
522d829b | 6368 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
6369 | if (s->iam_policy) { |
6370 | e = s->iam_policy->eval(s->env, *s->auth.identity, | |
31f18b77 | 6371 | rgw::IAM::s3AbortMultipartUpload, |
522d829b | 6372 | s->object->get_obj(), princ_type); |
11fdf7f2 | 6373 | } |
522d829b TL |
6374 | |
6375 | if (e == Effect::Deny) { | |
31f18b77 | 6376 | return -EACCES; |
522d829b TL |
6377 | } |
6378 | ||
6379 | if (!s->session_policies.empty()) { | |
6380 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
6381 | boost::none, | |
6382 | rgw::IAM::s3PutObject, | |
6383 | s->object->get_obj()); | |
6384 | if (session_policy_res == Effect::Deny) { | |
6385 | return -EACCES; | |
6386 | } | |
6387 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
6388 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
6389 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
6390 | (session_policy_res == Effect::Allow && e == Effect::Allow)) { | |
6391 | return 0; | |
6392 | } | |
6393 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
6394 | //Intersection of session policy and identity policy plus bucket policy | |
6395 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || e == Effect::Allow) { | |
6396 | return 0; | |
6397 | } | |
6398 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
6399 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
6400 | return 0; | |
6401 | } | |
6402 | } | |
6403 | return -EACCES; | |
6404 | } | |
6405 | if (e == Effect::Allow || identity_policy_res == Effect::Allow) { | |
11fdf7f2 | 6406 | return 0; |
522d829b | 6407 | } |
31f18b77 FG |
6408 | } |
6409 | ||
11fdf7f2 | 6410 | if (!verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae | 6411 | return -EACCES; |
31f18b77 | 6412 | } |
7c673cae FG |
6413 | |
6414 | return 0; | |
6415 | } | |
6416 | ||
6417 | void RGWAbortMultipart::pre_exec() | |
6418 | { | |
6419 | rgw_bucket_object_pre_exec(s); | |
6420 | } | |
6421 | ||
f67539c2 | 6422 | void RGWAbortMultipart::execute(optional_yield y) |
7c673cae FG |
6423 | { |
6424 | op_ret = -EINVAL; | |
6425 | string upload_id; | |
6426 | string meta_oid; | |
6427 | upload_id = s->info.args.get("uploadId"); | |
7c673cae FG |
6428 | rgw_obj meta_obj; |
6429 | RGWMPObj mp; | |
6430 | ||
f67539c2 | 6431 | if (upload_id.empty() || rgw::sal::RGWObject::empty(s->object.get())) |
7c673cae FG |
6432 | return; |
6433 | ||
f67539c2 | 6434 | mp.init(s->object->get_name(), upload_id); |
7c673cae FG |
6435 | meta_oid = mp.get_meta(); |
6436 | ||
b3b6e05e | 6437 | op_ret = get_multipart_info(this, s, meta_oid, nullptr); |
7c673cae FG |
6438 | if (op_ret < 0) |
6439 | return; | |
6440 | ||
6441 | RGWObjectCtx *obj_ctx = static_cast<RGWObjectCtx *>(s->obj_ctx); | |
b3b6e05e | 6442 | op_ret = abort_multipart_upload(this, store, s->cct, obj_ctx, s->bucket->get_info(), mp); |
7c673cae FG |
6443 | } |
6444 | ||
f67539c2 | 6445 | int RGWListMultipart::verify_permission(optional_yield y) |
7c673cae | 6446 | { |
11fdf7f2 | 6447 | if (!verify_object_permission(this, s, rgw::IAM::s3ListMultipartUploadParts)) |
7c673cae FG |
6448 | return -EACCES; |
6449 | ||
6450 | return 0; | |
6451 | } | |
6452 | ||
6453 | void RGWListMultipart::pre_exec() | |
6454 | { | |
6455 | rgw_bucket_object_pre_exec(s); | |
6456 | } | |
6457 | ||
f67539c2 | 6458 | void RGWListMultipart::execute(optional_yield y) |
7c673cae | 6459 | { |
7c673cae FG |
6460 | string meta_oid; |
6461 | RGWMPObj mp; | |
6462 | ||
f67539c2 | 6463 | op_ret = get_params(y); |
7c673cae FG |
6464 | if (op_ret < 0) |
6465 | return; | |
6466 | ||
f67539c2 | 6467 | mp.init(s->object->get_name(), upload_id); |
7c673cae FG |
6468 | meta_oid = mp.get_meta(); |
6469 | ||
b3b6e05e | 6470 | op_ret = get_multipart_info(this, s, meta_oid, nullptr); |
7c673cae FG |
6471 | if (op_ret < 0) |
6472 | return; | |
6473 | ||
b3b6e05e | 6474 | op_ret = list_multipart_parts(this, store, s, upload_id, meta_oid, max_parts, |
7c673cae FG |
6475 | marker, parts, NULL, &truncated); |
6476 | } | |
6477 | ||
f67539c2 | 6478 | int RGWListBucketMultiparts::verify_permission(optional_yield y) |
7c673cae | 6479 | { |
11fdf7f2 TL |
6480 | if (!verify_bucket_permission(this, |
6481 | s, | |
28e407b8 | 6482 | rgw::IAM::s3ListBucketMultipartUploads)) |
7c673cae FG |
6483 | return -EACCES; |
6484 | ||
6485 | return 0; | |
6486 | } | |
6487 | ||
6488 | void RGWListBucketMultiparts::pre_exec() | |
6489 | { | |
6490 | rgw_bucket_object_pre_exec(s); | |
6491 | } | |
6492 | ||
f67539c2 | 6493 | void RGWListBucketMultiparts::execute(optional_yield y) |
7c673cae FG |
6494 | { |
6495 | vector<rgw_bucket_dir_entry> objs; | |
6496 | string marker_meta; | |
6497 | ||
f67539c2 | 6498 | op_ret = get_params(y); |
7c673cae FG |
6499 | if (op_ret < 0) |
6500 | return; | |
6501 | ||
6502 | if (s->prot_flags & RGW_REST_SWIFT) { | |
6503 | string path_args; | |
6504 | path_args = s->info.args.get("path"); | |
6505 | if (!path_args.empty()) { | |
6506 | if (!delimiter.empty() || !prefix.empty()) { | |
6507 | op_ret = -EINVAL; | |
6508 | return; | |
6509 | } | |
6510 | prefix = path_args; | |
6511 | delimiter="/"; | |
6512 | } | |
6513 | } | |
6514 | marker_meta = marker.get_meta(); | |
6515 | ||
b3b6e05e | 6516 | op_ret = list_bucket_multiparts(this, store, s->bucket->get_info(), prefix, marker_meta, delimiter, |
224ce89b WB |
6517 | max_uploads, &objs, &common_prefixes, &is_truncated); |
6518 | if (op_ret < 0) { | |
6519 | return; | |
6520 | } | |
7c673cae | 6521 | |
7c673cae FG |
6522 | if (!objs.empty()) { |
6523 | vector<rgw_bucket_dir_entry>::iterator iter; | |
6524 | RGWMultipartUploadEntry entry; | |
6525 | for (iter = objs.begin(); iter != objs.end(); ++iter) { | |
6526 | rgw_obj_key key(iter->key); | |
6527 | if (!entry.mp.from_meta(key.name)) | |
6528 | continue; | |
6529 | entry.obj = *iter; | |
6530 | uploads.push_back(entry); | |
6531 | } | |
6532 | next_marker = entry; | |
6533 | } | |
6534 | } | |
6535 | ||
f67539c2 | 6536 | void RGWGetHealthCheck::execute(optional_yield y) |
7c673cae | 6537 | { |
11fdf7f2 TL |
6538 | if (!g_conf()->rgw_healthcheck_disabling_path.empty() && |
6539 | (::access(g_conf()->rgw_healthcheck_disabling_path.c_str(), F_OK) == 0)) { | |
7c673cae FG |
6540 | /* Disabling path specified & existent in the filesystem. */ |
6541 | op_ret = -ERR_SERVICE_UNAVAILABLE; /* 503 */ | |
6542 | } else { | |
6543 | op_ret = 0; /* 200 OK */ | |
6544 | } | |
6545 | } | |
6546 | ||
f67539c2 | 6547 | int RGWDeleteMultiObj::verify_permission(optional_yield y) |
7c673cae | 6548 | { |
f67539c2 TL |
6549 | int op_ret = get_params(y); |
6550 | if (op_ret) { | |
6551 | return op_ret; | |
6552 | } | |
6553 | ||
522d829b | 6554 | if (s->iam_policy || ! s->iam_user_policies.empty() || ! s->session_policies.empty()) { |
f67539c2 | 6555 | if (s->bucket->get_info().obj_lock_enabled() && bypass_governance_mode) { |
522d829b | 6556 | auto r = eval_identity_or_session_policies(s->iam_user_policies, s->env, boost::none, |
f67539c2 TL |
6557 | rgw::IAM::s3BypassGovernanceRetention, ARN(s->bucket->get_key())); |
6558 | if (r == Effect::Deny) { | |
6559 | bypass_perm = false; | |
6560 | } else if (r == Effect::Pass && s->iam_policy) { | |
6561 | r = s->iam_policy->eval(s->env, *s->auth.identity, rgw::IAM::s3BypassGovernanceRetention, | |
6562 | ARN(s->bucket->get_key())); | |
6563 | if (r == Effect::Deny) { | |
6564 | bypass_perm = false; | |
6565 | } | |
522d829b TL |
6566 | } else if (r == Effect::Pass && !s->session_policies.empty()) { |
6567 | r = eval_identity_or_session_policies(s->session_policies, s->env, boost::none, | |
6568 | rgw::IAM::s3BypassGovernanceRetention, ARN(s->bucket->get_key())); | |
6569 | if (r == Effect::Deny) { | |
6570 | bypass_perm = false; | |
6571 | } | |
f67539c2 TL |
6572 | } |
6573 | } | |
6574 | ||
6575 | bool not_versioned = rgw::sal::RGWObject::empty(s->object.get()) || s->object->get_instance().empty(); | |
6576 | ||
522d829b | 6577 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, |
11fdf7f2 | 6578 | boost::none, |
f67539c2 | 6579 | not_versioned ? |
11fdf7f2 TL |
6580 | rgw::IAM::s3DeleteObject : |
6581 | rgw::IAM::s3DeleteObjectVersion, | |
f67539c2 | 6582 | ARN(s->bucket->get_key())); |
522d829b | 6583 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
6584 | return -EACCES; |
6585 | } | |
6586 | ||
6587 | rgw::IAM::Effect r = Effect::Pass; | |
522d829b | 6588 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
6589 | if (s->iam_policy) { |
6590 | r = s->iam_policy->eval(s->env, *s->auth.identity, | |
f67539c2 | 6591 | not_versioned ? |
11fdf7f2 TL |
6592 | rgw::IAM::s3DeleteObject : |
6593 | rgw::IAM::s3DeleteObjectVersion, | |
522d829b TL |
6594 | ARN(s->bucket->get_key()), |
6595 | princ_type); | |
11fdf7f2 | 6596 | } |
522d829b TL |
6597 | if (r == Effect::Deny) |
6598 | return -EACCES; | |
6599 | ||
6600 | if (!s->session_policies.empty()) { | |
6601 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
6602 | boost::none, | |
6603 | not_versioned ? | |
6604 | rgw::IAM::s3DeleteObject : | |
6605 | rgw::IAM::s3DeleteObjectVersion, | |
6606 | ARN(s->bucket->get_key())); | |
6607 | if (session_policy_res == Effect::Deny) { | |
6608 | return -EACCES; | |
6609 | } | |
6610 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
6611 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
6612 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
6613 | (session_policy_res == Effect::Allow && r == Effect::Allow)) { | |
6614 | return 0; | |
6615 | } | |
6616 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
6617 | //Intersection of session policy and identity policy plus bucket policy | |
6618 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || r == Effect::Allow) { | |
6619 | return 0; | |
6620 | } | |
6621 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
6622 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
6623 | return 0; | |
6624 | } | |
6625 | } | |
11fdf7f2 | 6626 | return -EACCES; |
522d829b TL |
6627 | } |
6628 | if (r == Effect::Allow || identity_policy_res == Effect::Allow) | |
11fdf7f2 TL |
6629 | return 0; |
6630 | } | |
6631 | ||
6632 | acl_allowed = verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE); | |
6633 | if (!acl_allowed) | |
7c673cae FG |
6634 | return -EACCES; |
6635 | ||
6636 | return 0; | |
6637 | } | |
6638 | ||
6639 | void RGWDeleteMultiObj::pre_exec() | |
6640 | { | |
6641 | rgw_bucket_object_pre_exec(s); | |
6642 | } | |
6643 | ||
f67539c2 | 6644 | void RGWDeleteMultiObj::execute(optional_yield y) |
7c673cae FG |
6645 | { |
6646 | RGWMultiDelDelete *multi_delete; | |
6647 | vector<rgw_obj_key>::iterator iter; | |
6648 | RGWMultiDelXMLParser parser; | |
7c673cae | 6649 | RGWObjectCtx *obj_ctx = static_cast<RGWObjectCtx *>(s->obj_ctx); |
11fdf7f2 | 6650 | char* buf; |
7c673cae | 6651 | |
11fdf7f2 TL |
6652 | buf = data.c_str(); |
6653 | if (!buf) { | |
7c673cae FG |
6654 | op_ret = -EINVAL; |
6655 | goto error; | |
6656 | } | |
6657 | ||
6658 | if (!parser.init()) { | |
6659 | op_ret = -EINVAL; | |
6660 | goto error; | |
6661 | } | |
6662 | ||
11fdf7f2 | 6663 | if (!parser.parse(buf, data.length(), 1)) { |
7c673cae FG |
6664 | op_ret = -EINVAL; |
6665 | goto error; | |
6666 | } | |
6667 | ||
6668 | multi_delete = static_cast<RGWMultiDelDelete *>(parser.find_first("Delete")); | |
6669 | if (!multi_delete) { | |
6670 | op_ret = -EINVAL; | |
6671 | goto error; | |
11fdf7f2 TL |
6672 | } else { |
6673 | #define DELETE_MULTI_OBJ_MAX_NUM 1000 | |
6674 | int max_num = s->cct->_conf->rgw_delete_multi_obj_max_num; | |
6675 | if (max_num < 0) { | |
6676 | max_num = DELETE_MULTI_OBJ_MAX_NUM; | |
6677 | } | |
6678 | int multi_delete_object_num = multi_delete->objects.size(); | |
6679 | if (multi_delete_object_num > max_num) { | |
6680 | op_ret = -ERR_MALFORMED_XML; | |
6681 | goto error; | |
6682 | } | |
7c673cae FG |
6683 | } |
6684 | ||
6685 | if (multi_delete->is_quiet()) | |
6686 | quiet = true; | |
6687 | ||
f67539c2 | 6688 | if (s->bucket->get_info().mfa_enabled()) { |
11fdf7f2 TL |
6689 | bool has_versioned = false; |
6690 | for (auto i : multi_delete->objects) { | |
6691 | if (!i.instance.empty()) { | |
6692 | has_versioned = true; | |
6693 | break; | |
6694 | } | |
6695 | } | |
6696 | if (has_versioned && !s->mfa_verified) { | |
6697 | ldpp_dout(this, 5) << "NOTICE: multi-object delete request with a versioned object, mfa auth not provided" << dendl; | |
6698 | op_ret = -ERR_MFA_REQUIRED; | |
6699 | goto error; | |
6700 | } | |
6701 | } | |
6702 | ||
7c673cae FG |
6703 | begin_response(); |
6704 | if (multi_delete->objects.empty()) { | |
6705 | goto done; | |
6706 | } | |
6707 | ||
6708 | for (iter = multi_delete->objects.begin(); | |
11fdf7f2 TL |
6709 | iter != multi_delete->objects.end(); |
6710 | ++iter) { | |
f67539c2 | 6711 | std::string version_id; |
522d829b TL |
6712 | std::unique_ptr<rgw::sal::RGWObject> obj = bucket->get_object(*iter); |
6713 | if (s->iam_policy || ! s->iam_user_policies.empty() || !s->session_policies.empty()) { | |
6714 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, | |
11fdf7f2 TL |
6715 | boost::none, |
6716 | iter->instance.empty() ? | |
6717 | rgw::IAM::s3DeleteObject : | |
6718 | rgw::IAM::s3DeleteObjectVersion, | |
f67539c2 | 6719 | ARN(obj->get_obj())); |
522d829b | 6720 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
6721 | send_partial_response(*iter, false, "", -EACCES); |
6722 | continue; | |
6723 | } | |
6724 | ||
6725 | rgw::IAM::Effect e = Effect::Pass; | |
522d829b | 6726 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; |
11fdf7f2 TL |
6727 | if (s->iam_policy) { |
6728 | e = s->iam_policy->eval(s->env, | |
31f18b77 FG |
6729 | *s->auth.identity, |
6730 | iter->instance.empty() ? | |
6731 | rgw::IAM::s3DeleteObject : | |
6732 | rgw::IAM::s3DeleteObjectVersion, | |
522d829b TL |
6733 | ARN(obj->get_obj()), |
6734 | princ_type); | |
6735 | } | |
6736 | if (e == Effect::Deny) { | |
6737 | send_partial_response(*iter, false, "", -EACCES); | |
6738 | continue; | |
11fdf7f2 | 6739 | } |
522d829b TL |
6740 | |
6741 | if (!s->session_policies.empty()) { | |
6742 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
6743 | boost::none, | |
6744 | iter->instance.empty() ? | |
6745 | rgw::IAM::s3DeleteObject : | |
6746 | rgw::IAM::s3DeleteObjectVersion, | |
6747 | ARN(obj->get_obj())); | |
6748 | if (session_policy_res == Effect::Deny) { | |
6749 | send_partial_response(*iter, false, "", -EACCES); | |
6750 | continue; | |
6751 | } | |
6752 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
6753 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
6754 | if ((session_policy_res != Effect::Allow || identity_policy_res != Effect::Allow) && | |
6755 | (session_policy_res != Effect::Allow || e != Effect::Allow)) { | |
6756 | send_partial_response(*iter, false, "", -EACCES); | |
6757 | continue; | |
6758 | } | |
6759 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
6760 | //Intersection of session policy and identity policy plus bucket policy | |
6761 | if ((session_policy_res != Effect::Allow || identity_policy_res != Effect::Allow) && e != Effect::Allow) { | |
6762 | send_partial_response(*iter, false, "", -EACCES); | |
6763 | continue; | |
6764 | } | |
6765 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
6766 | if (session_policy_res != Effect::Allow || identity_policy_res != Effect::Allow) { | |
6767 | send_partial_response(*iter, false, "", -EACCES); | |
6768 | continue; | |
6769 | } | |
6770 | } | |
6771 | send_partial_response(*iter, false, "", -EACCES); | |
6772 | continue; | |
6773 | } | |
6774 | ||
6775 | if ((identity_policy_res == Effect::Pass && e == Effect::Pass && !acl_allowed)) { | |
f67539c2 TL |
6776 | send_partial_response(*iter, false, "", -EACCES); |
6777 | continue; | |
31f18b77 FG |
6778 | } |
6779 | } | |
7c673cae | 6780 | |
f67539c2 TL |
6781 | // verify_object_lock |
6782 | bool check_obj_lock = obj->have_instance() && bucket->get_info().obj_lock_enabled(); | |
6783 | if (check_obj_lock) { | |
b3b6e05e | 6784 | int get_attrs_response = obj->get_obj_attrs(s->obj_ctx, s->yield, this); |
f67539c2 TL |
6785 | if (get_attrs_response < 0) { |
6786 | if (get_attrs_response == -ENOENT) { | |
6787 | // object maybe delete_marker, skip check_obj_lock | |
6788 | check_obj_lock = false; | |
6789 | } else { | |
6790 | // Something went wrong. | |
6791 | send_partial_response(*iter, false, "", get_attrs_response); | |
6792 | continue; | |
6793 | } | |
6794 | } | |
6795 | } | |
7c673cae | 6796 | |
f67539c2 TL |
6797 | if (check_obj_lock) { |
6798 | int object_lock_response = verify_object_lock(this, obj->get_attrs(), bypass_perm, bypass_governance_mode); | |
6799 | if (object_lock_response != 0) { | |
6800 | send_partial_response(*iter, false, "", object_lock_response); | |
6801 | continue; | |
6802 | } | |
6803 | } | |
6804 | // make reservation for notification if needed | |
6805 | const auto versioned_object = s->bucket->versioning_enabled(); | |
b3b6e05e | 6806 | rgw::notify::reservation_t res(this, store, s, obj.get()); |
f67539c2 TL |
6807 | const auto event_type = versioned_object && obj->get_instance().empty() ? |
6808 | rgw::notify::ObjectRemovedDeleteMarkerCreated : rgw::notify::ObjectRemovedDelete; | |
b3b6e05e | 6809 | op_ret = rgw::notify::publish_reserve(this, event_type, res, nullptr); |
f67539c2 TL |
6810 | if (op_ret < 0) { |
6811 | send_partial_response(*iter, false, "", op_ret); | |
6812 | continue; | |
6813 | } | |
7c673cae | 6814 | |
f67539c2 | 6815 | obj->set_atomic(obj_ctx); |
7c673cae | 6816 | |
b3b6e05e | 6817 | op_ret = obj->delete_object(this, obj_ctx, s->owner, s->bucket_owner, ceph::real_time(), |
f67539c2 | 6818 | false, 0, version_id, s->yield); |
7c673cae FG |
6819 | if (op_ret == -ENOENT) { |
6820 | op_ret = 0; | |
6821 | } | |
6822 | ||
f67539c2 | 6823 | send_partial_response(*iter, obj->get_delete_marker(), version_id, op_ret); |
9f95a23c | 6824 | |
f67539c2 | 6825 | const auto obj_state = obj_ctx->get_state(obj->get_obj()); |
9f95a23c TL |
6826 | bufferlist etag_bl; |
6827 | const auto etag = obj_state->get_attr(RGW_ATTR_ETAG, etag_bl) ? etag_bl.to_str() : ""; | |
6828 | ||
f67539c2 | 6829 | // send request to notification manager |
b3b6e05e | 6830 | const auto ret = rgw::notify::publish_commit(obj.get(), obj_state->size, obj_state->mtime, etag, event_type, res, this); |
9f95a23c | 6831 | if (ret < 0) { |
f67539c2 TL |
6832 | ldpp_dout(this, 1) << "ERROR: publishing notification failed, with error: " << ret << dendl; |
6833 | // too late to rollback operation, hence op_ret is not set here | |
9f95a23c | 6834 | } |
7c673cae FG |
6835 | } |
6836 | ||
6837 | /* set the return code to zero, errors at this point will be | |
6838 | dumped to the response */ | |
6839 | op_ret = 0; | |
6840 | ||
6841 | done: | |
6842 | // will likely segfault if begin_response() has not been called | |
6843 | end_response(); | |
7c673cae FG |
6844 | return; |
6845 | ||
6846 | error: | |
6847 | send_status(); | |
7c673cae FG |
6848 | return; |
6849 | ||
6850 | } | |
6851 | ||
6852 | bool RGWBulkDelete::Deleter::verify_permission(RGWBucketInfo& binfo, | |
6853 | map<string, bufferlist>& battrs, | |
f67539c2 TL |
6854 | ACLOwner& bucket_owner /* out */, |
6855 | optional_yield y) | |
7c673cae FG |
6856 | { |
6857 | RGWAccessControlPolicy bacl(store->ctx()); | |
b3b6e05e | 6858 | int ret = read_bucket_policy(dpp, store, s, binfo, battrs, &bacl, binfo.bucket, y); |
7c673cae FG |
6859 | if (ret < 0) { |
6860 | return false; | |
6861 | } | |
6862 | ||
f67539c2 | 6863 | auto policy = get_iam_policy_from_attr(s->cct, battrs, binfo.bucket.tenant); |
31f18b77 | 6864 | |
7c673cae FG |
6865 | bucket_owner = bacl.get_owner(); |
6866 | ||
6867 | /* We can use global user_acl because each BulkDelete request is allowed | |
6868 | * to work on entities from a single account only. */ | |
11fdf7f2 | 6869 | return verify_bucket_permission(dpp, s, binfo.bucket, s->user_acl.get(), |
522d829b | 6870 | &bacl, policy, s->iam_user_policies, s->session_policies, rgw::IAM::s3DeleteBucket); |
7c673cae FG |
6871 | } |
6872 | ||
f67539c2 | 6873 | bool RGWBulkDelete::Deleter::delete_single(const acct_path_t& path, optional_yield y) |
7c673cae | 6874 | { |
f67539c2 | 6875 | std::unique_ptr<rgw::sal::RGWBucket> bucket; |
7c673cae | 6876 | ACLOwner bowner; |
9f95a23c TL |
6877 | RGWObjVersionTracker ot; |
6878 | ||
b3b6e05e | 6879 | int ret = store->get_bucket(dpp, s->user.get(), s->user->get_tenant(), path.bucket_name, &bucket, y); |
f67539c2 TL |
6880 | if (ret < 0) { |
6881 | goto binfo_fail; | |
6882 | } | |
7c673cae | 6883 | |
b3b6e05e | 6884 | ret = bucket->get_bucket_info(dpp, s->yield); |
7c673cae FG |
6885 | if (ret < 0) { |
6886 | goto binfo_fail; | |
6887 | } | |
6888 | ||
f67539c2 | 6889 | if (!verify_permission(bucket->get_info(), bucket->get_attrs(), bowner, y)) { |
7c673cae FG |
6890 | ret = -EACCES; |
6891 | goto auth_fail; | |
6892 | } | |
6893 | ||
6894 | if (!path.obj_key.empty()) { | |
f67539c2 TL |
6895 | ACLOwner bucket_owner; |
6896 | std::string version_id; | |
7c673cae | 6897 | |
f67539c2 TL |
6898 | bucket_owner.set_id(bucket->get_info().owner); |
6899 | std::unique_ptr<rgw::sal::RGWObject> obj = bucket->get_object(path.obj_key); | |
6900 | obj->set_atomic(s->obj_ctx); | |
7c673cae | 6901 | |
b3b6e05e TL |
6902 | ret = obj->delete_object(dpp, s->obj_ctx, bowner, bucket_owner, ceph::real_time(), false, 0, |
6903 | version_id, s->yield); | |
7c673cae FG |
6904 | if (ret < 0) { |
6905 | goto delop_fail; | |
6906 | } | |
6907 | } else { | |
b3b6e05e | 6908 | ret = bucket->remove_bucket(dpp, false, string(), string(), true, &s->info, s->yield); |
7c673cae FG |
6909 | if (ret < 0) { |
6910 | goto delop_fail; | |
6911 | } | |
7c673cae FG |
6912 | } |
6913 | ||
6914 | num_deleted++; | |
6915 | return true; | |
6916 | ||
6917 | ||
6918 | binfo_fail: | |
6919 | if (-ENOENT == ret) { | |
b3b6e05e | 6920 | ldpp_dout(dpp, 20) << "cannot find bucket = " << path.bucket_name << dendl; |
7c673cae FG |
6921 | num_unfound++; |
6922 | } else { | |
b3b6e05e | 6923 | ldpp_dout(dpp, 20) << "cannot get bucket info, ret = " << ret << dendl; |
7c673cae FG |
6924 | |
6925 | fail_desc_t failed_item = { | |
6926 | .err = ret, | |
6927 | .path = path | |
6928 | }; | |
6929 | failures.push_back(failed_item); | |
6930 | } | |
6931 | return false; | |
6932 | ||
6933 | auth_fail: | |
b3b6e05e | 6934 | ldpp_dout(dpp, 20) << "wrong auth for " << path << dendl; |
7c673cae FG |
6935 | { |
6936 | fail_desc_t failed_item = { | |
6937 | .err = ret, | |
6938 | .path = path | |
6939 | }; | |
6940 | failures.push_back(failed_item); | |
6941 | } | |
6942 | return false; | |
6943 | ||
6944 | delop_fail: | |
6945 | if (-ENOENT == ret) { | |
b3b6e05e | 6946 | ldpp_dout(dpp, 20) << "cannot find entry " << path << dendl; |
7c673cae FG |
6947 | num_unfound++; |
6948 | } else { | |
6949 | fail_desc_t failed_item = { | |
6950 | .err = ret, | |
6951 | .path = path | |
6952 | }; | |
6953 | failures.push_back(failed_item); | |
6954 | } | |
6955 | return false; | |
6956 | } | |
6957 | ||
f67539c2 | 6958 | bool RGWBulkDelete::Deleter::delete_chunk(const std::list<acct_path_t>& paths, optional_yield y) |
7c673cae | 6959 | { |
b3b6e05e | 6960 | ldpp_dout(dpp, 20) << "in delete_chunk" << dendl; |
7c673cae | 6961 | for (auto path : paths) { |
b3b6e05e | 6962 | ldpp_dout(dpp, 20) << "bulk deleting path: " << path << dendl; |
f67539c2 | 6963 | delete_single(path, y); |
7c673cae FG |
6964 | } |
6965 | ||
6966 | return true; | |
6967 | } | |
6968 | ||
f67539c2 | 6969 | int RGWBulkDelete::verify_permission(optional_yield y) |
7c673cae FG |
6970 | { |
6971 | return 0; | |
6972 | } | |
6973 | ||
6974 | void RGWBulkDelete::pre_exec() | |
6975 | { | |
6976 | rgw_bucket_object_pre_exec(s); | |
6977 | } | |
6978 | ||
f67539c2 | 6979 | void RGWBulkDelete::execute(optional_yield y) |
7c673cae | 6980 | { |
11fdf7f2 | 6981 | deleter = std::unique_ptr<Deleter>(new Deleter(this, store, s)); |
7c673cae FG |
6982 | |
6983 | bool is_truncated = false; | |
6984 | do { | |
6985 | list<RGWBulkDelete::acct_path_t> items; | |
6986 | ||
6987 | int ret = get_data(items, &is_truncated); | |
6988 | if (ret < 0) { | |
6989 | return; | |
6990 | } | |
6991 | ||
f67539c2 | 6992 | ret = deleter->delete_chunk(items, y); |
7c673cae FG |
6993 | } while (!op_ret && is_truncated); |
6994 | ||
6995 | return; | |
6996 | } | |
6997 | ||
6998 | ||
6999 | constexpr std::array<int, 2> RGWBulkUploadOp::terminal_errors; | |
7000 | ||
f67539c2 | 7001 | int RGWBulkUploadOp::verify_permission(optional_yield y) |
7c673cae FG |
7002 | { |
7003 | if (s->auth.identity->is_anonymous()) { | |
7004 | return -EACCES; | |
7005 | } | |
7006 | ||
11fdf7f2 | 7007 | if (! verify_user_permission_no_policy(this, s, RGW_PERM_WRITE)) { |
7c673cae FG |
7008 | return -EACCES; |
7009 | } | |
7010 | ||
9f95a23c | 7011 | if (s->user->get_tenant() != s->bucket_tenant) { |
11fdf7f2 | 7012 | ldpp_dout(this, 10) << "user cannot create a bucket in a different tenant" |
9f95a23c | 7013 | << " (user_id.tenant=" << s->user->get_tenant() |
11fdf7f2 | 7014 | << " requested=" << s->bucket_tenant << ")" << dendl; |
7c673cae FG |
7015 | return -EACCES; |
7016 | } | |
7017 | ||
9f95a23c | 7018 | if (s->user->get_max_buckets() < 0) { |
7c673cae FG |
7019 | return -EPERM; |
7020 | } | |
7021 | ||
7022 | return 0; | |
7023 | } | |
7024 | ||
7025 | void RGWBulkUploadOp::pre_exec() | |
7026 | { | |
7027 | rgw_bucket_object_pre_exec(s); | |
7028 | } | |
7029 | ||
7030 | boost::optional<std::pair<std::string, rgw_obj_key>> | |
f67539c2 | 7031 | RGWBulkUploadOp::parse_path(const std::string_view& path) |
7c673cae FG |
7032 | { |
7033 | /* We need to skip all slashes at the beginning in order to preserve | |
7034 | * compliance with Swift. */ | |
7035 | const size_t start_pos = path.find_first_not_of('/'); | |
7036 | ||
f67539c2 | 7037 | if (std::string_view::npos != start_pos) { |
7c673cae FG |
7038 | /* Seperator is the first slash after the leading ones. */ |
7039 | const size_t sep_pos = path.substr(start_pos).find('/'); | |
7040 | ||
f67539c2 | 7041 | if (std::string_view::npos != sep_pos) { |
7c673cae FG |
7042 | const auto bucket_name = path.substr(start_pos, sep_pos - start_pos); |
7043 | const auto obj_name = path.substr(sep_pos + 1); | |
7044 | ||
f67539c2 TL |
7045 | return std::make_pair(std::string(bucket_name), |
7046 | rgw_obj_key(std::string(obj_name))); | |
7c673cae FG |
7047 | } else { |
7048 | /* It's guaranteed here that bucket name is at least one character | |
7049 | * long and is different than slash. */ | |
f67539c2 | 7050 | return std::make_pair(std::string(path.substr(start_pos)), |
7c673cae FG |
7051 | rgw_obj_key()); |
7052 | } | |
7053 | } | |
7054 | ||
31f18b77 | 7055 | return none; |
7c673cae FG |
7056 | } |
7057 | ||
7058 | std::pair<std::string, std::string> | |
7059 | RGWBulkUploadOp::handle_upload_path(struct req_state *s) | |
7060 | { | |
7061 | std::string bucket_path, file_prefix; | |
7062 | if (! s->init_state.url_bucket.empty()) { | |
7063 | file_prefix = bucket_path = s->init_state.url_bucket + "/"; | |
f67539c2 TL |
7064 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
7065 | const std::string& object_name = s->object->get_name(); | |
7c673cae | 7066 | |
f67539c2 | 7067 | /* As rgw_obj_key::empty() already verified emptiness of s->object->get_name(), |
7c673cae FG |
7068 | * we can safely examine its last element. */ |
7069 | if (object_name.back() == '/') { | |
7070 | file_prefix.append(object_name); | |
7071 | } else { | |
7072 | file_prefix.append(object_name).append("/"); | |
7073 | } | |
7074 | } | |
7075 | } | |
7076 | return std::make_pair(bucket_path, file_prefix); | |
7077 | } | |
7078 | ||
f67539c2 | 7079 | int RGWBulkUploadOp::handle_dir_verify_permission(optional_yield y) |
7c673cae | 7080 | { |
9f95a23c TL |
7081 | if (s->user->get_max_buckets() > 0) { |
7082 | rgw::sal::RGWBucketList buckets; | |
7c673cae | 7083 | std::string marker; |
b3b6e05e | 7084 | op_ret = rgw_read_user_buckets(this, store, s->user->get_user(), buckets, |
9f95a23c | 7085 | marker, std::string(), s->user->get_max_buckets(), |
f67539c2 | 7086 | false, y); |
7c673cae FG |
7087 | if (op_ret < 0) { |
7088 | return op_ret; | |
7089 | } | |
7090 | ||
9f95a23c | 7091 | if (buckets.count() >= static_cast<size_t>(s->user->get_max_buckets())) { |
7c673cae FG |
7092 | return -ERR_TOO_MANY_BUCKETS; |
7093 | } | |
7094 | } | |
7095 | ||
7096 | return 0; | |
7097 | } | |
7098 | ||
7099 | static void forward_req_info(CephContext *cct, req_info& info, const std::string& bucket_name) | |
7100 | { | |
7101 | /* the request of container or object level will contain bucket name. | |
7102 | * only at account level need to append the bucket name */ | |
7103 | if (info.script_uri.find(bucket_name) != std::string::npos) { | |
7104 | return; | |
7105 | } | |
7106 | ||
7107 | ldout(cct, 20) << "append the bucket: "<< bucket_name << " to req_info" << dendl; | |
7108 | info.script_uri.append("/").append(bucket_name); | |
7109 | info.request_uri_aws4 = info.request_uri = info.script_uri; | |
7110 | info.effective_uri = "/" + bucket_name; | |
7111 | } | |
7112 | ||
9f95a23c | 7113 | void RGWBulkUploadOp::init(rgw::sal::RGWRadosStore* const store, |
11fdf7f2 TL |
7114 | struct req_state* const s, |
7115 | RGWHandler* const h) | |
7116 | { | |
7117 | RGWOp::init(store, s, h); | |
9f95a23c | 7118 | dir_ctx.emplace(store->svc()->sysobj->init_obj_ctx()); |
11fdf7f2 TL |
7119 | } |
7120 | ||
f67539c2 | 7121 | int RGWBulkUploadOp::handle_dir(const std::string_view path, optional_yield y) |
7c673cae | 7122 | { |
11fdf7f2 | 7123 | ldpp_dout(this, 20) << "got directory=" << path << dendl; |
7c673cae | 7124 | |
f67539c2 | 7125 | op_ret = handle_dir_verify_permission(y); |
7c673cae FG |
7126 | if (op_ret < 0) { |
7127 | return op_ret; | |
7128 | } | |
7129 | ||
7130 | std::string bucket_name; | |
7131 | rgw_obj_key object_junk; | |
7132 | std::tie(bucket_name, object_junk) = *parse_path(path); | |
7133 | ||
9f95a23c | 7134 | rgw_raw_obj obj(store->svc()->zone->get_zone_params().domain_root, |
7c673cae FG |
7135 | rgw_make_bucket_entry_name(s->bucket_tenant, bucket_name)); |
7136 | ||
7137 | /* we need to make sure we read bucket info, it's not read before for this | |
7138 | * specific request */ | |
f67539c2 | 7139 | std::unique_ptr<rgw::sal::RGWBucket> bucket; |
7c673cae FG |
7140 | |
7141 | /* Create metadata: ACLs. */ | |
7142 | std::map<std::string, ceph::bufferlist> attrs; | |
7143 | RGWAccessControlPolicy policy; | |
9f95a23c | 7144 | policy.create_default(s->user->get_id(), s->user->get_display_name()); |
7c673cae FG |
7145 | ceph::bufferlist aclbl; |
7146 | policy.encode(aclbl); | |
7147 | attrs.emplace(RGW_ATTR_ACL, std::move(aclbl)); | |
7148 | ||
f67539c2 TL |
7149 | obj_version objv, ep_objv; |
7150 | bool bucket_exists; | |
7c673cae | 7151 | RGWQuotaInfo quota_info; |
f67539c2 | 7152 | const RGWQuotaInfo* pquota_info = nullptr; |
7c673cae | 7153 | RGWBucketInfo out_info; |
f67539c2 TL |
7154 | string swift_ver_location; |
7155 | rgw_bucket new_bucket; | |
7156 | req_info info = s->info; | |
7157 | new_bucket.tenant = s->bucket_tenant; /* ignored if bucket exists */ | |
7158 | new_bucket.name = bucket_name; | |
7159 | rgw_placement_rule placement_rule; | |
7160 | placement_rule.storage_class = s->info.storage_class; | |
7161 | forward_req_info(s->cct, info, bucket_name); | |
7162 | ||
b3b6e05e | 7163 | op_ret = store->create_bucket(this, *s->user, new_bucket, |
f67539c2 TL |
7164 | store->get_zonegroup().get_id(), |
7165 | placement_rule, swift_ver_location, | |
7166 | pquota_info, policy, attrs, | |
7167 | out_info, ep_objv, | |
7168 | true, false, &bucket_exists, | |
7169 | info, &bucket, y); | |
7c673cae FG |
7170 | /* continue if EEXIST and create_bucket will fail below. this way we can |
7171 | * recover from a partial create by retrying it. */ | |
11fdf7f2 TL |
7172 | ldpp_dout(this, 20) << "rgw_create_bucket returned ret=" << op_ret |
7173 | << ", bucket=" << bucket << dendl; | |
7c673cae FG |
7174 | |
7175 | if (op_ret && op_ret != -EEXIST) { | |
7176 | return op_ret; | |
7177 | } | |
7178 | ||
7179 | const bool existed = (op_ret == -EEXIST); | |
7180 | if (existed) { | |
7181 | /* bucket already existed, might have raced with another bucket creation, or | |
7182 | * might be partial bucket creation that never completed. Read existing bucket | |
7183 | * info, verify that the reported bucket owner is the current user. | |
7184 | * If all is ok then update the user's list of buckets. | |
7185 | * Otherwise inform client about a name conflict. | |
7186 | */ | |
9f95a23c | 7187 | if (out_info.owner.compare(s->user->get_id()) != 0) { |
7c673cae | 7188 | op_ret = -EEXIST; |
11fdf7f2 | 7189 | ldpp_dout(this, 20) << "conflicting bucket name" << dendl; |
7c673cae FG |
7190 | return op_ret; |
7191 | } | |
f67539c2 | 7192 | new_bucket = out_info.bucket; |
7c673cae FG |
7193 | } |
7194 | ||
f67539c2 | 7195 | op_ret = store->ctl()->bucket->link_bucket(s->user->get_id(), new_bucket, |
9f95a23c | 7196 | out_info.creation_time, |
b3b6e05e | 7197 | s->yield, s, false); |
7c673cae FG |
7198 | if (op_ret && !existed && op_ret != -EEXIST) { |
7199 | /* if it exists (or previously existed), don't remove it! */ | |
b3b6e05e | 7200 | op_ret = store->ctl()->bucket->unlink_bucket(s->user->get_id(), new_bucket, s->yield, this); |
7c673cae | 7201 | if (op_ret < 0) { |
11fdf7f2 | 7202 | ldpp_dout(this, 0) << "WARNING: failed to unlink bucket: ret=" << op_ret << dendl; |
7c673cae FG |
7203 | } |
7204 | } else if (op_ret == -EEXIST || (op_ret == 0 && existed)) { | |
11fdf7f2 | 7205 | ldpp_dout(this, 20) << "containers already exists" << dendl; |
7c673cae FG |
7206 | op_ret = -ERR_BUCKET_EXISTS; |
7207 | } | |
7208 | ||
7209 | return op_ret; | |
7210 | } | |
7211 | ||
7212 | ||
7213 | bool RGWBulkUploadOp::handle_file_verify_permission(RGWBucketInfo& binfo, | |
31f18b77 | 7214 | const rgw_obj& obj, |
7c673cae | 7215 | std::map<std::string, ceph::bufferlist>& battrs, |
f67539c2 TL |
7216 | ACLOwner& bucket_owner /* out */, |
7217 | optional_yield y) | |
7c673cae FG |
7218 | { |
7219 | RGWAccessControlPolicy bacl(store->ctx()); | |
b3b6e05e | 7220 | op_ret = read_bucket_policy(this, store, s, binfo, battrs, &bacl, binfo.bucket, y); |
7c673cae | 7221 | if (op_ret < 0) { |
11fdf7f2 | 7222 | ldpp_dout(this, 20) << "cannot read_policy() for bucket" << dendl; |
7c673cae FG |
7223 | return false; |
7224 | } | |
7225 | ||
f67539c2 | 7226 | auto policy = get_iam_policy_from_attr(s->cct, battrs, binfo.bucket.tenant); |
31f18b77 | 7227 | |
7c673cae | 7228 | bucket_owner = bacl.get_owner(); |
522d829b TL |
7229 | if (policy || ! s->iam_user_policies.empty() || !s->session_policies.empty()) { |
7230 | auto identity_policy_res = eval_identity_or_session_policies(s->iam_user_policies, s->env, | |
11fdf7f2 TL |
7231 | boost::none, |
7232 | rgw::IAM::s3PutObject, obj); | |
522d829b | 7233 | if (identity_policy_res == Effect::Deny) { |
11fdf7f2 TL |
7234 | return false; |
7235 | } | |
522d829b TL |
7236 | |
7237 | rgw::IAM::PolicyPrincipal princ_type = rgw::IAM::PolicyPrincipal::Other; | |
31f18b77 | 7238 | auto e = policy->eval(s->env, *s->auth.identity, |
522d829b TL |
7239 | rgw::IAM::s3PutObject, obj, princ_type); |
7240 | if (e == Effect::Deny) { | |
31f18b77 | 7241 | return false; |
522d829b TL |
7242 | } |
7243 | ||
7244 | if (!s->session_policies.empty()) { | |
7245 | auto session_policy_res = eval_identity_or_session_policies(s->session_policies, s->env, | |
7246 | boost::none, | |
7247 | rgw::IAM::s3PutObject, obj); | |
7248 | if (session_policy_res == Effect::Deny) { | |
7249 | return false; | |
7250 | } | |
7251 | if (princ_type == rgw::IAM::PolicyPrincipal::Role) { | |
7252 | //Intersection of session policy and identity policy plus intersection of session policy and bucket policy | |
7253 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || | |
7254 | (session_policy_res == Effect::Allow && e == Effect::Allow)) { | |
7255 | return true; | |
7256 | } | |
7257 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Session) { | |
7258 | //Intersection of session policy and identity policy plus bucket policy | |
7259 | if ((session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) || e == Effect::Allow) { | |
7260 | return true; | |
7261 | } | |
7262 | } else if (princ_type == rgw::IAM::PolicyPrincipal::Other) {// there was no match in the bucket policy | |
7263 | if (session_policy_res == Effect::Allow && identity_policy_res == Effect::Allow) { | |
7264 | return true; | |
7265 | } | |
7266 | } | |
7267 | return false; | |
7268 | } | |
7269 | if (e == Effect::Allow || identity_policy_res == Effect::Allow) { | |
11fdf7f2 | 7270 | return true; |
31f18b77 FG |
7271 | } |
7272 | } | |
7273 | ||
11fdf7f2 | 7274 | return verify_bucket_permission_no_policy(this, s, s->user_acl.get(), |
31f18b77 | 7275 | &bacl, RGW_PERM_WRITE); |
7c673cae FG |
7276 | } |
7277 | ||
f67539c2 | 7278 | int RGWBulkUploadOp::handle_file(const std::string_view path, |
7c673cae | 7279 | const size_t size, |
f67539c2 | 7280 | AlignedStreamGetter& body, optional_yield y) |
7c673cae FG |
7281 | { |
7282 | ||
11fdf7f2 | 7283 | ldpp_dout(this, 20) << "got file=" << path << ", size=" << size << dendl; |
7c673cae | 7284 | |
11fdf7f2 | 7285 | if (size > static_cast<size_t>(s->cct->_conf->rgw_max_put_size)) { |
7c673cae FG |
7286 | op_ret = -ERR_TOO_LARGE; |
7287 | return op_ret; | |
7288 | } | |
7289 | ||
7290 | std::string bucket_name; | |
7291 | rgw_obj_key object; | |
7292 | std::tie(bucket_name, object) = *parse_path(path); | |
7293 | ||
7294 | auto& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx); | |
f67539c2 | 7295 | std::unique_ptr<rgw::sal::RGWBucket> bucket; |
7c673cae | 7296 | ACLOwner bowner; |
f67539c2 | 7297 | |
b3b6e05e | 7298 | op_ret = store->get_bucket(this, s->user.get(), rgw_bucket(rgw_bucket_key(s->user->get_tenant(), bucket_name)), &bucket, y); |
7c673cae | 7299 | if (op_ret == -ENOENT) { |
11fdf7f2 | 7300 | ldpp_dout(this, 20) << "non existent directory=" << bucket_name << dendl; |
7c673cae FG |
7301 | } else if (op_ret < 0) { |
7302 | return op_ret; | |
7303 | } | |
7304 | ||
f67539c2 TL |
7305 | std::unique_ptr<rgw::sal::RGWObject> obj = bucket->get_object(object); |
7306 | ||
7307 | if (! handle_file_verify_permission(bucket->get_info(), | |
7308 | obj->get_obj(), | |
7309 | bucket->get_attrs(), bowner, y)) { | |
11fdf7f2 | 7310 | ldpp_dout(this, 20) << "object creation unauthorized" << dendl; |
7c673cae FG |
7311 | op_ret = -EACCES; |
7312 | return op_ret; | |
7313 | } | |
7314 | ||
f67539c2 | 7315 | op_ret = bucket->check_quota(user_quota, bucket_quota, size, y); |
7c673cae FG |
7316 | if (op_ret < 0) { |
7317 | return op_ret; | |
7318 | } | |
7319 | ||
f67539c2 TL |
7320 | if (bucket->versioning_enabled()) { |
7321 | obj->gen_rand_obj_instance_name(); | |
11fdf7f2 | 7322 | } |
7c673cae | 7323 | |
11fdf7f2 | 7324 | rgw_placement_rule dest_placement = s->dest_placement; |
f67539c2 | 7325 | dest_placement.inherit_from(bucket->get_placement_rule()); |
7c673cae | 7326 | |
9f95a23c TL |
7327 | auto aio = rgw::make_throttle(s->cct->_conf->rgw_put_obj_min_window_size, |
7328 | s->yield); | |
11fdf7f2 TL |
7329 | |
7330 | using namespace rgw::putobj; | |
f67539c2 TL |
7331 | AtomicObjectProcessor processor(&*aio, store, bucket.get(), &s->dest_placement, bowner.get_id(), |
7332 | obj_ctx, std::move(obj), 0, s->req_id, this, s->yield); | |
11fdf7f2 | 7333 | |
9f95a23c | 7334 | op_ret = processor.prepare(s->yield); |
7c673cae | 7335 | if (op_ret < 0) { |
11fdf7f2 | 7336 | ldpp_dout(this, 20) << "cannot prepare processor due to ret=" << op_ret << dendl; |
7c673cae FG |
7337 | return op_ret; |
7338 | } | |
7339 | ||
11fdf7f2 TL |
7340 | /* No filters by default. */ |
7341 | DataProcessor *filter = &processor; | |
7342 | ||
9f95a23c | 7343 | const auto& compression_type = store->svc()->zone->get_zone_params().get_compression_type( |
11fdf7f2 | 7344 | dest_placement); |
7c673cae | 7345 | CompressorRef plugin; |
11fdf7f2 | 7346 | boost::optional<RGWPutObj_Compress> compressor; |
7c673cae FG |
7347 | if (compression_type != "none") { |
7348 | plugin = Compressor::create(s->cct, compression_type); | |
7349 | if (! plugin) { | |
11fdf7f2 TL |
7350 | ldpp_dout(this, 1) << "Cannot load plugin for rgw_compression_type " |
7351 | << compression_type << dendl; | |
7c673cae FG |
7352 | } else { |
7353 | compressor.emplace(s->cct, plugin, filter); | |
7354 | filter = &*compressor; | |
7355 | } | |
7356 | } | |
7357 | ||
7358 | /* Upload file content. */ | |
7359 | ssize_t len = 0; | |
7360 | size_t ofs = 0; | |
7361 | MD5 hash; | |
7362 | do { | |
7363 | ceph::bufferlist data; | |
7364 | len = body.get_at_most(s->cct->_conf->rgw_max_chunk_size, data); | |
7365 | ||
11fdf7f2 | 7366 | ldpp_dout(this, 20) << "body=" << data.c_str() << dendl; |
7c673cae FG |
7367 | if (len < 0) { |
7368 | op_ret = len; | |
7369 | return op_ret; | |
7370 | } else if (len > 0) { | |
11fdf7f2 TL |
7371 | hash.Update((const unsigned char *)data.c_str(), data.length()); |
7372 | op_ret = filter->process(std::move(data), ofs); | |
7c673cae | 7373 | if (op_ret < 0) { |
11fdf7f2 | 7374 | ldpp_dout(this, 20) << "filter->process() returned ret=" << op_ret << dendl; |
7c673cae FG |
7375 | return op_ret; |
7376 | } | |
7377 | ||
7378 | ofs += len; | |
7379 | } | |
7380 | ||
7381 | } while (len > 0); | |
7382 | ||
11fdf7f2 TL |
7383 | // flush |
7384 | op_ret = filter->process({}, ofs); | |
7385 | if (op_ret < 0) { | |
7386 | return op_ret; | |
7387 | } | |
7388 | ||
7c673cae | 7389 | if (ofs != size) { |
11fdf7f2 | 7390 | ldpp_dout(this, 10) << "real file size different from declared" << dendl; |
7c673cae | 7391 | op_ret = -EINVAL; |
11fdf7f2 | 7392 | return op_ret; |
7c673cae FG |
7393 | } |
7394 | ||
f67539c2 | 7395 | op_ret = bucket->check_quota(user_quota, bucket_quota, size, y); |
7c673cae | 7396 | if (op_ret < 0) { |
11fdf7f2 | 7397 | ldpp_dout(this, 20) << "quota exceeded for path=" << path << dendl; |
7c673cae FG |
7398 | return op_ret; |
7399 | } | |
7400 | ||
7401 | char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; | |
7402 | unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE]; | |
7403 | hash.Final(m); | |
7404 | buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5); | |
7405 | ||
7406 | /* Create metadata: ETAG. */ | |
7407 | std::map<std::string, ceph::bufferlist> attrs; | |
7408 | std::string etag = calc_md5; | |
7409 | ceph::bufferlist etag_bl; | |
7410 | etag_bl.append(etag.c_str(), etag.size() + 1); | |
7411 | attrs.emplace(RGW_ATTR_ETAG, std::move(etag_bl)); | |
7412 | ||
7413 | /* Create metadata: ACLs. */ | |
7414 | RGWAccessControlPolicy policy; | |
9f95a23c | 7415 | policy.create_default(s->user->get_id(), s->user->get_display_name()); |
7c673cae FG |
7416 | ceph::bufferlist aclbl; |
7417 | policy.encode(aclbl); | |
7418 | attrs.emplace(RGW_ATTR_ACL, std::move(aclbl)); | |
7419 | ||
7420 | /* Create metadata: compression info. */ | |
7421 | if (compressor && compressor->is_compressed()) { | |
7422 | ceph::bufferlist tmp; | |
7423 | RGWCompressionInfo cs_info; | |
7424 | cs_info.compression_type = plugin->get_type_name(); | |
7425 | cs_info.orig_size = s->obj_size; | |
f67539c2 | 7426 | cs_info.compressor_message = compressor->get_compressor_message(); |
7c673cae | 7427 | cs_info.blocks = std::move(compressor->get_compression_blocks()); |
11fdf7f2 | 7428 | encode(cs_info, tmp); |
7c673cae FG |
7429 | attrs.emplace(RGW_ATTR_COMPRESSION, std::move(tmp)); |
7430 | } | |
7431 | ||
7432 | /* Complete the transaction. */ | |
11fdf7f2 TL |
7433 | op_ret = processor.complete(size, etag, nullptr, ceph::real_time(), |
7434 | attrs, ceph::real_time() /* delete_at */, | |
9f95a23c TL |
7435 | nullptr, nullptr, nullptr, nullptr, nullptr, |
7436 | s->yield); | |
7c673cae | 7437 | if (op_ret < 0) { |
11fdf7f2 | 7438 | ldpp_dout(this, 20) << "processor::complete returned op_ret=" << op_ret << dendl; |
7c673cae FG |
7439 | } |
7440 | ||
7441 | return op_ret; | |
7442 | } | |
7443 | ||
f67539c2 | 7444 | void RGWBulkUploadOp::execute(optional_yield y) |
7c673cae FG |
7445 | { |
7446 | ceph::bufferlist buffer(64 * 1024); | |
7447 | ||
11fdf7f2 | 7448 | ldpp_dout(this, 20) << "start" << dendl; |
7c673cae FG |
7449 | |
7450 | /* Create an instance of stream-abstracting class. Having this indirection | |
7451 | * allows for easy introduction of decompressors like gzip and bzip2. */ | |
7452 | auto stream = create_stream(); | |
7453 | if (! stream) { | |
7454 | return; | |
7455 | } | |
7456 | ||
7457 | /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See: | |
7458 | * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */ | |
7459 | std::string bucket_path, file_prefix; | |
7460 | std::tie(bucket_path, file_prefix) = handle_upload_path(s); | |
7461 | ||
7462 | auto status = rgw::tar::StatusIndicator::create(); | |
7463 | do { | |
7464 | op_ret = stream->get_exactly(rgw::tar::BLOCK_SIZE, buffer); | |
7465 | if (op_ret < 0) { | |
11fdf7f2 | 7466 | ldpp_dout(this, 2) << "cannot read header" << dendl; |
7c673cae FG |
7467 | return; |
7468 | } | |
7469 | ||
7470 | /* We need to re-interpret the buffer as a TAR block. Exactly two blocks | |
7471 | * must be tracked to detect out end-of-archive. It occurs when both of | |
7472 | * them are empty (zeroed). Tracing this particular inter-block dependency | |
7473 | * is responsibility of the rgw::tar::StatusIndicator class. */ | |
7474 | boost::optional<rgw::tar::HeaderView> header; | |
7475 | std::tie(status, header) = rgw::tar::interpret_block(status, buffer); | |
7476 | ||
7477 | if (! status.empty() && header) { | |
7478 | /* This specific block isn't empty (entirely zeroed), so we can parse | |
7479 | * it as a TAR header and dispatch. At the moment we do support only | |
7480 | * regular files and directories. Everything else (symlinks, devices) | |
7481 | * will be ignored but won't cease the whole upload. */ | |
7482 | switch (header->get_filetype()) { | |
7483 | case rgw::tar::FileType::NORMAL_FILE: { | |
11fdf7f2 | 7484 | ldpp_dout(this, 2) << "handling regular file" << dendl; |
7c673cae | 7485 | |
f67539c2 TL |
7486 | std::string_view filename; |
7487 | if (bucket_path.empty()) | |
7488 | filename = header->get_filename(); | |
7489 | else | |
7490 | filename = file_prefix + std::string(header->get_filename()); | |
7491 | auto body = AlignedStreamGetter(0, header->get_filesize(), | |
7c673cae FG |
7492 | rgw::tar::BLOCK_SIZE, *stream); |
7493 | op_ret = handle_file(filename, | |
7494 | header->get_filesize(), | |
f67539c2 | 7495 | body, y); |
7c673cae FG |
7496 | if (! op_ret) { |
7497 | /* Only regular files counts. */ | |
7498 | num_created++; | |
7499 | } else { | |
f67539c2 | 7500 | failures.emplace_back(op_ret, std::string(filename)); |
7c673cae FG |
7501 | } |
7502 | break; | |
7503 | } | |
7504 | case rgw::tar::FileType::DIRECTORY: { | |
11fdf7f2 | 7505 | ldpp_dout(this, 2) << "handling regular directory" << dendl; |
7c673cae | 7506 | |
f67539c2 TL |
7507 | std::string_view dirname = bucket_path.empty() ? header->get_filename() : bucket_path; |
7508 | op_ret = handle_dir(dirname, y); | |
7c673cae | 7509 | if (op_ret < 0 && op_ret != -ERR_BUCKET_EXISTS) { |
f67539c2 | 7510 | failures.emplace_back(op_ret, std::string(dirname)); |
7c673cae FG |
7511 | } |
7512 | break; | |
7513 | } | |
7514 | default: { | |
7515 | /* Not recognized. Skip. */ | |
7516 | op_ret = 0; | |
7517 | break; | |
7518 | } | |
7519 | } | |
7520 | ||
7521 | /* In case of any problems with sub-request authorization Swift simply | |
7522 | * terminates whole upload immediately. */ | |
7523 | if (boost::algorithm::contains(std::initializer_list<int>{ op_ret }, | |
7524 | terminal_errors)) { | |
11fdf7f2 | 7525 | ldpp_dout(this, 2) << "terminating due to ret=" << op_ret << dendl; |
7c673cae FG |
7526 | break; |
7527 | } | |
7528 | } else { | |
11fdf7f2 | 7529 | ldpp_dout(this, 2) << "an empty block" << dendl; |
7c673cae FG |
7530 | op_ret = 0; |
7531 | } | |
7532 | ||
7533 | buffer.clear(); | |
7534 | } while (! status.eof()); | |
7535 | ||
7536 | return; | |
7537 | } | |
7538 | ||
7539 | RGWBulkUploadOp::AlignedStreamGetter::~AlignedStreamGetter() | |
7540 | { | |
7541 | const size_t aligned_legnth = length + (-length % alignment); | |
7542 | ceph::bufferlist junk; | |
7543 | ||
7544 | DecoratedStreamGetter::get_exactly(aligned_legnth - position, junk); | |
7545 | } | |
7546 | ||
7547 | ssize_t RGWBulkUploadOp::AlignedStreamGetter::get_at_most(const size_t want, | |
7548 | ceph::bufferlist& dst) | |
7549 | { | |
7550 | const size_t max_to_read = std::min(want, length - position); | |
7551 | const auto len = DecoratedStreamGetter::get_at_most(max_to_read, dst); | |
7552 | if (len > 0) { | |
7553 | position += len; | |
7554 | } | |
7555 | return len; | |
7556 | } | |
7557 | ||
7558 | ssize_t RGWBulkUploadOp::AlignedStreamGetter::get_exactly(const size_t want, | |
7559 | ceph::bufferlist& dst) | |
7560 | { | |
7561 | const auto len = DecoratedStreamGetter::get_exactly(want, dst); | |
7562 | if (len > 0) { | |
7563 | position += len; | |
7564 | } | |
7565 | return len; | |
7566 | } | |
7567 | ||
f67539c2 TL |
7568 | int RGWGetAttrs::verify_permission(optional_yield y) |
7569 | { | |
7570 | s->object->set_atomic(s->obj_ctx); | |
7571 | ||
7572 | auto iam_action = s->object->get_instance().empty() ? | |
7573 | rgw::IAM::s3GetObject : | |
7574 | rgw::IAM::s3GetObjectVersion; | |
7575 | ||
7576 | if (!verify_object_permission(this, s, iam_action)) { | |
7577 | return -EACCES; | |
7578 | } | |
7579 | ||
7580 | return 0; | |
7581 | } | |
7582 | ||
7583 | void RGWGetAttrs::pre_exec() | |
7584 | { | |
7585 | rgw_bucket_object_pre_exec(s); | |
7586 | } | |
7587 | ||
7588 | void RGWGetAttrs::execute(optional_yield y) | |
7589 | { | |
7590 | op_ret = get_params(); | |
7591 | if (op_ret < 0) | |
7592 | return; | |
7593 | ||
7594 | s->object->set_atomic(s->obj_ctx); | |
7595 | ||
b3b6e05e | 7596 | op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, this); |
f67539c2 TL |
7597 | if (op_ret < 0) { |
7598 | ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << s->object | |
7599 | << " ret=" << op_ret << dendl; | |
7600 | return; | |
7601 | } | |
7602 | ||
7603 | /* XXX RGWObject::get_obj_attrs() does not support filtering (yet) */ | |
7604 | auto& obj_attrs = s->object->get_attrs(); | |
7605 | if (attrs.size() != 0) { | |
7606 | /* return only attrs requested */ | |
7607 | for (auto& att : attrs) { | |
7608 | auto iter = obj_attrs.find(att.first); | |
7609 | if (iter != obj_attrs.end()) { | |
7610 | att.second = iter->second; | |
7611 | } | |
7612 | } | |
7613 | } else { | |
7614 | /* return all attrs */ | |
7615 | for (auto& att : obj_attrs) { | |
7616 | attrs.insert(get_attrs_t::value_type(att.first, att.second));; | |
7617 | } | |
7618 | } | |
7619 | ||
7620 | return; | |
7621 | } | |
7622 | ||
7623 | int RGWRMAttrs::verify_permission(optional_yield y) | |
7c673cae | 7624 | { |
31f18b77 FG |
7625 | // This looks to be part of the RGW-NFS machinery and has no S3 or |
7626 | // Swift equivalent. | |
7c673cae | 7627 | bool perm; |
f67539c2 | 7628 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
11fdf7f2 | 7629 | perm = verify_object_permission_no_policy(this, s, RGW_PERM_WRITE); |
7c673cae | 7630 | } else { |
11fdf7f2 | 7631 | perm = verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE); |
7c673cae FG |
7632 | } |
7633 | if (!perm) | |
7634 | return -EACCES; | |
7635 | ||
7636 | return 0; | |
7637 | } | |
7638 | ||
f67539c2 | 7639 | void RGWRMAttrs::pre_exec() |
7c673cae FG |
7640 | { |
7641 | rgw_bucket_object_pre_exec(s); | |
7642 | } | |
7643 | ||
f67539c2 | 7644 | void RGWRMAttrs::execute(optional_yield y) |
7c673cae FG |
7645 | { |
7646 | op_ret = get_params(); | |
7647 | if (op_ret < 0) | |
7648 | return; | |
7649 | ||
f67539c2 TL |
7650 | s->object->set_atomic(s->obj_ctx); |
7651 | ||
b3b6e05e | 7652 | op_ret = s->object->set_obj_attrs(this, s->obj_ctx, nullptr, &attrs, y); |
f67539c2 TL |
7653 | if (op_ret < 0) { |
7654 | ldpp_dout(this, 0) << "ERROR: failed to delete obj attrs, obj=" << s->object | |
7655 | << " ret=" << op_ret << dendl; | |
7656 | } | |
7657 | return; | |
7658 | } | |
7659 | ||
7660 | int RGWSetAttrs::verify_permission(optional_yield y) | |
7661 | { | |
7662 | // This looks to be part of the RGW-NFS machinery and has no S3 or | |
7663 | // Swift equivalent. | |
7664 | bool perm; | |
7665 | if (!rgw::sal::RGWObject::empty(s->object.get())) { | |
7666 | perm = verify_object_permission_no_policy(this, s, RGW_PERM_WRITE); | |
7667 | } else { | |
7668 | perm = verify_bucket_permission_no_policy(this, s, RGW_PERM_WRITE); | |
7669 | } | |
7670 | if (!perm) | |
7671 | return -EACCES; | |
7672 | ||
7673 | return 0; | |
7674 | } | |
7675 | ||
7676 | void RGWSetAttrs::pre_exec() | |
7677 | { | |
7678 | rgw_bucket_object_pre_exec(s); | |
7679 | } | |
7680 | ||
7681 | void RGWSetAttrs::execute(optional_yield y) | |
7682 | { | |
7683 | op_ret = get_params(y); | |
7684 | if (op_ret < 0) | |
7685 | return; | |
7c673cae | 7686 | |
f67539c2 TL |
7687 | if (!rgw::sal::RGWObject::empty(s->object.get())) { |
7688 | rgw::sal::RGWAttrs a(attrs); | |
b3b6e05e | 7689 | op_ret = s->object->set_obj_attrs(this, s->obj_ctx, &a, nullptr, y); |
7c673cae | 7690 | } else { |
f67539c2 TL |
7691 | op_ret = store->ctl()->bucket->set_bucket_instance_attrs( |
7692 | s->bucket->get_info(), attrs, &s->bucket->get_info().objv_tracker, | |
b3b6e05e | 7693 | s->yield, this); |
7c673cae | 7694 | } |
f67539c2 TL |
7695 | |
7696 | } /* RGWSetAttrs::execute() */ | |
7c673cae FG |
7697 | |
7698 | void RGWGetObjLayout::pre_exec() | |
7699 | { | |
7700 | rgw_bucket_object_pre_exec(s); | |
7701 | } | |
7702 | ||
f67539c2 | 7703 | void RGWGetObjLayout::execute(optional_yield y) |
7c673cae | 7704 | { |
f67539c2 TL |
7705 | /* Make sure bucket is correct */ |
7706 | s->object->set_bucket(s->bucket.get()); | |
7707 | ||
7708 | std::unique_ptr<rgw::sal::RGWObject::ReadOp> stat_op(s->object->get_read_op(s->obj_ctx)); | |
7c673cae | 7709 | |
f67539c2 | 7710 | |
b3b6e05e | 7711 | op_ret = stat_op->prepare(y, this); |
7c673cae FG |
7712 | if (op_ret < 0) { |
7713 | return; | |
7714 | } | |
7715 | ||
f67539c2 | 7716 | head_obj = stat_op->result.head_obj; |
7c673cae | 7717 | |
b3b6e05e | 7718 | op_ret = stat_op->get_manifest(this, &manifest, y); |
7c673cae FG |
7719 | } |
7720 | ||
7721 | ||
f67539c2 | 7722 | int RGWConfigBucketMetaSearch::verify_permission(optional_yield y) |
31f18b77 FG |
7723 | { |
7724 | if (!s->auth.identity->is_owner_of(s->bucket_owner.get_id())) { | |
7725 | return -EACCES; | |
7726 | } | |
7727 | ||
7728 | return 0; | |
7729 | } | |
7730 | ||
7731 | void RGWConfigBucketMetaSearch::pre_exec() | |
7732 | { | |
7733 | rgw_bucket_object_pre_exec(s); | |
7734 | } | |
7735 | ||
f67539c2 | 7736 | void RGWConfigBucketMetaSearch::execute(optional_yield y) |
31f18b77 | 7737 | { |
f67539c2 | 7738 | op_ret = get_params(y); |
31f18b77 | 7739 | if (op_ret < 0) { |
11fdf7f2 | 7740 | ldpp_dout(this, 20) << "NOTICE: get_params() returned ret=" << op_ret << dendl; |
31f18b77 FG |
7741 | return; |
7742 | } | |
7743 | ||
f67539c2 | 7744 | s->bucket->get_info().mdsearch_config = mdsearch_config; |
31f18b77 | 7745 | |
b3b6e05e | 7746 | op_ret = s->bucket->put_instance_info(this, false, real_time()); |
31f18b77 | 7747 | if (op_ret < 0) { |
f67539c2 | 7748 | ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket->get_name() |
11fdf7f2 | 7749 | << " returned err=" << op_ret << dendl; |
31f18b77 FG |
7750 | return; |
7751 | } | |
f67539c2 | 7752 | s->bucket_attrs = s->bucket->get_attrs(); |
31f18b77 FG |
7753 | } |
7754 | ||
f67539c2 | 7755 | int RGWGetBucketMetaSearch::verify_permission(optional_yield y) |
31f18b77 FG |
7756 | { |
7757 | if (!s->auth.identity->is_owner_of(s->bucket_owner.get_id())) { | |
7758 | return -EACCES; | |
7759 | } | |
7760 | ||
7761 | return 0; | |
7762 | } | |
7763 | ||
7764 | void RGWGetBucketMetaSearch::pre_exec() | |
7765 | { | |
7766 | rgw_bucket_object_pre_exec(s); | |
7767 | } | |
7768 | ||
f67539c2 | 7769 | int RGWDelBucketMetaSearch::verify_permission(optional_yield y) |
31f18b77 FG |
7770 | { |
7771 | if (!s->auth.identity->is_owner_of(s->bucket_owner.get_id())) { | |
7772 | return -EACCES; | |
7773 | } | |
7774 | ||
7775 | return 0; | |
7776 | } | |
7777 | ||
7778 | void RGWDelBucketMetaSearch::pre_exec() | |
7779 | { | |
7780 | rgw_bucket_object_pre_exec(s); | |
7781 | } | |
7782 | ||
f67539c2 | 7783 | void RGWDelBucketMetaSearch::execute(optional_yield y) |
31f18b77 | 7784 | { |
f67539c2 | 7785 | s->bucket->get_info().mdsearch_config.clear(); |
31f18b77 | 7786 | |
b3b6e05e | 7787 | op_ret = s->bucket->put_instance_info(this, false, real_time()); |
31f18b77 | 7788 | if (op_ret < 0) { |
f67539c2 | 7789 | ldpp_dout(this, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket->get_name() |
11fdf7f2 | 7790 | << " returned err=" << op_ret << dendl; |
31f18b77 FG |
7791 | return; |
7792 | } | |
f67539c2 | 7793 | s->bucket_attrs = s->bucket->get_attrs(); |
31f18b77 FG |
7794 | } |
7795 | ||
7796 | ||
7c673cae FG |
7797 | RGWHandler::~RGWHandler() |
7798 | { | |
7799 | } | |
7800 | ||
9f95a23c | 7801 | int RGWHandler::init(rgw::sal::RGWRadosStore *_store, |
7c673cae FG |
7802 | struct req_state *_s, |
7803 | rgw::io::BasicClient *cio) | |
7804 | { | |
7805 | store = _store; | |
7806 | s = _s; | |
7807 | ||
7808 | return 0; | |
7809 | } | |
7810 | ||
b3b6e05e | 7811 | int RGWHandler::do_init_permissions(const DoutPrefixProvider *dpp, optional_yield y) |
7c673cae | 7812 | { |
b3b6e05e | 7813 | int ret = rgw_build_bucket_policies(dpp, store, s, y); |
7c673cae | 7814 | if (ret < 0) { |
b3b6e05e | 7815 | ldpp_dout(dpp, 10) << "init_permissions on " << s->bucket |
11fdf7f2 TL |
7816 | << " failed, ret=" << ret << dendl; |
7817 | return ret==-ENODATA ? -EACCES : ret; | |
7c673cae FG |
7818 | } |
7819 | ||
11fdf7f2 | 7820 | rgw_build_iam_environment(store, s); |
7c673cae FG |
7821 | return ret; |
7822 | } | |
7823 | ||
f67539c2 | 7824 | int RGWHandler::do_read_permissions(RGWOp *op, bool only_bucket, optional_yield y) |
7c673cae FG |
7825 | { |
7826 | if (only_bucket) { | |
7827 | /* already read bucket info */ | |
7828 | return 0; | |
7829 | } | |
b3b6e05e | 7830 | int ret = rgw_build_object_policies(op, store, s, op->prefetch_data(), y); |
7c673cae FG |
7831 | |
7832 | if (ret < 0) { | |
11fdf7f2 | 7833 | ldpp_dout(op, 10) << "read_permissions on " << s->bucket << ":" |
7c673cae FG |
7834 | << s->object << " only_bucket=" << only_bucket |
7835 | << " ret=" << ret << dendl; | |
7836 | if (ret == -ENODATA) | |
7837 | ret = -EACCES; | |
e306af50 TL |
7838 | if (s->auth.identity->is_anonymous() && ret == -EACCES) |
7839 | ret = -EPERM; | |
7c673cae FG |
7840 | } |
7841 | ||
7842 | return ret; | |
7843 | } | |
7844 | ||
f67539c2 TL |
7845 | int RGWOp::error_handler(int err_no, string *error_content, optional_yield y) { |
7846 | return dialect_handler->error_handler(err_no, error_content, y); | |
7c673cae FG |
7847 | } |
7848 | ||
f67539c2 | 7849 | int RGWHandler::error_handler(int err_no, string *error_content, optional_yield) { |
7c673cae FG |
7850 | // This is the do-nothing error handler |
7851 | return err_no; | |
7852 | } | |
31f18b77 | 7853 | |
11fdf7f2 TL |
7854 | std::ostream& RGWOp::gen_prefix(std::ostream& out) const |
7855 | { | |
7856 | // append <dialect>:<op name> to the prefix | |
7857 | return s->gen_prefix(out) << s->dialect << ':' << name() << ' '; | |
7858 | } | |
7859 | ||
7860 | void RGWDefaultResponseOp::send_response() { | |
7861 | if (op_ret) { | |
7862 | set_req_state_err(s, op_ret); | |
7863 | } | |
7864 | dump_errno(s); | |
7865 | end_header(s); | |
7866 | } | |
31f18b77 FG |
7867 | |
7868 | void RGWPutBucketPolicy::send_response() | |
7869 | { | |
adb31ebb TL |
7870 | if (!op_ret) { |
7871 | /* A successful Put Bucket Policy should return a 204 on success */ | |
7872 | op_ret = STATUS_NO_CONTENT; | |
7873 | } | |
31f18b77 FG |
7874 | if (op_ret) { |
7875 | set_req_state_err(s, op_ret); | |
7876 | } | |
7877 | dump_errno(s); | |
7878 | end_header(s); | |
7879 | } | |
7880 | ||
f67539c2 | 7881 | int RGWPutBucketPolicy::verify_permission(optional_yield y) |
31f18b77 | 7882 | { |
11fdf7f2 | 7883 | if (!verify_bucket_permission(this, s, rgw::IAM::s3PutBucketPolicy)) { |
31f18b77 FG |
7884 | return -EACCES; |
7885 | } | |
7886 | ||
7887 | return 0; | |
7888 | } | |
7889 | ||
f67539c2 | 7890 | int RGWPutBucketPolicy::get_params(optional_yield y) |
31f18b77 FG |
7891 | { |
7892 | const auto max_size = s->cct->_conf->rgw_max_put_param_size; | |
7893 | // At some point when I have more time I want to make a version of | |
7894 | // rgw_rest_read_all_input that doesn't use malloc. | |
11fdf7f2 TL |
7895 | std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false); |
7896 | ||
31f18b77 FG |
7897 | // And throws exceptions. |
7898 | return op_ret; | |
7899 | } | |
7900 | ||
f67539c2 | 7901 | void RGWPutBucketPolicy::execute(optional_yield y) |
31f18b77 | 7902 | { |
f67539c2 | 7903 | op_ret = get_params(y); |
31f18b77 FG |
7904 | if (op_ret < 0) { |
7905 | return; | |
7906 | } | |
7907 | ||
b3b6e05e | 7908 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, data, nullptr, s->info, y); |
f67539c2 TL |
7909 | if (op_ret < 0) { |
7910 | ldpp_dout(this, 20) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
7911 | return; | |
31f18b77 FG |
7912 | } |
7913 | ||
7914 | try { | |
11fdf7f2 | 7915 | const Policy p(s->cct, s->bucket_tenant, data); |
f67539c2 | 7916 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
9f95a23c TL |
7917 | if (s->bucket_access_conf && |
7918 | s->bucket_access_conf->block_public_policy() && | |
7919 | rgw::IAM::is_public(p)) { | |
7920 | op_ret = -EACCES; | |
7921 | return; | |
7922 | } | |
7923 | ||
b3b6e05e | 7924 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [&p, this, &attrs] { |
b32b8144 FG |
7925 | attrs[RGW_ATTR_IAM_POLICY].clear(); |
7926 | attrs[RGW_ATTR_IAM_POLICY].append(p.text); | |
b3b6e05e | 7927 | op_ret = s->bucket->set_instance_attrs(this, attrs, s->yield); |
b32b8144 FG |
7928 | return op_ret; |
7929 | }); | |
31f18b77 | 7930 | } catch (rgw::IAM::PolicyParseException& e) { |
11fdf7f2 | 7931 | ldpp_dout(this, 20) << "failed to parse policy: " << e.what() << dendl; |
31f18b77 FG |
7932 | op_ret = -EINVAL; |
7933 | } | |
7934 | } | |
7935 | ||
7936 | void RGWGetBucketPolicy::send_response() | |
7937 | { | |
7938 | if (op_ret) { | |
7939 | set_req_state_err(s, op_ret); | |
7940 | } | |
7941 | dump_errno(s); | |
7942 | end_header(s, this, "application/json"); | |
7943 | dump_body(s, policy); | |
7944 | } | |
7945 | ||
f67539c2 | 7946 | int RGWGetBucketPolicy::verify_permission(optional_yield y) |
31f18b77 | 7947 | { |
11fdf7f2 | 7948 | if (!verify_bucket_permission(this, s, rgw::IAM::s3GetBucketPolicy)) { |
31f18b77 FG |
7949 | return -EACCES; |
7950 | } | |
7951 | ||
7952 | return 0; | |
7953 | } | |
7954 | ||
f67539c2 | 7955 | void RGWGetBucketPolicy::execute(optional_yield y) |
31f18b77 | 7956 | { |
f67539c2 TL |
7957 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
7958 | auto aiter = attrs.find(RGW_ATTR_IAM_POLICY); | |
31f18b77 | 7959 | if (aiter == attrs.end()) { |
11fdf7f2 TL |
7960 | ldpp_dout(this, 0) << "can't find bucket IAM POLICY attr bucket_name = " |
7961 | << s->bucket_name << dendl; | |
31f18b77 FG |
7962 | op_ret = -ERR_NO_SUCH_BUCKET_POLICY; |
7963 | s->err.message = "The bucket policy does not exist"; | |
7964 | return; | |
7965 | } else { | |
7966 | policy = attrs[RGW_ATTR_IAM_POLICY]; | |
7967 | ||
7968 | if (policy.length() == 0) { | |
11fdf7f2 TL |
7969 | ldpp_dout(this, 10) << "The bucket policy does not exist, bucket: " |
7970 | << s->bucket_name << dendl; | |
31f18b77 FG |
7971 | op_ret = -ERR_NO_SUCH_BUCKET_POLICY; |
7972 | s->err.message = "The bucket policy does not exist"; | |
7973 | return; | |
7974 | } | |
7975 | } | |
7976 | } | |
7977 | ||
7978 | void RGWDeleteBucketPolicy::send_response() | |
7979 | { | |
7980 | if (op_ret) { | |
7981 | set_req_state_err(s, op_ret); | |
7982 | } | |
7983 | dump_errno(s); | |
7984 | end_header(s); | |
7985 | } | |
7986 | ||
f67539c2 | 7987 | int RGWDeleteBucketPolicy::verify_permission(optional_yield y) |
31f18b77 | 7988 | { |
11fdf7f2 | 7989 | if (!verify_bucket_permission(this, s, rgw::IAM::s3DeleteBucketPolicy)) { |
31f18b77 FG |
7990 | return -EACCES; |
7991 | } | |
7992 | ||
7993 | return 0; | |
7994 | } | |
7995 | ||
f67539c2 | 7996 | void RGWDeleteBucketPolicy::execute(optional_yield y) |
31f18b77 | 7997 | { |
b3b6e05e | 7998 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 | 7999 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
b32b8144 | 8000 | attrs.erase(RGW_ATTR_IAM_POLICY); |
b3b6e05e | 8001 | op_ret = s->bucket->set_instance_attrs(this, attrs, s->yield); |
b32b8144 FG |
8002 | return op_ret; |
8003 | }); | |
31f18b77 | 8004 | } |
28e407b8 | 8005 | |
eafe8130 TL |
8006 | void RGWPutBucketObjectLock::pre_exec() |
8007 | { | |
8008 | rgw_bucket_object_pre_exec(s); | |
8009 | } | |
8010 | ||
f67539c2 | 8011 | int RGWPutBucketObjectLock::verify_permission(optional_yield y) |
eafe8130 TL |
8012 | { |
8013 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3PutBucketObjectLockConfiguration); | |
8014 | } | |
8015 | ||
f67539c2 | 8016 | void RGWPutBucketObjectLock::execute(optional_yield y) |
eafe8130 | 8017 | { |
f67539c2 | 8018 | if (!s->bucket->get_info().obj_lock_enabled()) { |
522d829b TL |
8019 | s->err.message = "object lock configuration can't be set if bucket object lock not enabled"; |
8020 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8021 | op_ret = -ERR_INVALID_BUCKET_STATE; |
8022 | return; | |
8023 | } | |
8024 | ||
8025 | RGWXMLDecoder::XMLParser parser; | |
8026 | if (!parser.init()) { | |
8027 | ldpp_dout(this, 0) << "ERROR: failed to initialize parser" << dendl; | |
8028 | op_ret = -EINVAL; | |
8029 | return; | |
8030 | } | |
f67539c2 | 8031 | op_ret = get_params(y); |
eafe8130 TL |
8032 | if (op_ret < 0) { |
8033 | return; | |
8034 | } | |
8035 | if (!parser.parse(data.c_str(), data.length(), 1)) { | |
8036 | op_ret = -ERR_MALFORMED_XML; | |
8037 | return; | |
8038 | } | |
8039 | ||
8040 | try { | |
8041 | RGWXMLDecoder::decode_xml("ObjectLockConfiguration", obj_lock, &parser, true); | |
8042 | } catch (RGWXMLDecoder::err& err) { | |
b3b6e05e | 8043 | ldpp_dout(this, 5) << "unexpected xml:" << err << dendl; |
eafe8130 TL |
8044 | op_ret = -ERR_MALFORMED_XML; |
8045 | return; | |
8046 | } | |
8047 | if (obj_lock.has_rule() && !obj_lock.retention_period_valid()) { | |
522d829b TL |
8048 | s->err.message = "retention period must be a positive integer value"; |
8049 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8050 | op_ret = -ERR_INVALID_RETENTION_PERIOD; |
8051 | return; | |
8052 | } | |
8053 | ||
b3b6e05e | 8054 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, data, nullptr, s->info, y); |
f67539c2 | 8055 | if (op_ret < 0) { |
b3b6e05e | 8056 | ldpp_dout(this, 20) << __func__ << "forward_request_to_master returned ret=" << op_ret << dendl; |
f67539c2 | 8057 | return; |
eafe8130 TL |
8058 | } |
8059 | ||
b3b6e05e | 8060 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 | 8061 | s->bucket->get_info().obj_lock = obj_lock; |
b3b6e05e | 8062 | op_ret = s->bucket->put_instance_info(this, false, real_time()); |
eafe8130 TL |
8063 | return op_ret; |
8064 | }); | |
8065 | return; | |
8066 | } | |
8067 | ||
8068 | void RGWGetBucketObjectLock::pre_exec() | |
8069 | { | |
8070 | rgw_bucket_object_pre_exec(s); | |
8071 | } | |
8072 | ||
f67539c2 | 8073 | int RGWGetBucketObjectLock::verify_permission(optional_yield y) |
eafe8130 TL |
8074 | { |
8075 | return verify_bucket_owner_or_policy(s, rgw::IAM::s3GetBucketObjectLockConfiguration); | |
8076 | } | |
8077 | ||
f67539c2 | 8078 | void RGWGetBucketObjectLock::execute(optional_yield y) |
eafe8130 | 8079 | { |
f67539c2 | 8080 | if (!s->bucket->get_info().obj_lock_enabled()) { |
eafe8130 TL |
8081 | op_ret = -ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION; |
8082 | return; | |
8083 | } | |
8084 | } | |
8085 | ||
f67539c2 | 8086 | int RGWPutObjRetention::verify_permission(optional_yield y) |
eafe8130 TL |
8087 | { |
8088 | if (!verify_object_permission(this, s, rgw::IAM::s3PutObjectRetention)) { | |
8089 | return -EACCES; | |
8090 | } | |
f67539c2 | 8091 | op_ret = get_params(y); |
eafe8130 TL |
8092 | if (op_ret) { |
8093 | return op_ret; | |
8094 | } | |
8095 | if (bypass_governance_mode) { | |
8096 | bypass_perm = verify_object_permission(this, s, rgw::IAM::s3BypassGovernanceRetention); | |
8097 | } | |
8098 | return 0; | |
8099 | } | |
8100 | ||
8101 | void RGWPutObjRetention::pre_exec() | |
8102 | { | |
8103 | rgw_bucket_object_pre_exec(s); | |
8104 | } | |
8105 | ||
f67539c2 | 8106 | void RGWPutObjRetention::execute(optional_yield y) |
eafe8130 | 8107 | { |
f67539c2 | 8108 | if (!s->bucket->get_info().obj_lock_enabled()) { |
522d829b TL |
8109 | s->err.message = "object retention can't be set if bucket object lock not configured"; |
8110 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8111 | op_ret = -ERR_INVALID_REQUEST; |
8112 | return; | |
8113 | } | |
8114 | ||
8115 | RGWXMLDecoder::XMLParser parser; | |
8116 | if (!parser.init()) { | |
8117 | ldpp_dout(this, 0) << "ERROR: failed to initialize parser" << dendl; | |
8118 | op_ret = -EINVAL; | |
8119 | return; | |
8120 | } | |
8121 | ||
8122 | if (!parser.parse(data.c_str(), data.length(), 1)) { | |
8123 | op_ret = -ERR_MALFORMED_XML; | |
8124 | return; | |
8125 | } | |
8126 | ||
8127 | try { | |
8128 | RGWXMLDecoder::decode_xml("Retention", obj_retention, &parser, true); | |
8129 | } catch (RGWXMLDecoder::err& err) { | |
8130 | ldpp_dout(this, 5) << "unexpected xml:" << err << dendl; | |
8131 | op_ret = -ERR_MALFORMED_XML; | |
8132 | return; | |
8133 | } | |
8134 | ||
8135 | if (ceph::real_clock::to_time_t(obj_retention.get_retain_until_date()) < ceph_clock_now()) { | |
522d829b TL |
8136 | s->err.message = "the retain-until date must be in the future"; |
8137 | ldpp_dout(this, 0) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8138 | op_ret = -EINVAL; |
8139 | return; | |
8140 | } | |
8141 | bufferlist bl; | |
8142 | obj_retention.encode(bl); | |
eafe8130 TL |
8143 | |
8144 | //check old retention | |
b3b6e05e | 8145 | op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, this); |
eafe8130 TL |
8146 | if (op_ret < 0) { |
8147 | ldpp_dout(this, 0) << "ERROR: get obj attr error"<< dendl; | |
8148 | return; | |
8149 | } | |
f67539c2 | 8150 | rgw::sal::RGWAttrs attrs = s->object->get_attrs(); |
eafe8130 TL |
8151 | auto aiter = attrs.find(RGW_ATTR_OBJECT_RETENTION); |
8152 | if (aiter != attrs.end()) { | |
8153 | RGWObjectRetention old_obj_retention; | |
8154 | try { | |
8155 | decode(old_obj_retention, aiter->second); | |
8156 | } catch (buffer::error& err) { | |
8157 | ldpp_dout(this, 0) << "ERROR: failed to decode RGWObjectRetention" << dendl; | |
8158 | op_ret = -EIO; | |
8159 | return; | |
8160 | } | |
8161 | if (ceph::real_clock::to_time_t(obj_retention.get_retain_until_date()) < ceph::real_clock::to_time_t(old_obj_retention.get_retain_until_date())) { | |
8162 | if (old_obj_retention.get_mode().compare("GOVERNANCE") != 0 || !bypass_perm || !bypass_governance_mode) { | |
522d829b | 8163 | s->err.message = "proposed retain-until date shortens an existing retention period and governance bypass check failed"; |
eafe8130 TL |
8164 | op_ret = -EACCES; |
8165 | return; | |
8166 | } | |
8167 | } | |
8168 | } | |
8169 | ||
b3b6e05e | 8170 | op_ret = s->object->modify_obj_attrs(s->obj_ctx, RGW_ATTR_OBJECT_RETENTION, bl, s->yield, this); |
eafe8130 TL |
8171 | |
8172 | return; | |
8173 | } | |
8174 | ||
f67539c2 | 8175 | int RGWGetObjRetention::verify_permission(optional_yield y) |
eafe8130 TL |
8176 | { |
8177 | if (!verify_object_permission(this, s, rgw::IAM::s3GetObjectRetention)) { | |
8178 | return -EACCES; | |
8179 | } | |
8180 | return 0; | |
8181 | } | |
8182 | ||
8183 | void RGWGetObjRetention::pre_exec() | |
8184 | { | |
8185 | rgw_bucket_object_pre_exec(s); | |
8186 | } | |
8187 | ||
f67539c2 | 8188 | void RGWGetObjRetention::execute(optional_yield y) |
eafe8130 | 8189 | { |
f67539c2 | 8190 | if (!s->bucket->get_info().obj_lock_enabled()) { |
522d829b TL |
8191 | s->err.message = "bucket object lock not configured"; |
8192 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8193 | op_ret = -ERR_INVALID_REQUEST; |
8194 | return; | |
8195 | } | |
b3b6e05e | 8196 | op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, this); |
eafe8130 | 8197 | if (op_ret < 0) { |
f67539c2 | 8198 | ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << s->object |
eafe8130 TL |
8199 | << " ret=" << op_ret << dendl; |
8200 | return; | |
8201 | } | |
f67539c2 | 8202 | rgw::sal::RGWAttrs attrs = s->object->get_attrs(); |
eafe8130 TL |
8203 | auto aiter = attrs.find(RGW_ATTR_OBJECT_RETENTION); |
8204 | if (aiter == attrs.end()) { | |
8205 | op_ret = -ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION; | |
8206 | return; | |
8207 | } | |
8208 | ||
8209 | bufferlist::const_iterator iter{&aiter->second}; | |
8210 | try { | |
8211 | obj_retention.decode(iter); | |
8212 | } catch (const buffer::error& e) { | |
b3b6e05e | 8213 | ldpp_dout(this, 0) << __func__ << "decode object retention config failed" << dendl; |
eafe8130 TL |
8214 | op_ret = -EIO; |
8215 | return; | |
8216 | } | |
8217 | return; | |
8218 | } | |
8219 | ||
f67539c2 | 8220 | int RGWPutObjLegalHold::verify_permission(optional_yield y) |
eafe8130 TL |
8221 | { |
8222 | if (!verify_object_permission(this, s, rgw::IAM::s3PutObjectLegalHold)) { | |
8223 | return -EACCES; | |
8224 | } | |
8225 | return 0; | |
8226 | } | |
8227 | ||
8228 | void RGWPutObjLegalHold::pre_exec() | |
8229 | { | |
8230 | rgw_bucket_object_pre_exec(s); | |
8231 | } | |
8232 | ||
f67539c2 TL |
8233 | void RGWPutObjLegalHold::execute(optional_yield y) { |
8234 | if (!s->bucket->get_info().obj_lock_enabled()) { | |
522d829b TL |
8235 | s->err.message = "object legal hold can't be set if bucket object lock not enabled"; |
8236 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8237 | op_ret = -ERR_INVALID_REQUEST; |
8238 | return; | |
8239 | } | |
8240 | ||
8241 | RGWXMLDecoder::XMLParser parser; | |
8242 | if (!parser.init()) { | |
8243 | ldpp_dout(this, 0) << "ERROR: failed to initialize parser" << dendl; | |
8244 | op_ret = -EINVAL; | |
8245 | return; | |
8246 | } | |
8247 | ||
f67539c2 | 8248 | op_ret = get_params(y); |
eafe8130 TL |
8249 | if (op_ret < 0) |
8250 | return; | |
8251 | ||
8252 | if (!parser.parse(data.c_str(), data.length(), 1)) { | |
8253 | op_ret = -ERR_MALFORMED_XML; | |
8254 | return; | |
8255 | } | |
8256 | ||
8257 | try { | |
8258 | RGWXMLDecoder::decode_xml("LegalHold", obj_legal_hold, &parser, true); | |
8259 | } catch (RGWXMLDecoder::err &err) { | |
b3b6e05e | 8260 | ldpp_dout(this, 5) << "unexpected xml:" << err << dendl; |
eafe8130 TL |
8261 | op_ret = -ERR_MALFORMED_XML; |
8262 | return; | |
8263 | } | |
8264 | bufferlist bl; | |
8265 | obj_legal_hold.encode(bl); | |
eafe8130 | 8266 | //if instance is empty, we should modify the latest object |
b3b6e05e | 8267 | op_ret = s->object->modify_obj_attrs(s->obj_ctx, RGW_ATTR_OBJECT_LEGAL_HOLD, bl, s->yield, this); |
eafe8130 TL |
8268 | return; |
8269 | } | |
8270 | ||
f67539c2 | 8271 | int RGWGetObjLegalHold::verify_permission(optional_yield y) |
eafe8130 TL |
8272 | { |
8273 | if (!verify_object_permission(this, s, rgw::IAM::s3GetObjectLegalHold)) { | |
8274 | return -EACCES; | |
8275 | } | |
8276 | return 0; | |
8277 | } | |
8278 | ||
8279 | void RGWGetObjLegalHold::pre_exec() | |
8280 | { | |
8281 | rgw_bucket_object_pre_exec(s); | |
8282 | } | |
8283 | ||
f67539c2 | 8284 | void RGWGetObjLegalHold::execute(optional_yield y) |
eafe8130 | 8285 | { |
f67539c2 | 8286 | if (!s->bucket->get_info().obj_lock_enabled()) { |
522d829b TL |
8287 | s->err.message = "bucket object lock not configured"; |
8288 | ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl; | |
eafe8130 TL |
8289 | op_ret = -ERR_INVALID_REQUEST; |
8290 | return; | |
8291 | } | |
eafe8130 | 8292 | map<string, bufferlist> attrs; |
b3b6e05e | 8293 | op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield, this); |
eafe8130 | 8294 | if (op_ret < 0) { |
f67539c2 | 8295 | ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << s->object |
eafe8130 TL |
8296 | << " ret=" << op_ret << dendl; |
8297 | return; | |
8298 | } | |
f67539c2 TL |
8299 | auto aiter = s->object->get_attrs().find(RGW_ATTR_OBJECT_LEGAL_HOLD); |
8300 | if (aiter == s->object->get_attrs().end()) { | |
eafe8130 TL |
8301 | op_ret = -ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION; |
8302 | return; | |
8303 | } | |
8304 | ||
8305 | bufferlist::const_iterator iter{&aiter->second}; | |
8306 | try { | |
8307 | obj_legal_hold.decode(iter); | |
8308 | } catch (const buffer::error& e) { | |
b3b6e05e | 8309 | ldpp_dout(this, 0) << __func__ << "decode object legal hold config failed" << dendl; |
eafe8130 TL |
8310 | op_ret = -EIO; |
8311 | return; | |
8312 | } | |
8313 | return; | |
8314 | } | |
8315 | ||
f67539c2 | 8316 | void RGWGetClusterStat::execute(optional_yield y) |
28e407b8 | 8317 | { |
f67539c2 | 8318 | op_ret = store->cluster_stat(stats_op); |
28e407b8 AA |
8319 | } |
8320 | ||
f67539c2 | 8321 | int RGWGetBucketPolicyStatus::verify_permission(optional_yield y) |
9f95a23c TL |
8322 | { |
8323 | if (!verify_bucket_permission(this, s, rgw::IAM::s3GetBucketPolicyStatus)) { | |
8324 | return -EACCES; | |
8325 | } | |
8326 | ||
8327 | return 0; | |
8328 | } | |
8329 | ||
f67539c2 | 8330 | void RGWGetBucketPolicyStatus::execute(optional_yield y) |
9f95a23c | 8331 | { |
b3b6e05e | 8332 | isPublic = (s->iam_policy && rgw::IAM::is_public(*s->iam_policy)) || s->bucket_acl->is_public(this); |
9f95a23c TL |
8333 | } |
8334 | ||
f67539c2 | 8335 | int RGWPutBucketPublicAccessBlock::verify_permission(optional_yield y) |
9f95a23c TL |
8336 | { |
8337 | if (!verify_bucket_permission(this, s, rgw::IAM::s3PutBucketPublicAccessBlock)) { | |
8338 | return -EACCES; | |
8339 | } | |
8340 | ||
8341 | return 0; | |
8342 | } | |
8343 | ||
f67539c2 | 8344 | int RGWPutBucketPublicAccessBlock::get_params(optional_yield y) |
9f95a23c TL |
8345 | { |
8346 | const auto max_size = s->cct->_conf->rgw_max_put_param_size; | |
8347 | std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false); | |
8348 | return op_ret; | |
8349 | } | |
8350 | ||
f67539c2 | 8351 | void RGWPutBucketPublicAccessBlock::execute(optional_yield y) |
9f95a23c TL |
8352 | { |
8353 | RGWXMLDecoder::XMLParser parser; | |
8354 | if (!parser.init()) { | |
8355 | ldpp_dout(this, 0) << "ERROR: failed to initialize parser" << dendl; | |
8356 | op_ret = -EINVAL; | |
8357 | return; | |
8358 | } | |
8359 | ||
f67539c2 | 8360 | op_ret = get_params(y); |
9f95a23c TL |
8361 | if (op_ret < 0) |
8362 | return; | |
8363 | ||
8364 | if (!parser.parse(data.c_str(), data.length(), 1)) { | |
8365 | ldpp_dout(this, 0) << "ERROR: malformed XML" << dendl; | |
8366 | op_ret = -ERR_MALFORMED_XML; | |
8367 | return; | |
8368 | } | |
8369 | ||
8370 | try { | |
8371 | RGWXMLDecoder::decode_xml("PublicAccessBlockConfiguration", access_conf, &parser, true); | |
8372 | } catch (RGWXMLDecoder::err &err) { | |
8373 | ldpp_dout(this, 5) << "unexpected xml:" << err << dendl; | |
8374 | op_ret = -ERR_MALFORMED_XML; | |
8375 | return; | |
8376 | } | |
8377 | ||
b3b6e05e | 8378 | op_ret = store->forward_request_to_master(this, s->user.get(), nullptr, data, nullptr, s->info, y); |
f67539c2 TL |
8379 | if (op_ret < 0) { |
8380 | ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; | |
8381 | return; | |
9f95a23c TL |
8382 | } |
8383 | ||
8384 | bufferlist bl; | |
8385 | access_conf.encode(bl); | |
b3b6e05e | 8386 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this, &bl] { |
f67539c2 | 8387 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
9f95a23c | 8388 | attrs[RGW_ATTR_PUBLIC_ACCESS] = bl; |
b3b6e05e | 8389 | return s->bucket->set_instance_attrs(this, attrs, s->yield); |
9f95a23c TL |
8390 | }); |
8391 | ||
8392 | } | |
8393 | ||
f67539c2 | 8394 | int RGWGetBucketPublicAccessBlock::verify_permission(optional_yield y) |
9f95a23c TL |
8395 | { |
8396 | if (!verify_bucket_permission(this, s, rgw::IAM::s3GetBucketPolicy)) { | |
8397 | return -EACCES; | |
8398 | } | |
8399 | ||
8400 | return 0; | |
8401 | } | |
8402 | ||
f67539c2 | 8403 | void RGWGetBucketPublicAccessBlock::execute(optional_yield y) |
9f95a23c TL |
8404 | { |
8405 | auto attrs = s->bucket_attrs; | |
8406 | if (auto aiter = attrs.find(RGW_ATTR_PUBLIC_ACCESS); | |
8407 | aiter == attrs.end()) { | |
8408 | ldpp_dout(this, 0) << "can't find bucket IAM POLICY attr bucket_name = " | |
8409 | << s->bucket_name << dendl; | |
8410 | // return the default; | |
8411 | return; | |
8412 | } else { | |
8413 | bufferlist::const_iterator iter{&aiter->second}; | |
8414 | try { | |
8415 | access_conf.decode(iter); | |
8416 | } catch (const buffer::error& e) { | |
8417 | ldpp_dout(this, 0) << __func__ << "decode access_conf failed" << dendl; | |
8418 | op_ret = -EIO; | |
8419 | return; | |
8420 | } | |
8421 | } | |
8422 | } | |
8423 | ||
8424 | ||
8425 | void RGWDeleteBucketPublicAccessBlock::send_response() | |
8426 | { | |
8427 | if (op_ret) { | |
8428 | set_req_state_err(s, op_ret); | |
8429 | } | |
8430 | dump_errno(s); | |
8431 | end_header(s); | |
8432 | } | |
8433 | ||
f67539c2 | 8434 | int RGWDeleteBucketPublicAccessBlock::verify_permission(optional_yield y) |
9f95a23c TL |
8435 | { |
8436 | if (!verify_bucket_permission(this, s, rgw::IAM::s3PutBucketPublicAccessBlock)) { | |
8437 | return -EACCES; | |
8438 | } | |
8439 | ||
8440 | return 0; | |
8441 | } | |
8442 | ||
f67539c2 | 8443 | void RGWDeleteBucketPublicAccessBlock::execute(optional_yield y) |
9f95a23c | 8444 | { |
b3b6e05e | 8445 | op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] { |
f67539c2 | 8446 | rgw::sal::RGWAttrs attrs(s->bucket_attrs); |
9f95a23c | 8447 | attrs.erase(RGW_ATTR_PUBLIC_ACCESS); |
b3b6e05e | 8448 | op_ret = s->bucket->set_instance_attrs(this, attrs, s->yield); |
9f95a23c TL |
8449 | return op_ret; |
8450 | }); | |
8451 | } |