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

overlord/fdestate/fdestate.go: fix path to data mount point on hybrid #14734

Open
wants to merge 1 commit into
base: fde-manager-features
Choose a base branch
from

Conversation

valentindavid
Copy link
Contributor

@valentindavid valentindavid commented Nov 18, 2024

We used a path that is not a mount point on hybrid to discover the data disk. Instead we now use / for hybrid, and /writable on core.

@valentindavid valentindavid added Run nested The PR also runs tests inluded in nested suite FDE Manager Pull requests that target FDE manager branch labels Nov 18, 2024
@valentindavid valentindavid reopened this Nov 18, 2024
@valentindavid
Copy link
Contributor Author

That should make tests/nested/manual/muinstaller-real work again.

@valentindavid valentindavid force-pushed the valentindavid/fix-hybrid-data-path branch 2 times, most recently from 6f19bb3 to 39ad1ff Compare November 18, 2024 12:11
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (fde-manager-features@544bb48). Learn more about missing BASE report.

Additional details and impacted files
@@                   Coverage Diff                   @@
##             fde-manager-features   #14734   +/-   ##
=======================================================
  Coverage                        ?   78.84%           
=======================================================
  Files                           ?     1093           
  Lines                           ?   147888           
  Branches                        ?        0           
=======================================================
  Hits                            ?   116599           
  Misses                          ?    24010           
  Partials                        ?     7279           
Flag Coverage Δ
unittests 78.84% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@valentindavid valentindavid marked this pull request as ready for review November 18, 2024 12:29
Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the PR description?

@@ -218,7 +219,12 @@ func initializeState(st *state.State) error {

// FIXME mount points will be different in recovery or factory-reset modes
// either inspect degraded.json, or use boot.HostUbuntuDataForMode()
dataUUID, dataErr := disksDMCryptUUIDFromMountPoint(dirs.SnapdStateDir(dirs.GlobalRootDir))
dataDir := dirs.GlobalRootDir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this true on hybrid as well? Unless, I'm misunderstanding what the problem is and which path exists in which scenario.

Suggested change
dataDir := dirs.GlobalRootDir
dataDir := dirs.SnapdStateDir(dirs.GlobalRootDir)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is a mount point on hybrid. On core it is a bind mount.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tests/nested/manual/muinstaller-real fails with this.

Comment on lines 224 to 229
if osutil.FileExists(writable) {
dataDir = writable
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if osutil.FileExists(writable) {
dataDir = writable
}
if osutil.FileExists(writable) {
// appears be an Ubuntu Core device, where /writable exists
dataDir = writable
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of it, I will test it is a mount point. Because someone could create /writable and easily break it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we check whether release indicates we are on Core and so choose the right path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. That might be just simpler.

Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some suggestions about tweaks to the unit tests

defer fdestate.MockDMCryptUUIDFromMountPoint(func(mountpoint string) (string, error) {
fmt.Printf("%s %s %s\n", mountpoint, dirs.GlobalRootDir, filepath.Join(dirs.GlobalRootDir, "writable"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.Logf() ?

Suggested change
fmt.Printf("%s %s %s\n", mountpoint, dirs.GlobalRootDir, filepath.Join(dirs.GlobalRootDir, "writable"))
c.Logf("%s %s %s\n", mountpoint, dirs.GlobalRootDir, filepath.Join(dirs.GlobalRootDir, "writable"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that was some debug thing. I can just remove it.

@@ -101,10 +103,17 @@ func (u *instrumentedUnlocker) Relock() {
u.relocked += 1
}

func (s *fdeMgrSuite) startedManager(c *C) *fdestate.FDEManager {
func (s *fdeMgrSuite) startedManager(c *C, onClassic bool) *fdestate.FDEManager {
s.AddCleanup(release.MockOnClassic(onClassic))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd move the mocking back to the actual test and have a MockOnClassic(true) in SetUpTest() so that we have a clear 'view' of the system state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@ZeyadYasser ZeyadYasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Some small nitpicks

@@ -218,7 +220,12 @@ func initializeState(st *state.State) error {

// FIXME mount points will be different in recovery or factory-reset modes
// either inspect degraded.json, or use boot.HostUbuntuDataForMode()
dataUUID, dataErr := disksDMCryptUUIDFromMountPoint(dirs.SnapdStateDir(dirs.GlobalRootDir))
dataDir := dirs.GlobalRootDir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes / the correct mount point to look at to find the data disk on classic? maybe a small comment is needed to explain this.

c.Check(primaryKey.Digest.Digest, DeepEquals, []byte{5, 6, 7, 8})
}

func (s *fdeMgrSuite) TestGetManagerFromStateWithWritable(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, both tests seem identical, maybe the could be merged

Suggested change
func (s *fdeMgrSuite) TestGetManagerFromStateWithWritable(c *C) {
func (s *fdeMgrSuite) testGetManagerFromState(c *C, onClassic bool)
st := s.st
defer release.MockOnClassic(onClassic)()
manager := s.startedManager(c, onClassic)
st.Lock()
defer st.Unlock()
foundManager := fdestate.FdeMgr(st)
c.Check(foundManager, Equals, manager)
var fdeSt fdestate.FdeState
err := st.Get("fde", &fdeSt)
c.Assert(err, IsNil)
primaryKey, hasPrimaryKey := fdeSt.PrimaryKeys[0]
c.Assert(hasPrimaryKey, Equals, true)
c.Check(crypto.Hash(primaryKey.Digest.Algorithm), Equals, crypto.Hash(crypto.SHA256))
c.Check(primaryKey.Digest.Salt, DeepEquals, []byte{1, 2, 3, 4})
c.Check(primaryKey.Digest.Digest, DeepEquals, []byte{5, 6, 7, 8})
}
func (s *fdeMgrSuite) TestGetManagerFromState(c *C) {
const onClassic = true
s.testGetManagerFromState(c, onClassic)
}
func (s *fdeMgrSuite) TestGetManagerFromStateWithWritable(c *C) {
const onClassic = false
s.testGetManagerFromState(c, onClassic)
}

@@ -82,6 +84,8 @@ func (s *fdeMgrSuite) SetUpTest(c *C) {
}
err := m.WriteTo(dirs.GlobalRootDir)
c.Assert(err, IsNil)

s.AddCleanup(release.MockOnClassic(true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bboozzoo asked for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valentindavid valentindavid force-pushed the valentindavid/fix-hybrid-data-path branch from 61223f5 to a80d97c Compare November 20, 2024 13:15
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

if !release.OnClassic {
// If on Core /writable is a bind mount from data dir
dataDir = filepath.Join(dirs.GlobalRootDir, "writable")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: it feels like this logic should be a function of the dirs package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

We used a path that is not a mount point on hybrid to discover the
data disk. Instead we now use / for hybrid, and /writable on core.
@valentindavid valentindavid force-pushed the valentindavid/fix-hybrid-data-path branch from 491569b to 1d6746f Compare November 22, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FDE Manager Pull requests that target FDE manager branch Run nested The PR also runs tests inluded in nested suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants