Skip to content

Commit 9b957df

Browse files
committed
chore: uki code restructure
UKI code re-structure, no-op. Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent e41a995 commit 9b957df

42 files changed

Lines changed: 131 additions & 129 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hack/release.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ cluster:
7373
```
7474
7575
Usage of `authorization-mode` CLI argument will not support this form of customization.
76+
"""
7677

7778
[make_deps]
7879

internal/app/init/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func run() error {
6060
}
6161

6262
// extend PCR 11 with enter-initrd
63-
if err := tpm2.PCRExtend(secureboot.UKIPCR, []byte(secureboot.EnterInitrd)); err != nil {
64-
return fmt.Errorf("failed to extend PCR %d with enter-initrd: %v", secureboot.UKIPCR, err)
63+
if err := tpm2.PCRExtend(constants.UKIPCR, []byte(secureboot.EnterInitrd)); err != nil {
64+
return fmt.Errorf("failed to extend PCR %d with enter-initrd: %v", constants.UKIPCR, err)
6565
}
6666

6767
log.Printf("booting Talos %s", version.Tag)

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func WriteUdevRules(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
328328
// StartMachined represents the task to start machined.
329329
func StartMachined(_ runtime.Sequence, _ any) (runtime.TaskExecutionFunc, string) {
330330
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) error {
331-
if err := tpm2.PCRExtend(secureboot.UKIPCR, []byte(secureboot.EnterMachined)); err != nil {
331+
if err := tpm2.PCRExtend(constants.UKIPCR, []byte(secureboot.EnterMachined)); err != nil {
332332
return err
333333
}
334334

@@ -423,7 +423,7 @@ func StartUdevd(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
423423
// ExtendPCRStartAll represents the task to extend the PCR with the StartTheWorld PCR phase.
424424
func ExtendPCRStartAll(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
425425
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) {
426-
return tpm2.PCRExtend(secureboot.UKIPCR, []byte(secureboot.StartTheWorld))
426+
return tpm2.PCRExtend(constants.UKIPCR, []byte(secureboot.StartTheWorld))
427427
}, "extendPCRStartAll"
428428
}
429429

internal/pkg/encryption/keys/tpm2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/siderolabs/go-blockdevice/v2/encryption/luks"
1717
"github.com/siderolabs/go-blockdevice/v2/encryption/token"
1818

19-
"github.com/siderolabs/talos/internal/pkg/secureboot"
2019
"github.com/siderolabs/talos/internal/pkg/secureboot/tpm2"
20+
"github.com/siderolabs/talos/pkg/machinery/constants"
2121
)
2222

2323
// TPMToken is the userdata stored in the partition token metadata.
@@ -74,7 +74,7 @@ func (h *TPMKeyHandler) NewKey(ctx context.Context) (*encryption.Key, token.Toke
7474
KeySlots: []int{h.slot},
7575
SealedBlobPrivate: resp.SealedBlobPrivate,
7676
SealedBlobPublic: resp.SealedBlobPublic,
77-
PCRs: []int{secureboot.UKIPCR},
77+
PCRs: []int{constants.UKIPCR},
7878
Alg: "sha256",
7979
PolicyHash: resp.PolicyDigest,
8080
KeyName: resp.KeyName,

internal/pkg/secureboot/measure/internal/pcr/bank_data.go renamed to internal/pkg/measure/internal/pcr/bank_data.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/siderolabs/talos/internal/pkg/secureboot"
1919
tpm2internal "github.com/siderolabs/talos/internal/pkg/secureboot/tpm2"
20+
"github.com/siderolabs/talos/pkg/machinery/constants"
2021
)
2122

2223
// RSAKey is the input for the CalculateBankData function.
@@ -30,7 +31,7 @@ type RSAKey interface {
3031
// This mimics the process happening happening in the TPM when the UKI is being loaded.
3132
//
3233
//nolint:gocyclo
33-
func CalculateBankData(pcrNumber int, alg tpm2.TPMAlgID, sectionData map[secureboot.Section]string, rsaKey RSAKey) ([]tpm2internal.BankData, error) {
34+
func CalculateBankData(pcrNumber int, alg tpm2.TPMAlgID, sectionData map[string]string, rsaKey RSAKey) ([]tpm2internal.BankData, error) {
3435
// get fingerprint of public key
3536
pubKeyFingerprint := sha256.Sum256(x509.MarshalPKCS1PublicKey(rsaKey.PublicRSAKey()))
3637

@@ -39,7 +40,7 @@ func CalculateBankData(pcrNumber int, alg tpm2.TPMAlgID, sectionData map[secureb
3940
return nil, err
4041
}
4142

42-
pcrSelector, err := tpm2internal.CreateSelector([]int{secureboot.UKIPCR})
43+
pcrSelector, err := tpm2internal.CreateSelector([]int{constants.UKIPCR})
4344
if err != nil {
4445
return nil, fmt.Errorf("failed to create PCR selection: %v", err)
4546
}
@@ -55,7 +56,7 @@ func CalculateBankData(pcrNumber int, alg tpm2.TPMAlgID, sectionData map[secureb
5556

5657
hashData := NewDigest(hashAlg)
5758

58-
for _, section := range secureboot.OrderedSections() {
59+
for _, section := range OrderedSections() {
5960
if file := sectionData[section]; file != "" {
6061
hashData.Extend(append([]byte(section), 0))
6162

internal/pkg/secureboot/measure/internal/pcr/bank_data_test.go renamed to internal/pkg/measure/internal/pcr/bank_data_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414
"github.com/google/go-tpm/tpm2"
1515
"github.com/stretchr/testify/require"
1616

17-
"github.com/siderolabs/talos/internal/pkg/secureboot"
18-
"github.com/siderolabs/talos/internal/pkg/secureboot/measure/internal/pcr"
17+
"github.com/siderolabs/talos/internal/pkg/measure/internal/pcr"
1918
tpm2internal "github.com/siderolabs/talos/internal/pkg/secureboot/tpm2"
2019
)
2120

@@ -40,10 +39,10 @@ func TestCalculateBankData(t *testing.T) {
4039
require.NoError(t, err)
4140

4241
bankData, err := pcr.CalculateBankData(15, tpm2.TPMAlgSHA256,
43-
map[secureboot.Section]string{
44-
secureboot.Initrd: "testdata/a",
45-
secureboot.Linux: "testdata/b",
46-
secureboot.DTB: "testdata/c",
42+
map[string]string{
43+
".initrd": "testdata/a",
44+
".linux": "testdata/b",
45+
".dtb": "testdata/c",
4746
},
4847
keyWrapper{key})
4948
require.NoError(t, err)
File renamed without changes.

internal/pkg/secureboot/measure/internal/pcr/extend_test.go renamed to internal/pkg/measure/internal/pcr/extend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/stretchr/testify/assert"
1212

13-
"github.com/siderolabs/talos/internal/pkg/secureboot/measure/internal/pcr"
13+
"github.com/siderolabs/talos/internal/pkg/measure/internal/pcr"
1414
)
1515

1616
func TestExtend(t *testing.T) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package pcr
6+
7+
// OrderedSections returns the sections that are measured into PCR.
8+
//
9+
// Derived from https://github.com/systemd/systemd/blob/v257.1/src/fundamental/uki.h#L6
10+
// .pcrsig section is omitted here since that's what we are calulating here.
11+
func OrderedSections() []string {
12+
// DO NOT REARRANGE
13+
return []string{
14+
".linux",
15+
".osrel",
16+
".cmdline",
17+
".initrd",
18+
".ucode",
19+
".splash",
20+
".dtb",
21+
".uname",
22+
".sbat",
23+
".pcrpkey",
24+
".profile",
25+
".dtbauto",
26+
".hwids",
27+
}
28+
}
File renamed without changes.

0 commit comments

Comments
 (0)