Skip to content

Commit

Permalink
overlord/fdestate: keep FDE state up to date
Browse files Browse the repository at this point in the history
Ensure() initializes the empty profiles, and reseal updates them.
  • Loading branch information
valentindavid committed Sep 20, 2024
1 parent 6491f5f commit 728ff63
Show file tree
Hide file tree
Showing 21 changed files with 951 additions and 247 deletions.
16 changes: 8 additions & 8 deletions boot/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var _ = Suite(&assetsSuite{})
func (s *assetsSuite) SetUpTest(c *C) {
s.baseBootenvSuite.SetUpTest(c)

restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
return nil
})
s.AddCleanup(restore)
Expand Down Expand Up @@ -788,7 +788,7 @@ func (s *assetsSuite) testUpdateObserverUpdateMockedWithReseal(c *C, seedRole st

// everything is set up, trigger a reseal
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -893,7 +893,7 @@ func (s *assetsSuite) TestUpdateObserverUpdateExistingAssetMocked(c *C) {

// everything is set up, trigger reseal
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -1649,7 +1649,7 @@ func (s *assetsSuite) TestUpdateObserverCanceledSimpleAfterBackupMocked(c *C) {
"shim": []string{shimHash},
})
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -1809,7 +1809,7 @@ func (s *assetsSuite) TestUpdateObserverCanceledNoActionsMocked(c *C) {
obs, _ := s.uc20UpdateObserverEncryptedSystemMockedBootloader(c)

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -2561,7 +2561,7 @@ func (s *assetsSuite) TestUpdateObserverReseal(c *C) {

// everything is set up, trigger a reseal
resealCalls := 0
restore = boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore = boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 1)
Expand Down Expand Up @@ -2713,7 +2713,7 @@ func (s *assetsSuite) TestUpdateObserverCanceledReseal(c *C) {

resealCalls := 0

restore = boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore = boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 1)
Expand Down Expand Up @@ -2846,7 +2846,7 @@ func (s *assetsSuite) TestUpdateObserverUpdateMockedNonEncryption(c *C) {

// make sure that no reseal is triggered
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down
48 changes: 24 additions & 24 deletions boot/boot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type baseBootenv20Suite struct {
func (s *baseBootenv20Suite) SetUpTest(c *C) {
s.baseBootenvSuite.SetUpTest(c)

restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
return nil
})
s.AddCleanup(restore)
Expand Down Expand Up @@ -1121,7 +1121,7 @@ func (s *bootenv20Suite) TestCoreParticipant20SetNextNewKernelSnapWithReseal(c *
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 2)
Expand Down Expand Up @@ -1241,7 +1241,7 @@ func (s *bootenv20Suite) TestCoreParticipant20SetNextNewUnassertedKernelSnapWith
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 2)
Expand Down Expand Up @@ -1362,7 +1362,7 @@ func (s *bootenv20Suite) TestCoreParticipant20SetNextSameKernelSnapNoReseal(c *C
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -1459,7 +1459,7 @@ func (s *bootenv20Suite) TestCoreParticipant20SetNextSameUnassertedKernelSnapNoR
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -2058,7 +2058,7 @@ func (s *bootenv20Suite) TestMarkBootSuccessful20KernelUpdateWithReseal(c *C) {
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 1)
Expand Down Expand Up @@ -2292,7 +2292,7 @@ func (s *bootenv20Suite) TestMarkBootSuccessful20BootAssetsUpdateHappy(c *C) {
c.Assert(coreDev.HasModeenv(), Equals, true)

resealCalls := 0
restore = boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore = boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 1)
Expand Down Expand Up @@ -2453,7 +2453,7 @@ func (s *bootenv20Suite) TestMarkBootSuccessful20BootAssetsStableStateHappy(c *C
c.Assert(coreDev.HasModeenv(), Equals, true)

resealCalls := 0
restore = boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore = boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -2567,7 +2567,7 @@ func (s *bootenv20Suite) TestMarkBootSuccessful20BootUnassertedKernelAssetsStabl
c.Assert(coreDev.HasModeenv(), Equals, true)

resealCalls := 0
restore = boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore = boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -3156,7 +3156,7 @@ var _ = Suite(&bootConfigSuite{})
func (s *bootConfigSuite) SetUpTest(c *C) {
s.baseBootenvSuite.SetUpTest(c)

restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
return nil
})
s.AddCleanup(restore)
Expand Down Expand Up @@ -3193,7 +3193,7 @@ func (s *bootConfigSuite) TestBootConfigUpdateHappyNoKeysNoReseal(c *C) {
c.Assert(m.WriteTo(""), IsNil)

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -3245,7 +3245,7 @@ func (s *bootConfigSuite) testBootConfigUpdateHappyWithReseal(c *C, cmdlineAppen
newCmdline := strutil.JoinNonEmpty([]string{
"snapd_recovery_mode=run mocked candidate panic=-1", cmdlineAppend}, " ")
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
c.Assert(params, NotNil)

Expand Down Expand Up @@ -3305,7 +3305,7 @@ func (s *bootConfigSuite) testBootConfigUpdateHappyNoChange(c *C, cmdlineAppend
c.Assert(m.WriteTo(""), IsNil)

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -3470,7 +3470,7 @@ volumes:
c.Assert(m.WriteTo(""), IsNil)

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
c.Assert(params, NotNil)

Expand Down Expand Up @@ -3536,7 +3536,7 @@ volumes:
// reseal does not happen, because the gadget overrides the static
// command line which is part of boot config, thus there's no resulting
// change in the command lines tracked in modeenv and no need to reseal
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return fmt.Errorf("unexpected call")
})
Expand Down Expand Up @@ -3573,7 +3573,7 @@ var _ = Suite(&bootKernelCommandLineSuite{})
func (s *bootKernelCommandLineSuite) SetUpTest(c *C) {
s.baseBootenvSuite.SetUpTest(c)

restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
return nil
})
s.AddCleanup(restore)
Expand Down Expand Up @@ -3633,7 +3633,7 @@ func (s *bootKernelCommandLineSuite) SetUpTest(c *C) {

s.resealCommandLines = nil
s.resealCalls = 0
restore = boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore = boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
s.resealCalls++
c.Assert(params, NotNil)
c.Assert(params.RunModeBootChains, HasLen, 0)
Expand Down Expand Up @@ -3909,7 +3909,7 @@ volumes:
c.Assert(s.modeenvWithEncryption.WriteTo(""), IsNil)

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return fmt.Errorf("reseal fails")
})
Expand Down Expand Up @@ -4053,7 +4053,7 @@ func (s *bootKernelCommandLineSuite) TestCommandLineUpdateUC20OverSpuriousReboot
s.stampSealedKeys(c, dirs.GlobalRootDir)

resealPanic := false
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
s.resealCalls++
c.Logf("reseal call %v", s.resealCalls)
c.Assert(params, NotNil)
Expand Down Expand Up @@ -4636,7 +4636,7 @@ func (s *bootenv20Suite) TestCoreParticipant20UndoKernelSnapInstallNewWithReseal
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 1)
Expand Down Expand Up @@ -4747,7 +4747,7 @@ func (s *bootenv20Suite) TestCoreParticipant20UndoUnassertedKernelSnapInstallNew
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++

c.Assert(params.RunModeBootChains, HasLen, 1)
Expand Down Expand Up @@ -4859,7 +4859,7 @@ func (s *bootenv20Suite) TestCoreParticipant20UndoKernelSnapInstallSameNoReseal(
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -4956,7 +4956,7 @@ func (s *bootenv20Suite) TestCoreParticipant20UndoUnassertedKernelSnapInstallSam
defer r()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down Expand Up @@ -5092,7 +5092,7 @@ func (s *bootenv20Suite) TestCoreParticipant20UndoBaseSnapInstallNewNoReseal(c *
model := coreDev.Model()

resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
restore := boot.MockResealKeyForBootChains(func(locked bool, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion boot/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func EnableTestingRebootFunction() (restore func()) {
return func() { testingRebootItself = false }
}

func MockResealKeyForBootChains(f func(method device.SealingMethod, rootdir string, params *ResealKeyForBootChainsParams, expectReseal bool) error) (restore func()) {
func MockResealKeyForBootChains(f func(locked bool, method device.SealingMethod, rootdir string, params *ResealKeyForBootChainsParams, expectReseal bool) error) (restore func()) {
old := ResealKeyForBootChains
ResealKeyForBootChains = f
return func() {
Expand Down
Loading

0 comments on commit 728ff63

Please sign in to comment.