The following line:
ENV['FOREMAN_HOOKS_USER'] = User.current.login
in lib/foreman_hooks/util.rb sets current user as an environment variable. This does not work when a new external user logs in and Foreman tries to update user attributes (firstname, lastname, email). The changes are executed and audited which will trigger any hooks you may have in audited/audit/, which will fail with backtrace:
2022-05-12T08:59:08 [D|app|d0bc1f0d] Running 6 hooks for Audited::Audit#after_create
2022-05-12T08:59:08 [D|sql|d0bc1f0d] Running hook: /usr/share/foreman/config/hooks/audited/audit/after_create/05-test.sh after_create 166891
2022-05-12T08:59:08 [D|sql|d0bc1f0d] (0.5ms) ROLLBACK
2022-05-12T08:59:08 [W|app|d0bc1f0d] undefined method `login' for nil:NilClass
2022-05-12T08:59:08 [I|app|d0bc1f0d] Backtrace for 'undefined method `login' for nil:NilClass' error (NoMethodError): undefined method `login' for nil:NilClass
d0bc1f0d | /usr/share/gems/gems/foreman_hooks-0.3.17/lib/foreman_hooks/util.rb:56:in `exec_hook_int'
Probably because the User.current.login is not available at this stage. So we would need some validation and fallback setting here.
The following line:
ENV['FOREMAN_HOOKS_USER'] = User.current.login
in
lib/foreman_hooks/util.rb
sets current user as an environment variable. This does not work when a new external user logs in and Foreman tries to update user attributes (firstname, lastname, email). The changes are executed and audited which will trigger any hooks you may have inaudited/audit/
, which will fail with backtrace:Probably because the
User.current.login
is not available at this stage. So we would need some validation and fallback setting here.