-
Notifications
You must be signed in to change notification settings - Fork 11
Add support for TPM- and Tang-based disk encryption #83
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/bash | ||
|
|
||
| depends() { | ||
| echo systemd | ||
| } | ||
|
|
||
| install() { | ||
| inst_simple "$moddir/networkd-dependency-generator" \ | ||
| "$systemdutildir/system-generators/networkd-dependency-generator" | ||
| } |
17 changes: 17 additions & 0 deletions
17
dracut/40networkd-dependency/networkd-dependency-generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| UNIT_DIR="$1" | ||
|
|
||
| if cat /proc/cmdline | grep -qw "rd.networkd=1"; then | ||
| mkdir -p "${UNIT_DIR}/dracut-initqueue.service.d" | ||
|
|
||
| cat >${UNIT_DIR}/dracut-initqueue.service.d/networkd_dependency.conf <<EOF | ||
| # Automatically generated by networkd-dependency-generator | ||
|
|
||
| [Unit] | ||
| Wants=systemd-networkd.service systemd-resolved.service network-online.target | ||
| After=systemd-networkd.service systemd-resolved.service network-online.target | ||
| EOF | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the note from the upstream module: https://github.com/coreos/ignition/blob/main/dracut/30ignition/module-setup.sh, more precisely https://github.com/coreos/ignition/blob/main/dracut/30ignition/module-setup.sh#L49. Can we reuse the upstream clevis module for this purpose in order to not diverge from the upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could add a comment here that points to the upstream clevis module to have a chance of finding divergence more easily .
If we import the clevis module we would still add the same contents we have here, I'm both ok with having it imported and patched or with having things here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, the
clevismodule for dracut from app-crypt/clevis is included in the initramfs. One way to see this is that the module40clevis-unlockcurrently lists it as a dependency here. Unfortunately, theclevismodule will not unlock disks in Flatcar's initramfs though as explained in this comment. That is why we have our own40clevis-unlockdracut module in addition theclevismodule. The lines of code you commented on replace files installed by theclevismodule, such as/usr/bin/tpm2_unseal, with symlinks to the same files under/sysusr/. That is, we can remove the symlinking logic here and things will work just fine. My understanding was that replacing files with symlinks was meant to avoid blowing up the initramfs image unnecessarily, given that the files we need are in/sysusr/anyways. But I started working on this PR after the symlinking had been introduced and maybe I am misunderstanding and the symlinking was originally introduced under the assumption that theclevismodule would not be installed, in which case the symlinks would be essential for the unlocking to work.Some options on how to proceed:
clevisand40clevis-unlockas they currently are, and add a comment noting that we diverge from upstream30ignitionhereclevisand40clevis-unlockas they currently are, but do not overwrite the real files with symlinks, instead using the files from theclevismodule; this would keep us us closer to upstream30ignition(if I understood correctly, this was @ader1990's suggestion)clevismodule and instead make sure that all files that40clevis-unlockdepends on are present in/sysusr/usrand symlinked40clevis-unlockand instead extend the Flatcar patch ofapp-crypt/clevisso that theclevismodule manages to unlock disks on its own by registering a dracut hookI do not have particularly strong opinions on how to proceed, so let me know which option you prefer. I am not sure how straightforward option 4 would be, and once we use a dracut hook rather than our own systemd unit for unlocking, we might not be able to switch off initramfs unlocking using the kernel cmdline (without further patching of app-crypt/clevis).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 1 sounds ok, or? We should keep the symlinks for reducing the initrd size impact of this addition. About the systemd-cryptsetup integration: I think that can also be triggered through a
luks.uuid=cmdline parameter instead of/etc/crypttab- maybe it would work to write this out togrub.cfgthrough a helper? Jeremi also noted that https://www.freedesktop.org/software/systemd/man/latest/systemd-gpt-auto-generator.html exists and could work. Anyway, I think the current way is ok even if we iterate on it. Once we document things we ideally shouldn't change them in a backwards-incompatible way anymore, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re symlinks: Agreed. I will add a comment explaining that we diverge from
30ignitionby symlinking to save space. I will also check that we really symlink everything we can.Re how to unlock in initramfs: I like the idea of using
rd.luks.uuid/nameorrd.autoto trigger disk unlock through systemd-cryptsetup in the initramfs. I tried setting these cmdline parameter instead ofrd.clevis_unlockon an image built on the current version in this PR, and the initramfs unlock worked fine.Suggestion:
rd.clevis_unlockparameterrd.network=1, and make the generator add a dependency from dracut-initqueue (or some other unit that runs early enough) to systemd-networkd, systemd-resolved, etc.I'm pretty sure I can push those changes until tomorrow end of day, so it shouldn't delay the merge too much. I think this approach is better than the current approach because
rd.*parameters rather than introducing a Flatcar-specificrd.clevis_unlockparameter,rd.*paramsUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem seems to be that the gpt auto generator only runs as "late" generator.
Edit: Maybe this is the problem:
But it looks like it might work once we have this bli module https://wiki.archlinux.org/title/GRUB#LoaderDevicePartUUID
But
root=must also not be specified on the cmdline.… so I guess we could write a custom generator that runs the systemd gpt auto generator with the right environment in a mount namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it instead of adding a hack to run the gpt auto generator we could have a custom generator that that looks up the luks UDID based on the
by-partlabel/ROOTentry and then runs thesystemd-cryptsetup-generatorwith a kernel cmdline bind-mounted in a mount namespaceUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed commits that implement the switch to using the systemd-cryptsetup unlocking in the initramfs and
rd.*arguments, as described here.From the user's perspective, here's how it works:
See also the changes to the automated tests in the mantle repository that I just pushed here. These tests pass with the new version of the bootengine.
From an implementation perspective, the only bootengine code we now add is the generator that implements adding a dependency on
systemd-networkdetc. ifrd.networkd=1is set. I deleted the custom unlock service.Personally, I feel better about this solution than about the previous one; I think this solution is user-friendly and adds less complexity on the Flatcar side, by reusing systemd-cryptsetup.
From my perspective, the only thing left to do (other than getting the initramfs image size under control---see the thread below) is to consider removing the need for the user to set
kernel_argumentsin their Butane for root disk encryption. I think it'd probably be okay to merge as is and then later remove the need for kernel_arguments as an optimization, but I'd also be happy to push another commit that adds this optimization before we merge. Let me know what you think.Regarding how to optimize, what you suggest would be a way to solve the problem, I think:
I'm not sure how big of a problem that is, but note that this solution would not work for Butane configs that do not label their root partition at all or label it something other than
ROOT. As far as I know, it is no requirement to use this label for the root partition. Of course, we could document that users need to use this label for unlocking in the initramfs to work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, that looks good.
The partition label already is ROOT and won't change, when the partition is reformatted with luks, or? In any case it's easy to require using a partition label and it's nicer than having to provide the uuid upfront. Anyway, I think this is a follow-up improvement.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the case where the root partition is moved to a new partition on a disk other than the OS disk, e.g. as described here in the documentation. In the case where the root partition on the OS disk is used, you are right.
In any case, I 100% agree with you that we could just require the user to use this partition label.