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

Initial Qubes OS support #156

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Initial Qubes OS support #156

wants to merge 21 commits into from

Conversation

jevank
Copy link

@jevank jevank commented Oct 31, 2021

This allows to build qubes-safeboot package using qubes-builder and
use it to generate and setup UEFI Secure Boot keys and configuration,
generate and sign unified EFI executable bundle with xen, xen config,
kernel and ramdisk.

References to issues
#21
QubesOS/qubes-issues#4371

This allows to build qubes-safeboot package using qubes-builder and
use it to generate and setup UEFI Secure Boot keys and configuration,
generate and sign unified EFI executable bundle with xen, xen config,
kernel and ramdisk.
@jevank
Copy link
Author

jevank commented Oct 31, 2021

Tested with Lenovo X1C6/C7 and Qubes OS r4.1. It requires manual boot configuration with xen.efi loader instead of grub2.

I'm not sure that it should be merged as is, but it might help step forward.

@JordanBoulan
Copy link

JordanBoulan commented May 15, 2022

EDIT nvm see my comment below first

I ended up just installing sbsigntools and mtools from qubes repo cause they were there. It was telling me that the safeboot rpm relied on efitools, and that wasn't in the your repo at all. I checked what the tpm repos provided on pkgs.com and efitools was not listed. The oldest efitools I could find was for fedora 34 but I decided I would try it. That wanted an updated version of glibc so I got the oldest one possible that satisfied the rec was from fedora 33. Then after copying rpms to dom0 I ran qubes-dom0-update ./efitools.rpm ./glibc-common.rpm ./glibc-lang-en.rpm .... ./safeboot.rpm all the dependencies were resolved and everything installed fine.

However on restart my vms would start but no windows would open for any of my vms. Even running xterm in a running vm didn't do anything or open a window. I figured it was most likely because of updating glibc was the problem. so i did qubes-dom0-update --action=downgrade to downgrade glibc to the same version it was before and then on restart my qubes wouldn't even boot. Maybe because I was stupid and forgot to uninstall efitools to, but that also doesn't make much sense because it never needed that to boot before. I ended up having to reinstall my entire OS, which isn't a huge deal. I even made a new test installation and installed the rpms again just to confirm that was the issue and it was.
Efitools didn't even seem to exist at all for F32 but safeboot rpm requires it. The Efitools is what required the updated glibc**. That seems to make all my vms unusable though unless im wrong about what caused it.

@JordanBoulan
Copy link

JordanBoulan commented May 15, 2022

@jevank nvm efitools is linked in the repo but maybe I missed it cause it can't be clicked on github.com cause its from kernel.org. Cause I went through all the highlighted/clickable repos that were linked and tried to manually build the ones without spec files. So installing the newer one was probably what caused all my problems. It seems wierd I wasn't able to find efitools built for fc32 anywhere though even though the project is decades old and I looked for like an hour.

Still instructions and tips on building and installing to make the steps a bit more clear would be appreciated.

Can you please share your builder.conf as well as instructions on commands and stuff as far as order and how you go about installing. No need to go into extreme detail on building but detail on places I may have went wrong building would be great. how I go about installing it properly.

Do I need to do something as simple as update my whole system to the testing branch or something? I'm on 4.1 stable everything updated.

Am I not supposed to be installing this in dom0 or something? If that's the case I'm confused about how it's supposed to work at boot-time. Thanks for your help and time. I'm sure I missed something simple or did something really stupid. Keep in mind I have never used safeboot on normal linux either, which may be why I am so confused on how this works.

it seems like at least safeboot needs to be installed in dom0 since the specfile says

%triggerin -- xen-hypervisor
if [ -f /boot/efi/EFI/qubes/qubes.efi.signed ]; then
/usr/sbin/safeboot qubes-sign
fi

Thanks again.

@jevank
Copy link
Author

jevank commented May 17, 2022

Efitools didn't even seem to exist at all for F32 but safeboot rpm requires it.

Hi, all necessary packages (efitools and sbsigntools) are available in dom0 from fedora repositories. This implementation does not provide yubikey support so there is no need to build them from sources.

Still instructions and tips on building and installing to make the steps a bit more clear would be appreciated.

Agree. I'll make additional description.

In short you need to build a package (I think qubes-r4.1.conf is OK), copy this package to dom0 and install with qubes-dom0-update tool (to get all requited packages from repos).

@JordanBoulan
Copy link

JordanBoulan commented Jun 12, 2022

Still not sure how to get efitools requirement. I can build the module fine but when i try to install after transfering rpm to dom0...
I run qubes-dom0-update ./safeboot.rpm in dom0 and it wants efitools packages and can't find it.

I'm on 4.1 with fc32 dom0 (basically everything is default 4.1, updated on current stable branch) and can't seem to find efitools when a try to install or search for packages. First a try to install efitools with qubes-dom0-update, in the 2nd screenshot I use --action=search to look for efi related packages and scroll up to ones starting with e in package name

sudo qubes-dom0-update efitools 
sudo qubes-dom0-update --action=search efi

efitools
efisearch

@jevank
Copy link
Author

jevank commented Jun 12, 2022

Missed that, efitools must be built from source for fedora 32. I will try to add the spec file here

@JordanBoulan
Copy link

Thanks, appreciated. I can just build efitools for now possible from the commit you specified. Also what needs to be done to get yubikey working? Maybe I could help?

Are you on the testing or unstable branch of qubes or something with newer fedora in dom0? just wondering. I'm on 4.1 stable with all the latest updates. Says you tested it on r4.1 in the 2nd comment, maybe you just manually built efi tools or something.

@jevank
Copy link
Author

jevank commented Jun 20, 2022

Thanks, appreciated. I can just build efitools for now possible from the commit you specified.

Added commit to build efitools with qubes-builder. You can try to update sources and rebuild.

Also what needs to be done to get yubikey working? Maybe I could help?

I don't have yubikey available, and even if I did, it's hard to use in Qubes OS because of the untrusted sys-usb. A possible way would be to use two USB controllers, one of which stays in dom0 and is used for yubikey. In that case it requires to build sbsigntools with yubikey support.

Are you on the testing or unstable branch of qubes or something with newer fedora in dom0?

I use heavy customized Qubes OS from sources.

@jevank
Copy link
Author

jevank commented Jun 21, 2022

Build from sources instructions (uses repo/branch from this PR)

git clone https://github.com/QubesOS/qubes-builder
cd qubes-builder
cp example-configs/qubes-r4.1.conf builder.conf
make COMPONENTS=builder-rpm get-sources
make COMPONENTS=safeboot GIT_URL_safeboot=https://github.com/jevank/safeboot BRANCH_safeboot=jevank INSECURE_SKIP_CHECKING=safeboot get-sources
make USE_DIST_BUILD_TOOLS=1 install-deps
make remount
make USE_DIST_BUILD_TOOLS=1 COMPONENTS=safeboot safeboot-dom0

Copy and install packages to dom0

[user@dom0 ~]$ qvm-run -p VMNAME -- cat qubes-builder/qubes-src/safeboot/pkgs/dom0-fc32/qubes-safeboot-0.8-1.fc32.x86_64.rpm > qubes-safeboot-0.8-1.fc32.x86_64.rpm 
[user@dom0 ~]$ qvm-run -p VMNAME -- cat qubes-builder/qubes-src/safeboot/pkgs/dom0-fc32/efitools-1.9.2-7.fc32.x86_64.rpm > efitools-1.9.2-7.fc32.x86_64.rpm
[user@dom0 ~]$ sudo qubes-dom0-update mtools sbsigntools
[user@dom0 ~]$ sudo dnf localinstall qubes-safeboot-0.8-1.fc32.x86_64.rpm efitools-1.9.2-7.fc32.x86_64.rpm

Setup safeboot (requires clearing existing keys from UEFI)

[user@dom0 ~]$ sudo safeboot key-init "/CN=user/OU=test/O=myorg"
[user@dom0 ~]$ sudo safeboot uefi-sign-keys
[user@dom0 ~]$ sudo safeboot qubes-sign

jevank added 11 commits July 29, 2022 19:05
This should prevents from such errors:

