]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: add helper function rgw_transport_is_secure()
authorCasey Bodley <cbodley@redhat.com>
Mon, 22 Oct 2018 18:13:21 +0000 (14:13 -0400)
committerCasey Bodley <cbodley@redhat.com>
Mon, 22 Oct 2018 18:56:22 +0000 (14:56 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h

index 4ce812f139743efff0a934ca761b645d24f0d3ff..466fa42c13544c982c0984e7335091521e110e4f 100644 (file)
@@ -1044,6 +1044,31 @@ string RGWHTTPArgs::sys_get(const string& name, bool * const exists) const
   return e ? iter->second : string();
 }
 
+bool rgw_transport_is_secure(CephContext *cct, const RGWEnv& env)
+{
+  const auto& m = env.get_map();
+  // frontend connected with ssl
+  if (m.count("SERVER_PORT_SECURE")) {
+    return true;
+  }
+  // ignore proxy headers unless explicitly enabled
+  if (!cct->_conf->rgw_trust_forwarded_https) {
+    return false;
+  }
+  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
+  // Forwarded: by=<identifier>; for=<identifier>; host=<host>; proto=<http|https>
+  auto i = m.find("HTTP_FORWARDED");
+  if (i != m.end() && i->second.find("proto=https") != std::string::npos) {
+    return true;
+  }
+  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
+  i = m.find("HTTP_X_FORWARDED_PROTO");
+  if (i != m.end() && i->second == "https") {
+    return true;
+  }
+  return false;
+}
+
 namespace {
 Effect eval_or_pass(const boost::optional<Policy>& policy,
                    const rgw::IAM::Environment& env,
index 10c41370c92623de1a9289723645583209bfb7f8..0fcdca142c92d6b57f1d21d60c6d51d33ce2ab83 100644 (file)
@@ -437,6 +437,10 @@ public:
   }
 };
 
+// return true if the connection is secure. this either means that the
+// connection arrived via ssl, or was forwarded as https by a trusted proxy
+bool rgw_transport_is_secure(CephContext *cct, const RGWEnv& env);
+
 enum http_op {
   OP_GET,
   OP_PUT,