Project

General

Profile

Actions

Bug #35792

closed

save_to_file function should not use shellescape on the filename

Added by Sayan Das over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Templates
Target version:
-
Difficulty:
easy
Triaged:
No
Fixed in Releases:
Found in Releases:

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

  1. 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.

  1. ls l /etc/sysconfig/network-scripts
    total 8
    -rw-r--r-
    . 1 root root 153 Nov 25 11:44 'ifcfg-$sanitized_real'
    rw-r--r-. 1 root root 365 Nov 25 11:44 ifcfg-ens32

Related issues 2 (0 open2 closed)

Related to Foreman - Bug #35530: save_to_file macro does not work if the thing being saved contains a heredoc terminated with EOFClosedAdam RuzickaActions
Has duplicate Foreman - Bug #35814: save_to_file does not work as expected when a shell variable needs to be part of the saved file nameClosedActions
Actions #1

Updated by The Foreman Bot over 1 year ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/9523 added
Actions #2

Updated by Sayan Das over 1 year 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.
Actions #3

Updated by Ewoud Kohl van Wijngaarden over 1 year ago

  • Related to Bug #35530: save_to_file macro does not work if the thing being saved contains a heredoc terminated with EOF added
Actions #4

Updated by Ewoud Kohl van Wijngaarden over 1 year 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
Actions #5

Updated by Leos Stejskal over 1 year ago

  • Status changed from Ready For Testing to Closed
Actions

Also available in: Atom PDF