Skip to content

Commit 4d36470

Browse files
committed
Merge: uki_addons: add downstream SBAT for UKI addons
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6893 JIRA: https://issues.redhat.com/browse/RHEL-92594 Upstream Status: RHEL-Only Replace the old sbat/sbat.conf mechanism with a input-provided sbat one. Also provide a downstream sbat for the generated addons, as it's better to have it in case we have bugs in the command line too. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Approved-by: Vitaly Kuznetsov <vkuznets@redhat.com> Approved-by: Jan Stancek <jstancek@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Jan Stancek <jstancek@redhat.com>
2 parents 5661b45 + 61a167b commit 4d36470

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

redhat/kernel.spec.template

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,12 @@ BuildKernel() {
23822382
EOF
23832383
)
23842384

2385+
ADDONS_SBAT=$(cat <<- EOF
2386+
sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
2387+
kernel-uki-virt-addons.$SBATsuffix,1,Red Hat,kernel-uki-virt-addons,$KernelVer,mailto:secalert@redhat.com
2388+
EOF
2389+
)
2390+
23852391
KernelUnifiedImageDir="$RPM_BUILD_ROOT/lib/modules/$KernelVer"
23862392
KernelUnifiedImage="$KernelUnifiedImageDir/$InstallName-virt.efi"
23872393

