Bug 2168967

Summary: New kickstart_kernel_options snippet breaks UEFI (Grub2) PXE provisioning when boot_mode is static
Product: Red Hat Satellite Reporter: Joniel Pasqualetto <jpasqual>
Component: Provisioning TemplatesAssignee: Joniel Pasqualetto <jpasqual>
Status: CLOSED ERRATA QA Contact: sganar
Severity: medium Docs Contact:
Priority: high    
Version: 6.12.1CC: ahumbe, etiennedh, jbreitwe, lstejska, mhulan, osousa, pcreech, riehecky, risantam, sadas, saydas
Target Milestone: 6.13.0Keywords: Regression, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-3.5.1.12-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2175005 (view as bug list) Environment:
Last Closed: 2023-05-03 13:25:08 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 Joniel Pasqualetto 2023-02-10 19:13:03 UTC
Description of problem:

Starting on Satellite 6.12.2 (foreman-3.3.0.20-1.el8sat.noarch) a new version of the snippet kickstart_kernel_options is shipped.

This new version includes new options that push a parameter "static=1" to the ks URL. However, when pushing this extra parameter, it needs to co-exist with token=<token> on the same URL. The URL generated is not properly escaped and then we hit this Grub2 issue[1]

Solution is to properly escape the URL.

[1] https://access.redhat.com/solutions/6810791

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

foreman-3.3.0.20-1.el8sat.noarch

How reproducible:

Always

Steps to Reproduce:
1. Have subnet with boot mode set to static
2. Try provisioning an UEFI hosts (using PXELoader Grub2 UEFI)
3. When boot, system will stop on the grub terminal(won't load the grub configuration)

Actual results:
Fails to PXE boot

Expected results:
Boot properly and start provisioning

Additional info:

marked version 6.12.1 because couldn't find 6.12.2 on the list. Keep in mind that  6.12.1 should not be affected by this issue.

Comment 1 Joniel Pasqualetto 2023-02-10 20:32:43 UTC
Workaround for customers running Satellite 6.12.2:

Create a patch file named /root/kickstart_kernel_options_fix.patch with the following content:

~~~
--- original.erb	2023-02-10 15:16:54.429723695 -0500
+++ fix.erb	2023-02-10 15:18:37.722730201 -0500
@@ -39,19 +39,19 @@
   # both current and legacy syntax provided
   if (is_fedora && os_major >= 33) || (rhel_compatible && os_major >= 9)
     if subnet4 && !subnet4.dhcp_boot_mode?
-      options.push("inst.ks=#{foreman_url('provision', static: '1')}")
+      options.push("inst.ks=#{foreman_url('provision', static: '1').gsub('&','\\\\&')}")
     elsif subnet6 && !subnet6.dhcp_boot_mode?
-      options.push("inst.ks=#{foreman_url('provision', static6: '1')}")
+      options.push("inst.ks=#{foreman_url('provision', static6: '1').gsub('&','\\\\&')}")
     else
-      options.push("inst.ks=#{foreman_url('provision')}", "inst.ks.sendmac")
+      options.push("inst.ks=#{foreman_url('provision').gsub('&','\\\\&')}", "inst.ks.sendmac")
     end
   else
     if subnet4 && !subnet4.dhcp_boot_mode?
-      options.push("ks=#{foreman_url('provision', static: '1')}")
+      options.push("ks=#{foreman_url('provision', static: '1').gsub('&','\\\\&')}")
     elsif subnet6 && !subnet6.dhcp_boot_mode?
-      options.push("ks=#{foreman_url('provision', static6: '1')}")
+      options.push("ks=#{foreman_url('provision', static6: '1').gsub('&','\\\\&')}")
     else
-      options.push("ks=#{foreman_url('provision')}", "kssendmac", "ks.sendmac")
+      options.push("ks=#{foreman_url('provision').gsub('&','\\\\&')}", "kssendmac", "ks.sendmac")
     end  
   end
~~~

Run the following commands:

TEMPLATE_ID=$(hammer template list --search name=kickstart_kernel_options --fields id |grep -v -e 'ID' -e '^-')
cp /usr/share/foreman/app/views/unattended/provisioning_templates/snippet/kickstart_kernel_options.erb /root/kickstart_kernel_options_fix.erb
patch -p1 /root/kickstart_kernel_options_fix.erb < /root/kickstart_kernel_options_fix.patch 
hammer template update --locked false --id $TEMPLATE_ID
hammer template import --name kickstart_kernel_options --file /root/kickstart_kernel_options_fix.erb
hammer template update --locked true --id $TEMPLATE_ID

Comment 2 etiennedh 2023-02-13 19:30:51 UTC
same problem here.

need to force "BIOS mode" in VMware to start the VM

Comment 3 Joniel Pasqualetto 2023-02-13 19:39:44 UTC
Hello 

Have a look at comment #1 for a workaround: https://bugzilla.redhat.com/show_bug.cgi?id=2168967#c1

It was marked private, but I don't see a reason to keep it that way.

If you're a Red Hat customer, you can also find the workaround here: https://access.redhat.com/solutions/6997923

Comment 4 Leos Stejskal 2023-02-14 09:18:38 UTC
Hi,
in upstream PR [0] is suggested to use different approach,
instead of escaping special chars just quote the URL.
Could you please confirm the fix?

[0] https://github.com/theforeman/foreman/pull/9582/files

Comment 5 Joniel Pasqualetto 2023-02-14 13:13:13 UTC
Hello

While quoting would work for Grub2 and solve the problem described in this BZ, using a quoted URL would break BIOS provisioning which uses Grub.

Escaping works in both scenarios and that's why I proposed escaping in my PR.

Comment 6 Leos Stejskal 2023-02-23 13:52:45 UTC
*** Bug 2172545 has been marked as a duplicate of this bug. ***

Comment 8 Brad Buckingham 2023-02-23 16:58:15 UTC
Moving to POST as PR is merged upstream.

Comment 13 errata-xmlrpc 2023-05-03 13:25:08 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

Comment 14 Odilon Sousa 2023-10-26 18:04:25 UTC
*** Bug 2242913 has been marked as a duplicate of this bug. ***