Bug #19465
openUser data template rendering does not render host parameters
Description
When a host parameter is specified at creation time (ie not inherited from a host group or something similar), either in the UI or in a POST request via the API, the parameter is not bound to @host.params before the template is rendered and sent to the compute resource.
Updated by Marek Hulán over 7 years ago
- Related to Bug #20062: Host parameter not rendered in user_data template added
Updated by Marek Hulán over 7 years ago
- Status changed from New to Need more information
What version of Foreman do you experience this with? Do you use organizations or locations?
Updated by Tyler Gregory over 7 years ago
It was experienced on version 1.14.3, and yes we do use organizations and locations
Updated by Marek Hulán about 7 years ago
- Status changed from Need more information to New
Updated by Oleh Fedorenko 7 days ago
This is still valid: https://community.theforeman.org/t/shellhook-and-host-parameter/41994.
Few notes:
- During host creation, such host parameters are not being saved before they are used in provisioning templates during orchestration.
- During provision templates render, such parameters are being called and then cached in https://github.com/theforeman/foreman/blob/3.14-stable/app/models/concerns/host_params.rb#L65.
- The cache is not global and stays until a host object is discarded. The issue is rather in https://github.com/theforeman/foreman/blob/3.14-stable/app/models/concerns/host_params.rb#L24, more specifically in how we check for permissions.
- In https://github.com/theforeman/foreman/blob/3.14-stable/app/models/concerns/authorizable.rb#L50-L58 we're referring to the model itself (e.g. HostParameter.all) and thus fully ignoring currently unsaved host parameters.
- Due to the above, https://github.com/theforeman/foreman/blob/3.14-stable/app/models/concerns/host_params.rb#L24 will always return an empty array for new parameters during host creation, then caching it for current host object, which will lead to such errors until the host object is then reloaded with already saved host parameters object from DB.