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

FOREMAN_HOOKS_USER not working with audits and user logins #63

Open
wiad opened this issue May 12, 2022 · 0 comments
Open

FOREMAN_HOOKS_USER not working with audits and user logins #63

wiad opened this issue May 12, 2022 · 0 comments

Comments

@wiad
Copy link
Contributor

wiad commented May 12, 2022

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.

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

No branches or pull requests

1 participant