Bug #35792
closedsave_to_file function should not use shellescape on the filename
Description
We have improved the save_to_file function via https://projects.theforeman.org/issues/35530 but here in https://github.com/theforeman/foreman/blob/develop/app/services/foreman/renderer/scope/macros/base.rb#L116 , as we use shellescape on the filename, that breaks the functionality of kickstart_networking_snippet
- foreman-rake console
Loading production environment (Rails 6.0.4.7)
~~~~~
irb(main):002:0> filename = '/etc/sysconfig/network-scripts/ifcfg-$sanitized_real'
=> "/etc/sysconfig/network-scripts/ifcfg-$sanitized_real"
irb(main):003:0> filename.shellescape
=> "/etc/sysconfig/network-scripts/ifcfg-\\$sanitized_real"
So in foreman 3.4-stable, the rendering used to be:
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$sanitized_real
BOOTPROTO="dhcp"
DOMAIN="example.com"
DEVICE=$real
HWADDR="00:50:56:b4:14:44"
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
DEFROUTE=yes
MTU=1500
EOF
and Now, it's
cat << EOF-cd4e31fd > /etc/sysconfig/network-scripts/ifcfg-\$sanitized_real
BOOTPROTO="dhcp"
DOMAIN="example.com"
DEVICE=$real
HWADDR="00:50:56:b4:4f:c6"
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
DEFROUTE=yes
MTU=1500
EOF-cd4e31fd
And that escaping results in two ifcfg configs on the deployed system i.e.
- ls
l /etc/sysconfig/network-scripts. 1 root root 153 Nov 25 11:44 'ifcfg-$sanitized_real'
total 8
-rw-r--r-rw-r--r-. 1 root root 365 Nov 25 11:44 ifcfg-ens32
Updated by The Foreman Bot about 2 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/9523 added
Updated by Sayan Das about 2 years ago
Based on the detailed discussion later with the reviewers, The following has been finalized:
- By default, The filename will not be escaped ( even if it has any whitespace or special characters ) when save_to_file macro is used.
- End-users will need to process such filenames via shell_escape if any special characters need to be escaped.
- The same updates along with an example would be updated in the macro description as well.
Updated by Ewoud Kohl van Wijngaarden about 2 years ago
- Related to Bug #35530: save_to_file macro does not work if the thing being saved contains a heredoc terminated with EOF added
Updated by Ewoud Kohl van Wijngaarden about 2 years ago
- Has duplicate Bug #35814: save_to_file does not work as expected when a shell variable needs to be part of the saved file name added
Updated by Leos Stejskal about 2 years ago
- Status changed from Ready For Testing to Closed