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

feat: support uki profiles via imager #10337

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
29 changes: 14 additions & 15 deletions internal/pkg/uki/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,26 @@ func (builder *Builder) generatePCRPublicKey() error {
return nil
}

func defaultProfiles() []Profile {
return []Profile{
{
ID: "main",
},
}
}

func (builder *Builder) generateProfiles() error {
if !quirks.New(builder.Version).SupportsUKIProfiles() {
return nil
}

for _, profile := range []Profile{
{
ID: "main",
},
{
ID: "reset-maintenance",
Title: "Reset to maintenance mode",
if slices.ContainsFunc(builder.Profiles, func(p Profile) bool {
return p.ID == "main"
}) {
return fmt.Errorf("profile with ID 'main' is reserved")
}

Cmdline: builder.Cmdline + " talos.experimental.wipe=system:EPHEMERAL,STATE",
},
{
ID: "reset",
Title: "Reset system disk",
Cmdline: builder.Cmdline + " talos.experimental.wipe=system",
},
} {
for _, profile := range slices.Concat(defaultProfiles(), builder.Profiles) {
path := filepath.Join(builder.scratchDir, fmt.Sprintf("profile-%s", profile.ID))

if err := os.WriteFile(path, []byte(profile.String()), 0o600); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/uki/uki.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type Builder struct {
SecureBootSigner pesign.CertificateSigner
// PCR signer.
PCRSigner measure.RSAKey
// Profiles to include in the UKI.
Profiles []Profile

// Output options:
//
Expand Down
21 changes: 19 additions & 2 deletions internal/pkg/uki/uki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/siderolabs/talos/internal/pkg/measure"
"github.com/siderolabs/talos/internal/pkg/uki"
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
"github.com/siderolabs/talos/pkg/machinery/constants"
"github.com/siderolabs/talos/pkg/machinery/imager/quirks"
"github.com/siderolabs/talos/pkg/machinery/version"
"github.com/siderolabs/talos/pkg/splash"
Expand Down Expand Up @@ -166,6 +167,20 @@ func TestBuildUKI(t *testing.T) {
sdStubPath := "internal/pe/testdata/linuxx64.efi.stub"
addonStubPath := "internal/pe/testdata/addonx64.efi.stub"

ukiProfiles := []uki.Profile{
{
ID: "reset-maintenance",
Title: "Reset to maintenance mode",

Cmdline: cmdline + fmt.Sprintf(" %s=system:EPHEMERAL,STATE", constants.KernelParamWipe),
},
{
ID: "reset",
Title: "Reset system disk",
Cmdline: cmdline + fmt.Sprintf(" %s=system", constants.KernelParamWipe),
},
}

for _, talosVersion := range []string{"1.9.0", "1.10.0"} {
ukiUnsigned := filepath.Join(tempDir, fmt.Sprintf("uki-%s.efi", talosVersion))
ukiSigned := filepath.Join(tempDir, fmt.Sprintf("uki-%s-signed.efi", talosVersion))
Expand All @@ -180,6 +195,7 @@ func TestBuildUKI(t *testing.T) {
KernelPath: kernel,
InitrdPath: initrd,
Cmdline: cmdline,
Profiles: ukiProfiles,

OutSdBootPath: sdBootSigned,
OutUKIPath: ukiUnsigned,
Expand All @@ -197,6 +213,7 @@ func TestBuildUKI(t *testing.T) {
Cmdline: cmdline,
SecureBootSigner: &certificateProvider{signingKey},
PCRSigner: rsaKey,
Profiles: ukiProfiles,

OutSdBootPath: sdBootSigned,
OutUKIPath: ukiSigned,
Expand Down Expand Up @@ -286,7 +303,7 @@ func TestBuildUKI(t *testing.T) {
"--profile",
"ID=reset-maintenance\nTITLE=Reset to maintenance mode",
"--cmdline",
cmdline + " talos.experimental.wipe=system:EPHEMERAL,STATE",
cmdline + fmt.Sprintf(" %s=system:EPHEMERAL,STATE", constants.KernelParamWipe),
"--output",
resetMaintenanceProfile,
}...,
Expand All @@ -308,7 +325,7 @@ func TestBuildUKI(t *testing.T) {
"--profile",
"ID=reset\nTITLE=Reset system disk",
"--cmdline",
cmdline + " talos.experimental.wipe=system",
cmdline + fmt.Sprintf(" %s=system", constants.KernelParamWipe),
"--output",
resetProfile,
}...,
Expand Down
16 changes: 16 additions & 0 deletions pkg/imager/imager.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,22 @@ func (i *Imager) buildUKI(ctx context.Context, report *reporter.Reporter) error
OutUKIPath: i.ukiPath,
}

switch i.prof.Output.Kind { //nolint:exhaustive
case profile.OutKindISO:
builder.Profiles = append(builder.Profiles, uki.Profile{
ID: "reset",
Title: "Reset system disk",
Cmdline: builder.Cmdline + fmt.Sprintf(" %s=system", constants.KernelParamWipe),
})
case profile.OutKindImage, profile.OutKindInstaller:
builder.Profiles = append(builder.Profiles, uki.Profile{
ID: "reset-maintenance",
Title: "Reset to maintenance mode",

Cmdline: builder.Cmdline + fmt.Sprintf(" %s=system:EPHEMERAL,STATE", constants.KernelParamWipe),
})
}

buildFunc := builder.Build

if i.prof.SecureBootEnabled() {
Expand Down
Loading