Bug #14541
closedforeman-rake must preserve environment variables
Description
Calling foreman-rake db:seed fills the database with default entries.
Of theses seeds, 04-admin.rb
takes care of adding the default admin account.
This can be configured using SEED_ADMIN_*
environment variables but calling foreman-rake
with id != foreman
fails.
Looking at foreman-rake
, the su
call misses the -p
flag, so environment is dropped when changing user.
Updated by The Foreman Bot over 8 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3533 added
Updated by Stijn Tintel over 8 years ago
Adding -p to the su call is unfortunately not an option:
root@foreman:~# /usr/sbin/foreman-rake db:seed -su: /root/.bash_profile: Permission denied rake aborted! Errno::EACCES: Permission denied - /root/.facter/facts.d /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:75:in `open' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:75:in `entries' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:75:in `entries' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/directory_loader.rb:55:in `load' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/composite_loader.rb:10:in `block in load' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/composite_loader.rb:10:in `each' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/composite_loader.rb:10:in `load' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:154:in `load_external_facts' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:110:in `load' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:84:in `fact' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/collection.rb:140:in `value' /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter.rb:112:in `block (2 levels) in singleton class' /usr/share/foreman/app/models/setting/general.rb:7:in `load_defaults' /usr/share/foreman/config/initializers/foreman.rb:21:in `each' /usr/share/foreman/config/initializers/foreman.rb:21:in `<top (required)>' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:241:in `load' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:241:in `block in load' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:232:in `load_dependency' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:241:in `load' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:648:in `block in load_config_initializer' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/notifications.rb:161:in `instrument' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:647:in `load_config_initializer' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:611:in `each' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/engine.rb:611:in `block in <class:Engine>' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:30:in `instance_exec' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:30:in `run' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:55:in `block in run_initializers' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:44:in `each' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:44:in `tsort_each_child' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/initializable.rb:54:in `run_initializers' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/application.rb:300:in `initialize!' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/railtie.rb:194:in `public_send' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/railtie.rb:194:in `method_missing' /usr/share/foreman/config/environment.rb:5:in `<top (required)>' /usr/share/foreman/vendor/ruby/2.0.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require' /usr/share/foreman/vendor/ruby/2.0.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:247:in `block in require' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:232:in `load_dependency' /usr/share/foreman/vendor/ruby/2.0.0/gems/activesupport-4.1.14.2/lib/active_support/dependencies.rb:247:in `require' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/application.rb:276:in `require_environment!' /usr/share/foreman/vendor/ruby/2.0.0/gems/railties-4.1.14.2/lib/rails/application.rb:405:in `block in run_tasks_blocks' /usr/share/foreman/vendor/ruby/2.0.0/gems/activerecord-4.1.14.2/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>' /usr/bin/rake2.0:37:in `<main>' Tasks: TOP => db:abort_if_pending_migrations => environment (See full trace by running task with --trace)
Updated by Dominic Cleal over 8 years ago
- Status changed from Ready For Testing to New
- Pull request deleted (
https://github.com/theforeman/foreman/pull/3533)
HOME might be carried through with -p?
Updated by Stijn Tintel over 8 years ago
This is just a warning and can be ignored:
-su: /root/.bash_profile: Permission denied
But the problem seems to be in the facter gem, in /usr/share/foreman/vendor/ruby/2.0.0/gems/facter-1.7.6/lib/facter/util/config.rb:
def self.external_facts_dirs if Facter::Util::Root.root? windows_dir = windows_data_dir if windows_dir.nil? then ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"] else [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')] end else [File.expand_path(File.join("~", ".facter", "facts.d"))] end end
So with the -p option, the environment contains HOME=/root, which is causing the above problem.
Updated by The Foreman Bot over 8 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3534 added
Updated by Anonymous over 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 9fd991210db89b693cb17fa2c25c8104f8981b16.
Updated by Dominic Cleal over 8 years ago
- Translation missing: en.field_release set to 136