Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-71687

Support using Mongo shell to imitate internal clients

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Service Arch

      There are tests that use the Mongo shell to imitate an internal client. For example, see the following:

      ...
      const testInternalClient = (function createInternalClient() {
          const connInternal = new Mongo(testDB.getMongo().host);
          const curDB = connInternal.getDB(dbName);
          assert.commandWorked(curDB.runCommand({
              ["hello"]: 1,
              internalClient: {minWireVersion: NumberInt(0), maxWireVersion: NumberInt(7)}
          }));
          return connInternal;
      })();
      ...
      

      Currently, we rely on the global WireSpec to identify internal clients. This ticket should provide support for creating new shell connections that are considered to be originating form an internal client (i.e., by appending the internalClient field to the initial hello command).

      For context, using Mongo to create a new database connection results in calling the following:

      // "new Mongo(uri, encryptedDBClientCallback, {options...})"
      void MongoExternalInfo::construct(JSContext* cx, JS::CallArgs args) {
          ...
          auto cs = uassertStatusOK(MongoURI::parse(host));
          ...
          std::unique_ptr<DBClientBase> conn(
              cs.connect(appname.value_or("MongoDB Shell"), errmsg, boost::none, &apiParameters));
          ...
      }
      

      Which calls into DBClientConnection::connect and initWireVersion . This internally uses the global WireSpec to decide if the initial hello command, sent to initiate the client/server handshake, should include the internalClient field:

      ...
          if (auto wireSpec = WireSpec::instance().get(); wireSpec->isInternalClient) {
              WireSpec::appendInternalClientWireVersion(wireSpec->outgoing, &bob);
          }
      ...
      

      However, WireSpec is a global construct that is initialized at startup, and we only consider connections originating from MongoD and MongoS to come from internal clients (e.g., see here).

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            amirsaman.memaripour@mongodb.com Amirsaman Memaripour
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: