Skip to content

Ruby on Rails Application that uses Mongoid/MongoDB to demonstrate Client-Side Field Level Encryption

License

Notifications You must be signed in to change notification settings

mongodb-labs/mongoid-fle-sample-app

Repository files navigation

Sample Mongoid CSFLE Application

This is a sample application that demonstrates how to use the Mongoid Client-Side Field Level Encryption feature with the Mongoid ODM.

Prerequisites

To use CSFLE with Mongoid, you must have the following:

  • A MongoDB Atlas cluster running MongoDB 4.2 or later.
  • MongoDB Ruby driver 2.13.0 or later.
  • Mongoid 9.0.0 or later. This version is not released yet, so you must use the master branch of the Mongoid repository.
  • The crypt_shared library. It can be downloaded from the MongoDB Download Center. Store the library file in vendor/crypt_shared directory.

Getting Started

  1. Clone this repository.

  2. Install the dependencies:

    bundle install

    Please note that libmongocrypt-helper gem builds the library from sources, so you need to have cmake installed. If you want to avoid building the library, you can download a pre-built version following these instructions. If you decide to do so, you will need to set the LIBMONGOCRYPT_PATH environment variable to the path where you downloaded the library:

    export LIBMONGOCRYPT_PATH=<path to libmongocrypt>

    In this case also remove gem libmongocrypt-helper from the Gemfile.

  3. Export the following environment variables :

    export ATLAS_URI=<your MongoDB Atlas connection string>
    export LOCAL_MASTER_KEY=<Random 96-byte string>
  4. Create your first data key:

    rails db:mongoid:encryption:create_data_key
  5. Export the id of the data key as an environment variable:

    export USER_KEY_ID=<your data key id>
  6. Seed the database:

    rails db:seed
  7. Run the application:

    rails server

The seeds includes two users: '[email protected]' and '[email protected]', both with password '111111'. You can log in with either of them.

License

Copyright (c) 2023-Present MongoDB Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Ruby on Rails Application that uses Mongoid/MongoDB to demonstrate Client-Side Field Level Encryption

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published