You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ka...@apache.org on 2016/04/26 19:26:53 UTC

[02/13] mesos git commit: Added a realm parameter to 'process::initialize' (Mesos).

Added a realm parameter to 'process::initialize' (Mesos).

In order to enable authentication on libprocess-level
HTTP endpoints, this patch adds code to the master and
agent's main.cpp file which makes use of the new
`authenticationRealm` argument to `process::initialize`
which allows the authentication realm of such endpoints
to be set when libprocess is initialized. The argument is
added to libprocess initialization in the tests as well.

Review: https://reviews.apache.org/r/46255/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/23bff549
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/23bff549
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/23bff549

Branch: refs/heads/master
Commit: 23bff549128c50586d34cda110e6f02021242973
Parents: 3d78119
Author: Greg Mann <gr...@mesosphere.io>
Authored: Tue Apr 26 10:42:42 2016 -0400
Committer: Kapil Arya <ka...@mesosphere.io>
Committed: Tue Apr 26 10:42:42 2016 -0400

----------------------------------------------------------------------
 src/master/main.cpp | 10 ++++++++--
 src/slave/main.cpp  |  8 +++++++-
 src/tests/main.cpp  | 10 ++++++++--
 src/tests/mesos.hpp |  2 ++
 4 files changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/23bff549/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index e1b6d48..23149d5 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -240,8 +240,14 @@ int main(int argc, char** argv)
     }
   }
 
-  // Initialize libprocess.
-  process::initialize("master");
+  // This should be the first invocation of `process::initialize`. If it returns
+  // `false`, then it has already been called, which means that the
+  // authentication realm for libprocess-level HTTP endpoints was not set to the
+  // correct value for the master.
+  if (!process::initialize("master", DEFAULT_HTTP_AUTHENTICATION_REALM)) {
+    EXIT(EXIT_FAILURE) << "The call to `process::initialize()` in the master's "
+                       << "`main()` was not the function's first invocation";
+  }
 
   logging::initialize(argv[0], flags, true); // Catch signals.
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/23bff549/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index 3ea1453..fee46ba 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -211,7 +211,13 @@ int main(int argc, char** argv)
 
   const string id = process::ID::generate("slave"); // Process ID.
 
-  process::initialize(id);
+  // If `process::initialize()` returns `false`, then it was called before this
+  // invocation, meaning the authentication realm for libprocess-level HTTP
+  // endpoints was set incorrectly. This should be the first invocation.
+  if (!process::initialize(id, DEFAULT_HTTP_AUTHENTICATION_REALM)) {
+    EXIT(EXIT_FAILURE) << "The call to `process::initialize()` in the agent's "
+                       << "`main()` was not the function's first invocation";
+  }
 
   logging::initialize(argv[0], flags, true); // Catch signals.
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/23bff549/src/tests/main.cpp
----------------------------------------------------------------------
diff --git a/src/tests/main.cpp b/src/tests/main.cpp
index 1425850..c3ccf91 100644
--- a/src/tests/main.cpp
+++ b/src/tests/main.cpp
@@ -31,6 +31,7 @@
 
 #include "tests/environment.hpp"
 #include "tests/flags.hpp"
+#include "tests/mesos.hpp"
 #include "tests/module.hpp"
 
 using namespace mesos::internal;
@@ -74,8 +75,13 @@ int main(int argc, char** argv)
   // overwrite whatever the user set.
   os::setenv("LIBPROCESS_METRICS_SNAPSHOT_ENDPOINT_RATE_LIMIT", "", false);
 
-  // Initialize libprocess.
-  process::initialize();
+  // If `process::initialize()` returns `false`, then it was called before this
+  // invocation, meaning the authentication realm for libprocess-level HTTP
+  // endpoints was set incorrectly. This should be the first invocation.
+  if (!process::initialize(None(), DEFAULT_HTTP_AUTHENTICATION_REALM)) {
+    EXIT(EXIT_FAILURE) << "The call to `process::initialize()` in the tests' "
+                       << "`main()` was not the function's first invocation";
+  }
 
   // Be quiet by default!
   if (!flags.verbose) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/23bff549/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index bff7938..78edab8 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -98,6 +98,8 @@ namespace mesos {
 namespace internal {
 namespace tests {
 
+constexpr char DEFAULT_HTTP_AUTHENTICATION_REALM[] = "test-realm";
+
 // Forward declarations.
 class MockExecutor;