@@ -2401,7 +2407,7 @@ BuildKernel() {
24012407

24022408
KernelAddonsDirOut="$KernelUnifiedImage.extra.d"
24032409
mkdir -p $KernelAddonsDirOut
2404-
python3 %{SOURCE151} %{SOURCE152} $KernelAddonsDirOut virt %{primary_target} %{_target_cpu}
2410+
python3 %{SOURCE151} %{SOURCE152} $KernelAddonsDirOut virt %{primary_target} %{_target_cpu} "$ADDONS_SBAT"
24052411

24062412
%if %{signkernel}
24072413

redhat/scripts/uki_addons/uki_create_addons.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# creates an addon for each key/value pair matching the given uki, distro and
55
# arch provided in input.
66
#
7-
# Usage: python uki_create_addons.py input_json out_dir uki distro arch
7+
# Usage: python uki_create_addons.py input_json out_dir uki distro arch [sbat]
88
#
99
# This tool requires the systemd-ukify and systemd-boot packages.
1010
#
@@ -26,14 +26,6 @@
2626
# json['virt']['common']['test.addon'] = ['test2'], any other uki except virt
2727
# will have a test.addon.efi with text "test1", and virt will have a
2828
# test.addon.efi with "test2"
29-
#
30-
# sbat.conf
31-
#----------
32-
# This dict is containing the sbat string for *all* addons being created.
33-
# This dict is optional, but when used has to be put in a sub-dict with
34-
# { 'sbat' : { 'sbat.conf' : ['your text here'] }}
35-
# It follows the same syntax as the addon files, meaning '#' is comment and
36-
# the rest is taken as sbat string and feed to ukify.
3729

3830
import os
3931
import sys
@@ -45,7 +37,7 @@
4537
UKIFY_PATH = '/usr/lib/systemd/ukify'
4638

4739
def usage(err):
48-
print(f'Usage: {os.path.basename(__file__)} input_json output_dir uki distro arch')
40+
print(f'Usage: {os.path.basename(__file__)} input_json output_dir uki distro arch [sbat]')
4941
print(f'Error:{err}')
5042
sys.exit(1)
5143

@@ -62,37 +54,26 @@ def check_clean_arguments(input_json, out_dir):
6254
UKICmdlineAddon = collections.namedtuple('UKICmdlineAddon', ['name', 'cmdline'])
6355
uki_addons_list = []
6456
uki_addons = {}
65-
addon_sbat_string = None
6657

67-
def parse_lines(lines, rstrip=True):
58+
def parse_lines(lines):
6859
cmdline = ''
6960
for l in lines:
7061
l = l.lstrip()
7162
if not l:
7263
continue
7364
if l[0] == '#':
7465
continue
75-
# rstrip is used only for addons cmdline, not sbat.conf, as it replaces
76-
# return lines with spaces.
77-
if rstrip:
78-
l = l.rstrip() + ' '
79-
cmdline += l
66+
cmdline += l.rstrip() + ' '
8067
if cmdline == '':
8168
return ''
8269
return cmdline
8370

8471
def parse_all_addons(in_obj):
85-
global addon_sbat_string
86-
8772
for el in in_obj.keys():
8873
# addon found: copy it in our global dict uki_addons
8974
if el.endswith('.addon'):
9075
uki_addons[el] = in_obj[el]
9176

92-
if 'sbat' in in_obj and 'sbat.conf' in in_obj['sbat']:
93-
# sbat.conf found: override sbat with the most specific one found
94-
addon_sbat_string = parse_lines(in_obj['sbat']['sbat.conf'], rstrip=False)
95-
9677
def recursively_find_addons(in_obj, folder_list):
9778
# end of recursion, leaf directory. Search all addons here
9879
if len(folder_list) == 0:
@@ -121,21 +102,21 @@ def parse_in_json(in_json, uki_name, distro, arch):
121102
if cmdline:
122103
uki_addons_list.append(UKICmdlineAddon(addon_full_name, cmdline))
123104

124-
def create_addons(out_dir):
105+
def create_addons(out_dir, sbat):
125106
for uki_addon in uki_addons_list:
126107
out_path = os.path.join(out_dir, uki_addon.name)
127108
cmd = [
128109
f'{UKIFY_PATH}', 'build',
129110
'--cmdline', uki_addon.cmdline,
130111
'--output', out_path]
131-
if addon_sbat_string:
132-
cmd.extend(['--sbat', addon_sbat_string.rstrip()])
112+
if sbat:
113+
cmd.extend(['--sbat', sbat.rstrip()])
133114

134115
subprocess.check_call(cmd, text=True)
135116

136117
if __name__ == "__main__":
137118
argc = len(sys.argv) - 1
138-
if argc != 5:
119+
if argc < 5 or argc > 6:
139120
usage('too few or too many parameters!')
140121

141122
input_json = sys.argv[1]
@@ -144,8 +125,12 @@ def create_addons(out_dir):
144125
distro = sys.argv[4]
145126
arch = sys.argv[5]
146127

128+
custom_sbat = None
129+
if argc == 6:
130+
custom_sbat = sys.argv[6]
131+
147132
out_dir = check_clean_arguments(input_json, out_dir)
148133
parse_in_json(input_json, uki_name, distro, arch)
149-
create_addons(out_dir)
134+
create_addons(out_dir, custom_sbat)
150135

151136

redhat/scripts/uki_addons/uki_create_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# The name of the end resulting addon is taken from the folder hierarchy, but this
2222
# is handled by uki_create_addons.py when building the rpm. This script only
2323
# prepares the json file to be added in the srpm. For more information about
24-
# the folder hierarchy, what the 'common' and 'sbat' folder are, look at
24+
# the folder hierarchy and what the 'common' folder is, look at
2525
# uki_create_addons.py.
2626
#
2727
# The common folder, present in any folder under redhat/uki_addons
@@ -51,7 +51,7 @@ def usage(err):
5151
sys.exit(1)
5252

5353
def find_addons():
54-
cmd = ['/usr/bin/find', 'uki_addons', "(", '-name', '*.addon', '-o', '-name', 'sbat.conf', ")"]
54+
cmd = ['/usr/bin/find', 'uki_addons', '-name', '*.addon']
5555
proc_out = subprocess.run(cmd, check=True, capture_output=True, text=True)
5656
if proc_out.returncode == 0:
5757
return proc_out.stdout

0 commit comments

Comments
 (0)