简体   繁体   English

如何设置 mongoDB 的新 CSFLE 功能,使用 nodejs 进行显式加密隐式解密?

[英]How do I set up mongoDB's new CSFLE feature, with explicit encryption implicit decryption using nodejs?

I'm trying to use MongoDB's Client-Side Filed Level Encryption feature with the community edition.我正在尝试将 MongoDB 的客户端文件级加密功能与社区版一起使用。 I'm not interested in the auto-encryption feature.我对自动加密功能不感兴趣。 However, we need the auto-decryption feature which as per the docs is possible in the community edition as well.但是,我们需要自动解密功能,根据文档,社区版也可以使用该功能。

We generally use mongoose in our application but I tried with native nodejs driver as well.我们通常在我们的应用程序中使用 mongoose,但我也尝试使用本机 nodejs 驱动程序。 Here's the code I'm using to create the connection.这是我用来创建连接的代码。 This works fine if I comment out the autoEncryption object. Doing so allows me to encrypt manually, but this way we will also have to decrypt manually, which kind of beats the purpose.如果我注释掉autoEncryption object,这很好用。这样做允许我手动加密,但这样我们也必须手动解密,这就达到了目的。

Some docs suggest adding bypassAutoEncryption: true with extraOptions object to the autoEncryption object. I've treid that as well as seen below.一些文档建议将bypassAutoEncryption: true with extraOptions object 添加到autoEncryption object 中。我已经尝试过了,如下所示。

const secureClient = new MongoClient('mongodb://someUri', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    autoEncryption: {
        keyVaultNamespace,
        kmsProviders,
        bypassAutoEncryption: true,
        extraOptions: {
            // mongocryptdBypassSpawn: true,
            mongocryptdSpawnArgs: [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port", "27021"],
            mongocryptdURI: "mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000"
        },
    }
});

My code is working till generating the master key, data-key and explicitly encrypting the data.我的代码一直有效,直到生成主密钥、数据密钥并显式加密数据。 Unfortunately, I haven't been able to set up the auto-decryption.不幸的是,我无法设置自动解密。 To configure the client with CSFLE options the autoEncryption has to be passed in the options.要使用CSFLE选项配置客户端,必须在选项中传递自动加密。 But whenever I pass this option, I get the following exception但是每当我通过这个选项时,我都会得到以下异常

(node:53721) UnhandledPromiseRejectionWarning: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27021
    at Timeout._onTimeout (/Users/NiccsJ/ORI/code/testmongoEncryption/node_modules/mongodb/lib/sdam/topology.js:325:38)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)

I've followed almost all suggestions from the below refs.我已经遵循了以下参考文献中的几乎所有建议。 Surprisingly, mondodb-nodejs documentation doesn't even mention bypassAutoEncryption .令人惊讶的是,mondodb-nodejs 文档甚至没有提到bypassAutoEncryption I just happen to stumble across mongodb-c(point 3 & 4 below) driver documentation where I first found ant reference of such an option我只是碰巧偶然发现了 mongodb-c(下面的第 3 点和第 4 点)驱动程序文档,我在其中首次找到了 ant 对此类选项的引用

  1. https://github.com/mongodb/node-mongodb-native/blob/4ecaa37f72040ed8ace6eebc861b43ee9cb32a99/test/spec/client-side-encryption/tests/README.rst https://github.com/mongodb/node-mongodb-native/blob/4ecaa37f72040ed8ace6eebc861b43ee9cb32a99/test/spec/client-side-encryption/tests/README.rst
  2. https://github.com/Automattic/mongoose/issues/8167 https://github.com/Automattic/mongoose/issues/8167
  3. http://mongocxx.org/mongocxx-v3/client-side-encryption/ http://mongocxx.org/mongocxx-v3/client-side-encryption/
  4. https://mongodb.github.io/mongo-csharp-driver/2.11/reference/driver/crud/client_side_encryption/#explicit-encryption-and-auto-decryption https://mongodb.github.io/mongo-csharp-driver/2.11/reference/driver/crud/client_side_encryption/#explicit-encryption-and-auto-decryption

I was able to configure mongoShell with auto-decryption, meaning that my initial setup is not at fault.我能够使用自动解密配置 mongoShell,这意味着我的初始设置没有错误。 Also, it leads me to believe that there has to be a way to do it.via code as well.此外,它让我相信必须有一种方法来做到这一点。也可以通过代码。

My stack:我的堆栈:

  • nodeJS: > 14.7节点JS:> 14.7
  • mongoDB: 4.4 mongoDB:4.4
  • OS: macOS for dev, prod will be on AmazonLinux2操作系统:macOS for dev,prod 将在 AmazonLinux2 上
  • Drivers: mongoose, native-nodejs, mongodb-client-encryption驱动程序:mongoose、native-nodejs、 mongodb-client-encryption

It's not clearly mentioned in the docs.文档中没有明确提及。 But from what I've read, automatic decryption doesn't require the enterprise-only mongocryptd process.但据我所知,自动解密不需要企业专用的 mongocryptd 进程。

As mentioned in the official mongoDB-c-driver如官方mongoDB-c-driver中所述

Although automatic encryption requires MongoDB 4.2 enterprise or a MongoDB 4.2 Atlas cluster, automatic decryption is supported for all users.虽然自动加密需要MongoDB 4.2企业版或MongoDB 4.2 Atlas集群,但所有用户都支持自动解密。 To configure automatic decryption without automatic encryption, set bypass_auto_encryption=True in the options::auto_encryption class.要配置自动解密而不自动加密,请在 options::auto_encryption class 中设置 bypass_auto_encryption=True。

I believe the bypassAutoEncryption option was made for this very purpose.我相信bypassAutoEncryption选项就是为此目的而设计的。

Not exactly an answer, but this is the best resolution at the moment.不完全是答案,但这是目前最好的解决方案。 I reported this as a bug on the official JIRA.我将此报告为官方 JIRA 上的错误。

Turns out, this apparently is a bug with the node-mongo-native library.事实证明,这显然是 node-mongo-native 库的一个错误 As per their comment, this should be fixed in the next release.根据他们的评论,这应该在下一个版本中修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Nodejs 和 AWS KMS 在 s3 中加密和解密文件 - Encryption and Decryption file in s3 using Nodejs with AWS KMS 如何使用nodejs进行解析设置? - How do I set up parsely with nodejs? 使用公钥进行加密/解密 加密模块| 的NodeJS - Encryption/decryption using publickey | Crypto Module | NodeJS 如何在Node.js中将用户的电话号码设置为密码恢复选项 - How do I set up a user's phone number as a password recovery option in Nodejs 如何在nodejs中使用单个密钥实现加密和使用多个密钥解密? - How can i imlplement Encryption with single key and decryption with multiple keys in nodejs? 如果我的用户未使用nodeJS登录,如何设置NGINX进行重定向 - How do I set up NGINX to redirect if my user is not logged in using nodeJS 设置 ZCCADDEDB567ABAE643E15DCF0974E503Z 模式进行身份验证后,如何使用 Mongodb 查询数据库? - How do I query the database using Mongodb after I set up a Mongoose schema for authentication? 如何使用NodeJS中的Bluemix Message Hub设置“长期轮询” - How do I set up a 'long poll' using Bluemix Message Hub in NodeJS Nodejs。 异步加密和解密 - Nodejs. Asynchronous Encryption and Decryption Xcode上的AES加密和解密Node.js - AES encryption on xcode and decryption nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM