[SERVER-65459] Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands Created: 11/Apr/22  Updated: 29/Oct/23  Resolved: 14/Jul/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.1.0-rc0

Type: Task Priority: Major - P3
Reporter: Janna Golden Assignee: Sophia Tan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-64608 Add tenantID to NamespaceString Closed
depends on SERVER-65458 Parse and validate tenantId at the st... Closed
Problem/Incident
Backwards Compatibility: Fully Compatible
Sprint: Server Serverless 2022-05-30, Server Serverless 2022-06-13, Server Serverless 2022-06-27, Server Serverless 2022-07-11, Server Serverless 2022-07-25
Participants:
Linked BF Score: 168

 Description   

For any commands that use concatenate_with_db, we'll pass the tenantId, if it exists on the opMsgRequest, to the NamespaceString constructor. In order to do this, we'll need to pass tenantId to gen_namespace_check() (we'll need to pass it through _gen_command_deserializer())- it can default to None for both functions. In CommandWithNamespaceTypeInfo::gen_namespace_check(), pass this tenantId to IDLParserErrorContext::parseNSCollectionRequired. We'll have to add tenantId as an optional parameter to IDLParserErrorContext::parseNSCollectionRequired.

Once this is done, we should be able to successfully run some commands on a standalone mongod (or perhaps a single node RS) using either a securityToken or the $tenant field to pass the tenantId. Only commands which are IDL defined will work at this point, let's write a simple workload that runs create collection, some CRUD ops, and find commands using both the securityToken and $tenant.

Here are the example idl generated cpp code:

-  for constructing the "to" field of "renameCollection"

if (MONGO_likely(ctxt.checkAndAssertType(commandElement, String))) {
           _commandParameter = NamespaceString(request.getValidatedTenantId(), commandElement.valueStringData());
       }
       else {
           ctxt.throwMissingField(kCommandParameterFieldName);
       }
   } 

-  for constructing the nss from command feild of "renameCollection" cmd. Its cmd namespace is "namespace: type".

   {
        if (MONGO_likely(ctxt.checkAndAssertType(commandElement, String))) {
            _commandParameter = NamespaceString(request.getValidatedTenantId(), commandElement.valueStringData());
        }
        else {
            ctxt.throwMissingField(kCommandParameterFieldName);
        }
    }

-  for constructing the nss from db name and command field of "insert" cmd. Its cmd namespace is "namespace: concatenate_with_db".

    invariant(_nss.isEmpty());
    DatabaseName dbName(request.getValidatedTenantId(), _dbName);
    _nss = ctxt.parseNSCollectionRequired(dbName, commandElement, false);



 Comments   
Comment by Githook User [ 13/Jul/22 ]

Author:

{'name': 'Sophia Tan', 'email': 'sophia_tll@hotmail.com', 'username': 'sophiatll'}

Message: SERVER-65459 Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands
Branch: master
https://github.com/mongodb/mongo/commit/79b17eb848026e2b9d5ea3c5b99212ecc56157b9

Comment by Githook User [ 12/Jul/22 ]

Author:

{'name': 'jannaerin', 'email': 'golden.janna@gmail.com', 'username': 'jannaerin'}

Message: Revert "SERVER-65459 Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands"

This reverts commit c340d5a7a891758510728997c839f8e8d7e5eaa0.
Branch: master
https://github.com/mongodb/mongo/commit/ac1ca195885cd42bb2ae7ac9a892c93425082669

Comment by Githook User [ 11/Jul/22 ]

Author:

{'name': 'Sophia Tan', 'email': 'sophia_tll@hotmail.com', 'username': 'sophiatll'}

Message: SERVER-65459 Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands
Branch: master
https://github.com/mongodb/mongo/commit/c340d5a7a891758510728997c839f8e8d7e5eaa0

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