OPTION(rgw_swift_auth_entry, OPT_STR, "auth") // entry point for which a url is considered a swift auth url
OPTION(rgw_keystone_url, OPT_STR, "") // url for keystone server
OPTION(rgw_keystone_admin_token, OPT_STR, "") // keystone admin token (shared secret)
+OPTION(rgw_keystone_admin_user, OPT_STR, "") // keystone admin user name
+OPTION(rgw_keystone_admin_password, OPT_STR, "") // keystone admin user password
+OPTION(rgw_keystone_admin_tenant, OPT_STR, "") // keystone admin user tenant
OPTION(rgw_keystone_accepted_roles, OPT_STR, "Member, admin") // roles required to serve requests
OPTION(rgw_keystone_token_cache_size, OPT_INT, 10000) // max number of entries in keystone token cache
OPTION(rgw_keystone_revocation_interval, OPT_INT, 15 * 60) // seconds between tokens revocation check
return 0;
}
-
-
-class RGWValidateKeystoneToken : public RGWHTTPClient {
+class RGWPostHTTPData : public RGWHTTPClient {
bufferlist *bl;
+ std::string post_data;
+ size_t post_data_index;
public:
- RGWValidateKeystoneToken(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl) {}
+ RGWPostHTTPData(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0) {}
+
+ void set_post_data(const std::string& _post_data) {
+ this->post_data = _post_data;
+ }
+
+ int send_data(void* ptr, size_t len) {
+ int length_to_copy = 0;
+ if (post_data_index < post_data.length()) {
+ length_to_copy = min(post_data.length() - post_data_index, len);
+ memcpy(ptr, post_data.data() + post_data_index, length_to_copy);
+ post_data_index += length_to_copy;
+ }
+ return length_to_copy;
+ }
int receive_data(void *ptr, size_t len) {
bl->append((char *)ptr, len);
return 0;
}
+
int receive_header(void *ptr, size_t len) {
return 0;
}
- int send_data(void *ptr, size_t len) {
- return 0;
- }
-
};
-static RGWKeystoneTokenCache *keystone_token_cache = NULL;
+typedef RGWPostHTTPData RGWGetKeystoneAdminToken;
+typedef RGWPostHTTPData RGWGetRevokedTokens;
-class RGWGetRevokedTokens : public RGWHTTPClient {
+class RGWValidateKeystoneToken : public RGWHTTPClient {
bufferlist *bl;
public:
- RGWGetRevokedTokens(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl) {}
+ RGWValidateKeystoneToken(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl) {}
int receive_data(void *ptr, size_t len) {
bl->append((char *)ptr, len);
int send_data(void *ptr, size_t len) {
return 0;
}
+
};
+static RGWKeystoneTokenCache *keystone_token_cache = NULL;
+
static int open_cms_envelope(CephContext *cct, string& src, string& dst)
{
#define BEGIN_CMS "-----BEGIN CMS-----"
return 0;
}
-
-int RGWSwift::check_revoked()
+int RGWSwift::get_keystone_url(std::string& url)
{
bufferlist bl;
RGWGetRevokedTokens req(cct, &bl);
- string url = g_conf->rgw_keystone_url;
+ url = cct->_conf->rgw_keystone_url;
if (url.empty()) {
ldout(cct, 0) << "ERROR: keystone url is not configured" << dendl;
return -EINVAL;
}
if (url[url.size() - 1] != '/')
url.append("/");
- url.append("v2.0/tokens/revoked");
+ return 0;
+}
- req.append_header("X-Auth-Token", g_conf->rgw_keystone_admin_token);
+int RGWSwift::get_keystone_admin_token(std::string& token)
+{
+ std::string token_url;
+
+ if (get_keystone_url(token_url) < 0)
+ return -EINVAL;
+ if (cct->_conf->rgw_keystone_admin_token.empty()) {
+ token_url.append("v2.0/tokens");
+ KeystoneToken t;
+ bufferlist token_bl;
+ RGWGetKeystoneAdminToken token_req(cct, &token_bl);
+ std::ostringstream os;
+ os << "{ \"auth\":{ \"passwordCredentials\":{ \"username\":\"";
+ os << cct->_conf->rgw_keystone_admin_user;
+ os << "\", \"password\":\"";
+ os << cct->_conf->rgw_keystone_admin_password;
+ os << "\"}, \"tenantName\":\"";
+ os << cct->_conf->rgw_keystone_admin_tenant;
+ os << "\"}}";
+ token_req.set_post_data(os.str());
+ int ret = token_req.process(token_url.c_str());
+ if (ret < 0)
+ return ret;
+ if (t.parse(cct, token_bl) != 0)
+ return -EINVAL;
+ token = t.token.id;
+ } else {
+ token = cct->_conf->rgw_keystone_admin_token;
+ }
+ return 0;
+}
+
+int RGWSwift::check_revoked()
+{
+ string url;
+ string token;
+
+ bufferlist bl;
+ RGWGetRevokedTokens req(cct, &bl);
+
+ if (get_keystone_admin_token(token) < 0)
+ return -EINVAL;
+ if (get_keystone_url(url) < 0)
+ return -EINVAL;
+ url.append("v2.0/tokens/revoked");
+ req.append_header("X-Auth-Token", token);
int ret = req.process(url.c_str());
if (ret < 0)
return ret;