You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2016/06/16 19:42:23 UTC

[1/4] mesos git commit: Added note about generation of ExecutorInfo for CommandInfo.

Repository: mesos
Updated Branches:
  refs/heads/master 5f252e16c -> 2f04e4c44


Added note about generation of ExecutorInfo for CommandInfo.

In case of a task specifies a CommandInfo the agent will implictly
generate an ExecutorInfo.

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


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

Branch: refs/heads/master
Commit: 2f04e4c441d24bb03c27be2486eb890f0aa1ac33
Parents: 9aa14af
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Thu Jun 16 20:06:04 2016 +0200
Committer: Till Toenshoff <to...@me.com>
Committed: Thu Jun 16 21:24:46 2016 +0200

----------------------------------------------------------------------
 docs/app-framework-development-guide.md | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2f04e4c4/docs/app-framework-development-guide.md
----------------------------------------------------------------------
diff --git a/docs/app-framework-development-guide.md b/docs/app-framework-development-guide.md
index 78d8f36..6d283db 100644
--- a/docs/app-framework-development-guide.md
+++ b/docs/app-framework-development-guide.md
@@ -307,6 +307,10 @@ message TaskInfo {
 The Mesos slave will fill in the rest of the `ExecutorInfo` for you when tasks
 are specified this way.
 
+Note that the agent will derive an `ExecutorInfo` from the `TaskInfo` and
+additionally copy fields (e.g., `Labels`) from `TaskInfo` into the new
+`ExecutorInfo`. This `ExecutorInfo` is only visible on the agent.
+
 ### Creating a custom Framework Executor
 
 If your framework has special requirements, you might want to provide your own


[3/4] mesos git commit: Added tests for sandbox authorization.

Posted by ti...@apache.org.
Added tests for sandbox authorization.

We add tests for checking whether the LocalAuthorizer authorizes
sandbox access as expected. Furthermore we extend the
'Get_ExecutorInfo' test to check for correct copying of fields
which are relevant to authorization.

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


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

Branch: refs/heads/master
Commit: 9aa14af3b7e151c624b30b9b7c197bc04e25cf80
Parents: dce0845
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Thu Jun 16 20:05:29 2016 +0200
Committer: Till Toenshoff <to...@me.com>
Committed: Thu Jun 16 21:24:46 2016 +0200

----------------------------------------------------------------------
 src/tests/authorization_tests.cpp | 154 +++++++++++++++++++++++++++++++++
 src/tests/slave_tests.cpp         |  16 ++++
 2 files changed, 170 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9aa14af3/src/tests/authorization_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/authorization_tests.cpp b/src/tests/authorization_tests.cpp
index ef49ec6..c133f52 100644
--- a/src/tests/authorization_tests.cpp
+++ b/src/tests/authorization_tests.cpp
@@ -2103,6 +2103,160 @@ TYPED_TEST(AuthorizationTest, ViewExecutor)
 }
 
 
+// This tests the authorization of sandboxe access.
+TYPED_TEST(AuthorizationTest, SandBoxAccess)
+{
+  // Setup ACLs.
+  ACLs acls;
+
+  {
+    // "foo" principal cannot view any sandboxes.
+    mesos::ACL::AccessSandbox* acl = acls.add_access_sandboxes();
+    acl->mutable_principals()->add_values("foo");
+    acl->mutable_users()->set_type(mesos::ACL::Entity::NONE);
+  }
+
+  {
+    // "bar" principal can see sandboxes running under user "bar".
+    mesos::ACL::AccessSandbox* acl = acls.add_access_sandboxes();
+    acl->mutable_principals()->add_values("bar");
+    acl->mutable_users()->add_values("bar");
+  }
+
+  {
+    // "ops" principal can see all sandboxes.
+    mesos::ACL::AccessSandbox* acl = acls.add_access_sandboxes();
+    acl->mutable_principals()->add_values("ops");
+    acl->mutable_users()->set_type(mesos::ACL::Entity::ANY);
+  }
+
+  {
+    // No one else can view any sandboxes.
+    mesos::ACL::AccessSandbox* acl = acls.add_access_sandboxes();
+    acl->mutable_principals()->set_type(mesos::ACL::Entity::ANY);
+    acl->mutable_users()->set_type(mesos::ACL::Entity::NONE);
+  }
+
+  // Create an `Authorizer` with the ACLs.
+  Try<Authorizer*> create = TypeParam::create(parameterize(acls));
+  ASSERT_SOME(create);
+  Owned<Authorizer> authorizer(create.get());
+
+  // Create ExecutorInfo with a user not mentioned in the ACLs in
+  // command as object to be authorized.
+  ExecutorInfo executorInfo;
+  {
+    executorInfo.set_name("Task");
+    executorInfo.mutable_executor_id()->set_value("t");
+    executorInfo.mutable_command()->set_value("echo hello");
+    executorInfo.mutable_command()->set_user("user");
+  }
+
+  // Create ExecutorInfo with user "bar" in command as object to
+  // be authorized.
+  ExecutorInfo executorInfoBar;
+  {
+    executorInfoBar.set_name("Executor");
+    executorInfoBar.mutable_executor_id()->set_value("e");
+    executorInfoBar.mutable_command()->set_value("echo hello");
+    executorInfoBar.mutable_command()->set_user("bar");
+  }
+
+  // Create ExecutorInfo with no user in command as object to
+  // be authorized.
+  ExecutorInfo executorInfoNoUser;
+  {
+    executorInfoNoUser.set_name("Executor");
+    executorInfoNoUser.mutable_executor_id()->set_value("e");
+    executorInfoNoUser.mutable_command()->set_value("echo hello");
+  }
+
+  // Create FrameworkInfo with a generic user as object to authorized.
+  FrameworkInfo frameworkInfo;
+  {
+    frameworkInfo.set_user("user");
+    frameworkInfo.set_name("f");
+  }
+
+  // Create FrameworkInfo with user "bar" as object to authorized.
+  FrameworkInfo frameworkInfoBar;
+  {
+    frameworkInfoBar.set_user("bar");
+    frameworkInfoBar.set_name("f");
+  }
+
+  // Principal "foo" cannot access a sandbox with a request with
+  // ExecutorInfo and FrameworkInfo running with user "user".
+  {
+    authorization::Request request;
+    request.set_action(authorization::ACCESS_SANDBOX);
+    request.mutable_subject()->set_value("foo");
+    request.mutable_object()->mutable_executor_info()->MergeFrom(executorInfo);
+    request.mutable_object()->mutable_framework_info()->MergeFrom(
+        frameworkInfo);
+
+    AWAIT_EXPECT_FALSE(authorizer.get()->authorized(request));
+  }
+
+  // Principal "bar" cannot access a sandbox with a request with
+  // ExecutorInfo and FrameworkInfo running with user "user".
+  {
+    authorization::Request request;
+    request.set_action(authorization::ACCESS_SANDBOX);
+    request.mutable_subject()->set_value("bar");
+    request.mutable_object()->mutable_executor_info()->MergeFrom(executorInfo);
+    request.mutable_object()->mutable_framework_info()->MergeFrom(
+        frameworkInfo);
+
+    AWAIT_EXPECT_FALSE(authorizer.get()->authorized(request));
+  }
+
+  // Principal "ops" can access a sandbox with a request with
+  // ExecutorInfo and FrameworkInfo running with user "user".
+  {
+    authorization::Request request;
+    request.set_action(authorization::ACCESS_SANDBOX);
+    request.mutable_subject()->set_value("ops");
+    request.mutable_object()->mutable_executor_info()->MergeFrom(executorInfo);
+    request.mutable_object()->mutable_framework_info()->MergeFrom(
+      frameworkInfo);
+
+    AWAIT_EXPECT_TRUE(authorizer.get()->authorized(request));
+  }
+
+  // Principal "bar" can access a sandbox with a request with
+  // ExecutorInfo and FrameworkInfo running with user "bar".
+  {
+    authorization::Request request;
+    request.set_action(authorization::ACCESS_SANDBOX);
+    request.mutable_subject()->set_value("bar");
+    request.mutable_object()->mutable_executor_info()->MergeFrom(
+        executorInfoBar);
+
+    request.mutable_object()->mutable_framework_info()->MergeFrom(
+        frameworkInfoBar);
+
+    AWAIT_EXPECT_TRUE(authorizer.get()->authorized(request));
+  }
+
+  // Principal "bar" can access a sandbox with a request with a
+  // ExecutorInfo without user and FrameworkInfo running with user
+  // "bar".
+  {
+    authorization::Request request;
+    request.set_action(authorization::ACCESS_SANDBOX);
+    request.mutable_subject()->set_value("bar");
+    request.mutable_object()->mutable_executor_info()->MergeFrom(
+        executorInfoNoUser);
+
+    request.mutable_object()->mutable_framework_info()->MergeFrom(
+        frameworkInfoBar);
+
+    AWAIT_EXPECT_TRUE(authorizer.get()->authorized(request));
+  }
+}
+
+
 // This tests that a missing request.object is allowed for an ACL whose
 // Object is ANY.
 // NOTE: The only usecase for this behavior is currently teardownFramework.

