'Heroku error: "key must be 16 bytes" but the key I have inputted is 16 bytes
I am launching to Heroku for the first time and I am getting the error "ArgumentError: key must be 16 bytes".
I have run rails credentials:edit
to generate a new key, got the key which is 32 characters, ran heroku config:set RAILS_MASTER_KEY='<master key>'
and it was accepted. But I still get the error when I run it.
I am unsure what I am doing wrong.
Here is the full error message:
Running: rake assets:precompile
rake aborted!
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:183:in `_decrypt'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:79:in `decrypt'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:42:in `read'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:21:in `read'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:33:in `config'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:38:in `options'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:24:in `key_exists?'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:10:in `find'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/devise-4.6.2/lib/devise/rails.rb:37:in `block in <class:Engine>'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!'
/tmp/build_e151bdf198daf12c42102939c20b0959/config/environment.rb:7:in `<top (required)>'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Caused by:
ArgumentError: key must be 16 bytes
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:193:in `key='
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:193:in `_decrypt'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:79:in `decrypt'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:42:in `read'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:21:in `read'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:33:in `config'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:38:in `options'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:24:in `key_exists?'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:10:in `find'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/devise-4.6.2/lib/devise/rails.rb:37:in `block in <class:Engine>'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!'
/tmp/build_e151bdf198daf12c42102939c20b0959/config/environment.rb:7:in `<top (required)>'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
/tmp/build_e151bdf198daf12c42102939c20b0959/vendor/bundle/ruby/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app.
! Push failed
Solution 1:[1]
Originally, there were quotes around the master key configuration set command, like this: '<master key>'
which Heroku interprets as part of the master key.
Just for posterity, I'm going to leave the correctly formatted command we figured out in the comments:
$ heroku config:set RAILS_MASTER_KEY=<master key>
Solution 2:[2]
If Veridian solution doesn't work for rails 7 try use this:
heroku config:set RAILS_MASTER_KEY=`cat config/master.key`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Veridian Dynamics |
Solution 2 | antoniolulee |