Skip to content

Commit

Permalink
add verity to EMU API
Browse files Browse the repository at this point in the history
  • Loading branch information
elainezhao96 committed Sep 30, 2024
1 parent 9a3aa76 commit 24cdbc9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions toolkit/tools/osmodifierapi/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type OS struct {
SELinux imagecustomizerapi.SELinux `yaml:"selinux"`
Users []imagecustomizerapi.User `yaml:"users"`
Overlays *[]Overlay `yaml:"overlays"`
Verity *imagecustomizerapi.Verity `yaml:"verity"`
RootHash string `yaml:"rootHash"`
}

func (s *OS) IsValid() error {
Expand Down
39 changes: 39 additions & 0 deletions toolkit/tools/pkg/osmodifierlib/modifierutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,45 @@ func doModifications(baseConfigPath string, osConfig *osmodifierapi.OS) error {
}
}

if osConfig.Verity != nil {

bootCustomizer, err := imagecustomizerlib.NewBootCustomizer(dummyChroot)
if err != nil {
return err
}

err = updateDefaultGrubForVerity(osConfig.RootHash, osConfig.Verity, bootCustomizer)
if err != nil {
return err
}

err = bootCustomizer.WriteToFile(dummyChroot)
if err != nil {
return err
}
}

return nil
}

func updateDefaultGrubForVerity(roothash string, verity *imagecustomizerapi.Verity, bootCustomizer *imagecustomizerlib.BootCustomizer) error {

var err error

newArgs := []string{
"rd.systemd.verity=1",
fmt.Sprintf("roothash=%s", roothash),
fmt.Sprintf("systemd.verity_root_data=%s", verity.DataPartition),
fmt.Sprintf("systemd.verity_root_hash=%s", verity.HashPartition),
fmt.Sprintf("systemd.verity_root_options=%s", verity.CorruptionOption),
}

err = bootCustomizer.UpdateKernelCommandLineArgs("GRUB_CMDLINE_LINUX", []string{"rd.systemd.verity", "roothash",
"systemd.verity_root_data", "systemd.verity_root_hash", "systemd.verity_root_options"}, newArgs)
if err != nil {
return err
}

return nil
}

Expand Down
4 changes: 0 additions & 4 deletions toolkit/tools/pkg/osmodifierlib/modifydefaultgrub.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ import (

var grubArgs = []string{
"rd.overlayfs",
"roothash",
"root",
"rd.systemd.verity",
"systemd.verity_root_data",
"systemd.verity_root_hash",
"systemd.verity_root_options",
"selinux",
"enforcing",
}
Expand Down

0 comments on commit 24cdbc9

Please sign in to comment.