http://git-wip-us.apache.org/repos/asf/mesos/blob/9aa14af3/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index 7ba03e8..12be60c 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -663,12 +663,28 @@ TEST_F(SlaveTest, GetExecutorInfo)
 
   task.mutable_command()->MergeFrom(command);
 
+  DiscoveryInfo* info = task.mutable_discovery();
+  info->set_visibility(DiscoveryInfo::EXTERNAL);
+  info->set_name("mytask");
+  info->set_environment("mytest");
+  info->set_location("mylocation");
+  info->set_version("v0.1.1");
+
+  Labels* labels = task.mutable_labels();
+  labels->add_labels()->CopyFrom(createLabel("label1", "key1"));
+  labels->add_labels()->CopyFrom(createLabel("label2", "key2"));
+
   const ExecutorInfo& executor = slave.getExecutorInfo(frameworkInfo, task);
 
   // Now assert that it actually is running mesos-executor without any
   // bleedover from the command we intend on running.
   EXPECT_TRUE(executor.command().shell());
   EXPECT_EQ(0, executor.command().arguments_size());
+  ASSERT_TRUE(executor.has_labels());
+  EXPECT_EQ(2, executor.labels().labels_size());
+  ASSERT_TRUE(executor.has_discovery());
+  ASSERT_TRUE(executor.discovery().has_name());
+  EXPECT_EQ("mytask", executor.discovery().name());
   EXPECT_NE(string::npos, executor.command().value().find("mesos-executor"));
 }
 


[2/4] mesos git commit: Added 'labels' and 'discovery' to derived ExecutorInfo.

Posted by ti...@apache.org.
Added 'labels' and 'discovery' to derived ExecutorInfo.

If a task uses a CommandExecutor Mesos generates a special
ExecutorInfo inside the agent. As these fields might be relevant
to authorization it now receives Labels and DiscoveryInfo from
the source TaskInfo.

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


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

Branch: refs/heads/master
Commit: dce084594d7c8a76fd02b8803b4f46087d669744
Parents: c8d6759
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Thu Jun 16 20:03:22 2016 +0200
Committer: Till Toenshoff <to...@me.com>
Committed: Thu Jun 16 21:24:46 2016 +0200

----------------------------------------------------------------------
 src/slave/slave.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dce08459/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 27a206f..f46fc01 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -3913,6 +3913,17 @@ ExecutorInfo Slave::getExecutorInfo(
           task.command().environment());
     }
 
+    // Add fields which can be relevant (depending on Authorizer) for
+    // authorization.
+
+    if (task.has_labels()) {
+      executor.mutable_labels()->MergeFrom(task.labels());
+    }
+
+    if (task.has_discovery()) {
+      executor.mutable_discovery()->MergeFrom(task.discovery());
+    }
+
     // Adjust the executor shutdown grace period if the kill policy is
     // set. We add a small buffer of time to avoid destroying the
     // container before `TASK_KILLED` is sent by the executor.


[4/4] mesos git commit: Refactored sandbox authorization logic to use ObjectAuthorizer.

Posted by ti...@apache.org.
Refactored sandbox authorization logic to use ObjectAuthorizer.

Previously the sandbox authorization used the Request object based
authorization interface. Additionally this review fixes some issues
with sandbox authorization object handling  in the LocalAuthorizer.

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


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

Branch: refs/heads/master
Commit: c8d67590064e35566274116cede9c6a733187b48
Parents: 5f252e1
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Thu Jun 16 20:02:49 2016 +0200
Committer: Till Toenshoff <to...@me.com>
Committed: Thu Jun 16 21:24:46 2016 +0200

----------------------------------------------------------------------
 src/authorizer/local/authorizer.cpp |  9 +++----
 src/slave/slave.cpp                 | 46 +++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c8d67590/src/authorizer/local/authorizer.cpp
----------------------------------------------------------------------
diff --git a/src/authorizer/local/authorizer.cpp b/src/authorizer/local/authorizer.cpp
index 3c0fe04..558f332 100644
--- a/src/authorizer/local/authorizer.cpp
+++ b/src/authorizer/local/authorizer.cpp
@@ -238,14 +238,13 @@ public:
           break;
         }
         case authorization::ACCESS_SANDBOX: {
-          // Check object has the required types set.
-          CHECK_NOTNULL(object->executor_info);
-          CHECK_NOTNULL(object->framework_info);
+          aclObject.set_type(mesos::ACL::Entity::ANY);
 
-          if (object->executor_info->command().has_user()) {
+          if (object->executor_info != NULL &&
+              object->executor_info->command().has_user()) {
             aclObject.add_values(object->executor_info->command().user());
             aclObject.set_type(mesos::ACL::Entity::SOME);
-          } else {
+          } else if (object->framework_info != NULL) {
             aclObject.add_values(object->framework_info->user());
             aclObject.set_type(mesos::ACL::Entity::SOME);
           }

http://git-wip-us.apache.org/repos/asf/mesos/blob/c8d67590/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index f7a52fc..27a206f 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -5418,26 +5418,46 @@ Future<bool> Slave::authorizeSandboxAccess(
     return true;
   }
 
-  authorization::Request request;
-  request.set_action(authorization::ACCESS_SANDBOX);
+  // Set authorization subject.
+  authorization::Subject subject;
 
   if (principal.isSome()) {
-    request.mutable_subject()->set_value(principal.get());
+    subject.set_value(principal.get());
   }
 
-  if (frameworks.contains(frameworkId)) {
-    Framework* framework = frameworks.get(frameworkId).get();
+  Future<Owned<ObjectApprover>> sandboxApprover =
+    authorizer.get()->getObjectApprover(subject, authorization::ACCESS_SANDBOX);
 
-    request.mutable_object()->mutable_framework_info()->CopyFrom(
-        framework->info);
+  return sandboxApprover
+    .then(defer(self(),
+        [this, &frameworkId, &executorId]
+            (const Owned<ObjectApprover>& sandboxApprover)
+            -> Future<bool> {
+        // Construct authorization object.
+        ObjectApprover::Object object;
 
-    if (framework->executors.contains(executorId)) {
-      request.mutable_object()->mutable_executor_info()->CopyFrom(
-          framework->executors.get(executorId).get()->info);
-    }
-  }
+        if (frameworks.contains(frameworkId)) {
+          Framework* framework = frameworks.get(frameworkId).get();
 
-  return authorizer.get()->authorized(request);
+          object.framework_info = &(framework->info);
+
+          if (framework->executors.contains(executorId)) {
+            object.executor_info =
+              &(framework->executors.get(executorId).get()->info);
+          }
+        }
+
+        Try<bool> approved = sandboxApprover.get()->approved(object);
+
+        if (approved.isError()) {
+          return Failure("Error during sandbox authorization: " +
+                         approved.error());
+        }
+        return approved.get();
+    }))
+    .repair([](const Future<bool>) {
+      return Failure("Error during sandbox authorization");
+    });
 }