Bug 2148433

Summary: kickstart_networking_setup template does not configure network
Product: Red Hat Satellite Reporter: Satyajit Das <sadas>
Component: Provisioning TemplatesAssignee: Sayan Das <saydas>
Status: CLOSED ERRATA QA Contact: visawant
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.12.0CC: ahumbe, ajambhul, aperotti, arunas.z.vaznevicius, j.becker, lstejska, mhulan, pcreech, saydas, sebastien.girard, sganar, shwsingh
Target Milestone: 6.13.0Keywords: EasyFix, Regression, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-3.5.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2158567 (view as bug list) Environment:
Last Closed: 2023-05-03 13:23:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Satyajit Das 2022-11-25 12:38:10 UTC
Description of problem:

kickstart_networking_setup template does not configure the network


Version-Release number of selected component (if applicable):

6.12

How reproducible:

100%


Steps to Reproduce:
1. Deploy a fresh 6.12 satellite.
2. Configure provisioning setup
3. Create a host and review the template:-

Actual results:

preview shows this:
cat << EOF-cd4e31fd > /etc/sysconfig/network-scripts/ifcfg-\$sanitized_real

and should be without backslash "\"


==========================================
As I am using PXE to provision the host, for me the host is provisioned successfully, however on the client host, it created two entries.

# 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
==========================================
# cat /etc/sysconfig/network-scripts/ifcfg-\$sanitized_real 
BOOTPROTO="dhcp"
DOMAIN="example.com"
DEVICE=ens32
HWADDR="00:50:56:b4:4f:c6"
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
DEFROUTE=yes
MTU=1500


Expected results:

Validate interface should be created.


Additional info:

Comment 2 Sayan Das 2022-11-25 13:39:31 UTC
This change done in Satellite 6.12 seems to be creating the issue i.e. https://github.com/theforeman/foreman/commit/767fea2621952fc0cf14120b723614f58e1bd818 

Specifically the shellescape on the filename here in https://github.com/theforeman/foreman/blob/develop/app/services/foreman/renderer/scope/macros/base.rb#L116 

# 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"



6.11 does this:

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


But due to the change in 6.12 code, It does this:

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 following fixes the escaping issue i.e. 

diff --git a/app/services/foreman/renderer/scope/macros/base.rb b/app/services/foreman/renderer/scope/macros/base.rb
index 9b7304a..ebdde11 100644
--- a/app/services/foreman/renderer/scope/macros/base.rb
+++ b/app/services/foreman/renderer/scope/macros/base.rb
             example "save_to_file('/etc/motd', \"hello\\nworld\\n\") # => 'cat << EOF-0e4f089a > /etc/motd\\nhello\\nworld\\nEOF-0e4f089a'"
           def save_to_file(filename, content, verbatim: false)
-            filename = filename.shellescape
             delimiter = 'EOF-' + Digest::SHA512.hexdigest(filename)[0..7]
             if content.empty?
               "cp /dev/null #{filename}"

Comment 3 Sayan Das 2022-11-25 13:45:32 UTC
I am not sure if we absolutely have to use shellescape here on the filename or not. But if yes, Then The resolution perhaps will become more complicated.

It would be good if someone from the Engg team can share their opinion here as well.

Comment 5 Satyajit Das 2022-11-25 14:27:43 UTC
(In reply to Sayan Das from comment #3)
> I am not sure if we absolutely have to use shellescape here on the filename
> or not. But if yes, Then The resolution perhaps will become more complicated.
> 
> It would be good if someone from the Engg team can share their opinion here
> as well.

@sayan, after the changes it's working as expected. can you share the steps to apply the fix in the bug, so that I can share the same with the customer.

Comment 6 Sayan Das 2022-11-25 14:30:27 UTC
Hi Satyajit.

This is what I did.

# cd /usr/share/foreman

# git init .;git add .;git commit -m 'original state'

--> Create the file 2148433.patch manually here with the following content.

diff --git a/app/services/foreman/renderer/scope/macros/base.rb b/app/services/foreman/renderer/scope/macros/base.rb
index 9b7304a..ebdde11 100644
--- a/app/services/foreman/renderer/scope/macros/base.rb
+++ b/app/services/foreman/renderer/scope/macros/base.rb
@@ -113,7 +113,6 @@ module Foreman
             example "save_to_file('/etc/motd', \"hello\\nworld\\n\") # => 'cat << EOF-0e4f089a > /etc/motd\\nhello\\nworld\\nEOF-0e4f089a'"
           end
           def save_to_file(filename, content, verbatim: false)
-            filename = filename.shellescape
             delimiter = 'EOF-' + Digest::SHA512.hexdigest(filename)[0..7]
             if content.empty?
               "cp /dev/null #{filename}"
               
               
--> Apply the patch:

# patch -p1 < 2148433.patch

# systemctl restart httpd foreman

# sleep 20 && hammer ping


and then simply rebuild the host or test a new build.

Comment 7 Sayan Das 2022-11-25 14:56:06 UTC
Connecting redmine issue https://projects.theforeman.org/issues/35792 from this bug.

Comment 9 Leos Stejskal 2022-12-13 08:37:19 UTC
Moving to modified as upstream PR have been merged and cherry-picked into the 3.5 upstream branch: https://github.com/theforeman/foreman/commit/9c56caa860cb9c641400184da9859839a9ea780e

Comment 13 errata-xmlrpc 2023-05-03 13:23:05 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: Satellite 6.13 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:2097