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

Use composefs crate for fsverity digest reading #24

Closed
wants to merge 3 commits into from

Conversation

cgwalters
Copy link
Collaborator

tests: Add support for CFS_TEST_TMPDIR

Because we require fsverity in the tests, make this easy
to configure externally for different test harnesses to use.

Signed-off-by: Colin Walters [email protected]


ci: Switch to using Fedora in a container

Prep for linking to the composefs crate and C shared library
to ensure we share code and maintain an incentive to contribute
to those.

Signed-off-by: Colin Walters [email protected]


Use composefs crate for fsverity digest reading

To increase the motivation to improve that crate and the C library;
especially the C library, because we must have it anyways because
we depend on the binaries and we are just not going to rewrite
everything in Rust in the near future.

(And if we did start a rewrite of the composefs core I think
that rewrite should live in that repo, not this one)

Signed-off-by: Colin Walters [email protected]


Because we require fsverity in the tests, make this easy
to configure externally for different test harnesses to use.

Signed-off-by: Colin Walters <[email protected]>
Prep for linking to the composefs crate and C shared library
to ensure we share code and maintain an incentive to contribute
to those.

Signed-off-by: Colin Walters <[email protected]>
To increase the motivation to improve that crate and the C library;
especially the C library, because we *must* have it anyways because
we depend on the binaries and we are just not going to rewrite
everything in Rust in the near future.

(And if we *did* start a rewrite of the composefs core I think
 that rewrite should live in that repo, not this one)

Signed-off-by: Colin Walters <[email protected]>
// #define FS_IOC_MEASURE_VERITY _IORW('f', 134, struct fsverity_digest)
type FsIocMeasureVerity = ioctl::ReadWriteOpcode<b'f', 134, FsVerityDigest<()>>;

pub fn fs_ioc_measure_verity<F: AsFd, H: FsVerityHashValue>(fd: F) -> Result<H> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That said this code is quite elegant and nice; the generics usage for sha256/sha512 is cool. But OTOH there are no plans to use anything but sha256 for composefs.

What we could do though is move some of this "reimplement composefs core in Rust" into the composefs git repo under the composefs crate under an optional feature flag or something - might be especially useful to "cross test" i.e. verify the C and Rust codepaths do the same thing.

Ok(digest.digest)
}
pub fn fs_ioc_measure_verity<F: AsFd>(fd: F) -> Result<Sha256HashValue> {
let mut digest = composefs::fsverity::Digest::new();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also looking at this, perhaps we should drop the Digest wrapper and do what you have here and just have it write into an array. Definitely the compile-time known size is better than what we have in .get() at the moment.

OTOH, and this relates to a larger topic...I feel like in practice we end up converting to hex in many places anyways, so we may as well canonicalize to e.g. this Sha256Digest instead.

@allisonkarlitskaya
Copy link
Collaborator

I'm afraid I don't like this change. I really like the way the ioctl interface in rustix looks... and in general, if we can avoid the trouble of taking the dependency I'd really prefer to do so. Indeed: we use mkcomposefs at runtime, but not from the tests that we run in GitHub actions.

I kinda get some of the higher-level ideas about unifying this repo with the composefs repo a bit more...

@cgwalters
Copy link
Collaborator Author

f we can avoid the trouble of taking the dependency I'd really prefer to do so.

Is there a better reason that the below ⬇️ (That I already addressed via using Fedora)?

Indeed: we use mkcomposefs at runtime, but not from the tests that we run in GitHub actions.

Sure but in reality I think what we'll want is integration tests and it's those that can require fsverity. Requiring fsverity for unit tests isn't wrong, but it isn't right either.

@cgwalters
Copy link
Collaborator Author

I do think we want to help get the composefs C core packaged for Ubuntu and Arch etc. in the near term which would help address the dependency issue.

@cgwalters
Copy link
Collaborator Author

cgwalters commented Nov 6, 2024

I really like the way the ioctl interface in rustix looks...

Me too, but to be clear this is just starting the ball rolling on deduping things. I don't think it makes sense for this crate to have its own dumpfile code either for example.

@cgwalters
Copy link
Collaborator Author

We had a quick realtime debate on this and the conclusion was:

  • We will depend on the mkcomposefs and composefs-info dump for the near term future
  • But the libcomposefs C library is not doing enough today that we need to take a dependency on it

Instead we will:

  • Make this repository be containers/composefs-storage or so (or maybe containers/composefs-rs)
  • Merge the good code from the existing Rust crates in containers/composefs into that combined repository (most likely at least the dumpfile parser/generator)
  • Publish the combined merged thing as composefs to crates.io

Incidentally in this I think we should actually switch over this crate to being a workspace...if you look at the composefs crate today it's just a thin binding for working with mkcomposefs and composefs-info dump, plus fsverity helpers. The fsverity helpers can be pure Rust for now, but those would I think continue to live in a composefs core crate.

I think then what is in repository.rs here should probably become a composefs-storage crate that builds on that with many more opinions about things such as all of the repo management, etc.

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