]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: implement ipv4 aws:SourceIp condition for bucket policy 19167/head
authoryuliyang <yuliyang@cmss.chinamobile.com>
Mon, 27 Nov 2017 06:32:44 +0000 (14:32 +0800)
committeryuliyang <yuliyang@cmss.chinamobile.com>
Thu, 30 Nov 2017 05:12:24 +0000 (13:12 +0800)
Signed-off-by: yuliyang <yuliyang@cmss.chinamobile.com>
src/rgw/rgw_asio_client.cc
src/rgw/rgw_iam_policy.cc
src/rgw/rgw_op.cc

index d59e7bb03b90f184d9db60bfd86e9bfdb922a913..39040a2607f2b04b877058311ca94a4648e13c00 100644 (file)
@@ -75,6 +75,7 @@ void ClientIO::init_env(CephContext *cct)
   char port_buf[16];
   snprintf(port_buf, sizeof(port_buf), "%d", socket.local_endpoint().port());
   env.set("SERVER_PORT", port_buf);
+  env.set("REMOTE_ADDR", socket.remote_endpoint().address().to_string());
   // TODO: set SERVER_PORT_SECURE if using ssl
   // TODO: set REMOTE_USER if authenticated
 }
index 6414c8bb423a014dd3a77f76541e462d5575af52..0b967716ae287e693a96a9a4fce0ddf3be9443a8 100644 (file)
@@ -1038,7 +1038,8 @@ optional<MaskedIP> Condition::as_network(const string& s) {
     return none;
   }
 
-  m.v6 = s.find(':');
+  m.v6 = (s.find(':') == string::npos) ? false : true;
+
   auto slash = s.find('/');
   if (slash == string::npos) {
     m.prefix = m.v6 ? 128 : 32;
@@ -1061,7 +1062,7 @@ optional<MaskedIP> Condition::as_network(const string& s) {
 
   if (m.v6) {
     struct sockaddr_in6 a;
-    if (inet_pton(AF_INET6, p->c_str(), static_cast<void*>(&a)) != 1) {
+    if (inet_pton(AF_INET6, p->c_str(), static_cast<void*>(&a.sin6_addr)) != 1) {
       return none;
     }
 
@@ -1083,13 +1084,13 @@ optional<MaskedIP> Condition::as_network(const string& s) {
     m.addr |= Address(a.sin6_addr.s6_addr[15]) << 120;
   } else {
     struct sockaddr_in a;
-    if (inet_pton(AF_INET, p->c_str(), static_cast<void*>(&a)) != 1) {
+    if (inet_pton(AF_INET, p->c_str(), static_cast<void*>(&a.sin_addr)) != 1) {
       return none;
     }
     m.addr = ntohl(a.sin_addr.s_addr);
   }
 
-  return none;
+  return m;
 }
 
 namespace {
index 73aa0ed543716abb80530aa9b728f68431b8423f..f6b0cd9a820624dfa02a889e9305c88a3490914c 100644 (file)
@@ -603,7 +603,7 @@ rgw::IAM::Environment rgw_build_iam_environment(RGWRados* store,
     e.emplace("aws:SecureTransport", "true");
   }
 
-  i = m.find("HTTP_HOST");
+  i = m.find("REMOTE_ADDR");
   if (i != m.end()) {
     e.emplace("aws:SourceIp", i->second);
   }