Skip to content

Commit 6148ed7

Browse files
committed
Configure ActiveRecord encryption
Following the ActiveRecord encryption rails guide[1] this commit configures active record with the necessary encryption keys and salts. In development the values of these variables doesn't matter, but to avoid confusion I've set them to something that isn't obviously an encryption key (such as the ones generated by `db:encryption:init`). We'll need to ensure that these three environment variables are set in non-local environments before this change is deployed. [1] https://guides.rubyonrails.org/active_record_encryption.html
1 parent f82f10f commit 6148ed7

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
POSTGRES_USER: choco
2929
POSTGRES_HOST: "127.0.0.1"
3030
RAILS_ENV: test
31+
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: primary-key
32+
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: deterministic-key
33+
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: derivation-salt
3134
steps:
3235
- checkout
3336
- browser-tools/install-firefox

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ HOST_URL=http://localhost:3009
3131
EDITOR_PUBLIC_URL=http://localhost:3012
3232

3333
PROFILE_API_KEY=test # This has to match the value set in Profile (https://github.com/RaspberryPiFoundation/profile/blob/ca10a4f360b6fe2b04be76264e03283054126b0f/.env.example#L45).
34+
35+
# Run bin/rails db:encryption:init to generate values for these if you need to encrypt securely locally.
36+
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=primary-key
37+
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=deterministic-key
38+
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=derivation-salt

config/initializers/encryption.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
Rails.application.configure do
4+
config.active_record.encryption.primary_key = ENV.fetch('ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY')
5+
config.active_record.encryption.deterministic_key = ENV.fetch('ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY')
6+
config.active_record.encryption.key_derivation_salt = ENV.fetch('ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT')
7+
end

0 commit comments

Comments
 (0)