Foreman + rails creds doesn't work

Problem:
Hello there! I have a problem.
I’m installing Foreman from this link: Foreman :: Quickstart
It works OK. But I need to use not password from config/database.yml. I need to use Rails creds:
Rails.application.credentials.<PASS_VAR>
I’ve checked that it works in this way:

cat test.rb 
test =  Rails.application.credentials.password
puts "#{test}"

The output is:

# rails runner test.rb --environment=production
Hello
<MY_ENV_PASS>

But! I’ll have an error If I use this way (without environment):

# rails runner test.rb
2024-03-24T10:30:44 [I|app|] Rails cache backend: File
Traceback (most recent call last):
	2: from /usr/local/bin/rails:9:in `<main>'
	1: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require'
/opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- rails/commands (LoadError)
	49: from /usr/local/bin/rails:9:in `<main>'
	48: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:147:in `require'
	47: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:158:in `rescue in require'
	46: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:158:in `require'
	45: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands.rb:18:in `<top (required)>'
	44: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/command.rb:46:in `invoke'
	43: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/command/base.rb:69:in `perform'
	42: from /opt/theforeman/tfm/root/usr/share/gems/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
	41: from /opt/theforeman/tfm/root/usr/share/gems/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	40: from /opt/theforeman/tfm/root/usr/share/gems/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	39: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands/runner/runner_command.rb:33:in `perform'
	38: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
	37: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/command/actions.rb:28:in `require_environment!'
	36: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/application.rb:339:in `require_environment!'
	35: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:324:in `require'
	34: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:291:in `load_dependency'
	33: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:324:in `block in require'
	32: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require'
	31: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require'
	30: from /usr/share/foreman/config/environment.rb:5:in `<top (required)>'
	29: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:190:in `method_missing'
	28: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/railtie.rb:190:in `public_send'
	27: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/application.rb:363:in `initialize!'
	26: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/initializable.rb:60:in `run_initializers'
	25: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:205:in `tsort_each'
	24: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:226:in `tsort_each'
	23: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:347:in `each_strongly_connected_component'
	22: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:347:in `call'
	21: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:347:in `each'
	20: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:349:in `block in each_strongly_connected_component'
	19: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:431:in `each_strongly_connected_component_from'
	18: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	17: from /opt/rh/rh-ruby27/root/usr/share/ruby/tsort.rb:228:in `block in tsort_each'
	16: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/initializable.rb:61:in `block in run_initializers'
	15: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/initializable.rb:32:in `run'
	14: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/initializable.rb:32:in `instance_exec'
	13: from /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/railtie.rb:198:in `block in <class:Railtie>'
	12: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:42:in `on_load'
	11: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:42:in `each'
	10: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:43:in `block in on_load'
	 9: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
	 8: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
	 7: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
	 6: from /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
	 5: from /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/railtie.rb:201:in `block (2 levels) in <class:Railtie>'
	 4: from /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_handling.rb:50:in `establish_connection'
	 3: from /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_handling.rb:170:in `resolve_config_for_connection'
	 2: from /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/connection_specification.rb:139:in `resolve'
	 1: from /opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/connection_specification.rb:218:in `resolve_connection'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/connection_specification.rb:250:in `resolve_symbol_connection': The `development` database is not configured for the `development` environment. (ActiveRecord::AdapterNotSpecified)

Available databases configurations are:

production

So! The main problem is here!
When I try to restart the foreman, I have the same problem:

Mar 24 10:11:30  systemd[1]: Starting Foreman...
Mar 24 10:11:34  foreman[29434]: => Booting Puma
Mar 24 10:11:34  foreman[29434]: => Rails 6.0.3.7 application starting in production
Mar 24 10:11:34  foreman[29434]: => Run `rails server --help` for more startup options
Mar 24 10:11:34  foreman[29434]: Exiting
Mar 24 10:11:34  foreman[29434]: /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/server.rb:453:in `read': Permission denied @ rb_sysopen - /usr/share/for
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/server.rb:453:in `pidfile_process_status'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/server.rb:441:in `check_pid!'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/rack-2.2.3/lib/rack/server.rb:307:in `start'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands/server/server_command.rb:39:in `start'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands/server/server_command.rb:147:in `block in perform'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands/server/server_command.rb:138:in `tap'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands/server/server_command.rb:138:in `perform'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/command/base.rb:69:in `perform'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/command.rb:46:in `invoke'
Mar 24 10:11:34  foreman[29434]: from /opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/commands.rb:18:in `<top (required)>'
Mar 24 10:11:34  foreman[29434]: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:158:in `require'
Mar 24 10:11:34  foreman[29434]: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:158:in `rescue in require'
Mar 24 10:11:34  foreman[29434]: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:147:in `require'
Mar 24 10:11:34  foreman[29434]: from /usr/share/foreman/bin/rails:9:in `<main>'
Mar 24 10:11:34  foreman[29434]: /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- rails/commands (L
Mar 24 10:11:34  foreman[29434]: from /opt/rh/rh-ruby27/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require'
Mar 24 10:11:34  foreman[29434]: from /usr/share/foreman/bin/rails:9:in `<main>'
Mar 24 10:11:34  systemd[1]: foreman.service: main process exited, code=exited, status=1/FAILURE
Mar 24 10:11:34  systemd[1]: Failed to start Foreman.
Mar 24 10:11:34  systemd[1]: Unit foreman.service entered failed state.
Mar 24 10:11:34  systemd[1]: foreman.service failed.

This problem starts, when I change creds like this:
EDITOR=“code --wait” rails credentials:edit
or like this:
EDITOR=vi rails credentials:edit

What’s wrong and how I can get creds in foreman? Thanks!

**Foreman version: 2.5
**Rails version: Rails 6.0.3.7

I’ve tried it on Foreman 2.5 and Foreman 3.3. The same problem.

I need to use password like:

  password: <%= Rails.application.credentials.production_dbpwd %>

I’m not sure what you are try to do exactly. I’ve never seen Rails.application.credentials.password.

From the traceback it looks like you’re running ona production EL7 system without loading the SCL environment.

If you just want to run something, I think you can also use foreman-rake console to get an interactive console. Otherwise you’ll need to use the proper commands to start SCL, which I’ve actually forgotten since it’s been so long since I touched EL7.

I’d urge you to upgrade.

I found the problem. The problem was in these files:
/usr/share/foreman/config/credentials.yml.enc
/usr/share/foreman/config/master.key
Not enough rights. Just Rights into files