Git Product home page Git Product logo

zach-carr / client-side-field-level-encryption-csfle-mongodb-node-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joekarlsson/client-side-field-level-encryption-csfle-mongodb-node-demo

0.0 1.0 0.0 48 KB

A sample implementation of field level encryption in MongoDB, meant to accompany the CSFLE guide at https://developer.mongodb.com

Home Page: https://developer.mongodb.com

License: Apache License 2.0

JavaScript 91.38% Dockerfile 8.62%

client-side-field-level-encryption-csfle-mongodb-node-demo's Introduction

MonogDB Client Side Field Level Encryption (CSFLE) Node.js Demo

This guide shows you how to implement automatic Client-Side Field Level Encryption (CSFLE) using supported MongoDB drivers and is intended for full-stack developers. The guide presents the following information in the context of a real-world scenario.

Once you complete the steps in this guide, you should have:

  • an understanding of how client-side field level encryption works and in what situations it is practical
  • a working client application that demonstrates automatic CSFLE
  • resources on how to move the sample client application to production

Running Locally

Requirements

  • MongoDB Atlas 4.2+
  • MongoDB Node driver 3.6.2+
  • The libmongocrypt library installed
  • The mongocryptd binary installed
  1. Clone this repository and navigate to the nodejs directory.

    git clone https://github.com/mongodb-university/csfle-guides.git
    cd nodejs

    Work from the nodejs directory for the remainder of these instructions.

  2. Start a locally running mongod instance (Enterprise version >= 4.2) running on port 27017

  3. Install the dependencies in package.json

    npm install
  4. Make sure you have the master-key.txt file in the root of your execution environment. This is a 96-byte cryptographically-secure generated master encryption key required to run this example project. To generate your own master key or use a KMS, refer to the CSFLE Use Case Guide.

  5. Run the make-data-key.js script to make a data key. If there is an existing data key in the encryption.__keyVault collection this script will not create a duplicate data key.

    node make-data-key.js

    This outputs a base64 encoded string of the UUID of your newly created data key. Paste this into clients.js where you see this line

    let dataKey = null // change this!
  6. Run the clients.js script to insert a document with the CSFLE-enabled client and then read that document with it as well as a regular client. You will see that the CSFLE-enabled client prints the document out in plaintext, and the regular client prints the document out with encrypted fields in binary format. This is safe to run multiple times as the insert operation used is an update with upsert specified.

    node clients.js
  7. Suggestion: Try inserting a document with the regular client. What happens?

Running CSFLE with Docker

  1. Change directories to the docker directory.
cd docker
  1. Build Docker image with a tag name. Within this directory execute:

    • For using the latest driver version:
      docker build . -t mdb-csfle-example

    This will build a Docker image with a tag name mdb-csfle-example.

  2. Run the Docker image by executing:

    docker run -tih csfle mdb-csfle-example

    The command above will run a Docker image with tag mdb-csfle-example and provide it with csfle as its hostname.

  3. Once you're inside the Docker container, you could follow below steps to run the NodeJS code example.

$ export MONGODB_URL="mongodb+srv://USER:[email protected]/dbname?retryWrites=true&w=majority"`
$ node ./example.js

If you're connecting to MongoDB Atlas please make sure to Configure Whitelist Entries

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Contributing TLDR;

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Maintainers


Joe Karlsson

License

client-side-field-level-encryption-csfle-mongodb-node-demo's People

Contributors

joekarlsson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.