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

examples/unified-secureboot: Add Secure Boot signed example #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

travier
Copy link
Member

@travier travier commented Jan 17, 2025

examples/README: Split each sentence on its own line

Signed-off-by: Timothée Ravier [email protected]


examples/unified: Bind mount /tmp/sysroot

We need an fs-verity enabled for this operation so mount it from the
host which is more likely to have it (btrfs or ext4).

Signed-off-by: Timothée Ravier [email protected]


examples/unified-secureboot: Add Secure Boot signed example

  • Based on unified example
  • Generate keys for Secure Boot signing on demand
  • Add mokutil to list Secure Boot related info
  • Sign the UKI & systemd-boot
  • Generate EUFI VARS including only our own keys and pass it to the EDK2
    firwmare with QEMU

Signed-off-by: Timothée Ravier [email protected]

@allisonkarlitskaya
Copy link
Collaborator

I think the issues were caused by using fuse-overlayfs as your storage driver. Two fixes are in #63

@travier travier force-pushed the main-sb-signed branch 4 times, most recently from c41d676 to 83a3268 Compare January 29, 2025 17:19
@travier travier marked this pull request as ready for review January 29, 2025 17:19
We need an fs-verity enabled for this operation so mount it from the
host which is more likely to have it (btrfs or ext4).

Signed-off-by: Timothée Ravier <[email protected]>
- Based on `unified` example
- Generate keys for Secure Boot signing on demand
- Add mokutil to list Secure Boot related info
- Sign the UKI & systemd-boot
- Generate EUFI VARS including only our own keys and pass it to the EDK2
  firwmare with QEMU

Signed-off-by: Timothée Ravier <[email protected]>
@travier travier changed the title example/unified: Sign UKI for Secure Boot examples/unified-secureboot: Add Secure Boot signed example Jan 30, 2025
Copy link
Collaborator

@allisonkarlitskaya allisonkarlitskaya left a comment

Choose a reason for hiding this comment

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

Let's try to get this merged next week :)

Image](https://github.com/uapi-group/specifications/blob/main/specs/unified_kernel_image.md). If this image is signed then the signature effectively covers every single file in the filesystem. This works with a special form of multi-stage `Containerfile` which builds a base image, measures it using `cfsctl` and then uses that measurement to inject the composefs image fs-verity hash into the second stage of the build which actually builds the UKI (and embeds the hash into the `.cmdline`). We avoid a circular hash dependency by removing the UKI from the final image via a white-out (but `cfsctl` still knows how to find it).
- `bls`: an OS built around a separate kernel and initramfs installed with a [Type #1 Boot Loader Specification Entries](https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-specification-entries). In this case we simply hack the bootloader entry to refer to the correct composefs hash at install type.
- `unified`: similar to the `uki` example, but avoiding the intermediate `cfsctl` step by running `cfsctl` inside a build stage from the `Containerfile` itself. This involves bind-mounting the earlier build stage of the base image so that we can measure it from inside the stage that builds the UKI.
- `uki`: an OS built around a [Unified Kernel Image](https://github.com/uapi-group/specifications/blob/main/specs/unified_kernel_image.md).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure why I did such long lines here. Maybe it would make more sense to wrap on 72 or something?

@@ -13,10 +13,12 @@ CFSCTL='./cfsctl --repo tmp/sysroot/composefs'
rm -rf tmp
mkdir -p tmp/sysroot/composefs tmp/sysroot/var

# mkdir tmp/internal-sysroot # for debugging
# podman build -v $(pwd)/tmp/internal-sysroot:/tmp/sysroot:z,U --iidfile=tmp/iid "$@" .
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really strange: in my head I committed this without this code commented out. Thanks for bringing it back.

I wonder if this would let us enable the unified example in GitHub Actions.


set -eux

cd "${0%/*}"

if [[ -d "secureboot" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think it might make sense to make this into a separate script as well? The secureboot-related bits of it are ~80-90% of the file at this point.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On the other hand, it might be interesting (in theory) to be able to add secure boot support to the other examples. hmm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, ideally we should add Secure Boot to all examples so we don't need distinct ones for Secure Boot.

I can also copy this script if you prefer.

if [[ ! -d "secureboot" ]]; then
echo "Generating test Secure Boot keys"
mkdir secureboot
pushd secureboot > /dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

I sort of like doing this pattern:

(
    cd secureboot
    ...
)

mkdir -p tmp/efi/loader
echo 'timeout 3' > tmp/efi/loader/loader.conf
mkdir -p tmp/efi/EFI/BOOT tmp/efi/EFI/systemd
sbsign --key secureboot/db.key --cert secureboot/db.crt \
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we sign the UKI inside of the container build but we do this out of band. That's interesting...

Of course we can't sign the kernel out here, because it's part of the image itself...

I guess this starts to brush up against ideas about bootupd and how to get the boot resources from inside of the container...

Copy link
Member Author

Choose a reason for hiding this comment

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

This is clearly a shortcut here. We should sign it in the container like we do for the UKI and then extract it for the image setup.

The might be future setups where people would want to "pause" the build to be able to send their artifacts for signing "somewhere" (HSM, remote service, etc.) and then resume it with the signed artifacts.

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.

2 participants