Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

OTA-3969: Do the full verification of metadata on the IP Secondary #1449

Merged
merged 2 commits into from
Nov 26, 2019

Conversation

mike-sul
Copy link
Collaborator

Signed-off-by: Mykhaylo Sul myk.sul@gmail.com

@pattivacek
Copy link
Collaborator

Nice, maybe this is easier than I thought! Let me know when you're ready for a deeper review. But at first glance it's looking good.

@mike-sul mike-sul force-pushed the feat/OTA-3969/ip-secondary-full-verification branch from e53af0d to b7867bb Compare November 15, 2019 16:00
@codecov-io
Copy link

codecov-io commented Nov 15, 2019

Codecov Report

Merging #1449 into master will increase coverage by 0.34%.
The diff coverage is 85.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1449      +/-   ##
==========================================
+ Coverage   80.25%   80.59%   +0.34%     
==========================================
  Files         182      184       +2     
  Lines       11029    11068      +39     
==========================================
+ Hits         8851     8920      +69     
+ Misses       2178     2148      -30
Impacted Files Coverage Δ
src/aktualizr_secondary/aktualizr_secondary.h 100% <ø> (ø) ⬆️
src/libaktualizr/uptane/imagesrepository.h 100% <ø> (ø) ⬆️
src/libaktualizr/uptane/fetcher.cc 100% <ø> (ø) ⬆️
.../virtual_secondary/partialverificationsecondary.cc 70.21% <100%> (ø) ⬆️
src/libaktualizr/primary/sotauptaneclient.cc 88.93% <100%> (+0.14%) ⬆️
...aktualizr_secondary/aktualizr_secondary_metadata.h 100% <100%> (ø)
src/libaktualizr/uptane/uptanerepository.h 100% <100%> (ø) ⬆️
...c/aktualizr_secondary/aktualizr_secondary_common.h 100% <100%> (ø) ⬆️
src/libaktualizr/uptane/tuf.h 95.86% <100%> (+0.33%) ⬆️
src/libaktualizr/uptane/directorrepository.cc 95.94% <100%> (+0.05%) ⬆️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d06138...0fdd4c0. Read the comment docs.

@mike-sul mike-sul force-pushed the feat/OTA-3969/ip-secondary-full-verification branch 6 times, most recently from 631945a to 307dcb6 Compare November 22, 2019 09:50
@mike-sul mike-sul force-pushed the feat/OTA-3969/ip-secondary-full-verification branch 4 times, most recently from d33d800 to 09214cb Compare November 25, 2019 14:27
Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Thanks! This looks really good. I like the metadata "fetching" refactoring, and I think that looks forward-compatible with delegations, once we support them for secondaries. The tests look good, too. We can probably do more, but it's a great start.

@@ -61,7 +68,7 @@ if(BUILD_OSTREE)
LIBRARIES uptane_generator_lib
LIBRARIES aktualizr-posix
ARGS ${PROJECT_BINARY_DIR}/ostree_repo PROJECT_WORKING_DIRECTORY)
target_link_libraries(t_aktualizr_secondary_uptane virtual_secondary)
target_link_libraries(t_aktualizr_secondary_uptane virtual_secondary)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not at all critical, but what's up with this indent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some kind of typo, will move it back.

@@ -113,14 +86,17 @@ bool AktualizrSecondary::putRootResp(const std::string& root, bool director) {
}

bool AktualizrSecondary::sendFirmwareResp(const std::shared_ptr<std::string>& firmware) {
if (target_ == nullptr) {
LOG_ERROR << "No valid installation target found";
auto targetsForThisEcu = director_repo_.getTargets(getSerial());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be rechecking the metadata (without fetching) like we do on the Primary before installation? It seems redundant, but it's a protection against unexpected changes in the time since the metadata was received.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I agree, we should check at least an image file size (binary case) and its hash (for both ostree and binary).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's also worth rechecking the whole metadata chain from the metadata, but yeah, checking the object's hash/size is even more important.

//
// The followin steps of the Director's target metadata verification are missing in DirectorRepository::updateMeta()
// 6. If checking Targets metadata from the Director repository, verify that there are no delegations.
// 7. If checking Targets metadata from the Director repository, check that no ECU identifier is represented more
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make a tech debt ticket for this and put it in the robustness epic?

It looks like you've already implemented the check for the secondary; is your proposal to move that check into the Uptane code directly so it is applied universally as early as is reasonable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I'll do it.

I did #7, not #6, and yes my proposal to do apply it universally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood. We implicitly do step 6 in that we ignore the concept of delegations from the Director, but it's not a bad idea to check for them and throw a warning if found. Since we don't use the Snapshot role on the Director, though, all we can do is just check for them in the Targets metadata.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

// This procedure doesn't exactly follow the spec:
// https://uptane.github.io/uptane-standard/uptane-standard.html#check_root At first, it should try to download N+1
// version of the Root metadata file instead of downloading the "latest" one how do we know which version is the
// latest and why just root.json is downloaded ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

root.json without a number is guaranteed to be the latest in our scheme. The design is to fetch the latest, and if it matches what we already have stored, we're good. If not, then we have to go fetch the missing ones by name/number until we catch up. Might be worth a renewed discussion on what the best method is; I don't see the harm in our method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for explanation.

// 1. At initial stage (just after provisioning) the root metadata from 1.root.json are not verified
// 2. If local_version becomes higher than 1, e.g. 2 than a rollback attack is possible since the business logic
// here won't return any error as suggested in #4 of
// https://uptane.github.io/uptane-standard/uptane-standard.html#check_root
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good call. Can you make another tech debt for this? (It's the same logic with the Image repo, so it can all be in one ticket.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -235,6 +241,11 @@ bool ImagesRepository::updateMeta(INvStorage& storage, Fetcher& fetcher) {
local_version = -1;
}

// I am not sure that #6 of https://uptane.github.io/uptane-standard/uptane-standard.html#check_snapshot is
// performed
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's your concern? That we don't match the Targets metadata filenames?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I mean exactly what #6 says

"Check that each Targets metadata filename listed in the previous Snapshot metadata file is also listed in this"

Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be another thing worth making a ticket for and looking into more. I'm not sure how critical this really is, though, and I'm also not sure that the backend doesn't make some optimizations that would prevent that from working. In fact, I'm not sure this is actually sensible; what happens if a delegation gets (legitimately) removed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI: uptane/uptane-standard#149. Let's wait for resolution on that before making changes on our side.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

Signed-off-by: Mykhaylo Sul <myk.sul@gmail.com>
Signed-off-by: Mykhaylo Sul <myk.sul@gmail.com>
@mike-sul mike-sul force-pushed the feat/OTA-3969/ip-secondary-full-verification branch from 09214cb to 0fdd4c0 Compare November 26, 2019 11:46
@mike-sul
Copy link
Collaborator Author

@patrickvacek Updated the PR according to the comments as well as created the suggested "robustness" tickets.
Also, created a follow-up ticket for more detailed testing as we discussed https://saeljira.it.here.com/browse/OTA-4120.

Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@pattivacek pattivacek merged commit 8136440 into master Nov 26, 2019
@pattivacek pattivacek deleted the feat/OTA-3969/ip-secondary-full-verification branch November 26, 2019 12:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants