Skip to content

boot/grub.go: add new bootchain#13412

Merged
Meulengracht merged 5 commits intocanonical:masterfrom
valentindavid:valentindavid/grub-all-boot-chains
Mar 13, 2024
Merged

boot/grub.go: add new bootchain#13412
Meulengracht merged 5 commits intocanonical:masterfrom
valentindavid:valentindavid/grub-all-boot-chains

Conversation

@valentindavid
Copy link
Copy Markdown
Member

We need to resolve the boot chains another place based on the trusted assets we encountered to be installed. At this point it could be any chain. We will need to discover later what the correct chain is.

Also make TrustedAssets return an unsorted data structure to make sure we do not use the order like the comments claimed.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 6, 2023

Codecov Report

Attention: Patch coverage is 86.63102% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 78.88%. Comparing base (6a7ecfe) to head (25b4ef9).
Report is 76 commits behind head on master.

Files Patch % Lines
boot/seal.go 80.68% 11 Missing and 6 partials ⚠️
boot/assets.go 82.60% 5 Missing and 3 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #13412     +/-   ##
=========================================
  Coverage   78.88%   78.88%             
=========================================
  Files        1037     1040      +3     
  Lines      132757   133944   +1187     
=========================================
+ Hits       104722   105668    +946     
- Misses      21503    21675    +172     
- Partials     6532     6601     +69     
Flag Coverage Δ
unittests 78.88% <86.63%> (+<0.01%) ⬆️

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 marked this pull request as ready for review December 6, 2023 13:09
@valentindavid
Copy link
Copy Markdown
Member Author

Needed for #13205

Comment thread boot/assets.go Outdated
Comment thread boot/seal.go Outdated
Comment thread boot/seal.go Outdated
@valentindavid valentindavid changed the title boot/grub.go: return all possible boot chains boot/grub.go: add new bootchain Dec 6, 2023
@pedronis pedronis self-requested a review December 6, 2023 18:42
@valentindavid
Copy link
Copy Markdown
Member Author

I have found a bug. We do not seem to remove files that should be removed. So moving from boot entry back to non boot entry (that is removing the fbx64.efi) would not work.

I wonder if we should add "removed" content to the gadget.yaml.

@github-actions github-actions Bot added the Run Nested -auto- Label automatically added in case nested tests need to be executed label Dec 7, 2023
Copy link
Copy Markdown
Contributor

@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.

did a pass, I'm slightly wary of the changes to assets.go

Comment thread bootloader/bootloader.go Outdated
Comment thread bootloader/bootloader.go Outdated
Comment thread bootloader/grub.go Outdated
Comment thread boot/assets.go Outdated
Comment thread boot/assets.go Outdated
Comment thread bootloader/bootloader.go Outdated
@valentindavid valentindavid force-pushed the valentindavid/grub-all-boot-chains branch from 207b4f2 to 5401330 Compare December 8, 2023 12:59
@valentindavid valentindavid force-pushed the valentindavid/grub-all-boot-chains branch from 759e5d3 to 5d9a30b Compare January 9, 2024 08:50
@valentindavid valentindavid reopened this Jan 10, 2024
@valentindavid valentindavid force-pushed the valentindavid/grub-all-boot-chains branch from 5d9a30b to 3188a4c Compare January 10, 2024 15:47
@valentindavid
Copy link
Copy Markdown
Member Author

I had to rebase. So I cleaned up the history.

Copy link
Copy Markdown
Contributor

@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, mainly some comments/questions about using Ids as Paths in BootFiles

Comment thread tests/nested/manual/uc-grub-boot-chains/modify-gadget.py Outdated
Comment thread tests/nested/manual/uc-grub-boot-chains/modify-gadget.py Outdated
Comment on lines 89 to 95
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this not supported? will it be?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh! I am missing a fixme here.

I need to fix the deletion of gadget content that is not available in the next gadget. In case of downgrade, the "next gadget" should not have "fbx64.efi", so we should remove it, because it changes the behavior of shim.

I will do this fix in a different PR. But I will for sure comment here on why this does not work. And why it needs to work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have added the explanation.

Comment thread bootloader/grub.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a bit strange given that BootFile has a still a field called Path, I thought we would keep the path as they were and use the TrustedAssets map to get to id to use in the cache

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for the tip. I did not realize I could do that. I have fixed it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the comment should go away or be changed now

Comment thread boot/assets.go Outdated
Copy link
Copy Markdown
Contributor

@pedronis pedronis Jan 11, 2024

Choose a reason for hiding this comment

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

why the []string? assetNames are now unique again and have one asset assigned to them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was verifying that we had only one later. But now I have rewritten it so that we verify it right away.

Comment thread boot/seal.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

buildBootAssets could take the TrustedAssets map and then BootFile could still carry paths?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread bootloader/grub.go Outdated
@valentindavid
Copy link
Copy Markdown
Member Author

@olivercalder I have added you as reviewer. This has some changes from your branch to add the new boot chain. But it does not do anything with the variables yet. I will rebase your branch on top of this. I thought you would like to have a look.

Copy link
Copy Markdown
Contributor

@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, some detail comments on the last round of changes

Comment thread bootloader/bootloader.go Outdated
Comment thread bootloader/grub.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the comment should go away or be changed now

Comment thread bootloader/grub.go Outdated
Comment thread boot/seal_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we call this ...AllBootChains to clarify what is about a bit more?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This tests the internal function runModeBootChains. This is why I named it like that. Function recoveryBootChainsForSystems is already tested by TestRecoveryBootChainsForSystems. And we were missing tests for runModeBootChains. Not sure what to name it if not TestRunModeBootChains.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, do have higher level tests then that test the case where we need to consider both old and new grub assets locations? I saw only this one doing that but maybe I missed them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, I think we are missing a test for ResealKeyToModeenv with both chain present at the same time. We do test both. But separately.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have modified TestResealKeyToModeenvWithSystemFallback to also cover cases where we upgrade or downgrade. This calls ResealKeyToModeenv which is higher level.

