• Stars
    star
    106
  • Rank 325,811 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 3 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

example workflow

MassEncryption

MassEncryption lets you encrypt large sets of data using Active Record encryption.

Its main use case is adding encryption to existing applications where you have a large amount of existing data to encrypt.

It relies on Active Job to create encryption jobs that take care of encrypting data in batches.

Installation

Add this line to your application's Gemfile:

gem 'mass_encryption'

Usage

MassEncryption offers two modes of operation:

  • Encrypt data in tracks (recommended)
  • Encrypt data in parallel jobs

Encrypt data in tracks (recommended)

When encrypting in tracks, you create a limited number of jobs that will encrypt a batch of records. Each job represents a track. When the job encrypts its batch, it enqueues the next batch in the track.

This mode of encryption lets you keep the number of jobs you enqueue under control. This has two advantages:

  • It avoids having to enqueue all the jobs ahead of time. For example, you don't normally want to enqueue millions of jobs up front to encrypt billions of rows.
  • It lets you limit concurrency to avoid capacity issues.

You can launch the encryption in this mode with:

rake mass_encryption:encrypt_all_in_tracks

By default it will encrypt all the models with encrypted attributes using a batch size of 1000 records per job and one track, so only one job will encrypt data at any given moment.

For example:

# Encrypt all the posts starting with id 10 using 6 encryption jobs
rake mass_encryption:encrypt_all_in_tracks EXCEPT="Post" FROM_ID=10 TRACKS=6

Encrypt data in parallel jobs

In this mode, it will simply loop through all the batches of records and enqueue a job for each.

By default it will encrypt all the models with encrypted attributes using a batch size of 1000 records per job.

# Encrypt all the posts starting with id 10 using as many jobs as needed to encrypt them in batches of 500 records 
rake mass_encryption:encrypt_all_in_parallel_jobs EXCEPT="Post" FROM_ID=10 BATCH_SIZE=500

Options

You can customize it by passing the following environment variables when invoking the rake task:

  • ONLY. Comma-separated list of class names to encrypt.
  • EXCLUDE. Comma-separated list of class name to exclude.
  • FROM_ID. Id to use as an anchor to start encryption. This is handy to resume encryption operations that got interrupted. Ids lower than it won't be encrypted. By default it will be the id of the first model record.
  • BATCH_SIZE. The amount of records each job will encrypt. By default it's 1000.
  • TRACKS: The number of tracks to use (only available when encrypting in tracks). By default it's 1.

How it works

  • MassEncryption internally uses upsert_all to perform fast updates in bulk.

  • If there was some error when trying to update the records, MassEncryption jobs will try to encrypt the records in the batch one by one. They will collect all the individual errors and raise a single MassEncryption::MassEncryption::BatchEncryptionError error aggregating them all. This way, one record failing to encrypt won't prevent other records in the batch from being encrypted.

License

The gem is available as open source under the terms of the MIT License.

More Repositories

1

trix

A rich text editor for everyday writing
JavaScript
17,847
star
2

kamal

Deploy web apps anywhere.
Ruby
9,584
star
3

handbook

Basecamp Employee Handbook
6,165
star
4

omakub

Opinionated Ubuntu Setup
Shell
4,152
star
5

pow

Zero-configuration Rack server for Mac OS X
CoffeeScript
3,423
star
6

policies

37signals policies, terms, and legal. Share them; reuse them; contribute to them.
1,863
star
7

local_time

Rails engine for cache-friendly, client-side local time
CoffeeScript
1,791
star
8

marginalia

Attach comments to ActiveRecord's SQL queries
Ruby
1,676
star
9

mail_view

Visual email testing
Ruby
1,341
star
10

xip-pdns

PowerDNS pipe backend adapter powering xip.io
Shell
1,159
star
11

geared_pagination

Paginate Active Record sets at variable speeds
Ruby
758
star
12

wysihat

A WYSIWYG JavaScript framework
JavaScript
681
star
13

bcx-api

API documentation and wrappers for Basecamp 2
672
star
14

name_of_person

