Skip to content

Commit c3e8b62

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 c3e8b62

3 files changed

Lines changed: 58 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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 sys
7+
8+
9+
FIPS_SH = Path("/usr/lib/dracut/modules.d/01fips/fips.sh")
10+
11+
OLD = """ if ! mount -oro "$boot" /boot; then
12+
return 1
13+
fi
14+
FIPS_MOUNTED_BOOT=1
15+
"""
16+
17+
NEW = """ if ! mount -oro "$boot" /boot; then
18+
local _bp
19+
for _bp in /sysroot/sysroot/boot /sysroot/boot; do
20+
if [ -d "${_bp}/ostree" ]; then
21+
fips_info "Device mount failed, bind-mounting ${_bp} to /boot"
22+
if mount --bind "${_bp}" /boot; then
23+
break
24+
fi
25+
fi
26+
done
27+
ismounted /boot || return 1
28+
fi
29+
FIPS_MOUNTED_BOOT=1
30+
"""
31+
32+
33+
def main() -> int:
34+
text = FIPS_SH.read_text()
35+
36+
if NEW in text:
37+
print(f"{FIPS_SH} already patched")
38+
return 0
39+
40+
if OLD not in text:
41+
print(f"expected mount_boot block not found in {FIPS_SH}", file=sys.stderr)
42+
return 1
43+
44+
FIPS_SH.write_text(text.replace(OLD, NEW))
45+
print(f"patched {FIPS_SH}")
46+
return 0
47+
48+
49+
if __name__ == "__main__":
50+
raise SystemExit(main())

0 commit comments

Comments
 (0)