But that is starting to be complicated. Specially because of ordering and factorization of boot chains. There is lots of ways to express allowed boot chains. But we only test one, which is very hard to guess. I spend a day to make it work.

Comment thread boot/assets.go Outdated
Comment thread boot/assets.go Outdated
Comment thread boot/assets.go Outdated
Comment on lines 803 to 807
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we probably want to keep this comment before the log below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not all trusted assets will be present now. So I am thinking we should remove the notice. But the logic is still fine. If the asset is not in the cache, then we should ignore it.

Comment thread boot/seal.go Outdated
Comment on lines 875 to 879
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is strange, it should either be a log or a panic, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That was some debugging that I committed by mistake.

Comment thread boot/seal.go Outdated
Comment thread boot/seal.go Outdated
Copy link
Copy Markdown
Contributor

@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, looking good, just some remarks about comments and a question about the test combinations #13412 (comment)

Comment thread bootloader/bootloader.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/names in/names recorded in/ is perhaps slightly clearer?

Comment thread bootloader/grub.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/names in/names recorded in/

Comment thread boot/seal.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this probably merit a comment why the new logic is ok with not finding some asset chains

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This one can only be generated by a broken bootloader. So it should be an error.

Comment thread boot/seal.go Outdated
Comment thread boot/seal.go Outdated
Copy link
Copy Markdown
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.

I have a question about the spread test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this work by removing the content of the EFI boot vars, as a temporary workaround? Or by removing the files under EFI/ubuntu/.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, we do not touch variables in this PR. This will come in the Oliver's PR. It is better to remove EFI/ubuntu and EFI/boot/fbx64.efi. If the variables are wrong, it will fallback anyway. But this is what I want installation of gadget to do. A "content" entry that disappears should imply removing the file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But maybe still worth running this part of the test by removing "manually" the files, even while keeping the comment so when removing from snapd is implemented we can remove the workaround?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will try preventing reboot with systemd-inhibit and see if I can remove the assets before reboot.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, it is true that being faster than the reboot can be a problem, so please ignore this if it gets too hacky. Approving now, thanks for the changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! Maybe the comment above need to be slightly adapted now explaining the workaround.

Comment thread bootloader/grub.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

super-nitpick: 2024 now 🙂

Comment thread bootloader/grub.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: s/the list load chains/the list of load chains/

Copy link
Copy Markdown
Contributor

@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, small issue with the error message also there seem to be formatting issues as the static checks are failing

Comment thread boot/seal.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/Asset/internal error: asset/ error always start with lowercase

Copy link
Copy Markdown
Member

@olivercalder olivercalder left a comment

Choose a reason for hiding this comment

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

Looks really good, thank you!

Comment thread boot/assets.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't believe relativeTarget is used anymore in this function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct. Not easy to spot. I have removed it.

Comment thread boot/assets.go Outdated
Comment thread boot/assets.go Outdated
Comment on lines 806 to 817
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a comment here would be very useful to explain if it is expected behavior that there are multiple assets of the same name, and if not, why we use byAssetName instead of trustedAssets in the latter for loop. It seems to me that constructing and using byAssetName guarantees there are no reused asset names and is thus safer, but a comment to this effect would be useful. Something like "same as trustedAssets, but with uniqueness guarantee"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed this multiple times. So it seems in the end it was just about filtering duplicates. I will simplify the code here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have simplified the code.

Comment thread boot/assets.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't seem to find where TrustedAssetsList is actually defined outside of mocking, but perhaps s/TrustedAssetsList/TrustedAssetsMap/g, since it's now a map instead of a list?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed it and all the tests to use a map.

Comment thread bootloader/grub.go Outdated
Comment on lines 525 to 536
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why no tag?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I should may comment on it. The idea about using "asset names" instead of the path is because current implementation uses base names. So for backward compliance, we need to use no tag for all the paths that were used before. I will comment it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah now I understand. fb was not an old one. I can put boot: for this one.

Comment thread bootloader/grub_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

2024 here as well :)

Copy link
Copy Markdown
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

@valentindavid valentindavid force-pushed the valentindavid/grub-all-boot-chains branch from 7c253df to d6db7d9 Compare February 21, 2024 14:25
@Meulengracht Meulengracht added this to the 2.62 milestone Mar 5, 2024
@ernestl ernestl added the Needs Samuele review Needs a review from Samuele before it can land label Mar 6, 2024
Copy link
Copy Markdown
Contributor

@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, one wondering

Comment thread boot/assets.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder as we are very much in control of this from the bootloader side, whether this should be an actual error? cc @alfonsosanchezbeato @bboozzoo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably this should return as an internal error, I agree

Copy link
Copy Markdown
Member

@olivercalder olivercalder left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for taking on all of this!

@valentindavid
Copy link
Copy Markdown
Member Author

Everything should be fixed. I will let the CI run and then autosquash it.

We need to resolve the boot chains another place based on the trusted
assets we encountered to be installed. At this point it could be any chain.
We will need to discover later what the correct chain is.

Also make TrustedAssets return an unsorted data structure to make sure
we do not use the order like the comments claimed.
@valentindavid valentindavid force-pushed the valentindavid/grub-all-boot-chains branch from 25b4ef9 to 95b2edb Compare March 12, 2024 14:47
@Meulengracht Meulengracht merged commit 3424bc3 into canonical:master Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Samuele review Needs a review from Samuele before it can land Run Nested -auto- Label automatically added in case nested tests need to be executed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants