]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: check cap before executing tell command
authorKefu Chai <kchai@redhat.com>
Tue, 19 Nov 2019 02:44:16 +0000 (10:44 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 20 Dec 2019 07:56:04 +0000 (15:56 +0800)
tell command is sent from a client from network, we need to authorize
the cap of client before executing the command sent by it.

in this change, the check for `session->caps.is_allow_all()` is removed,
because

- simpler this way
- `session->caps.is_capable()` also check it, and this code path is
  not a critical path, so no need for trading the simplicity for
  performance here.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/Monitor.cc

index b96f1071220e72d760744cd017208f9c038f5dd2..5baa2c9b5517aee6a50beab7e2fe8caf915d12ec 100644 (file)
@@ -3180,27 +3180,24 @@ void Monitor::handle_tell_command(MonOpRequestRef op)
     dout(5) << __func__ << " dropping stray message " << *m << dendl;
     return;
   }
-  if (!session->caps.is_allow_all()) {
-    // see if command is whitelisted
-    cmdmap_t cmdmap;
-    stringstream ss;
-    if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) {
-      return reply_tell_command(op, -EINVAL, ss.str());
-    }
-    map<string,string> param_str_map;
-    _generate_command_map(cmdmap, param_str_map);
-    string prefix;
-    if (!cmd_getval(g_ceph_context, cmdmap, "prefix", prefix)) {
-      return reply_tell_command(op, -EINVAL, "no prefix");
-    }
-    if (!session->caps.is_capable(
-         g_ceph_context,
-         session->entity_name,
-         "mon", prefix, param_str_map,
-         true, true, true,
-         session->get_peer_socket_addr())) {
-      return reply_tell_command(op, -EACCES, "insufficient caps");
-    }
+  cmdmap_t cmdmap;
+  if (stringstream ss; !cmdmap_from_json(m->cmd, &cmdmap, ss)) {
+    return reply_tell_command(op, -EINVAL, ss.str());
+  }
+  map<string,string> param_str_map;
+  _generate_command_map(cmdmap, param_str_map);
+  string prefix;
+  if (!cmd_getval(g_ceph_context, cmdmap, "prefix", prefix)) {
+    return reply_tell_command(op, -EINVAL, "no prefix");
+  }
+  // see if command is whitelisted
+  if (!session->caps.is_capable(
+      g_ceph_context,
+      session->entity_name,
+      "mon", prefix, param_str_map,
+      true, true, true,
+      session->get_peer_socket_addr())) {
+    return reply_tell_command(op, -EACCES, "insufficient caps");
   }
   // pass it to asok
   cct->get_admin_socket()->queue_tell_command(m);