mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject [1/3] mesos git commit: Added 'Master::authorize{Destroy, Create}Volume' to create/destroy persistent volumes.
Date Thu, 17 Dec 2015 22:06:26 GMT
Repository: mesos
Updated Branches:
  refs/heads/master a798048b2 -> da8e37841


Added 'Master::authorize{Destroy,Create}Volume' to create/destroy
persistent volumes.

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


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

Branch: refs/heads/master
Commit: da8e378415b08cdae3c00a3650db107acd731ed1
Parents: 92bf12e
Author: Greg Mann <greg@mesosphere.io>
Authored: Thu Dec 17 13:27:39 2015 -0800
Committer: Jie Yu <yujie.jay@gmail.com>
Committed: Thu Dec 17 14:06:16 2015 -0800

----------------------------------------------------------------------
 src/master/master.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 src/master/master.hpp | 42 ++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/da8e3784/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 0d14822..470b542 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -2819,6 +2819,71 @@ Future<bool> Master::authorizeUnreserveResources(
 }
 
 
+Future<bool> Master::authorizeCreateVolume(
+    const Offer::Operation::Create& create,
+    const Option<string>& principal)
+{
+  if (authorizer.isNone()) {
+    return true; // Authorization is disabled.
+  }
+
+  mesos::ACL::CreateVolume request;
+
+  if (principal.isSome()) {
+    request.mutable_principals()->add_values(principal.get());
+  } else {
+    request.mutable_principals()->set_type(ACL::Entity::ANY);
+  }
+
+  // TODO(greggomann): Determine what `volume_types` we may want to
+  // allow/prevent creation of. Currently, we simply use ANY.
+  request.mutable_volume_types()->set_type(ACL::Entity::ANY);
+
+  LOG(INFO)
+    << "Authorizing principal '"
+    << (principal.isSome() ? principal.get() : "ANY")
+    << "' to create volumes";
+
+  return authorizer.get()->authorize(request);
+}
+
+
+Future<bool> Master::authorizeDestroyVolume(
+    const Offer::Operation::Destroy& destroy,
+    const Option<string>& principal)
+{
+  if (authorizer.isNone()) {
+    return true; // Authorization is disabled.
+  }
+
+  mesos::ACL::DestroyVolume request;
+
+  if (principal.isSome()) {
+    request.mutable_principals()->add_values(principal.get());
+  } else {
+    request.mutable_principals()->set_type(ACL::Entity::ANY);
+  }
+
+  foreach (const Resource& volume, destroy.volumes()) {
+    // NOTE: Since validation of this operation may be performed after
+    // authorization, we must check here that this resource is a persistent
+    // volume. If it isn't, the error will be caught during validation.
+    if (Resources::isPersistentVolume(volume)) {
+      request.mutable_creator_principals()->add_values(
+          volume.disk().persistence().principal());
+    }
+  }
+
+  LOG(INFO)
+    << "Authorizing principal '"
+    << (principal.isSome() ? principal.get() : "ANY")
+    << "' to destroy volumes '"
+    << stringify(destroy.volumes()) << "'";
+
+  return authorizer.get()->authorize(request);
+}
+
+
 Resources Master::addTask(
     const TaskInfo& task,
     Framework* framework,

http://git-wip-us.apache.org/repos/asf/mesos/blob/da8e3784/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 9aa548a..7cb0e16 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -725,6 +725,48 @@ protected:
       const Offer::Operation::Unreserve& unreserve,
       const Option<std::string>& principal);
 
+  /**
+   * Authorizes a `CREATE` offer operation.
+   *
+   * Returns whether the Create operation is authorized with the provided
+   * principal. This function is used for authorization of operations
+   * originating both from frameworks and operators. Note that operations may be
+   * validated AFTER authorization, so it's possible that `create` could be
+   * malformed.
+   *
+   * @param create The `CREATE` operation to be performed.
+   * @param principal An `Option` containing the principal attempting this
+   *     operation.
+   *
+   * @return A `Future` containing a boolean value representing the success or
+   *     failure of this authorization. A failed `Future` implies that
+   *     validation of the operation did not succeed.
+   */
+  process::Future<bool> authorizeCreateVolume(
+      const Offer::Operation::Create& create,
+      const Option<std::string>& principal);
+
+  /**
+   * Authorizes a `DESTROY` offer operation.
+   *
+   * Returns whether the Destroy operation is authorized with the provided
+   * principal. This function is used for authorization of operations
+   * originating both from frameworks and operators. Note that operations may be
+   * validated AFTER authorization, so it's possible that `destroy` could be
+   * malformed.
+   *
+   * @param destroy The `DESTROY` operation to be performed.
+   * @param principal An `Option` containing the principal attempting this
+   *     operation.
+   *
+   * @return A `Future` containing a boolean value representing the success or
+   *     failure of this authorization. A failed `Future` implies that
+   *     validation of the operation did not succeed.
+   */
+  process::Future<bool> authorizeDestroyVolume(
+      const Offer::Operation::Destroy& destroy,
+      const Option<std::string>& principal);
+
   // Add the task and its executor (if not already running) to the
   // framework and slave. Returns the resources consumed as a result,
   // which includes resources for the task and its executor


Mime
View raw message