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
19 #include "common/ceph_crypto.h"
20 #include "common/perf_counters.h"
24 #include "rgw_quota.h"
25 #include "rgw_string.h"
26 #include "rgw_website.h"
27 #include "cls/version/cls_version_types.h"
28 #include "cls/user/cls_user_types.h"
29 #include "cls/rgw/cls_rgw_types.h"
30 #include "include/rados/librados.hpp"
38 using ceph::crypto::MD5
;
41 #define RGW_ATTR_PREFIX "user.rgw."
43 #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_"
44 #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-"
46 #define RGW_AMZ_PREFIX "x-amz-"
47 #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-"
48 #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location"
50 #define RGW_SYS_PARAM_PREFIX "rgwx-"
52 #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl"
53 #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc"
54 #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
55 #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
56 #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
57 #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
58 #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
59 #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control"
60 #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition"
61 #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding"
62 #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language"
63 #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires"
64 #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at"
65 #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag"
66 #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name"
67 #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest"
68 #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest"
69 #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION
70 #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest"
71 /* Information whether an object is SLO or not must be exposed to
72 * user through custom HTTP header named X-Static-Large-Object. */
73 #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object"
74 #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
76 #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver"
77 #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone"
79 #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key"
80 #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2"
82 /* Account/container quota of the Swift API. */
83 #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count"
84 #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes"
86 /* Static Web Site of Swift API. */
87 #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index"
88 #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error"
89 #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings"
90 #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css"
91 #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type"
93 #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh."
95 #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info"
96 #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver"
97 #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag"
98 #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending."
100 #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression"
102 /* RGW File Attributes */
103 #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1"
104 #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1"
106 #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt."
107 #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode"
108 #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5"
109 #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid"
110 #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel"
112 #define RGW_BUCKETS_OBJ_SUFFIX ".buckets"
114 #define RGW_FORMAT_PLAIN 0
115 #define RGW_FORMAT_XML 1
116 #define RGW_FORMAT_JSON 2
117 #define RGW_FORMAT_HTML 3
119 #define RGW_CAP_READ 0x1
120 #define RGW_CAP_WRITE 0x2
121 #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE)
123 #define RGW_REST_SWIFT 0x1
124 #define RGW_REST_SWIFT_AUTH 0x2
125 #define RGW_REST_S3 0x4
126 #define RGW_REST_WEBSITE 0x8
128 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2
130 #define RGW_OP_TYPE_READ 0x01
131 #define RGW_OP_TYPE_WRITE 0x02
132 #define RGW_OP_TYPE_DELETE 0x04
134 #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
135 #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE)
137 #define RGW_DEFAULT_MAX_BUCKETS 1000
139 #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1
140 #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2
142 #define STATUS_CREATED 1900
143 #define STATUS_ACCEPTED 1901
144 #define STATUS_NO_CONTENT 1902
145 #define STATUS_PARTIAL_CONTENT 1903
146 #define STATUS_REDIRECT 1904
147 #define STATUS_NO_APPLY 1905
148 #define STATUS_APPLIED 1906
150 #define ERR_INVALID_BUCKET_NAME 2000
151 #define ERR_INVALID_OBJECT_NAME 2001
152 #define ERR_NO_SUCH_BUCKET 2002
153 #define ERR_METHOD_NOT_ALLOWED 2003
154 #define ERR_INVALID_DIGEST 2004
155 #define ERR_BAD_DIGEST 2005
156 #define ERR_UNRESOLVABLE_EMAIL 2006
157 #define ERR_INVALID_PART 2007
158 #define ERR_INVALID_PART_ORDER 2008
159 #define ERR_NO_SUCH_UPLOAD 2009
160 #define ERR_REQUEST_TIMEOUT 2010
161 #define ERR_LENGTH_REQUIRED 2011
162 #define ERR_REQUEST_TIME_SKEWED 2012
163 #define ERR_BUCKET_EXISTS 2013
164 #define ERR_BAD_URL 2014
165 #define ERR_PRECONDITION_FAILED 2015
166 #define ERR_NOT_MODIFIED 2016
167 #define ERR_INVALID_UTF8 2017
168 #define ERR_UNPROCESSABLE_ENTITY 2018
169 #define ERR_TOO_LARGE 2019
170 #define ERR_TOO_MANY_BUCKETS 2020
171 #define ERR_INVALID_REQUEST 2021
172 #define ERR_TOO_SMALL 2022
173 #define ERR_NOT_FOUND 2023
174 #define ERR_PERMANENT_REDIRECT 2024
175 #define ERR_LOCKED 2025
176 #define ERR_QUOTA_EXCEEDED 2026
177 #define ERR_SIGNATURE_NO_MATCH 2027
178 #define ERR_INVALID_ACCESS_KEY 2028
179 #define ERR_MALFORMED_XML 2029
180 #define ERR_USER_EXIST 2030
181 #define ERR_NOT_SLO_MANIFEST 2031
182 #define ERR_EMAIL_EXIST 2032
183 #define ERR_KEY_EXIST 2033
184 #define ERR_INVALID_SECRET_KEY 2034
185 #define ERR_INVALID_KEY_TYPE 2035
186 #define ERR_INVALID_CAP 2036
187 #define ERR_INVALID_TENANT_NAME 2037
188 #define ERR_WEBSITE_REDIRECT 2038
189 #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039
190 #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040
191 #define ERR_NO_SUCH_LC 2041
192 #define ERR_USER_SUSPENDED 2100
193 #define ERR_INTERNAL_ERROR 2200
194 #define ERR_NOT_IMPLEMENTED 2201
195 #define ERR_SERVICE_UNAVAILABLE 2202
196 #define ERR_ROLE_EXISTS 2203
197 #define ERR_MALFORMED_DOC 2204
198 #define ERR_NO_ROLE_FOUND 2205
199 #define ERR_DELETE_CONFLICT 2206
202 #define UINT32_MAX (0xffffffffu)
205 typedef void *RGWAccessHandle
;
210 extern PerfCounters
*perfcounter
;
212 extern int rgw_perf_start(CephContext
*cct
);
213 extern void rgw_perf_stop(CephContext
*cct
);
234 l_rgw_keystone_token_cache_hit
,
235 l_rgw_keystone_token_cache_miss
,
241 /* size should be the required string size + 1 */
242 extern int gen_rand_base64(CephContext
*cct
, char *dest
, int size
);
243 extern int gen_rand_alphanumeric(CephContext
*cct
, char *dest
, int size
);
244 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, char *dest
, int size
);
245 extern int gen_rand_alphanumeric_upper(CephContext
*cct
, char *dest
, int size
);
246 extern int gen_rand_alphanumeric_no_underscore(CephContext
*cct
, char *dest
, int size
);
247 extern int gen_rand_alphanumeric_plain(CephContext
*cct
, char *dest
, int size
);
249 extern int gen_rand_alphanumeric_lower(CephContext
*cct
, string
*str
, int length
);
251 enum RGWIntentEvent
{
256 enum RGWObjCategory
{
257 RGW_OBJ_CATEGORY_NONE
= 0,
258 RGW_OBJ_CATEGORY_MAIN
= 1,
259 RGW_OBJ_CATEGORY_SHADOW
= 2,
260 RGW_OBJ_CATEGORY_MULTIMETA
= 3,
263 /** Store error returns for output at a different point in the program */
266 rgw_err(int http
, const std::string
&s3
);
268 bool is_clear() const;
270 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
278 /* Helper class used for RGWHTTPArgs parsing */
285 explicit NameVal(string nv
) : str(nv
) {}
289 string
& get_name() { return name
; }
290 string
& get_val() { return val
; }
293 /** Stores the XML arguments associated with the HTTP request in req_state*/
296 string str
, empty_str
;
297 map
<string
, string
> val_map
;
298 map
<string
, string
> sys_val_map
;
299 map
<string
, string
> sub_resources
;
300 bool has_resp_modifier
;
301 bool admin_subresource_added
;
303 RGWHTTPArgs() : has_resp_modifier(false), admin_subresource_added(false) {}
305 /** Set the arguments; as received */
307 has_resp_modifier
= false;
309 sub_resources
.clear();
312 /** parse the received arguments */
314 void append(const string
& name
, const string
& val
);
315 /** Get the value for a specific argument parameter */
316 const string
& get(const string
& name
, bool *exists
= NULL
) const;
317 int get_bool(const string
& name
, bool *val
, bool *exists
);
318 int get_bool(const char *name
, bool *val
, bool *exists
);
319 void get_bool(const char *name
, bool *val
, bool def_val
);
321 /** Get the value for specific system argument parameter */
322 std::string
sys_get(const string
& name
, bool *exists
= nullptr) const;
324 /** see if a parameter is contained in this RGWHTTPArgs */
325 bool exists(const char *name
) const {
326 return (val_map
.find(name
) != std::end(val_map
));
328 bool sub_resource_exists(const char *name
) const {
329 return (sub_resources
.find(name
) != std::end(sub_resources
));
331 map
<string
, string
>& get_params() {
334 const std::map
<std::string
, std::string
>& get_sub_resources() const {
335 return sub_resources
;
337 unsigned get_num_params() const {
338 return val_map
.size();
340 bool has_response_modifier() const {
341 return has_resp_modifier
;
343 void set_system() { /* make all system params visible */
344 map
<string
, string
>::iterator iter
;
345 for (iter
= sys_val_map
.begin(); iter
!= sys_val_map
.end(); ++iter
) {
346 val_map
[iter
->first
] = iter
->second
;
349 const string
& get_str() {
359 void init(CephContext
*cct
, RGWEnv
* env
);
364 defer_to_bucket_acls(0) {
368 int enable_usage_log
;
369 uint8_t defer_to_bucket_acls
;
373 std::map
<string
, string
, ltstr_nocase
> env_map
;
377 void init(CephContext
*cct
);
378 void init(CephContext
*cct
, char **envp
);
379 void set(const boost::string_ref
& name
, const boost::string_ref
& val
);
380 const char *get(const char *name
, const char *def_val
= NULL
);
381 int get_int(const char *name
, int def_val
= 0);
382 bool get_bool(const char *name
, bool def_val
= 0);
383 size_t get_size(const char *name
, size_t def_val
= 0);
384 bool exists(const char *name
);
385 bool exists_prefix(const char *prefix
);
387 void remove(const char *name
);
389 std::map
<string
, string
, ltstr_nocase
>& get_map() { return env_map
; }
409 RGW_OP_GET_BUCKET_LOGGING
,
410 RGW_OP_GET_BUCKET_VERSIONING
,
411 RGW_OP_SET_BUCKET_VERSIONING
,
412 RGW_OP_GET_BUCKET_WEBSITE
,
413 RGW_OP_SET_BUCKET_WEBSITE
,
415 RGW_OP_CREATE_BUCKET
,
416 RGW_OP_DELETE_BUCKET
,
420 RGW_OP_PUT_METADATA_ACCOUNT
,
421 RGW_OP_PUT_METADATA_BUCKET
,
422 RGW_OP_PUT_METADATA_OBJECT
,
432 RGW_OP_GET_REQUEST_PAYMENT
,
433 RGW_OP_SET_REQUEST_PAYMENT
,
434 RGW_OP_INIT_MULTIPART
,
435 RGW_OP_COMPLETE_MULTIPART
,
436 RGW_OP_ABORT_MULTIPART
,
437 RGW_OP_LIST_MULTIPART
,
438 RGW_OP_LIST_BUCKET_MULTIPARTS
,
439 RGW_OP_DELETE_MULTI_OBJ
,
442 RGW_OP_GET_CROSS_DOMAIN_POLICY
,
443 RGW_OP_GET_HEALTH_CHECK
,
450 RGW_OP_PUT_ROLE_POLICY
,
451 RGW_OP_GET_ROLE_POLICY
,
452 RGW_OP_LIST_ROLE_POLICIES
,
453 RGW_OP_DELETE_ROLE_POLICY
,
456 RGW_OP_ADMIN_SET_METADATA
,
457 RGW_OP_GET_OBJ_LAYOUT
,
462 class RGWAccessControlPolicy
;
465 struct RGWAccessKey
{
466 string id
; // AccessKey
467 string key
; // SecretKey
471 RGWAccessKey(std::string _id
, std::string _key
)
472 : id(std::move(_id
)), key(std::move(_key
)) {}
474 void encode(bufferlist
& bl
) const {
475 ENCODE_START(2, 2, bl
);
478 ::encode(subuser
, bl
);
482 void decode(bufferlist::iterator
& bl
) {
483 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
486 ::decode(subuser
, bl
);
489 void dump(Formatter
*f
) const;
490 void dump_plain(Formatter
*f
) const;
491 void dump(Formatter
*f
, const string
& user
, bool swift
) const;
492 static void generate_test_instances(list
<RGWAccessKey
*>& o
);
494 void decode_json(JSONObj
*obj
);
495 void decode_json(JSONObj
*obj
, bool swift
);
497 WRITE_CLASS_ENCODER(RGWAccessKey
)
503 RGWSubUser() : perm_mask(0) {}
504 void encode(bufferlist
& bl
) const {
505 ENCODE_START(2, 2, bl
);
507 ::encode(perm_mask
, bl
);
511 void decode(bufferlist::iterator
& bl
) {
512 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
514 ::decode(perm_mask
, bl
);
517 void dump(Formatter
*f
) const;
518 void dump(Formatter
*f
, const string
& user
) const;
519 static void generate_test_instances(list
<RGWSubUser
*>& o
);
521 void decode_json(JSONObj
*obj
);
523 WRITE_CLASS_ENCODER(RGWSubUser
)
527 map
<string
, uint32_t> caps
;
529 int get_cap(const string
& cap
, string
& type
, uint32_t *perm
);
530 int add_cap(const string
& cap
);
531 int remove_cap(const string
& cap
);
533 static int parse_cap_perm(const string
& str
, uint32_t *perm
);
534 int add_from_string(const string
& str
);
535 int remove_from_string(const string
& str
);
537 void encode(bufferlist
& bl
) const {
538 ENCODE_START(1, 1, bl
);
542 void decode(bufferlist::iterator
& bl
) {
547 int check_cap(const string
& cap
, uint32_t perm
);
548 bool is_valid_cap_type(const string
& tp
);
549 void dump(Formatter
*f
) const;
550 void dump(Formatter
*f
, const char *name
) const;
552 void decode_json(JSONObj
*obj
);
554 WRITE_CLASS_ENCODER(RGWUserCaps
)
556 void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
557 void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
559 void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
561 enum RGWUserSourceType
575 map
<string
, RGWAccessKey
> access_keys
;
576 map
<string
, RGWAccessKey
> swift_keys
;
577 map
<string
, RGWSubUser
> subusers
;
584 string default_placement
;
585 list
<string
> placement_tags
;
586 RGWQuotaInfo bucket_quota
;
587 map
<int, string
> temp_url_keys
;
588 RGWQuotaInfo user_quota
;
594 max_buckets(RGW_DEFAULT_MAX_BUCKETS
),
595 op_mask(RGW_OP_TYPE_ALL
),
601 RGWAccessKey
* get_key0() {
602 if (access_keys
.empty())
605 return &(access_keys
.begin()->second
);
608 void encode(bufferlist
& bl
) const {
609 ENCODE_START(19, 9, bl
);
613 if (!access_keys
.empty()) {
614 map
<string
, RGWAccessKey
>::const_iterator iter
= access_keys
.begin();
615 const RGWAccessKey
& k
= iter
->second
;
619 ::encode(access_key
, bl
);
620 ::encode(secret_key
, bl
);
621 ::encode(display_name
, bl
);
622 ::encode(user_email
, bl
);
625 if (!swift_keys
.empty()) {
626 map
<string
, RGWAccessKey
>::const_iterator iter
= swift_keys
.begin();
627 const RGWAccessKey
& k
= iter
->second
;
631 ::encode(swift_name
, bl
);
632 ::encode(swift_key
, bl
);
633 ::encode(user_id
.id
, bl
);
634 ::encode(access_keys
, bl
);
635 ::encode(subusers
, bl
);
636 ::encode(suspended
, bl
);
637 ::encode(swift_keys
, bl
);
638 ::encode(max_buckets
, bl
);
640 ::encode(op_mask
, bl
);
641 ::encode(system
, bl
);
642 ::encode(default_placement
, bl
);
643 ::encode(placement_tags
, bl
);
644 ::encode(bucket_quota
, bl
);
645 ::encode(temp_url_keys
, bl
);
646 ::encode(user_quota
, bl
);
647 ::encode(user_id
.tenant
, bl
);
652 void decode(bufferlist::iterator
& bl
) {
653 DECODE_START_LEGACY_COMPAT_LEN_32(19, 9, 9, bl
);
654 if (struct_v
>= 2) ::decode(auid
, bl
);
655 else auid
= CEPH_AUTH_UID_DEFAULT
;
658 ::decode(access_key
, bl
);
659 ::decode(secret_key
, bl
);
664 access_keys
[access_key
] = k
;
666 ::decode(display_name
, bl
);
667 ::decode(user_email
, bl
);
668 /* We populate swift_keys map later nowadays, but we have to decode. */
671 if (struct_v
>= 3) ::decode(swift_name
, bl
);
672 if (struct_v
>= 4) ::decode(swift_key
, bl
);
674 ::decode(user_id
.id
, bl
);
676 user_id
.id
= access_key
;
678 ::decode(access_keys
, bl
);
679 ::decode(subusers
, bl
);
683 ::decode(suspended
, bl
);
686 ::decode(swift_keys
, bl
);
688 if (struct_v
>= 10) {
689 ::decode(max_buckets
, bl
);
691 max_buckets
= RGW_DEFAULT_MAX_BUCKETS
;
693 if (struct_v
>= 11) {
696 if (struct_v
>= 12) {
697 ::decode(op_mask
, bl
);
699 op_mask
= RGW_OP_TYPE_ALL
;
701 if (struct_v
>= 13) {
702 ::decode(system
, bl
);
703 ::decode(default_placement
, bl
);
704 ::decode(placement_tags
, bl
); /* tags of allowed placement rules */
706 if (struct_v
>= 14) {
707 ::decode(bucket_quota
, bl
);
709 if (struct_v
>= 15) {
710 ::decode(temp_url_keys
, bl
);
712 if (struct_v
>= 16) {
713 ::decode(user_quota
, bl
);
715 if (struct_v
>= 17) {
716 ::decode(user_id
.tenant
, bl
);
718 user_id
.tenant
.clear();
720 if (struct_v
>= 18) {
723 if (struct_v
>= 19) {
728 void dump(Formatter
*f
) const;
729 static void generate_test_instances(list
<RGWUserInfo
*>& o
);
731 void decode_json(JSONObj
*obj
);
733 WRITE_CLASS_ENCODER(RGWUserInfo
)
740 rgw_pool(const rgw_pool
& _p
) : name(_p
.name
), ns(_p
.ns
) {}
741 rgw_pool(const string
& _s
) {
744 rgw_pool(const string
& _name
, const string
& _ns
) : name(_name
), ns(_ns
) {}
746 string
to_str() const;
747 void from_str(const string
& s
);
749 void init(const string
& _s
) {
757 int compare(const rgw_pool
& p
) const {
758 int r
= name
.compare(p
.name
);
762 return ns
.compare(p
.ns
);
765 void encode(bufferlist
& bl
) const {
766 ENCODE_START(10, 10, bl
);
772 void decode_from_bucket(bufferlist::iterator
& bl
);
774 void decode(bufferlist::iterator
& bl
) {
775 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
782 * note that rgw_pool can be used where rgw_bucket was used before
783 * therefore we inherit rgw_bucket's old versions. However, we only
784 * need the first field from rgw_bucket. unless we add more fields
785 * in which case we'll need to look at struct_v, and check the actual
786 * version. Anything older than 10 needs to be treated as old rgw_bucket
796 bool operator==(const rgw_pool
& p
) const {
797 return (compare(p
) == 0);
799 bool operator!=(const rgw_pool
& p
) const {
800 return !(*this == p
);
802 bool operator<(const rgw_pool
& p
) const {
803 int r
= name
.compare(p
.name
);
805 return (ns
.compare(p
.ns
) < 0);
810 WRITE_CLASS_ENCODER(rgw_pool
)
812 struct rgw_data_placement_target
{
814 rgw_pool data_extra_pool
;
817 rgw_data_placement_target() {}
819 rgw_data_placement_target(const rgw_pool
& _data_pool
, const rgw_pool
& _data_extra_pool
, const rgw_pool
& _index_pool
)
820 : data_pool(_data_pool
), data_extra_pool(_data_extra_pool
), index_pool(_index_pool
) {}
822 const rgw_pool
& get_data_extra_pool() const {
823 if (data_extra_pool
.empty()) {
826 return data_extra_pool
;
829 int compare(const rgw_data_placement_target
& t
) {
830 int c
= data_pool
.compare(t
.data_pool
);
834 c
= data_extra_pool
.compare(t
.data_extra_pool
);
838 return index_pool
.compare(t
.index_pool
);
841 void dump(Formatter
*f
) const;
842 void decode_json(JSONObj
*obj
);
845 inline ostream
& operator<<(ostream
& out
, const rgw_pool
& p
) {
856 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
) {
859 rgw_raw_obj(const rgw_pool
& _pool
, const std::string
& _oid
, const string
& _loc
) : loc(_loc
) {
863 void init(const rgw_pool
& _pool
, const std::string
& _oid
) {
872 void encode(bufferlist
& bl
) const {
873 ENCODE_START(6, 6, bl
);
880 void decode_from_rgw_obj(bufferlist::iterator
& bl
);
882 void decode(bufferlist::iterator
& bl
) {
883 unsigned ofs
= bl
.get_off();
887 * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it,
888 * let's decode it as rgw_obj and convert it
891 decode_from_rgw_obj(bl
);
900 bool operator<(const rgw_raw_obj
& o
) const {
901 int r
= pool
.compare(o
.pool
);
903 r
= oid
.compare(o
.oid
);
905 r
= loc
.compare(o
.loc
);
911 bool operator==(const rgw_raw_obj
& o
) const {
912 return (pool
== o
.pool
&& oid
== o
.oid
&& loc
== o
.loc
);
915 void dump(Formatter
*f
) const;
916 void decode_json(JSONObj
*obj
);
918 WRITE_CLASS_ENCODER(rgw_raw_obj
)
920 inline ostream
& operator<<(ostream
& out
, const rgw_raw_obj
& o
) {
921 out
<< o
.pool
<< ":" << o
.oid
;
929 std::string bucket_id
;
930 rgw_data_placement_target explicit_placement
;
933 * runtime in-memory only info. If not empty, points to the bucket instance object
937 // cppcheck-suppress noExplicitConstructor
938 explicit rgw_bucket(const rgw_user
& u
, const cls_user_bucket
& b
) :
942 bucket_id(b
.bucket_id
),
943 explicit_placement(b
.explicit_placement
.data_pool
,
944 b
.explicit_placement
.data_extra_pool
,
945 b
.explicit_placement
.index_pool
) {}
947 void convert(cls_user_bucket
*b
) const {
950 b
->bucket_id
= bucket_id
;
951 b
->explicit_placement
.data_pool
= explicit_placement
.data_pool
.to_str();
952 b
->explicit_placement
.data_extra_pool
= explicit_placement
.data_extra_pool
.to_str();
953 b
->explicit_placement
.index_pool
= explicit_placement
.index_pool
.to_str();
956 void encode(bufferlist
& bl
) const {
957 ENCODE_START(10, 10, bl
);
959 ::encode(marker
, bl
);
960 ::encode(bucket_id
, bl
);
961 ::encode(tenant
, bl
);
962 bool encode_explicit
= !explicit_placement
.data_pool
.empty();
963 ::encode(encode_explicit
, bl
);
964 if (encode_explicit
) {
965 ::encode(explicit_placement
.data_pool
, bl
);
966 ::encode(explicit_placement
.data_extra_pool
, bl
);
967 ::encode(explicit_placement
.index_pool
, bl
);
971 void decode(bufferlist::iterator
& bl
) {
972 DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl
);
975 ::decode(explicit_placement
.data_pool
.name
, bl
);
978 ::decode(marker
, bl
);
983 snprintf(buf
, sizeof(buf
), "%llu", (long long)id
);
986 ::decode(bucket_id
, bl
);
991 ::decode(explicit_placement
.index_pool
.name
, bl
);
993 explicit_placement
.index_pool
= explicit_placement
.data_pool
;
996 ::decode(explicit_placement
.data_extra_pool
.name
, bl
);
1000 ::decode(tenant
, bl
);
1002 if (struct_v
>= 10) {
1003 bool decode_explicit
= !explicit_placement
.data_pool
.empty();
1004 ::decode(decode_explicit
, bl
);
1005 if (decode_explicit
) {
1006 ::decode(explicit_placement
.data_pool
, bl
);
1007 ::decode(explicit_placement
.data_extra_pool
, bl
);
1008 ::decode(explicit_placement
.index_pool
, bl
);
1014 // format a key for the bucket/instance. pass delim=0 to skip a field
1015 std::string
get_key(char tenant_delim
= '/',
1016 char id_delim
= ':') const;
1018 const rgw_pool
& get_data_extra_pool() const {
1019 return explicit_placement
.get_data_extra_pool();
1022 void dump(Formatter
*f
) const;
1023 void decode_json(JSONObj
*obj
);
1024 static void generate_test_instances(list
<rgw_bucket
*>& o
);
1026 bool operator<(const rgw_bucket
& b
) const {
1027 return name
.compare(b
.name
) < 0;
1029 bool operator==(const rgw_bucket
& b
) const {
1030 return (name
== b
.name
) && (bucket_id
== b
.bucket_id
);
1033 WRITE_CLASS_ENCODER(rgw_bucket
)
1035 inline ostream
& operator<<(ostream
& out
, const rgw_bucket
&b
) {
1036 out
<< b
.name
<< "[" << b
.marker
<< "])";
1040 struct rgw_bucket_shard
{
1044 rgw_bucket_shard() : shard_id(-1) {}
1045 rgw_bucket_shard(const rgw_bucket
& _b
, int _sid
) : bucket(_b
), shard_id(_sid
) {}
1047 std::string
get_key(char tenant_delim
= '/', char id_delim
= ':',
1048 char shard_delim
= ':') const;
1050 bool operator<(const rgw_bucket_shard
& b
) const {
1051 if (bucket
< b
.bucket
) {
1054 if (b
.bucket
< bucket
) {
1057 return shard_id
< b
.shard_id
;
1062 struct RGWObjVersionTracker
{
1063 obj_version read_version
;
1064 obj_version write_version
;
1066 obj_version
*version_for_read() {
1067 return &read_version
;
1070 obj_version
*version_for_write() {
1071 if (write_version
.ver
== 0)
1074 return &write_version
;
1077 obj_version
*version_for_check() {
1078 if (read_version
.ver
== 0)
1081 return &read_version
;
1084 void prepare_op_for_read(librados::ObjectReadOperation
*op
);
1085 void prepare_op_for_write(librados::ObjectWriteOperation
*op
);
1087 void apply_write() {
1088 read_version
= write_version
;
1089 write_version
= obj_version();
1093 read_version
= obj_version();
1094 write_version
= obj_version();
1097 void generate_new_write_ver(CephContext
*cct
);
1100 enum RGWBucketFlags
{
1101 BUCKET_SUSPENDED
= 0x1,
1102 BUCKET_VERSIONED
= 0x2,
1103 BUCKET_VERSIONS_SUSPENDED
= 0x4,
1106 enum RGWBucketIndexType
{
1107 RGWBIType_Normal
= 0,
1108 RGWBIType_Indexless
= 1,
1111 inline ostream
& operator<<(ostream
& out
, const RGWBucketIndexType
&index_type
)
1113 switch (index_type
) {
1114 case RGWBIType_Normal
:
1115 return out
<< "Normal";
1116 case RGWBIType_Indexless
:
1117 return out
<< "Indexless";
1119 return out
<< "Unknown";
1123 struct RGWBucketInfo
1125 enum BIShardsHashType
{
1133 ceph::real_time creation_time
;
1134 string placement_rule
;
1135 bool has_instance_obj
;
1136 RGWObjVersionTracker objv_tracker
; /* we don't need to serialize this, for runtime tracking */
1137 obj_version ep_objv
; /* entry point object version, for runtime tracking only */
1140 // Represents the number of bucket index object shards:
1141 // - value of 0 indicates there is no sharding (this is by default before this
1142 // feature is implemented).
1143 // - value of UINT32_T::MAX indicates this is a blind bucket.
1144 uint32_t num_shards
;
1146 // Represents the bucket index shard hash type.
1147 uint8_t bucket_index_shard_hash_type
;
1149 // Represents the shard number for blind bucket.
1150 const static uint32_t NUM_SHARDS_BLIND_BUCKET
;
1152 bool requester_pays
;
1155 RGWBucketWebsiteConf website_conf
;
1157 RGWBucketIndexType index_type
;
1159 bool swift_versioning
;
1160 string swift_ver_location
;
1163 void encode(bufferlist
& bl
) const {
1164 ENCODE_START(17, 4, bl
);
1165 ::encode(bucket
, bl
);
1166 ::encode(owner
.id
, bl
);
1167 ::encode(flags
, bl
);
1168 ::encode(zonegroup
, bl
);
1169 uint64_t ct
= real_clock::to_time_t(creation_time
);
1171 ::encode(placement_rule
, bl
);
1172 ::encode(has_instance_obj
, bl
);
1173 ::encode(quota
, bl
);
1174 ::encode(num_shards
, bl
);
1175 ::encode(bucket_index_shard_hash_type
, bl
);
1176 ::encode(requester_pays
, bl
);
1177 ::encode(owner
.tenant
, bl
);
1178 ::encode(has_website
, bl
);
1180 ::encode(website_conf
, bl
);
1182 ::encode((uint32_t)index_type
, bl
);
1183 ::encode(swift_versioning
, bl
);
1184 if (swift_versioning
) {
1185 ::encode(swift_ver_location
, bl
);
1187 ::encode(creation_time
, bl
);
1190 void decode(bufferlist::iterator
& bl
) {
1191 DECODE_START_LEGACY_COMPAT_LEN_32(17, 4, 4, bl
);
1192 ::decode(bucket
, bl
);
1193 if (struct_v
>= 2) {
1199 ::decode(flags
, bl
);
1201 ::decode(zonegroup
, bl
);
1202 if (struct_v
>= 6) {
1206 creation_time
= ceph::real_clock::from_time_t((time_t)ct
);
1209 ::decode(placement_rule
, bl
);
1211 ::decode(has_instance_obj
, bl
);
1213 ::decode(quota
, bl
);
1215 ::decode(num_shards
, bl
);
1217 ::decode(bucket_index_shard_hash_type
, bl
);
1219 ::decode(requester_pays
, bl
);
1221 ::decode(owner
.tenant
, bl
);
1222 if (struct_v
>= 14) {
1223 ::decode(has_website
, bl
);
1225 ::decode(website_conf
, bl
);
1227 website_conf
= RGWBucketWebsiteConf();
1230 if (struct_v
>= 15) {
1233 index_type
= (RGWBucketIndexType
)it
;
1235 index_type
= RGWBIType_Normal
;
1237 swift_versioning
= false;
1238 swift_ver_location
.clear();
1239 if (struct_v
>= 16) {
1240 ::decode(swift_versioning
, bl
);
1241 if (swift_versioning
) {
1242 ::decode(swift_ver_location
, bl
);
1245 if (struct_v
>= 17) {
1246 ::decode(creation_time
, bl
);
1250 void dump(Formatter
*f
) const;
1251 static void generate_test_instances(list
<RGWBucketInfo
*>& o
);
1253 void decode_json(JSONObj
*obj
);
1255 bool versioned() const { return (flags
& BUCKET_VERSIONED
) != 0; }
1256 int versioning_status() { return flags
& (BUCKET_VERSIONED
| BUCKET_VERSIONS_SUSPENDED
); }
1257 bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED
; }
1259 bool has_swift_versioning() const {
1260 /* A bucket may be versioned through one mechanism only. */
1261 return swift_versioning
&& !versioned();
1264 RGWBucketInfo() : flags(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD
), requester_pays(false),
1265 has_website(false), swift_versioning(false) {}
1267 WRITE_CLASS_ENCODER(RGWBucketInfo
)
1269 struct RGWBucketEntryPoint
1273 ceph::real_time creation_time
;
1276 bool has_bucket_info
;
1277 RGWBucketInfo old_bucket_info
;
1279 RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {}
1281 void encode(bufferlist
& bl
) const {
1282 ENCODE_START(10, 8, bl
);
1283 ::encode(bucket
, bl
);
1284 ::encode(owner
.id
, bl
);
1285 ::encode(linked
, bl
);
1286 uint64_t ctime
= (uint64_t)real_clock::to_time_t(creation_time
);
1287 ::encode(ctime
, bl
);
1288 ::encode(owner
, bl
);
1289 ::encode(creation_time
, bl
);
1292 void decode(bufferlist::iterator
& bl
) {
1293 bufferlist::iterator orig_iter
= bl
;
1294 DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl
);
1296 /* ouch, old entry, contains the bucket info itself */
1297 old_bucket_info
.decode(orig_iter
);
1298 has_bucket_info
= true;
1301 has_bucket_info
= false;
1302 ::decode(bucket
, bl
);
1303 ::decode(owner
.id
, bl
);
1304 ::decode(linked
, bl
);
1306 ::decode(ctime
, bl
);
1307 if (struct_v
< 10) {
1308 creation_time
= real_clock::from_time_t((time_t)ctime
);
1310 if (struct_v
>= 9) {
1311 ::decode(owner
, bl
);
1313 if (struct_v
>= 10) {
1314 ::decode(creation_time
, bl
);
1319 void dump(Formatter
*f
) const;
1320 void decode_json(JSONObj
*obj
);
1322 WRITE_CLASS_ENCODER(RGWBucketEntryPoint
)
1324 struct RGWStorageStats
1326 RGWObjCategory category
;
1328 uint64_t size_rounded
;
1329 uint64_t size_utilized
{0}; //< size after compression, encryption
1330 uint64_t num_objects
;
1333 : category(RGW_OBJ_CATEGORY_NONE
),
1338 void dump(Formatter
*f
) const;
1345 /* Namespaced forward declarations. */
1349 class RGWGetPolicyV2Extractor
;
1360 map
<string
, string
> x_meta_map
;
1366 string request_uri_aws4
;
1367 string effective_uri
;
1368 string request_params
;
1371 req_info(CephContext
*cct
, RGWEnv
*_env
);
1372 void rebuild_from(req_info
& src
);
1373 void init_meta_info(bool *found_bad_meta
);
1376 typedef cls_rgw_obj_key rgw_obj_index_key
;
1378 struct rgw_obj_key
{
1384 // cppcheck-suppress noExplicitConstructor
1385 rgw_obj_key(const string
& n
) : name(n
) {}
1386 rgw_obj_key(const string
& n
, const string
& i
) : name(n
), instance(i
) {}
1387 rgw_obj_key(const string
& n
, const string
& i
, const string
& _ns
) : name(n
), instance(i
), ns(_ns
) {}
1389 rgw_obj_key(const rgw_obj_index_key
& k
) {
1390 parse_index_key(k
.name
, &name
, &ns
);
1391 instance
= k
.instance
;
1394 static void parse_index_key(const string
& key
, string
*name
, string
*ns
) {
1395 if (key
[0] != '_') {
1400 if (key
[1] == '_') {
1401 *name
= key
.substr(1);
1405 ssize_t pos
= key
.find('_', 1);
1407 /* shouldn't happen, just use key */
1413 *name
= key
.substr(pos
+ 1);
1414 *ns
= key
.substr(1, pos
-1);
1417 void set(const string
& n
) {
1423 void set(const string
& n
, const string
& i
) {
1429 void set(const string
& n
, const string
& i
, const string
& _ns
) {
1435 bool set(const rgw_obj_index_key
& index_key
) {
1436 if (!parse_raw_oid(index_key
.name
, this)) {
1439 instance
= index_key
.instance
;
1443 void set_instance(const string
& i
) {
1447 string
get_index_key_name() const {
1449 if (name
.size() < 1 || name
[0] != '_') {
1452 return string("_") + name
;
1455 char buf
[ns
.size() + 16];
1456 snprintf(buf
, sizeof(buf
), "_%s_", ns
.c_str());
1457 return string(buf
) + name
;
1460 void get_index_key(rgw_obj_index_key
*key
) const {
1461 key
->name
= get_index_key_name();
1462 key
->instance
= instance
;
1465 string
get_loc() const {
1467 * For backward compatibility. Older versions used to have object locator on all objects,
1468 * however, the name was the effective object locator. This had the same effect as not
1469 * having object locator at all for most objects but the ones that started with underscore as
1470 * these were escaped.
1472 if (name
[0] == '_' && ns
.empty()) {
1479 bool empty() const {
1480 return name
.empty();
1483 bool have_null_instance() const {
1484 return instance
== "null";
1487 bool have_instance() const {
1488 return !instance
.empty();
1491 bool need_to_encode_instance() const {
1492 return have_instance() && !have_null_instance();
1495 string
get_oid() const {
1496 if (ns
.empty() && !need_to_encode_instance()) {
1497 if (name
.size() < 1 || name
[0] != '_') {
1500 return string("_") + name
;
1505 if (need_to_encode_instance()) {
1506 oid
.append(string(":") + instance
);
1513 bool operator==(const rgw_obj_key
& k
) const {
1514 return (name
.compare(k
.name
) == 0) &&
1515 (instance
.compare(k
.instance
) == 0);
1518 bool operator<(const rgw_obj_key
& k
) const {
1519 int r
= name
.compare(k
.name
);
1521 r
= instance
.compare(k
.instance
);
1526 bool operator<=(const rgw_obj_key
& k
) const {
1527 return !(k
< *this);
1530 static void parse_ns_field(string
& ns
, string
& instance
) {
1531 int pos
= ns
.find(':');
1533 instance
= ns
.substr(pos
+ 1);
1534 ns
= ns
.substr(0, pos
);
1540 static bool parse_raw_oid(const string
& oid
, rgw_obj_key
*key
) {
1541 key
->instance
.clear();
1543 if (oid
[0] != '_') {
1548 if (oid
.size() >= 2 && oid
[1] == '_') {
1549 key
->name
= oid
.substr(1);
1553 if (oid
[0] != '_' || oid
.size() < 3) // for namespace, min size would be 3: _x_
1556 int pos
= oid
.find('_', 1);
1557 if (pos
<= 1) // if it starts with __, it's not in our namespace
1560 key
->ns
= oid
.substr(1, pos
- 1);
1561 parse_ns_field(key
->ns
, key
->instance
);
1563 key
->name
= oid
.substr(pos
+ 1);
1568 * Translate a namespace-mangled object name to the user-facing name
1569 * existing in the given namespace.
1571 * If the object is part of the given namespace, it returns true
1572 * and cuts down the name to the unmangled version. If it is not
1573 * part of the given namespace, it returns false.
1575 static bool oid_to_key_in_ns(const string
& oid
, rgw_obj_key
*key
, const string
& ns
) {
1577 bool ret
= parse_raw_oid(oid
, key
);
1582 return (ns
== key
->ns
);
1586 * Given a mangled object name and an empty namespace string, this
1587 * function extracts the namespace into the string and sets the object
1588 * name to be the unmangled version.
1590 * It returns true after successfully doing so, or
1591 * false if it fails.
1593 static bool strip_namespace_from_name(string
& name
, string
& ns
, string
& instance
) {
1596 if (name
[0] != '_') {
1600 size_t pos
= name
.find('_', 1);
1601 if (pos
== string::npos
) {
1605 if (name
[1] == '_') {
1606 name
= name
.substr(1);
1610 size_t period_pos
= name
.find('.');
1611 if (period_pos
< pos
) {
1615 ns
= name
.substr(1, pos
-1);
1616 name
= name
.substr(pos
+1, string::npos
);
1618 parse_ns_field(ns
, instance
);
1622 void encode(bufferlist
& bl
) const {
1623 ENCODE_START(2, 1, bl
);
1625 ::encode(instance
, bl
);
1629 void decode(bufferlist::iterator
& bl
) {
1630 DECODE_START(2, bl
);
1632 ::decode(instance
, bl
);
1633 if (struct_v
>= 2) {
1638 void dump(Formatter
*f
) const;
1640 WRITE_CLASS_ENCODER(rgw_obj_key
)
1642 inline ostream
& operator<<(ostream
& out
, const rgw_obj_key
&o
) {
1643 if (o
.instance
.empty()) {
1644 return out
<< o
.name
;
1646 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1650 inline ostream
& operator<<(ostream
& out
, const rgw_obj_index_key
&o
) {
1651 if (o
.instance
.empty()) {
1652 return out
<< o
.name
;
1654 return out
<< o
.name
<< "[" << o
.instance
<< "]";
1658 struct rgw_aws4_auth
{
1662 string signedheaders
;
1664 string access_key_id
;
1665 string credential_scope
;
1666 string canonical_uri
;
1667 string canonical_qs
;
1668 string canonical_hdrs
;
1670 string new_signature
;
1671 string payload_hash
;
1672 string seed_signature
;
1674 char signing_k
[CEPH_CRYPTO_HMACSHA256_DIGESTSIZE
];
1678 struct req_init_state
{
1679 /* Keeps [[tenant]:]bucket until we parse the token. */
1684 /* XXX why don't RGWRequest (or descendants) hold this state? */
1687 #include "rgw_auth.h"
1689 /** Store all the state necessary to complete and respond to an HTTP request*/
1692 rgw::io::BasicClient
*cio
;
1693 RGWRequest
*req
; /// XXX: re-remove??
1696 bool content_started
;
1698 ceph::Formatter
*formatter
;
1700 string relative_uri
;
1702 int64_t content_length
;
1703 map
<string
, string
> generic_attrs
;
1708 bool enable_ops_log
;
1709 bool enable_usage_log
;
1710 uint8_t defer_to_bucket_acls
;
1713 /* Set once when url_bucket is parsed and not violated thereafter. */
1714 string account_name
;
1716 string bucket_tenant
;
1721 string src_tenant_name
;
1722 string src_bucket_name
;
1723 rgw_obj_key src_object
;
1724 ACLOwner bucket_owner
;
1727 string zonegroup_name
;
1728 string zonegroup_endpoint
;
1729 string bucket_instance_id
;
1730 int bucket_instance_shard_id
;
1734 RGWBucketInfo bucket_info
;
1735 map
<string
, bufferlist
> bucket_attrs
;
1743 /* TODO(rzarzynski): switch out to the static_ptr for both members. */
1745 /* Object having the knowledge about an authenticated identity and allowing
1746 * to apply it during the authorization phase (verify_permission() methods
1747 * of a given RGWOp). Thus, it bounds authentication and authorization steps
1748 * through a well-defined interface. For more details, see rgw_auth.h. */
1749 std::unique_ptr
<rgw::auth::Identity
> identity
;
1751 std::unique_ptr
<rgw::auth::Completer
> completer
;
1753 /* A container for credentials of the S3's browser upload. It's necessary
1754 * because: 1) the ::authenticate() method of auth engines and strategies
1755 * take req_state only; 2) auth strategies live much longer than RGWOps -
1756 * there is no way to pass additional data dependencies through ctors. */
1759 friend class RGWPostObj_ObjStore_S3
;
1761 friend class rgw::auth::s3::RGWGetPolicyV2Extractor
;
1763 std::string access_key
;
1764 std::string signature
;
1765 ceph::bufferlist encoded_policy
;
1769 std::unique_ptr
<RGWAccessControlPolicy
> user_acl
;
1770 RGWAccessControlPolicy
*bucket_acl
;
1771 RGWAccessControlPolicy
*object_acl
;
1773 /* Is the request made by an user marked as a system one?
1774 * Being system user means we also have the admin status. */
1775 bool system_request
;
1777 /* aws4 auth support */
1778 bool aws4_auth_needs_complete
;
1779 bool aws4_auth_streaming_mode
;
1780 unique_ptr
<rgw_aws4_auth
> aws4_auth
;
1783 bool has_acl_header
;
1784 const char *http_auth
;
1785 bool local_source
; /* source is local */
1789 /* Content-Disposition override for TempURL of Swift API. */
1798 req_init_state init_state
;
1806 req_state(CephContext
* _cct
, RGWEnv
* e
, RGWUserInfo
* u
);
1810 /** Store basic data on bucket */
1811 struct RGWBucketEnt
{
1814 size_t size_rounded
;
1815 real_time creation_time
;
1818 RGWBucketEnt() : size(0), size_rounded(0), count(0) {}
1820 explicit RGWBucketEnt(const rgw_user
& u
, const cls_user_bucket_entry
& e
)
1821 : bucket(u
, e
.bucket
),
1823 size_rounded(e
.size_rounded
),
1824 creation_time(e
.creation_time
),
1828 void convert(cls_user_bucket_entry
*b
) const {
1829 bucket
.convert(&b
->bucket
);
1831 b
->size_rounded
= size_rounded
;
1832 b
->creation_time
= creation_time
;
1836 void encode(bufferlist
& bl
) const {
1837 ENCODE_START(6, 5, bl
);
1839 __u32 mt
= ceph::real_clock::to_time_t(creation_time
);
1840 string empty_str
; // originally had the bucket name here, but we encode bucket later
1841 ::encode(empty_str
, bl
);
1844 ::encode(count
, bl
);
1845 ::encode(bucket
, bl
);
1848 ::encode(creation_time
, bl
);
1851 void decode(bufferlist::iterator
& bl
) {
1852 DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl
);
1855 string empty_str
; // backward compatibility
1856 ::decode(empty_str
, bl
);
1861 creation_time
= ceph::real_clock::from_time_t(mt
);
1864 ::decode(count
, bl
);
1866 ::decode(bucket
, bl
);
1871 ::decode(creation_time
, bl
);
1874 void dump(Formatter
*f
) const;
1875 static void generate_test_instances(list
<RGWBucketEnt
*>& o
);
1877 WRITE_CLASS_ENCODER(RGWBucketEnt
)
1883 bool in_extra_data
{false}; /* in-memory only member, does not serialize */
1885 // Represents the hash index source for this object once it is set (non-empty)
1886 std::string index_hash_source
;
1889 rgw_obj(const rgw_bucket
& b
, const std::string
& name
) : bucket(b
), key(name
) {}
1890 rgw_obj(const rgw_bucket
& b
, const rgw_obj_key
& k
) : bucket(b
), key(k
) {}
1891 rgw_obj(const rgw_bucket
& b
, const rgw_obj_index_key
& k
) : bucket(b
), key(k
) {}
1893 void init(const rgw_bucket
& b
, const std::string
& name
) {
1897 void init(const rgw_bucket
& b
, const std::string
& name
, const string
& i
, const string
& n
) {
1899 key
.set(name
, i
, n
);
1901 void init_ns(const rgw_bucket
& b
, const std::string
& name
, const string
& n
) {
1904 key
.instance
.clear();
1908 bool empty() const {
1912 void set_key(const rgw_obj_key
& k
) {
1916 string
get_oid() const {
1917 return key
.get_oid();
1920 const string
& get_hash_object() const {
1921 return index_hash_source
.empty() ? key
.name
: index_hash_source
;
1924 void set_in_extra_data(bool val
) {
1925 in_extra_data
= val
;
1928 bool is_in_extra_data() const {
1929 return in_extra_data
;
1932 void encode(bufferlist
& bl
) const {
1933 ENCODE_START(6, 6, bl
);
1934 ::encode(bucket
, bl
);
1935 ::encode(key
.ns
, bl
);
1936 ::encode(key
.name
, bl
);
1937 ::encode(key
.instance
, bl
);
1938 // ::encode(placement_id, bl);
1941 void decode(bufferlist::iterator
& bl
) {
1942 DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl
);
1945 ::decode(bucket
.name
, bl
); /* bucket.name */
1946 ::decode(s
, bl
); /* loc */
1947 ::decode(key
.ns
, bl
);
1948 ::decode(key
.name
, bl
);
1950 ::decode(bucket
, bl
);
1952 ::decode(key
.instance
, bl
);
1953 if (key
.ns
.empty() && key
.instance
.empty()) {
1954 if (key
.name
[0] == '_') {
1955 key
.name
= key
.name
.substr(1);
1958 if (struct_v
>= 5) {
1959 ::decode(key
.name
, bl
);
1961 ssize_t pos
= key
.name
.find('_', 1);
1963 throw buffer::error();
1965 key
.name
= key
.name
.substr(pos
);
1969 ::decode(bucket
, bl
);
1970 ::decode(key
.ns
, bl
);
1971 ::decode(key
.name
, bl
);
1972 ::decode(key
.instance
, bl
);
1973 // ::decode(placement_id, bl);
1977 void dump(Formatter
*f
) const;
1978 static void generate_test_instances(list
<rgw_obj
*>& o
);
1980 bool operator==(const rgw_obj
& o
) const {
1981 return (key
== o
.key
) &&
1982 (bucket
== o
.bucket
);
1984 bool operator<(const rgw_obj
& o
) const {
1985 int r
= key
.name
.compare(o
.key
.name
);
1987 r
= bucket
.bucket_id
.compare(o
.bucket
.bucket_id
); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */
1989 r
= key
.ns
.compare(o
.key
.ns
);
1991 r
= key
.instance
.compare(o
.key
.instance
);
1999 const rgw_pool
& get_explicit_data_pool() {
2000 if (!in_extra_data
|| bucket
.explicit_placement
.data_extra_pool
.empty()) {
2001 return bucket
.explicit_placement
.data_pool
;
2003 return bucket
.explicit_placement
.data_extra_pool
;
2006 WRITE_CLASS_ENCODER(rgw_obj
)
2008 struct rgw_cache_entry_info
{
2009 string cache_locator
;
2012 rgw_cache_entry_info() : gen(0) {}
2015 inline ostream
& operator<<(ostream
& out
, const rgw_obj
&o
) {
2016 return out
<< o
.bucket
.name
<< ":" << o
.get_oid();
2019 static inline void buf_to_hex(const unsigned char *buf
, int len
, char *str
)
2023 for (i
= 0; i
< len
; i
++) {
2024 sprintf(&str
[i
*2], "%02x", (int)buf
[i
]);
2028 static inline int hexdigit(char c
)
2030 if (c
>= '0' && c
<= '9')
2033 if (c
>= 'A' && c
<= 'F')
2034 return c
- 'A' + 0xa;
2038 static inline int hex_to_buf(const char *hex
, char *buf
, int len
)
2041 const char *p
= hex
;
2046 int d
= hexdigit(*p
);
2063 static inline int rgw_str_to_bool(const char *s
, int def_val
)
2068 return (strcasecmp(s
, "on") == 0 ||
2069 strcasecmp(s
, "yes") == 0 ||
2070 strcasecmp(s
, "1") == 0);
2073 static inline void append_rand_alpha(CephContext
*cct
, const string
& src
, string
& dest
, int len
)
2077 gen_rand_alphanumeric(cct
, buf
, len
);
2082 static inline const char *rgw_obj_category_name(RGWObjCategory category
)
2085 case RGW_OBJ_CATEGORY_NONE
:
2087 case RGW_OBJ_CATEGORY_MAIN
:
2089 case RGW_OBJ_CATEGORY_SHADOW
:
2090 return "rgw.shadow";
2091 case RGW_OBJ_CATEGORY_MULTIMETA
:
2092 return "rgw.multimeta";
2098 static inline uint64_t rgw_rounded_kb(uint64_t bytes
)
2100 return (bytes
+ 1023) / 1024;
2103 static inline uint64_t rgw_rounded_objsize(uint64_t bytes
)
2105 return ((bytes
+ 4095) & ~4095);
2108 static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes
)
2110 return ((bytes
+ 4095) & ~4095) / 1024;
2113 extern string
rgw_string_unquote(const string
& s
);
2114 extern void parse_csv_string(const string
& ival
, vector
<string
>& ovals
);
2115 extern int parse_key_value(string
& in_str
, string
& key
, string
& val
);
2116 extern int parse_key_value(string
& in_str
, const char *delim
, string
& key
, string
& val
);
2118 extern int parse_time(const char *time_str
, real_time
*time
);
2119 extern bool parse_rfc2616(const char *s
, struct tm
*t
);
2120 extern bool parse_iso8601(const char *s
, struct tm
*t
, uint32_t *pns
= NULL
, bool extended_format
= true);
2121 extern string
rgw_trim_whitespace(const string
& src
);
2122 extern boost::string_ref
rgw_trim_whitespace(const boost::string_ref
& src
);
2123 extern string
rgw_trim_quotes(const string
& val
);
2125 extern void rgw_to_iso8601(const real_time
& t
, char *dest
, int buf_size
);
2126 extern void rgw_to_iso8601(const real_time
& t
, string
*dest
);
2128 /** Check if the req_state's user has the necessary permissions
2129 * to do the requested action */
2130 bool verify_user_permission(struct req_state
* const s
,
2131 RGWAccessControlPolicy
* const user_acl
,
2133 bool verify_user_permission(struct req_state
* const s
,
2135 extern bool verify_bucket_permission(struct req_state
* s
,
2136 RGWAccessControlPolicy
* user_acl
,
2137 RGWAccessControlPolicy
* bucket_acl
,
2139 extern bool verify_bucket_permission(struct req_state
*s
, int perm
);
2140 extern bool verify_object_permission(struct req_state
*s
,
2141 RGWAccessControlPolicy
* user_acl
,
2142 RGWAccessControlPolicy
* bucket_acl
,
2143 RGWAccessControlPolicy
* object_acl
,
2145 extern bool verify_object_permission(struct req_state
*s
, int perm
);
2146 /** Convert an input URL into a sane object name
2147 * by converting %-escaped strings into characters, etc*/
2148 extern void rgw_uri_escape_char(char c
, string
& dst
);
2149 extern bool url_decode(const std::string
& src_str
,
2150 std::string
& dest_str
,
2151 bool in_query
= false);
2152 extern void url_encode(const std::string
& src
,
2154 extern std::string
url_encode(const std::string
& src
);
2156 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
2157 extern void calc_hmac_sha1(const char *key
, int key_len
,
2158 const char *msg
, int msg_len
, char *dest
);
2159 /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */
2160 extern void calc_hmac_sha256(const char *key
, int key_len
, const char *msg
, int msg_len
, char *dest
);
2161 extern void calc_hash_sha256(const char *msg
, int len
, string
& dest
);
2162 extern void calc_hash_sha256(const string
& msg
, string
& dest
);
2164 using ceph::crypto::SHA256
;
2165 extern SHA256
* calc_hash_sha256_open_stream();
2166 extern void calc_hash_sha256_update_stream(SHA256
*hash
, const char *msg
, int len
);
2167 extern string
calc_hash_sha256_close_stream(SHA256
**hash
);
2169 extern int rgw_parse_op_type_list(const string
& str
, uint32_t *perm
);
2171 int match(const string
& pattern
, const string
& input
, int flag
);