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

add verity to EMU API #10584

Draft
wants to merge 4 commits into
base: 3.0-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions toolkit/tools/osmodifierapi/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type OS struct {
SELinux imagecustomizerapi.SELinux `yaml:"selinux"`
Users []imagecustomizerapi.User `yaml:"users"`
Overlays *[]Overlay `yaml:"overlays"`
Verity *imagecustomizerapi.Verity `yaml:"verity"`
}

func (s *OS) IsValid() error {
Expand Down Expand Up @@ -65,5 +66,12 @@ func (s *OS) IsValid() error {
}
}

// if s.Verity != nil {
// err = s.Verity.IsValid()
// if err != nil {
// return fmt.Errorf("invalid verity:\n%w", err)
// }
// }

return nil
}
4 changes: 2 additions & 2 deletions toolkit/tools/pkg/imagecustomizerlib/customizeverity.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func updateGrubConfigForVerity(dataPartitionIdType imagecustomizerapi.IdType, da
return err
}

formattedCorruptionOption, err := systemdFormatCorruptionOption(corruptionOption)
formattedCorruptionOption, err := SystemdFormatCorruptionOption(corruptionOption)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func systemdFormatPartitionId(idType imagecustomizerapi.IdType, id string) (stri
}
}

func systemdFormatCorruptionOption(corruptionOption imagecustomizerapi.CorruptionOption) (string, error) {
func SystemdFormatCorruptionOption(corruptionOption imagecustomizerapi.CorruptionOption) (string, error) {
switch corruptionOption {
case imagecustomizerapi.CorruptionOptionDefault, imagecustomizerapi.CorruptionOptionIoError:
return "", nil
Expand Down
43 changes: 43 additions & 0 deletions toolkit/tools/pkg/osmodifierlib/modifierutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,49 @@ 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.Verity, bootCustomizer)
if err != nil {
return err
}

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

return nil
}

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

var err error

formattedCorruptionOption, err := imagecustomizerlib.SystemdFormatCorruptionOption(verity.CorruptionOption)
if err != nil {
return err
}

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

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

return nil
}

Expand Down
7 changes: 1 addition & 6 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",
"roothash",
"selinux",
"enforcing",
}
Expand Down Expand Up @@ -92,6 +88,5 @@ func extractValuesFromGrubConfig(imageChroot safechroot.ChrootInterface) ([]stri
}
}
}

return values, rootDevice, nil
}