[SERVER-71687] Support using Mongo shell to imitate internal clients Created: 29/Nov/22  Updated: 20/Nov/23

Status: Backlog
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Amirsaman Memaripour Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Gantt Dependency
has to be done before SERVER-56392 Don't allow clients to change the val... Backlog
Assigned Teams:
Service Arch
Participants:

 Description   

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).



 Comments   
Comment by Huayu Ouyang [ 20/Nov/23 ]

I believe there's not a specific team that owns the legacy shell/mongo test runner, but I think it might fit with the backlog-server-servicearch team

Generated at Thu Feb 08 06:19:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.