-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement secure boot from disk
This includes sd-boot handling, EFI variables, etc. There are some TODOs which need to be addressed to make things smooth. Install to disk, upgrades work. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
- Loading branch information
Showing
19 changed files
with
439 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
internal/app/machined/pkg/runtime/v1alpha1/bootloader/sdboot/efivars.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package sdboot | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ecks/uefi/efi/efiguid" | ||
"github.com/ecks/uefi/efi/efivario" | ||
"golang.org/x/text/encoding/unicode" | ||
) | ||
|
||
// SystemdBootGUIDString is the GUID of the SystemdBoot EFI variables. | ||
const SystemdBootGUIDString = "4a67b082-0a4c-41cf-b6c7-440b29bb8c4f" | ||
|
||
// SystemdBootGUID is the GUID of the SystemdBoot EFI variables. | ||
var SystemdBootGUID = efiguid.MustFromString(SystemdBootGUIDString) | ||
|
||
// Variable names. | ||
const ( | ||
LoaderEntryDefaultName = "LoaderEntryDefault" | ||
LoaderEntrySelectedName = "LoaderEntrySelected" | ||
LoaderConfigTimeoutName = "LoaderConfigTimeout" | ||
) | ||
|
||
// ReadVariable reads a SystemdBoot EFI variable. | ||
func ReadVariable(c efivario.Context, name string) (string, error) { | ||
_, data, err := efivario.ReadAll(c, name, SystemdBootGUID) | ||
if err != nil { | ||
if errors.Is(err, efivario.ErrNotFound) { | ||
return "", nil | ||
} | ||
|
||
return "", err | ||
} | ||
|
||
out := make([]byte, len(data)) | ||
|
||
decoder := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewDecoder() | ||
|
||
n, _, err := decoder.Transform(out, data, true) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if n > 0 && out[n-1] == 0 { | ||
n-- | ||
} | ||
|
||
return string(out[:n]), nil | ||
} | ||
|
||
// WriteVariable reads a SystemdBoot EFI variable. | ||
func WriteVariable(c efivario.Context, name, value string) error { | ||
out := make([]byte, (len(value)+1)*2) | ||
|
||
encoder := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder() | ||
|
||
n, _, err := encoder.Transform(out, []byte(value), true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
out = append(out[:n], 0, 0) | ||
|
||
return c.Set(name, SystemdBootGUID, efivario.BootServiceAccess|efivario.RuntimeAccess|efivario.NonVolatile, out) | ||
} |
Oops, something went wrong.