Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s390x: add secure-execution support #1353

Merged
merged 4 commits into from
Jun 27, 2022

Conversation

nikita-dubrovskii
Copy link
Contributor

@nikita-dubrovskii nikita-dubrovskii commented Nov 29, 2021

This adds genprotimg tool, for creating encrypted sd-boot image, and turns on (if required) SecureExecution during firstboot-complete
Depends on: coreos/coreos-installer#851

Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As previously agreed, hold until feature planning is complete.

@nikita-dubrovskii nikita-dubrovskii force-pushed the secure-execution branch 2 times, most recently from 626f9eb to 0609f3e Compare February 16, 2022 16:37
@bgilbert bgilbert dismissed their stale review February 17, 2022 06:16

No longer blocked on planning.

@nikita-dubrovskii nikita-dubrovskii changed the title s390x: add base secure-execution support WIP: add base secure-execution support Apr 19, 2022
@nikita-dubrovskii nikita-dubrovskii force-pushed the secure-execution branch 4 times, most recently from 00f916d to 194400a Compare April 22, 2022 10:45
@nikita-dubrovskii nikita-dubrovskii changed the title WIP: add base secure-execution support s390x: add secure-execution support May 5, 2022
Copy link
Member

@travier travier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only added some suggestions as I don't have the context to review.

@nikita-dubrovskii nikita-dubrovskii force-pushed the secure-execution branch 2 times, most recently from e63b281 to 0b9b28a Compare May 24, 2022 14:15
device=$(realpath /dev/disk/by-label/"${DM_NAME}")
eval $(udevadm info --query=property --export $device | grep PARTN=)
eval $(lsblk -o PKNAME --nodeps --noheadings --paths --pairs $device)
parted $PKNAME resizepart $PARTN 100%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already done by growpart at the earlier part iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it does, than it's broken or doesn't work wit LUKS pre-encrypted partitions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That growpart is tested by CI at least. There's actually a LUKS test which does this: https://github.com/coreos/fedora-coreos-config/tree/testing-devel/tests/kola/root-reprovision/luks. That should be the same setup as we have here (root on LUKS on partition).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some debug output:

[   19.502720] ignition-ostree-growfs[1292]: ++ realpath /dev/disk/by-label/root
[   19.503058] ignition-ostree-growfs[1288]: + partition=/dev/dm-0
[   19.503216] ignition-ostree-growfs[1293]: + lsblk -no TYPE /dev/dm-0
...
[   19.504843] ignition-ostree-growfs[1288]: + current_blkdev=/dev/dm-0
[   19.504855] ignition-ostree-growfs[1288]: + true
[   19.504933] ignition-ostree-growfs[1296]: ++ lsblk --paths --nodeps --pairs -o NAME,TYPE,PKNAME /dev/dm-0
[   19.505523] ignition-ostree-growfs[1288]: + eval 'NAME="/dev/mapper/crypt_rootfs" TYPE="crypt" PKNAME=""'
[   19.505538] ignition-ostree-growfs[1288]: ++ NAME=/dev/mapper/crypt_rootfs
[   19.505550] ignition-ostree-growfs[1288]: ++ TYPE=crypt
[   19.505561] ignition-ostree-growfs[1288]: ++ PKNAME=
[   19.505892] ignition-ostree-growfs[1298]: +++ lsblk -dno MAJ:MIN /dev/mapper/crypt_rootfs

So we always enter crypt case-switch first. And part is unreachable in that case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be the same setup as we have here (root on LUKS on partition).

pls correct me if i'm wrong, but that test creates LUKSed root with ignition.disks stage

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, that test uses Ignition to create the LUKS root. I thought the end result would be the same, but maybe I'm missing something.