Presenting names of people in full, familiar, abbreviated, and initialized forms (but without titulation etc)
Ruby
647
star
15

console1984

The Rails console you love, 1984 style
Ruby
609
star
16

google_sign_in

Sign in (or up) with Google for Rails applications
Ruby
494
star
17

bc3-api

API documentation for Basecamp 4
472
star
18

intermission

intermission helps you perform zero down time application maintenance
Lua
364
star
19

audits1984

Auditing tool for Rails console sessions
Ruby
336
star
20

snapback_cache

A client side page cache for jquery.
JavaScript
316
star
21

full_request_logger

Make full request logs accessible via web UI
Ruby
305
star
22

mysql_role_swap

(Nearly) Zero interruption mysql maintenance script.
Ruby
282
star
23

concerning

Bite-sized separation of concerns
Ruby
201
star
24

api

API integration and more for Basecamp products (Basecamp, Highrise, Campfire, Backpack)
192
star
25

easymon

Easy Monitoring
Ruby
191
star
26

trashed

Tell StatsD about request time, GC, objects and more. Latest Rails 4 and Ruby 2.1 support, and ancient Rails 2 and Ruby 1.8 support.
Ruby
189
star
27

highrise-api

Official API documentation for Highrise
130
star
28

fast_remote_cache

A faster version of Capistrano's remote_cache deployment strategy
Ruby
125
star
29

platform_agent

Parse user agent to deduce the platform
Ruby
103
star
30

cached_externals

Symlink to external dependencies, rather than bloating your repositories with them
Ruby
100
star
31

homographic_spoofing

Toolkit to both detect and sanitize homographic spoofing attacks in URLs and Email addresses
Ruby
98
star
32

campfire-api

Official API documentation for Campfire
97
star
33

basecamp-classic-api

Official API documentation for Basecamp Classic
87
star
34

lufo

Tracks the most recent options chosen on a `<select>` element and displays them at the top of the list
JavaScript
87
star
35

powprox

Pow .dev sites, meet SSL and HTTP/2
Shell
83
star
36

libmemcached_store

ActiveSupport::Cache wrapper for libmemcached
Ruby
81
star
37

action_profiler

Profile Rails requests on a live app
Ruby
75
star
38

bc3-integrations

Ruby
73
star
39

project_search

Rails plugin that adds a script/find command for searching your project
Ruby
71
star
40

activestorage-office-previewer

Active Storage previewer for Microsoft Office files based on LibreOffice
Ruby
67
star
41

turbo-8-morphing-demo

Ruby
58
star
42

dumpsterfire-2020

Code that runs the dumpster
HTML
47
star
43

cognition

Match text; run commands. Works great for building a chatbot!
Ruby
37
star
44

snapshot

A rails plugin that provides tasks for creating and restoring snapshots of development data.
Ruby
34
star
45

backpack-api

Official API documentation for Backpack
Ruby
20
star
46

ruby-dev

Old Rubies on new Macs
15
star
47

orc

Orc(hestrator) - A really bad pow.cx clone for linux
Shell
10
star
48

cleversafe

Ruby
7
star
49

accessibility

Guidelines and tools we use at 37signals to make sure our apps are accessible
7
star
50

memcached_bench

Ruby
6
star
51

duo-api

Ruby Gem for communicating with the Duo Api
Ruby
6
star
52

Xamarin.iOS.OnePasswordExtension

1Password bindings for Xamarin.iOS
C#
5
star
53

mail

Ruby
4
star
54

composed_of_ipaddr

Compact IPv4 attributes for Active Record. Presents an unsigned int (4 bytes) as an IPAddr.
Ruby
4
star
55

house-style

37signals house style
Ruby
3
star
56

deep_hash_transform

Re-key a nested Hash to all-Symbol or -String keys. Rails 4+ backport.
Ruby
3
star
57

assets-redirect

Ruby
2
star
58

github-issues

Github Issue query CLI
Go
2
star
59

homebrew-dev

Old software to build old stuff on new Macs
Ruby
1
star
60

nsone

A stupid simple API client for NS1
Ruby
1
star