]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_oidc_provider.h
import ceph pacific 16.2.5
[ceph.git] / ceph / src / rgw / rgw_oidc_provider.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #ifndef CEPH_RGW_OIDC_PROVIDER_H
5 #define CEPH_RGW_OIDC_PROVIDER_H
6
7 #include <string>
8
9 #include "common/ceph_context.h"
10 #include "common/ceph_json.h"
11
12 #include "rgw/rgw_rados.h"
13
14 class RGWCtl;
15
16 class RGWOIDCProvider
17 {
18 using string = std::string;
19 static const string oidc_url_oid_prefix;
20 static const string oidc_arn_prefix;
21 static constexpr int MAX_OIDC_NUM_CLIENT_IDS = 100;
22 static constexpr int MAX_OIDC_CLIENT_ID_LEN = 255;
23 static constexpr int MAX_OIDC_NUM_THUMBPRINTS = 5;
24 static constexpr int MAX_OIDC_THUMBPRINT_LEN = 40;
25 static constexpr int MAX_OIDC_URL_LEN = 255;
26
27 CephContext *cct;
28 RGWCtl *ctl;
29 string id;
30 string provider_url;
31 string arn;
32 string creation_date;
33 string tenant;
34 vector<string> client_ids;
35 vector<string> thumbprints;
36
37 int get_tenant_url_from_arn(string& tenant, string& url);
38 int store_url(const DoutPrefixProvider *dpp, const string& url, bool exclusive, optional_yield y);
39 int read_url(const DoutPrefixProvider *dpp, const string& url, const string& tenant);
40 bool validate_input();
41
42 public:
43 RGWOIDCProvider(CephContext *cct,
44 RGWCtl *ctl,
45 string provider_url,
46 string tenant,
47 vector<string> client_ids,
48 vector<string> thumbprints)
49 : cct(cct),
50 ctl(ctl),
51 provider_url(std::move(provider_url)),
52 tenant(std::move(tenant)),
53 client_ids(std::move(client_ids)),
54 thumbprints(std::move(thumbprints)) {
55 }
56
57 RGWOIDCProvider(CephContext *cct,
58 RGWCtl *ctl,
59 string arn,
60 string tenant)
61 : cct(cct),
62 ctl(ctl),
63 arn(std::move(arn)),
64 tenant(std::move(tenant)) {
65 }
66
67 RGWOIDCProvider(CephContext *cct,
68 RGWCtl *ctl,
69 string tenant)
70 : cct(cct),
71 ctl(ctl),
72 tenant(std::move(tenant)) {}
73
74 RGWOIDCProvider(CephContext *cct,
75 RGWCtl *ctl)
76 : cct(cct),
77 ctl(ctl) {}
78
79 RGWOIDCProvider() {}
80
81 ~RGWOIDCProvider() = default;
82
83 void encode(bufferlist& bl) const {
84 ENCODE_START(3, 1, bl);
85 encode(id, bl);
86 encode(provider_url, bl);
87 encode(arn, bl);
88 encode(creation_date, bl);
89 encode(tenant, bl);
90 encode(client_ids, bl);
91 encode(thumbprints, bl);
92 ENCODE_FINISH(bl);
93 }
94
95 void decode(bufferlist::const_iterator& bl) {
96 DECODE_START(2, bl);
97 decode(id, bl);
98 decode(provider_url, bl);
99 decode(arn, bl);
100 decode(creation_date, bl);
101 decode(tenant, bl);
102 decode(client_ids, bl);
103 decode(thumbprints, bl);
104 DECODE_FINISH(bl);
105 }
106
107 const string& get_provider_url() const { return provider_url; }
108 const string& get_arn() const { return arn; }
109 const string& get_create_date() const { return creation_date; }
110 const vector<string>& get_client_ids() const { return client_ids;}
111 const vector<string>& get_thumbprints() const { return thumbprints; }
112
113 int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y);
114 int delete_obj(const DoutPrefixProvider *dpp, optional_yield y);
115 int get(const DoutPrefixProvider *dpp);
116 void dump(Formatter *f) const;
117 void dump_all(Formatter *f) const;
118 void decode_json(JSONObj *obj);
119
120 static const string& get_url_oid_prefix();
121 static int get_providers(const DoutPrefixProvider *dpp, RGWRados *store,
122 const string& tenant,
123 vector<RGWOIDCProvider>& providers);
124 };
125 WRITE_CLASS_ENCODER(RGWOIDCProvider)
126 #endif /* CEPH_RGW_OIDC_PROVIDER_H */
127