Skip to content

Commit

Permalink
Fix uki mode detection (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka authored Jan 10, 2024
1 parent 174d69c commit 53f4916
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 10 additions & 0 deletions internal/agent/hooks/kcrypt_uki.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kairos-io/kairos-sdk/machine"
"github.com/kairos-io/kairos-sdk/utils"
kcrypt "github.com/kairos-io/kcrypt/pkg/lib"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -41,6 +42,15 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error {
return nil
}

// Check for a TPM 2.0 device as its needed to encrypt
// Exposed by the kernel to userspace as /dev/tpmrm0 since kernel 4.12
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fdc915f7f71939ad5a3dda3389b8d2d7a7c5ee66
_, err = os.Stat("/dev/tpmrm0")
if err != nil {
c.Logger.Warnf("Skipping partition encryption, could not find TPM 2.0 device at /dev/tpmrm0")
return nil
}

// We always encrypt OEM and PERSISTENT under UKI
// If mounted, unmount it
_ = machine.Umount(constants.OEMDir) //nolint:errcheck
Expand Down
14 changes: 10 additions & 4 deletions internal/agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ func RunInstall(c *config.Config) error {

// UKI path. Check if we are on UKI AND if we are running off a cd, otherwise it makes no sense to run the install
// From the installed system
if internalutils.UkiBootMode() == internalutils.UkiRemovableMedia {
return runInstallUki(c)
if internalutils.IsUki() {
c.Logger.Debugf("UKI mode: %s\n", internalutils.UkiBootMode())
if internalutils.UkiBootMode() == internalutils.UkiRemovableMedia {
return runInstallUki(c)
}
c.Logger.Warnf("UKI boot mode is not removable media, skipping install")
return nil
} else { // Non-uki path
return runInstall(c)
}
Expand Down Expand Up @@ -289,8 +294,9 @@ func dumpCCStringToFile(c *config.Config) (string, error) {
c.Logger.Error("Error creating temporary file for install config: %s\n", err.Error())
return "", err
}
defer os.RemoveAll(f.Name())

defer func(f *os.File) {
_ = f.Close()
}(f)
ccstring, err := c.String()
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ const (
func UkiBootMode() state.Boot {
if IsUki() {
_, err := os.Stat("/run/cos/uki_boot_mode")
if err != nil {
if err == nil {
return UkiHDD
}
return UkiRemovableMedia
Expand Down

0 comments on commit 53f4916

Please sign in to comment.