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

Authentication support #101

Closed
sergioprado opened this issue Feb 3, 2023 · 6 comments · Fixed by #109
Closed

Authentication support #101

sergioprado opened this issue Feb 3, 2023 · 6 comments · Fixed by #109

Comments

@sergioprado
Copy link

I'm the maintainer of TorizonCore (https://www.toradex.com/operating-systems/torizon-core), an open-source and container-based Linux distribution built with OE that leverages OSTree.

I am very interested in composefs, especially for the root-of-trust implementation, and I am willing to help with testing and the OSTree integration.

I am following the mailing list discussion and reading all documentation.

One question I have is about authenticity checks. As far as I understood, composefs leverages fs-verity for integrity checks, but authentication is not supported. Is that right?

I was wondering if it would be possible to sign the descriptor digest so we could trust it by just checking the signature, avoiding the need to encode it inside an early boot stage (kernel/ramdisk). That would make it easier to implement remote updates with verified boot/chain-of-trust support.

@alexlarsson
Copy link
Collaborator

This is not currently possible, but I've been thinking about this too. fs-verity already supports pkcs#7 signatures, so it is already possible to some extent do do this. In particular, if you load your certificate to the .fs-verity keyring and then set the fs.verity.require_signatures, then the kernel will validate that all fs-verity files are signed by this key.

However, this is clearly overkill. We don't need (or want!) to sign every file in the system. However, I imagine that if we supported signature validation of the composefs image itself in the mount call, that would be fine. For example, we would make the verity_check=3 mount option mean that verity is not just required, but additionally the image must be signed.

A signed version of the composefs image digest can easily be distributed with the ostree commit, so deploying this should not be too hard.

@sergioprado
Copy link
Author

sergioprado commented Feb 28, 2023

However, I imagine that if we supported signature validation of the composefs image itself in the mount call, that would be fine.

Exactly, that is what I was thinking about. Since it is a Merkle tree, validating the root hash from the image itself would be enough.

I am currently working on integrating composefs into an OSTree-based Yocto build and I might be able to share the results soon.

@alexlarsson
Copy link
Collaborator

I assume you've seen ostreedev/ostree#2640 then?

@sergioprado
Copy link
Author

Yes, I have. Though currently in my PoC I am not using it. I integrated ostree-convert-commit.py and writer-json in OpenEmbedded to generate the composefs image after commiting to the OSTree repository.

@alexlarsson
Copy link
Collaborator

So, I'm looking at this doc for the build-in fs-verity signatures:
https://git.kernel.org/pub/scm/fs/fsverity/fsverity-utils.git/tree/README.md?h=v1.5#n103

It doesn't really sell this feature all that well ("fs-verity built-in signatures are primarily intended as a proof-of-concept", etc). I wonder if we really want to use those. Really, all we need is any kind of signature that signs the fs-verity digest. There is no real need for it to be done by the kernel.

alexlarsson added a commit to alexlarsson/composefs that referenced this issue Mar 14, 2023
This works by using the build-in fs-verity signatures and the kernel
keyring. When you open any file that has fs-verity enabled with a
signature the kernel verifies its signature against the keys in the
kernel .fs-verity keyring. If the required key is not in the keychain
then open will fail.

So, to work with this we just ensure that the file is open (i.e. we
have an fd to it), it has fs-verity enabled, and there is a signature
for the file. If this is all true we must have the valid key in the
keyring.

To test this, do something like this:

Generate keys and sign image:

    openssl req -newkey rsa:4096 -nodes -keyout key.pem -x509 -out cert.pem
    fsverity sign image.composefs image.composefs.sig --key=key.pem --cert=cert.pem

Load the certificate into the fs-verity keyring:
    openssl x509 -in cert.pem -out cert.der -outform der
    keyctl padd asymmetric '' %keyring:.fs-verity < cert.der

Optionally, lock the keyring so that no more keys can be added:
    keyctl restrict_keyring %keyring:.fs-verity

Sign the image:
    fsverity enable image.composefs --signature=image.composefs.sig

Mount the image with the `signed` option:
    mount -t composefs -o basedir=objects,signed image.composefs mnt

This will only succeed if image.composefs is signed with a key, and the matching
cert is loaded in the keyring.

Fixes: containers#101

Signed-off-by: Alexander Larsson <[email protected]>
alexlarsson added a commit to alexlarsson/composefs that referenced this issue Mar 14, 2023
This works by using the build-in fs-verity signatures and the kernel
keyring. When you open any file that has fs-verity enabled with a
signature the kernel verifies its signature against the keys in the
kernel .fs-verity keyring. If the required key is not in the keychain
then open will fail.

So, to work with this we just ensure that the file is open (i.e. we
have an fd to it), it has fs-verity enabled, and there is a signature
for the file. If this is all true we must have the valid key in the
keyring.

To test this, do something like this:

Generate keys and sign image:

    openssl req -newkey rsa:4096 -nodes -keyout key.pem -x509 -out cert.pem
    fsverity sign image.composefs image.composefs.sig --key=key.pem --cert=cert.pem

Load the certificate into the fs-verity keyring:
    openssl x509 -in cert.pem -out cert.der -outform der
    keyctl padd asymmetric '' %keyring:.fs-verity < cert.der

Optionally, lock the keyring so that no more keys can be added:
    keyctl restrict_keyring %keyring:.fs-verity

Sign the image:
    fsverity enable image.composefs --signature=image.composefs.sig

Mount the image with the `signed` option:
    mount -t composefs -o basedir=objects,signed image.composefs mnt

This will only succeed if image.composefs is signed with a key, and the matching
cert is loaded in the keyring.

Fixes: containers#101

Signed-off-by: Alexander Larsson <[email protected]>
@sergioprado
Copy link
Author

Really, all we need is any kind of signature that signs the fs-verity digest. There is no real need for it to be done by the kernel.

Yeah, that is right. Though it is convenient to have that integrated, the signature can be done as a separate process.

Tagging @ricardosalveti, as he has similar needs in Linux microPlatform and might provide good feedback.

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 a pull request may close this issue.

2 participants