I simply cant get past the message
Missing
secret_key_base
for 'production' environment, set this string withrails credentials:edit
(ArgumentError)
I have here rails 5.2.0. Ran EDITOR=vim rails credentials:edit
and inside:
production:
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx
Save and, in terminal: RAILS_ENV=production rails c
Am I missing something? Ive restarted server and same issue. No issue in development mode.
Keep default the secrets.yml file
# config/secrets.yml
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
RAILS_ENV=production SECRET_KEY_BASE=production_test_key rails c
Rails 5.2.0 requires an extra stage for the production environment:
config.require_master_key = true # in config/environments/production.rb
Without it, Rails still falls back to the legacy secret.yml
mechanism (for now).
Engine Yard's Christopher Rigor has written a concise post on it. The relevant piece:
Reading the Credentials
If you want to use the credentials in the production environment, add the following to
config/environments/production.rb
config.require_master_key = true
A good read to also see up and down sides.
Note: As @TomDogg found out, Rails 5.2.1 seems again different, so this answer may only apply to 5.2.0.
There are no production:
development:
and test:
environment tags in the credentials file. Further information in this DHH's post: https://github.com/rails/rails/pull/30067
So write directly
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx
Please don't confuse master key with the secret key base. The master key is used to open the credentials encrypted file.
Switching back to the previous secrets system should not be the solution, nor the accepted answer.
config/credentials.yml.enc:
development:
some_username: XXXXXXXXX
some_password: YYYYYYYYY
test:
some_username: XXXXXXXXX
some_password: YYYYYYYYY
production:
some_username: XXXXXXXXX
some_password: YYYYYYYYY
secret_key_base: ZZZZZZZZZ
# `secret_key_base:` must NOT be indented !
# It must be put at the very start of a new line.
# There is also no need for it in development or test environment,
# since there are no attacks to be expected.
Also make sure that you respect all YAML indention rules (i.e. 2 spaces only) as failing to do so my make loading of this file fail silently.
来源:https://stackoverflow.com/questions/51466887/missing-secret-key-base-for-production-environment