> DEBUG: ./cert-to-efi-sig-list PK.crt PK-blacklist.esl
> DEBUG: make: ./cert-to-efi-sig-list: Command not found
> DEBUG: make: *** [Make.rules:75: PK-blacklist.esl] Error 127
This could be useful to support unattended updates in a secure
environment, such as Qubes OS.
Update qubes.efi after linux-firmware upgrading.
This fixes error:
> tail: 'standard input': cannot seek to relative offset 4: Illegal seek
@jevank
Copy link
Author

jevank commented Jul 29, 2022

Added support for Qubes OS in the luks-seal and prcs-sign procedures. Also added dracut unseal module based on AEM and initramfs unseal script.
Key differences w/ Linux:

  • not implementing recovery mode (not sure if this is necessary with Qubes)
  • using kernel command line option instead of modifying crypttab. Not sure about any advantages of this, but it is similar to AEM.

Tested with Qubes R4.1 on X1C5-C7. Have a problem with PCR4 prediction on X1C8 I assume because of GPU ROM. Any ideas with it?

I'm really not sure about merging as is, specially with building the required packages from single repo, but I hope to get your review @marmarek @osresearch

thanks

marmarek added a commit to marmarek/qubes-builder that referenced this pull request Jul 31, 2022
@marmarek
Copy link

specially with building the required packages from single repo

It shouldn't be needed anymore, I've put all mentioned backports into R4.1's repo (current-testing right now).

@jevank
Copy link
Author

jevank commented Jul 31, 2022

It shouldn't be needed anymore, I've put all mentioned backports into R4.1's repo (current-testing right now).

Great to see you here! It needs at least one modification to sbsigtools (the --hash-only option osresearch/sbsigntools@370abb7) and I'm not sure about openssl3.patch - it was made for Fedora 36 AFAIK.

@jevank
Copy link
Author

jevank commented Aug 2, 2022

Fixed PCR4 computing with Lenovo X1C7+ devices where the EFI ACTION event appears. It needs setup TPM_EFI_ACTION=1 in local.conf to get all work.

@jevank
Copy link
Author

jevank commented Aug 2, 2022

Also it needs to disable Absolute Persistent Module in UEFI settings (I prefer permanent disabling :).

@pietrushnic
Copy link

pietrushnic commented Sep 11, 2022

@jevank @marmarek I'm trying to follow above instruction to build on debian and getting this:

debian@build-engine:~/src/qubes-summit/qubes-builder$ make COMPONENTS=safeboot GIT_URL_safeboot=https://github.com/jevank/safeboot BRANCH_safeboot=jevank INSECURE_SKIP_CHECKING=safeboot get-sources
-> Updating sources for safeboot...
--> Fetching from https://github.com/jevank/safeboot jevank...
--> NOT verifying tags
--> Switching branch from jevank branch to jevank
Reset branch 'jevank'
Your branch is up to date with 'origin/jevank'.

debian@build-engine:~/src/qubes-summit/qubes-builder$ make install-deps
[sudo] password for debian: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package createrepo
E: Unable to locate package perl-Digest-MD5
E: Unable to locate package perl-Digest-SHA
E: Unable to locate package rpm-build
E: Unable to locate package rpmdevtools
make: *** [Makefile:1148: install-deps.dpkg] Error 100

Of course I cannot use USE_DIST_BUILD_TOOLS=1 since this is not Fedora.

@jevank
Copy link
Author

jevank commented Sep 11, 2022

I've never tried to build components under debian-based environment... does it should work?..

@pietrushnic
Copy link

@jevank it has many problems that qubes-builderv2 should resolve. Do we really want to say you can build Qubes packages only on Fedora?

Ideally if Qubes would allow Debian dom0. Anyway I want to give a try for your changes and help merging that to Qubes, so I probably will setup Fedora VM just for building but it is additional overhead.

marmarek added a commit to QubesOS/qubes-builderv2 that referenced this pull request Jan 20, 2023
They were needed in fc32 dom0, but R4.2 has newer one.

sbsigntools carries one extra patch:
osresearch/safeboot#156 (comment)
marmarek added a commit to QubesOS/qubes-builder that referenced this pull request Jan 20, 2023
They were needed in fc32 dom0, but R4.2 has newer one.

sbsigntools carries one extra patch:
osresearch/safeboot#156 (comment)
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