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

Allow assets:precompile to be run in a production build step without passing in RAILS_MASTER_KEY #46760

Merged
merged 4 commits into from
Dec 17, 2022

Conversation

dhh
Copy link
Member

@dhh dhh commented Dec 17, 2022

When compiling assets in production as part of an image build step, it's inconvenient to have to pass in the real RAILS_MASTER_KEY. So allow passing in a dummy secret_key_base, just like we do in development and test, via ENV["SECRET_KEY_BASE_DUMMY"] = 1. This will not give access to any of the real credentials or message verifiers, but allow the build step to complete, since it typically does not need it anyway.

This is useful when precompiling assets for production as part of a build step that otherwise does not need access to the production secrets.
@dhh dhh merged commit a3e392f into main Dec 17, 2022
@dhh dhh deleted the add-secret-key-base-dummy branch December 17, 2022 19:53
dhh added a commit that referenced this pull request Dec 19, 2022
* main:
  Remind of credentials diff enrollment on edit
  [docs] Code samples for postgres configs
  Silence credentials generator in app generator
  Let `initialize` not create an Array as its return value
  Reduce Array allocations in MimeNegotiation
  Trim trailing whitespace from *.md files
  Avoid unnecessary replacements when the node doesn't change
  Allow assets:precompile to be run in a production build step without passing in RAILS_MASTER_KEY (#46760)
@aishek
Copy link

aishek commented Dec 26, 2022

Passing a dummy secret_key_base was exactly the way I fix same problem:

# config/environments/production.rb

Rails.application.configure do
  # ...
  config.secret_key_base = ENV.fetch('SECRET_KEY_BASE')
  # ...
end
# Dockerfile

RUN SECRET_KEY_BASE=DummyValueToPassAssetsCompilation bundle exec rails assets:precompile

@morgoth
Copy link
Member

morgoth commented Feb 13, 2023

@dhh This does not work when the config.require_master_key = true is set.

remote: Missing encryption key to decrypt file with. Ask your team for your master key and write it to /rails/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
remote: The command '/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile' returned a non-zero code: 1

Is the recommendation now to disable require_master_key enforcement or should SECRET_KEY_BASE_DUMMY=1 (or some other new name) maybe also take the master key into account?

@dhh
Copy link
Member Author

dhh commented Feb 13, 2023

Yeah, I don't think we want to make a liar about of that config. If you have a setup where you don't want to inject the master key during build (and use dummy key base), then you need to turn that off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants