Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3224

autoEncryption with username password in connection string uri produces warning options credentials is not supported

      When I try to use autoEncryption with username and password inside connection string uri, there is terminal output:

      (node:934467) [MONGODB DRIVER] Warning: the options [credentials] is not supported

      This warning start show at mongodb version 3.6.6. Previous version (3.6.5) not show.

      I use:

      • module mongodb 3.6.6
      • module mongodb-client-encryption 1.2.3
      • mongo from dockerhub 4.4.3-bionic
      • node 12.18.3, typescript 4.1.3

      I use this sample code.

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import fs from 'fs';
      import { MongoClient, MongoClientOptions } from 'mongodb';
      import { ClientEncryption } from 'mongodb-client-encryption';
      
      process.on('uncaughtException', (ex) => {
        console.error('Uncaught Exception: %s', ex.message);
      });
      
      process.on('unhandledRejection', (re) => {
        console.error('Unahandled Rejection: %s', re);
        process.exit(1);
      });
      
      (async () => {
        const uri = 'mongodb://test:test@172.17.0.2:27017?poolSize=2&authSource=admin';
        console.log('URI: %s', uri);  
        const masterKey = fs.readFileSync('master-key.txt');
        console.log('Master Key Read');  
        const client = new MongoClient(uri, {
          appname: 'mongenc-plain',
          useUnifiedTopology: true,
          useNewUrlParser: true,
        } as MongoClientOptions);
        console.log('Try to connect');
        await client.connect();
        console.log('Client connected');  
        const dbName = 'test';
        const collName = 'col';
        const keyVaultNamespace = `${dbName}.datakeys`;
        const kmsProviders = {
          local: {
            key: masterKey,
          },
        };
        // Create new ClientEncryption.
        const clientEncryption = new ClientEncryption(client, {
          kmsProviders,
          keyVaultNamespace,
        })  
        // Check for mySpecialKey.
        const db = client.db(dbName);
        const col = db.collection('datakeys');
        const resultDK = await col.find({ keyAltNames: 'mySpecialKey'}).limit(1).toArray();
        const dataKeyId = (typeof resultDK[0] !== 'undefined')
          ? resultDK[0]._id
          : await clientEncryption.createDataKey('local', { keyAltNames: ['mySpecialKey'] });  
        const schemaMap = {
          [`${dbName}.${collName}`]: {
            bsonType: 'object',
            properties: {
              encryptedField: {
                encrypt: {
                  keyId: [ dataKeyId ],
                  bsonType: 'string',
                  algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'
                }
              }
            }
          }
        };  
        const encryptedClient = new MongoClient(uri, {
          appname: 'mongenc-secure',
          useUnifiedTopology: true,
          autoEncryption: {
            keyVaultNamespace,
            kmsProviders,
            schemaMap,
            extraOptions: {
              mongocryptdSpawnPath: './bin/mongocryptd',
              mongocryptdSpawnArgs: ['--nounixsocket'],
            },
          },
        } as any);  
        await encryptedClient.connect();
        console.log('Encrypted client connect.');  
        const dbSecure= encryptedClient.db(dbName);
        const collectionSecure = dbSecure.collection(collName);  
        const sampleString = new Date().toISOString();
        console.log('Sample String:', sampleString);  
        await collectionSecure.insertOne({ encryptedField: sampleString });
        const result = await collectionSecure.findOne({
          encryptedField: { $eq: sampleString },
        });
        console.log(result);  
      
        await encryptedClient.close();
        await client.close();
        console.log('Close client');
      })();
      

       When I run the code, these are output at terminal.

       

      URI: mongodb://test:test@172.17.0.2:27017?poolSize=2&authSource=admin
      Master Key Read
      Try to connect
      Client connected
      (node:935159) [MONGODB DRIVER] Warning: Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
      (node:935159) [MONGODB DRIVER] Warning: the options [poolsize] is not supported
      (node:935159) [MONGODB DRIVER] Warning: the options [credentials] is not supported
      Encrypted client connect.
      Sample String: 2021-04-23T15:31:12.015Z
      {
       _id: 6082e8400fdd7a4505ddaa45,
       encryptedField: '2021-04-23T15:31:12.015Z'
      }
      Close client

      Field encryptedField gets encrypted successfully, but I see output [MONGODB DRIVER] Warning for options credentials. There is also warning for poolsize (lowercase) when I use poolSize at connection string uri.

       

        1. Selection_235.png
          75 kB
          Andreas Yulius Nugroho

            Assignee:
            Unassigned Unassigned
            Reporter:
            andreas@alterra.id Andreas Yulius Nugroho
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: