From: yuliyang Date: Mon, 27 Nov 2017 06:32:44 +0000 (+0800) Subject: rgw: implement ipv4 aws:SourceIp condition for bucket policy X-Git-Tag: v12.2.3~207^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7cca4a6c1034ce32c41b73bace538965c5e77a8c;p=ceph.git rgw: implement ipv4 aws:SourceIp condition for bucket policy Signed-off-by: yuliyang (cherry picked from commit 2fb445b6f7c1e997e83b1c7da2a1fecdde164d35) --- diff --git a/src/rgw/rgw_asio_client.cc b/src/rgw/rgw_asio_client.cc index 63de2d27e757..1211c8362de4 100644 --- a/src/rgw/rgw_asio_client.cc +++ b/src/rgw/rgw_asio_client.cc @@ -78,6 +78,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 } diff --git a/src/rgw/rgw_iam_policy.cc b/src/rgw/rgw_iam_policy.cc index cff4fa493351..745d28afffb7 100644 --- a/src/rgw/rgw_iam_policy.cc +++ b/src/rgw/rgw_iam_policy.cc @@ -1059,7 +1059,8 @@ optional 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; @@ -1082,7 +1083,7 @@ optional Condition::as_network(const string& s) { if (m.v6) { struct sockaddr_in6 a; - if (inet_pton(AF_INET6, p->c_str(), static_cast(&a)) != 1) { + if (inet_pton(AF_INET6, p->c_str(), static_cast(&a.sin6_addr)) != 1) { return none; } @@ -1104,13 +1105,13 @@ optional 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(&a)) != 1) { + if (inet_pton(AF_INET, p->c_str(), static_cast(&a.sin_addr)) != 1) { return none; } m.addr = ntohl(a.sin_addr.s_addr); } - return none; + return m; } namespace { diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index e951b61cf303..3738dbd074f5 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -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); }