2024-04-17 05:19:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
%w(
|
|
|
|
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY
|
|
|
|
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
|
|
|
|
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY
|
|
|
|
).each do |key|
|
2024-06-10 16:08:04 -04:00
|
|
|
if ENV['SECRET_KEY_BASE_DUMMY']
|
|
|
|
# Use placeholder value during production env asset compilation
|
|
|
|
ENV[key] = SecureRandom.hex(64)
|
|
|
|
end
|
|
|
|
|
2024-05-17 05:28:40 -04:00
|
|
|
value = ENV.fetch(key) do
|
2024-05-03 05:26:24 -04:00
|
|
|
abort <<~MESSAGE
|
2024-04-17 05:19:02 -04:00
|
|
|
|
2024-05-03 05:26:24 -04:00
|
|
|
Mastodon now requires that these variables are set:
|
2024-04-17 05:19:02 -04:00
|
|
|
|
|
|
|
- ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY
|
|
|
|
- ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
|
|
|
|
- ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY
|
|
|
|
|
2024-05-17 05:28:40 -04:00
|
|
|
Run `bin/rails db:encryption:init` to generate new secrets and then assign the environment variables.
|
2024-04-17 05:19:02 -04:00
|
|
|
MESSAGE
|
|
|
|
end
|
2024-05-17 05:28:40 -04:00
|
|
|
|
|
|
|
next unless Rails.env.production? && value.end_with?('DO_NOT_USE_IN_PRODUCTION')
|
|
|
|
|
|
|
|
abort <<~MESSAGE
|
|
|
|
|
|
|
|
It looks like you are trying to run Mastodon in production with a #{key} value from the test environment.
|
|
|
|
|
|
|
|
Please generate fresh secrets using `bin/rails db:encryption:init` and use them instead.
|
|
|
|
MESSAGE
|
2024-04-17 05:19:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Rails.application.configure do
|
|
|
|
config.active_record.encryption.deterministic_key = ENV.fetch('ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY')
|
|
|
|
config.active_record.encryption.key_derivation_salt = ENV.fetch('ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT')
|
|
|
|
config.active_record.encryption.primary_key = ENV.fetch('ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY')
|
2024-06-10 02:32:20 -04:00
|
|
|
config.active_record.encryption.support_sha1_for_non_deterministic_encryption = true
|
|
|
|
|
|
|
|
# TODO: https://github.com/rails/rails/issues/50604#issuecomment-1880990392
|
|
|
|
# Remove after updating to Rails 7.1.4
|
|
|
|
ActiveRecord::Encryption.configure(**config.active_record.encryption)
|
2024-04-17 05:19:02 -04:00
|
|
|
end
|