Skip to content

Commit 64b870c

Browse files
committed
image: Always enable verity on the rootfs partition
This rewrites the partition table after creation so that it works both with filesystem and disk customizations.
1 parent d9e4fce commit 64b870c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

bib/cmd/bootc-image-builder/image.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,35 @@ func genPartitionTable(c *ManifestConfig, customizations *blueprint.Customizatio
211211
if err != nil {
212212
return nil, fmt.Errorf("error reading disk customizations: %w", err)
213213
}
214+
var partitionTable *disk.PartitionTable
214215
switch {
215216
// XXX: move into images library
216217
case fsCust != nil && diskCust != nil:
217218
return nil, fmt.Errorf("cannot combine disk and filesystem customizations")
218219
case diskCust != nil:
219-
return genPartitionTableDiskCust(c, diskCust, rng)
220+
partitionTable, err = genPartitionTableDiskCust(c, diskCust, rng)
221+
if err != nil {
222+
return nil, err
223+
}
220224
default:
221-
return genPartitionTableFsCust(c, fsCust, rng)
225+
partitionTable, err = genPartitionTableFsCust(c, fsCust, rng)
226+
if err != nil {
227+
return nil, err
228+
}
222229
}
230+
231+
// Ensure ext4 rootfs has fs-verity enabled
232+
rootfs := partitionTable.FindMountable("/")
233+
if rootfs != nil {
234+
switch elem := rootfs.(type) {
235+
case *disk.Filesystem:
236+
if elem.Type == "ext4" {
237+
elem.MkfsOptions = append(elem.MkfsOptions, []disk.MkfsOption{disk.MkfsVerity}...)
238+
}
239+
}
240+
}
241+
242+
return partitionTable, nil
223243
}
224244

225245
// calcRequiredDirectorySizes will calculate the minimum sizes for /
@@ -421,9 +441,7 @@ func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest
421441
mf.Distro = manifest.DISTRO_FEDORA
422442
runner := &runner.Linux{}
423443

424-
if err := img.InstantiateManifestFromContainers(&mf,
425-
[]container.SourceSpec{containerSource},
426-
[]container.SourceSpec{buildContainerSource}, runner, rng); err != nil {
444+
if err := img.InstantiateManifestFromContainers(&mf, []container.SourceSpec{containerSource}, runner, rng); err != nil {
427445
return nil, err
428446
}
429447

0 commit comments

Comments
 (0)