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

overload/fdestate/backend: implement FDE hook resealing #14305

Conversation

valentindavid
Copy link
Contributor

@valentindavid valentindavid commented Aug 5, 2024

This also adds:

  • tests/lib/fakestore: add support for tracking channels
  • tests: add remodeling test using fakestore

@valentindavid valentindavid added Run nested The PR also runs tests inluded in nested suite FDE Manager Pull requests that target FDE manager branch labels Aug 5, 2024
@github-actions github-actions bot added the Run Nested -auto- Label automatically added in case nested tests need to be executed label Aug 5, 2024
@valentindavid valentindavid force-pushed the valentindavid/remodel-fakestore branch from 2695fa0 to 9cd28d9 Compare August 30, 2024 11:44
@valentindavid valentindavid force-pushed the valentindavid/remodel-fakestore branch 2 times, most recently from b0bd57d to 825c315 Compare September 20, 2024 14:33
@valentindavid valentindavid force-pushed the valentindavid/remodel-fakestore branch 5 times, most recently from 185cc1d to 083087c Compare October 3, 2024 09:03
@valentindavid valentindavid marked this pull request as ready for review October 3, 2024 11:54
@valentindavid valentindavid changed the title tests: add remodeling test using fakestore overload/fdestate/backend: implement FDE hook resealing Oct 3, 2024
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.

thanks, did a first pass on this

@@ -394,7 +413,7 @@ func (s *Store) detailsEndpoint(w http.ResponseWriter, req *http.Request) {
w.Write(out)
}

