Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2148433 - kickstart_networking_setup template does not configure network
Summary: kickstart_networking_setup template does not configure network
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Provisioning Templates
Version: 6.12.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium with 3 votes
Target Milestone: 6.13.0
Assignee: Sayan Das
QA Contact: visawant
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-11-25 12:38 UTC by Satyajit Das
Modified: 2023-05-03 13:23 UTC (History)
12 users (show)

Fixed In Version: foreman-3.5.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2158567 (view as bug list)
Environment:
Last Closed: 2023-05-03 13:23:05 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 35530 0 Normal Closed save_to_file macro does not work if the thing being saved contains a heredoc terminated with EOF 2022-12-07 12:47:22 UTC
Foreman Issue Tracker 35792 0 Normal Closed save_to_file function should not use shellescape on the filename 2023-01-03 13:59:26 UTC
Github SatelliteQE robottelo pull 10993 0 None Merged Add closed loop BZ#2148433 for Provisioning Templates 2023-03-24 07:41:49 UTC
Red Hat Issue Tracker SAT-14067 0 None None None 2022-11-28 14:17:35 UTC
Red Hat Knowledge Base (Solution) 6987997 0 None None None 2023-01-11 14:51:43 UTC
Red Hat Product Errata RHSA-2023:2097 0 None None None 2023-05-03 13:23:18 UTC

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


Note You need to log in before you can comment on or make changes to this bug.