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

Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • 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
    • 168

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

            Assignee:
            sophia.tan@mongodb.com Sophia Tan
            Reporter:
            janna.golden@mongodb.com Janna Golden
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: