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

fix/ota-2421/disallow downloading non-OSTree binaries #1282

Merged

Conversation

Zee314159
Copy link
Contributor

Draft code, just some thoughts to address this issue.

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch from 6e64eb4 to c9e5607 Compare August 7, 2019 14:34
@Zee314159 Zee314159 requested a review from lbonn August 7, 2019 14:36
@codecov-io
Copy link

codecov-io commented Aug 7, 2019

Codecov Report

Merging #1282 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1282      +/-   ##
==========================================
- Coverage   79.05%   79.02%   -0.04%     
==========================================
  Files         178      178              
  Lines       10475    10482       +7     
==========================================
+ Hits         8281     8283       +2     
- Misses       2194     2199       +5
Impacted Files Coverage Δ
src/libaktualizr/primary/sotauptaneclient.h 100% <ø> (ø) ⬆️
src/libaktualizr/primary/sotauptaneclient.cc 92.31% <100%> (+0.19%) ⬆️
src/libaktualizr/uptane/exceptions.h 91.66% <100%> (+0.55%) ⬆️
src/libaktualizr/storage/sqlstorage_base.h 60% <0%> (-40%) ⬇️
src/libaktualizr/storage/sqlstorage_base.cc 74.32% <0%> (-4.06%) ⬇️
src/libaktualizr/utilities/utils.h 93.33% <0%> (ø) ⬆️
src/libaktualizr/storage/sqlstorage.cc 75.86% <0%> (+0.24%) ⬆️

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 7971998...a2ae26d. Read the comment docs.

if (!target.IsOstree() &&
(config.pacman.type == PackageManager::kOstree || config.pacman.type == PackageManager::kOstreeDockerApp)) {
LOG_ERROR << "Cannot install a non-OSTree package on an OSTree system";
sendEvent<event::InstallTargetComplete>(primary_ecu_serial, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO, I'd make this code more generic and extendable, i.e. instead of comparing a specific target type with specific package manager types do something like the following:
if (target.type != config.pacman.type)

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO, I'd make this code more generic and extendable

I like the idea but currently we don't really have a good way to support that. The only type that we can recognize in the Target metadata is OSTree, so for now, that's the only one worth checking.

In other cases when is_new = false the event event::InstallTargetComplete is not sent, I am just wondering if it's correct place to do it here.

I agree, instead of sending that event, we should just set last_exception and return false. The log message is fine, though.

if (!target.IsOstree() &&
(config.pacman.type == PackageManager::kOstree || config.pacman.type == PackageManager::kOstreeDockerApp)) {
LOG_ERROR << "Cannot install a non-OSTree package on an OSTree system";
sendEvent<event::InstallTargetComplete>(primary_ecu_serial, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In other cases when is_new = false the event event::InstallTargetComplete is not sent, I am just wondering if it's correct place to do it here.

@pattivacek
Copy link
Collaborator

The logic looks about right, but we need a test for this. It will need to use the OSTree package manager, but it won't need to actually use it since the update will already fail at the check for updates.

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch from 487028c to 4d52a04 Compare August 9, 2019 04:11
Copy link
Contributor Author

@Zee314159 Zee314159 left a comment

Choose a reason for hiding this comment

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

It will need to use the OSTree package manager,

https://github.com/advancedtelematic/ostree-basic-pkg
This tool?

if (!target.IsOstree() &&
(config.pacman.type == PackageManager::kOstree || config.pacman.type == PackageManager::kOstreeDockerApp)) {
LOG_ERROR << "Cannot install a non-OSTree package on an OSTree system";
last_exception = Uptane::InvalidMetadata(target.filename(), "", "Non-OSTree 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.

Is ‘InvalidMetadata’ the proper exception type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not a bad choice, but since it's usually used for problems in parsing the metadata, maybe we should find something else. Nothing else looks better, though, so how about making a new exception? InvalidTarget perhaps?

Copy link
Contributor Author

@Zee314159 Zee314159 Aug 12, 2019

Choose a reason for hiding this comment

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

Sure,I was considering making a new one too. Thanks!

@pattivacek
Copy link
Collaborator

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 2 times, most recently from ff60411 to 8f1eed4 Compare August 12, 2019 14:25
@Zee314159
Copy link
Contributor Author

Totally raw! Maybe I should use json to make a fake target instead of using aktualizr tool to generate one? And the 'generate ostree sysroot' part also looks not good.

@pattivacek
Copy link
Collaborator

Maybe I should use json to make a fake target instead of using aktualizr tool to generate one?

Nah, using aktualizr-repo is perfect. That looks fine to me.

And the 'generate ostree sysroot' part also looks not good.

I also think that part is a bit overcomplicated. You don't actually need to mock the sysroot and all that, or at least I don't think so. It looks like you modeled that part off of the test_aktualizr_fullostree, but what you actually want is just to use the simpler method used by ostreemanager_test, which just uses a sysroot generated by the make_ostree_sysroot.sh script I mentioned. Since you don't have to actually install anything, you shouldn't need to do the whole complex mocking bit.

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 4 times, most recently from fe3430c to 5a24aab Compare August 13, 2019 06:26
@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 8 times, most recently from 5e7dcca to 4ad2074 Compare August 14, 2019 07:10
@pattivacek
Copy link
Collaborator

If you rebase on latest master, you should be able to get the Travis timeout resolved.

I ran your branch locally and noticed this in the output: image command requires --targetsha256 or --targetsha512, and --targetlength when --filename is not supplied.. That's uptane-generator (former aktualizr-repo) complaining and might be part of what's going wrong.

@Zee314159
Copy link
Contributor Author

If you rebase on latest master

Trapped in git chaos...I'll figure the way out tomorrow.

image command requires --targetsha256 or --targetsha512, and --targetlength when --filename is not supplied.. That's uptane-generator (former aktualizr-repo) complaining and might be part of what's going wrong.

I might should start with this issue first.

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 2 times, most recently from 4c74ecf to 9d1aa78 Compare August 16, 2019 06:20
@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 2 times, most recently from 4b3da79 to 3db232a Compare August 16, 2019 09:37
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.

A few minor comments. As far as why the test is failing... perhaps my assumptions about how easy it would be to fake an ostree sysroot for this purpose was wrong. I'm not sure i understand why ostree is complaining, though. Have you been able to trace it with gdb?


#include <ostree.h>

boost::filesystem::path aktualizr_repo_path;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This variable doesn't need to be global.

#include "storage/sqlstorage.h"
#include "test_utils.h"

#include <ostree.h>
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 this include shouldn't be necessary anymore.

#include <future>
#include <iostream>
#include <string>
#include <thread>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are all of these includes necessary as well?

boost::trim_if(new_rev, boost::is_any_of(" \t\r\n"));
LOG_INFO << "DEST: " << new_rev;

Process akt_repo(aktualizr_repo_path.string());
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 I recommend renaming the "aktualizr_repo" references here to "uptane_generator". (I also changed every "akt_repo" to just "gen".)

@Zee314159
Copy link
Contributor Author

A few minor comments. As far as why the test is failing... perhaps my assumptions about how easy it would be to fake an ostree sysroot for this purpose was wrong. I'm not sure i understand why ostree is complaining, though. Have you been able to trace it with gdb?

No, I was trying to use the whole mock the sysroot and unptane-generate part from aktuarlizr_fullostree_test. But aktuarlizr_fullostree_test will fail locally too.

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch from 3db232a to 702c9aa Compare August 16, 2019 13:07
@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 2 times, most recently from 6ae1ed9 to ba061fa Compare August 19, 2019 01:58
@lbonn
Copy link
Contributor

lbonn commented Aug 19, 2019

The code looks good but can we change the commit messages before merging?

@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch 2 times, most recently from 96ddefb to 784fd81 Compare August 19, 2019 11:34
Added unit test

Fixed bugs that failed the test

Removed unnecessary ostree bits

Signed-off-by: Zee314159 <252806294@qq.com>
@Zee314159 Zee314159 force-pushed the fix/ota-2421/disallow-downloading-non-ostree-binaries branch from 784fd81 to a2ae26d Compare August 20, 2019 12:47
@pattivacek pattivacek merged commit 2c9fed9 into master Aug 21, 2019
@pattivacek pattivacek deleted the fix/ota-2421/disallow-downloading-non-ostree-binaries branch August 21, 2019 07:51
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

5 participants