func (s *Store) collectSnaps() (map[string]string, error) {
func (s *Store) collectSnaps(cs *ChannelRepository) (map[string]string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is cs passed in when is also on s?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't see an answer or change related to this question

tests/lib/fakestore/store/store.go Outdated Show resolved Hide resolved
overlord/fdestate/backend/reseal.go Outdated Show resolved Hide resolved
overlord/fdestate/backend/reseal.go Show resolved Hide resolved
overlord/fdestate/backend/reseal.go Outdated Show resolved Hide resolved
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.

thanks, looking good, small comment/questions and I'm not sure a question from the previous review about the fakestore changes was addressed

Comment on lines 1 to 4
summary: verify remodel from UC20 to UC22
details: |
Blah
Verify remodel from UC20 to UC22. This verifies unencrypted, tpm and
fde hook modes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this mention the fakestore? do we have a not fakestore variant?

@@ -394,7 +413,7 @@ func (s *Store) detailsEndpoint(w http.ResponseWriter, req *http.Request) {
w.Write(out)
}

func (s *Store) collectSnaps() (map[string]string, error) {
func (s *Store) collectSnaps(cs *ChannelRepository) (map[string]string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't see an answer or change related to this question

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

Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

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

Thanks, l have some comments / questions

Comment on lines 723 to 739
if a.Channel != "" {
snapPath, foundSnap = snaps[fmt.Sprintf("%s|%s", name, a.Channel)]
}
if !foundSnap {
snapPath, foundSnap = snaps[name]
}

Choose a reason for hiding this comment

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

Maybe a nitpick as this is test code, but do we want to look with the normal name if a channel has been specified? Shouldn't we just return with error/empty result? Unless channel is latest/stable maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good question. I suppose I did it like that because other tests are not setting channels correctly, that are matching the model, or the --channel=... parameter to refresh or install. And I suppose it is rarely "latest/stable" the tests actually look for. But I do not remember. That is probably a task to look at at some point to clean-up the broken tests.

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 will add a comment

Choose a reason for hiding this comment

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

Great, thanks for adding the comment


mkdir "${tmpd}/early"
mkdir "${tmpd}/main"
( (cd "${tmpd}/early"; cpio -id) ; (cd "${tmpd}/main"; zstdcat | cpio -id) ) <"${tmpd}/initrd"

Choose a reason for hiding this comment

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

cannot we just use unmkinitramfs?

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 am not a fan of initramfs-tools in general. And also the overcomplicated way unmkinitramfs tries to split the initramfs.

Choose a reason for hiding this comment

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

Ok, but this will fail for older initramfs not using zstd, or newer using maybe something else. So maybe we need to chang in the future.

Comment on lines 55 to 57
if [ "${BUILD_FDE_HOOK-}" = 1 ]; then
go build -o "${tmpd}/pc-kernel/meta/hooks/fde-setup" /project/tests/lib/fde-setup-hook
fi

Choose a reason for hiding this comment

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

isn't this compiling the same as fde-reveal-key? why not just copy around the already compiled binary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go has a build cache, right?

Choose a reason for hiding this comment

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

Tbh I was not that concerned about build time but about something changing and then forgetting to change the thing in two places, but not really very important anyway.

Choose a reason for hiding this comment

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

This is very useful, maybe it should go to tests/lib/. As a side point, we do similar things in different places, it would be great to unify at some point. Maybe this script could be the reference for repacking kernels.

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 agree. But I would like to go through tests/lib/nested.sh and rewrite some of the code to use some generic script. And then use the same script here.

mkdir -p ./extra-initrd/usr/bin/
go build -o ./extra-initrd/usr/bin/fde-reveal-key "$TESTSLIB"/fde-setup-hook/fde-setup.go
mkdir -p ./extra-kernel-snap/meta/hooks
go build -o ./extra-kernel-snap/meta/hooks/fde-setup "$TESTSLIB"/fde-setup-hook/fde-setup.go

Choose a reason for hiding this comment

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

Same nitpick about double building the same binary instead of copying

Comment on lines 158 to 160
for f in updates/{core22,pc-22,pc-kernel-22}.{snap,assert} updates/pc-22.{snap,assert} updates/pc-kernel-22.{snap,assert}; do
remote.push "${f}"
done

Choose a reason for hiding this comment

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

Is pushing the snaps 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.

It is probably the remains some old attempts without changing the fakestore. I will remove that.

boot/seal.go Outdated

Choose a reason for hiding this comment

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

As far as I can see the main changes in this file are that things that in the past were done only for TPM-backed FDE are done also when using hooks. As in principle we dot not care about boot chains / sealing for hooks, what is the purpose of these changes? Maybe there is some spec that would help me understand this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On FDE hooks, we do care about what model is used depending of the key we unseal. This is a boot chain. That is much smaller than TPM, but it is still a boot chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably have some abstractions though here. But it is yet obvious what it should look like. There will be the run mode that will be introduce in the future, that is not here. And maybe it will start to make more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should rename it to "boot context" at some point.

Choose a reason for hiding this comment

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

Thanks for the offline clarification

Comment on lines +65 to +74
type comparableModel struct {
BrandID string
SignKeyID string
Model string
Classic bool
Grade asserts.ModelGrade
Series string
}

Choose a reason for hiding this comment

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

do we need this just because there is no Series field in modelForSealing? Maybe worth adding a comment explaining.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There should be Series in modelForSealing.

The problem here is that it is not useable as an index for a map, because it is not comparable.

return "some-key"
}

func (s *secbootSuite) TestResealKeysWithFDESetupHookV1(c *C) {

Choose a reason for hiding this comment

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

What is v1 in this context? Which other formats for keyslots do we have?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this is a mistake here. It tests v2. The new format is v3.

We have 2 format of keydata. Keydata are json. v1 is not json. But this does not need resealing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note, the version here is not related to the key slots. But the key format. Which might be stored in the token for the key slot, or stored in a file.

@valentindavid valentindavid force-pushed the valentindavid/remodel-fakestore branch 4 times, most recently from e0ce10a to dac3674 Compare October 21, 2024 08:46
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 63.46154% with 76 lines in your changes missing coverage. Please review.

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

Files with missing lines Patch % Lines
tests/lib/fakestore/store/store.go 57.33% 26 Missing and 6 partials ⚠️
secboot/secboot_hooks.go 42.50% 16 Missing and 7 partials ⚠️
boot/seal.go 72.91% 9 Missing and 4 partials ⚠️
overlord/fdestate/backend/reseal.go 86.04% 4 Missing and 2 partials ⚠️
secboot/secboot_dummy.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##             fde-manager-features   #14305   +/-   ##
=======================================================
  Coverage                        ?   78.83%           
=======================================================
  Files                           ?     1093           
  Lines                           ?   147706           
  Branches                        ?        0           
=======================================================
  Hits                            ?   116449           
  Misses                          ?    23992           
  Partials                        ?     7265           
Flag Coverage Δ
unittests 78.83% <63.46%> (?)

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.

@valentindavid valentindavid force-pushed the valentindavid/remodel-fakestore branch 5 times, most recently from a20dc03 to 73ea788 Compare October 21, 2024 16:45
@valentindavid
Copy link
Contributor Author

I have implemented the update of the state as part of #14674 that will go on top of this.

Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes

@pedronis pedronis merged commit 58e1ac7 into canonical:fde-manager-features Nov 5, 2024
42 of 58 checks passed
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 -auto- Label automatically added in case nested tests need to be executed Run nested The PR also runs tests inluded in nested suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants