Skip to content

Commit b6a7bee

Browse files
committed
Patch bootc FIPS dracut boot handling
bootc non-LUKS single-root deployments can fail FIPS boot because dracut's `01fips` module assumes `/boot` can be mounted read-only as a separate device. On bootc single-root layouts that mount can fail before the kernel HMAC check runs. Patch the image at build time so dracut falls back to bind-mounting the existing /boot tree when the default mount path fails. This is an image-side workaround for the current bootc single-root FIPS boot path; the underlying fix should eventually land upstream in dracut, bootc, or their interaction. Signed-off-by: rabi <ramishra@redhat.com>
1 parent af252e5 commit b6a7bee

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

bootc/Containerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ RUN --mount=type=secret,id=rhsm,dst=/var/tmp/rhsm-script.sh \
144144
(subscription-manager unregister || true) && \
145145
systemctl enable $ENABLE_UNITS
146146

147+
COPY patch-dracut-fips.py /usr/local/bin/patch-dracut-fips.py
148+
RUN python3 /usr/local/bin/patch-dracut-fips.py && \
149+
bash -n /usr/lib/dracut/modules.d/01fips/fips.sh
150+
147151

148152
# Configure FIPS
149153
ARG FIPS=1

bootc/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ then run the following commands::
2828
To continue using CentOS Stream 9, leave the defaults in place and run
2929
``make build`` (the default tag is ``latest``).
3030

31+
FIPS-enabled images include a build-time patch to dracut's ``01fips`` module
32+
so bootc deployments on single-root layouts can bind-mount the existing
33+
``/boot`` tree when the standard read-only device mount fails.
34+
3135
To build a RHEL 9 based bootc EDPM container image using internal repositories,
3236
install the required certificates then run the following commands::
3337

bootc/patch-dracut-fips.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
"""Patch dracut's FIPS boot handling for bootc single-root layouts."""
4+
5+
from pathlib import Path
6+
import re
7+
import sys
8+
9+
10+
FIPS_SH = Path("/usr/lib/dracut/modules.d/01fips/fips.sh")
11+
PATTERN = re.compile(
12+
r'(?ms)^([ \t]*)if ! mount -oro "\$boot" /boot; then\n'
13+
r'(?:.*\n)*?^\1FIPS_MOUNTED_BOOT=1\n'
14+
)
15+
16+
17+
def main() -> int:
18+
text = FIPS_SH.read_text()
19+
20+
if 'Device mount failed, bind-mounting ${_bp} to /boot' in text:
21+
print(f"{FIPS_SH} already patched")
22+
return 0
23+
24+
match = PATTERN.search(text)
25+
if not match:
26+
print(f"expected mount_boot block not found in {FIPS_SH}", file=sys.stderr)
27+
return 1
28+
29+
indent = match.group(1)
30+
replacement = "\n".join([
31+
f'{indent}if ! mount -oro "$boot" /boot; then',
32+
f'{indent} local _bp',
33+
f'{indent} for _bp in /sysroot/sysroot/boot /sysroot/boot; do',
34+
f'{indent} if [ -d "${{_bp}}/ostree" ]; then',
35+
f'{indent} fips_info "Device mount failed, bind-mounting ${{_bp}} to /boot"',
36+
f'{indent} if mount --bind "${{_bp}}" /boot; then',
37+
f'{indent} break',
38+
f'{indent} fi',
39+
f'{indent} fi',
40+
f'{indent} done',
41+
f'{indent} ismounted /boot || return 1',
42+
f'{indent}fi',
43+
f'{indent}FIPS_MOUNTED_BOOT=1',
44+
"",
45+
])
46+
FIPS_SH.write_text(PATTERN.sub(replacement, text, count=1))
47+
print(f"patched {FIPS_SH}")
48+
return 0
49+
50+
51+
if __name__ == "__main__":
52+
raise SystemExit(main())

0 commit comments

Comments
 (0)