What's the output of lsblk on a booted s390x system with your cosa patch? Maybe we should do a screen sharing session for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core@localhost ~]$ lsblk -f
NAME             FSTYPE      FSVER LABEL        UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
vda                                                                                                 
|-vda1           ext4        1.0   se           71589f1a-5698-4d22-8877-91317173ec61                
|-vda3           crypto_LUKS 2     crypt_bootfs 8dc99436-f245-470e-81c3-d2f07d49dcfa                
| `-crypt_bootfs ext4        1.0   boot         a774674a-e0d6-11ec-8ab8-0f20fe3c51e1    224M    26% /boot
`-vda4           crypto_LUKS 2     crypt_rootfs 5e9d4812-87e5-4ed7-8c68-dd1874031839                
  `-crypt_rootfs xfs               root         a8ec61ea-e0d6-11ec-a07c-525400123456    7.9G    16% /var
                                                                                                    /sysroot/ostree/deploy/fedora-coreos/var
                                                                                                    /usr
                                                                                                    /etc
                                                                                                    /
                                                                                                    /sysroot

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK right, looking at this more, I think we need to adapt the top of the file to handle Secure Execution correctly. Can you try the following patch on top of this PR?

diff --git a/manifests/bootable-rpm-ostree.yaml b/manifests/bootable-rpm-ostree.yaml
index b0659834..8c41320c 100644
--- a/manifests/bootable-rpm-ostree.yaml
+++ b/manifests/bootable-rpm-ostree.yaml
@@ -29,8 +29,6 @@ packages-s390x:
   # provided by s390utils-base, but soon will be -core too.
   - /usr/sbin/zipl
   - /usr/bin/genprotimg
-  # resize LUKS encrypted rootfs
-  - /usr/sbin/parted
 packages-x86_64:
   - grub2 grub2-efi-x64 efibootmgr shim
   - microcode_ctl
diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh
index 1a0d68a7..946de6e1 100755
--- a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh
+++ b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh
@@ -17,8 +17,21 @@ path=/sysroot
 # this shouldn't happen for us but we're being conservative.
 src=$(findmnt -nvr -o SOURCE "$path" | tail -n1)

+# IBM SecureExecution
+secure_execution=0
+if [[ $(uname -m) == s390x ]] && [[ -e /sys/firmware/uv/prot_virt_guest ]]; then
+    secure_execution=$(cat /sys/firmware/uv/prot_virt_guest)
+fi
+
 if [ ! -f "${saved_partstate}" ]; then
     partition=$(realpath /dev/disk/by-label/root)
+    # in the Secure Execution case, the rootfs is pre-baked on LUKS, so
+    # `partition` is actually the device mapper device; get its parent
+    if [[ "${secure_execution}" != "0" ]]; then
+        # lsblk doesn't print PKNAME of crypt devices with --nodeps
+        MAJMIN=$(echo $(lsblk -dno MAJ:MIN "${partition}"))
+        partition=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
+    fi
 else
     # The rootfs was reprovisioned. Our rule in this case is: we only grow if
     # the partition backing the rootfs is the same and its size didn't change
@@ -40,12 +53,6 @@ else
     fi
 fi

-# IBM SecureExecution
-secure_execution=0
-if [[ $(uname -m) == s390x ]] && [[ -e /sys/firmware/uv/prot_virt_guest ]]; then
-    secure_execution=$(cat /sys/firmware/uv/prot_virt_guest)
-fi
-
 # Go through each blockdev in the hierarchy and verify we know how to grow them
 lsblk -no TYPE "${partition}" | while read dev; do
     case "${dev}" in
@@ -86,22 +93,13 @@ while true; do
             fi
             ;;
         crypt)
-            eval $(udevadm info --query=property --export "${NAME}")
-            if [[ "${secure_execution}" == "0" ]]; then
-                # XXX: yuck... we need to expose this sanely in clevis
-                (. /usr/bin/clevis-luks-common-functions
-                # lsblk doesn't print PKNAME of crypt devices with --nodeps
-                PKNAME=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
-                clevis_luks_unlock_device "${PKNAME}" | cryptsetup resize -d- "${DM_NAME}"
-                )
-            else
-                device=$(realpath /dev/disk/by-label/"${DM_NAME}")
-                eval $(udevadm info --query=property --export $device | grep PARTN=)
-                eval $(lsblk -o PKNAME --nodeps --noheadings --paths --pairs $device)
-                growpart "${PKNAME}" "${PARTN}" || :
-                parted $PKNAME resizepart $PARTN 100%
-                cryptsetup resize --key-file=/etc/luks/root "${DM_NAME}"
-            fi
+            # XXX: yuck... we need to expose this sanely in clevis
+            (. /usr/bin/clevis-luks-common-functions
+             eval $(udevadm info --query=property --export "${NAME}")
+             # lsblk doesn't print PKNAME of crypt devices with --nodeps
+             PKNAME=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
+             clevis_luks_unlock_device "${PKNAME}" | cryptsetup resize -d- "${DM_NAME}"
+            )
             ;;
         # already checked
         *) echo "unreachable" 1>&2; exit 1 ;;
diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh
index 1ce53c48..bf9a7872 100755
--- a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh
+++ b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh
@@ -46,7 +46,6 @@ install() {
         xfs_admin  \
         xfs_growfs \
         wc         \
-        parted     \
         wipefs

     # growpart deps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK right, looking at this more, I think we need to adapt the top of the file to handle Secure Execution correctly. Can you try the following patch on top of this PR?

yup, thx. only had to skip clevis part in SE. not sure, but maybe clevis bind could be used to automate the unlocking here. will check that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we cannot and shouldn't use clevis

@nikita-dubrovskii nikita-dubrovskii force-pushed the secure-execution branch 2 times, most recently from 6bda640 to 5e4f879 Compare May 27, 2022 15:43
device=$(realpath /dev/disk/by-label/"${DM_NAME}")
eval $(udevadm info --query=property --export $device | grep PARTN=)
eval $(lsblk -o PKNAME --nodeps --noheadings --paths --pairs $device)
parted $PKNAME resizepart $PARTN 100%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, that test uses Ignition to create the LUKS root. I thought the end result would be the same, but maybe I'm missing something.

What's the output of lsblk on a booted s390x system with your cosa patch? Maybe we should do a screen sharing session for this.

@nikita-dubrovskii nikita-dubrovskii force-pushed the secure-execution branch 3 times, most recently from 6cd553a to 02808f0 Compare May 31, 2022 14:42
@@ -28,6 +28,9 @@ packages-s390x:
# On Fedora, this is provided by s390utils-core. on RHEL, this is for now
# provided by s390utils-base, but soon will be -core too.
- /usr/sbin/zipl
- /usr/bin/genprotimg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to compose an s390x FCOS with this? I suspect it will fail because of:

We'll have to temporarily split that out into a separately conditional-included treefile until coreos/fedora-coreos-tracker#1217 is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to compose an s390x FCOS with this?

yes, no issues at all (metal/metal4k/qemu/secex/live/dasd images)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh interesting. So actually, /usr/bin/perl is provided by perl-interpreter, which is why this works.

I'll add it to the list, but will take care of doing the include splitting to not break s390x builds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to this in #1848 now that we've moved it out of FCOS again.

device=$(realpath /dev/disk/by-label/"${DM_NAME}")
eval $(udevadm info --query=property --export $device | grep PARTN=)
eval $(lsblk -o PKNAME --nodeps --noheadings --paths --pairs $device)
parted $PKNAME resizepart $PARTN 100%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK right, looking at this more, I think we need to adapt the top of the file to handle Secure Execution correctly. Can you try the following patch on top of this PR?

diff --git a/manifests/bootable-rpm-ostree.yaml b/manifests/bootable-rpm-ostree.yaml
index b0659834..8c41320c 100644
--- a/manifests/bootable-rpm-ostree.yaml
+++ b/manifests/bootable-rpm-ostree.yaml
@@ -29,8 +29,6 @@ packages-s390x:
   # provided by s390utils-base, but soon will be -core too.
   - /usr/sbin/zipl
   - /usr/bin/genprotimg
-  # resize LUKS encrypted rootfs
-  - /usr/sbin/parted
 packages-x86_64:
   - grub2 grub2-efi-x64 efibootmgr shim
   - microcode_ctl
diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh
index 1a0d68a7..946de6e1 100755
--- a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh
+++ b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/ignition-ostree-growfs.sh
@@ -17,8 +17,21 @@ path=/sysroot
 # this shouldn't happen for us but we're being conservative.
 src=$(findmnt -nvr -o SOURCE "$path" | tail -n1)

+# IBM SecureExecution
+secure_execution=0
+if [[ $(uname -m) == s390x ]] && [[ -e /sys/firmware/uv/prot_virt_guest ]]; then
+    secure_execution=$(cat /sys/firmware/uv/prot_virt_guest)
+fi
+
 if [ ! -f "${saved_partstate}" ]; then
     partition=$(realpath /dev/disk/by-label/root)
+    # in the Secure Execution case, the rootfs is pre-baked on LUKS, so
+    # `partition` is actually the device mapper device; get its parent
+    if [[ "${secure_execution}" != "0" ]]; then
+        # lsblk doesn't print PKNAME of crypt devices with --nodeps
+        MAJMIN=$(echo $(lsblk -dno MAJ:MIN "${partition}"))
+        partition=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
+    fi
 else
     # The rootfs was reprovisioned. Our rule in this case is: we only grow if
     # the partition backing the rootfs is the same and its size didn't change
@@ -40,12 +53,6 @@ else
     fi
 fi

-# IBM SecureExecution
-secure_execution=0
-if [[ $(uname -m) == s390x ]] && [[ -e /sys/firmware/uv/prot_virt_guest ]]; then
-    secure_execution=$(cat /sys/firmware/uv/prot_virt_guest)
-fi
-
 # Go through each blockdev in the hierarchy and verify we know how to grow them
 lsblk -no TYPE "${partition}" | while read dev; do
     case "${dev}" in
@@ -86,22 +93,13 @@ while true; do
             fi
             ;;
         crypt)
-            eval $(udevadm info --query=property --export "${NAME}")
-            if [[ "${secure_execution}" == "0" ]]; then
-                # XXX: yuck... we need to expose this sanely in clevis
-                (. /usr/bin/clevis-luks-common-functions
-                # lsblk doesn't print PKNAME of crypt devices with --nodeps
-                PKNAME=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
-                clevis_luks_unlock_device "${PKNAME}" | cryptsetup resize -d- "${DM_NAME}"
-                )
-            else
-                device=$(realpath /dev/disk/by-label/"${DM_NAME}")
-                eval $(udevadm info --query=property --export $device | grep PARTN=)
-                eval $(lsblk -o PKNAME --nodeps --noheadings --paths --pairs $device)
-                growpart "${PKNAME}" "${PARTN}" || :
-                parted $PKNAME resizepart $PARTN 100%
-                cryptsetup resize --key-file=/etc/luks/root "${DM_NAME}"
-            fi
+            # XXX: yuck... we need to expose this sanely in clevis
+            (. /usr/bin/clevis-luks-common-functions
+             eval $(udevadm info --query=property --export "${NAME}")
+             # lsblk doesn't print PKNAME of crypt devices with --nodeps
+             PKNAME=/dev/$(ls "/sys/dev/block/${MAJMIN}/slaves")
+             clevis_luks_unlock_device "${PKNAME}" | cryptsetup resize -d- "${DM_NAME}"
+            )
             ;;
         # already checked
         *) echo "unreachable" 1>&2; exit 1 ;;
diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh
index 1ce53c48..bf9a7872 100755
--- a/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh
+++ b/overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/module-setup.sh
@@ -46,7 +46,6 @@ install() {
         xfs_admin  \
         xfs_growfs \
         wc         \
-        parted     \
         wipefs

     # growpart deps

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@jlebon jlebon merged commit ecc9497 into coreos:testing-devel Jun 27, 2022
@nikita-dubrovskii nikita-dubrovskii deleted the secure-execution branch June 27, 2022 15:45
@jlebon
Copy link
Member

jlebon commented Jun 27, 2022

Hmm, interesting. It looks like the FCOS pipeline is failing to build s390x with this:

Importing rpm-md... done
rpm-md repo 'fedora-coreos-pool'; generated: 2022-06-26T16:28:46Z solvables: 17070
rpm-md repo 'fedora'; generated: 2022-05-04T21:15:53Z solvables: 57625
rpm-md repo 'fedora-updates'; generated: 2022-06-27T01:26:43Z solvables: 11906
error: Packages not found: /usr/bin/genprotimg

@jlebon
Copy link
Member

jlebon commented Jun 27, 2022

Ahh yes of course, we missed a step here. We need to add s390utils-base to the s390x lockfile as documented in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants