1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
7 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
16 #ifndef CEPH_RGW_COMMON_H
17 #define CEPH_RGW_COMMON_H
21 #include <boost/utility/string_view.hpp>
23 #include "common/ceph_crypto.h"
24 #include "common/perf_counters.h"
28 #include "rgw_iam_policy.h"
29 #include "rgw_quota.h"
30 #include "rgw_string.h"
31 #include "rgw_website.h"
32 #include "cls/version/cls_version_types.h"
33 #include "cls/user/cls_user_types.h"
34 #include "cls/rgw/cls_rgw_types.h"
35 #include "include/rados/librados.hpp"
41 using ceph::crypto::MD5
;
44 #define RGW_ATTR_PREFIX "user.rgw."
46 #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_"
47 #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-"
49 #define RGW_AMZ_PREFIX "x-amz-"
50 #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-"
51 #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location"
52 #define RGW_AMZ_TAG_COUNT RGW_AMZ_PREFIX "tagging-count"
54 #define RGW_SYS_PARAM_PREFIX "rgwx-"
56 #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl"
57 #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc"
58 #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
59 #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
60 #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
61 #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
62 #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
63 #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control"
64 #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition"
65 #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding"
66 #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language"
67 #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires"
68 #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at"
69 #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag"
70 #define RGW_ATTR_TAIL_TAG RGW_ATTR_PREFIX "tail_tag"
71 #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name"
72 #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest"
73 #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest"
74 #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION
75 #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest"
76 /* Information whether an object is SLO or not must be exposed to
77 * user through custom HTTP header named X-Static-Large-Object. */
78 #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object"
79 #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
81 #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
82 #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"
83 #define RGW_ATTR_TAGS RGW_ATTR_PREFIX RGW_AMZ_PREFIX "tagging"
85 #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key"
86 #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2"
88 /* Account/container quota of the Swift API. */
89 #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count"
90 #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes"
92 /* Static Web Site of Swift API. */
93 #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index"
94 #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error"
95 #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings"
96 #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css"
97 #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type"
99 #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh."
101 #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info"
102 #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver"
103 #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag"
104 #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending."
106 #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression"
109 #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy"
112 /* RGW File Attributes */
113 #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1"
114 #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1"
116 #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt."
117 #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode"
118 #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5"
119 #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid"
120 #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel"
122 #define RGW_BUCKETS_OBJ_SUFFIX ".buckets"
124 #define RGW_FORMAT_PLAIN 0
125 #define RGW_FORMAT_XML 1
126 #define RGW_FORMAT_JSON 2
127 #define RGW_FORMAT_HTML 3
129 #define RGW_CAP_READ 0x1
130 #define RGW_CAP_WRITE 0x2
131 #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE)
133 #define RGW_REST_SWIFT 0x1
134 #define RGW_REST_SWIFT_AUTH 0x2
135 #define RGW_REST_S3 0x4
136 #define RGW_REST_WEBSITE 0x8
138 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2
140 #define RGW_OP_TYPE_READ 0x01
141 #define RGW_OP_TYPE_WRITE 0x02
142 #define RGW_OP_TYPE_DELETE 0x04
144 #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
145 #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
147 #define RGW_DEFAULT_MAX_BUCKETS 1000
149 #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1
150 #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2
152 #define STATUS_CREATED 1900
153 #define STATUS_ACCEPTED 1901
154 #define STATUS_NO_CONTENT 1902
155 #define STATUS_PARTIAL_CONTENT 1903
156 #define STATUS_REDIRECT 1904
157 #define STATUS_NO_APPLY 1905
158 #define STATUS_APPLIED 1906
160 #define ERR_INVALID_BUCKET_NAME 2000
161 #define ERR_INVALID_OBJECT_NAME 2001
162 #define ERR_NO_SUCH_BUCKET 2002
163 #define ERR_METHOD_NOT_ALLOWED 2003
164 #define ERR_INVALID_DIGEST 2004
165 #define ERR_BAD_DIGEST 2005
166 #define ERR_UNRESOLVABLE_EMAIL 2006
167 #define ERR_INVALID_PART 2007
168 #define ERR_INVALID_PART_ORDER 2008
169 #define ERR_NO_SUCH_UPLOAD 2009
170 #define ERR_REQUEST_TIMEOUT 2010
171 #define ERR_LENGTH_REQUIRED 2011
172 #define ERR_REQUEST_TIME_SKEWED 2012
173 #define ERR_BUCKET_EXISTS 2013
174 #define ERR_BAD_URL 2014
175 #define ERR_PRECONDITION_FAILED 2015
176 #define ERR_NOT_MODIFIED 2016
177 #define ERR_INVALID_UTF8 2017
178 #define ERR_UNPROCESSABLE_ENTITY 2018
179 #define ERR_TOO_LARGE 2019
180 #define ERR_TOO_MANY_BUCKETS 2020
181 #define ERR_INVALID_REQUEST 2021
182 #define ERR_TOO_SMALL 2022
183 #define ERR_NOT_FOUND 2023
184 #define ERR_PERMANENT_REDIRECT 2024
185 #define ERR_LOCKED 2025
186 #define ERR_QUOTA_EXCEEDED 2026
187 #define ERR_SIGNATURE_NO_MATCH 2027
188 #define ERR_INVALID_ACCESS_KEY 2028
189 #define ERR_MALFORMED_XML 2029
190 #define ERR_USER_EXIST 2030
191 #define ERR_NOT_SLO_MANIFEST 2031
192 #define ERR_EMAIL_EXIST 2032
193 #define ERR_KEY_EXIST 2033
194 #define ERR_INVALID_SECRET_KEY 2034
195 #define ERR_INVALID_KEY_TYPE 2035
196 #define ERR_INVALID_CAP 2036
197 #define ERR_INVALID_TENANT_NAME 2037
198 #define ERR_WEBSITE_REDIRECT 2038
199 #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039
200 #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040
201 #define ERR_NO_SUCH_LC 2041
202 #define ERR_NO_SUCH_USER 2042
203 #define ERR_NO_SUCH_SUBUSER 2043
204 #define ERR_USER_SUSPENDED 2100
205 #define ERR_INTERNAL_ERROR 2200
206 #define ERR_NOT_IMPLEMENTED 2201
207 #define ERR_SERVICE_UNAVAILABLE 2202
208 #define ERR_ROLE_EXISTS 2203
209 #define ERR_MALFORMED_DOC 2204
210 #define ERR_NO_ROLE_FOUND 2205
211 #define ERR_DELETE_CONFLICT 2206
212 #define ERR_NO_SUCH_BUCKET_POLICY 2207
213 #define ERR_INVALID_LOCATION_CONSTRAINT 2208
214 #define ERR_TAG_CONFLICT 2209
215 #define ERR_INVALID_TAG 2210
216 #define ERR_ZERO_IN_URL 2211
217 #define ERR_MALFORMED_ACL_ERROR 2212
218 #define ERR_ZONEGROUP_DEFAULT_PLACEMENT_MISCONFIGURATION 2213
219 #define ERR_INVALID_ENCRYPTION_ALGORITHM 2214
221 #define ERR_BUSY_RESHARDING 2300
224 #define UINT32_MAX (0xffffffffu)
229 typedef void *RGWAccessHandle
;
234 extern PerfCounters
*perfcounter
;
236 extern int rgw_perf_start(CephContext
*cct
);
237 extern void rgw_perf_stop(CephContext
*cct
);
258 l_rgw_keystone_token_cache_hit
,
259 l_rgw_keystone_token_cache_miss
,
265 /* size should be the required string size + 1 */
266 extern int gen_rand_base64(CephContext
*cct
, char *dest
, int size
);
267 extern int gen_rand_alphanumeric(CephContext
*cct
, char *dest
, int size
);
268 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, char *dest
, int size
);
269 extern int gen_rand_alphanumeric_upper(CephContext
*cct
, char *dest
, int size
);
270 extern int gen_rand_alphanumeric_no_underscore(CephContext
*cct
, char *dest
, int size
);
271 extern int gen_rand_alphanumeric_plain(CephContext
*cct
, char *dest
, int size
);
273 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, string
*str
, int length
);
275 enum RGWIntentEvent
{
280 enum RGWObjCategory
{
281 RGW_OBJ_CATEGORY_NONE
= 0,
282 RGW_OBJ_CATEGORY_MAIN
= 1,
283 RGW_OBJ_CATEGORY_SHADOW
= 2,
284 RGW_OBJ_CATEGORY_MULTIMETA
= 3,
287 /** Store error returns for output at a different point in the program */
291 bool is_clear() const;
293 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
297 std::string err_code
;
303 /* Helper class used for RGWHTTPArgs parsing */
310 explicit NameVal(string nv
) : str(nv
) {}
314 string
& get_name() { return name
; }
315 string
& get_val() { return val
; }
318 /** Stores the XML arguments associated with the HTTP request in req_state*/
321 string str
, empty_str
;
322 map
<string
, string
> val_map
;
323 map
<string
, string
> sys_val_map
;
324 map
<string
, string
> sub_resources
;
325 bool has_resp_modifier
;
326 bool admin_subresource_added
;
328 RGWHTTPArgs() : has_resp_modifier(false), admin_subresource_added(false) {}
330 /** Set the arguments; as received */
332 has_resp_modifier
= false;
334 sub_resources
.clear();
337 /** parse the received arguments */
339 void append(const string
& name
, const string
& val
);
340 /** Get the value for a specific argument parameter */
341 const string
& get(const string
& name
, bool *exists
= NULL
) const;
342 boost::optional
<const std::string
&>
343 get_optional(const std::string
& name
) const;
344 int get_bool(const string
& name
, bool *val
, bool *exists
);
345 int get_bool(const char *name
, bool *val
, bool *exists
);
346 void get_bool(const char *name
, bool *val
, bool def_val
);
348 /** Get the value for specific system argument parameter */
349 std::string
sys_get(const string
& name
, bool *exists
= nullptr) const;
351 /** see if a parameter is contained in this RGWHTTPArgs */
352 bool exists(const char *name
) const {
353 return (val_map
.find(name
) != std::end(val_map
));
355 bool sub_resource_exists(const char *name
) const {
356 return (sub_resources
.find(name
) != std::end(sub_resources
));
358 map
<string
, string
>& get_params() {
361 const std::map
<std::string
, std::string
>& get_sub_resources() const {
362 return sub_resources
;
364 unsigned get_num_params() const {
365 return val_map
.size();
367 bool has_response_modifier() const {
368 return has_resp_modifier
;
370 void set_system() { /* make all system params visible */
371 map
<string
, string
>::iterator iter
;
372 for (iter
= sys_val_map
.begin(); iter
!= sys_val_map
.end(); ++iter
) {
373 val_map
[iter
->first
] = iter
->second
;
376 const string
& get_str() {
381 const char *rgw_conf_get(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, const char *def_val
);
382 int rgw_conf_get_int(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, int def_val
);
383 bool rgw_conf_get_bool(const map
<string
, string
, ltstr_nocase
>& conf_map
, const char *name
, bool def_val
);
390 void init(CephContext
*cct
, RGWEnv
* env
);
395 defer_to_bucket_acls(0) {
399 int enable_usage_log
;
400 uint8_t defer_to_bucket_acls
;
404 std::map
<string
, string
, ltstr_nocase
> env_map
;
408 void init(CephContext
*cct
);
409 void init(CephContext
*cct
, char **envp
);
410 void set(std::string name
, std::string val
);
411 const char *get(const char *name
, const char *def_val
= nullptr) const;
412 int get_int(const char *name
, int def_val
= 0) const;
413 bool get_bool(const char *name
, bool def_val
= 0);
414 size_t get_size(const char *name
, size_t def_val
= 0) const;
415 bool exists(const char *name
) const;
416 bool exists_prefix(const char *prefix
) const;
418 void remove(const char *name
);
420 const std::map
<string
, string
, ltstr_nocase
>& get_map() const { return env_map
; }
440 RGW_OP_GET_BUCKET_LOGGING
,
441 RGW_OP_GET_BUCKET_LOCATION
,
442 RGW_OP_GET_BUCKET_VERSIONING
,
443 RGW_OP_SET_BUCKET_VERSIONING
,
444 RGW_OP_GET_BUCKET_WEBSITE
,
445 RGW_OP_SET_BUCKET_WEBSITE
,
447 RGW_OP_CREATE_BUCKET
,
448 RGW_OP_DELETE_BUCKET
,
452 RGW_OP_PUT_METADATA_ACCOUNT
,
453 RGW_OP_PUT_METADATA_BUCKET
,
454 RGW_OP_PUT_METADATA_OBJECT
,
464 RGW_OP_GET_REQUEST_PAYMENT
,
465 RGW_OP_SET_REQUEST_PAYMENT
,
466 RGW_OP_INIT_MULTIPART
,
467 RGW_OP_COMPLETE_MULTIPART
,
468 RGW_OP_ABORT_MULTIPART
,
469 RGW_OP_LIST_MULTIPART
,
470 RGW_OP_LIST_BUCKET_MULTIPARTS
,
471 RGW_OP_DELETE_MULTI_OBJ
,
474 RGW_OP_GET_CROSS_DOMAIN_POLICY
,
475 RGW_OP_GET_HEALTH_CHECK
,
482 RGW_OP_PUT_ROLE_POLICY
,
483 RGW_OP_GET_ROLE_POLICY
,
484 RGW_OP_LIST_ROLE_POLICIES
,
485 RGW_OP_DELETE_ROLE_POLICY
,
486 RGW_OP_PUT_BUCKET_POLICY
,
487 RGW_OP_GET_BUCKET_POLICY
,
488 RGW_OP_DELETE_BUCKET_POLICY
,
489 RGW_OP_PUT_OBJ_TAGGING
,
490 RGW_OP_GET_OBJ_TAGGING
,
491 RGW_OP_DELETE_OBJ_TAGGING
,
496 RGW_OP_ADMIN_SET_METADATA
,
497 RGW_OP_GET_OBJ_LAYOUT
,
499 RGW_OP_METADATA_SEARCH
,
500 RGW_OP_CONFIG_BUCKET_META_SEARCH
,
501 RGW_OP_GET_BUCKET_META_SEARCH
,
502 RGW_OP_DEL_BUCKET_META_SEARCH
,
505 class RGWAccessControlPolicy
;
508 struct RGWAccessKey
{
509 string id
; // AccessKey
510 string key
; // SecretKey
514 RGWAccessKey(std::string _id
, std::string _key
)
515 : id(std::move(_id
)), key(std::move(_key
)) {}
517 void encode(bufferlist
& bl
) const {
518 ENCODE_START(2, 2, bl
);
521 ::encode(subuser
, bl
);
525 void decode(bufferlist::iterator
& bl
) {
526 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
529 ::decode(subuser
, bl
);
532 void dump(Formatter
*f
) const;
533 void dump_plain(Formatter
*f
) const;
534 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
535 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
537 void decode_json(JSONObj
*obj
);
538 void decode_json(JSONObj
*obj
, bool swift
);
540 WRITE_CLASS_ENCODER(RGWAccessKey
)
546 RGWSubUser() : perm_mask(0) {}
547 void encode(bufferlist
& bl
) const {
548 ENCODE_START(2, 2, bl
);
550 ::encode(perm_mask
, bl
);
554 void decode(bufferlist::iterator
& bl
) {
555 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
557 ::decode(perm_mask
, bl
);
560 void dump(Formatter
*f
) const;
561 void dump(Formatter
*f
, const string
& user
) const;
562 static void generate_test_instances(list
<RGWSubUser
*>& o
);
564 void decode_json(JSONObj
*obj
);
566 WRITE_CLASS_ENCODER(RGWSubUser
)
570 map
<string
, uint32_t> caps
;
572 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
573 int add_cap(const string
& cap
);
574 int remove_cap(const string
& cap
);
576 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
577 int add_from_string(const string
& str
);
578 int remove_from_string(const string
& str
);
580 void encode(bufferlist
& bl
) const {
581 ENCODE_START(1, 1, bl
);
585 void decode(bufferlist::iterator
& bl
) {
590 int check_cap(const string
& cap
, uint32_t perm
);
591 bool is_valid_cap_type(const string
& tp
);
592 void dump(Formatter
*f
) const;
593 void dump(Formatter
*f
, const char *name
) const;
595 void decode_json(JSONObj
*obj
);
597 WRITE_CLASS_ENCODER(RGWUserCaps
)
599 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
600 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
602 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
604 enum RGWUserSourceType
618 map
<string
, RGWAccessKey
> access_keys
;
619 map
<string
, RGWAccessKey
> swift_keys
;
620 map
<string
, RGWSubUser
> subusers
;
627 string default_placement
;
628 list
<string
> placement_tags
;
629 RGWQuotaInfo bucket_quota
;
630 map
<int, string
> temp_url_keys
;
631 RGWQuotaInfo user_quota
;
637 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
638 op_mask(RGW_OP_TYPE_ALL
),
644 RGWAccessKey
* get_key0() {
645 if (access_keys
.empty())
648 return &(access_keys
.begin()->second
);
651 void encode(bufferlist
& bl
) const {
652 ENCODE_START(19, 9, bl
);
656 if (!access_keys
.empty()) {
657 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
658 const RGWAccessKey
& k
= iter
->second
;
662 ::encode(access_key
, bl
);
663 ::encode(secret_key
, bl
);
664 ::encode(display_name
, bl
);
665 ::encode(user_email
, bl
);
668 if (!swift_keys
.empty()) {
669 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
670 const RGWAccessKey
& k
= iter
->second
;
674 ::encode(swift_name
, bl
);
675 ::encode(swift_key
, bl
);
676 ::encode(user_id
.id
, bl
);
677 ::encode(access_keys
, bl
);
678 ::encode(subusers
, bl
);
679 ::encode(suspended
, bl
);
680 ::encode(swift_keys
, bl
);
681 ::encode(max_buckets
, bl
);
683 ::encode(op_mask
, bl
);
684 ::encode(system
, bl
);
685 ::encode(default_placement
, bl
);
686 ::encode(placement_tags
, bl
);
687 ::encode(bucket_quota
, bl
);
688 ::encode(temp_url_keys
, bl
);
689 ::encode(user_quota
, bl
);
690 ::encode(user_id
.tenant
, bl
);
695 void decode(bufferlist::iterator
& bl
) {
696 DECODE_START_LEGACY_COMPAT_LEN_32(19, 9, 9, bl
);
697 if (struct_v
>= 2) ::decode(auid
, bl
);
698 else auid
= CEPH_AUTH_UID_DEFAULT
;
701 ::decode(access_key
, bl
);
702 ::decode(secret_key
, bl
);
707 access_keys
[access_key
] = k
;
709 ::decode(display_name
, bl
);
710 ::decode(user_email
, bl
);
711 /* We populate swift_keys map later nowadays, but we have to decode. */
714 if (struct_v
>= 3) ::decode(swift_name
, bl
);
715 if (struct_v
>= 4) ::decode(swift_key
, bl
);
717 ::decode(user_id
.id
, bl
);
719 user_id
.id
= access_key
;
721 ::decode(access_keys
, bl
);
722 ::decode(subusers
, bl
);
726 ::decode(suspended
, bl
);
729 ::decode(swift_keys
, bl
);
731 if (struct_v
>= 10) {
732 ::decode(max_buckets
, bl
);
734 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
736 if (struct_v
>= 11) {
739 if (struct_v
>= 12) {
740 ::decode(op_mask
, bl
);
742 op_mask
= RGW_OP_TYPE_ALL
;
744 if (struct_v
>= 13) {
745 ::decode(system
, bl
);
746 ::decode(default_placement
, bl
);
747 ::decode(placement_tags
, bl
); /* tags of allowed placement rules */
749 if (struct_v
>= 14) {
750 ::decode(bucket_quota
, bl
);
752 if (struct_v
>= 15) {
753 ::decode(temp_url_keys
, bl
);
755 if (struct_v
>= 16) {
756 ::decode(user_quota
, bl
);
758 if (struct_v
>= 17) {
759 ::decode(user_id
.tenant
, bl
);
761 user_id
.tenant
.clear();
763 if (struct_v
>= 18) {
766 if (struct_v
>= 19) {
771 void dump(Formatter
*f
) const;
772 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
774 void decode_json(JSONObj
*obj
);
776 WRITE_CLASS_ENCODER(RGWUserInfo
)
782 rgw_pool() = default;
783 rgw_pool(const rgw_pool
& _p
) : name(_p
.name
), ns(_p
.ns
) {}
784 rgw_pool(rgw_pool
&&) = default;
785 rgw_pool(const string
& _s
) {
788 rgw_pool(const string
& _name
, const string
& _ns
) : name(_name
), ns(_ns
) {}
790 string
to_str() const;
791 void from_str(const string
& s
);
793 void init(const string
& _s
) {
801 int compare(const rgw_pool
& p
) const {
802 int r
= name
.compare(p
.name
);
806 return ns
.compare(p
.ns
);
809 void encode(bufferlist
& bl
) const {
810 ENCODE_START(10, 10, bl
);
816 void decode_from_bucket(bufferlist::iterator
& bl
);
818 void decode(bufferlist::iterator
& bl
) {
819 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
826 * note that rgw_pool can be used where rgw_bucket was used before
827 * therefore we inherit rgw_bucket's old versions. However, we only
828 * need the first field from rgw_bucket. unless we add more fields
829 * in which case we'll need to look at struct_v, and check the actual
830 * version. Anything older than 10 needs to be treated as old rgw_bucket
840 rgw_pool
& operator=(const rgw_pool
&) = default;
842 bool operator==(const rgw_pool
& p
) const {
843 return (compare(p
) == 0);
845 bool operator!=(const rgw_pool
& p
) const {
846 return !(*this == p
);
848 bool operator<(const rgw_pool
& p
) const {
849 int r
= name
.compare(p
.name
);
851 return (ns
.compare(p
.ns
) < 0);
856 WRITE_CLASS_ENCODER(rgw_pool
)
858 struct rgw_data_placement_target
{
860 rgw_pool data_extra_pool
;
863 rgw_data_placement_target() = default;
864 rgw_data_placement_target(const rgw_data_placement_target
&) = default;
865 rgw_data_placement_target(rgw_data_placement_target
&&) = default;
867 rgw_data_placement_target(const rgw_pool
& data_pool
,
868 const rgw_pool
& data_extra_pool
,
869 const rgw_pool
& index_pool
)
870 : data_pool(data_pool
),
871 data_extra_pool(data_extra_pool
),
872 index_pool(index_pool
) {
875 rgw_data_placement_target
&
876 operator=(const rgw_data_placement_target
&) = default;
878 const rgw_pool
& get_data_extra_pool() const {
879 if (data_extra_pool
.empty()) {
882 return data_extra_pool
;
885 int compare(const rgw_data_placement_target
& t
) {
886 int c
= data_pool
.compare(t
.data_pool
);
890 c
= data_extra_pool
.compare(t
.data_extra_pool
);
894 return index_pool
.compare(t
.index_pool
);
897 void dump(Formatter
*f
) const;
898 void decode_json(JSONObj
*obj
);
901 inline ostream
& operator<<(ostream
& out
, const rgw_pool
& p
) {
912 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
915 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
919 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
928 void encode(bufferlist
& bl
) const {
929 ENCODE_START(6, 6, bl
);
936 void decode_from_rgw_obj(bufferlist::iterator
& bl
);
938 void decode(bufferlist::iterator
& bl
) {
939 unsigned ofs
= bl
.get_off();
943 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
944 * let's decode it as rgw_obj and convert it
947 decode_from_rgw_obj(bl
);
956 bool operator<(const rgw_raw_obj
& o
) const {
957 int r
= pool
.compare(o
.pool
);
959 r
= oid
.compare(o
.oid
);
961 r
= loc
.compare(o
.loc
);
967 bool operator==(const rgw_raw_obj
& o
) const {
968 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
971 void dump(Formatter
*f
) const;
972 void decode_json(JSONObj
*obj
);
974 WRITE_CLASS_ENCODER(rgw_raw_obj
)
976 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
977 out
<< o
.pool
<< ":" << o
.oid
;
985 std::string bucket_id
;
986 rgw_data_placement_target explicit_placement
;
989 * runtime in-memory only info. If not empty, points to the bucket instance object
993 // cppcheck-suppress noExplicitConstructor
994 explicit rgw_bucket(const rgw_user
& u
, const cls_user_bucket
& b
) :
998 bucket_id(b
.bucket_id
),
999 explicit_placement(b
.explicit_placement
.data_pool
,
1000 b
.explicit_placement
.data_extra_pool
,
1001 b
.explicit_placement
.index_pool
) {}
1002 rgw_bucket(const rgw_bucket
&) = default;
1003 rgw_bucket(rgw_bucket
&&) = default;
1005 void convert(cls_user_bucket
*b
) const {
1008 b
->bucket_id
= bucket_id
;
1009 b
->explicit_placement
.data_pool
= explicit_placement
.data_pool
.to_str();
1010 b
->explicit_placement
.data_extra_pool
= explicit_placement
.data_extra_pool
.to_str();
1011 b
->explicit_placement
.index_pool
= explicit_placement
.index_pool
.to_str();
1014 void encode(bufferlist
& bl
) const {
1015 ENCODE_START(10, 10, bl
);
1017 ::encode(marker
, bl
);
1018 ::encode(bucket_id
, bl
);
1019 ::encode(tenant
, bl
);
1020 bool encode_explicit
= !explicit_placement
.data_pool
.empty();
1021 ::encode(encode_explicit
, bl
);
1022 if (encode_explicit
) {
1023 ::encode(explicit_placement
.data_pool
, bl
);
1024 ::encode(explicit_placement
.data_extra_pool
, bl
);
1025 ::encode(explicit_placement
.index_pool
, bl
);
1029 void decode(bufferlist::iterator
& bl
) {
1030 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
1032 if (struct_v
< 10) {
1033 ::decode(explicit_placement
.data_pool
.name
, bl
);
1035 if (struct_v
>= 2) {
1036 ::decode(marker
, bl
);
1037 if (struct_v
<= 3) {
1041 snprintf(buf
, sizeof(buf
), "%llu", (long long)id
);
1044 ::decode(bucket_id
, bl
);
1047 if (struct_v
< 10) {
1048 if (struct_v
>= 5) {
1049 ::decode(explicit_placement
.index_pool
.name
, bl
);
1051 explicit_placement
.index_pool
= explicit_placement
.data_pool
;
1053 if (struct_v
>= 7) {
1054 ::decode(explicit_placement
.data_extra_pool
.name
, bl
);
1057 if (struct_v
>= 8) {
1058 ::decode(tenant
, bl
);
1060 if (struct_v
>= 10) {
1061 bool decode_explicit
= !explicit_placement
.data_pool
.empty();
1062 ::decode(decode_explicit
, bl
);
1063 if (decode_explicit
) {
1064 ::decode(explicit_placement
.data_pool
, bl
);
1065 ::decode(explicit_placement
.data_extra_pool
, bl
);
1066 ::decode(explicit_placement
.index_pool
, bl
);
1072 void update_bucket_id(const string
& new_bucket_id
) {
1073 bucket_id
= new_bucket_id
;
1077 // format a key for the bucket/instance. pass delim=0 to skip a field
1078 std::string
get_key(char tenant_delim
= '/',
1079 char id_delim
= ':') const;
1081 const rgw_pool
& get_data_extra_pool() const {
1082 return explicit_placement
.get_data_extra_pool();
1085 void dump(Formatter
*f
) const;
1086 void decode_json(JSONObj
*obj
);
1087 static void generate_test_instances(list
<rgw_bucket
*>& o
);
1089 rgw_bucket
& operator=(const rgw_bucket
&) = default;
1091 bool operator<(const rgw_bucket
& b
) const {
1092 return name
.compare(b
.name
) < 0;
1094 bool operator==(const rgw_bucket
& b
) const {
1095 return (name
== b
.name
) && (bucket_id
== b
.bucket_id
);
1098 WRITE_CLASS_ENCODER(rgw_bucket
)
1100 inline ostream
& operator<<(ostream
& out
, const rgw_bucket
&b
) {
1101 out
<< b
.name
<< "[" << b
.marker
<< "])";
1105 struct rgw_bucket_shard
{
1109 rgw_bucket_shard() : shard_id(-1) {}
1110 rgw_bucket_shard(const rgw_bucket
& _b
, int _sid
) : bucket(_b
), shard_id(_sid
) {}
1112 std::string
get_key(char tenant_delim
= '/', char id_delim
= ':',
1113 char shard_delim
= ':') const;
1115 bool operator<(const rgw_bucket_shard
& b
) const {
1116 if (bucket
< b
.bucket
) {
1119 if (b
.bucket
< bucket
) {
1122 return shard_id
< b
.shard_id
;
1127 struct RGWObjVersionTracker
{
1128 obj_version read_version
;
1129 obj_version write_version
;
1131 obj_version
*version_for_read() {
1132 return &read_version
;
1135 obj_version
*version_for_write() {
1136 if (write_version
.ver
== 0)
1139 return &write_version
;
1142 obj_version
*version_for_check() {
1143 if (read_version
.ver
== 0)
1146 return &read_version
;
1149 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1150 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1152 void apply_write() {
1153 read_version
= write_version
;
1154 write_version
= obj_version();
1158 read_version
= obj_version();
1159 write_version
= obj_version();
1162 void generate_new_write_ver(CephContext
*cct
);
1165 enum RGWBucketFlags
{
1166 BUCKET_SUSPENDED
= 0x1,
1167 BUCKET_VERSIONED
= 0x2,
1168 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1169 BUCKET_DATASYNC_DISABLED
= 0X8,
1172 enum RGWBucketIndexType
{
1173 RGWBIType_Normal
= 0,
1174 RGWBIType_Indexless
= 1,
1177 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1179 switch (index_type
) {
1180 case RGWBIType_Normal
:
1181 return out
<< "Normal";
1182 case RGWBIType_Indexless
:
1183 return out
<< "Indexless";
1185 return out
<< "Unknown";
1189 struct RGWBucketInfo
1191 enum BIShardsHashType
{
1199 ceph::real_time creation_time
;
1200 string placement_rule
;
1201 bool has_instance_obj
;
1202 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1203 obj_version ep_objv
; /* entry point object version, for runtime tracking only */
1206 // Represents the number of bucket index object shards:
1207 // - value of 0 indicates there is no sharding (this is by default before this
1208 // feature is implemented).
1209 // - value of UINT32_T::MAX indicates this is a blind bucket.
1210 uint32_t num_shards
;
1212 // Represents the bucket index shard hash type.
1213 uint8_t bucket_index_shard_hash_type
;
1215 // Represents the shard number for blind bucket.
1216 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1218 bool requester_pays
;
1221 RGWBucketWebsiteConf website_conf
;
1223 RGWBucketIndexType index_type
;
1225 bool swift_versioning
;
1226 string swift_ver_location
;
1228 map
<string
, uint32_t> mdsearch_config
;
1231 uint8_t reshard_status
;
1232 string new_bucket_instance_id
;
1234 void encode(bufferlist
& bl
) const {
1235 ENCODE_START(19, 4, bl
);
1236 ::encode(bucket
, bl
);
1237 ::encode(owner
.id
, bl
);
1238 ::encode(flags
, bl
);
1239 ::encode(zonegroup
, bl
);
1240 uint64_t ct
= real_clock::to_time_t(creation_time
);
1242 ::encode(placement_rule
, bl
);
1243 ::encode(has_instance_obj
, bl
);
1244 ::encode(quota
, bl
);
1245 ::encode(num_shards
, bl
);
1246 ::encode(bucket_index_shard_hash_type
, bl
);
1247 ::encode(requester_pays
, bl
);
1248 ::encode(owner
.tenant
, bl
);
1249 ::encode(has_website
, bl
);
1251 ::encode(website_conf
, bl
);
1253 ::encode((uint32_t)index_type
, bl
);
1254 ::encode(swift_versioning
, bl
);
1255 if (swift_versioning
) {
1256 ::encode(swift_ver_location
, bl
);
1258 ::encode(creation_time
, bl
);
1259 ::encode(mdsearch_config
, bl
);
1260 ::encode(reshard_status
, bl
);
1261 ::encode(new_bucket_instance_id
, bl
);
1264 void decode(bufferlist::iterator
& bl
) {
1265 DECODE_START_LEGACY_COMPAT_LEN_32(19, 4, 4, bl
);
1266 ::decode(bucket
, bl
);
1267 if (struct_v
>= 2) {
1273 ::decode(flags
, bl
);
1275 ::decode(zonegroup
, bl
);
1276 if (struct_v
>= 6) {
1280 creation_time
= ceph::real_clock::from_time_t((time_t)ct
);
1283 ::decode(placement_rule
, bl
);
1285 ::decode(has_instance_obj
, bl
);
1287 ::decode(quota
, bl
);
1289 ::decode(num_shards
, bl
);
1291 ::decode(bucket_index_shard_hash_type
, bl
);
1293 ::decode(requester_pays
, bl
);
1295 ::decode(owner
.tenant
, bl
);
1296 if (struct_v
>= 14) {
1297 ::decode(has_website
, bl
);
1299 ::decode(website_conf
, bl
);
1301 website_conf
= RGWBucketWebsiteConf();
1304 if (struct_v
>= 15) {
1307 index_type
= (RGWBucketIndexType
)it
;
1309 index_type
= RGWBIType_Normal
;
1311 swift_versioning
= false;
1312 swift_ver_location
.clear();
1313 if (struct_v
>= 16) {
1314 ::decode(swift_versioning
, bl
);
1315 if (swift_versioning
) {
1316 ::decode(swift_ver_location
, bl
);
1319 if (struct_v
>= 17) {
1320 ::decode(creation_time
, bl
);
1322 if (struct_v
>= 18) {
1323 ::decode(mdsearch_config
, bl
);
1325 if (struct_v
>= 19) {
1326 ::decode(reshard_status
, bl
);
1327 ::decode(new_bucket_instance_id
, bl
);
1331 void dump(Formatter
*f
) const;
1332 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1334 void decode_json(JSONObj
*obj
);
1336 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1337 int versioning_status() { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
); }
1338 bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED
; }
1339 bool datasync_flag_enabled() const { return (flags
& BUCKET_DATASYNC_DISABLED
) == 0; }
1341 bool has_swift_versioning() const {
1342 /* A bucket may be versioned through one mechanism only. */
1343 return swift_versioning
&& !versioned();
1346 RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD
), requester_pays(false),
1347 has_website(false), swift_versioning(false), reshard_status(0) {}
1349 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1351 struct RGWBucketEntryPoint
1355 ceph::real_time creation_time
;
1358 bool has_bucket_info
;
1359 RGWBucketInfo old_bucket_info
;
1361 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1363 void encode(bufferlist
& bl
) const {
1364 ENCODE_START(10, 8, bl
);
1365 ::encode(bucket
, bl
);
1366 ::encode(owner
.id
, bl
);
1367 ::encode(linked
, bl
);
1368 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1369 ::encode(ctime
, bl
);
1370 ::encode(owner
, bl
);
1371 ::encode(creation_time
, bl
);
1374 void decode(bufferlist::iterator
& bl
) {
1375 bufferlist::iterator orig_iter
= bl
;
1376 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1378 /* ouch, old entry, contains the bucket info itself */
1379 old_bucket_info
.decode(orig_iter
);
1380 has_bucket_info
= true;
1383 has_bucket_info
= false;
1384 ::decode(bucket
, bl
);
1385 ::decode(owner
.id
, bl
);
1386 ::decode(linked
, bl
);
1388 ::decode(ctime
, bl
);
1389 if (struct_v
< 10) {
1390 creation_time
= real_clock::from_time_t((time_t)ctime
);
1392 if (struct_v
>= 9) {
1393 ::decode(owner
, bl
);
1395 if (struct_v
>= 10) {
1396 ::decode(creation_time
, bl
);
1401 void dump(Formatter
*f
) const;
1402 void decode_json(JSONObj
*obj
);
1404 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1406 struct RGWStorageStats
1408 RGWObjCategory category
;
1410 uint64_t size_rounded
;
1411 uint64_t size_utilized
{0}; //< size after compression, encryption
1412 uint64_t num_objects
;
1415 : category(RGW_OBJ_CATEGORY_NONE
),
1420 void dump(Formatter
*f
) const;
1425 /* Namespaced forward declarations. */
1429 class AWSBrowserUploadAbstractor
;
1442 map
<string
, string
> x_meta_map
;
1448 string request_uri_aws4
;
1449 string effective_uri
;
1450 string request_params
;
1453 req_info(CephContext
*cct
, const RGWEnv
*env
);
1454 void rebuild_from(req_info
& src
);
1455 void init_meta_info(bool *found_bad_meta
);
1458 typedef cls_rgw_obj_key rgw_obj_index_key
;
1460 struct rgw_obj_key
{
1466 // cppcheck-suppress noExplicitConstructor
1467 rgw_obj_key(const string
& n
) : name(n
) {}
1468 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1469 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1471 rgw_obj_key(const rgw_obj_index_key
& k
) {
1472 parse_index_key(k
.name
, &name
, &ns
);
1473 instance
= k
.instance
;
1476 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1477 if (key
[0] != '_') {
1482 if (key
[1] == '_') {
1483 *name
= key
.substr(1);
1487 ssize_t pos
= key
.find('_', 1);
1489 /* shouldn't happen, just use key */
1495 *name
= key
.substr(pos
+ 1);
1496 *ns
= key
.substr(1, pos
-1);
1499 void set(const string
& n
) {
1505 void set(const string
& n
, const string
& i
) {
1511 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1517 bool set(const rgw_obj_index_key
& index_key
) {
1518 if (!parse_raw_oid(index_key
.name
, this)) {
1521 instance
= index_key
.instance
;
1525 void set_instance(const string
& i
) {
1529 string
get_index_key_name() const {
1531 if (name
.size() < 1 || name
[0] != '_') {
1534 return string("_") + name
;
1537 char buf
[ns
.size() + 16];
1538 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1539 return string(buf
) + name
;
1542 void get_index_key(rgw_obj_index_key
*key
) const {
1543 key
->name
= get_index_key_name();
1544 key
->instance
= instance
;
1547 string
get_loc() const {
1549 * For backward compatibility. Older versions used to have object locator on all objects,
1550 * however, the name was the effective object locator. This had the same effect as not
1551 * having object locator at all for most objects but the ones that started with underscore as
1552 * these were escaped.
1554 if (name
[0] == '_' && ns
.empty()) {
1561 bool empty() const {
1562 return name
.empty();
1565 bool have_null_instance() const {
1566 return instance
== "null";
1569 bool have_instance() const {
1570 return !instance
.empty();
1573 bool need_to_encode_instance() const {
1574 return have_instance() && !have_null_instance();
1577 string
get_oid() const {
1578 if (ns
.empty() && !need_to_encode_instance()) {
1579 if (name
.size() < 1 || name
[0] != '_') {
1582 return string("_") + name
;
1587 if (need_to_encode_instance()) {
1588 oid
.append(string(":") + instance
);
1595 bool operator==(const rgw_obj_key
& k
) const {
1596 return (name
.compare(k
.name
) == 0) &&
1597 (instance
.compare(k
.instance
) == 0);
1600 bool operator<(const rgw_obj_key
& k
) const {
1601 int r
= name
.compare(k
.name
);
1603 r
= instance
.compare(k
.instance
);
1608 bool operator<=(const rgw_obj_key
& k
) const {
1609 return !(k
< *this);
1612 static void parse_ns_field(string
& ns
, string
& instance
) {
1613 int pos
= ns
.find(':');
1615 instance
= ns
.substr(pos
+ 1);
1616 ns
= ns
.substr(0, pos
);
1622 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1623 key
->instance
.clear();
1625 if (oid
[0] != '_') {
1630 if (oid
.size() >= 2 && oid
[1] == '_') {
1631 key
->name
= oid
.substr(1);
1635 if (oid
[0] != '_' || oid
.size() < 3) // for namespace, min size would be 3: _x_
1638 int pos
= oid
.find('_', 1);
1639 if (pos
<= 1) // if it starts with __, it's not in our namespace
1642 key
->ns
= oid
.substr(1, pos
- 1);
1643 parse_ns_field(key
->ns
, key
->instance
);
1645 key
->name
= oid
.substr(pos
+ 1);
1650 * Translate a namespace-mangled object name to the user-facing name
1651 * existing in the given namespace.
1653 * If the object is part of the given namespace, it returns true
1654 * and cuts down the name to the unmangled version. If it is not
1655 * part of the given namespace, it returns false.
1657 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1658 bool ret
= parse_raw_oid(oid
, key
);
1663 return (ns
== key
->ns
);
1667 * Given a mangled object name and an empty namespace string, this
1668 * function extracts the namespace into the string and sets the object
1669 * name to be the unmangled version.
1671 * It returns true after successfully doing so, or
1672 * false if it fails.
1674 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1677 if (name
[0] != '_') {
1681 size_t pos
= name
.find('_', 1);
1682 if (pos
== string::npos
) {
1686 if (name
[1] == '_') {
1687 name
= name
.substr(1);
1691 size_t period_pos
= name
.find('.');
1692 if (period_pos
< pos
) {
1696 ns
= name
.substr(1, pos
-1);
1697 name
= name
.substr(pos
+1, string::npos
);
1699 parse_ns_field(ns
, instance
);
1703 void encode(bufferlist
& bl
) const {
1704 ENCODE_START(2, 1, bl
);
1706 ::encode(instance
, bl
);
1710 void decode(bufferlist::iterator
& bl
) {
1711 DECODE_START(2, bl
);
1713 ::decode(instance
, bl
);
1714 if (struct_v
>= 2) {
1719 void dump(Formatter
*f
) const;
1720 void decode_json(JSONObj
*obj
);
1722 WRITE_CLASS_ENCODER(rgw_obj_key
)
1724 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1725 if (o
.instance
.empty()) {
1726 return out
<< o
.name
;
1728 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1732 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1733 if (o
.instance
.empty()) {
1734 return out
<< o
.name
;
1736 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1740 struct req_init_state
{
1741 /* Keeps [[tenant]:]bucket until we parse the token. */
1746 /* XXX why don't RGWRequest (or descendants) hold this state? */
1749 #include "rgw_auth.h"
1751 /** Store all the state necessary to complete and respond to an HTTP request*/
1754 rgw::io::BasicClient
*cio
;
1755 RGWRequest
*req
{nullptr}; /// XXX: re-remove??
1757 RGWOpType op_type
{};
1758 bool content_started
;
1760 ceph::Formatter
*formatter
;
1762 string relative_uri
;
1764 int64_t content_length
;
1765 map
<string
, string
> generic_attrs
;
1769 bool enable_ops_log
;
1770 bool enable_usage_log
;
1771 uint8_t defer_to_bucket_acls
;
1774 /* Set once when url_bucket is parsed and not violated thereafter. */
1775 string account_name
;
1777 string bucket_tenant
;
1782 string src_tenant_name
;
1783 string src_bucket_name
;
1784 rgw_obj_key src_object
;
1785 ACLOwner bucket_owner
;
1788 string zonegroup_name
;
1789 string zonegroup_endpoint
;
1790 string bucket_instance_id
;
1791 int bucket_instance_shard_id
;
1795 RGWBucketInfo bucket_info
;
1796 map
<string
, bufferlist
> bucket_attrs
;
1804 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
1806 /* Object having the knowledge about an authenticated identity and allowing
1807 * to apply it during the authorization phase (verify_permission() methods
1808 * of a given RGWOp). Thus, it bounds authentication and authorization steps
1809 * through a well-defined interface. For more details, see rgw_auth.h. */
1810 std::unique_ptr
<rgw::auth::Identity
> identity
;
1812 std::shared_ptr
<rgw::auth::Completer
> completer
;
1814 /* A container for credentials of the S3's browser upload. It's necessary
1815 * because: 1) the ::authenticate() method of auth engines and strategies
1816 * take req_state only; 2) auth strategies live much longer than RGWOps -
1817 * there is no way to pass additional data dependencies through ctors. */
1820 friend class RGWPostObj_ObjStore_S3
;
1822 friend class rgw::auth::s3::AWSBrowserUploadAbstractor
;
1824 std::string access_key
;
1825 std::string signature
;
1826 std::string x_amz_algorithm
;
1827 std::string x_amz_credential
;
1828 std::string x_amz_date
;
1829 ceph::bufferlist encoded_policy
;
1833 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
1834 std::unique_ptr
<RGWAccessControlPolicy
> bucket_acl
;
1835 std::unique_ptr
<RGWAccessControlPolicy
> object_acl
;
1837 rgw::IAM::Environment env
;
1838 boost::optional
<rgw::IAM::Policy
> iam_policy
;
1840 /* Is the request made by an user marked as a system one?
1841 * Being system user means we also have the admin status. */
1842 bool system_request
;
1845 bool has_acl_header
;
1846 bool local_source
; /* source is local */
1850 /* Content-Disposition override for TempURL of Swift API. */
1859 req_init_state init_state
;
1867 req_state(CephContext
* _cct
, RGWEnv
* e
, RGWUserInfo
* u
);
1870 bool is_err() const { return err
.is_err(); }
1873 void set_req_state_err(struct req_state
*, int);
1874 void set_req_state_err(struct req_state
*, int, const string
&);
1875 void set_req_state_err(struct rgw_err
&, int, const int);
1876 void dump(struct req_state
*);
1878 /** Store basic data on bucket */
1879 struct RGWBucketEnt
{
1882 size_t size_rounded
;
1883 ceph::real_time creation_time
;
1886 /* The placement_rule is necessary to calculate per-storage-policy statics
1887 * of the Swift API. Although the info available in RGWBucketInfo, we need
1888 * to duplicate it here to not affect the performance of buckets listing. */
1889 std::string placement_rule
;
1896 RGWBucketEnt(const RGWBucketEnt
&) = default;
1897 RGWBucketEnt(RGWBucketEnt
&&) = default;
1898 explicit RGWBucketEnt(const rgw_user
& u
, cls_user_bucket_entry
&& e
)
1899 : bucket(u
, std::move(e
.bucket
)),
1901 size_rounded(e
.size_rounded
),
1902 creation_time(e
.creation_time
),
1906 RGWBucketEnt
& operator=(const RGWBucketEnt
&) = default;
1908 void convert(cls_user_bucket_entry
*b
) const {
1909 bucket
.convert(&b
->bucket
);
1911 b
->size_rounded
= size_rounded
;
1912 b
->creation_time
= creation_time
;
1916 void encode(bufferlist
& bl
) const {
1917 ENCODE_START(7, 5, bl
);
1919 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
1920 string empty_str
; // originally had the bucket name here, but we encode bucket later
1921 ::encode(empty_str
, bl
);
1924 ::encode(count
, bl
);
1925 ::encode(bucket
, bl
);
1928 ::encode(creation_time
, bl
);
1929 ::encode(placement_rule
, bl
);
1932 void decode(bufferlist::iterator
& bl
) {
1933 DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl
);
1936 string empty_str
; // backward compatibility
1937 ::decode(empty_str
, bl
);
1942 creation_time
= ceph::real_clock::from_time_t(mt
);
1945 ::decode(count
, bl
);
1947 ::decode(bucket
, bl
);
1952 ::decode(creation_time
, bl
);
1954 ::decode(placement_rule
, bl
);
1957 void dump(Formatter
*f
) const;
1958 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
1960 WRITE_CLASS_ENCODER(RGWBucketEnt
)
1966 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
1968 // Represents the hash index source for this object once it is set (non-empty)
1969 std::string index_hash_source
;
1972 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
1973 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
1974 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
1976 void init(const rgw_bucket
& b
, const std::string
& name
) {
1980 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
1982 key
.set(name
, i
, n
);
1984 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
1987 key
.instance
.clear();
1991 bool empty() const {
1995 void set_key(const rgw_obj_key
& k
) {
1999 string
get_oid() const {
2000 return key
.get_oid();
2003 const string
& get_hash_object() const {
2004 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
2007 void set_in_extra_data(bool val
) {
2008 in_extra_data
= val
;
2011 bool is_in_extra_data() const {
2012 return in_extra_data
;
2015 void encode(bufferlist
& bl
) const {
2016 ENCODE_START(6, 6, bl
);
2017 ::encode(bucket
, bl
);
2018 ::encode(key
.ns
, bl
);
2019 ::encode(key
.name
, bl
);
2020 ::encode(key
.instance
, bl
);
2021 // ::encode(placement_id, bl);
2024 void decode(bufferlist::iterator
& bl
) {
2025 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
2028 ::decode(bucket
.name
, bl
); /* bucket.name */
2029 ::decode(s
, bl
); /* loc */
2030 ::decode(key
.ns
, bl
);
2031 ::decode(key
.name
, bl
);
2033 ::decode(bucket
, bl
);
2035 ::decode(key
.instance
, bl
);
2036 if (key
.ns
.empty() && key
.instance
.empty()) {
2037 if (key
.name
[0] == '_') {
2038 key
.name
= key
.name
.substr(1);
2041 if (struct_v
>= 5) {
2042 ::decode(key
.name
, bl
);
2044 ssize_t pos
= key
.name
.find('_', 1);
2046 throw buffer::error();
2048 key
.name
= key
.name
.substr(pos
);
2052 ::decode(bucket
, bl
);
2053 ::decode(key
.ns
, bl
);
2054 ::decode(key
.name
, bl
);
2055 ::decode(key
.instance
, bl
);
2056 // ::decode(placement_id, bl);
2060 void dump(Formatter
*f
) const;
2061 static void generate_test_instances(list
<rgw_obj
*>& o
);
2063 bool operator==(const rgw_obj
& o
) const {
2064 return (key
== o
.key
) &&
2065 (bucket
== o
.bucket
);
2067 bool operator<(const rgw_obj
& o
) const {
2068 int r
= key
.name
.compare(o
.key
.name
);
2070 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
2072 r
= key
.ns
.compare(o
.key
.ns
);
2074 r
= key
.instance
.compare(o
.key
.instance
);
2082 const rgw_pool
& get_explicit_data_pool() {
2083 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
2084 return bucket
.explicit_placement
.data_pool
;
2086 return bucket
.explicit_placement
.data_extra_pool
;
2089 WRITE_CLASS_ENCODER(rgw_obj
)
2091 struct rgw_cache_entry_info
{
2092 string cache_locator
;
2095 rgw_cache_entry_info() : gen(0) {}
2098 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
2099 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
2102 static inline void buf_to_hex(const unsigned char* const buf
,
2107 for (size_t i
= 0; i
< len
; i
++) {
2108 ::sprintf(&str
[i
*2], "%02x", static_cast<int>(buf
[i
]));
2112 template<size_t N
> static inline std::array
<char, N
* 2 + 1>
2113 buf_to_hex(const std::array
<unsigned char, N
>& buf
)
2115 static_assert(N
> 0, "The input array must be at least one element long");
2117 std::array
<char, N
* 2 + 1> hex_dest
;
2118 buf_to_hex(buf
.data(), N
, hex_dest
.data());
2122 static inline int hexdigit(char c
)
2124 if (c
>= '0' && c
<= '9')
2127 if (c
>= 'A' && c
<= 'F')
2128 return c
- 'A' + 0xa;
2132 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2135 const char *p
= hex
;
2140 int d
= hexdigit(*p
);
2157 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2162 return (strcasecmp(s
, "on") == 0 ||
2163 strcasecmp(s
, "yes") == 0 ||
2164 strcasecmp(s
, "1") == 0);
2167 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2171 gen_rand_alphanumeric(cct
, buf
, len
);
2176 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2179 case RGW_OBJ_CATEGORY_NONE
:
2181 case RGW_OBJ_CATEGORY_MAIN
:
2183 case RGW_OBJ_CATEGORY_SHADOW
:
2184 return "rgw.shadow";
2185 case RGW_OBJ_CATEGORY_MULTIMETA
:
2186 return "rgw.multimeta";
2192 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2194 return (bytes
+ 1023) / 1024;
2197 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2199 return ((bytes
+ 4095) & ~4095);
2202 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2204 return ((bytes
+ 4095) & ~4095) / 1024;
2207 extern string
rgw_string_unquote(const string
& s
);
2208 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2209 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2210 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2212 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2213 parse_key_value(const boost::string_view
& in_str
,
2214 const boost::string_view
& delim
);
2215 extern boost::optional
<std::pair
<boost::string_view
, boost::string_view
>>
2216 parse_key_value(const boost::string_view
& in_str
);
2220 extern int parse_time(const char *time_str
, real_time
*time
);
2221 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2222 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2223 extern string
rgw_trim_whitespace(const string
& src
);
2224 extern boost::string_view
rgw_trim_whitespace(const boost::string_view
& src
);
2225 extern string
rgw_trim_quotes(const string
& val
);
2227 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2228 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2229 extern std::string
rgw_to_asctime(const utime_t
& t
);
2231 /** Check if the req_state's user has the necessary permissions
2232 * to do the requested action */
2233 bool verify_user_permission(struct req_state
* const s
,
2234 RGWAccessControlPolicy
* const user_acl
,
2236 bool verify_user_permission(struct req_state
* const s
,
2238 bool verify_bucket_permission(
2239 struct req_state
* const s
,
2240 const rgw_bucket
& bucket
,
2241 RGWAccessControlPolicy
* const user_acl
,
2242 RGWAccessControlPolicy
* const bucket_acl
,
2243 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2245 bool verify_bucket_permission(struct req_state
* const s
, const uint64_t op
);
2246 bool verify_bucket_permission_no_policy(
2247 struct req_state
* const s
,
2248 RGWAccessControlPolicy
* const user_acl
,
2249 RGWAccessControlPolicy
* const bucket_acl
,
2251 bool verify_bucket_permission_no_policy(struct req_state
* const s
,
2253 int verify_bucket_owner_or_policy(struct req_state
* const s
,
2255 extern bool verify_object_permission(
2256 struct req_state
* const s
,
2258 RGWAccessControlPolicy
* const user_acl
,
2259 RGWAccessControlPolicy
* const bucket_acl
,
2260 RGWAccessControlPolicy
* const object_acl
,
2261 const boost::optional
<rgw::IAM::Policy
>& bucket_policy
,
2263 extern bool verify_object_permission(struct req_state
*s
, uint64_t op
);
2264 extern bool verify_object_permission_no_policy(
2265 struct req_state
* const s
,
2266 RGWAccessControlPolicy
* const user_acl
,
2267 RGWAccessControlPolicy
* const bucket_acl
,
2268 RGWAccessControlPolicy
* const object_acl
,
2270 extern bool verify_object_permission_no_policy(struct req_state
*s
,
2272 /** Convert an input URL into a sane object name
2273 * by converting %-escaped strings into characters, etc*/
2274 extern void rgw_uri_escape_char(char c
, string
& dst
);
2275 extern std::string
url_decode(const boost::string_view
& src_str
,
2276 bool in_query
= false);
2277 extern void url_encode(const std::string
& src
,
2279 extern std::string
url_encode(const std::string
& src
);
2280 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2281 extern void calc_hmac_sha1(const char *key
, int key_len
,
2282 const char *msg
, int msg_len
, char *dest
);
2284 using sha1_digest_t
= \
2285 std::array
<char, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE
>;
2287 static inline sha1_digest_t
2288 calc_hmac_sha1(const boost::string_view
& key
, const boost::string_view
& msg
) {
2290 calc_hmac_sha1(key
.data(), key
.size(), msg
.data(), msg
.size(), dest
.data());
2294 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2295 extern void calc_hmac_sha256(const char *key
, int key_len
,
2296 const char *msg
, int msg_len
,
2299 using sha256_digest_t
= \
2300 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
>;
2302 static inline sha256_digest_t
2303 calc_hmac_sha256(const char *key
, const int key_len
,
2304 const char *msg
, const int msg_len
) {
2305 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2306 calc_hmac_sha256(key
, key_len
, msg
, msg_len
,
2307 reinterpret_cast<char*>(dest
.data()));
2311 static inline sha256_digest_t
2312 calc_hmac_sha256(const boost::string_view
& key
, const boost::string_view
& msg
) {
2313 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2314 calc_hmac_sha256(key
.data(), key
.size(),
2315 msg
.data(), msg
.size(),
2316 reinterpret_cast<char*>(dest
.data()));
2320 static inline sha256_digest_t
2321 calc_hmac_sha256(const std::vector
<unsigned char>& key
,
2322 const boost::string_view
& msg
) {
2323 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2324 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2325 msg
.data(), msg
.size(),
2326 reinterpret_cast<char*>(dest
.data()));
2330 template<size_t KeyLenN
>
2331 static inline sha256_digest_t
2332 calc_hmac_sha256(const std::array
<unsigned char, KeyLenN
>& key
,
2333 const boost::string_view
& msg
) {
2334 std::array
<unsigned char, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
> dest
;
2335 calc_hmac_sha256(reinterpret_cast<const char*>(key
.data()), key
.size(),
2336 msg
.data(), msg
.size(),
2337 reinterpret_cast<char*>(dest
.data()));
2341 extern sha256_digest_t
calc_hash_sha256(const boost::string_view
& msg
);
2343 extern ceph::crypto::SHA256
* calc_hash_sha256_open_stream();
2344 extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256
* hash
,
2347 extern std::string
calc_hash_sha256_close_stream(ceph::crypto::SHA256
** phash
);
2348 extern std::string
calc_hash_sha256_restart_stream(ceph::crypto::SHA256
** phash
);
2350 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2352 static constexpr uint32_t MATCH_POLICY_ACTION
= 0x01;
2353 static constexpr uint32_t MATCH_POLICY_RESOURCE
= 0x02;
2354 static constexpr uint32_t MATCH_POLICY_ARN
= 0x04;
2355 static constexpr uint32_t MATCH_POLICY_STRING
= 0x08;
2357 extern bool match_policy(boost::string_view pattern
, boost::string_view input
,