Skip to content

Commit 44e794a

Browse files
alexlarssonachilleas-k
authored andcommitted
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 5bae3b6 commit 44e794a

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
@@ -223,15 +223,35 @@ func genPartitionTable(c *ManifestConfig, customizations *blueprint.Customizatio
223223
}
224224
}
225225

226+
var partitionTable *disk.PartitionTable
226227
switch {
227228
// XXX: move into images library
228229
case fsCust != nil && diskCust != nil:
229230
return nil, fmt.Errorf("cannot combine disk and filesystem customizations")
230231
case diskCust != nil:
231-
return genPartitionTableDiskCust(c, diskCust, rng)
232+
partitionTable, err = genPartitionTableDiskCust(c, diskCust, rng)
233+
if err != nil {
234+
return nil, err
235+
}
232236
default:
233-
return genPartitionTableFsCust(c, fsCust, rng)
237+
partitionTable, err = genPartitionTableFsCust(c, fsCust, rng)
238+
if err != nil {
239+
return nil, err
240+
}
234241
}
242+
243+
// Ensure ext4 rootfs has fs-verity enabled
244+
rootfs := partitionTable.FindMountable("/")
245+
if rootfs != nil {
246+
switch elem := rootfs.(type) {
247+
case *disk.Filesystem:
248+
if elem.Type == "ext4" {
249+
elem.MkfsOptions = append(elem.MkfsOptions, []disk.MkfsOption{disk.MkfsVerity}...)
250+
}
251+
}
252+
}
253+
254+
return partitionTable, nil
235255
}
236256

237257
// calcRequiredDirectorySizes will calculate the minimum sizes for /
@@ -433,9 +453,7 @@ func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest
433453
mf.Distro = manifest.DISTRO_FEDORA
434454
runner := &runner.Linux{}
435455

436-
if err := img.InstantiateManifestFromContainers(&mf,
437-
[]container.SourceSpec{containerSource},
438-
[]container.SourceSpec{buildContainerSource}, runner, rng); err != nil {
456+
if err := img.InstantiateManifestFromContainers(&mf, []container.SourceSpec{containerSource}, runner, rng); err != nil {
439457
return nil, err
440458
}
441459

0 commit comments

Comments
 (0)