]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
4 | /* |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net> | |
8 | * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com> | |
9 | * | |
10 | * This is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU Lesser General Public | |
12 | * License version 2.1, as published by the Free Software | |
13 | * Foundation. See file COPYING. | |
14 | * | |
15 | */ | |
16 | ||
17 | #ifndef CEPH_RGW_COMMON_H | |
18 | #define CEPH_RGW_COMMON_H | |
19 | ||
31f18b77 FG |
20 | #include <array> |
21 | ||
22 | #include <boost/utility/string_view.hpp> | |
23 | ||
7c673cae | 24 | #include "common/ceph_crypto.h" |
9f95a23c | 25 | #include "common/random_string.h" |
7c673cae FG |
26 | #include "rgw_acl.h" |
27 | #include "rgw_cors.h" | |
31f18b77 | 28 | #include "rgw_iam_policy.h" |
7c673cae FG |
29 | #include "rgw_quota.h" |
30 | #include "rgw_string.h" | |
11fdf7f2 | 31 | #include "common/async/yield_context.h" |
7c673cae | 32 | #include "rgw_website.h" |
eafe8130 | 33 | #include "rgw_object_lock.h" |
9f95a23c TL |
34 | #include "rgw_tag.h" |
35 | #include "rgw_sync_policy.h" | |
7c673cae FG |
36 | #include "cls/version/cls_version_types.h" |
37 | #include "cls/user/cls_user_types.h" | |
38 | #include "cls/rgw/cls_rgw_types.h" | |
39 | #include "include/rados/librados.hpp" | |
9f95a23c | 40 | #include "rgw_public_access.h" |
7c673cae | 41 | |
7c673cae FG |
42 | namespace ceph { |
43 | class Formatter; | |
44 | } | |
45 | ||
9f95a23c TL |
46 | namespace rgw::sal { |
47 | class RGWUser; | |
48 | } | |
7c673cae | 49 | |
9f95a23c | 50 | using ceph::crypto::MD5; |
7c673cae FG |
51 | |
52 | #define RGW_ATTR_PREFIX "user.rgw." | |
53 | ||
54 | #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" | |
55 | #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-" | |
56 | ||
57 | #define RGW_AMZ_PREFIX "x-amz-" | |
58 | #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "meta-" | |
59 | #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location" | |
224ce89b | 60 | #define RGW_AMZ_TAG_COUNT RGW_AMZ_PREFIX "tagging-count" |
7c673cae FG |
61 | |
62 | #define RGW_SYS_PARAM_PREFIX "rgwx-" | |
63 | ||
64 | #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl" | |
65 | #define RGW_ATTR_LC RGW_ATTR_PREFIX "lc" | |
66 | #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors" | |
67 | #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag" | |
68 | #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets" | |
69 | #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX | |
70 | #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type" | |
71 | #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control" | |
72 | #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition" | |
73 | #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding" | |
74 | #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language" | |
75 | #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires" | |
76 | #define RGW_ATTR_DELETE_AT RGW_ATTR_PREFIX "delete_at" | |
77 | #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag" | |
181888fb | 78 | #define RGW_ATTR_TAIL_TAG RGW_ATTR_PREFIX "tail_tag" |
7c673cae FG |
79 | #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name" |
80 | #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest" | |
81 | #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest" | |
82 | #define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION | |
83 | #define RGW_ATTR_SLO_MANIFEST RGW_ATTR_PREFIX "slo_manifest" | |
84 | /* Information whether an object is SLO or not must be exposed to | |
85 | * user through custom HTTP header named X-Static-Large-Object. */ | |
86 | #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object" | |
87 | #define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag" | |
11fdf7f2 | 88 | #define RGW_ATTR_STORAGE_CLASS RGW_ATTR_PREFIX "storage_class" |
7c673cae | 89 | |
eafe8130 TL |
90 | /* S3 Object Lock*/ |
91 | #define RGW_ATTR_OBJECT_LOCK RGW_ATTR_PREFIX "object-lock" | |
92 | #define RGW_ATTR_OBJECT_RETENTION RGW_ATTR_PREFIX "object-retention" | |
93 | #define RGW_ATTR_OBJECT_LEGAL_HOLD RGW_ATTR_PREFIX "object-legal-hold" | |
94 | ||
95 | ||
7c673cae FG |
96 | #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver" |
97 | #define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone" | |
224ce89b | 98 | #define RGW_ATTR_TAGS RGW_ATTR_PREFIX RGW_AMZ_PREFIX "tagging" |
7c673cae FG |
99 | |
100 | #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key" | |
101 | #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2" | |
102 | ||
103 | /* Account/container quota of the Swift API. */ | |
104 | #define RGW_ATTR_QUOTA_NOBJS RGW_ATTR_META_PREFIX "quota-count" | |
105 | #define RGW_ATTR_QUOTA_MSIZE RGW_ATTR_META_PREFIX "quota-bytes" | |
106 | ||
107 | /* Static Web Site of Swift API. */ | |
108 | #define RGW_ATTR_WEB_INDEX RGW_ATTR_META_PREFIX "web-index" | |
109 | #define RGW_ATTR_WEB_ERROR RGW_ATTR_META_PREFIX "web-error" | |
110 | #define RGW_ATTR_WEB_LISTINGS RGW_ATTR_META_PREFIX "web-listings" | |
111 | #define RGW_ATTR_WEB_LIST_CSS RGW_ATTR_META_PREFIX "web-listings-css" | |
112 | #define RGW_ATTR_SUBDIR_MARKER RGW_ATTR_META_PREFIX "web-directory-type" | |
113 | ||
114 | #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh." | |
115 | ||
116 | #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info" | |
117 | #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver" | |
118 | #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag" | |
119 | #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending." | |
120 | ||
121 | #define RGW_ATTR_COMPRESSION RGW_ATTR_PREFIX "compression" | |
122 | ||
11fdf7f2 TL |
123 | #define RGW_ATTR_APPEND_PART_NUM RGW_ATTR_PREFIX "append_part_num" |
124 | ||
31f18b77 FG |
125 | /* IAM Policy */ |
126 | #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy" | |
11fdf7f2 | 127 | #define RGW_ATTR_USER_POLICY RGW_ATTR_PREFIX "user-policy" |
9f95a23c | 128 | #define RGW_ATTR_PUBLIC_ACCESS RGW_ATTR_PREFIX "public-access" |
31f18b77 | 129 | |
7c673cae FG |
130 | /* RGW File Attributes */ |
131 | #define RGW_ATTR_UNIX_KEY1 RGW_ATTR_PREFIX "unix-key1" | |
132 | #define RGW_ATTR_UNIX1 RGW_ATTR_PREFIX "unix1" | |
133 | ||
134 | #define RGW_ATTR_CRYPT_PREFIX RGW_ATTR_PREFIX "crypt." | |
135 | #define RGW_ATTR_CRYPT_MODE RGW_ATTR_CRYPT_PREFIX "mode" | |
136 | #define RGW_ATTR_CRYPT_KEYMD5 RGW_ATTR_CRYPT_PREFIX "keymd5" | |
137 | #define RGW_ATTR_CRYPT_KEYID RGW_ATTR_CRYPT_PREFIX "keyid" | |
138 | #define RGW_ATTR_CRYPT_KEYSEL RGW_ATTR_CRYPT_PREFIX "keysel" | |
139 | ||
7c673cae FG |
140 | |
141 | #define RGW_FORMAT_PLAIN 0 | |
142 | #define RGW_FORMAT_XML 1 | |
143 | #define RGW_FORMAT_JSON 2 | |
144 | #define RGW_FORMAT_HTML 3 | |
145 | ||
146 | #define RGW_CAP_READ 0x1 | |
147 | #define RGW_CAP_WRITE 0x2 | |
148 | #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE) | |
149 | ||
150 | #define RGW_REST_SWIFT 0x1 | |
151 | #define RGW_REST_SWIFT_AUTH 0x2 | |
152 | #define RGW_REST_S3 0x4 | |
153 | #define RGW_REST_WEBSITE 0x8 | |
11fdf7f2 | 154 | #define RGW_REST_STS 0x10 |
92f5a8d4 | 155 | #define RGW_REST_IAM 0x20 |
7c673cae FG |
156 | |
157 | #define RGW_SUSPENDED_USER_AUID (uint64_t)-2 | |
158 | ||
159 | #define RGW_OP_TYPE_READ 0x01 | |
160 | #define RGW_OP_TYPE_WRITE 0x02 | |
161 | #define RGW_OP_TYPE_DELETE 0x04 | |
162 | ||
163 | #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) | |
164 | #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) | |
165 | ||
166 | #define RGW_DEFAULT_MAX_BUCKETS 1000 | |
167 | ||
168 | #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1 | |
169 | #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2 | |
170 | ||
171 | #define STATUS_CREATED 1900 | |
172 | #define STATUS_ACCEPTED 1901 | |
173 | #define STATUS_NO_CONTENT 1902 | |
174 | #define STATUS_PARTIAL_CONTENT 1903 | |
175 | #define STATUS_REDIRECT 1904 | |
176 | #define STATUS_NO_APPLY 1905 | |
177 | #define STATUS_APPLIED 1906 | |
178 | ||
179 | #define ERR_INVALID_BUCKET_NAME 2000 | |
180 | #define ERR_INVALID_OBJECT_NAME 2001 | |
181 | #define ERR_NO_SUCH_BUCKET 2002 | |
182 | #define ERR_METHOD_NOT_ALLOWED 2003 | |
183 | #define ERR_INVALID_DIGEST 2004 | |
184 | #define ERR_BAD_DIGEST 2005 | |
185 | #define ERR_UNRESOLVABLE_EMAIL 2006 | |
186 | #define ERR_INVALID_PART 2007 | |
187 | #define ERR_INVALID_PART_ORDER 2008 | |
188 | #define ERR_NO_SUCH_UPLOAD 2009 | |
189 | #define ERR_REQUEST_TIMEOUT 2010 | |
190 | #define ERR_LENGTH_REQUIRED 2011 | |
191 | #define ERR_REQUEST_TIME_SKEWED 2012 | |
192 | #define ERR_BUCKET_EXISTS 2013 | |
193 | #define ERR_BAD_URL 2014 | |
194 | #define ERR_PRECONDITION_FAILED 2015 | |
195 | #define ERR_NOT_MODIFIED 2016 | |
196 | #define ERR_INVALID_UTF8 2017 | |
197 | #define ERR_UNPROCESSABLE_ENTITY 2018 | |
198 | #define ERR_TOO_LARGE 2019 | |
199 | #define ERR_TOO_MANY_BUCKETS 2020 | |
200 | #define ERR_INVALID_REQUEST 2021 | |
201 | #define ERR_TOO_SMALL 2022 | |
202 | #define ERR_NOT_FOUND 2023 | |
203 | #define ERR_PERMANENT_REDIRECT 2024 | |
204 | #define ERR_LOCKED 2025 | |
205 | #define ERR_QUOTA_EXCEEDED 2026 | |
206 | #define ERR_SIGNATURE_NO_MATCH 2027 | |
207 | #define ERR_INVALID_ACCESS_KEY 2028 | |
208 | #define ERR_MALFORMED_XML 2029 | |
209 | #define ERR_USER_EXIST 2030 | |
210 | #define ERR_NOT_SLO_MANIFEST 2031 | |
211 | #define ERR_EMAIL_EXIST 2032 | |
212 | #define ERR_KEY_EXIST 2033 | |
213 | #define ERR_INVALID_SECRET_KEY 2034 | |
214 | #define ERR_INVALID_KEY_TYPE 2035 | |
215 | #define ERR_INVALID_CAP 2036 | |
216 | #define ERR_INVALID_TENANT_NAME 2037 | |
217 | #define ERR_WEBSITE_REDIRECT 2038 | |
218 | #define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2039 | |
219 | #define ERR_AMZ_CONTENT_SHA256_MISMATCH 2040 | |
220 | #define ERR_NO_SUCH_LC 2041 | |
224ce89b WB |
221 | #define ERR_NO_SUCH_USER 2042 |
222 | #define ERR_NO_SUCH_SUBUSER 2043 | |
11fdf7f2 TL |
223 | #define ERR_MFA_REQUIRED 2044 |
224 | #define ERR_NO_SUCH_CORS_CONFIGURATION 2045 | |
eafe8130 TL |
225 | #define ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION 2046 |
226 | #define ERR_INVALID_RETENTION_PERIOD 2047 | |
7c673cae FG |
227 | #define ERR_USER_SUSPENDED 2100 |
228 | #define ERR_INTERNAL_ERROR 2200 | |
229 | #define ERR_NOT_IMPLEMENTED 2201 | |
230 | #define ERR_SERVICE_UNAVAILABLE 2202 | |
231 | #define ERR_ROLE_EXISTS 2203 | |
232 | #define ERR_MALFORMED_DOC 2204 | |
233 | #define ERR_NO_ROLE_FOUND 2205 | |
234 | #define ERR_DELETE_CONFLICT 2206 | |
31f18b77 FG |
235 | #define ERR_NO_SUCH_BUCKET_POLICY 2207 |
236 | #define ERR_INVALID_LOCATION_CONSTRAINT 2208 | |
224ce89b WB |
237 | #define ERR_TAG_CONFLICT 2209 |
238 | #define ERR_INVALID_TAG 2210 | |
239 | #define ERR_ZERO_IN_URL 2211 | |
c07f9fc5 FG |
240 | #define ERR_MALFORMED_ACL_ERROR 2212 |
241 | #define ERR_ZONEGROUP_DEFAULT_PLACEMENT_MISCONFIGURATION 2213 | |
3efd9988 | 242 | #define ERR_INVALID_ENCRYPTION_ALGORITHM 2214 |
11fdf7f2 TL |
243 | #define ERR_INVALID_CORS_RULES_ERROR 2215 |
244 | #define ERR_NO_CORS_FOUND 2216 | |
245 | #define ERR_INVALID_WEBSITE_ROUTING_RULES_ERROR 2217 | |
246 | #define ERR_RATE_LIMITED 2218 | |
247 | #define ERR_POSITION_NOT_EQUAL_TO_LENGTH 2219 | |
248 | #define ERR_OBJECT_NOT_APPENDABLE 2220 | |
249 | #define ERR_INVALID_BUCKET_STATE 2221 | |
31f18b77 FG |
250 | |
251 | #define ERR_BUSY_RESHARDING 2300 | |
11fdf7f2 | 252 | #define ERR_NO_SUCH_ENTITY 2301 |
9f95a23c | 253 | #define ERR_LIMIT_EXCEEDED 2302 |
11fdf7f2 TL |
254 | |
255 | // STS Errors | |
256 | #define ERR_PACKED_POLICY_TOO_LARGE 2400 | |
257 | #define ERR_INVALID_IDENTITY_TOKEN 2401 | |
7c673cae | 258 | |
9f95a23c TL |
259 | #define ERR_NO_SUCH_TAG_SET 2402 |
260 | ||
7c673cae FG |
261 | #ifndef UINT32_MAX |
262 | #define UINT32_MAX (0xffffffffu) | |
263 | #endif | |
264 | ||
31f18b77 FG |
265 | struct req_state; |
266 | ||
7c673cae FG |
267 | typedef void *RGWAccessHandle; |
268 | ||
7c673cae FG |
269 | enum RGWIntentEvent { |
270 | DEL_OBJ = 0, | |
271 | DEL_DIR = 1, | |
272 | }; | |
273 | ||
11fdf7f2 TL |
274 | enum HostStyle { |
275 | PathStyle = 0, | |
276 | VirtualStyle = 1, | |
7c673cae FG |
277 | }; |
278 | ||
279 | /** Store error returns for output at a different point in the program */ | |
280 | struct rgw_err { | |
281 | rgw_err(); | |
7c673cae FG |
282 | void clear(); |
283 | bool is_clear() const; | |
284 | bool is_err() const; | |
285 | friend std::ostream& operator<<(std::ostream& oss, const rgw_err &err); | |
286 | ||
287 | int http_ret; | |
288 | int ret; | |
31f18b77 | 289 | std::string err_code; |
7c673cae FG |
290 | std::string message; |
291 | }; | |
292 | ||
293 | /* Helper class used for RGWHTTPArgs parsing */ | |
294 | class NameVal | |
295 | { | |
eafe8130 TL |
296 | const std::string str; |
297 | std::string name; | |
298 | std::string val; | |
7c673cae | 299 | public: |
eafe8130 | 300 | explicit NameVal(const std::string& nv) : str(nv) {} |
7c673cae FG |
301 | |
302 | int parse(); | |
303 | ||
eafe8130 TL |
304 | std::string& get_name() { return name; } |
305 | std::string& get_val() { return val; } | |
7c673cae FG |
306 | }; |
307 | ||
308 | /** Stores the XML arguments associated with the HTTP request in req_state*/ | |
1adf2230 | 309 | class RGWHTTPArgs { |
eafe8130 TL |
310 | std::string str, empty_str; |
311 | std::map<std::string, std::string> val_map; | |
312 | std::map<std::string, std::string> sys_val_map; | |
313 | std::map<std::string, std::string> sub_resources; | |
314 | bool has_resp_modifier = false; | |
315 | bool admin_subresource_added = false; | |
7c673cae | 316 | public: |
eafe8130 TL |
317 | RGWHTTPArgs() = default; |
318 | explicit RGWHTTPArgs(const std::string& s) { | |
319 | set(s); | |
320 | parse(); | |
321 | } | |
7c673cae FG |
322 | |
323 | /** Set the arguments; as received */ | |
eafe8130 | 324 | void set(const std::string& s) { |
7c673cae FG |
325 | has_resp_modifier = false; |
326 | val_map.clear(); | |
327 | sub_resources.clear(); | |
328 | str = s; | |
329 | } | |
330 | /** parse the received arguments */ | |
331 | int parse(); | |
eafe8130 | 332 | void append(const std::string& name, const string& val); |
7c673cae | 333 | /** Get the value for a specific argument parameter */ |
eafe8130 | 334 | const string& get(const std::string& name, bool *exists = NULL) const; |
d2e6a577 FG |
335 | boost::optional<const std::string&> |
336 | get_optional(const std::string& name) const; | |
eafe8130 | 337 | int get_bool(const std::string& name, bool *val, bool *exists); |
7c673cae FG |
338 | int get_bool(const char *name, bool *val, bool *exists); |
339 | void get_bool(const char *name, bool *val, bool def_val); | |
11fdf7f2 | 340 | int get_int(const char *name, int *val, int def_val); |
7c673cae FG |
341 | |
342 | /** Get the value for specific system argument parameter */ | |
eafe8130 | 343 | std::string sys_get(const std::string& name, bool *exists = nullptr) const; |
7c673cae FG |
344 | |
345 | /** see if a parameter is contained in this RGWHTTPArgs */ | |
346 | bool exists(const char *name) const { | |
347 | return (val_map.find(name) != std::end(val_map)); | |
348 | } | |
349 | bool sub_resource_exists(const char *name) const { | |
350 | return (sub_resources.find(name) != std::end(sub_resources)); | |
351 | } | |
eafe8130 | 352 | std::map<std::string, std::string>& get_params() { |
7c673cae FG |
353 | return val_map; |
354 | } | |
355 | const std::map<std::string, std::string>& get_sub_resources() const { | |
356 | return sub_resources; | |
357 | } | |
358 | unsigned get_num_params() const { | |
359 | return val_map.size(); | |
360 | } | |
361 | bool has_response_modifier() const { | |
362 | return has_resp_modifier; | |
363 | } | |
364 | void set_system() { /* make all system params visible */ | |
eafe8130 | 365 | std::map<std::string, std::string>::iterator iter; |
7c673cae FG |
366 | for (iter = sys_val_map.begin(); iter != sys_val_map.end(); ++iter) { |
367 | val_map[iter->first] = iter->second; | |
368 | } | |
369 | } | |
eafe8130 | 370 | const std::string& get_str() { |
7c673cae FG |
371 | return str; |
372 | } | |
1adf2230 | 373 | }; // RGWHTTPArgs |
7c673cae | 374 | |
31f18b77 FG |
375 | const char *rgw_conf_get(const map<string, string, ltstr_nocase>& conf_map, const char *name, const char *def_val); |
376 | int rgw_conf_get_int(const map<string, string, ltstr_nocase>& conf_map, const char *name, int def_val); | |
377 | bool rgw_conf_get_bool(const map<string, string, ltstr_nocase>& conf_map, const char *name, bool def_val); | |
378 | ||
7c673cae FG |
379 | class RGWEnv; |
380 | ||
381 | class RGWConf { | |
382 | friend class RGWEnv; | |
11fdf7f2 TL |
383 | int enable_ops_log; |
384 | int enable_usage_log; | |
385 | uint8_t defer_to_bucket_acls; | |
386 | void init(CephContext *cct); | |
7c673cae FG |
387 | public: |
388 | RGWConf() | |
389 | : enable_ops_log(1), | |
390 | enable_usage_log(1), | |
391 | defer_to_bucket_acls(0) { | |
392 | } | |
7c673cae FG |
393 | }; |
394 | ||
395 | class RGWEnv { | |
396 | std::map<string, string, ltstr_nocase> env_map; | |
7c673cae | 397 | RGWConf conf; |
11fdf7f2 | 398 | public: |
7c673cae FG |
399 | void init(CephContext *cct); |
400 | void init(CephContext *cct, char **envp); | |
b32b8144 | 401 | void set(std::string name, std::string val); |
31f18b77 FG |
402 | const char *get(const char *name, const char *def_val = nullptr) const; |
403 | int get_int(const char *name, int def_val = 0) const; | |
7c673cae | 404 | bool get_bool(const char *name, bool def_val = 0); |
31f18b77 FG |
405 | size_t get_size(const char *name, size_t def_val = 0) const; |
406 | bool exists(const char *name) const; | |
407 | bool exists_prefix(const char *prefix) const; | |
7c673cae | 408 | void remove(const char *name); |
31f18b77 | 409 | const std::map<string, string, ltstr_nocase>& get_map() const { return env_map; } |
11fdf7f2 TL |
410 | int get_enable_ops_log() const { |
411 | return conf.enable_ops_log; | |
412 | } | |
413 | ||
414 | int get_enable_usage_log() const { | |
415 | return conf.enable_usage_log; | |
416 | } | |
417 | ||
418 | int get_defer_to_bucket_acls() const { | |
419 | return conf.defer_to_bucket_acls; | |
420 | } | |
7c673cae FG |
421 | }; |
422 | ||
f64942e4 AA |
423 | // return true if the connection is secure. this either means that the |
424 | // connection arrived via ssl, or was forwarded as https by a trusted proxy | |
425 | bool rgw_transport_is_secure(CephContext *cct, const RGWEnv& env); | |
426 | ||
7c673cae FG |
427 | enum http_op { |
428 | OP_GET, | |
429 | OP_PUT, | |
430 | OP_DELETE, | |
431 | OP_HEAD, | |
432 | OP_POST, | |
433 | OP_COPY, | |
434 | OP_OPTIONS, | |
435 | OP_UNKNOWN, | |
436 | }; | |
437 | ||
438 | enum RGWOpType { | |
439 | RGW_OP_UNKNOWN = 0, | |
440 | RGW_OP_GET_OBJ, | |
441 | RGW_OP_LIST_BUCKETS, | |
442 | RGW_OP_STAT_ACCOUNT, | |
443 | RGW_OP_LIST_BUCKET, | |
444 | RGW_OP_GET_BUCKET_LOGGING, | |
3efd9988 | 445 | RGW_OP_GET_BUCKET_LOCATION, |
7c673cae FG |
446 | RGW_OP_GET_BUCKET_VERSIONING, |
447 | RGW_OP_SET_BUCKET_VERSIONING, | |
448 | RGW_OP_GET_BUCKET_WEBSITE, | |
449 | RGW_OP_SET_BUCKET_WEBSITE, | |
450 | RGW_OP_STAT_BUCKET, | |
451 | RGW_OP_CREATE_BUCKET, | |
452 | RGW_OP_DELETE_BUCKET, | |
453 | RGW_OP_PUT_OBJ, | |
454 | RGW_OP_STAT_OBJ, | |
455 | RGW_OP_POST_OBJ, | |
456 | RGW_OP_PUT_METADATA_ACCOUNT, | |
457 | RGW_OP_PUT_METADATA_BUCKET, | |
458 | RGW_OP_PUT_METADATA_OBJECT, | |
459 | RGW_OP_SET_TEMPURL, | |
460 | RGW_OP_DELETE_OBJ, | |
461 | RGW_OP_COPY_OBJ, | |
462 | RGW_OP_GET_ACLS, | |
463 | RGW_OP_PUT_ACLS, | |
464 | RGW_OP_GET_CORS, | |
465 | RGW_OP_PUT_CORS, | |
466 | RGW_OP_DELETE_CORS, | |
467 | RGW_OP_OPTIONS_CORS, | |
468 | RGW_OP_GET_REQUEST_PAYMENT, | |
469 | RGW_OP_SET_REQUEST_PAYMENT, | |
470 | RGW_OP_INIT_MULTIPART, | |
471 | RGW_OP_COMPLETE_MULTIPART, | |
472 | RGW_OP_ABORT_MULTIPART, | |
473 | RGW_OP_LIST_MULTIPART, | |
474 | RGW_OP_LIST_BUCKET_MULTIPARTS, | |
475 | RGW_OP_DELETE_MULTI_OBJ, | |
476 | RGW_OP_BULK_DELETE, | |
477 | RGW_OP_SET_ATTRS, | |
478 | RGW_OP_GET_CROSS_DOMAIN_POLICY, | |
479 | RGW_OP_GET_HEALTH_CHECK, | |
480 | RGW_OP_GET_INFO, | |
481 | RGW_OP_CREATE_ROLE, | |
482 | RGW_OP_DELETE_ROLE, | |
483 | RGW_OP_GET_ROLE, | |
484 | RGW_OP_MODIFY_ROLE, | |
485 | RGW_OP_LIST_ROLES, | |
486 | RGW_OP_PUT_ROLE_POLICY, | |
487 | RGW_OP_GET_ROLE_POLICY, | |
488 | RGW_OP_LIST_ROLE_POLICIES, | |
489 | RGW_OP_DELETE_ROLE_POLICY, | |
31f18b77 FG |
490 | RGW_OP_PUT_BUCKET_POLICY, |
491 | RGW_OP_GET_BUCKET_POLICY, | |
492 | RGW_OP_DELETE_BUCKET_POLICY, | |
224ce89b WB |
493 | RGW_OP_PUT_OBJ_TAGGING, |
494 | RGW_OP_GET_OBJ_TAGGING, | |
495 | RGW_OP_DELETE_OBJ_TAGGING, | |
d2e6a577 FG |
496 | RGW_OP_PUT_LC, |
497 | RGW_OP_GET_LC, | |
498 | RGW_OP_DELETE_LC, | |
11fdf7f2 TL |
499 | RGW_OP_PUT_USER_POLICY, |
500 | RGW_OP_GET_USER_POLICY, | |
501 | RGW_OP_LIST_USER_POLICIES, | |
502 | RGW_OP_DELETE_USER_POLICY, | |
eafe8130 TL |
503 | RGW_OP_PUT_BUCKET_OBJ_LOCK, |
504 | RGW_OP_GET_BUCKET_OBJ_LOCK, | |
505 | RGW_OP_PUT_OBJ_RETENTION, | |
506 | RGW_OP_GET_OBJ_RETENTION, | |
507 | RGW_OP_PUT_OBJ_LEGAL_HOLD, | |
508 | RGW_OP_GET_OBJ_LEGAL_HOLD, | |
7c673cae FG |
509 | /* rgw specific */ |
510 | RGW_OP_ADMIN_SET_METADATA, | |
511 | RGW_OP_GET_OBJ_LAYOUT, | |
31f18b77 FG |
512 | RGW_OP_BULK_UPLOAD, |
513 | RGW_OP_METADATA_SEARCH, | |
514 | RGW_OP_CONFIG_BUCKET_META_SEARCH, | |
515 | RGW_OP_GET_BUCKET_META_SEARCH, | |
516 | RGW_OP_DEL_BUCKET_META_SEARCH, | |
11fdf7f2 TL |
517 | /* sts specific*/ |
518 | RGW_STS_ASSUME_ROLE, | |
519 | RGW_STS_GET_SESSION_TOKEN, | |
520 | RGW_STS_ASSUME_ROLE_WEB_IDENTITY, | |
521 | /* pubsub */ | |
522 | RGW_OP_PUBSUB_TOPIC_CREATE, | |
523 | RGW_OP_PUBSUB_TOPICS_LIST, | |
524 | RGW_OP_PUBSUB_TOPIC_GET, | |
525 | RGW_OP_PUBSUB_TOPIC_DELETE, | |
526 | RGW_OP_PUBSUB_SUB_CREATE, | |
527 | RGW_OP_PUBSUB_SUB_GET, | |
528 | RGW_OP_PUBSUB_SUB_DELETE, | |
529 | RGW_OP_PUBSUB_SUB_PULL, | |
530 | RGW_OP_PUBSUB_SUB_ACK, | |
531 | RGW_OP_PUBSUB_NOTIF_CREATE, | |
532 | RGW_OP_PUBSUB_NOTIF_DELETE, | |
533 | RGW_OP_PUBSUB_NOTIF_LIST, | |
9f95a23c TL |
534 | RGW_OP_GET_BUCKET_TAGGING, |
535 | RGW_OP_PUT_BUCKET_TAGGING, | |
536 | RGW_OP_DELETE_BUCKET_TAGGING, | |
537 | RGW_OP_GET_BUCKET_REPLICATION, | |
538 | RGW_OP_PUT_BUCKET_REPLICATION, | |
539 | RGW_OP_DELETE_BUCKET_REPLICATION, | |
540 | ||
541 | /* public access */ | |
542 | RGW_OP_GET_BUCKET_POLICY_STATUS, | |
543 | RGW_OP_PUT_BUCKET_PUBLIC_ACCESS_BLOCK, | |
544 | RGW_OP_GET_BUCKET_PUBLIC_ACCESS_BLOCK, | |
545 | RGW_OP_DELETE_BUCKET_PUBLIC_ACCESS_BLOCK, | |
f91f0fd5 TL |
546 | |
547 | /*OIDC provider specific*/ | |
548 | RGW_OP_CREATE_OIDC_PROVIDER, | |
549 | RGW_OP_DELETE_OIDC_PROVIDER, | |
550 | RGW_OP_GET_OIDC_PROVIDER, | |
551 | RGW_OP_LIST_OIDC_PROVIDERS, | |
7c673cae FG |
552 | }; |
553 | ||
554 | class RGWAccessControlPolicy; | |
555 | class JSONObj; | |
556 | ||
557 | struct RGWAccessKey { | |
558 | string id; // AccessKey | |
559 | string key; // SecretKey | |
560 | string subuser; | |
561 | ||
562 | RGWAccessKey() {} | |
563 | RGWAccessKey(std::string _id, std::string _key) | |
564 | : id(std::move(_id)), key(std::move(_key)) {} | |
565 | ||
566 | void encode(bufferlist& bl) const { | |
567 | ENCODE_START(2, 2, bl); | |
11fdf7f2 TL |
568 | encode(id, bl); |
569 | encode(key, bl); | |
570 | encode(subuser, bl); | |
7c673cae FG |
571 | ENCODE_FINISH(bl); |
572 | } | |
573 | ||
11fdf7f2 | 574 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 575 | DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); |
11fdf7f2 TL |
576 | decode(id, bl); |
577 | decode(key, bl); | |
578 | decode(subuser, bl); | |
7c673cae FG |
579 | DECODE_FINISH(bl); |
580 | } | |
581 | void dump(Formatter *f) const; | |
582 | void dump_plain(Formatter *f) const; | |
583 | void dump(Formatter *f, const string& user, bool swift) const; | |
584 | static void generate_test_instances(list<RGWAccessKey*>& o); | |
585 | ||
586 | void decode_json(JSONObj *obj); | |
587 | void decode_json(JSONObj *obj, bool swift); | |
588 | }; | |
589 | WRITE_CLASS_ENCODER(RGWAccessKey) | |
590 | ||
591 | struct RGWSubUser { | |
592 | string name; | |
593 | uint32_t perm_mask; | |
594 | ||
595 | RGWSubUser() : perm_mask(0) {} | |
596 | void encode(bufferlist& bl) const { | |
597 | ENCODE_START(2, 2, bl); | |
11fdf7f2 TL |
598 | encode(name, bl); |
599 | encode(perm_mask, bl); | |
7c673cae FG |
600 | ENCODE_FINISH(bl); |
601 | } | |
602 | ||
11fdf7f2 | 603 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 604 | DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); |
11fdf7f2 TL |
605 | decode(name, bl); |
606 | decode(perm_mask, bl); | |
7c673cae FG |
607 | DECODE_FINISH(bl); |
608 | } | |
609 | void dump(Formatter *f) const; | |
610 | void dump(Formatter *f, const string& user) const; | |
611 | static void generate_test_instances(list<RGWSubUser*>& o); | |
612 | ||
613 | void decode_json(JSONObj *obj); | |
614 | }; | |
615 | WRITE_CLASS_ENCODER(RGWSubUser) | |
616 | ||
617 | class RGWUserCaps | |
618 | { | |
619 | map<string, uint32_t> caps; | |
620 | ||
621 | int get_cap(const string& cap, string& type, uint32_t *perm); | |
622 | int add_cap(const string& cap); | |
623 | int remove_cap(const string& cap); | |
624 | public: | |
625 | static int parse_cap_perm(const string& str, uint32_t *perm); | |
626 | int add_from_string(const string& str); | |
627 | int remove_from_string(const string& str); | |
628 | ||
629 | void encode(bufferlist& bl) const { | |
630 | ENCODE_START(1, 1, bl); | |
11fdf7f2 | 631 | encode(caps, bl); |
7c673cae FG |
632 | ENCODE_FINISH(bl); |
633 | } | |
11fdf7f2 | 634 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 635 | DECODE_START(1, bl); |
11fdf7f2 | 636 | decode(caps, bl); |
7c673cae FG |
637 | DECODE_FINISH(bl); |
638 | } | |
9f95a23c | 639 | int check_cap(const string& cap, uint32_t perm) const; |
7c673cae FG |
640 | bool is_valid_cap_type(const string& tp); |
641 | void dump(Formatter *f) const; | |
642 | void dump(Formatter *f, const char *name) const; | |
643 | ||
644 | void decode_json(JSONObj *obj); | |
645 | }; | |
646 | WRITE_CLASS_ENCODER(RGWUserCaps) | |
647 | ||
648 | void encode_json(const char *name, const obj_version& v, Formatter *f); | |
649 | void encode_json(const char *name, const RGWUserCaps& val, Formatter *f); | |
650 | ||
651 | void decode_json_obj(obj_version& v, JSONObj *obj); | |
652 | ||
11fdf7f2 TL |
653 | |
654 | ||
655 | enum RGWIdentityType | |
7c673cae FG |
656 | { |
657 | TYPE_NONE=0, | |
658 | TYPE_RGW=1, | |
659 | TYPE_KEYSTONE=2, | |
11fdf7f2 TL |
660 | TYPE_LDAP=3, |
661 | TYPE_ROLE=4, | |
662 | TYPE_WEB=5, | |
663 | }; | |
664 | ||
665 | static string RGW_STORAGE_CLASS_STANDARD = "STANDARD"; | |
666 | ||
667 | struct rgw_placement_rule { | |
668 | std::string name; | |
669 | std::string storage_class; | |
670 | ||
671 | rgw_placement_rule() {} | |
672 | rgw_placement_rule(const string& _n, const string& _sc) : name(_n), storage_class(_sc) {} | |
673 | rgw_placement_rule(const rgw_placement_rule& _r, const string& _sc) : name(_r.name) { | |
674 | if (!_sc.empty()) { | |
675 | storage_class = _sc; | |
676 | } else { | |
677 | storage_class = _r.storage_class; | |
678 | } | |
679 | } | |
680 | ||
681 | bool empty() const { | |
682 | return name.empty() && storage_class.empty(); | |
683 | } | |
684 | ||
685 | void inherit_from(const rgw_placement_rule& r) { | |
686 | if (name.empty()) { | |
687 | name = r.name; | |
688 | } | |
689 | if (storage_class.empty()) { | |
690 | storage_class = r.storage_class; | |
691 | } | |
692 | } | |
693 | ||
694 | void clear() { | |
695 | name.clear(); | |
696 | storage_class.clear(); | |
697 | } | |
698 | ||
699 | void init(const string& n, const string& c) { | |
700 | name = n; | |
701 | storage_class = c; | |
702 | } | |
703 | ||
704 | static const string& get_canonical_storage_class(const string& storage_class) { | |
705 | if (storage_class.empty()) { | |
706 | return RGW_STORAGE_CLASS_STANDARD; | |
707 | } | |
708 | return storage_class; | |
709 | } | |
710 | ||
711 | const string& get_storage_class() const { | |
712 | return get_canonical_storage_class(storage_class); | |
713 | } | |
714 | ||
715 | int compare(const rgw_placement_rule& r) const { | |
716 | int c = name.compare(r.name); | |
717 | if (c != 0) { | |
718 | return c; | |
719 | } | |
720 | return get_storage_class().compare(r.get_storage_class()); | |
721 | } | |
722 | ||
723 | bool operator==(const rgw_placement_rule& r) const { | |
724 | return (name == r.name && | |
725 | get_storage_class() == r.get_storage_class()); | |
726 | } | |
727 | ||
728 | bool operator!=(const rgw_placement_rule& r) const { | |
729 | return !(*this == r); | |
730 | } | |
731 | ||
732 | void encode(bufferlist& bl) const { | |
733 | /* no ENCODE_START/END due to backward compatibility */ | |
81eedcae | 734 | std::string s = to_str(); |
11fdf7f2 TL |
735 | ceph::encode(s, bl); |
736 | } | |
737 | ||
738 | void decode(bufferlist::const_iterator& bl) { | |
739 | std::string s; | |
740 | ceph::decode(s, bl); | |
741 | from_str(s); | |
742 | } | |
743 | ||
744 | std::string to_str() const { | |
745 | if (standard_storage_class()) { | |
746 | return name; | |
747 | } | |
748 | return to_str_explicit(); | |
749 | } | |
750 | ||
751 | std::string to_str_explicit() const { | |
752 | return name + "/" + storage_class; | |
753 | } | |
754 | ||
755 | void from_str(const std::string& s) { | |
756 | size_t pos = s.find("/"); | |
757 | if (pos == std::string::npos) { | |
758 | name = s; | |
81eedcae | 759 | storage_class.clear(); |
11fdf7f2 TL |
760 | return; |
761 | } | |
762 | name = s.substr(0, pos); | |
81eedcae | 763 | storage_class = s.substr(pos + 1); |
11fdf7f2 TL |
764 | } |
765 | ||
766 | bool standard_storage_class() const { | |
767 | return storage_class.empty() || storage_class == RGW_STORAGE_CLASS_STANDARD; | |
768 | } | |
7c673cae | 769 | }; |
11fdf7f2 TL |
770 | WRITE_CLASS_ENCODER(rgw_placement_rule) |
771 | ||
772 | void encode_json(const char *name, const rgw_placement_rule& val, ceph::Formatter *f); | |
773 | void decode_json_obj(rgw_placement_rule& v, JSONObj *obj); | |
7c673cae | 774 | |
11fdf7f2 TL |
775 | inline ostream& operator<<(ostream& out, const rgw_placement_rule& rule) { |
776 | return out << rule.to_str(); | |
777 | } | |
7c673cae FG |
778 | struct RGWUserInfo |
779 | { | |
7c673cae FG |
780 | rgw_user user_id; |
781 | string display_name; | |
782 | string user_email; | |
783 | map<string, RGWAccessKey> access_keys; | |
784 | map<string, RGWAccessKey> swift_keys; | |
785 | map<string, RGWSubUser> subusers; | |
786 | __u8 suspended; | |
787 | int32_t max_buckets; | |
788 | uint32_t op_mask; | |
789 | RGWUserCaps caps; | |
790 | __u8 admin; | |
791 | __u8 system; | |
11fdf7f2 | 792 | rgw_placement_rule default_placement; |
7c673cae FG |
793 | list<string> placement_tags; |
794 | RGWQuotaInfo bucket_quota; | |
795 | map<int, string> temp_url_keys; | |
796 | RGWQuotaInfo user_quota; | |
797 | uint32_t type; | |
11fdf7f2 TL |
798 | set<string> mfa_ids; |
799 | string assumed_role_arn; | |
7c673cae FG |
800 | |
801 | RGWUserInfo() | |
11fdf7f2 | 802 | : suspended(0), |
7c673cae FG |
803 | max_buckets(RGW_DEFAULT_MAX_BUCKETS), |
804 | op_mask(RGW_OP_TYPE_ALL), | |
805 | admin(0), | |
806 | system(0), | |
807 | type(TYPE_NONE) { | |
808 | } | |
809 | ||
a8e16298 | 810 | RGWAccessKey* get_key(const string& access_key) { |
7c673cae FG |
811 | if (access_keys.empty()) |
812 | return nullptr; | |
a8e16298 TL |
813 | |
814 | auto k = access_keys.find(access_key); | |
815 | if (k == access_keys.end()) | |
816 | return nullptr; | |
7c673cae | 817 | else |
a8e16298 | 818 | return &(k->second); |
7c673cae FG |
819 | } |
820 | ||
821 | void encode(bufferlist& bl) const { | |
11fdf7f2 TL |
822 | ENCODE_START(21, 9, bl); |
823 | encode((uint64_t)0, bl); // old auid | |
7c673cae FG |
824 | string access_key; |
825 | string secret_key; | |
826 | if (!access_keys.empty()) { | |
827 | map<string, RGWAccessKey>::const_iterator iter = access_keys.begin(); | |
828 | const RGWAccessKey& k = iter->second; | |
829 | access_key = k.id; | |
830 | secret_key = k.key; | |
831 | } | |
11fdf7f2 TL |
832 | encode(access_key, bl); |
833 | encode(secret_key, bl); | |
834 | encode(display_name, bl); | |
835 | encode(user_email, bl); | |
7c673cae FG |
836 | string swift_name; |
837 | string swift_key; | |
838 | if (!swift_keys.empty()) { | |
839 | map<string, RGWAccessKey>::const_iterator iter = swift_keys.begin(); | |
840 | const RGWAccessKey& k = iter->second; | |
841 | swift_name = k.id; | |
842 | swift_key = k.key; | |
843 | } | |
11fdf7f2 TL |
844 | encode(swift_name, bl); |
845 | encode(swift_key, bl); | |
846 | encode(user_id.id, bl); | |
847 | encode(access_keys, bl); | |
848 | encode(subusers, bl); | |
849 | encode(suspended, bl); | |
850 | encode(swift_keys, bl); | |
851 | encode(max_buckets, bl); | |
852 | encode(caps, bl); | |
853 | encode(op_mask, bl); | |
854 | encode(system, bl); | |
855 | encode(default_placement, bl); | |
856 | encode(placement_tags, bl); | |
857 | encode(bucket_quota, bl); | |
858 | encode(temp_url_keys, bl); | |
859 | encode(user_quota, bl); | |
860 | encode(user_id.tenant, bl); | |
861 | encode(admin, bl); | |
862 | encode(type, bl); | |
863 | encode(mfa_ids, bl); | |
864 | encode(assumed_role_arn, bl); | |
7c673cae FG |
865 | ENCODE_FINISH(bl); |
866 | } | |
11fdf7f2 | 867 | void decode(bufferlist::const_iterator& bl) { |
9f95a23c | 868 | DECODE_START_LEGACY_COMPAT_LEN_32(21, 9, 9, bl); |
11fdf7f2 TL |
869 | if (struct_v >= 2) { |
870 | uint64_t old_auid; | |
871 | decode(old_auid, bl); | |
872 | } | |
7c673cae FG |
873 | string access_key; |
874 | string secret_key; | |
11fdf7f2 TL |
875 | decode(access_key, bl); |
876 | decode(secret_key, bl); | |
7c673cae FG |
877 | if (struct_v < 6) { |
878 | RGWAccessKey k; | |
879 | k.id = access_key; | |
880 | k.key = secret_key; | |
881 | access_keys[access_key] = k; | |
882 | } | |
11fdf7f2 TL |
883 | decode(display_name, bl); |
884 | decode(user_email, bl); | |
7c673cae FG |
885 | /* We populate swift_keys map later nowadays, but we have to decode. */ |
886 | string swift_name; | |
887 | string swift_key; | |
11fdf7f2 TL |
888 | if (struct_v >= 3) decode(swift_name, bl); |
889 | if (struct_v >= 4) decode(swift_key, bl); | |
7c673cae | 890 | if (struct_v >= 5) |
11fdf7f2 | 891 | decode(user_id.id, bl); |
7c673cae FG |
892 | else |
893 | user_id.id = access_key; | |
894 | if (struct_v >= 6) { | |
11fdf7f2 TL |
895 | decode(access_keys, bl); |
896 | decode(subusers, bl); | |
7c673cae FG |
897 | } |
898 | suspended = 0; | |
899 | if (struct_v >= 7) { | |
11fdf7f2 | 900 | decode(suspended, bl); |
7c673cae FG |
901 | } |
902 | if (struct_v >= 8) { | |
11fdf7f2 | 903 | decode(swift_keys, bl); |
7c673cae FG |
904 | } |
905 | if (struct_v >= 10) { | |
11fdf7f2 | 906 | decode(max_buckets, bl); |
7c673cae FG |
907 | } else { |
908 | max_buckets = RGW_DEFAULT_MAX_BUCKETS; | |
909 | } | |
910 | if (struct_v >= 11) { | |
11fdf7f2 | 911 | decode(caps, bl); |
7c673cae FG |
912 | } |
913 | if (struct_v >= 12) { | |
11fdf7f2 | 914 | decode(op_mask, bl); |
7c673cae FG |
915 | } else { |
916 | op_mask = RGW_OP_TYPE_ALL; | |
917 | } | |
918 | if (struct_v >= 13) { | |
11fdf7f2 TL |
919 | decode(system, bl); |
920 | decode(default_placement, bl); | |
921 | decode(placement_tags, bl); /* tags of allowed placement rules */ | |
7c673cae FG |
922 | } |
923 | if (struct_v >= 14) { | |
11fdf7f2 | 924 | decode(bucket_quota, bl); |
7c673cae FG |
925 | } |
926 | if (struct_v >= 15) { | |
11fdf7f2 | 927 | decode(temp_url_keys, bl); |
7c673cae FG |
928 | } |
929 | if (struct_v >= 16) { | |
11fdf7f2 | 930 | decode(user_quota, bl); |
7c673cae FG |
931 | } |
932 | if (struct_v >= 17) { | |
11fdf7f2 | 933 | decode(user_id.tenant, bl); |
7c673cae FG |
934 | } else { |
935 | user_id.tenant.clear(); | |
936 | } | |
937 | if (struct_v >= 18) { | |
11fdf7f2 | 938 | decode(admin, bl); |
7c673cae FG |
939 | } |
940 | if (struct_v >= 19) { | |
11fdf7f2 TL |
941 | decode(type, bl); |
942 | } | |
943 | if (struct_v >= 20) { | |
944 | decode(mfa_ids, bl); | |
945 | } | |
946 | if (struct_v >= 21) { | |
947 | decode(assumed_role_arn, bl); | |
7c673cae FG |
948 | } |
949 | DECODE_FINISH(bl); | |
950 | } | |
951 | void dump(Formatter *f) const; | |
952 | static void generate_test_instances(list<RGWUserInfo*>& o); | |
953 | ||
954 | void decode_json(JSONObj *obj); | |
955 | }; | |
956 | WRITE_CLASS_ENCODER(RGWUserInfo) | |
957 | ||
7c673cae FG |
958 | struct rgw_raw_obj { |
959 | rgw_pool pool; | |
960 | std::string oid; | |
961 | std::string loc; | |
962 | ||
963 | rgw_raw_obj() {} | |
964 | rgw_raw_obj(const rgw_pool& _pool, const std::string& _oid) { | |
965 | init(_pool, _oid); | |
966 | } | |
967 | rgw_raw_obj(const rgw_pool& _pool, const std::string& _oid, const string& _loc) : loc(_loc) { | |
968 | init(_pool, _oid); | |
969 | } | |
970 | ||
971 | void init(const rgw_pool& _pool, const std::string& _oid) { | |
972 | pool = _pool; | |
973 | oid = _oid; | |
974 | } | |
975 | ||
976 | bool empty() const { | |
977 | return oid.empty(); | |
978 | } | |
979 | ||
980 | void encode(bufferlist& bl) const { | |
981 | ENCODE_START(6, 6, bl); | |
11fdf7f2 TL |
982 | encode(pool, bl); |
983 | encode(oid, bl); | |
984 | encode(loc, bl); | |
7c673cae FG |
985 | ENCODE_FINISH(bl); |
986 | } | |
987 | ||
11fdf7f2 | 988 | void decode_from_rgw_obj(bufferlist::const_iterator& bl); |
7c673cae | 989 | |
11fdf7f2 | 990 | void decode(bufferlist::const_iterator& bl) { |
7c673cae FG |
991 | unsigned ofs = bl.get_off(); |
992 | DECODE_START(6, bl); | |
993 | if (struct_v < 6) { | |
994 | /* | |
995 | * this object was encoded as rgw_obj, prior to rgw_raw_obj been split out of it, | |
996 | * let's decode it as rgw_obj and convert it | |
997 | */ | |
998 | bl.seek(ofs); | |
999 | decode_from_rgw_obj(bl); | |
1000 | return; | |
1001 | } | |
11fdf7f2 TL |
1002 | decode(pool, bl); |
1003 | decode(oid, bl); | |
1004 | decode(loc, bl); | |
7c673cae FG |
1005 | DECODE_FINISH(bl); |
1006 | } | |
1007 | ||
1008 | bool operator<(const rgw_raw_obj& o) const { | |
1009 | int r = pool.compare(o.pool); | |
1010 | if (r == 0) { | |
1011 | r = oid.compare(o.oid); | |
1012 | if (r == 0) { | |
1013 | r = loc.compare(o.loc); | |
1014 | } | |
1015 | } | |
1016 | return (r < 0); | |
1017 | } | |
1018 | ||
1019 | bool operator==(const rgw_raw_obj& o) const { | |
1020 | return (pool == o.pool && oid == o.oid && loc == o.loc); | |
1021 | } | |
1022 | ||
1023 | void dump(Formatter *f) const; | |
1024 | void decode_json(JSONObj *obj); | |
1025 | }; | |
1026 | WRITE_CLASS_ENCODER(rgw_raw_obj) | |
1027 | ||
1028 | inline ostream& operator<<(ostream& out, const rgw_raw_obj& o) { | |
1029 | out << o.pool << ":" << o.oid; | |
1030 | return out; | |
1031 | } | |
1032 | ||
9f95a23c TL |
1033 | struct rgw_bucket_placement { |
1034 | rgw_placement_rule placement_rule; | |
7c673cae | 1035 | rgw_bucket bucket; |
7c673cae | 1036 | |
9f95a23c | 1037 | void dump(Formatter *f) const; |
7c673cae FG |
1038 | }; |
1039 | ||
7c673cae FG |
1040 | struct RGWObjVersionTracker { |
1041 | obj_version read_version; | |
1042 | obj_version write_version; | |
1043 | ||
1044 | obj_version *version_for_read() { | |
1045 | return &read_version; | |
1046 | } | |
1047 | ||
1048 | obj_version *version_for_write() { | |
1049 | if (write_version.ver == 0) | |
1050 | return NULL; | |
1051 | ||
1052 | return &write_version; | |
1053 | } | |
1054 | ||
1055 | obj_version *version_for_check() { | |
1056 | if (read_version.ver == 0) | |
1057 | return NULL; | |
1058 | ||
1059 | return &read_version; | |
1060 | } | |
1061 | ||
1062 | void prepare_op_for_read(librados::ObjectReadOperation *op); | |
1063 | void prepare_op_for_write(librados::ObjectWriteOperation *op); | |
1064 | ||
f91f0fd5 | 1065 | void apply_write(); |
7c673cae FG |
1066 | |
1067 | void clear() { | |
1068 | read_version = obj_version(); | |
1069 | write_version = obj_version(); | |
1070 | } | |
1071 | ||
1072 | void generate_new_write_ver(CephContext *cct); | |
1073 | }; | |
1074 | ||
11fdf7f2 TL |
1075 | inline ostream& operator<<(ostream& out, const obj_version &v) |
1076 | { | |
1077 | out << v.tag << ":" << v.ver; | |
1078 | return out; | |
1079 | } | |
1080 | ||
1081 | inline ostream& operator<<(ostream& out, const RGWObjVersionTracker &ot) | |
1082 | { | |
1083 | out << "{r=" << ot.read_version << ",w=" << ot.write_version << "}"; | |
1084 | return out; | |
1085 | } | |
1086 | ||
7c673cae FG |
1087 | enum RGWBucketFlags { |
1088 | BUCKET_SUSPENDED = 0x1, | |
1089 | BUCKET_VERSIONED = 0x2, | |
1090 | BUCKET_VERSIONS_SUSPENDED = 0x4, | |
c07f9fc5 | 1091 | BUCKET_DATASYNC_DISABLED = 0X8, |
11fdf7f2 | 1092 | BUCKET_MFA_ENABLED = 0X10, |
eafe8130 | 1093 | BUCKET_OBJ_LOCK_ENABLED = 0X20, |
7c673cae FG |
1094 | }; |
1095 | ||
1096 | enum RGWBucketIndexType { | |
1097 | RGWBIType_Normal = 0, | |
1098 | RGWBIType_Indexless = 1, | |
1099 | }; | |
1100 | ||
1101 | inline ostream& operator<<(ostream& out, const RGWBucketIndexType &index_type) | |
1102 | { | |
1103 | switch (index_type) { | |
1104 | case RGWBIType_Normal: | |
1105 | return out << "Normal"; | |
1106 | case RGWBIType_Indexless: | |
1107 | return out << "Indexless"; | |
1108 | default: | |
1109 | return out << "Unknown"; | |
1110 | } | |
1111 | } | |
1112 | ||
9f95a23c TL |
1113 | class RGWSI_Zone; |
1114 | ||
1adf2230 | 1115 | struct RGWBucketInfo { |
7c673cae FG |
1116 | enum BIShardsHashType { |
1117 | MOD = 0 | |
1118 | }; | |
1119 | ||
1120 | rgw_bucket bucket; | |
1121 | rgw_user owner; | |
9f95a23c | 1122 | uint32_t flags{0}; |
7c673cae FG |
1123 | string zonegroup; |
1124 | ceph::real_time creation_time; | |
11fdf7f2 | 1125 | rgw_placement_rule placement_rule; |
9f95a23c | 1126 | bool has_instance_obj{false}; |
7c673cae | 1127 | RGWObjVersionTracker objv_tracker; /* we don't need to serialize this, for runtime tracking */ |
7c673cae FG |
1128 | RGWQuotaInfo quota; |
1129 | ||
1130 | // Represents the number of bucket index object shards: | |
9f95a23c TL |
1131 | // - value of 0 indicates there is no sharding (this is by default |
1132 | // before this feature is implemented). | |
7c673cae | 1133 | // - value of UINT32_T::MAX indicates this is a blind bucket. |
9f95a23c | 1134 | uint32_t num_shards{0}; |
7c673cae FG |
1135 | |
1136 | // Represents the bucket index shard hash type. | |
9f95a23c | 1137 | uint8_t bucket_index_shard_hash_type{MOD}; |
7c673cae FG |
1138 | |
1139 | // Represents the shard number for blind bucket. | |
1140 | const static uint32_t NUM_SHARDS_BLIND_BUCKET; | |
1141 | ||
9f95a23c | 1142 | bool requester_pays{false}; |
7c673cae | 1143 | |
9f95a23c | 1144 | bool has_website{false}; |
7c673cae FG |
1145 | RGWBucketWebsiteConf website_conf; |
1146 | ||
11fdf7f2 | 1147 | RGWBucketIndexType index_type = RGWBIType_Normal; |
7c673cae | 1148 | |
9f95a23c | 1149 | bool swift_versioning{false}; |
7c673cae FG |
1150 | string swift_ver_location; |
1151 | ||
31f18b77 FG |
1152 | map<string, uint32_t> mdsearch_config; |
1153 | ||
9f95a23c TL |
1154 | // resharding |
1155 | cls_rgw_reshard_status reshard_status{cls_rgw_reshard_status::NOT_RESHARDING}; | |
31f18b77 | 1156 | string new_bucket_instance_id; |
7c673cae | 1157 | |
eafe8130 TL |
1158 | RGWObjectLock obj_lock; |
1159 | ||
9f95a23c TL |
1160 | std::optional<rgw_sync_policy_info> sync_policy; |
1161 | ||
1162 | void encode(bufferlist& bl) const; | |
1163 | void decode(bufferlist::const_iterator& bl); | |
1164 | ||
7c673cae FG |
1165 | void dump(Formatter *f) const; |
1166 | static void generate_test_instances(list<RGWBucketInfo*>& o); | |
1167 | ||
1168 | void decode_json(JSONObj *obj); | |
1169 | ||
1170 | bool versioned() const { return (flags & BUCKET_VERSIONED) != 0; } | |
11fdf7f2 TL |
1171 | int versioning_status() const { return flags & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED | BUCKET_MFA_ENABLED); } |
1172 | bool versioning_enabled() const { return (versioning_status() & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED)) == BUCKET_VERSIONED; } | |
1173 | bool mfa_enabled() const { return (versioning_status() & BUCKET_MFA_ENABLED) != 0; } | |
c07f9fc5 | 1174 | bool datasync_flag_enabled() const { return (flags & BUCKET_DATASYNC_DISABLED) == 0; } |
eafe8130 | 1175 | bool obj_lock_enabled() const { return (flags & BUCKET_OBJ_LOCK_ENABLED) != 0; } |
7c673cae FG |
1176 | |
1177 | bool has_swift_versioning() const { | |
1178 | /* A bucket may be versioned through one mechanism only. */ | |
1179 | return swift_versioning && !versioned(); | |
1180 | } | |
1181 | ||
9f95a23c TL |
1182 | void set_sync_policy(rgw_sync_policy_info&& policy); |
1183 | ||
1184 | bool empty_sync_policy() const; | |
1185 | ||
1186 | RGWBucketInfo(); | |
1187 | ~RGWBucketInfo(); | |
7c673cae FG |
1188 | }; |
1189 | WRITE_CLASS_ENCODER(RGWBucketInfo) | |
1190 | ||
1191 | struct RGWBucketEntryPoint | |
1192 | { | |
1193 | rgw_bucket bucket; | |
1194 | rgw_user owner; | |
1195 | ceph::real_time creation_time; | |
1196 | bool linked; | |
1197 | ||
1198 | bool has_bucket_info; | |
1199 | RGWBucketInfo old_bucket_info; | |
1200 | ||
1201 | RGWBucketEntryPoint() : linked(false), has_bucket_info(false) {} | |
1202 | ||
1203 | void encode(bufferlist& bl) const { | |
1204 | ENCODE_START(10, 8, bl); | |
11fdf7f2 TL |
1205 | encode(bucket, bl); |
1206 | encode(owner.id, bl); | |
1207 | encode(linked, bl); | |
7c673cae | 1208 | uint64_t ctime = (uint64_t)real_clock::to_time_t(creation_time); |
11fdf7f2 TL |
1209 | encode(ctime, bl); |
1210 | encode(owner, bl); | |
1211 | encode(creation_time, bl); | |
7c673cae FG |
1212 | ENCODE_FINISH(bl); |
1213 | } | |
11fdf7f2 TL |
1214 | void decode(bufferlist::const_iterator& bl) { |
1215 | auto orig_iter = bl; | |
7c673cae FG |
1216 | DECODE_START_LEGACY_COMPAT_LEN_32(10, 4, 4, bl); |
1217 | if (struct_v < 8) { | |
1218 | /* ouch, old entry, contains the bucket info itself */ | |
1219 | old_bucket_info.decode(orig_iter); | |
1220 | has_bucket_info = true; | |
1221 | return; | |
1222 | } | |
1223 | has_bucket_info = false; | |
11fdf7f2 TL |
1224 | decode(bucket, bl); |
1225 | decode(owner.id, bl); | |
1226 | decode(linked, bl); | |
7c673cae | 1227 | uint64_t ctime; |
11fdf7f2 | 1228 | decode(ctime, bl); |
7c673cae FG |
1229 | if (struct_v < 10) { |
1230 | creation_time = real_clock::from_time_t((time_t)ctime); | |
1231 | } | |
1232 | if (struct_v >= 9) { | |
11fdf7f2 | 1233 | decode(owner, bl); |
7c673cae FG |
1234 | } |
1235 | if (struct_v >= 10) { | |
11fdf7f2 | 1236 | decode(creation_time, bl); |
7c673cae FG |
1237 | } |
1238 | DECODE_FINISH(bl); | |
1239 | } | |
1240 | ||
1241 | void dump(Formatter *f) const; | |
1242 | void decode_json(JSONObj *obj); | |
9f95a23c | 1243 | static void generate_test_instances(list<RGWBucketEntryPoint*>& o); |
7c673cae FG |
1244 | }; |
1245 | WRITE_CLASS_ENCODER(RGWBucketEntryPoint) | |
1246 | ||
1247 | struct RGWStorageStats | |
1248 | { | |
1249 | RGWObjCategory category; | |
1250 | uint64_t size; | |
1251 | uint64_t size_rounded; | |
1252 | uint64_t size_utilized{0}; //< size after compression, encryption | |
1253 | uint64_t num_objects; | |
1254 | ||
1255 | RGWStorageStats() | |
11fdf7f2 | 1256 | : category(RGWObjCategory::None), |
7c673cae FG |
1257 | size(0), |
1258 | size_rounded(0), | |
1259 | num_objects(0) {} | |
1260 | ||
1261 | void dump(Formatter *f) const; | |
1262 | }; | |
1263 | ||
7c673cae FG |
1264 | class RGWEnv; |
1265 | ||
1266 | /* Namespaced forward declarations. */ | |
1267 | namespace rgw { | |
1268 | namespace auth { | |
1269 | namespace s3 { | |
31f18b77 | 1270 | class AWSBrowserUploadAbstractor; |
9f95a23c | 1271 | class STSEngine; |
7c673cae | 1272 | } |
31f18b77 | 1273 | class Completer; |
7c673cae FG |
1274 | } |
1275 | namespace io { | |
1276 | class BasicClient; | |
1277 | } | |
1278 | } | |
1279 | ||
9f95a23c | 1280 | using meta_map_t = boost::container::flat_map <std::string, std::string>; |
31f18b77 | 1281 | |
7c673cae | 1282 | struct req_info { |
31f18b77 | 1283 | const RGWEnv *env; |
7c673cae | 1284 | RGWHTTPArgs args; |
9f95a23c | 1285 | meta_map_t x_meta_map; |
7c673cae FG |
1286 | |
1287 | string host; | |
1288 | const char *method; | |
1289 | string script_uri; | |
1290 | string request_uri; | |
1291 | string request_uri_aws4; | |
1292 | string effective_uri; | |
1293 | string request_params; | |
1294 | string domain; | |
11fdf7f2 | 1295 | string storage_class; |
7c673cae | 1296 | |
31f18b77 | 1297 | req_info(CephContext *cct, const RGWEnv *env); |
7c673cae FG |
1298 | void rebuild_from(req_info& src); |
1299 | void init_meta_info(bool *found_bad_meta); | |
1300 | }; | |
1301 | ||
1302 | typedef cls_rgw_obj_key rgw_obj_index_key; | |
1303 | ||
1304 | struct rgw_obj_key { | |
1305 | string name; | |
1306 | string instance; | |
1307 | string ns; | |
1308 | ||
1309 | rgw_obj_key() {} | |
1310 | // cppcheck-suppress noExplicitConstructor | |
1311 | rgw_obj_key(const string& n) : name(n) {} | |
1312 | rgw_obj_key(const string& n, const string& i) : name(n), instance(i) {} | |
1313 | rgw_obj_key(const string& n, const string& i, const string& _ns) : name(n), instance(i), ns(_ns) {} | |
1314 | ||
1315 | rgw_obj_key(const rgw_obj_index_key& k) { | |
1316 | parse_index_key(k.name, &name, &ns); | |
1317 | instance = k.instance; | |
1318 | } | |
1319 | ||
1320 | static void parse_index_key(const string& key, string *name, string *ns) { | |
1321 | if (key[0] != '_') { | |
1322 | *name = key; | |
1323 | ns->clear(); | |
1324 | return; | |
1325 | } | |
1326 | if (key[1] == '_') { | |
1327 | *name = key.substr(1); | |
1328 | ns->clear(); | |
1329 | return; | |
1330 | } | |
1331 | ssize_t pos = key.find('_', 1); | |
1332 | if (pos < 0) { | |
1333 | /* shouldn't happen, just use key */ | |
1334 | *name = key; | |
1335 | ns->clear(); | |
1336 | return; | |
1337 | } | |
1338 | ||
1339 | *name = key.substr(pos + 1); | |
1340 | *ns = key.substr(1, pos -1); | |
1341 | } | |
1342 | ||
1343 | void set(const string& n) { | |
1344 | name = n; | |
1345 | instance.clear(); | |
1346 | ns.clear(); | |
1347 | } | |
1348 | ||
1349 | void set(const string& n, const string& i) { | |
1350 | name = n; | |
1351 | instance = i; | |
1352 | ns.clear(); | |
1353 | } | |
1354 | ||
1355 | void set(const string& n, const string& i, const string& _ns) { | |
1356 | name = n; | |
1357 | instance = i; | |
1358 | ns = _ns; | |
1359 | } | |
1360 | ||
1361 | bool set(const rgw_obj_index_key& index_key) { | |
1362 | if (!parse_raw_oid(index_key.name, this)) { | |
1363 | return false; | |
1364 | } | |
1365 | instance = index_key.instance; | |
1366 | return true; | |
1367 | } | |
1368 | ||
1369 | void set_instance(const string& i) { | |
1370 | instance = i; | |
1371 | } | |
1372 | ||
11fdf7f2 TL |
1373 | const string& get_instance() const { |
1374 | return instance; | |
1375 | } | |
1376 | ||
9f95a23c TL |
1377 | void set_ns(const std::string& _ns) { |
1378 | ns = _ns; | |
1379 | } | |
1380 | ||
1381 | const std::string& get_ns() const { | |
1382 | return ns; | |
1383 | } | |
1384 | ||
7c673cae FG |
1385 | string get_index_key_name() const { |
1386 | if (ns.empty()) { | |
1387 | if (name.size() < 1 || name[0] != '_') { | |
1388 | return name; | |
1389 | } | |
1390 | return string("_") + name; | |
1391 | }; | |
1392 | ||
1393 | char buf[ns.size() + 16]; | |
1394 | snprintf(buf, sizeof(buf), "_%s_", ns.c_str()); | |
1395 | return string(buf) + name; | |
1396 | }; | |
1397 | ||
1398 | void get_index_key(rgw_obj_index_key *key) const { | |
1399 | key->name = get_index_key_name(); | |
1400 | key->instance = instance; | |
1401 | } | |
1402 | ||
1403 | string get_loc() const { | |
1404 | /* | |
1405 | * For backward compatibility. Older versions used to have object locator on all objects, | |
1406 | * however, the name was the effective object locator. This had the same effect as not | |
1407 | * having object locator at all for most objects but the ones that started with underscore as | |
1408 | * these were escaped. | |
1409 | */ | |
1410 | if (name[0] == '_' && ns.empty()) { | |
1411 | return name; | |
1412 | } | |
1413 | ||
1414 | return string(); | |
1415 | } | |
1416 | ||
1417 | bool empty() const { | |
1418 | return name.empty(); | |
1419 | } | |
1420 | ||
1421 | bool have_null_instance() const { | |
1422 | return instance == "null"; | |
1423 | } | |
1424 | ||
1425 | bool have_instance() const { | |
1426 | return !instance.empty(); | |
1427 | } | |
1428 | ||
1429 | bool need_to_encode_instance() const { | |
1430 | return have_instance() && !have_null_instance(); | |
1431 | } | |
1432 | ||
1433 | string get_oid() const { | |
1434 | if (ns.empty() && !need_to_encode_instance()) { | |
1435 | if (name.size() < 1 || name[0] != '_') { | |
1436 | return name; | |
1437 | } | |
1438 | return string("_") + name; | |
1439 | } | |
1440 | ||
1441 | string oid = "_"; | |
1442 | oid.append(ns); | |
1443 | if (need_to_encode_instance()) { | |
1444 | oid.append(string(":") + instance); | |
1445 | } | |
1446 | oid.append("_"); | |
1447 | oid.append(name); | |
1448 | return oid; | |
1449 | } | |
1450 | ||
1451 | bool operator==(const rgw_obj_key& k) const { | |
1452 | return (name.compare(k.name) == 0) && | |
1453 | (instance.compare(k.instance) == 0); | |
1454 | } | |
1455 | ||
1456 | bool operator<(const rgw_obj_key& k) const { | |
1457 | int r = name.compare(k.name); | |
1458 | if (r == 0) { | |
1459 | r = instance.compare(k.instance); | |
1460 | } | |
1461 | return (r < 0); | |
1462 | } | |
1463 | ||
1464 | bool operator<=(const rgw_obj_key& k) const { | |
1465 | return !(k < *this); | |
1466 | } | |
1467 | ||
1468 | static void parse_ns_field(string& ns, string& instance) { | |
1469 | int pos = ns.find(':'); | |
1470 | if (pos >= 0) { | |
1471 | instance = ns.substr(pos + 1); | |
1472 | ns = ns.substr(0, pos); | |
1473 | } else { | |
1474 | instance.clear(); | |
1475 | } | |
1476 | } | |
1477 | ||
11fdf7f2 TL |
1478 | // takes an oid and parses out the namespace (ns), name, and |
1479 | // instance | |
7c673cae FG |
1480 | static bool parse_raw_oid(const string& oid, rgw_obj_key *key) { |
1481 | key->instance.clear(); | |
1482 | key->ns.clear(); | |
1483 | if (oid[0] != '_') { | |
1484 | key->name = oid; | |
1485 | return true; | |
1486 | } | |
1487 | ||
1488 | if (oid.size() >= 2 && oid[1] == '_') { | |
1489 | key->name = oid.substr(1); | |
1490 | return true; | |
1491 | } | |
1492 | ||
11fdf7f2 | 1493 | if (oid.size() < 3) // for namespace, min size would be 3: _x_ |
7c673cae FG |
1494 | return false; |
1495 | ||
11fdf7f2 TL |
1496 | size_t pos = oid.find('_', 2); // oid must match ^_[^_].+$ |
1497 | if (pos == string::npos) | |
7c673cae FG |
1498 | return false; |
1499 | ||
1500 | key->ns = oid.substr(1, pos - 1); | |
1501 | parse_ns_field(key->ns, key->instance); | |
1502 | ||
1503 | key->name = oid.substr(pos + 1); | |
1504 | return true; | |
1505 | } | |
1506 | ||
1507 | /** | |
1508 | * Translate a namespace-mangled object name to the user-facing name | |
1509 | * existing in the given namespace. | |
1510 | * | |
1511 | * If the object is part of the given namespace, it returns true | |
1512 | * and cuts down the name to the unmangled version. If it is not | |
1513 | * part of the given namespace, it returns false. | |
1514 | */ | |
1515 | static bool oid_to_key_in_ns(const string& oid, rgw_obj_key *key, const string& ns) { | |
7c673cae FG |
1516 | bool ret = parse_raw_oid(oid, key); |
1517 | if (!ret) { | |
1518 | return ret; | |
1519 | } | |
1520 | ||
1521 | return (ns == key->ns); | |
1522 | } | |
1523 | ||
1524 | /** | |
1525 | * Given a mangled object name and an empty namespace string, this | |
1526 | * function extracts the namespace into the string and sets the object | |
1527 | * name to be the unmangled version. | |
1528 | * | |
1529 | * It returns true after successfully doing so, or | |
1530 | * false if it fails. | |
1531 | */ | |
1532 | static bool strip_namespace_from_name(string& name, string& ns, string& instance) { | |
1533 | ns.clear(); | |
1534 | instance.clear(); | |
1535 | if (name[0] != '_') { | |
1536 | return true; | |
1537 | } | |
1538 | ||
1539 | size_t pos = name.find('_', 1); | |
1540 | if (pos == string::npos) { | |
1541 | return false; | |
1542 | } | |
1543 | ||
1544 | if (name[1] == '_') { | |
1545 | name = name.substr(1); | |
1546 | return true; | |
1547 | } | |
1548 | ||
1549 | size_t period_pos = name.find('.'); | |
1550 | if (period_pos < pos) { | |
1551 | return false; | |
1552 | } | |
1553 | ||
1554 | ns = name.substr(1, pos-1); | |
1555 | name = name.substr(pos+1, string::npos); | |
1556 | ||
1557 | parse_ns_field(ns, instance); | |
1558 | return true; | |
1559 | } | |
1560 | ||
1561 | void encode(bufferlist& bl) const { | |
1562 | ENCODE_START(2, 1, bl); | |
11fdf7f2 TL |
1563 | encode(name, bl); |
1564 | encode(instance, bl); | |
1565 | encode(ns, bl); | |
7c673cae FG |
1566 | ENCODE_FINISH(bl); |
1567 | } | |
11fdf7f2 | 1568 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 1569 | DECODE_START(2, bl); |
11fdf7f2 TL |
1570 | decode(name, bl); |
1571 | decode(instance, bl); | |
7c673cae | 1572 | if (struct_v >= 2) { |
11fdf7f2 | 1573 | decode(ns, bl); |
7c673cae FG |
1574 | } |
1575 | DECODE_FINISH(bl); | |
1576 | } | |
1577 | void dump(Formatter *f) const; | |
b32b8144 | 1578 | void decode_json(JSONObj *obj); |
11fdf7f2 TL |
1579 | |
1580 | string to_str() const { | |
1581 | if (instance.empty()) { | |
1582 | return name; | |
1583 | } | |
1584 | char buf[name.size() + instance.size() + 16]; | |
1585 | snprintf(buf, sizeof(buf), "%s[%s]", name.c_str(), instance.c_str()); | |
1586 | return buf; | |
1587 | } | |
7c673cae FG |
1588 | }; |
1589 | WRITE_CLASS_ENCODER(rgw_obj_key) | |
1590 | ||
1591 | inline ostream& operator<<(ostream& out, const rgw_obj_key &o) { | |
11fdf7f2 | 1592 | return out << o.to_str(); |
7c673cae FG |
1593 | } |
1594 | ||
1595 | inline ostream& operator<<(ostream& out, const rgw_obj_index_key &o) { | |
1596 | if (o.instance.empty()) { | |
1597 | return out << o.name; | |
1598 | } else { | |
1599 | return out << o.name << "[" << o.instance << "]"; | |
1600 | } | |
1601 | } | |
1602 | ||
7c673cae FG |
1603 | struct req_init_state { |
1604 | /* Keeps [[tenant]:]bucket until we parse the token. */ | |
1605 | string url_bucket; | |
1606 | string src_bucket; | |
1607 | }; | |
1608 | ||
7c673cae FG |
1609 | #include "rgw_auth.h" |
1610 | ||
11fdf7f2 TL |
1611 | class RGWObjectCtx; |
1612 | class RGWSysObjectCtx; | |
1613 | ||
7c673cae | 1614 | /** Store all the state necessary to complete and respond to an HTTP request*/ |
11fdf7f2 | 1615 | struct req_state : DoutPrefixProvider { |
7c673cae | 1616 | CephContext *cct; |
11fdf7f2 TL |
1617 | rgw::io::BasicClient *cio{nullptr}; |
1618 | http_op op{OP_UNKNOWN}; | |
224ce89b | 1619 | RGWOpType op_type{}; |
11fdf7f2 TL |
1620 | bool content_started{false}; |
1621 | int format{0}; | |
1622 | ceph::Formatter *formatter{nullptr}; | |
7c673cae FG |
1623 | string decoded_uri; |
1624 | string relative_uri; | |
11fdf7f2 TL |
1625 | const char *length{nullptr}; |
1626 | int64_t content_length{0}; | |
7c673cae | 1627 | map<string, string> generic_attrs; |
31f18b77 | 1628 | rgw_err err; |
11fdf7f2 TL |
1629 | bool expect_cont{false}; |
1630 | uint64_t obj_size{0}; | |
7c673cae FG |
1631 | bool enable_ops_log; |
1632 | bool enable_usage_log; | |
1633 | uint8_t defer_to_bucket_acls; | |
11fdf7f2 | 1634 | uint32_t perm_mask{0}; |
7c673cae FG |
1635 | |
1636 | /* Set once when url_bucket is parsed and not violated thereafter. */ | |
1637 | string account_name; | |
1638 | ||
1639 | string bucket_tenant; | |
1640 | string bucket_name; | |
1641 | ||
1642 | rgw_bucket bucket; | |
1643 | rgw_obj_key object; | |
1644 | string src_tenant_name; | |
1645 | string src_bucket_name; | |
1646 | rgw_obj_key src_object; | |
1647 | ACLOwner bucket_owner; | |
1648 | ACLOwner owner; | |
1649 | ||
1650 | string zonegroup_name; | |
1651 | string zonegroup_endpoint; | |
1652 | string bucket_instance_id; | |
11fdf7f2 TL |
1653 | int bucket_instance_shard_id{-1}; |
1654 | string redirect_zone_endpoint; | |
7c673cae FG |
1655 | |
1656 | string redirect; | |
1657 | ||
1658 | RGWBucketInfo bucket_info; | |
9f95a23c | 1659 | obj_version bucket_ep_objv; |
11fdf7f2 TL |
1660 | real_time bucket_mtime; |
1661 | std::map<std::string, ceph::bufferlist> bucket_attrs; | |
1662 | bool bucket_exists{false}; | |
1663 | rgw_placement_rule dest_placement; | |
7c673cae | 1664 | |
11fdf7f2 | 1665 | bool has_bad_meta{false}; |
7c673cae | 1666 | |
9f95a23c | 1667 | rgw::sal::RGWUser *user; |
7c673cae FG |
1668 | |
1669 | struct { | |
1670 | /* TODO(rzarzynski): switch out to the static_ptr for both members. */ | |
1671 | ||
1672 | /* Object having the knowledge about an authenticated identity and allowing | |
1673 | * to apply it during the authorization phase (verify_permission() methods | |
1674 | * of a given RGWOp). Thus, it bounds authentication and authorization steps | |
1675 | * through a well-defined interface. For more details, see rgw_auth.h. */ | |
1676 | std::unique_ptr<rgw::auth::Identity> identity; | |
1677 | ||
31f18b77 | 1678 | std::shared_ptr<rgw::auth::Completer> completer; |
7c673cae FG |
1679 | |
1680 | /* A container for credentials of the S3's browser upload. It's necessary | |
1681 | * because: 1) the ::authenticate() method of auth engines and strategies | |
1682 | * take req_state only; 2) auth strategies live much longer than RGWOps - | |
1683 | * there is no way to pass additional data dependencies through ctors. */ | |
1684 | class { | |
1685 | /* Writer. */ | |
1686 | friend class RGWPostObj_ObjStore_S3; | |
1687 | /* Reader. */ | |
31f18b77 | 1688 | friend class rgw::auth::s3::AWSBrowserUploadAbstractor; |
9f95a23c | 1689 | friend class rgw::auth::s3::STSEngine; |
7c673cae FG |
1690 | |
1691 | std::string access_key; | |
1692 | std::string signature; | |
31f18b77 FG |
1693 | std::string x_amz_algorithm; |
1694 | std::string x_amz_credential; | |
1695 | std::string x_amz_date; | |
11fdf7f2 | 1696 | std::string x_amz_security_token; |
7c673cae FG |
1697 | ceph::bufferlist encoded_policy; |
1698 | } s3_postobj_creds; | |
1699 | } auth; | |
1700 | ||
1701 | std::unique_ptr<RGWAccessControlPolicy> user_acl; | |
c07f9fc5 FG |
1702 | std::unique_ptr<RGWAccessControlPolicy> bucket_acl; |
1703 | std::unique_ptr<RGWAccessControlPolicy> object_acl; | |
7c673cae | 1704 | |
31f18b77 FG |
1705 | rgw::IAM::Environment env; |
1706 | boost::optional<rgw::IAM::Policy> iam_policy; | |
9f95a23c | 1707 | boost::optional<PublicAccessBlockConfiguration> bucket_access_conf; |
11fdf7f2 | 1708 | vector<rgw::IAM::Policy> iam_user_policies; |
31f18b77 | 1709 | |
7c673cae FG |
1710 | /* Is the request made by an user marked as a system one? |
1711 | * Being system user means we also have the admin status. */ | |
11fdf7f2 | 1712 | bool system_request{false}; |
7c673cae | 1713 | |
7c673cae | 1714 | string canned_acl; |
11fdf7f2 TL |
1715 | bool has_acl_header{false}; |
1716 | bool local_source{false}; /* source is local */ | |
7c673cae | 1717 | |
11fdf7f2 | 1718 | int prot_flags{0}; |
7c673cae FG |
1719 | |
1720 | /* Content-Disposition override for TempURL of Swift API. */ | |
1721 | struct { | |
1722 | string override; | |
1723 | string fallback; | |
1724 | } content_disp; | |
1725 | ||
1726 | string host_id; | |
1727 | ||
1728 | req_info info; | |
1729 | req_init_state init_state; | |
1730 | ||
11fdf7f2 TL |
1731 | using Clock = ceph::coarse_real_clock; |
1732 | Clock::time_point time; | |
1733 | ||
1734 | Clock::duration time_elapsed() const { return Clock::now() - time; } | |
1735 | ||
1736 | RGWObjectCtx *obj_ctx{nullptr}; | |
1737 | RGWSysObjectCtx *sysobj_ctx{nullptr}; | |
7c673cae FG |
1738 | string dialect; |
1739 | string req_id; | |
1740 | string trans_id; | |
11fdf7f2 TL |
1741 | uint64_t id; |
1742 | ||
9f95a23c TL |
1743 | RGWObjTags tagset; |
1744 | ||
11fdf7f2 TL |
1745 | bool mfa_verified{false}; |
1746 | ||
1747 | /// optional coroutine context | |
1748 | optional_yield yield{null_yield}; | |
7c673cae | 1749 | |
adb31ebb TL |
1750 | //token claims from STS token for ops log (can be used for Keystone token also) |
1751 | std::vector<string> token_claims; | |
1752 | ||
9f95a23c | 1753 | req_state(CephContext* _cct, RGWEnv* e, rgw::sal::RGWUser* u, uint64_t id); |
7c673cae | 1754 | ~req_state(); |
31f18b77 FG |
1755 | |
1756 | bool is_err() const { return err.is_err(); } | |
11fdf7f2 TL |
1757 | |
1758 | // implements DoutPrefixProvider | |
1759 | std::ostream& gen_prefix(std::ostream& out) const override; | |
1760 | CephContext* get_cct() const override { return cct; } | |
1761 | unsigned get_subsys() const override { return ceph_subsys_rgw; } | |
7c673cae FG |
1762 | }; |
1763 | ||
31f18b77 FG |
1764 | void set_req_state_err(struct req_state*, int); |
1765 | void set_req_state_err(struct req_state*, int, const string&); | |
1766 | void set_req_state_err(struct rgw_err&, int, const int); | |
1767 | void dump(struct req_state*); | |
1768 | ||
7c673cae FG |
1769 | /** Store basic data on bucket */ |
1770 | struct RGWBucketEnt { | |
1771 | rgw_bucket bucket; | |
1772 | size_t size; | |
1773 | size_t size_rounded; | |
3efd9988 | 1774 | ceph::real_time creation_time; |
7c673cae FG |
1775 | uint64_t count; |
1776 | ||
3efd9988 FG |
1777 | /* The placement_rule is necessary to calculate per-storage-policy statics |
1778 | * of the Swift API. Although the info available in RGWBucketInfo, we need | |
1779 | * to duplicate it here to not affect the performance of buckets listing. */ | |
11fdf7f2 | 1780 | rgw_placement_rule placement_rule; |
7c673cae | 1781 | |
3efd9988 FG |
1782 | RGWBucketEnt() |
1783 | : size(0), | |
1784 | size_rounded(0), | |
1785 | count(0) { | |
1786 | } | |
1787 | RGWBucketEnt(const RGWBucketEnt&) = default; | |
1788 | RGWBucketEnt(RGWBucketEnt&&) = default; | |
1789 | explicit RGWBucketEnt(const rgw_user& u, cls_user_bucket_entry&& e) | |
1790 | : bucket(u, std::move(e.bucket)), | |
7c673cae FG |
1791 | size(e.size), |
1792 | size_rounded(e.size_rounded), | |
1793 | creation_time(e.creation_time), | |
1794 | count(e.count) { | |
1795 | } | |
1796 | ||
3efd9988 FG |
1797 | RGWBucketEnt& operator=(const RGWBucketEnt&) = default; |
1798 | ||
7c673cae FG |
1799 | void convert(cls_user_bucket_entry *b) const { |
1800 | bucket.convert(&b->bucket); | |
1801 | b->size = size; | |
1802 | b->size_rounded = size_rounded; | |
1803 | b->creation_time = creation_time; | |
1804 | b->count = count; | |
1805 | } | |
1806 | ||
1807 | void encode(bufferlist& bl) const { | |
3efd9988 | 1808 | ENCODE_START(7, 5, bl); |
7c673cae FG |
1809 | uint64_t s = size; |
1810 | __u32 mt = ceph::real_clock::to_time_t(creation_time); | |
1811 | string empty_str; // originally had the bucket name here, but we encode bucket later | |
11fdf7f2 TL |
1812 | encode(empty_str, bl); |
1813 | encode(s, bl); | |
1814 | encode(mt, bl); | |
1815 | encode(count, bl); | |
1816 | encode(bucket, bl); | |
7c673cae | 1817 | s = size_rounded; |
11fdf7f2 TL |
1818 | encode(s, bl); |
1819 | encode(creation_time, bl); | |
1820 | encode(placement_rule, bl); | |
7c673cae FG |
1821 | ENCODE_FINISH(bl); |
1822 | } | |
11fdf7f2 TL |
1823 | void decode(bufferlist::const_iterator& bl) { |
1824 | DECODE_START_LEGACY_COMPAT_LEN(7, 5, 5, bl); | |
7c673cae FG |
1825 | __u32 mt; |
1826 | uint64_t s; | |
1827 | string empty_str; // backward compatibility | |
11fdf7f2 TL |
1828 | decode(empty_str, bl); |
1829 | decode(s, bl); | |
1830 | decode(mt, bl); | |
7c673cae FG |
1831 | size = s; |
1832 | if (struct_v < 6) { | |
1833 | creation_time = ceph::real_clock::from_time_t(mt); | |
1834 | } | |
1835 | if (struct_v >= 2) | |
11fdf7f2 | 1836 | decode(count, bl); |
7c673cae | 1837 | if (struct_v >= 3) |
11fdf7f2 | 1838 | decode(bucket, bl); |
7c673cae | 1839 | if (struct_v >= 4) |
11fdf7f2 | 1840 | decode(s, bl); |
7c673cae FG |
1841 | size_rounded = s; |
1842 | if (struct_v >= 6) | |
11fdf7f2 | 1843 | decode(creation_time, bl); |
3efd9988 | 1844 | if (struct_v >= 7) |
11fdf7f2 | 1845 | decode(placement_rule, bl); |
7c673cae FG |
1846 | DECODE_FINISH(bl); |
1847 | } | |
1848 | void dump(Formatter *f) const; | |
1849 | static void generate_test_instances(list<RGWBucketEnt*>& o); | |
1850 | }; | |
1851 | WRITE_CLASS_ENCODER(RGWBucketEnt) | |
1852 | ||
1853 | struct rgw_obj { | |
1854 | rgw_bucket bucket; | |
1855 | rgw_obj_key key; | |
1856 | ||
1857 | bool in_extra_data{false}; /* in-memory only member, does not serialize */ | |
1858 | ||
1859 | // Represents the hash index source for this object once it is set (non-empty) | |
1860 | std::string index_hash_source; | |
1861 | ||
1862 | rgw_obj() {} | |
1863 | rgw_obj(const rgw_bucket& b, const std::string& name) : bucket(b), key(name) {} | |
1864 | rgw_obj(const rgw_bucket& b, const rgw_obj_key& k) : bucket(b), key(k) {} | |
1865 | rgw_obj(const rgw_bucket& b, const rgw_obj_index_key& k) : bucket(b), key(k) {} | |
1866 | ||
1867 | void init(const rgw_bucket& b, const std::string& name) { | |
1868 | bucket = b; | |
1869 | key.set(name); | |
1870 | } | |
1871 | void init(const rgw_bucket& b, const std::string& name, const string& i, const string& n) { | |
1872 | bucket = b; | |
1873 | key.set(name, i, n); | |
1874 | } | |
1875 | void init_ns(const rgw_bucket& b, const std::string& name, const string& n) { | |
1876 | bucket = b; | |
1877 | key.name = name; | |
1878 | key.instance.clear(); | |
1879 | key.ns = n; | |
1880 | } | |
1881 | ||
1882 | bool empty() const { | |
1883 | return key.empty(); | |
1884 | } | |
1885 | ||
1886 | void set_key(const rgw_obj_key& k) { | |
1887 | key = k; | |
1888 | } | |
1889 | ||
1890 | string get_oid() const { | |
1891 | return key.get_oid(); | |
1892 | } | |
1893 | ||
1894 | const string& get_hash_object() const { | |
1895 | return index_hash_source.empty() ? key.name : index_hash_source; | |
1896 | } | |
1897 | ||
1898 | void set_in_extra_data(bool val) { | |
1899 | in_extra_data = val; | |
1900 | } | |
1901 | ||
1902 | bool is_in_extra_data() const { | |
1903 | return in_extra_data; | |
1904 | } | |
1905 | ||
1906 | void encode(bufferlist& bl) const { | |
1907 | ENCODE_START(6, 6, bl); | |
11fdf7f2 TL |
1908 | encode(bucket, bl); |
1909 | encode(key.ns, bl); | |
1910 | encode(key.name, bl); | |
1911 | encode(key.instance, bl); | |
1912 | // encode(placement_id, bl); | |
7c673cae FG |
1913 | ENCODE_FINISH(bl); |
1914 | } | |
11fdf7f2 | 1915 | void decode(bufferlist::const_iterator& bl) { |
7c673cae FG |
1916 | DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl); |
1917 | if (struct_v < 6) { | |
1918 | string s; | |
11fdf7f2 TL |
1919 | decode(bucket.name, bl); /* bucket.name */ |
1920 | decode(s, bl); /* loc */ | |
1921 | decode(key.ns, bl); | |
1922 | decode(key.name, bl); | |
7c673cae | 1923 | if (struct_v >= 2) |
11fdf7f2 | 1924 | decode(bucket, bl); |
7c673cae | 1925 | if (struct_v >= 4) |
11fdf7f2 | 1926 | decode(key.instance, bl); |
7c673cae FG |
1927 | if (key.ns.empty() && key.instance.empty()) { |
1928 | if (key.name[0] == '_') { | |
1929 | key.name = key.name.substr(1); | |
1930 | } | |
1931 | } else { | |
1932 | if (struct_v >= 5) { | |
11fdf7f2 | 1933 | decode(key.name, bl); |
7c673cae FG |
1934 | } else { |
1935 | ssize_t pos = key.name.find('_', 1); | |
1936 | if (pos < 0) { | |
1937 | throw buffer::error(); | |
1938 | } | |
3a9019d9 | 1939 | key.name = key.name.substr(pos + 1); |
7c673cae FG |
1940 | } |
1941 | } | |
1942 | } else { | |
11fdf7f2 TL |
1943 | decode(bucket, bl); |
1944 | decode(key.ns, bl); | |
1945 | decode(key.name, bl); | |
1946 | decode(key.instance, bl); | |
1947 | // decode(placement_id, bl); | |
7c673cae FG |
1948 | } |
1949 | DECODE_FINISH(bl); | |
1950 | } | |
1951 | void dump(Formatter *f) const; | |
1952 | static void generate_test_instances(list<rgw_obj*>& o); | |
1953 | ||
1954 | bool operator==(const rgw_obj& o) const { | |
1955 | return (key == o.key) && | |
1956 | (bucket == o.bucket); | |
1957 | } | |
1958 | bool operator<(const rgw_obj& o) const { | |
1959 | int r = key.name.compare(o.key.name); | |
1960 | if (r == 0) { | |
1961 | r = bucket.bucket_id.compare(o.bucket.bucket_id); /* not comparing bucket.name, if bucket_id is equal so will be bucket.name */ | |
1962 | if (r == 0) { | |
1963 | r = key.ns.compare(o.key.ns); | |
1964 | if (r == 0) { | |
1965 | r = key.instance.compare(o.key.instance); | |
1966 | } | |
1967 | } | |
1968 | } | |
1969 | ||
1970 | return (r < 0); | |
1971 | } | |
1972 | ||
1973 | const rgw_pool& get_explicit_data_pool() { | |
1974 | if (!in_extra_data || bucket.explicit_placement.data_extra_pool.empty()) { | |
1975 | return bucket.explicit_placement.data_pool; | |
1976 | } | |
1977 | return bucket.explicit_placement.data_extra_pool; | |
1978 | } | |
1979 | }; | |
1980 | WRITE_CLASS_ENCODER(rgw_obj) | |
1981 | ||
1982 | struct rgw_cache_entry_info { | |
1983 | string cache_locator; | |
1984 | uint64_t gen; | |
1985 | ||
1986 | rgw_cache_entry_info() : gen(0) {} | |
1987 | }; | |
1988 | ||
1989 | inline ostream& operator<<(ostream& out, const rgw_obj &o) { | |
1990 | return out << o.bucket.name << ":" << o.get_oid(); | |
1991 | } | |
1992 | ||
31f18b77 FG |
1993 | static inline void buf_to_hex(const unsigned char* const buf, |
1994 | const size_t len, | |
1995 | char* const str) | |
7c673cae | 1996 | { |
7c673cae | 1997 | str[0] = '\0'; |
31f18b77 FG |
1998 | for (size_t i = 0; i < len; i++) { |
1999 | ::sprintf(&str[i*2], "%02x", static_cast<int>(buf[i])); | |
7c673cae FG |
2000 | } |
2001 | } | |
2002 | ||
31f18b77 FG |
2003 | template<size_t N> static inline std::array<char, N * 2 + 1> |
2004 | buf_to_hex(const std::array<unsigned char, N>& buf) | |
2005 | { | |
2006 | static_assert(N > 0, "The input array must be at least one element long"); | |
2007 | ||
2008 | std::array<char, N * 2 + 1> hex_dest; | |
2009 | buf_to_hex(buf.data(), N, hex_dest.data()); | |
2010 | return hex_dest; | |
2011 | } | |
2012 | ||
7c673cae FG |
2013 | static inline int hexdigit(char c) |
2014 | { | |
2015 | if (c >= '0' && c <= '9') | |
2016 | return (c - '0'); | |
2017 | c = toupper(c); | |
2018 | if (c >= 'A' && c <= 'F') | |
2019 | return c - 'A' + 0xa; | |
2020 | return -EINVAL; | |
2021 | } | |
2022 | ||
2023 | static inline int hex_to_buf(const char *hex, char *buf, int len) | |
2024 | { | |
2025 | int i = 0; | |
2026 | const char *p = hex; | |
2027 | while (*p) { | |
2028 | if (i >= len) | |
2029 | return -EINVAL; | |
2030 | buf[i] = 0; | |
2031 | int d = hexdigit(*p); | |
2032 | if (d < 0) | |
2033 | return d; | |
2034 | buf[i] = d << 4; | |
2035 | p++; | |
2036 | if (!*p) | |
2037 | return -EINVAL; | |
2038 | d = hexdigit(*p); | |
2039 | if (d < 0) | |
2040 | return d; | |
2041 | buf[i] += d; | |
2042 | i++; | |
2043 | p++; | |
2044 | } | |
2045 | return i; | |
2046 | } | |
2047 | ||
2048 | static inline int rgw_str_to_bool(const char *s, int def_val) | |
2049 | { | |
2050 | if (!s) | |
2051 | return def_val; | |
2052 | ||
11fdf7f2 TL |
2053 | return (strcasecmp(s, "true") == 0 || |
2054 | strcasecmp(s, "on") == 0 || | |
7c673cae FG |
2055 | strcasecmp(s, "yes") == 0 || |
2056 | strcasecmp(s, "1") == 0); | |
2057 | } | |
2058 | ||
2059 | static inline void append_rand_alpha(CephContext *cct, const string& src, string& dest, int len) | |
2060 | { | |
2061 | dest = src; | |
2062 | char buf[len + 1]; | |
2063 | gen_rand_alphanumeric(cct, buf, len); | |
2064 | dest.append("_"); | |
2065 | dest.append(buf); | |
2066 | } | |
2067 | ||
2068 | static inline const char *rgw_obj_category_name(RGWObjCategory category) | |
2069 | { | |
2070 | switch (category) { | |
11fdf7f2 | 2071 | case RGWObjCategory::None: |
7c673cae | 2072 | return "rgw.none"; |
11fdf7f2 | 2073 | case RGWObjCategory::Main: |
7c673cae | 2074 | return "rgw.main"; |
11fdf7f2 | 2075 | case RGWObjCategory::Shadow: |
7c673cae | 2076 | return "rgw.shadow"; |
11fdf7f2 | 2077 | case RGWObjCategory::MultiMeta: |
7c673cae FG |
2078 | return "rgw.multimeta"; |
2079 | } | |
2080 | ||
2081 | return "unknown"; | |
2082 | } | |
2083 | ||
2084 | static inline uint64_t rgw_rounded_kb(uint64_t bytes) | |
2085 | { | |
2086 | return (bytes + 1023) / 1024; | |
2087 | } | |
2088 | ||
2089 | static inline uint64_t rgw_rounded_objsize(uint64_t bytes) | |
2090 | { | |
2091 | return ((bytes + 4095) & ~4095); | |
2092 | } | |
2093 | ||
2094 | static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes) | |
2095 | { | |
2096 | return ((bytes + 4095) & ~4095) / 1024; | |
2097 | } | |
2098 | ||
a8e16298 TL |
2099 | /* implement combining step, S3 header canonicalization; k is a |
2100 | * valid header and in lc form */ | |
9f95a23c TL |
2101 | void rgw_add_amz_meta_header( |
2102 | meta_map_t& x_meta_map, | |
a8e16298 | 2103 | const std::string& k, |
9f95a23c | 2104 | const std::string& v); |
a8e16298 | 2105 | |
7c673cae FG |
2106 | extern string rgw_string_unquote(const string& s); |
2107 | extern void parse_csv_string(const string& ival, vector<string>& ovals); | |
2108 | extern int parse_key_value(string& in_str, string& key, string& val); | |
2109 | extern int parse_key_value(string& in_str, const char *delim, string& key, string& val); | |
31f18b77 FG |
2110 | |
2111 | extern boost::optional<std::pair<boost::string_view, boost::string_view>> | |
2112 | parse_key_value(const boost::string_view& in_str, | |
2113 | const boost::string_view& delim); | |
2114 | extern boost::optional<std::pair<boost::string_view, boost::string_view>> | |
2115 | parse_key_value(const boost::string_view& in_str); | |
2116 | ||
2117 | ||
7c673cae FG |
2118 | /** time parsing */ |
2119 | extern int parse_time(const char *time_str, real_time *time); | |
2120 | extern bool parse_rfc2616(const char *s, struct tm *t); | |
2121 | extern bool parse_iso8601(const char *s, struct tm *t, uint32_t *pns = NULL, bool extended_format = true); | |
2122 | extern string rgw_trim_whitespace(const string& src); | |
31f18b77 | 2123 | extern boost::string_view rgw_trim_whitespace(const boost::string_view& src); |
7c673cae FG |
2124 | extern string rgw_trim_quotes(const string& val); |
2125 | ||
2126 | extern void rgw_to_iso8601(const real_time& t, char *dest, int buf_size); | |
2127 | extern void rgw_to_iso8601(const real_time& t, string *dest); | |
c07f9fc5 | 2128 | extern std::string rgw_to_asctime(const utime_t& t); |
7c673cae | 2129 | |
9f95a23c TL |
2130 | struct perm_state_base { |
2131 | CephContext *cct; | |
2132 | const rgw::IAM::Environment& env; | |
2133 | rgw::auth::Identity *identity; | |
2134 | const RGWBucketInfo& bucket_info; | |
2135 | int perm_mask; | |
2136 | bool defer_to_bucket_acls; | |
2137 | boost::optional<PublicAccessBlockConfiguration> bucket_access_conf; | |
2138 | ||
2139 | perm_state_base(CephContext *_cct, | |
2140 | const rgw::IAM::Environment& _env, | |
2141 | rgw::auth::Identity *_identity, | |
2142 | const RGWBucketInfo& _bucket_info, | |
2143 | int _perm_mask, | |
2144 | bool _defer_to_bucket_acls, | |
2145 | boost::optional<PublicAccessBlockConfiguration> _bucket_acess_conf = boost::none) : | |
2146 | cct(_cct), | |
2147 | env(_env), | |
2148 | identity(_identity), | |
2149 | bucket_info(_bucket_info), | |
2150 | perm_mask(_perm_mask), | |
2151 | defer_to_bucket_acls(_defer_to_bucket_acls), | |
2152 | bucket_access_conf(_bucket_acess_conf) | |
2153 | {} | |
2154 | ||
2155 | virtual ~perm_state_base() {} | |
2156 | ||
2157 | virtual const char *get_referer() const = 0; | |
2158 | virtual std::optional<bool> get_request_payer() const = 0; /* | |
2159 | * empty state means that request_payer param was not passed in | |
2160 | */ | |
2161 | ||
2162 | }; | |
2163 | ||
2164 | struct perm_state : public perm_state_base { | |
2165 | const char *referer; | |
2166 | bool request_payer; | |
2167 | ||
2168 | perm_state(CephContext *_cct, | |
2169 | const rgw::IAM::Environment& _env, | |
2170 | rgw::auth::Identity *_identity, | |
2171 | const RGWBucketInfo& _bucket_info, | |
2172 | int _perm_mask, | |
2173 | bool _defer_to_bucket_acls, | |
2174 | const char *_referer, | |
2175 | bool _request_payer) : perm_state_base(_cct, | |
2176 | _env, | |
2177 | _identity, | |
2178 | _bucket_info, | |
2179 | _perm_mask, | |
2180 | _defer_to_bucket_acls), | |
2181 | referer(_referer), | |
2182 | request_payer(_request_payer) {} | |
2183 | ||
2184 | const char *get_referer() const override { | |
2185 | return referer; | |
2186 | } | |
2187 | ||
2188 | std::optional<bool> get_request_payer() const override { | |
2189 | return request_payer; | |
2190 | } | |
2191 | }; | |
2192 | ||
2193 | /** Check if the req_state's user has the necessary permissions | |
2194 | * to do the requested action */ | |
2195 | bool verify_bucket_permission_no_policy( | |
2196 | const DoutPrefixProvider* dpp, | |
2197 | struct perm_state_base * const s, | |
2198 | RGWAccessControlPolicy * const user_acl, | |
2199 | RGWAccessControlPolicy * const bucket_acl, | |
2200 | const int perm); | |
2201 | ||
2202 | bool verify_user_permission_no_policy(const DoutPrefixProvider* dpp, | |
2203 | struct perm_state_base * const s, | |
2204 | RGWAccessControlPolicy * const user_acl, | |
2205 | const int perm); | |
2206 | ||
2207 | bool verify_object_permission_no_policy(const DoutPrefixProvider* dpp, | |
2208 | struct perm_state_base * const s, | |
2209 | RGWAccessControlPolicy * const user_acl, | |
2210 | RGWAccessControlPolicy * const bucket_acl, | |
2211 | RGWAccessControlPolicy * const object_acl, | |
2212 | const int perm); | |
2213 | ||
7c673cae FG |
2214 | /** Check if the req_state's user has the necessary permissions |
2215 | * to do the requested action */ | |
11fdf7f2 TL |
2216 | rgw::IAM::Effect eval_user_policies(const vector<rgw::IAM::Policy>& user_policies, |
2217 | const rgw::IAM::Environment& env, | |
2218 | boost::optional<const rgw::auth::Identity&> id, | |
2219 | const uint64_t op, | |
eafe8130 | 2220 | const rgw::ARN& arn); |
11fdf7f2 TL |
2221 | bool verify_user_permission(const DoutPrefixProvider* dpp, |
2222 | struct req_state * const s, | |
7c673cae | 2223 | RGWAccessControlPolicy * const user_acl, |
11fdf7f2 | 2224 | const vector<rgw::IAM::Policy>& user_policies, |
eafe8130 | 2225 | const rgw::ARN& res, |
11fdf7f2 TL |
2226 | const uint64_t op); |
2227 | bool verify_user_permission_no_policy(const DoutPrefixProvider* dpp, | |
2228 | struct req_state * const s, | |
2229 | RGWAccessControlPolicy * const user_acl, | |
2230 | const int perm); | |
2231 | bool verify_user_permission(const DoutPrefixProvider* dpp, | |
2232 | struct req_state * const s, | |
eafe8130 | 2233 | const rgw::ARN& res, |
11fdf7f2 TL |
2234 | const uint64_t op); |
2235 | bool verify_user_permission_no_policy(const DoutPrefixProvider* dpp, | |
2236 | struct req_state * const s, | |
2237 | int perm); | |
31f18b77 | 2238 | bool verify_bucket_permission( |
11fdf7f2 | 2239 | const DoutPrefixProvider* dpp, |
31f18b77 FG |
2240 | struct req_state * const s, |
2241 | const rgw_bucket& bucket, | |
2242 | RGWAccessControlPolicy * const user_acl, | |
2243 | RGWAccessControlPolicy * const bucket_acl, | |
2244 | const boost::optional<rgw::IAM::Policy>& bucket_policy, | |
11fdf7f2 | 2245 | const vector<rgw::IAM::Policy>& user_policies, |
31f18b77 | 2246 | const uint64_t op); |
11fdf7f2 | 2247 | bool verify_bucket_permission(const DoutPrefixProvider* dpp, struct req_state * const s, const uint64_t op); |
31f18b77 | 2248 | bool verify_bucket_permission_no_policy( |
11fdf7f2 | 2249 | const DoutPrefixProvider* dpp, |
31f18b77 FG |
2250 | struct req_state * const s, |
2251 | RGWAccessControlPolicy * const user_acl, | |
2252 | RGWAccessControlPolicy * const bucket_acl, | |
2253 | const int perm); | |
11fdf7f2 TL |
2254 | bool verify_bucket_permission_no_policy(const DoutPrefixProvider* dpp, |
2255 | struct req_state * const s, | |
31f18b77 | 2256 | const int perm); |
b32b8144 FG |
2257 | int verify_bucket_owner_or_policy(struct req_state* const s, |
2258 | const uint64_t op); | |
31f18b77 | 2259 | extern bool verify_object_permission( |
11fdf7f2 | 2260 | const DoutPrefixProvider* dpp, |
31f18b77 FG |
2261 | struct req_state * const s, |
2262 | const rgw_obj& obj, | |
2263 | RGWAccessControlPolicy * const user_acl, | |
2264 | RGWAccessControlPolicy * const bucket_acl, | |
2265 | RGWAccessControlPolicy * const object_acl, | |
2266 | const boost::optional<rgw::IAM::Policy>& bucket_policy, | |
11fdf7f2 | 2267 | const vector<rgw::IAM::Policy>& user_policies, |
31f18b77 | 2268 | const uint64_t op); |
11fdf7f2 | 2269 | extern bool verify_object_permission(const DoutPrefixProvider* dpp, struct req_state *s, uint64_t op); |
31f18b77 | 2270 | extern bool verify_object_permission_no_policy( |
11fdf7f2 | 2271 | const DoutPrefixProvider* dpp, |
31f18b77 FG |
2272 | struct req_state * const s, |
2273 | RGWAccessControlPolicy * const user_acl, | |
2274 | RGWAccessControlPolicy * const bucket_acl, | |
2275 | RGWAccessControlPolicy * const object_acl, | |
2276 | int perm); | |
11fdf7f2 | 2277 | extern bool verify_object_permission_no_policy(const DoutPrefixProvider* dpp, struct req_state *s, |
31f18b77 | 2278 | int perm); |
7c673cae FG |
2279 | /** Convert an input URL into a sane object name |
2280 | * by converting %-escaped strings into characters, etc*/ | |
2281 | extern void rgw_uri_escape_char(char c, string& dst); | |
31f18b77 FG |
2282 | extern std::string url_decode(const boost::string_view& src_str, |
2283 | bool in_query = false); | |
11fdf7f2 TL |
2284 | extern void url_encode(const std::string& src, string& dst, |
2285 | bool encode_slash = true); | |
2286 | extern std::string url_encode(const std::string& src, bool encode_slash = true); | |
f91f0fd5 | 2287 | extern std::string url_remove_prefix(const std::string& url); // Removes hhtp, https and www from url |
7c673cae FG |
2288 | /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */ |
2289 | extern void calc_hmac_sha1(const char *key, int key_len, | |
2290 | const char *msg, int msg_len, char *dest); | |
31f18b77 | 2291 | |
31f18b77 FG |
2292 | static inline sha1_digest_t |
2293 | calc_hmac_sha1(const boost::string_view& key, const boost::string_view& msg) { | |
2294 | sha1_digest_t dest; | |
11fdf7f2 TL |
2295 | calc_hmac_sha1(key.data(), key.size(), msg.data(), msg.size(), |
2296 | reinterpret_cast<char*>(dest.v)); | |
31f18b77 FG |
2297 | return dest; |
2298 | } | |
2299 | ||
7c673cae | 2300 | /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */ |
31f18b77 FG |
2301 | extern void calc_hmac_sha256(const char *key, int key_len, |
2302 | const char *msg, int msg_len, | |
2303 | char *dest); | |
2304 | ||
31f18b77 FG |
2305 | static inline sha256_digest_t |
2306 | calc_hmac_sha256(const char *key, const int key_len, | |
2307 | const char *msg, const int msg_len) { | |
11fdf7f2 | 2308 | sha256_digest_t dest; |
31f18b77 | 2309 | calc_hmac_sha256(key, key_len, msg, msg_len, |
11fdf7f2 | 2310 | reinterpret_cast<char*>(dest.v)); |
31f18b77 FG |
2311 | return dest; |
2312 | } | |
2313 | ||
2314 | static inline sha256_digest_t | |
2315 | calc_hmac_sha256(const boost::string_view& key, const boost::string_view& msg) { | |
11fdf7f2 | 2316 | sha256_digest_t dest; |
31f18b77 FG |
2317 | calc_hmac_sha256(key.data(), key.size(), |
2318 | msg.data(), msg.size(), | |
11fdf7f2 TL |
2319 | reinterpret_cast<char*>(dest.v)); |
2320 | return dest; | |
2321 | } | |
2322 | ||
2323 | static inline sha256_digest_t | |
2324 | calc_hmac_sha256(const sha256_digest_t &key, | |
2325 | const boost::string_view& msg) { | |
2326 | sha256_digest_t dest; | |
2327 | calc_hmac_sha256(reinterpret_cast<const char*>(key.v), sha256_digest_t::SIZE, | |
2328 | msg.data(), msg.size(), | |
2329 | reinterpret_cast<char*>(dest.v)); | |
31f18b77 FG |
2330 | return dest; |
2331 | } | |
7c673cae | 2332 | |
31f18b77 FG |
2333 | static inline sha256_digest_t |
2334 | calc_hmac_sha256(const std::vector<unsigned char>& key, | |
2335 | const boost::string_view& msg) { | |
11fdf7f2 | 2336 | sha256_digest_t dest; |
31f18b77 FG |
2337 | calc_hmac_sha256(reinterpret_cast<const char*>(key.data()), key.size(), |
2338 | msg.data(), msg.size(), | |
11fdf7f2 | 2339 | reinterpret_cast<char*>(dest.v)); |
31f18b77 FG |
2340 | return dest; |
2341 | } | |
2342 | ||
2343 | template<size_t KeyLenN> | |
2344 | static inline sha256_digest_t | |
2345 | calc_hmac_sha256(const std::array<unsigned char, KeyLenN>& key, | |
2346 | const boost::string_view& msg) { | |
11fdf7f2 | 2347 | sha256_digest_t dest; |
31f18b77 FG |
2348 | calc_hmac_sha256(reinterpret_cast<const char*>(key.data()), key.size(), |
2349 | msg.data(), msg.size(), | |
11fdf7f2 | 2350 | reinterpret_cast<char*>(dest.v)); |
31f18b77 FG |
2351 | return dest; |
2352 | } | |
2353 | ||
2354 | extern sha256_digest_t calc_hash_sha256(const boost::string_view& msg); | |
2355 | ||
2356 | extern ceph::crypto::SHA256* calc_hash_sha256_open_stream(); | |
2357 | extern void calc_hash_sha256_update_stream(ceph::crypto::SHA256* hash, | |
2358 | const char* msg, | |
2359 | int len); | |
2360 | extern std::string calc_hash_sha256_close_stream(ceph::crypto::SHA256** phash); | |
2361 | extern std::string calc_hash_sha256_restart_stream(ceph::crypto::SHA256** phash); | |
7c673cae FG |
2362 | |
2363 | extern int rgw_parse_op_type_list(const string& str, uint32_t *perm); | |
2364 | ||
d2e6a577 FG |
2365 | static constexpr uint32_t MATCH_POLICY_ACTION = 0x01; |
2366 | static constexpr uint32_t MATCH_POLICY_RESOURCE = 0x02; | |
2367 | static constexpr uint32_t MATCH_POLICY_ARN = 0x04; | |
2368 | static constexpr uint32_t MATCH_POLICY_STRING = 0x08; | |
2369 | ||
2370 | extern bool match_policy(boost::string_view pattern, boost::string_view input, | |
2371 | uint32_t flag); | |
31f18b77 | 2372 | |
11fdf7f2 TL |
2373 | extern string camelcase_dash_http_attr(const string& orig); |
2374 | extern string lowercase_dash_http_attr(const string& orig); | |
2375 | ||
94b18763 FG |
2376 | void rgw_setup_saved_curl_handles(); |
2377 | void rgw_release_all_curl_handles(); | |
2378 | ||
1adf2230 AA |
2379 | static inline void rgw_escape_str(const string& s, char esc_char, |
2380 | char special_char, string *dest) | |
2381 | { | |
2382 | const char *src = s.c_str(); | |
2383 | char dest_buf[s.size() * 2 + 1]; | |
2384 | char *destp = dest_buf; | |
2385 | ||
2386 | for (size_t i = 0; i < s.size(); i++) { | |
2387 | char c = src[i]; | |
2388 | if (c == esc_char || c == special_char) { | |
2389 | *destp++ = esc_char; | |
2390 | } | |
2391 | *destp++ = c; | |
2392 | } | |
2393 | *destp++ = '\0'; | |
2394 | *dest = dest_buf; | |
2395 | } | |
2396 | ||
2397 | static inline ssize_t rgw_unescape_str(const string& s, ssize_t ofs, | |
2398 | char esc_char, char special_char, | |
2399 | string *dest) | |
2400 | { | |
2401 | const char *src = s.c_str(); | |
2402 | char dest_buf[s.size() + 1]; | |
2403 | char *destp = dest_buf; | |
2404 | bool esc = false; | |
2405 | ||
2406 | dest_buf[0] = '\0'; | |
2407 | ||
2408 | for (size_t i = ofs; i < s.size(); i++) { | |
2409 | char c = src[i]; | |
2410 | if (!esc && c == esc_char) { | |
2411 | esc = true; | |
2412 | continue; | |
2413 | } | |
2414 | if (!esc && c == special_char) { | |
2415 | *destp = '\0'; | |
2416 | *dest = dest_buf; | |
2417 | return (ssize_t)i + 1; | |
2418 | } | |
2419 | *destp++ = c; | |
2420 | esc = false; | |
2421 | } | |
2422 | *destp = '\0'; | |
2423 | *dest = dest_buf; | |
2424 | return string::npos; | |
2425 | } | |
2426 | ||
11fdf7f2 TL |
2427 | static inline string rgw_bl_str(ceph::buffer::list& raw) |
2428 | { | |
2429 | size_t len = raw.length(); | |
2430 | string s(raw.c_str(), len); | |
2431 | while (len && !s[len - 1]) { | |
2432 | --len; | |
2433 | s.resize(len); | |
2434 | } | |
2435 | return s; | |
2436 | } | |
2437 | ||
81eedcae TL |
2438 | template <typename T> |
2439 | int decode_bl(bufferlist& bl, T& t) | |
2440 | { | |
2441 | auto iter = bl.cbegin(); | |
2442 | try { | |
2443 | decode(t, iter); | |
2444 | } catch (buffer::error& err) { | |
2445 | return -EIO; | |
2446 | } | |
2447 | return 0; | |
2448 | } | |
2449 | ||
7c673cae | 2450 | #endif |