You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
repart: Add support for formatting verity partitions #24559
Is your feature request related to a problem? Please describe
Currently, users are required to manually run veritysetup format after running repart to format any verity partitions. Ideall,y repart should be able to do this for the user.
Describe the solution you'd like
Add support for a new Verity section to repart definitions files, providing a way to configure and format a verity partition for the given partition. If the Verity section is provided, repart will generate a verity partition for the current partition. The settings in the Verity section can be used to configure the generated Verity partition.
Describe alternatives you've considered
No response
The systemd version you checked that didn't have the feature you are asking for
So originally my focus for repart was to run at boot, and readjust partitions on the deployment machine. There it doesn't make too much sense to generate verity, since that's a job for an OS builder, not something you'd run on the deployment machine. But of course, the focus shifted a bit: repart is useful for building images too, on the OS builder's machine. So I guess adding this functionality would make sense, and I guess wouldn't even be that much code.
I'm a little unsure about the implementation. First, I was thinking along the lines of an optional Verity section that defines a verity partition for the regular partition defined in the same definition file. But then you'd have to duplicate many settings of the Partition section in the Verity section as well.
Then I figured we can add the Verity section to configure additional verity settings for a definition file defining a verity partition. But what I'm not sure about is how to specify the data partition for the verity partition in that case, the UUID is the closest to an identifier but when we're doing verity the UUID comes from the root hash so it's not defined yet for the data partition. The type can be ambiguous so I'm not sure that would be great either. We could do ordering based and use the previous partition as the data partition but that doesn't seem amazing either.
We could also use the definition file name as a match I guess (similar to unit file names which are also used as matches), but that would prevent us from making a verity partition of any partition that can't be matched against a definition file.
Any other ideas on how to specify the data partition for the verity partition? Or should we define data and corresponding verity partitions in the same definition file after all?
So what do you intend to use as source here for the whole op? i.e. have a ready made fs image that you want to generate a disk image from and then also add a verity partition for? i.e. CopyBlocks= in one partition? In that scheme things would be easy, you could just add VerityBlocks= or so and then have a pair of partitions: one with CopyBlocks= (for the payload) and one with VerityBlocks= (for the verity hashes). And then the UUID= setting would also learn two new magic values "verity-hi" and "verity-lo" or so, for the high/lo bits of the verity root hash of the CopyBlocks=/VerityBlocks= stuff. (of course, this means some caching would be needed to ensure we don't run the verity stuff twice, but just once).
The issue is that I don't have a ready made image, I have a directory tree that I'll copy into partitions using CopyFiles. But verity works on blocks, so I'd like to use the repart generated data partition as the data device for the verity partition, but to do that I need a way to specify that generated data partition by repart in the definition file for the verity partition. I'm just not sure what the best way is to specify that.
repart would then generate all the partitions, copy the files in there if CopyFiles is specified, and as the final step, format the verity partition based on the data partition and somehow communicate the resulting roothash to the user. Probably by just writing to a file in the directory that repart is running from or so.
Hmm, I guess we could do it the same way for CopyFiles=. I mean, we try very hard to generate file systems reproducibly already, i.e. derive uuid/label in a stable way. We can build on that, and simply say that as long as you specify the same data for the fs we generate we'll cache the resulting fs binary data stuff for you, so that we can reuse it for the verity generation
i.e. if we you run stuff like this, then once we come to generate the data for the first of the two partitions we'll notice we haven't generated that so far, so we generate the fs for it. if the first partition was the non-verity one, we just copy that into the partition, but we also maintain a cache that uses the copy source path (and some of the relevant other settings, i.e. fstype and so on) as key. And then, when we come to the second partition, we look into that cache. And then instead of generating the fs new, we just use that again.
i.e. cache key would by copy source path + fstype + … and the cache value would be triplet of fd + offset + size, pointing to where the prepared data can be read from. We'd keep the cache open for the whole operation and close it only when done. Thus, as long as you use the exact same source path and parameters we'll always only run mkfs/copy once.
I think this would be really nice and simple. I mean, the mkfs/copy stuff isn't truly reproducible (because we are using kernel fs drivers here), but superficially they'll look the same, because same contents and same metadata. And by employing the cache we can both optimize generation (because we don't have to genreate the fs twice) but also get bitwise identical copies even though running mkfs/copy twice wouldn't actually give us that.
This would ensure things remain nicely independent conceptually (since the .conf files on paper are still entirely indepndent of each other) but things would be fast and systematic.
How would we derive the cache key from the verity partition config? Would we just have to duplicate the relevant settings from the data partition (Format=, Encrypt=, MakeDirectories=)?
But then that configuration wouldn't actually be configuration for the partition, but it'd just be there to make sure we can find the correct cache entry, so we'd have to add checks everywhere to not actually apply any of those settings if VerityFiles is also specified. That seems somewhat ugly to me.
I guess we could add VerityFormat=, VerityEncrypt= and VerityMakeDirectories= to indicate that those are only to match in the filesystem cache and don't actually apply to the partition.
I'm still not sure if I like having to duplicate all the configuration between the two but that's the price of keeping the definition files independent from each other I guess.
I guess we could add VerityFormat=, VerityEncrypt= and VerityMakeDirectories= to indicate that those are only to match in the filesystem cache and don't actually apply to the partition.
Well, VerityEncrypt= doesn#t really make sense conceptually... Encryption and verity sounds a bogus concept to me. I'd refuse that.
But maybe you have a point. Instead of Adding VerityFiles= we maybe should instead just make it a new setting Verity=yes|no (with "no" — which should be the default — you get the behaviour as now. But if yes, then we'll simply store the the verity hashes of what is defined here, and then doing the caching as suggested.
Implementation-wise we should probably add another phase to the whole thing, so that we have one phase where we mkfs/copy all data, and then a second phase where we then generate the hash data from it.
I'm still not sure if I like having to duplicate all the configuration between the two but that's the price of keeping the definition files independent from each other I guess.
It's not thaaaat much. But I guess it means we should normalize things to minimize risk of fucking this up. i.e. sort MakeDirectories= arguments and so on while parsing.
So to summarize, maybe this:
50-root.conf:
[Partition]
Type=root
UUID=verity-lo
CopyFiles=/my/source/tree
MakeDirectories=a b c
Format=xfs
60-root-verity.conf:
[Partition]
Type=root-verity
UUID=verity-hi
Verity=yes
CopyFiles=/my/source/tree
MakeDirectories=a b c
Format=xfs
And then in one of the two phases we process 50-root.conf and generate the fs for the root. And then in the second phase we process 60-root-verity.conf and see the Verity=yes setting, and then look up in our cache if we already built an fs with this data, and use it then, and simply generate the verity data for it.
Hmm, thinking one step further: we support embedded PCKS#7 sigs for verity root hases in another partition these days, so maybe instead of Verity=yes|no we should make it an enum instead, so that you can pick
Verity=data
Verity=hash
Verity=signature
And the default woud be Verity=data, i.e. we actually format/copy files. But Verity=hash is set we'd generate the hash blob and write that instead, based on the cached fs image. And if Verity=signature we'd generate the PKCS7 signature and write that. The cache would thus no only carry info about generated file systems, but also about the root hash. And we'd have a three-phase process: first, iterate through all partitions to generate any filesystems/populate them. And then, iterate through all partitions again, generating verity data. And then iterate a third time, generating signatures.
And I'd probably make things simply fail if people use Verity=hash but never used Verity=data with the same parameters on some other partition. And similar, if people use Verity=signature but have no Verity=data partition elsewhere.
(I mean, I am not suggested you implement the pkcs#7 right-away – of course you#d be more than welcome –, all I am saying that maybe making this an enum [instead of a boolean] from the beginning is safer, and more future proof, given that this is something we likely want to add sooner rather than later)
Why would encryption and verity be bogus? I thought verity ensures the files haven't been tampered with, and encryption ensures the disk can't be read without the passphrase. Those concepts seem disjoint to me.
Do you mean that an encrypted verity hash partition doesn't make sense?
Why would encryption and verity be bogus? I thought verity ensures the files haven't been tampered with, and encryption ensures the disk can't be read without the passphrase. Those concepts seem disjoint to me.
But one would use the integrity stuff of LUKS for that, not verity. It's a lot more efficient, since dm-crypt and dm-integrity integrate with each other, and save work.
Also, how about to check Type= between the matching two partitions?
If Type= is one of the known partition types, then they have to match, e.g. root and root-verity, usr and usr-verity, so on.
Why not to simply introduce e.g. VerityName= or so?
What would the impact of that name be? Would that identifier you'd set here propagate anywhere into the image? Or is it purely intended for matching up the two partitions inside of repart's logic?
If the latter we already have such an identifier: the name of the dropin file. We could in theory use that.
Also, how about to check Type= between the matching two partitions?
If Type= is one of the known partition types, then they have to match, e.g. root and root-verity, usr and usr-verity, so on.
Hmm, a major usecase for repart is A/B update scenarios: you have multiple sets of partitions of the same type. That makes finding the counterparts via type uuid alone ugly.
I like the current approach of searching by contents, i.e. by the CopyBlocks=/CopyFiles=/MakeDirectories= values. But I'd also be OK going by drop-in filename. Might even be OK to support both: if in the hash partition definition no dropin file name for the data partition is specified match by CopyBlocks=/CopyFiles=/MakeDirectories=
I quite like the VerityName= approach, it avoids the ugly duplication of all the content options.
If the latter we already have such an identifier: the name of the dropin file. We could in theory use that.
Hmm, it seems more flexible if we decouple these. That allows changing the filename (for w.e. reason) without having to go and touch unrelated files to change VerityName in each of them. The only thing we really avoid by using the dropin file is that we don't have to specify VerityName in one of the definition files. So I'd prefer if we just use VerityName with an arbitrary string to couple partitions together. It's intuitive and explicit.
Since VerityName is super easy, I'd just support that and wouldn't do the other matching.
Hmm, a major usecase for repart is A/B update scenarios: you have multiple sets of partitions of the same type. That makes finding the counterparts via type uuid alone ugly.
I don't think Yu is suggesting to use the the partition type UUIDs for matching, just that if we have two matching verity partitions and the data partition type uuid is "root", that we verity that the hash partition type uuid is "root-verity".
I'd go even further and disallow Type= if Verity=hash, and just infer it from the data partition type UUID..
Activity
poettering commentedon Sep 5, 2022
So originally my focus for repart was to run at boot, and readjust partitions on the deployment machine. There it doesn't make too much sense to generate verity, since that's a job for an OS builder, not something you'd run on the deployment machine. But of course, the focus shifted a bit: repart is useful for building images too, on the OS builder's machine. So I guess adding this functionality would make sense, and I guess wouldn't even be that much code.
daandemeyer commentedon Sep 5, 2022
I'm a little unsure about the implementation. First, I was thinking along the lines of an optional
Veritysection that defines a verity partition for the regular partition defined in the same definition file. But then you'd have to duplicate many settings of thePartitionsection in theVeritysection as well.Then I figured we can add the
Veritysection to configure additional verity settings for a definition file defining a verity partition. But what I'm not sure about is how to specify the data partition for the verity partition in that case, the UUID is the closest to an identifier but when we're doing verity the UUID comes from the root hash so it's not defined yet for the data partition. The type can be ambiguous so I'm not sure that would be great either. We could do ordering based and use the previous partition as the data partition but that doesn't seem amazing either.We could also use the definition file name as a match I guess (similar to unit file names which are also used as matches), but that would prevent us from making a verity partition of any partition that can't be matched against a definition file.
Any other ideas on how to specify the data partition for the verity partition? Or should we define data and corresponding verity partitions in the same definition file after all?
poettering commentedon Sep 5, 2022
So what do you intend to use as source here for the whole op? i.e. have a ready made fs image that you want to generate a disk image from and then also add a verity partition for? i.e. CopyBlocks= in one partition? In that scheme things would be easy, you could just add VerityBlocks= or so and then have a pair of partitions: one with CopyBlocks= (for the payload) and one with VerityBlocks= (for the verity hashes). And then the UUID= setting would also learn two new magic values "verity-hi" and "verity-lo" or so, for the high/lo bits of the verity root hash of the CopyBlocks=/VerityBlocks= stuff. (of course, this means some caching would be needed to ensure we don't run the verity stuff twice, but just once).
i.e.:
50-root.conf:
60-root-verityconf:
poettering commentedon Sep 5, 2022
(and if there are other tweaks to verity people really want to make then add further VerityXYZ= fields to [Partition])
daandemeyer commentedon Sep 5, 2022
The issue is that I don't have a ready made image, I have a directory tree that I'll copy into partitions using CopyFiles. But verity works on blocks, so I'd like to use the repart generated data partition as the data device for the verity partition, but to do that I need a way to specify that generated data partition by repart in the definition file for the verity partition. I'm just not sure what the best way is to specify that.
repart would then generate all the partitions, copy the files in there if CopyFiles is specified, and as the final step, format the verity partition based on the data partition and somehow communicate the resulting roothash to the user. Probably by just writing to a file in the directory that repart is running from or so.
poettering commentedon Sep 5, 2022
Hmm, I guess we could do it the same way for CopyFiles=. I mean, we try very hard to generate file systems reproducibly already, i.e. derive uuid/label in a stable way. We can build on that, and simply say that as long as you specify the same data for the fs we generate we'll cache the resulting fs binary data stuff for you, so that we can reuse it for the verity generation
i.e. let's say you have:
50-root.conf:
60-root-verityconf:
i.e. if we you run stuff like this, then once we come to generate the data for the first of the two partitions we'll notice we haven't generated that so far, so we generate the fs for it. if the first partition was the non-verity one, we just copy that into the partition, but we also maintain a cache that uses the copy source path (and some of the relevant other settings, i.e. fstype and so on) as key. And then, when we come to the second partition, we look into that cache. And then instead of generating the fs new, we just use that again.
i.e. cache key would by copy source path + fstype + … and the cache value would be triplet of fd + offset + size, pointing to where the prepared data can be read from. We'd keep the cache open for the whole operation and close it only when done. Thus, as long as you use the exact same source path and parameters we'll always only run mkfs/copy once.
I think this would be really nice and simple. I mean, the mkfs/copy stuff isn't truly reproducible (because we are using kernel fs drivers here), but superficially they'll look the same, because same contents and same metadata. And by employing the cache we can both optimize generation (because we don't have to genreate the fs twice) but also get bitwise identical copies even though running mkfs/copy twice wouldn't actually give us that.
This would ensure things remain nicely independent conceptually (since the .conf files on paper are still entirely indepndent of each other) but things would be fast and systematic.
Does that make sense?
poettering commentedon Sep 5, 2022
(I guess the next step would then to teach repart to generate squashfs too)
daandemeyer commentedon Sep 5, 2022
How would we derive the cache key from the verity partition config? Would we just have to duplicate the relevant settings from the data partition (Format=, Encrypt=, MakeDirectories=)?
But then that configuration wouldn't actually be configuration for the partition, but it'd just be there to make sure we can find the correct cache entry, so we'd have to add checks everywhere to not actually apply any of those settings if
VerityFilesis also specified. That seems somewhat ugly to me.I guess we could add
VerityFormat=,VerityEncrypt=andVerityMakeDirectories=to indicate that those are only to match in the filesystem cache and don't actually apply to the partition.I'm still not sure if I like having to duplicate all the configuration between the two but that's the price of keeping the definition files independent from each other I guess.
poettering commentedon Sep 5, 2022
Well, VerityEncrypt= doesn#t really make sense conceptually... Encryption and verity sounds a bogus concept to me. I'd refuse that.
But maybe you have a point. Instead of Adding VerityFiles= we maybe should instead just make it a new setting Verity=yes|no (with "no" — which should be the default — you get the behaviour as now. But if yes, then we'll simply store the the verity hashes of what is defined here, and then doing the caching as suggested.
Implementation-wise we should probably add another phase to the whole thing, so that we have one phase where we mkfs/copy all data, and then a second phase where we then generate the hash data from it.
It's not thaaaat much. But I guess it means we should normalize things to minimize risk of fucking this up. i.e. sort MakeDirectories= arguments and so on while parsing.
So to summarize, maybe this:
50-root.conf:
60-root-verity.conf:
And then in one of the two phases we process 50-root.conf and generate the fs for the root. And then in the second phase we process 60-root-verity.conf and see the Verity=yes setting, and then look up in our cache if we already built an fs with this data, and use it then, and simply generate the verity data for it.
poettering commentedon Sep 5, 2022
Hmm, thinking one step further: we support embedded PCKS#7 sigs for verity root hases in another partition these days, so maybe instead of Verity=yes|no we should make it an enum instead, so that you can pick
And the default woud be
Verity=data, i.e. we actually format/copy files. But Verity=hash is set we'd generate the hash blob and write that instead, based on the cached fs image. And if Verity=signature we'd generate the PKCS7 signature and write that. The cache would thus no only carry info about generated file systems, but also about the root hash. And we'd have a three-phase process: first, iterate through all partitions to generate any filesystems/populate them. And then, iterate through all partitions again, generating verity data. And then iterate a third time, generating signatures.And I'd probably make things simply fail if people use Verity=hash but never used Verity=data with the same parameters on some other partition. And similar, if people use Verity=signature but have no Verity=data partition elsewhere.
poettering commentedon Sep 5, 2022
(I mean, I am not suggested you implement the pkcs#7 right-away – of course you#d be more than welcome –, all I am saying that maybe making this an enum [instead of a boolean] from the beginning is safer, and more future proof, given that this is something we likely want to add sooner rather than later)
daandemeyer commentedon Sep 5, 2022
Why would encryption and verity be bogus? I thought verity ensures the files haven't been tampered with, and encryption ensures the disk can't be read without the passphrase. Those concepts seem disjoint to me.
Do you mean that an encrypted verity hash partition doesn't make sense?
Aside from that, this approach looks OK to me.
poettering commentedon Sep 5, 2022
But one would use the integrity stuff of LUKS for that, not verity. It's a lot more efficient, since dm-crypt and dm-integrity integrate with each other, and save work.
4 remaining items
yuwata commentedon Sep 6, 2022
Also, how about to check Type= between the matching two partitions?
If Type= is one of the known partition types, then they have to match, e.g. root and root-verity, usr and usr-verity, so on.
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
poettering commentedon Sep 6, 2022
What would the impact of that name be? Would that identifier you'd set here propagate anywhere into the image? Or is it purely intended for matching up the two partitions inside of repart's logic?
If the latter we already have such an identifier: the name of the dropin file. We could in theory use that.
poettering commentedon Sep 6, 2022
Hmm, a major usecase for repart is A/B update scenarios: you have multiple sets of partitions of the same type. That makes finding the counterparts via type uuid alone ugly.
I like the current approach of searching by contents, i.e. by the CopyBlocks=/CopyFiles=/MakeDirectories= values. But I'd also be OK going by drop-in filename. Might even be OK to support both: if in the hash partition definition no dropin file name for the data partition is specified match by CopyBlocks=/CopyFiles=/MakeDirectories=
daandemeyer commentedon Sep 6, 2022
I quite like the VerityName= approach, it avoids the ugly duplication of all the content options.
Hmm, it seems more flexible if we decouple these. That allows changing the filename (for w.e. reason) without having to go and touch unrelated files to change VerityName in each of them. The only thing we really avoid by using the dropin file is that we don't have to specify
VerityNamein one of the definition files. So I'd prefer if we just useVerityNamewith an arbitrary string to couple partitions together. It's intuitive and explicit.Since
VerityNameis super easy, I'd just support that and wouldn't do the other matching.I don't think Yu is suggesting to use the the partition type UUIDs for matching, just that if we have two matching verity partitions and the data partition type uuid is "root", that we verity that the hash partition type uuid is "root-verity".
I'd go even further and disallow
Type=ifVerity=hash, and just infer it from the data partition type UUID..repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions
repart: Add support for formatting verity partitions