Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
Hi Lennart, "Sorry, but GPG is a no-go. Not in 2023." Yes, I understand that. What I am trying to get is a simple way to verify that the initramfs has not been tampered with. UKI comes with its own challenges, using encryption tied to a measured boot looks overkill, and I fully agree in which adding an authentication layer is not desirable. Then... what alternatives are available for just performing verification of the initramfs? I was giving a look at IMA now, so this could be sorted with a policy... but I think this is not supported in sd-boot. In the case I wrap the initramfs on a PE envelope, as you suggested, when then its signature be validated automatically? when it gets loaded? Because, if so... this would work enough for this use case. Thank you --- Felix Rubio "Don't believe what you're told. Double check." On 2023-05-24 18:11, Lennart Poettering wrote: On Mi, 24.05.23 16:20, Felix Rubio (fe...@kngnt.org) wrote: Hi Andrei, Lennart @Andrei: Do you think, then, that the same private key used for SecureBoot could be used for GPG signing the initramfs? That would be cool, as the whole boot signing infrastructure would still depend on a single entity. @Lennart: I was thinking in using a private key for which I'd enroll the certificate in MOK (I mean, just following the standard use case for MOK). Without having much idea about the code base of systemd-boot, I am willing to give it a try (to a GPG with private key from SB) provided you think is something the community might benefit from. What are your thoughts? Sorry, but GPG is a no-go. Not in 2023. But also I am not sure I understand what are you trying to do? Note that shim only authenticates PE binaries, hence you'd have to wrap your initrd in a PE binary anyway to validate an initrd against MOK. And we really don#t want to add another layer of authentication in sd-boot, let's leave that in uefi sb firmware + shim. i.e. we expressly don#t want to embedd a crypto stack like grub. And even if we could we don't get access to MOK iirc, shim makes that impossible for later boot components. If you wrap your initrd in a PE envelope this is pretty much exactly what UKIs are. – Also note that there's currently a PR pending that allows wrapping kernel command lines in separate PE files which can be read by a UKI, a concept we call "add-on", which would we could extend to initrds too i guess, see https://github.com/systemd/systemd/pull/27358 Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
On Mi, 24.05.23 16:20, Felix Rubio (fe...@kngnt.org) wrote: > Hi Andrei, Lennart > > @Andrei: Do you think, then, that the same private key used for SecureBoot > could be used for GPG signing the initramfs? That would be cool, as the > whole boot signing infrastructure would still depend on a single entity. > > @Lennart: I was thinking in using a private key for which I'd enroll the > certificate in MOK (I mean, just following the standard use case for MOK). > > Without having much idea about the code base of systemd-boot, I am willing > to give it a try (to a GPG with private key from SB) provided you think is > something the community might benefit from. What are your thoughts? Sorry, but GPG is a no-go. Not in 2023. But also I am not sure I understand what are you trying to do? Note that shim only authenticates PE binaries, hence you'd have to wrap your initrd in a PE binary anyway to validate an initrd against MOK. And we really don#t want to add another layer of authentication in sd-boot, let's leave that in uefi sb firmware + shim. i.e. we expressly don#t want to embedd a crypto stack like grub. And even if we could we don't get access to MOK iirc, shim makes that impossible for later boot components. If you wrap your initrd in a PE envelope this is pretty much exactly what UKIs are. – Also note that there's currently a PR pending that allows wrapping kernel command lines in separate PE files which can be read by a UKI, a concept we call "add-on", which would we could extend to initrds too i guess, see https://github.com/systemd/systemd/pull/27358 Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] Monotonic time went backwards, rotating log
On Di, 23.05.23 11:04, Phillip Susi (ph...@thesusis.net) wrote: > Every time I reboot, when I first log in, journald ( 253.3-r1 ) > complains that the monotonic time went backwards, rotating log file. > This appears to happen because journal_file_append_entry_internal() > wishes to enforce strict time ordering within the log file. I'm not > sure why it cares about the *monotonic* time being in strict order > though, since that will always go backwards when you reboot. I'm also > not sure why the previous check that the boot ID has changed did not > trigger. We want that within each file all records are strictly ordered by all clocks, so that we can find specific entries via bisection. Rotation doesn't mean systemd doesn't look at the records anymore. journalctl will look at all journal files it discoveres and display them in a single unified "interleaved" stream, so that you can't see that they are stored in separate journal files. > If it is intentional that journals be rotated after a reboot, could it > at least be done without complaining about it? The message is debug level, no? Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
Hi Andrei, Lennart @Andrei: Do you think, then, that the same private key used for SecureBoot could be used for GPG signing the initramfs? That would be cool, as the whole boot signing infrastructure would still depend on a single entity. @Lennart: I was thinking in using a private key for which I'd enroll the certificate in MOK (I mean, just following the standard use case for MOK). Without having much idea about the code base of systemd-boot, I am willing to give it a try (to a GPG with private key from SB) provided you think is something the community might benefit from. What are your thoughts? Regards, -- Felix Rubio "Don't believe what you're told. Double check." On 2023-05-24 14:35, Lennart Poettering wrote: On Mi, 24.05.23 12:22, Felix Rubio (fe...@kngnt.org) wrote: I agree that having a measured boot, that decrypts the system is a better solution... but this is, correct me if wrong, still very green: There are some approaches supported, but none of them seems to be structural: they rely on the existence of a TPM, introduce additional dependencies on the update process (when the kernel/initramfs changes the previous measurement will not be correct anymore and needs to be updated), etc. On the other hand UKI comes with its own challenges, and also forces the admin to rebuild the UKI any time there is an update. I feel there should be some middle point in which we do not have to rely on a TPM and a fully measured system, but we can still make sure that the initramfs is trusted. The question, then, is: Is this something that could be supported in systemd-boot, or this is something that is considered to be just out of scope? As in the other mail: Which key do you intend to use for validation? Note that in systemd git main there's already support for generating UKIs dynamically when a kernel RPM/DEB is installed (as long as the "kernel-install" infra is in use). It can be signed with a local key, that can be enrolled with MOK. With that we make it reasonably easy to run a setup with a locally signed initrd – but it means that you'll get a MOK prompt during at least one boot. Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
On Mi, 24.05.23 12:22, Felix Rubio (fe...@kngnt.org) wrote: > I agree that having a measured boot, that decrypts the system is a better > solution... but this is, correct me if wrong, still very green: There are > some approaches supported, but none of them seems to be structural: they > rely on the existence of a TPM, introduce additional dependencies on the > update process (when the kernel/initramfs changes the previous measurement > will not be correct anymore and needs to be updated), etc. On the other hand > UKI comes with its own challenges, and also forces the admin to rebuild the > UKI any time there is an update. > > I feel there should be some middle point in which we do not have to rely on > a TPM and a fully measured system, but we can still make sure that the > initramfs is trusted. The question, then, is: Is this something that could > be supported in systemd-boot, or this is something that is considered to be > just out of scope? As in the other mail: Which key do you intend to use for validation? Note that in systemd git main there's already support for generating UKIs dynamically when a kernel RPM/DEB is installed (as long as the "kernel-install" infra is in use). It can be signed with a local key, that can be enrolled with MOK. With that we make it reasonably easy to run a setup with a locally signed initrd – but it means that you'll get a MOK prompt during at least one boot. Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
On Di, 23.05.23 20:54, Felix Rubio (fe...@kngnt.org) wrote: > Hi everybody, > > I am trying to understand something, and after looking around I have not > found any explicit answer. Maybe somebody in this list can shed some light > on the matter? I have a laptop in which I am setting up the boot process > through systemd-boot, and this works. Now, I'd like to give a try to enable > Secure Boot so that the whole boot sequence is protected against tampering. > As I am still learning about the technology, I prefer to land on the use of > shim/MOK. For what I have read, the sequence should be: > > 1. Install a version of shim signed with MS keys. > 2. On that same folder copy systemd-bootx64.efi, renamed to grubx64.efi (as > shim seems to work only with Grub as 2nd stage loader). > 3. Sign the kernel with the key for which the certificate has been enrolled > in MOK. > 4. Reboot, enroll the keys and... voila. > > So far, so good... until we hit the initramfs wall: the efi's and kernel > signatures are verified, but not that of the initramfs. I have seen that > grub2 does not do it (it relies in GPG signatures, in which seems to be a > workaround), and I have not found any place stating that systemd-boot does > it. I have seen however, some steering towards the use of UKI... but this > comes with its own problems about out-of-tree kernel modules and so. > > So, the question is: why the kernel image gets verified but not the > initramfs? Is this mandated by some standard, or is an engineering decision? What key do you want to verify it with? The OS vendor key? this is what we are building with UKI. But this means no locally build initrds, which is what distros so far were all doing. A local key? Where is that stored? In the ESP? That would be pointless, as you could swap it out. You could use a MOK key, but that means intraction at at least one boot, which generic distros don't like. Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
On Wed, May 24, 2023 at 1:22 PM Felix Rubio wrote: > > Hi Andrei, > > Thank you for correcting my statement about Grub2, I did not know that. > > I agree that having a measured boot, that decrypts the system is a > better solution... but this is, correct me if wrong, still very green: > There are some approaches supported, but none of them seems to be > structural: they rely on the existence of a TPM, introduce additional > dependencies on the update process (when the kernel/initramfs changes > the previous measurement will not be correct anymore and needs to be > updated), etc. On the other hand UKI comes with its own challenges, and > also forces the admin to rebuild the UKI any time there is an update. > > I feel there should be some middle point in which we do not have to rely > on a TPM and a fully measured system, but we can still make sure that > the initramfs is trusted. The question, then, is: Is this something that > could be supported in systemd-boot, or this is something that is > considered to be just out of scope? > Secure Boot defines signatures for executable PE files. To apply it to initrd one would need to either wrap it in PE (which is effectively what UKI does) or develop a new standard for attaching signature to initrd. For example, using grub2 GPG keys :) > Thank you > > --- > Felix Rubio > "Don't believe what you're told. Double check." > > On 2023-05-23 21:32, Andrei Borzenkov wrote: > > On 23.05.2023 21:54, Felix Rubio wrote: > >> Hi everybody, > >> > >> I am trying to understand something, and after looking around I have > >> not > >> found any explicit answer. Maybe somebody in this list can shed some > >> light on the matter? I have a laptop in which I am setting up the boot > >> process through systemd-boot, and this works. Now, I'd like to give a > >> try to enable Secure Boot so that the whole boot sequence is protected > >> against tampering. As I am still learning about the technology, I > >> prefer > >> to land on the use of shim/MOK. For what I have read, the sequence > >> should be: > >> > >> 1. Install a version of shim signed with MS keys. > >> 2. On that same folder copy systemd-bootx64.efi, renamed to > >> grubx64.efi > >> (as shim seems to work only with Grub as 2nd stage loader). > >> 3. Sign the kernel with the key for which the certificate has been > >> enrolled in MOK. > >> 4. Reboot, enroll the keys and... voila. > >> > >> So far, so good... until we hit the initramfs wall: the efi's and > >> kernel > >> signatures are verified, but not that of the initramfs. I have seen > >> that > >> grub2 does not do it (it relies in GPG signatures, in which seems to > >> be > >> a workaround), and I have not found any place stating that > >> systemd-boot > > > > GPG is independent alternative method of verifying files and most > > certainly not a workaround (it was implemented in grub2 long before > > Secure Boot support). > > > >> does it. I have seen however, some steering towards the use of UKI... > >> but this comes with its own problems about out-of-tree kernel modules > >> and so. > >> > >> So, the question is: why the kernel image gets verified but not the > >> initramfs? Is this mandated by some standard, or is an engineering > >> decision? > >> > > > > Kernel image has verifiable origin (it is signed by the same entity > > that provides your distribution). It is static and does not change on > > end user system which makes it possible to sign by maintainers of > > distribution by a secret key that is hopefully kept secret. > > > > initrd is volatile, it is usually generated on the same system where > > it should be verified which means the key to sign it must be kept on > > the same system as well. Which makes it more probable that secret key > > will be leaked if system is compromised. And leaked secret key allows > > installing an arbitrary malware as part of initrd. > > > > Measured boot does not have this problem. If you encrypt your root and > > only allow decrypting if initrd (and kernel and any other data used > > during boot) has known content then initrd will be implicitly verified > > and if it is changed system simply fails to boot. This does not > > require any key management or storing any persistent secret on end > > system. Downside is that it requires TPM (or some other tamper > > resistant way to store hashes) so not universally applicable. > > > >> Thank you very much! > >>
Re: [systemd-devel] why systemd-boot (seems as everyone else) does not check the signatures of initramfs?
Hi Andrei, Thank you for correcting my statement about Grub2, I did not know that. I agree that having a measured boot, that decrypts the system is a better solution... but this is, correct me if wrong, still very green: There are some approaches supported, but none of them seems to be structural: they rely on the existence of a TPM, introduce additional dependencies on the update process (when the kernel/initramfs changes the previous measurement will not be correct anymore and needs to be updated), etc. On the other hand UKI comes with its own challenges, and also forces the admin to rebuild the UKI any time there is an update. I feel there should be some middle point in which we do not have to rely on a TPM and a fully measured system, but we can still make sure that the initramfs is trusted. The question, then, is: Is this something that could be supported in systemd-boot, or this is something that is considered to be just out of scope? Thank you --- Felix Rubio "Don't believe what you're told. Double check." On 2023-05-23 21:32, Andrei Borzenkov wrote: On 23.05.2023 21:54, Felix Rubio wrote: Hi everybody, I am trying to understand something, and after looking around I have not found any explicit answer. Maybe somebody in this list can shed some light on the matter? I have a laptop in which I am setting up the boot process through systemd-boot, and this works. Now, I'd like to give a try to enable Secure Boot so that the whole boot sequence is protected against tampering. As I am still learning about the technology, I prefer to land on the use of shim/MOK. For what I have read, the sequence should be: 1. Install a version of shim signed with MS keys. 2. On that same folder copy systemd-bootx64.efi, renamed to grubx64.efi (as shim seems to work only with Grub as 2nd stage loader). 3. Sign the kernel with the key for which the certificate has been enrolled in MOK. 4. Reboot, enroll the keys and... voila. So far, so good... until we hit the initramfs wall: the efi's and kernel signatures are verified, but not that of the initramfs. I have seen that grub2 does not do it (it relies in GPG signatures, in which seems to be a workaround), and I have not found any place stating that systemd-boot GPG is independent alternative method of verifying files and most certainly not a workaround (it was implemented in grub2 long before Secure Boot support). does it. I have seen however, some steering towards the use of UKI... but this comes with its own problems about out-of-tree kernel modules and so. So, the question is: why the kernel image gets verified but not the initramfs? Is this mandated by some standard, or is an engineering decision? Kernel image has verifiable origin (it is signed by the same entity that provides your distribution). It is static and does not change on end user system which makes it possible to sign by maintainers of distribution by a secret key that is hopefully kept secret. initrd is volatile, it is usually generated on the same system where it should be verified which means the key to sign it must be kept on the same system as well. Which makes it more probable that secret key will be leaked if system is compromised. And leaked secret key allows installing an arbitrary malware as part of initrd. Measured boot does not have this problem. If you encrypt your root and only allow decrypting if initrd (and kernel and any other data used during boot) has known content then initrd will be implicitly verified and if it is changed system simply fails to boot. This does not require any key management or storing any persistent secret on end system. Downside is that it requires TPM (or some other tamper resistant way to store hashes) so not universally applicable. Thank you very much!
Re: [systemd-devel] How to authenticate login using org.freedesktop.login1
On Wed, May 24, 2023 at 9:42 AM Lal, Arun wrote: > Hi All, > > > > I was trying to authenticate a user from a deamon running in my machine. > And I found systemd-login can be used. > > I went through documentation for interface org.freedesktop.login1, but I > am not clear on how it can be used. > > > > Lets assume that there is a deamon called xyz running in my device which > has a webserver component. And it receives a request to login from https > side. > > And once the deamon has username and password, I would like to invoke some > dbus calls to org.freedesktop.login1 to perform the authentication. > systemd-logind does not have that functionality. It's a session manager, not an authentication service. (And the sessions it manages are meant for mostly interactive connections; not for webapp sessions.) Usually system authentication is done by loading libpam in-process (must be done from a privileged process running as root). If that is not possible (e.g. if you're using an unprivileged webapp), the *saslauthd* daemon from Cyrus-SASL would be one option – it is designed to be used by various network services to validate passwords over a Unix socket interface and has a PAM backend (`saslauthd -a pam`). I don't know of other such daemons (surprisingly, SSSD doesn't expose an authenticate call through its D-Bus interface either, keeping it internal to PAM only), but that's the general approach if you plan on writing your own. -- Mantas Mikulėnas
[systemd-devel] How to authenticate login using org.freedesktop.login1
Hi All, I was trying to authenticate a user from a deamon running in my machine. And I found systemd-login can be used. I went through documentation for interface org.freedesktop.login1, but I am not clear on how it can be used. Lets assume that there is a deamon called xyz running in my device which has a webserver component. And it receives a request to login from https side. And once the deamon has username and password, I would like to invoke some dbus calls to org.freedesktop.login1 to perform the authentication. Assuming org.freedesktop.systemd1.Privileged("true"), I see that I can use CreateSession and ReleaseSession from interface org.freedesktop.login1.Manager. But I have some doubts: * Is this recommended approach. * I am not seeing an argument in CreateSession method that takes password, what am I missing here? Thanks in advance Regards, Arun Lal K M