viafintech / tidus

ActiveRecord database anonymization using views
MIT License
13 stars 4 forks source link

Tidus

Build Status

Tidus is a Ruby Gem which works in conjunction with ActiveRecord to automatically generate database views for every model which is a direct descendent from ActiveRecord::Base. The purpose of the views is to anonymize the contents of select columns to ensure that no confidential information leave the database while still providing access to the data in general.

Getting started

  1. add the Gem to the Gemfile

    gem 'tidus'
  2. Require the Gem at any point after ActiveRecord but before loading the models. Rails requires all Gems in the Gemfile by default.

  3. Add your anonymization rules

  4. Add load 'tasks/tidus_views.rake' after Rails.application.load_tasks in the Rakefile if it is a Rails application. Otherwise it will be required automatically.

  5. Execute rake db:migrate. The db:clear_views and db:generate_views tasks are hooked to automatically run every time before and after execution of db:migrate or db:rollback.

Anonymization rules

The rules to ensure anonymization can be defined as follows

    anonymizes :column_name, strategy: <strategy_name>, <additional_options>

Strategies

Note: to provide your own anonymization strategy you can also provide a class name for the strategy, e.g. strategy: Tidus::OverlayAnonymizer. It is expected though that the class is in a submodule. It is recommended to use Tidus as module name for better association of the purpose of the class.

Other options

Database support

PostgreSQL SQLite3 MySQL
cond
ean
email
null
overlay
sha256 ✅ (requires pgcrypto)
static
text
replace
remove_json_keys

Currently the Gem only contains strategy implementations for PostgreSQL.

Backup and Restore

You can use the bash example script located in examples to backup and restore databases prepared with tidus easily. tidus_backup_restore.sh can be called with any parameter other than -d|-r|--dump|--restore to get help for it's usage. The tidus_seq_rst.sql file is necessary for restores since it's will reset all sequences after restore for you - it's not necessary for backups only. You also need the tidus_credentials.conf with the IP/DNS, User and Password of the Dump and Restore users. If you use tidus_backup_restore.sh on separate machines for backup and restore, you can split up the credentials file and only provide the information necessary to backup and restore.

Basic usage

Before dumping or restoring you have to provide the tidus_credentials.conf file with all the informations needed for dumping and restoring. Those parameters are not exposed into the commandline due to security considerations. Also manually edit the tidus_backup_restore.sh and check the dump_it and restore_it functions and add the databases you want to dump or restore as well as the database names in your staging environment and the staging user which will get the permissions after restore.

Bugs and Contribution

For bugs and feature requests open an issue on Github. For code contributions fork the repo, make your changes and create a pull request.

Extending functionality

The number of strategies implemented so far is limited. You can however very easily define your own anonymization strategy. There is actually only one requirement: The class containing the strategy has to have an anonymize method. By passing the class name as a strategy value to the :strategy key, you are telling the anonymization extension on which class to execute said method.

License

LICENSE