ActiveSupport::MessageEncryptor 当 deploy:assets:precompile

ActiveSupport::MessageEncryptor when deploy:assets:precompile

我在将 rails 应用程序部署到服务器时遇到问题。 当我尝试在步骤 deploy:assets:precompile 中部署时,我得到

 01 rake aborted!
  01 ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
  01 /var/www/spycommerce/shared/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
  ...
  01
  01 Caused by:
  01 OpenSSL::Cipher::CipherError:
  01 /var/www/spycommerce/shared/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:201:in `final'
  ...

当我尝试手动编译资产时RAILS_ENV=production bundle exec rake assets:precompile我没有收到错误

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'

require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'

install_plugin Capistrano::Puma  # Default puma tasks

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

版本

rails -v => 5.2.1
capistrano -v => 3.11

我尝试使用 config.require_master_key = true 修复,并在 deploy.rb 中创建 link set :linked_files, %w{config/master.key}。没有任何帮助

我 运行 在从命令行测试 Rails Api 应用程序的 MessageEncryptor 时遇到了类似的问题。防止 InvalidMessage 异常的解决方案:如果您必须在 rails 初始化上下文之外使用 ActiveSupport::MessageEncryptor,请手动设置 ActiveSupport::MessageEncryptor.use_authenticated_message_encryption = true。 MessageEncryptor 然后使用预期的 default_cipher aes-256-gcm.