Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make encryption config optional for self hosting users #1476

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/concerns/store_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ module StoreLocation
helper_method :previous_path
before_action :store_return_to
after_action :clear_previous_path

rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
end

def previous_path
session[:return_to] || fallback_path
end

private
def handle_not_found
if request.fullpath == session[:return_to]
session.delete(:return_to)
redirect_to fallback_path
end
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, fixes a bug where clicking "back" from settings throws a 404 when the "return to" path is the URL of a resource that has been deleted from /accounts page.


def store_return_to
if params[:return_to].present?
Expand Down
5 changes: 4 additions & 1 deletion app/models/plaid_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class PlaidItem < ApplicationRecord
include Plaidable, Syncable

encrypts :access_token, deterministic: true
if Rails.application.credentials.active_record_encryption.present?
encrypts :access_token, deterministic: true
end

validates :name, :access_token, presence: true

before_destroy :remove_plaid_item
Expand Down
5 changes: 5 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ class Application < Rails::Application
config.i18n.fallbacks = true

config.app_mode = (ENV["SELF_HOSTED"] == "true" || ENV["SELF_HOSTING_ENABLED"] == "true" ? "self_hosted" : "managed").inquiry

# Self hosters can optionally set their own encryption keys if they want to use ActiveRecord encryption.
if Rails.application.credentials.active_record_encryption.present?
config.active_record.encryption = Rails.application.credentials.active_record_encryption
end
end
end
2 changes: 0 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,4 @@
# ]
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }

config.active_record.encryption = Rails.application.credentials.active_record_encryption
end
Loading